diff options
author | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2020-06-11 14:35:15 -0400 |
---|---|---|
committer | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2020-06-11 14:35:15 -0400 |
commit | 4c025a72c44c53a7b9ff6fbf88aad62d0a840771 (patch) | |
tree | 119711e23b9c4308a54e3d3139bb21604c184610 | |
parent | e6498f057b86c21310fd5e9d1ba2c593e31ef5a5 (diff) | |
download | sdl_android-feature/android_lcm.tar.gz |
Update formattingfeature/android_lcm
6 files changed, 641 insertions, 535 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java index 77097a9c1..84865f21e 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/SdlManagerTests.java @@ -356,7 +356,7 @@ public class SdlManagerTests extends AndroidTestCase2 { testSendMultipleRPCs(true); } - private void testSendMultipleRPCs(boolean sequentialSend){ + private void testSendMultipleRPCs(boolean sequentialSend) { listenerCalledCounter = 0; // When internalInterface.sendRPCs() is called, call listener.onFinished() to fake the response @@ -370,7 +370,7 @@ public class SdlManagerTests extends AndroidTestCase2 { } }; - if (sequentialSend){ + if (sequentialSend) { doAnswer(answer).when(internalInterface).sendSequentialRPCs(any(List.class), any(OnMultipleRequestListener.class)); } else { @@ -378,12 +378,12 @@ public class SdlManagerTests extends AndroidTestCase2 { } - // Test send RPC requests List<RPCMessage> rpcsList = Arrays.asList(new GetVehicleData(), new Show(), new OnAppServiceData(), new GetAppServiceDataResponse()); OnMultipleRequestListener onMultipleRequestListener = new OnMultipleRequestListener() { @Override - public void onUpdate(int remainingRequests) { } + public void onUpdate(int remainingRequests) { + } @Override public void onFinished() { @@ -391,10 +391,12 @@ public class SdlManagerTests extends AndroidTestCase2 { } @Override - public void onError(int correlationId, Result resultCode, String info) {} + public void onError(int correlationId, Result resultCode, String info) { + } @Override - public void onResponse(int correlationId, RPCResponse response) {} + public void onResponse(int correlationId, RPCResponse response) { + } }; if (sequentialSend) { sdlManager.sendSequentialRPCs(rpcsList, onMultipleRequestListener); diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java index e1d92c61d..2a34dc62e 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -60,318 +60,333 @@ import java.util.List; /** * <strong>SDLManager</strong> <br> - * + * <p> * This is the main point of contact between an application and SDL <br> - * + * <p> * It is broken down to these areas: <br> - * + * <p> * 1. SDLManagerBuilder <br> * 2. ISdl Interface along with its overridden methods - This can be passed into attached managers <br> * 3. Sending Requests <br> * 4. Helper methods */ -public class SdlManager extends BaseSdlManager{ - private Context context; - private LockScreenConfig lockScreenConfig; - - // Managers - private LockScreenManager lockScreenManager; - private VideoStreamManager videoStreamManager; - private AudioStreamManager audioStreamManager; - - /** - * Starts up a SdlManager, and calls provided callback called once all BaseSubManagers are done setting up - */ - @Override - public void start(){ - if (lifecycleManager == null) { - if(transport!= null && transport.getTransportType() == TransportType.MULTIPLEX){ - //Do the thing - MultiplexTransportConfig multiplexTransportConfig = (MultiplexTransportConfig)(transport); - final MultiplexTransportConfig.TransportListener devListener = multiplexTransportConfig.getTransportListener(); - multiplexTransportConfig.setTransportListener(new MultiplexTransportConfig.TransportListener() { - @Override - public void onTransportEvent(List<TransportRecord> connectedTransports, boolean audioStreamTransportAvail, boolean videoStreamTransportAvail) { - - //Pass to submanagers that need it - if(videoStreamManager != null){ - videoStreamManager.handleTransportUpdated(connectedTransports, audioStreamTransportAvail, videoStreamTransportAvail); - } - - if(audioStreamManager != null){ - audioStreamManager.handleTransportUpdated(connectedTransports, audioStreamTransportAvail, videoStreamTransportAvail); - } - //If the developer supplied a listener to start, it is time to call that - if(devListener != null){ - devListener.onTransportEvent(connectedTransports,audioStreamTransportAvail,videoStreamTransportAvail); - } - } - }); - - //If the requires audio support has not been set, it should be set to true if the - //app is a media app, and false otherwise - if(multiplexTransportConfig.requiresAudioSupport() == null){ - multiplexTransportConfig.setRequiresAudioSupport(isMediaApp); - } - } - - super.start(); - - lifecycleManager.setContext(context); - lifecycleManager.start(); - } - } - - @Override - protected void initialize(){ - // Instantiate sub managers - this.permissionManager = new PermissionManager(_internalInterface); - this.fileManager = new FileManager(_internalInterface, context, fileManagerConfig); - if (lockScreenConfig.isEnabled()) { - this.lockScreenManager = new LockScreenManager(lockScreenConfig, context, _internalInterface); - } - this.screenManager = new ScreenManager(_internalInterface, this.fileManager); - if(getAppTypes().contains(AppHMIType.NAVIGATION) || getAppTypes().contains(AppHMIType.PROJECTION)){ - this.videoStreamManager = new VideoStreamManager(_internalInterface); - } else { - this.videoStreamManager = null; - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN - && (getAppTypes().contains(AppHMIType.NAVIGATION) || getAppTypes().contains(AppHMIType.PROJECTION)) ) { - this.audioStreamManager = new AudioStreamManager(_internalInterface, context); - } else { - this.audioStreamManager = null; - } - - // Start sub managers - this.permissionManager.start(subManagerListener); - this.fileManager.start(subManagerListener); - if (lockScreenConfig.isEnabled()){ - this.lockScreenManager.start(subManagerListener); - } - this.screenManager.start(subManagerListener); - } - - @Override - void checkState() { - if (permissionManager != null && fileManager != null && screenManager != null && (!lockScreenConfig.isEnabled() || lockScreenManager != null)) { - if (permissionManager.getState() == BaseSubManager.READY && fileManager.getState() == BaseSubManager.READY && screenManager.getState() == BaseSubManager.READY && (!lockScreenConfig.isEnabled() || lockScreenManager.getState() == BaseSubManager.READY)) { - DebugTool.logInfo("Starting sdl manager, all sub managers are in ready state"); - transitionToState(BaseSubManager.READY); - handleQueuedNotifications(); - notifyDevListener(null); - onReady(); - } else if (permissionManager.getState() == BaseSubManager.ERROR && fileManager.getState() == BaseSubManager.ERROR && screenManager.getState() == BaseSubManager.ERROR && (!lockScreenConfig.isEnabled() || lockScreenManager.getState() == BaseSubManager.ERROR)) { - String info = "ERROR starting sdl manager, all sub managers are in error state"; - Log.e(TAG, info); - transitionToState(BaseSubManager.ERROR); - notifyDevListener(info); - } else if (permissionManager.getState() == BaseSubManager.SETTING_UP || fileManager.getState() == BaseSubManager.SETTING_UP || screenManager.getState() == BaseSubManager.SETTING_UP || (lockScreenConfig.isEnabled() && lockScreenManager != null && lockScreenManager.getState() == BaseSubManager.SETTING_UP)) { - DebugTool.logInfo("SETTING UP sdl manager, some sub managers are still setting up"); - transitionToState(BaseSubManager.SETTING_UP); - // No need to notify developer here! - } else { - Log.w(TAG, "LIMITED starting sdl manager, some sub managers are in error or limited state and the others finished setting up"); - transitionToState(BaseSubManager.LIMITED); - handleQueuedNotifications(); - notifyDevListener(null); - onReady(); - } - } else { - // We should never be here, but somehow one of the sub-sub managers is null - String info = "ERROR one of the sdl sub managers is null"; - Log.e(TAG, info); - transitionToState(BaseSubManager.ERROR); - notifyDevListener(info); - } - } - - private void notifyDevListener(String info) { - if (managerListener != null) { - if (getState() == BaseSubManager.ERROR){ - managerListener.onError(info, null); - } else { - managerListener.onStart(); - } - } - } - - @Override - void retryChangeRegistration() { - changeRegistrationRetry++; - if (changeRegistrationRetry < MAX_RETRY) { - final Handler handler = new Handler(Looper.getMainLooper()); - handler.postDelayed(new Runnable() { - @Override - public void run() { - checkLifecycleConfiguration(); - DebugTool.logInfo("Retry Change Registration Count: " + changeRegistrationRetry); - } - }, 3000); - } - } - - @Override - void onProxyClosed(SdlDisconnectedReason reason) { - Log.i(TAG,"Proxy is closed."); - if(managerListener != null){ - managerListener.onDestroy(); - } - - if (reason == null || !reason.equals(SdlDisconnectedReason.LANGUAGE_CHANGE)){ - dispose(); - } - } - - /** Dispose SdlManager and clean its resources - * <strong>Note: new instance of SdlManager should be created on every connection. SdlManager cannot be reused after getting disposed.</strong> - */ - @SuppressLint("NewApi") - @Override - public void dispose() { - if (this.permissionManager != null) { - this.permissionManager.dispose(); - } - - if (this.fileManager != null) { - this.fileManager.dispose(); - } - - if (this.lockScreenManager != null) { - this.lockScreenManager.dispose(); - } - - if (this.screenManager != null) { - this.screenManager.dispose(); - } - - if(this.videoStreamManager != null) { - this.videoStreamManager.dispose(); - } - - // SuppressLint("NewApi") is used because audioStreamManager is only available on android >= jelly bean - if (this.audioStreamManager != null) { - this.audioStreamManager.dispose(); - } - - if (this.lifecycleManager != null) { - this.lifecycleManager.stop(); - } - - if(managerListener != null){ - managerListener.onDestroy(); - managerListener = null; - } - - transitionToState(BaseSubManager.SHUTDOWN); - } - - // MANAGER GETTERS +public class SdlManager extends BaseSdlManager { + private Context context; + private LockScreenConfig lockScreenConfig; + + // Managers + private LockScreenManager lockScreenManager; + private VideoStreamManager videoStreamManager; + private AudioStreamManager audioStreamManager; + + /** + * Starts up a SdlManager, and calls provided callback called once all BaseSubManagers are done setting up + */ + @Override + public void start() { + if (lifecycleManager == null) { + if (transport != null && transport.getTransportType() == TransportType.MULTIPLEX) { + //Do the thing + MultiplexTransportConfig multiplexTransportConfig = (MultiplexTransportConfig) (transport); + final MultiplexTransportConfig.TransportListener devListener = multiplexTransportConfig.getTransportListener(); + multiplexTransportConfig.setTransportListener(new MultiplexTransportConfig.TransportListener() { + @Override + public void onTransportEvent(List<TransportRecord> connectedTransports, boolean audioStreamTransportAvail, boolean videoStreamTransportAvail) { + + //Pass to submanagers that need it + if (videoStreamManager != null) { + videoStreamManager.handleTransportUpdated(connectedTransports, audioStreamTransportAvail, videoStreamTransportAvail); + } + + if (audioStreamManager != null) { + audioStreamManager.handleTransportUpdated(connectedTransports, audioStreamTransportAvail, videoStreamTransportAvail); + } + //If the developer supplied a listener to start, it is time to call that + if (devListener != null) { + devListener.onTransportEvent(connectedTransports, audioStreamTransportAvail, videoStreamTransportAvail); + } + } + }); + + //If the requires audio support has not been set, it should be set to true if the + //app is a media app, and false otherwise + if (multiplexTransportConfig.requiresAudioSupport() == null) { + multiplexTransportConfig.setRequiresAudioSupport(isMediaApp); + } + } + + super.start(); + + lifecycleManager.setContext(context); + lifecycleManager.start(); + } + } + + @Override + protected void initialize() { + // Instantiate sub managers + this.permissionManager = new PermissionManager(_internalInterface); + this.fileManager = new FileManager(_internalInterface, context, fileManagerConfig); + if (lockScreenConfig.isEnabled()) { + this.lockScreenManager = new LockScreenManager(lockScreenConfig, context, _internalInterface); + } + this.screenManager = new ScreenManager(_internalInterface, this.fileManager); + if (getAppTypes().contains(AppHMIType.NAVIGATION) || getAppTypes().contains(AppHMIType.PROJECTION)) { + this.videoStreamManager = new VideoStreamManager(_internalInterface); + } else { + this.videoStreamManager = null; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN + && (getAppTypes().contains(AppHMIType.NAVIGATION) || getAppTypes().contains(AppHMIType.PROJECTION))) { + this.audioStreamManager = new AudioStreamManager(_internalInterface, context); + } else { + this.audioStreamManager = null; + } + + // Start sub managers + this.permissionManager.start(subManagerListener); + this.fileManager.start(subManagerListener); + if (lockScreenConfig.isEnabled()) { + this.lockScreenManager.start(subManagerListener); + } + this.screenManager.start(subManagerListener); + } + + @Override + void checkState() { + if (permissionManager != null && fileManager != null && screenManager != null && (!lockScreenConfig.isEnabled() || lockScreenManager != null)) { + if (permissionManager.getState() == BaseSubManager.READY && fileManager.getState() == BaseSubManager.READY && screenManager.getState() == BaseSubManager.READY && (!lockScreenConfig.isEnabled() || lockScreenManager.getState() == BaseSubManager.READY)) { + DebugTool.logInfo("Starting sdl manager, all sub managers are in ready state"); + transitionToState(BaseSubManager.READY); + handleQueuedNotifications(); + notifyDevListener(null); + onReady(); + } else if (permissionManager.getState() == BaseSubManager.ERROR && fileManager.getState() == BaseSubManager.ERROR && screenManager.getState() == BaseSubManager.ERROR && (!lockScreenConfig.isEnabled() || lockScreenManager.getState() == BaseSubManager.ERROR)) { + String info = "ERROR starting sdl manager, all sub managers are in error state"; + Log.e(TAG, info); + transitionToState(BaseSubManager.ERROR); + notifyDevListener(info); + } else if (permissionManager.getState() == BaseSubManager.SETTING_UP || fileManager.getState() == BaseSubManager.SETTING_UP || screenManager.getState() == BaseSubManager.SETTING_UP || (lockScreenConfig.isEnabled() && lockScreenManager != null && lockScreenManager.getState() == BaseSubManager.SETTING_UP)) { + DebugTool.logInfo("SETTING UP sdl manager, some sub managers are still setting up"); + transitionToState(BaseSubManager.SETTING_UP); + // No need to notify developer here! + } else { + Log.w(TAG, "LIMITED starting sdl manager, some sub managers are in error or limited state and the others finished setting up"); + transitionToState(BaseSubManager.LIMITED); + handleQueuedNotifications(); + notifyDevListener(null); + onReady(); + } + } else { + // We should never be here, but somehow one of the sub-sub managers is null + String info = "ERROR one of the sdl sub managers is null"; + Log.e(TAG, info); + transitionToState(BaseSubManager.ERROR); + notifyDevListener(info); + } + } + + private void notifyDevListener(String info) { + if (managerListener != null) { + if (getState() == BaseSubManager.ERROR) { + managerListener.onError(info, null); + } else { + managerListener.onStart(); + } + } + } + + @Override + void retryChangeRegistration() { + changeRegistrationRetry++; + if (changeRegistrationRetry < MAX_RETRY) { + final Handler handler = new Handler(Looper.getMainLooper()); + handler.postDelayed(new Runnable() { + @Override + public void run() { + checkLifecycleConfiguration(); + DebugTool.logInfo("Retry Change Registration Count: " + changeRegistrationRetry); + } + }, 3000); + } + } + + @Override + void onProxyClosed(SdlDisconnectedReason reason) { + Log.i(TAG, "Proxy is closed."); + if (managerListener != null) { + managerListener.onDestroy(); + } + + if (reason == null || !reason.equals(SdlDisconnectedReason.LANGUAGE_CHANGE)) { + dispose(); + } + } + + /** + * Dispose SdlManager and clean its resources + * <strong>Note: new instance of SdlManager should be created on every connection. SdlManager cannot be reused after getting disposed.</strong> + */ + @SuppressLint("NewApi") + @Override + public void dispose() { + if (this.permissionManager != null) { + this.permissionManager.dispose(); + } + + if (this.fileManager != null) { + this.fileManager.dispose(); + } + + if (this.lockScreenManager != null) { + this.lockScreenManager.dispose(); + } + + if (this.screenManager != null) { + this.screenManager.dispose(); + } + + if (this.videoStreamManager != null) { + this.videoStreamManager.dispose(); + } + + // SuppressLint("NewApi") is used because audioStreamManager is only available on android >= jelly bean + if (this.audioStreamManager != null) { + this.audioStreamManager.dispose(); + } + + if (this.lifecycleManager != null) { + this.lifecycleManager.stop(); + } + + if (managerListener != null) { + managerListener.onDestroy(); + managerListener = null; + } + + transitionToState(BaseSubManager.SHUTDOWN); + } + + // MANAGER GETTERS + /** * Gets the VideoStreamManager. <br> - * The VideoStreamManager returned will only be not null if the registered app type is - * either NAVIGATION or PROJECTION. Once the VideoStreamManager is retrieved, its start() - * method will need to be called before use. + * The VideoStreamManager returned will only be not null if the registered app type is + * either NAVIGATION or PROJECTION. Once the VideoStreamManager is retrieved, its start() + * method will need to be called before use. * <br><br><strong>Note: VideoStreamManager should be used only after SdlManager.start() CompletionListener callback is completed successfully.</strong> + * * @return a VideoStreamManager object attached to this SdlManager instance */ - public @Nullable VideoStreamManager getVideoStreamManager() { - checkSdlManagerState(); - return videoStreamManager; - } + public @Nullable + VideoStreamManager getVideoStreamManager() { + checkSdlManagerState(); + return videoStreamManager; + } /** * Gets the AudioStreamManager. <br> - * The AudioStreamManager returned will only be not null if the registered app type is - * either NAVIGATION or PROJECTION. Once the AudioStreamManager is retrieved, its start() - * method will need to be called before use. + * The AudioStreamManager returned will only be not null if the registered app type is + * either NAVIGATION or PROJECTION. Once the AudioStreamManager is retrieved, its start() + * method will need to be called before use. * <br><strong>Note: AudioStreamManager should be used only after SdlManager.start() CompletionListener callback is completed successfully.</strong> + * * @return a AudioStreamManager object */ - public @Nullable AudioStreamManager getAudioStreamManager() { - checkSdlManagerState(); - return audioStreamManager; - } - - /** - * Gets the LockScreenManager. <br> - * <strong>Note: LockScreenManager should be used only after SdlManager.start() CompletionListener callback is completed successfully.</strong> - * @return a LockScreenManager object - */ - public LockScreenManager getLockScreenManager() { - if (lockScreenManager.getState() != BaseSubManager.READY && lockScreenManager.getState() != BaseSubManager.LIMITED){ - Log.e(TAG, "LockScreenManager should not be accessed because it is not in READY/LIMITED state"); - } - checkSdlManagerState(); - return lockScreenManager; - } - - // PROTECTED GETTERS - protected LockScreenConfig getLockScreenConfig() { return lockScreenConfig; } - - // BUILDER - public static class Builder extends BaseSdlManager.Builder{ - /** - * Builder for the SdlManager. Parameters in the constructor are required. - * @param context the current context - * @param appId the app's ID - * @param appName the app's name - * @param listener a SdlManagerListener object - */ - public Builder(@NonNull Context context, @NonNull final String appId, @NonNull final String appName, @NonNull final SdlManagerListener listener){ - super(appId, appName, listener); - setContext(context); - } - /** - * Builder for the SdlManager. Parameters in the constructor are required. - * @param context the current context - * @param appId the app's ID - * @param appName the app's name - * @param listener a SdlManagerListener object - */ - public Builder(@NonNull Context context, @NonNull final String appId, @NonNull final String appName, @NonNull BaseTransportConfig transport, @NonNull final SdlManagerListener listener){ - super(appId, appName, listener); - setContext(context); - setTransportType(transport); - } - - /** - * Sets the LockScreenConfig for the session. <br> - * <strong>Note: If not set, the default configuration will be used.</strong> - * @param lockScreenConfig - configuration options - */ - public Builder setLockScreenConfig (final LockScreenConfig lockScreenConfig){ - sdlManager.lockScreenConfig = lockScreenConfig; - return this; - } - - /** - * Sets the Context - * @param context the current context - */ - public Builder setContext(Context context){ - sdlManager.context = context; - return this; - } - - /** - * Build SdlManager ang get it ready to be started - * <strong>Note: new instance of SdlManager should be created on every connection. SdlManager cannot be reused after getting disposed.</strong> - * @return SdlManager instance that is ready to be started - */ - public SdlManager build() { - if (sdlManager.transport == null) { - throw new IllegalArgumentException("You must set a transport type object"); - } - - if (sdlManager.lockScreenConfig == null){ - // if lock screen params are not set, use default - sdlManager.lockScreenConfig = new LockScreenConfig(); - } - - super.build(); - - return sdlManager; - } - } + public @Nullable + AudioStreamManager getAudioStreamManager() { + checkSdlManagerState(); + return audioStreamManager; + } + + /** + * Gets the LockScreenManager. <br> + * <strong>Note: LockScreenManager should be used only after SdlManager.start() CompletionListener callback is completed successfully.</strong> + * + * @return a LockScreenManager object + */ + public LockScreenManager getLockScreenManager() { + if (lockScreenManager.getState() != BaseSubManager.READY && lockScreenManager.getState() != BaseSubManager.LIMITED) { + Log.e(TAG, "LockScreenManager should not be accessed because it is not in READY/LIMITED state"); + } + checkSdlManagerState(); + return lockScreenManager; + } + + // PROTECTED GETTERS + protected LockScreenConfig getLockScreenConfig() { + return lockScreenConfig; + } + + // BUILDER + public static class Builder extends BaseSdlManager.Builder { + /** + * Builder for the SdlManager. Parameters in the constructor are required. + * + * @param context the current context + * @param appId the app's ID + * @param appName the app's name + * @param listener a SdlManagerListener object + */ + public Builder(@NonNull Context context, @NonNull final String appId, @NonNull final String appName, @NonNull final SdlManagerListener listener) { + super(appId, appName, listener); + setContext(context); + } + + /** + * Builder for the SdlManager. Parameters in the constructor are required. + * + * @param context the current context + * @param appId the app's ID + * @param appName the app's name + * @param listener a SdlManagerListener object + */ + public Builder(@NonNull Context context, @NonNull final String appId, @NonNull final String appName, @NonNull BaseTransportConfig transport, @NonNull final SdlManagerListener listener) { + super(appId, appName, listener); + setContext(context); + setTransportType(transport); + } + + /** + * Sets the LockScreenConfig for the session. <br> + * <strong>Note: If not set, the default configuration will be used.</strong> + * + * @param lockScreenConfig - configuration options + */ + public Builder setLockScreenConfig(final LockScreenConfig lockScreenConfig) { + sdlManager.lockScreenConfig = lockScreenConfig; + return this; + } + + /** + * Sets the Context + * + * @param context the current context + */ + public Builder setContext(Context context) { + sdlManager.context = context; + return this; + } + + /** + * Build SdlManager ang get it ready to be started + * <strong>Note: new instance of SdlManager should be created on every connection. SdlManager cannot be reused after getting disposed.</strong> + * + * @return SdlManager instance that is ready to be started + */ + public SdlManager build() { + if (sdlManager.transport == null) { + throw new IllegalArgumentException("You must set a transport type object"); + } + + if (sdlManager.lockScreenConfig == null) { + // if lock screen params are not set, use default + sdlManager.lockScreenConfig = new LockScreenConfig(); + } + + super.build(); + + return sdlManager; + } + } } diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java index d29029aaf..777e29f1b 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java @@ -115,7 +115,7 @@ public class LifecycleManager extends BaseLifecycleManager { private void cycleProxy(SdlDisconnectedReason disconnectedReason) { cleanProxy(); initializeProxy(); - if(!SdlDisconnectedReason.LEGACY_BLUETOOTH_MODE_ENABLED.equals(disconnectedReason) && !SdlDisconnectedReason.PRIMARY_TRANSPORT_CYCLE_REQUEST.equals(disconnectedReason)){ + if (!SdlDisconnectedReason.LEGACY_BLUETOOTH_MODE_ENABLED.equals(disconnectedReason) && !SdlDisconnectedReason.PRIMARY_TRANSPORT_CYCLE_REQUEST.equals(disconnectedReason)) { //We don't want to alert higher if we are just cycling for legacy bluetooth onClose("Sdl Proxy Cycled", new SdlException("Sdl Proxy Cycled", SdlExceptionCause.SDL_PROXY_CYCLED)); } @@ -153,7 +153,7 @@ public class LifecycleManager extends BaseLifecycleManager { } @Override - void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig){ + void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) { super.onTransportDisconnected(info, availablePrimary, transportConfig); if (availablePrimary) { _transportConfig = transportConfig; diff --git a/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java b/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java index 14e1eae49..c52f27b2d 100644 --- a/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java @@ -122,20 +122,21 @@ abstract class BaseSdlManager { final LifecycleManager.LifecycleListener lifecycleListener = new LifecycleManager.LifecycleListener() { @Override public void onProxyConnected(LifecycleManager lifeCycleManager) { - Log.i(TAG,"Proxy is connected. Now initializing."); - synchronized (this){ + Log.i(TAG, "Proxy is connected. Now initializing."); + synchronized (this) { changeRegistrationRetry = 0; checkLifecycleConfiguration(); initialize(); } } + @Override - public void onServiceStarted(SessionType sessionType){ + public void onServiceStarted(SessionType sessionType) { } @Override - public void onServiceEnded(SessionType sessionType){ + public void onServiceEnded(SessionType sessionType) { } @@ -154,7 +155,7 @@ abstract class BaseSdlManager { final CompletionListener subManagerListener = new CompletionListener() { @Override public synchronized void onComplete(boolean success) { - if(!success){ + if (!success) { Log.e(TAG, "Sub manager failed to initialize"); } checkState(); @@ -163,14 +164,18 @@ abstract class BaseSdlManager { // ABSTRACT METHODS abstract void retryChangeRegistration(); + abstract void onProxyClosed(SdlDisconnectedReason reason); + abstract void checkState(); + abstract void initialize(); + public abstract void dispose(); - protected void checkLifecycleConfiguration(){ - final Language actualLanguage = this.getRegisterAppInterfaceResponse().getLanguage(); - final Language actualHMILanguage = this.getRegisterAppInterfaceResponse().getHmiDisplayLanguage(); + protected void checkLifecycleConfiguration() { + final Language actualLanguage = this.getRegisterAppInterfaceResponse().getLanguage(); + final Language actualHMILanguage = this.getRegisterAppInterfaceResponse().getHmiDisplayLanguage(); if ((actualLanguage != null && !actualLanguage.equals(language)) || (actualHMILanguage != null && !actualHMILanguage.equals(hmiLanguage))) { @@ -194,7 +199,7 @@ abstract class BaseSdlManager { changeRegistration.setOnRPCResponseListener(new OnRPCResponseListener() { @Override public void onResponse(int correlationId, RPCResponse response) { - if (response.getSuccess()){ + if (response.getSuccess()) { // go through and change sdlManager properties that were changed via the LCU update hmiLanguage = actualHMILanguage; language = actualLanguage; @@ -235,6 +240,7 @@ abstract class BaseSdlManager { /** * Get the current state for the SdlManager + * * @return int value that represents the current state * @see BaseSubManager */ @@ -250,13 +256,13 @@ abstract class BaseSdlManager { } } - void checkSdlManagerState(){ - if (getState() != BaseSubManager.READY && getState() != BaseSubManager.LIMITED){ + void checkSdlManagerState() { + if (getState() != BaseSubManager.READY && getState() != BaseSubManager.LIMITED) { Log.e(TAG, "SdlManager is not ready for use, be sure to initialize with start() method, implement callback, and use SubManagers in the SdlManager's callback"); } } - void initNotificationQueue(){ + void initNotificationQueue() { //Setup the notification queue if (onRPCNotificationListeners != null) { Set<FunctionID> functionIDSet = onRPCNotificationListeners.keySet(); @@ -275,7 +281,7 @@ abstract class BaseSdlManager { } } - void handleQueuedNotifications(){ + void handleQueuedNotifications() { //Handle queued notifications and add the listeners if (onRPCNotificationListeners != null) { Set<FunctionID> functionIDSet = onRPCNotificationListeners.keySet(); @@ -312,7 +318,7 @@ abstract class BaseSdlManager { * Starts up a SdlManager, and calls provided callback called once all BaseSubManagers are done setting up */ @SuppressWarnings("unchecked") - public void start(){ + public void start() { LifecycleManager.AppConfig appConfig = new LifecycleManager.AppConfig(); appConfig.setAppName(appName); //short app name @@ -339,7 +345,7 @@ abstract class BaseSdlManager { initNotificationQueue(); } - void onReady(){ + void onReady() { // Set the app icon if (BaseSdlManager.this.appIcon != null && BaseSdlManager.this.appIcon.getName() != null) { if (fileManager != null && fileManager.getState() == BaseSubManager.READY && !fileManager.hasUploadedFile(BaseSdlManager.this.appIcon)) { @@ -360,43 +366,73 @@ abstract class BaseSdlManager { } // PROTECTED GETTERS - protected String getAppName() { return appName; } + protected String getAppName() { + return appName; + } - protected String getAppId() { return appId; } + protected String getAppId() { + return appId; + } - protected String getShortAppName() { return shortAppName; } + protected String getShortAppName() { + return shortAppName; + } - protected Version getMinimumProtocolVersion() { return minimumProtocolVersion; } + protected Version getMinimumProtocolVersion() { + return minimumProtocolVersion; + } - protected Version getMinimumRPCVersion() { return minimumRPCVersion; } + protected Version getMinimumRPCVersion() { + return minimumRPCVersion; + } - protected Language getHmiLanguage() { return hmiLanguage; } + protected Language getHmiLanguage() { + return hmiLanguage; + } - protected Language getLanguage() { return language; } + protected Language getLanguage() { + return language; + } - protected TemplateColorScheme getDayColorScheme() { return dayColorScheme; } + protected TemplateColorScheme getDayColorScheme() { + return dayColorScheme; + } - protected TemplateColorScheme getNightColorScheme() { return nightColorScheme; } + protected TemplateColorScheme getNightColorScheme() { + return nightColorScheme; + } - protected Vector<AppHMIType> getAppTypes() { return hmiTypes; } + protected Vector<AppHMIType> getAppTypes() { + return hmiTypes; + } - protected Vector<String> getVrSynonyms() { return vrSynonyms; } + protected Vector<String> getVrSynonyms() { + return vrSynonyms; + } - protected Vector<TTSChunk> getTtsChunks() { return ttsChunks; } + protected Vector<TTSChunk> getTtsChunks() { + return ttsChunks; + } - protected BaseTransportConfig getTransport() { return transport; } + protected BaseTransportConfig getTransport() { + return transport; + } - protected FileManagerConfig getFileManagerConfig() { return fileManagerConfig; } + protected FileManagerConfig getFileManagerConfig() { + return fileManagerConfig; + } // MANAGER GETTERS + /** * Gets the PermissionManager. <br> * <strong>Note: PermissionManager should be used only after SdlManager.start() CompletionListener callback is completed successfully.</strong> + * * @return a PermissionManager object */ public PermissionManager getPermissionManager() { - if (permissionManager.getState() != BaseSubManager.READY && permissionManager.getState() != BaseSubManager.LIMITED){ - Log.e(TAG,"PermissionManager should not be accessed because it is not in READY/LIMITED state"); + if (permissionManager.getState() != BaseSubManager.READY && permissionManager.getState() != BaseSubManager.LIMITED) { + Log.e(TAG, "PermissionManager should not be accessed because it is not in READY/LIMITED state"); } checkSdlManagerState(); return permissionManager; @@ -405,10 +441,11 @@ abstract class BaseSdlManager { /** * Gets the FileManager. <br> * <strong>Note: FileManager should be used only after SdlManager.start() CompletionListener callback is completed successfully.</strong> + * * @return a FileManager object */ public FileManager getFileManager() { - if (fileManager.getState() != BaseSubManager.READY && fileManager.getState() != BaseSubManager.LIMITED){ + if (fileManager.getState() != BaseSubManager.READY && fileManager.getState() != BaseSubManager.LIMITED) { Log.e(TAG, "FileManager should not be accessed because it is not in READY/LIMITED state"); } checkSdlManagerState(); @@ -418,10 +455,11 @@ abstract class BaseSdlManager { /** * Gets the ScreenManager. <br> * <strong>Note: ScreenManager should be used only after SdlManager.start() CompletionListener callback is completed successfully.</strong> + * * @return a ScreenManager object */ public ScreenManager getScreenManager() { - if (screenManager.getState() != BaseSubManager.READY && screenManager.getState() != BaseSubManager.LIMITED){ + if (screenManager.getState() != BaseSubManager.READY && screenManager.getState() != BaseSubManager.LIMITED) { Log.e(TAG, "ScreenManager should not be accessed because it is not in READY/LIMITED state"); } checkSdlManagerState(); @@ -431,9 +469,10 @@ abstract class BaseSdlManager { /** * Gets the SystemCapabilityManager. <br> * <strong>Note: SystemCapabilityManager should be used only after SdlManager.start() CompletionListener callback is completed successfully.</strong> + * * @return a SystemCapabilityManager object */ - public SystemCapabilityManager getSystemCapabilityManager(){ + public SystemCapabilityManager getSystemCapabilityManager() { return lifecycleManager.getSystemCapabilityManager((SdlManager) this); } @@ -445,8 +484,8 @@ abstract class BaseSdlManager { * @return RegisterAppInterfaceResponse received from the module or null if the app has not yet * registered with the module. */ - public RegisterAppInterfaceResponse getRegisterAppInterfaceResponse(){ - if(lifecycleManager != null){ + public RegisterAppInterfaceResponse getRegisterAppInterfaceResponse() { + if (lifecycleManager != null) { return lifecycleManager.getRegisterAppInterfaceResponse(); } return null; @@ -454,10 +493,11 @@ abstract class BaseSdlManager { /** * Get the current OnHMIStatus + * * @return OnHMIStatus object represents the current OnHMIStatus */ - public OnHMIStatus getCurrentHMIStatus(){ - if(this.lifecycleManager !=null ){ + public OnHMIStatus getCurrentHMIStatus() { + if (this.lifecycleManager != null) { return lifecycleManager.getCurrentHMIStatus(); } return null; @@ -466,9 +506,10 @@ abstract class BaseSdlManager { /** * Retrieves the auth token, if any, that was attached to the StartServiceACK for the RPC * service from the module. For example, this should be used to login to a user account. + * * @return the string representation of the auth token */ - public String getAuthToken(){ + public String getAuthToken() { return this.lifecycleManager.getAuthToken(); } @@ -476,6 +517,7 @@ abstract class BaseSdlManager { /** * Send RPC Message <br> + * * @param message RPCMessage */ public void sendRPC(RPCMessage message) { @@ -490,14 +532,14 @@ abstract class BaseSdlManager { * * <strong>ADDITIONAL NOTE: This only takes the type of RPCRequest for now, notifications and responses will be thrown out</strong> * - * @param rpcs is the list of RPCMessages being sent + * @param rpcs is the list of RPCMessages being sent * @param listener listener for updates and completions */ - public void sendSequentialRPCs(final List<? extends RPCMessage> rpcs, final OnMultipleRequestListener listener){ + public void sendSequentialRPCs(final List<? extends RPCMessage> rpcs, final OnMultipleRequestListener listener) { List<RPCRequest> rpcRequestList = new ArrayList<>(); for (int i = 0; i < rpcs.size(); i++) { - if (rpcs.get(i) instanceof RPCRequest){ - rpcRequestList.add((RPCRequest)rpcs.get(i)); + if (rpcs.get(i) instanceof RPCRequest) { + rpcRequestList.add((RPCRequest) rpcs.get(i)); } } @@ -514,51 +556,55 @@ abstract class BaseSdlManager { * * <strong>ADDITIONAL NOTE: This only takes the type of RPCRequest for now, notifications and responses will be thrown out</strong> * - * @param rpcs is the list of RPCMessages being sent + * @param rpcs is the list of RPCMessages being sent * @param listener listener for updates and completions */ public void sendRPCs(List<? extends RPCMessage> rpcs, final OnMultipleRequestListener listener) { List<RPCRequest> rpcRequestList = new ArrayList<>(); for (int i = 0; i < rpcs.size(); i++) { - if (rpcs.get(i) instanceof RPCRequest){ - rpcRequestList.add((RPCRequest)rpcs.get(i)); + if (rpcs.get(i) instanceof RPCRequest) { + rpcRequestList.add((RPCRequest) rpcs.get(i)); } } if (rpcRequestList.size() > 0) { - _internalInterface.sendRPCs(rpcRequestList,listener); + _internalInterface.sendRPCs(rpcRequestList, listener); } } /** * Add an OnRPCNotificationListener + * * @param listener listener that will be called when a notification is received */ - public void addOnRPCNotificationListener(FunctionID notificationId, OnRPCNotificationListener listener){ - _internalInterface.addOnRPCNotificationListener(notificationId,listener); + public void addOnRPCNotificationListener(FunctionID notificationId, OnRPCNotificationListener listener) { + _internalInterface.addOnRPCNotificationListener(notificationId, listener); } /** * Remove an OnRPCNotificationListener + * * @param listener listener that was previously added */ - public void removeOnRPCNotificationListener(FunctionID notificationId, OnRPCNotificationListener listener){ + public void removeOnRPCNotificationListener(FunctionID notificationId, OnRPCNotificationListener listener) { _internalInterface.removeOnRPCNotificationListener(notificationId, listener); } /** * Add an OnRPCRequestListener + * * @param listener listener that will be called when a request is received */ - public void addOnRPCRequestListener(FunctionID requestId, OnRPCRequestListener listener){ - _internalInterface.addOnRPCRequestListener(requestId,listener); + public void addOnRPCRequestListener(FunctionID requestId, OnRPCRequestListener listener) { + _internalInterface.addOnRPCRequestListener(requestId, listener); } /** * Remove an OnRPCRequestListener + * * @param listener listener that was previously added */ - public void removeOnRPCRequestListener(FunctionID requestId, OnRPCRequestListener listener){ + public void removeOnRPCRequestListener(FunctionID requestId, OnRPCRequestListener listener) { _internalInterface.removeOnRPCRequestListener(requestId, listener); } @@ -572,26 +618,30 @@ abstract class BaseSdlManager { setAppName(appName); setManagerListener(listener); } + /** * Sets the App ID + * * @param appId String representation of the App ID retreived from the SDL Developer Portal */ - public Builder setAppId(@NonNull final String appId){ + public Builder setAppId(@NonNull final String appId) { sdlManager.appId = appId; return this; } /** * Sets the Application Name + * * @param appName String that will be associated as the app's name */ - public Builder setAppName(@NonNull final String appName){ + public Builder setAppName(@NonNull final String appName) { sdlManager.appName = appName; return this; } /** * Sets the Short Application Name + * * @param shortAppName a shorter representation of the app's name for smaller displays */ public Builder setShortAppName(final String shortAppName) { @@ -603,6 +653,7 @@ abstract class BaseSdlManager { * Sets the minimum protocol version that will be permitted to connect. * If the protocol version of the head unit connected is below this version, * the app will disconnect with an EndService protocol message and will not register. + * * @param minimumProtocolVersion the minimum Protocol spec version that should be accepted */ public Builder setMinimumProtocolVersion(final Version minimumProtocolVersion) { @@ -613,6 +664,7 @@ abstract class BaseSdlManager { /** * The minimum RPC version that will be permitted to connect. * If the RPC version of the head unit connected is below this version, an UnregisterAppInterface will be sent. + * * @param minimumRPCVersion the minimum RPC spec version that should be accepted */ public Builder setMinimumRPCVersion(final Version minimumRPCVersion) { @@ -622,9 +674,10 @@ abstract class BaseSdlManager { /** * Sets the Language of the App + * * @param hmiLanguage the desired language to be used on the display/HMI of the connected module */ - public Builder setLanguage(final Language hmiLanguage){ + public Builder setLanguage(final Language hmiLanguage) { sdlManager.hmiLanguage = hmiLanguage; sdlManager.language = hmiLanguage; return this; @@ -632,30 +685,33 @@ abstract class BaseSdlManager { /** * Sets the TemplateColorScheme for daytime + * * @param dayColorScheme color scheme that will be used (if supported) when the display is in a "Day Mode" or * similar. Should comprise of colors that contrast well during the day under sunlight. */ - public Builder setDayColorScheme(final TemplateColorScheme dayColorScheme){ + public Builder setDayColorScheme(final TemplateColorScheme dayColorScheme) { sdlManager.dayColorScheme = dayColorScheme; return this; } /** * Sets the TemplateColorScheme for nighttime + * * @param nightColorScheme color scheme that will be used (if supported) when the display is in a "Night Mode" * or similar. Should comprise of colors that contrast well during the night and are not * brighter than average. */ - public Builder setNightColorScheme(final TemplateColorScheme nightColorScheme){ + public Builder setNightColorScheme(final TemplateColorScheme nightColorScheme) { sdlManager.nightColorScheme = nightColorScheme; return this; } /** * Sets the icon for the app on head unit / In-Vehicle-Infotainment system <br> + * * @param sdlArtwork the icon that will be used to represent this application on the connected module */ - public Builder setAppIcon(final SdlArtwork sdlArtwork){ + public Builder setAppIcon(final SdlArtwork sdlArtwork) { sdlManager.appIcon = sdlArtwork; return this; } @@ -663,10 +719,11 @@ abstract class BaseSdlManager { /** * Sets the vector of AppHMIType <br> * <strong>Note: This should be an ordered list from most -> least relevant</strong> + * * @param hmiTypes HMI types that represent this application. For example, if the app is a music player, the * MEDIA HMIType should be included. */ - public Builder setAppTypes(final Vector<AppHMIType> hmiTypes){ + public Builder setAppTypes(final Vector<AppHMIType> hmiTypes) { sdlManager.hmiTypes = hmiTypes; if (hmiTypes != null) { @@ -680,15 +737,17 @@ abstract class BaseSdlManager { * Sets the FileManagerConfig for the session.<br> * <strong>Note: If not set, the default configuration value of 1 will be set for * artworkRetryCount and fileRetryCount in FileManagerConfig</strong> + * * @param fileManagerConfig - configuration options */ - public Builder setFileManagerConfig (final FileManagerConfig fileManagerConfig){ + public Builder setFileManagerConfig(final FileManagerConfig fileManagerConfig) { sdlManager.fileManagerConfig = fileManagerConfig; return this; } /** * Sets the voice recognition synonyms that can be used to identify this application. + * * @param vrSynonyms a vector of Strings that can be associated with this app. For example the app's name should * be included as well as any phonetic spellings of the app name that might help the on-board * VR system associated a users spoken word with the supplied synonyms. @@ -701,6 +760,7 @@ abstract class BaseSdlManager { /** * Sets the Text-To-Speech Name of the application. These TTSChunks might be used by the module as an audio * representation of the app's name. + * * @param ttsChunks the TTS chunks that can represent this app's name */ public Builder setTtsName(final Vector<TTSChunk> ttsChunks) { @@ -711,15 +771,17 @@ abstract class BaseSdlManager { /** * This Object type may change with the transport refactor * Sets the BaseTransportConfig + * * @param transport the type of transport that should be used for this SdlManager instance. */ - public Builder setTransportType(@NonNull BaseTransportConfig transport){ + public Builder setTransportType(@NonNull BaseTransportConfig transport) { sdlManager.transport = transport; return this; } /** * Sets the Security libraries + * * @param secList The list of security class(es) */ @Deprecated @@ -730,7 +792,8 @@ abstract class BaseSdlManager { /** * Sets the security libraries and a callback to notify caller when there is update to encryption service - * @param secList The list of security class(es) + * + * @param secList The list of security class(es) * @param listener The callback object */ public Builder setSdlSecurity(@NonNull List<Class<? extends SdlSecurityBase>> secList, ServiceEncryptionListener listener) { @@ -741,19 +804,21 @@ abstract class BaseSdlManager { /** * Set the SdlManager Listener + * * @param listener the listener */ - public Builder setManagerListener(@NonNull final SdlManagerListener listener){ + public Builder setManagerListener(@NonNull final SdlManagerListener listener) { sdlManager.managerListener = listener; return this; } /** * Set RPCNotification listeners. SdlManager will preload these listeners before any RPCs are sent/received. + * * @param listeners a map of listeners that will be called when a notification is received. - * Key represents the FunctionID of the notification and value represents the listener + * Key represents the FunctionID of the notification and value represents the listener */ - public Builder setRPCNotificationListeners(Map<FunctionID, OnRPCNotificationListener> listeners){ + public Builder setRPCNotificationListeners(Map<FunctionID, OnRPCNotificationListener> listeners) { sdlManager.onRPCNotificationListeners = listeners; return this; } @@ -777,21 +842,21 @@ abstract class BaseSdlManager { sdlManager.hmiTypes = hmiTypesDefault; sdlManager.isMediaApp = false; } - if(sdlManager.fileManagerConfig == null){ + if (sdlManager.fileManagerConfig == null) { //if FileManagerConfig is not set use default sdlManager.fileManagerConfig = new FileManagerConfig(); } - if (sdlManager.hmiLanguage == null){ + if (sdlManager.hmiLanguage == null) { sdlManager.hmiLanguage = Language.EN_US; sdlManager.language = Language.EN_US; } - if (sdlManager.minimumProtocolVersion == null){ + if (sdlManager.minimumProtocolVersion == null) { sdlManager.minimumProtocolVersion = new Version("1.0.0"); } - if (sdlManager.minimumRPCVersion == null){ + if (sdlManager.minimumRPCVersion == null) { sdlManager.minimumRPCVersion = new Version("1.0.0"); } diff --git a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java index 4a12c18c1..0054b7810 100644 --- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java @@ -111,7 +111,7 @@ abstract class BaseLifecycleManager { UNREGISTER_APP_INTERFACE_CORRELATION_ID = 65530; // Sdl Synchronization Objects - private static final Object RPC_LISTENER_LOCK = new Object(), + private static final Object RPC_LISTENER_LOCK = new Object(), ON_UPDATE_LISTENER_LOCK = new Object(), ON_REQUEST_LISTENER_LOCK = new Object(), ON_NOTIFICATION_LISTENER_LOCK = new Object(); @@ -135,7 +135,7 @@ abstract class BaseLifecycleManager { Version minimumRPCVersion; BaseTransportConfig _transportConfig; - BaseLifecycleManager(AppConfig appConfig, BaseTransportConfig config, LifecycleListener listener){ + BaseLifecycleManager(AppConfig appConfig, BaseTransportConfig config, LifecycleListener listener) { this.appConfig = appConfig; this._transportConfig = config; this.lifecycleListener = listener; @@ -144,7 +144,7 @@ abstract class BaseLifecycleManager { initializeProxy(); } - public void start(){ + public void start() { try { session.startSession(); } catch (SdlException e) { @@ -161,7 +161,7 @@ abstract class BaseLifecycleManager { } } - public void stop(){ + public void stop() { session.close(); } @@ -172,11 +172,11 @@ abstract class BaseLifecycleManager { return new Version(1, 0, 0); } - private void sendRPCs(List<? extends RPCMessage> messages, final OnMultipleRequestListener listener){ - if(messages != null ){ - for(RPCMessage message : messages){ + private void sendRPCs(List<? extends RPCMessage> messages, final OnMultipleRequestListener listener) { + if (messages != null) { + for (RPCMessage message : messages) { // Request Specifics - if(message instanceof RPCRequest){ + if (message instanceof RPCRequest) { RPCRequest request = ((RPCRequest) message); final OnRPCResponseListener devOnRPCResponseListener = request.getOnRPCResponseListener(); request.setCorrelationID(CorrelationIdGenerator.generateId()); @@ -185,7 +185,7 @@ abstract class BaseLifecycleManager { request.setOnRPCResponseListener(new OnRPCResponseListener() { @Override public void onResponse(int correlationId, RPCResponse response) { - if (devOnRPCResponseListener != null){ + if (devOnRPCResponseListener != null) { devOnRPCResponseListener.onResponse(correlationId, response); } if (listener.getSingleRpcResponseListener() != null) { @@ -196,7 +196,7 @@ abstract class BaseLifecycleManager { @Override public void onError(int correlationId, Result resultCode, String info) { super.onError(correlationId, resultCode, info); - if (devOnRPCResponseListener != null){ + if (devOnRPCResponseListener != null) { devOnRPCResponseListener.onError(correlationId, resultCode, info); } if (listener.getSingleRpcResponseListener() != null) { @@ -206,12 +206,12 @@ abstract class BaseLifecycleManager { }); } sendRPCMessagePrivate(request, false); - }else { + } else { // Notifications and Responses sendRPCMessagePrivate(message, false); - if (listener != null){ + if (listener != null) { listener.onUpdate(messages.size()); - if (messages.size() == 0){ + if (messages.size() == 0) { listener.onFinished(); } } @@ -220,11 +220,11 @@ abstract class BaseLifecycleManager { } } - private void sendSequentialRPCs(final List<? extends RPCMessage> messages, final OnMultipleRequestListener listener){ - if (messages != null){ + private void sendSequentialRPCs(final List<? extends RPCMessage> messages, final OnMultipleRequestListener listener) { + if (messages != null) { // Break out of recursion, we have finished the requests if (messages.size() == 0) { - if(listener != null){ + if (listener != null) { listener.onFinished(); } return; @@ -242,7 +242,7 @@ abstract class BaseLifecycleManager { request.setOnRPCResponseListener(new OnRPCResponseListener() { @Override public void onResponse(int correlationId, RPCResponse response) { - if (devOnRPCResponseListener != null){ + if (devOnRPCResponseListener != null) { devOnRPCResponseListener.onResponse(correlationId, response); } if (listener != null) { @@ -255,7 +255,7 @@ abstract class BaseLifecycleManager { @Override public void onError(int correlationId, Result resultCode, String info) { - if (devOnRPCResponseListener != null){ + if (devOnRPCResponseListener != null) { devOnRPCResponseListener.onError(correlationId, resultCode, info); } if (listener != null) { @@ -290,17 +290,17 @@ abstract class BaseLifecycleManager { * @return the system capability manager. */ @RestrictTo(RestrictTo.Scope.LIBRARY) - public SystemCapabilityManager getSystemCapabilityManager(SdlManager sdlManager){ - if(sdlManager != null){ + public SystemCapabilityManager getSystemCapabilityManager(SdlManager sdlManager) { + if (sdlManager != null) { return systemCapabilityManager; } return null; } - private boolean isConnected(){ - if(session != null){ + private boolean isConnected() { + if (session != null) { return session.getIsConnected(); - }else{ + } else { return false; } } @@ -313,22 +313,23 @@ abstract class BaseLifecycleManager { * @return RegisterAppInterfaceResponse received from the module or null if the app has not yet * registered with the module. */ - public RegisterAppInterfaceResponse getRegisterAppInterfaceResponse(){ + public RegisterAppInterfaceResponse getRegisterAppInterfaceResponse() { return this.raiResponse; } /** * Get the current OnHMIStatus + * * @return OnHMIStatus object represents the current OnHMIStatus */ public OnHMIStatus getCurrentHMIStatus() { return currentHMIStatus; } - void onClose(String info, Exception e){ + void onClose(String info, Exception e) { Log.i(TAG, "onClose"); - if(lifecycleListener != null){ - lifecycleListener.onProxyClosed((LifecycleManager) this, info,e,null); + if (lifecycleListener != null) { + lifecycleListener.onProxyClosed((LifecycleManager) this, info, e, null); } } @@ -351,7 +352,7 @@ abstract class BaseLifecycleManager { ********************************** INTERNAL - RPC LISTENERS !! START !! ********************************* *********************************************************************************************************/ - private void setupInternalRpcListeners(){ + private void setupInternalRpcListeners() { addRpcListener(FunctionID.REGISTER_APP_INTERFACE, rpcListener); addRpcListener(FunctionID.ON_HMI_STATUS, rpcListener); addRpcListener(FunctionID.ON_HASH_CHANGE, rpcListener); @@ -413,7 +414,7 @@ abstract class BaseLifecycleManager { } }; handleOffboardTransmissionThread.start(); - }else if (onSystemRequest.getRequestType() == RequestType.ICON_URL && onSystemRequest.getUrl() != null) { + } else if (onSystemRequest.getRequestType() == RequestType.ICON_URL && onSystemRequest.getUrl() != null) { //Download the icon file and send SystemRequest RPC Thread handleOffBoardTransmissionThread = new Thread() { @Override @@ -443,7 +444,7 @@ abstract class BaseLifecycleManager { if (!onAppInterfaceUnregistered.getReason().equals(AppInterfaceUnregisteredReason.LANGUAGE_CHANGE)) { Log.v(TAG, "on app interface unregistered"); cleanProxy(); - }else{ + } else { Log.v(TAG, "re-registering for language change"); processLanguageChange(); } @@ -457,10 +458,9 @@ abstract class BaseLifecycleManager { } - }; - private void processLanguageChange(){ + private void processLanguageChange() { if (session != null) { if (session.getIsConnected()) { session.close(); @@ -482,15 +482,15 @@ abstract class BaseLifecycleManager { ********************************** METHODS - RPC LISTENERS !! START !! ********************************** *********************************************************************************************************/ - private boolean onRPCReceived(final RPCMessage message){ - synchronized(RPC_LISTENER_LOCK){ - if(message == null || message.getFunctionID() == null){ + private boolean onRPCReceived(final RPCMessage message) { + synchronized (RPC_LISTENER_LOCK) { + if (message == null || message.getFunctionID() == null) { return false; } final int id = message.getFunctionID().getId(); CopyOnWriteArrayList<OnRPCListener> listeners = rpcListeners.get(id); - if(listeners!=null && listeners.size()>0) { + if (listeners != null && listeners.size() > 0) { for (OnRPCListener listener : listeners) { listener.onReceived(message); } @@ -500,8 +500,8 @@ abstract class BaseLifecycleManager { } } - private void addRpcListener(FunctionID id, OnRPCListener listener){ - synchronized(RPC_LISTENER_LOCK){ + private void addRpcListener(FunctionID id, OnRPCListener listener) { + synchronized (RPC_LISTENER_LOCK) { if (id != null && listener != null) { if (!rpcListeners.containsKey(id.getId())) { rpcListeners.put(id.getId(), new CopyOnWriteArrayList<OnRPCListener>()); @@ -512,12 +512,12 @@ abstract class BaseLifecycleManager { } } - private boolean removeOnRPCListener(FunctionID id, OnRPCListener listener){ - synchronized(RPC_LISTENER_LOCK){ - if(rpcListeners!= null + private boolean removeOnRPCListener(FunctionID id, OnRPCListener listener) { + synchronized (RPC_LISTENER_LOCK) { + if (rpcListeners != null && id != null && listener != null - && rpcListeners.containsKey(id.getId())){ + && rpcListeners.containsKey(id.getId())) { return rpcListeners.get(id.getId()).remove(listener); } } @@ -526,16 +526,17 @@ abstract class BaseLifecycleManager { /** * Only call this method for a PutFile response. It will cause a class cast exception if not. + * * @param correlationId correlation id of the packet being updated - * @param bytesWritten how many bytes were written - * @param totalSize the total size in bytes + * @param bytesWritten how many bytes were written + * @param totalSize the total size in bytes */ @SuppressWarnings("unused") - private void onPacketProgress(int correlationId, long bytesWritten, long totalSize){ - synchronized(ON_UPDATE_LISTENER_LOCK){ - if(rpcResponseListeners !=null - && rpcResponseListeners.containsKey(correlationId)){ - ((OnPutFileUpdateListener)rpcResponseListeners.get(correlationId)).onUpdate(correlationId, bytesWritten, totalSize); + private void onPacketProgress(int correlationId, long bytesWritten, long totalSize) { + synchronized (ON_UPDATE_LISTENER_LOCK) { + if (rpcResponseListeners != null + && rpcResponseListeners.containsKey(correlationId)) { + ((OnPutFileUpdateListener) rpcResponseListeners.get(correlationId)).onUpdate(correlationId, bytesWritten, totalSize); } } @@ -544,19 +545,20 @@ abstract class BaseLifecycleManager { /** * Will provide callback to the listener either onFinish or onError depending on the RPCResponses result code, * <p>Will automatically remove the listener for the list of listeners on completion. + * * @param msg The RPCResponse message that was received * @return if a listener was called or not */ @SuppressWarnings("UnusedReturnValue") - private boolean onRPCResponseReceived(RPCResponse msg){ - synchronized(ON_UPDATE_LISTENER_LOCK){ + private boolean onRPCResponseReceived(RPCResponse msg) { + synchronized (ON_UPDATE_LISTENER_LOCK) { int correlationId = msg.getCorrelationID(); - if(rpcResponseListeners !=null - && rpcResponseListeners.containsKey(correlationId)){ + if (rpcResponseListeners != null + && rpcResponseListeners.containsKey(correlationId)) { OnRPCResponseListener listener = rpcResponseListeners.get(correlationId); - if(msg.getSuccess()){ + if (msg.getSuccess()) { listener.onResponse(correlationId, msg); - }else{ + } else { listener.onError(correlationId, msg.getResultCode(), msg.getInfo()); } rpcResponseListeners.remove(correlationId); @@ -568,16 +570,17 @@ abstract class BaseLifecycleManager { /** * Add a listener that will receive the response to the specific RPCRequest sent with the corresponding correlation id - * @param listener that will get called back when a response is received + * + * @param listener that will get called back when a response is received * @param correlationId of the RPCRequest that was sent - * @param totalSize only include if this is an OnPutFileUpdateListener. Otherwise it will be ignored. + * @param totalSize only include if this is an OnPutFileUpdateListener. Otherwise it will be ignored. */ - private void addOnRPCResponseListener(OnRPCResponseListener listener,int correlationId, int totalSize){ - synchronized(ON_UPDATE_LISTENER_LOCK){ - if(rpcResponseListeners!=null - && listener !=null){ - if(listener.getListenerType() == OnRPCResponseListener.UPDATE_LISTENER_TYPE_PUT_FILE){ - ((OnPutFileUpdateListener)listener).setTotalSize(totalSize); + private void addOnRPCResponseListener(OnRPCResponseListener listener, int correlationId, int totalSize) { + synchronized (ON_UPDATE_LISTENER_LOCK) { + if (rpcResponseListeners != null + && listener != null) { + if (listener.getListenerType() == OnRPCResponseListener.UPDATE_LISTENER_TYPE_PUT_FILE) { + ((OnPutFileUpdateListener) listener).setTotalSize(totalSize); } listener.onStart(correlationId); rpcResponseListeners.put(correlationId, listener); @@ -586,8 +589,8 @@ abstract class BaseLifecycleManager { } @SuppressWarnings("unused") - private HashMap<Integer, OnRPCResponseListener> getResponseListeners(){ - synchronized(ON_UPDATE_LISTENER_LOCK){ + private HashMap<Integer, OnRPCResponseListener> getResponseListeners() { + synchronized (ON_UPDATE_LISTENER_LOCK) { return this.rpcResponseListeners; } } @@ -595,22 +598,23 @@ abstract class BaseLifecycleManager { /** * Retrieves the auth token, if any, that was attached to the StartServiceACK for the RPC * service from the module. For example, this should be used to login to a user account. + * * @return the string representation of the auth token */ - public String getAuthToken(){ + public String getAuthToken() { return this.authToken; } @SuppressWarnings("UnusedReturnValue") - private boolean onRPCNotificationReceived(RPCNotification notification){ - if(notification == null){ + private boolean onRPCNotificationReceived(RPCNotification notification) { + if (notification == null) { DebugTool.logError("onRPCNotificationReceived - Notification was null"); return false; } - DebugTool.logInfo("onRPCNotificationReceived - " + notification.getFunctionName() ); + DebugTool.logInfo("onRPCNotificationReceived - " + notification.getFunctionName()); //Before updating any listeners, make sure to do any final updates to the notification RPC now - if(FunctionID.ON_HMI_STATUS.toString().equals(notification.getFunctionName())){ + if (FunctionID.ON_HMI_STATUS.toString().equals(notification.getFunctionName())) { OnHMIStatus onHMIStatus = (OnHMIStatus) notification; onHMIStatus.setFirstRun(firstTimeFull); if (onHMIStatus.getHmiLevel() == HMILevel.HMI_FULL) { @@ -618,9 +622,9 @@ abstract class BaseLifecycleManager { } } - synchronized(ON_NOTIFICATION_LISTENER_LOCK){ + synchronized (ON_NOTIFICATION_LISTENER_LOCK) { CopyOnWriteArrayList<OnRPCNotificationListener> listeners = rpcNotificationListeners.get(FunctionID.getFunctionId(notification.getFunctionName())); - if(listeners!=null && listeners.size()>0) { + if (listeners != null && listeners.size() > 0) { for (OnRPCNotificationListener listener : listeners) { listener.onNotified(notification); } @@ -633,27 +637,28 @@ abstract class BaseLifecycleManager { /** * This will add a listener for the specific type of notification. As of now it will only allow * a single listener per notification function id + * * @param notificationId The notification type that this listener is designated for - * @param listener The listener that will be called when a notification of the provided type is received + * @param listener The listener that will be called when a notification of the provided type is received */ @SuppressWarnings("unused") - private void addOnRPCNotificationListener(FunctionID notificationId, OnRPCNotificationListener listener){ - synchronized(ON_NOTIFICATION_LISTENER_LOCK){ - if(notificationId != null && listener != null){ - if(!rpcNotificationListeners.containsKey(notificationId.getId())){ - rpcNotificationListeners.put(notificationId.getId(),new CopyOnWriteArrayList<OnRPCNotificationListener>()); + private void addOnRPCNotificationListener(FunctionID notificationId, OnRPCNotificationListener listener) { + synchronized (ON_NOTIFICATION_LISTENER_LOCK) { + if (notificationId != null && listener != null) { + if (!rpcNotificationListeners.containsKey(notificationId.getId())) { + rpcNotificationListeners.put(notificationId.getId(), new CopyOnWriteArrayList<OnRPCNotificationListener>()); } rpcNotificationListeners.get(notificationId.getId()).add(listener); } } } - private boolean removeOnRPCNotificationListener(FunctionID notificationId, OnRPCNotificationListener listener){ - synchronized(ON_NOTIFICATION_LISTENER_LOCK){ - if(rpcNotificationListeners!= null + private boolean removeOnRPCNotificationListener(FunctionID notificationId, OnRPCNotificationListener listener) { + synchronized (ON_NOTIFICATION_LISTENER_LOCK) { + if (rpcNotificationListeners != null && notificationId != null && listener != null - && rpcNotificationListeners.containsKey(notificationId.getId())){ + && rpcNotificationListeners.containsKey(notificationId.getId())) { return rpcNotificationListeners.get(notificationId.getId()).remove(listener); } } @@ -661,16 +666,16 @@ abstract class BaseLifecycleManager { } @SuppressWarnings("UnusedReturnValue") - private boolean onRPCRequestReceived(RPCRequest request){ - if(request == null){ + private boolean onRPCRequestReceived(RPCRequest request) { + if (request == null) { DebugTool.logError("onRPCRequestReceived - request was null"); return false; } - DebugTool.logInfo("onRPCRequestReceived - " + request.getFunctionName() ); + DebugTool.logInfo("onRPCRequestReceived - " + request.getFunctionName()); - synchronized(ON_REQUEST_LISTENER_LOCK){ + synchronized (ON_REQUEST_LISTENER_LOCK) { CopyOnWriteArrayList<OnRPCRequestListener> listeners = rpcRequestListeners.get(FunctionID.getFunctionId(request.getFunctionName())); - if(listeners!=null && listeners.size()>0) { + if (listeners != null && listeners.size() > 0) { for (OnRPCRequestListener listener : listeners) { listener.onRequest(request); } @@ -683,15 +688,16 @@ abstract class BaseLifecycleManager { /** * This will add a listener for the specific type of request. As of now it will only allow * a single listener per request function id + * * @param requestId The request type that this listener is designated for - * @param listener The listener that will be called when a request of the provided type is received + * @param listener The listener that will be called when a request of the provided type is received */ @SuppressWarnings("unused") - private void addOnRPCRequestListener(FunctionID requestId, OnRPCRequestListener listener){ - synchronized(ON_REQUEST_LISTENER_LOCK){ - if(requestId != null && listener != null){ - if(!rpcRequestListeners.containsKey(requestId.getId())){ - rpcRequestListeners.put(requestId.getId(),new CopyOnWriteArrayList<OnRPCRequestListener>()); + private void addOnRPCRequestListener(FunctionID requestId, OnRPCRequestListener listener) { + synchronized (ON_REQUEST_LISTENER_LOCK) { + if (requestId != null && listener != null) { + if (!rpcRequestListeners.containsKey(requestId.getId())) { + rpcRequestListeners.put(requestId.getId(), new CopyOnWriteArrayList<OnRPCRequestListener>()); } rpcRequestListeners.get(requestId.getId()).add(listener); } @@ -699,12 +705,12 @@ abstract class BaseLifecycleManager { } @SuppressWarnings("UnusedReturnValue") - private boolean removeOnRPCRequestListener(FunctionID requestId, OnRPCRequestListener listener){ - synchronized(ON_REQUEST_LISTENER_LOCK){ - if(rpcRequestListeners!= null + private boolean removeOnRPCRequestListener(FunctionID requestId, OnRPCRequestListener listener) { + synchronized (ON_REQUEST_LISTENER_LOCK) { + if (rpcRequestListeners != null && requestId != null && listener != null - && rpcRequestListeners.containsKey(requestId.getId())){ + && rpcRequestListeners.containsKey(requestId.getId())) { return rpcRequestListeners.get(requestId.getId()).remove(listener); } } @@ -715,7 +721,7 @@ abstract class BaseLifecycleManager { **************************************** RPC LISTENERS !! END !! **************************************** *********************************************************************************************************/ - private void sendRPCMessagePrivate(RPCMessage message, boolean isInternalMessage){ + private void sendRPCMessagePrivate(RPCMessage message, boolean isInternalMessage) { try { if (!isInternalMessage && message.getMessageType().equals(RPCMessage.KEY_REQUEST)) { RPCRequest request = (RPCRequest) message; @@ -741,7 +747,7 @@ abstract class BaseLifecycleManager { //FIXME this is temporary until the next major release of the library where OK is removed if (message.getMessageType().equals(RPCMessage.KEY_REQUEST)) { RPCRequest request = (RPCRequest) message; - if(FunctionID.SUBSCRIBE_BUTTON.toString().equals(request.getFunctionName()) + if (FunctionID.SUBSCRIBE_BUTTON.toString().equals(request.getFunctionName()) || FunctionID.UNSUBSCRIBE_BUTTON.toString().equals(request.getFunctionName()) || FunctionID.BUTTON_PRESS.toString().equals(request.getFunctionName())) { @@ -768,12 +774,12 @@ abstract class BaseLifecycleManager { } } - message.format(rpcSpecVersion,true); - byte[] msgBytes = JsonRPCMarshaller.marshall(message, (byte)getProtocolVersion().getMajor()); + message.format(rpcSpecVersion, true); + byte[] msgBytes = JsonRPCMarshaller.marshall(message, (byte) getProtocolVersion().getMajor()); final ProtocolMessage pm = new ProtocolMessage(); pm.setData(msgBytes); - if (session != null){ + if (session != null) { pm.setSessionID(session.getSessionId()); } @@ -786,36 +792,36 @@ abstract class BaseLifecycleManager { } else { pm.setPayloadProtected(message.isPayloadProtected()); } - if (pm.getPayloadProtected() && (encryptionLifecycleManager == null || !encryptionLifecycleManager.isEncryptionReady())){ + if (pm.getPayloadProtected() && (encryptionLifecycleManager == null || !encryptionLifecycleManager.isEncryptionReady())) { String errorInfo = "Trying to send an encrypted message and there is no secured service"; if (message.getMessageType().equals((RPCMessage.KEY_REQUEST))) { RPCRequest request = (RPCRequest) message; OnRPCResponseListener listener = ((RPCRequest) message).getOnRPCResponseListener(); if (listener != null) { - listener.onError(request.getCorrelationID(), Result.ABORTED, errorInfo); + listener.onError(request.getCorrelationID(), Result.ABORTED, errorInfo); } } DebugTool.logWarning(errorInfo); return; } - if(RPCMessage.KEY_REQUEST.equals(message.getMessageType())){ // Request Specifics - pm.setRPCType((byte)0x00); - Integer corrId = ((RPCRequest)message).getCorrelationID(); - if( corrId== null) { + if (RPCMessage.KEY_REQUEST.equals(message.getMessageType())) { // Request Specifics + pm.setRPCType((byte) 0x00); + Integer corrId = ((RPCRequest) message).getCorrelationID(); + if (corrId == null) { Log.e(TAG, "No correlation ID attached to request. Not sending"); return; - }else{ + } else { pm.setCorrID(corrId); - OnRPCResponseListener listener = ((RPCRequest)message).getOnRPCResponseListener(); - if(listener != null){ + OnRPCResponseListener listener = ((RPCRequest) message).getOnRPCResponseListener(); + if (listener != null) { addOnRPCResponseListener(listener, corrId, msgBytes.length); } } - }else if (RPCMessage.KEY_RESPONSE.equals(message.getMessageType())){ // Response Specifics + } else if (RPCMessage.KEY_RESPONSE.equals(message.getMessageType())) { // Response Specifics RPCResponse response = (RPCResponse) message; - pm.setRPCType((byte)0x01); + pm.setRPCType((byte) 0x01); if (response.getCorrelationID() == null) { //Log error here //throw new SdlException("CorrelationID cannot be null. RPC: " + response.getFunctionName(), SdlExceptionCause.INVALID_ARGUMENT); @@ -824,15 +830,15 @@ abstract class BaseLifecycleManager { } else { pm.setCorrID(response.getCorrelationID()); } - }else if (message.getMessageType().equals(RPCMessage.KEY_NOTIFICATION)) { // Notification Specifics - pm.setRPCType((byte)0x02); + } else if (message.getMessageType().equals(RPCMessage.KEY_NOTIFICATION)) { // Notification Specifics + pm.setRPCType((byte) 0x02); } - if (message.getBulkData() != null){ + if (message.getBulkData() != null) { pm.setBulkData(message.getBulkData()); } - if(message.getFunctionName().equalsIgnoreCase(FunctionID.PUT_FILE.name())){ + if (message.getFunctionName().equalsIgnoreCase(FunctionID.PUT_FILE.name())) { pm.setPriorityCoefficient(1); } @@ -889,7 +895,7 @@ abstract class BaseLifecycleManager { FunctionID functionID = rpc.getFunctionID(); if (functionID != null && (functionID.equals(FunctionID.ON_BUTTON_PRESS)) || functionID.equals(FunctionID.ON_BUTTON_EVENT)) { RPCNotification notificationCompat = handleButtonNotificationFormatting(rpc); - if(notificationCompat != null){ + if (notificationCompat != null) { onRPCNotificationReceived((notificationCompat)); } } @@ -1159,15 +1165,19 @@ abstract class BaseLifecycleManager { ********************************************* ISdl - END ************************************************ *********************************************************************************************************/ - public interface LifecycleListener{ + public interface LifecycleListener { void onProxyConnected(LifecycleManager lifeCycleManager); + void onProxyClosed(LifecycleManager lifeCycleManager, String info, Exception e, SdlDisconnectedReason reason); + void onServiceStarted(SessionType sessionType); + void onServiceEnded(SessionType sessionType); + void onError(LifecycleManager lifeCycleManager, String info, Exception e); } - public static class AppConfig{ + public static class AppConfig { private String appID, appName, ngnMediaScreenAppName; private Vector<TTSChunk> ttsName; private Vector<String> vrSynonyms; @@ -1178,7 +1188,7 @@ abstract class BaseLifecycleManager { private Version minimumProtocolVersion; private Version minimumRPCVersion; - private void prepare(){ + private void prepare() { if (getNgnMediaScreenAppName() == null) { setNgnMediaScreenAppName(getAppName()); } @@ -1318,22 +1328,23 @@ abstract class BaseLifecycleManager { /** * Temporary method to bridge the new PLAY_PAUSE and OKAY button functionality with the old * OK button name. This should be removed during the next major release + * * @param notification an RPC message object that should be either an ON_BUTTON_EVENT or ON_BUTTON_PRESS otherwise * it will be ignored */ - private RPCNotification handleButtonNotificationFormatting(RPCMessage notification){ - if(FunctionID.ON_BUTTON_EVENT.toString().equals(notification.getFunctionName()) - || FunctionID.ON_BUTTON_PRESS.toString().equals(notification.getFunctionName())){ + private RPCNotification handleButtonNotificationFormatting(RPCMessage notification) { + if (FunctionID.ON_BUTTON_EVENT.toString().equals(notification.getFunctionName()) + || FunctionID.ON_BUTTON_PRESS.toString().equals(notification.getFunctionName())) { - ButtonName buttonName = (ButtonName)notification.getObject(ButtonName.class, OnButtonEvent.KEY_BUTTON_NAME); + ButtonName buttonName = (ButtonName) notification.getObject(ButtonName.class, OnButtonEvent.KEY_BUTTON_NAME); ButtonName compatBtnName = null; - if(rpcSpecVersion != null && rpcSpecVersion.getMajor() >= 5){ - if(ButtonName.PLAY_PAUSE.equals(buttonName)){ - compatBtnName = ButtonName.OK; + if (rpcSpecVersion != null && rpcSpecVersion.getMajor() >= 5) { + if (ButtonName.PLAY_PAUSE.equals(buttonName)) { + compatBtnName = ButtonName.OK; } - }else{ // rpc spec version is either null or less than 5 - if(ButtonName.OK.equals(buttonName)){ + } else { // rpc spec version is either null or less than 5 + if (ButtonName.OK.equals(buttonName)) { compatBtnName = ButtonName.PLAY_PAUSE; } } @@ -1360,14 +1371,14 @@ abstract class BaseLifecycleManager { notification2.setParameters(OnButtonEvent.KEY_BUTTON_NAME, compatBtnName); return notification2; } - }catch (Exception e){ + } catch (Exception e) { //Should never get here } } return null; } - void cleanProxy(){ + void cleanProxy() { firstTimeFull = true; currentHMIStatus = null; if (rpcListeners != null) { @@ -1385,7 +1396,7 @@ abstract class BaseLifecycleManager { if (session != null && session.getIsConnected()) { session.close(); } - if (encryptionLifecycleManager != null){ + if (encryptionLifecycleManager != null) { encryptionLifecycleManager.dispose(); } } @@ -1397,7 +1408,8 @@ abstract class BaseLifecycleManager { /** * Sets the security libraries and a callback to notify caller when there is update to encryption service - * @param secList The list of security class(es) + * + * @param secList The list of security class(es) * @param listener The callback object */ public void setSdlSecurity(@NonNull List<Class<? extends SdlSecurityBase>> secList, ServiceEncryptionListener listener) { @@ -1446,7 +1458,7 @@ abstract class BaseLifecycleManager { ********************************** Platform specific methods - START ************************************* *********************************************************************************************************/ - void initializeProxy(){ + void initializeProxy() { this.rpcListeners = new HashMap<>(); this.rpcResponseListeners = new HashMap<>(); this.rpcNotificationListeners = new HashMap<>(); @@ -1455,7 +1467,7 @@ abstract class BaseLifecycleManager { setupInternalRpcListeners(); } - void onProtocolSessionStarted (SessionType sessionType) { + void onProtocolSessionStarted(SessionType sessionType) { if (sessionType != null) { if (minimumProtocolVersion != null && minimumProtocolVersion.isNewerThan(getProtocolVersion()) == 1) { Log.w(TAG, String.format("Disconnecting from head unit, the configured minimum protocol version %s is greater than the supported protocol version %s", minimumProtocolVersion, getProtocolVersion())); @@ -1497,23 +1509,34 @@ abstract class BaseLifecycleManager { } } - void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) {} + void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) { + } - void onProtocolSessionStartedNACKed (SessionType sessionType) {} + void onProtocolSessionStartedNACKed(SessionType sessionType) { + } - void onProtocolSessionEnded (SessionType sessionType) {} + void onProtocolSessionEnded(SessionType sessionType) { + } - void onProtocolSessionEndedNACKed (SessionType sessionType) {} + void onProtocolSessionEndedNACKed(SessionType sessionType) { + } - void startVideoService(boolean encrypted, VideoStreamingParameters parameters) {} + void startVideoService(boolean encrypted, VideoStreamingParameters parameters) { + } - boolean endVideoStream() { return false; } + boolean endVideoStream() { + return false; + } - void startAudioService(boolean encrypted) {} + void startAudioService(boolean encrypted) { + } - boolean endAudioStream() { return false; } + boolean endAudioStream() { + return false; + } - void setSdlSecurityStaticVars() {} + void setSdlSecurityStaticVars() { + } /* ******************************************************************************************************* ********************************** Platform specific methods - End ************************************* diff --git a/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java b/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java index cdb42dd7b..a711438cc 100644 --- a/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java +++ b/javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java @@ -44,11 +44,11 @@ import com.smartdevicelink.util.DebugTool; /** * <strong>SDLManager</strong> <br> - * + * <p> * This is the main point of contact between an application and SDL <br> - * + * <p> * It is broken down to these areas: <br> - * + * <p> * 1. SDLManagerBuilder <br> * 2. ISdl Interface along with its overridden methods - This can be passed into attached managers <br> * 3. Sending Requests <br> @@ -80,7 +80,7 @@ public class SdlManager extends BaseSdlManager { } @Override - protected void initialize(){ + protected void initialize() { // Instantiate sub managers this.permissionManager = new PermissionManager(_internalInterface); this.fileManager = new FileManager(_internalInterface, fileManagerConfig); @@ -94,14 +94,14 @@ public class SdlManager extends BaseSdlManager { @Override void checkState() { - if (permissionManager != null && fileManager != null && screenManager != null ){ - if (permissionManager.getState() == BaseSubManager.READY && fileManager.getState() == BaseSubManager.READY && screenManager.getState() == BaseSubManager.READY){ + if (permissionManager != null && fileManager != null && screenManager != null) { + if (permissionManager.getState() == BaseSubManager.READY && fileManager.getState() == BaseSubManager.READY && screenManager.getState() == BaseSubManager.READY) { DebugTool.logInfo("Starting sdl manager, all sub managers are in ready state"); transitionToState(BaseSubManager.READY); handleQueuedNotifications(); notifyDevListener(null); onReady(); - } else if (permissionManager.getState() == BaseSubManager.ERROR && fileManager.getState() == BaseSubManager.ERROR && screenManager.getState() == BaseSubManager.ERROR){ + } else if (permissionManager.getState() == BaseSubManager.ERROR && fileManager.getState() == BaseSubManager.ERROR && screenManager.getState() == BaseSubManager.ERROR) { String info = "ERROR starting sdl manager, all sub managers are in error state"; Log.e(TAG, info); transitionToState(BaseSubManager.ERROR); @@ -128,8 +128,8 @@ public class SdlManager extends BaseSdlManager { private void notifyDevListener(String info) { if (managerListener != null) { - if (getState() == BaseSubManager.ERROR){ - managerListener.onError((SdlManager)this, info, null); + if (getState() == BaseSubManager.ERROR) { + managerListener.onError((SdlManager) this, info, null); } else { managerListener.onStart((SdlManager) this); } @@ -143,8 +143,8 @@ public class SdlManager extends BaseSdlManager { @Override void onProxyClosed(SdlDisconnectedReason reason) { - Log.i(TAG,"Proxy is closed."); - if(managerListener != null){ + Log.i(TAG, "Proxy is closed."); + if (managerListener != null) { managerListener.onDestroy(SdlManager.this); } } @@ -167,8 +167,8 @@ public class SdlManager extends BaseSdlManager { this.lifecycleManager.stop(); } - if(managerListener != null){ - managerListener.onDestroy((SdlManager)this); + if (managerListener != null) { + managerListener.onDestroy((SdlManager) this); managerListener = null; } @@ -179,11 +179,12 @@ public class SdlManager extends BaseSdlManager { public static class Builder extends BaseSdlManager.Builder { /** * Builder for the SdlManager. Parameters in the constructor are required. - * @param appId the app's ID - * @param appName the app's name + * + * @param appId the app's ID + * @param appName the app's name * @param listener a SdlManagerListener object */ - public Builder(@NonNull final String appId, @NonNull final String appName, @NonNull final SdlManagerListener listener){ + public Builder(@NonNull final String appId, @NonNull final String appName, @NonNull final SdlManagerListener listener) { super(appId, appName, listener); } } |