diff options
author | Andrew Comminos <andrew@morlunk.com> | 2015-04-01 05:49:20 +0300 |
---|---|---|
committer | Andrew Comminos <andrew@morlunk.com> | 2015-04-01 05:49:20 +0300 |
commit | 4e5a77d916d7ffe923f1288088b4cb6cc3cd45a7 (patch) | |
tree | a09096da4d956ce1fce43397a79b6550d3e3b4ef /src | |
parent | cec50689fbf9ceef17aa0cbe57603f34ef942328 (diff) |
Continued progress in consolidating reconfiguration.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/aidl/com/morlunk/jumble/IJumbleService.aidl | 8 | ||||
-rw-r--r-- | src/main/java/com/morlunk/jumble/JumbleService.java | 30 | ||||
-rw-r--r-- | src/main/java/com/morlunk/jumble/net/JumbleConnection.java | 13 |
3 files changed, 40 insertions, 11 deletions
diff --git a/src/main/aidl/com/morlunk/jumble/IJumbleService.aidl b/src/main/aidl/com/morlunk/jumble/IJumbleService.aidl index 4451752..25cc118 100644 --- a/src/main/aidl/com/morlunk/jumble/IJumbleService.aidl +++ b/src/main/aidl/com/morlunk/jumble/IJumbleService.aidl @@ -97,4 +97,12 @@ interface IJumbleService { // Observation void registerObserver(in IJumbleObserver observer); void unregisterObserver(in IJumbleObserver observer); + + /** + * Reconfigures the JumbleService with the given extras. + * These are the same extras you would pass in for a connect call. This "patches" the service + * only with the new extras specified. + * @return true if the a reconnect is required for changes to take effect. + */ + boolean reconfigure(in Bundle extras); }
\ No newline at end of file diff --git a/src/main/java/com/morlunk/jumble/JumbleService.java b/src/main/java/com/morlunk/jumble/JumbleService.java index ddeeb8e..3dfe661 100644 --- a/src/main/java/com/morlunk/jumble/JumbleService.java +++ b/src/main/java/com/morlunk/jumble/JumbleService.java @@ -23,7 +23,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.media.AudioManager; -import android.media.MediaRecorder; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Build; @@ -220,17 +219,16 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon @Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { - if (intent.getExtras() != null) { - Bundle extras = intent.getExtras(); + Bundle extras = intent.getExtras(); + if (extras != null) { try { - loadSettings(extras); + configureExtras(extras); } catch (AudioException e) { throw new RuntimeException("Attempted to initialize audio in onStartCommand erroneously."); } } if (ACTION_CONNECT.equals(intent.getAction())) { - Bundle extras = intent.getExtras(); if (extras == null || !extras.containsKey(EXTRAS_SERVER)) { // Ensure that we have been provided all required attributes. throw new RuntimeException(ACTION_CONNECT + " requires a server provided in extras."); @@ -473,7 +471,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon * @return true if a reconnect is required for changes to take effect. * @see com.morlunk.jumble.JumbleService */ - private boolean loadSettings(Bundle extras) throws AudioException { + private boolean configureExtras(Bundle extras) throws AudioException { boolean reconnectNeeded = false; if (extras.containsKey(EXTRAS_SERVER)) { mServer = extras.getParcelable(EXTRAS_SERVER); @@ -527,7 +525,9 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon } if (extras.containsKey(EXTRAS_ACCESS_TOKENS)) { mAccessTokens = extras.getStringArrayList(EXTRAS_ACCESS_TOKENS); - // TODO: send access tokens + if (mConnection != null && mConnection.isConnected()) { + mConnection.sendAccessTokens(mAccessTokens); + } } if (extras.containsKey(EXTRAS_AUDIO_SOURCE)) { mAudioBuilder.setAudioSource(extras.getInt(EXTRAS_AUDIO_SOURCE)); @@ -766,10 +766,7 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon @Override public void sendAccessTokens(List tokens) throws RemoteException { - mAccessTokens = new ArrayList<String>(tokens); - Mumble.Authenticate.Builder ab = Mumble.Authenticate.newBuilder(); - ab.addAllTokens(mAccessTokens); - mConnection.sendTCPMessage(ab.build(), JumbleTCPMessageType.Authenticate); + mConnection.sendAccessTokens(tokens); } @Override @@ -910,5 +907,16 @@ public class JumbleService extends Service implements JumbleConnection.JumbleCon public void unregisterObserver(IJumbleObserver observer) throws RemoteException { mCallbacks.unregisterObserver(observer); } + + @Override + public boolean reconfigure(Bundle extras) throws RemoteException { + try { + return configureExtras(extras); + } catch (AudioException e) { + e.printStackTrace(); + // TODO + return true; + } + } } } diff --git a/src/main/java/com/morlunk/jumble/net/JumbleConnection.java b/src/main/java/com/morlunk/jumble/net/JumbleConnection.java index f3474cc..2bbbad9 100644 --- a/src/main/java/com/morlunk/jumble/net/JumbleConnection.java +++ b/src/main/java/com/morlunk/jumble/net/JumbleConnection.java @@ -36,6 +36,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.ConnectException; import java.nio.ByteBuffer; +import java.nio.channels.NotYetConnectedException; import java.security.InvalidKeyException; import java.security.KeyManagementException; import java.security.KeyStore; @@ -45,6 +46,7 @@ import java.security.NoSuchProviderException; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -567,6 +569,17 @@ public class JumbleConnection implements JumbleTCP.TCPConnectionListener, Jumble sendTCPMessage(utb.build(), JumbleTCPMessageType.UDPTunnel); } + /** + * Sends the given access tokens to the server. + * @param tokens A list of new access tokens to send to the server. + */ + public void sendAccessTokens(Collection<String> tokens) { + if(!mConnected) return; + Mumble.Authenticate.Builder ab = Mumble.Authenticate.newBuilder(); + ab.addAllTokens(tokens); + sendTCPMessage(ab.build(), JumbleTCPMessageType.Authenticate); + } + @Override public void onTCPMessageReceived(JumbleTCPMessageType type, int length, byte[] data) { if(!UNLOGGED_MESSAGES.contains(type)) |