diff options
author | Noah Stanford <noah@livio.io> | 2022-02-14 11:05:13 -0500 |
---|---|---|
committer | Noah Stanford <noah@livio.io> | 2022-02-14 11:05:13 -0500 |
commit | 3f04ebaf36dbc566e5b1d73ca704ec32f1f0a4ff (patch) | |
tree | 94b2072ffdcb610d671eb96b3b809595a1845b37 | |
parent | 37b307fb005757a48c3fe904485b49b7db121495 (diff) | |
download | sdl_android-3f04ebaf36dbc566e5b1d73ca704ec32f1f0a4ff.tar.gz |
Create and use SESSION_LOCK object
Use SESSION_LOCK on synchronized blocks for session
2 files changed, 26 insertions, 24 deletions
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 5d872b35e..bc174819e 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 @@ -93,7 +93,7 @@ public class LifecycleManager extends BaseLifecycleManager { //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), disconnectedReason); } - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { try { session.startSession(); @@ -165,7 +165,7 @@ public class LifecycleManager extends BaseLifecycleManager { */ @Override void startVideoService(boolean isEncrypted, VideoStreamingParameters parameters, boolean afterPendingRestart) { - synchronized (session) { + synchronized (SESSION_LOCK) { if (session == null) { DebugTool.logWarning(TAG, "SdlSession is not created yet."); return; @@ -189,7 +189,7 @@ public class LifecycleManager extends BaseLifecycleManager { * @param parameters VideoStreamingParameters that are desired. Does not guarantee this is what will be accepted. */ private void tryStartVideoStream(boolean isEncrypted, VideoStreamingParameters parameters, boolean afterPendingRestart) { - synchronized (session) { + synchronized (SESSION_LOCK) { if (session == null) { DebugTool.logWarning(TAG, "SdlSession is not created yet."); return; @@ -204,7 +204,7 @@ public class LifecycleManager extends BaseLifecycleManager { return; } - synchronized (session) { + synchronized (SESSION_LOCK) { if (afterPendingRestart || !videoServiceStartResponseReceived || !videoServiceStartResponse //If we haven't started the service before || (videoServiceStartResponse && isEncrypted && !session.isServiceProtected(SessionType.NAV))) { //Or the service has been started but we'd like to start an encrypted one if (session != null) { @@ -247,7 +247,7 @@ public class LifecycleManager extends BaseLifecycleManager { } }; - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { session.addServiceListener(SessionType.NAV, videoServiceListener); } @@ -257,7 +257,7 @@ public class LifecycleManager extends BaseLifecycleManager { @Override void startAudioService(boolean isEncrypted) { - synchronized (session) { + synchronized (SESSION_LOCK) { if (session == null) { DebugTool.logWarning(TAG, "SdlSession is not created yet."); return; 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 bc1c09ed5..bf9865ca2 100644 --- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java @@ -116,6 +116,8 @@ abstract class BaseLifecycleManager { ON_UPDATE_LISTENER_LOCK = new Object(), ON_REQUEST_LISTENER_LOCK = new Object(), ON_NOTIFICATION_LISTENER_LOCK = new Object(); + protected static final Object SESSION_LOCK = new Object(); + SdlSession session; final AppConfig appConfig; @@ -151,7 +153,7 @@ abstract class BaseLifecycleManager { public void start() { try { - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { session.startSession(); } @@ -165,7 +167,7 @@ abstract class BaseLifecycleManager { * Start a secured RPC service */ public void startRPCEncryption() { - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { session.startService(SessionType.RPC, true); } @@ -173,7 +175,7 @@ abstract class BaseLifecycleManager { } public synchronized void stop() { - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { session.close(); session = null; @@ -202,7 +204,7 @@ abstract class BaseLifecycleManager { } Version getProtocolVersion() { - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null && session.getProtocolVersion() != null) { return session.getProtocolVersion(); } @@ -311,7 +313,7 @@ abstract class BaseLifecycleManager { } private boolean isConnected() { - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { return session.getIsConnected(); } else { @@ -413,7 +415,7 @@ abstract class BaseLifecycleManager { if (vehicleType != null || systemSoftwareVersion != null) { List<TransportRecord> activeTransports = null; - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { activeTransports = session.getActiveTransports(); } @@ -818,7 +820,7 @@ abstract class BaseLifecycleManager { final ProtocolMessage pm = new ProtocolMessage(); pm.setData(msgBytes); - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { pm.setSessionID((byte) session.getSessionId()); } @@ -889,7 +891,7 @@ abstract class BaseLifecycleManager { pm.setPriorityCoefficient(1); } - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { session.sendMessage(pm); } @@ -965,7 +967,7 @@ abstract class BaseLifecycleManager { DebugTool.logInfo(TAG, "on protocol session started"); if (minimumProtocolVersion != null && minimumProtocolVersion.isNewerThan(version) == 1) { DebugTool.logWarning(TAG, String.format("Disconnecting from head unit, the configured minimum protocol version %s is greater than the supported protocol version %s", minimumProtocolVersion, getProtocolVersion())); - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { session.endService(SessionType.RPC); } @@ -978,7 +980,7 @@ abstract class BaseLifecycleManager { if (systemInfo != null && lifecycleListener != null) { didCheckSystemInfo = true; List<TransportRecord> activeTransports = null; - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { activeTransports = session.getActiveTransports(); } @@ -987,7 +989,7 @@ abstract class BaseLifecycleManager { boolean validSystemInfo = lifecycleListener.onSystemInfoReceived(systemInfo); if (!validSystemInfo) { DebugTool.logWarning(TAG, "Disconnecting from head unit, the system info was not accepted."); - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { session.endService(SessionType.RPC); } @@ -1063,7 +1065,7 @@ abstract class BaseLifecycleManager { @Override public boolean isConnected() { synchronized (BaseLifecycleManager.this) { - synchronized (BaseLifecycleManager.this.session) { + synchronized (SESSION_LOCK) { if (BaseLifecycleManager.this.session != null) { return BaseLifecycleManager.this.session.getIsConnected(); } @@ -1075,7 +1077,7 @@ abstract class BaseLifecycleManager { @Override public void addServiceListener(SessionType serviceType, ISdlServiceListener sdlServiceListener) { synchronized (BaseLifecycleManager.this) { - synchronized (BaseLifecycleManager.this.session) { + synchronized (SESSION_LOCK) { if (BaseLifecycleManager.this.session != null) { BaseLifecycleManager.this.session.addServiceListener(serviceType, sdlServiceListener); } @@ -1086,7 +1088,7 @@ abstract class BaseLifecycleManager { @Override public void removeServiceListener(SessionType serviceType, ISdlServiceListener sdlServiceListener) { synchronized (BaseLifecycleManager.this) { - synchronized (BaseLifecycleManager.this.session) { + synchronized (SESSION_LOCK) { if (BaseLifecycleManager.this.session != null) { BaseLifecycleManager.this.session.removeServiceListener(serviceType, sdlServiceListener); } @@ -1159,7 +1161,7 @@ abstract class BaseLifecycleManager { @Override public boolean isTransportForServiceAvailable(SessionType serviceType) { synchronized (BaseLifecycleManager.this) { - synchronized (BaseLifecycleManager.this.session) { + synchronized (SESSION_LOCK) { if (BaseLifecycleManager.this.session != null) { return BaseLifecycleManager.this.session.isTransportForServiceAvailable(serviceType); } @@ -1191,7 +1193,7 @@ abstract class BaseLifecycleManager { @Override public long getMtu(SessionType serviceType) { synchronized (BaseLifecycleManager.this) { - synchronized (BaseLifecycleManager.this.session) { + synchronized (SESSION_LOCK) { if (BaseLifecycleManager.this.session != null) { return BaseLifecycleManager.this.session.getMtu(serviceType); } @@ -1295,7 +1297,7 @@ abstract class BaseLifecycleManager { if (rpcRequestListeners != null) { rpcRequestListeners.clear(); } - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null && session.getIsConnected()) { session.close(); } @@ -1353,7 +1355,7 @@ abstract class BaseLifecycleManager { if ((sec != null) && (sec.getMakeList() != null)) { if (sec.getMakeList().contains(make)) { sec.setAppId(appConfig.getAppID()); - synchronized (session) { + synchronized (SESSION_LOCK) { if (session != null) { session.setSdlSecurity(sec); sec.handleSdlSession(session); |