Skip to content

Commit ffe2f08

Browse files
Merge pull request #1226 from smartdevicelink/bugfix/issue_1225
Fix #1225
2 parents 9377865 + 93da869 commit ffe2f08

3 files changed

Lines changed: 79 additions & 34 deletions

File tree

android/sdl_android/src/main/java/com/smartdevicelink/managers/SdlManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public void dispose() {
365365
this.audioStreamManager.dispose();
366366
}
367367

368-
if (this.proxy != null) {
368+
if (this.proxy != null && !proxy.isDisposed()) {
369369
try {
370370
this.proxy.dispose();
371371
} catch (SdlException e) {

android/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,8 @@ public void onProtocolSessionStarted(SessionType sessionType,
622622

623623
if (minimumProtocolVersion != null && minimumProtocolVersion.isNewerThan(getProtocolVersion()) == 1){
624624
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()));
625-
endService(sessionType);
626625
try {
627-
cleanProxy(SdlDisconnectedReason.MINIMUM_PROTOCOL_VERSION_HIGHER_THAN_SUPPORTED);
626+
disposeInternal(SdlDisconnectedReason.MINIMUM_PROTOCOL_VERSION_HIGHER_THAN_SUPPORTED);
628627
} catch (SdlException e) {
629628
e.printStackTrace();
630629
}
@@ -1748,12 +1747,8 @@ public void close() throws SdlException {
17481747

17491748
@SuppressWarnings("UnusedParameters")
17501749
private void cleanProxy(SdlDisconnectedReason disconnectedReason) throws SdlException {
1751-
if (disconnectedReason == SdlDisconnectedReason.MINIMUM_PROTOCOL_VERSION_HIGHER_THAN_SUPPORTED || disconnectedReason == SdlDisconnectedReason.MINIMUM_RPC_VERSION_HIGHER_THAN_SUPPORTED){
1752-
notifyProxyClosed(disconnectedReason.toString(), null, disconnectedReason);
1753-
sdlSession.resetSession();
1754-
}
17551750
try {
1756-
1751+
17571752
// ALM Specific Cleanup
17581753
if (_advancedLifecycleManagementEnabled) {
17591754
_sdlConnectionState = SdlConnectionState.SDL_DISCONNECTED;
@@ -1791,18 +1786,36 @@ private void cleanProxy(SdlDisconnectedReason disconnectedReason) throws SdlExce
17911786

17921787
// Clean up SDL Connection
17931788
synchronized(CONNECTION_REFERENCE_LOCK) {
1794-
if (sdlSession != null) sdlSession.close();
1789+
if (sdlSession != null) {
1790+
sdlSession.close();
1791+
}
17951792
}
17961793
} finally {
17971794
SdlTrace.logProxyEvent("SdlProxy cleaned.", SDL_LIB_TRACE_KEY);
17981795
}
17991796
}
1800-
1797+
1798+
/**
1799+
* Check to see if the proxy has already been disposed
1800+
* @return if the proxy has been disposed
1801+
*/
1802+
public synchronized boolean isDisposed(){
1803+
return _proxyDisposed;
1804+
}
1805+
18011806
/**
18021807
* Terminates the App's Interface Registration, closes the transport connection, ends the protocol session, and frees any resources used by the proxy.
18031808
*/
1804-
public void dispose() throws SdlException
1805-
{
1809+
public void dispose() throws SdlException {
1810+
SdlTrace.logProxyEvent("Application called dispose() method.", SDL_LIB_TRACE_KEY);
1811+
disposeInternal(SdlDisconnectedReason.APPLICATION_REQUESTED_DISCONNECT);
1812+
}
1813+
/**
1814+
* Terminates the App's Interface Registration, closes the transport connection, ends the protocol session, and frees any resources used by the proxy.
1815+
* @param sdlDisconnectedReason the reason the proxy should be disposed.
1816+
*/
1817+
private synchronized void disposeInternal(SdlDisconnectedReason sdlDisconnectedReason) throws SdlException
1818+
{
18061819
if (_proxyDisposed) {
18071820
throw new SdlException("This object has been disposed, it is no long capable of executing methods.", SdlExceptionCause.SDL_PROXY_DISPOSED);
18081821
}
@@ -1811,12 +1824,16 @@ public void dispose() throws SdlException
18111824
rpcSecuredServiceStarted = false;
18121825
encryptionRequiredRPCs.clear();
18131826
serviceEncryptionListener = null;
1814-
1815-
SdlTrace.logProxyEvent("Application called dispose() method.", SDL_LIB_TRACE_KEY);
1816-
1827+
18171828
try{
18181829
// Clean the proxy
1819-
cleanProxy(SdlDisconnectedReason.APPLICATION_REQUESTED_DISCONNECT);
1830+
cleanProxy(sdlDisconnectedReason);
1831+
1832+
if (sdlDisconnectedReason == SdlDisconnectedReason.MINIMUM_PROTOCOL_VERSION_HIGHER_THAN_SUPPORTED
1833+
|| sdlDisconnectedReason == SdlDisconnectedReason.MINIMUM_RPC_VERSION_HIGHER_THAN_SUPPORTED){
1834+
//We want to notify listeners for this case before disposing the dispatchers
1835+
notifyProxyClosed(sdlDisconnectedReason.toString(), null, sdlDisconnectedReason);
1836+
}
18201837

18211838
// Close IncomingProxyMessageDispatcher thread
18221839
synchronized(INCOMING_MESSAGE_QUEUE_THREAD_LOCK) {
@@ -2152,6 +2169,10 @@ public void onNotified(RPCNotification notification) {
21522169
private ISdlServiceListener securedServiceListener = new ISdlServiceListener() {
21532170
@Override
21542171
public void onServiceStarted(SdlSession session, SessionType type, boolean isEncrypted) {
2172+
if(_proxyDisposed){
2173+
DebugTool.logInfo("Ignoring start service packet, proxy is disposed");
2174+
return;
2175+
}
21552176
if(SessionType.RPC.equals(type)){
21562177
rpcSecuredServiceStarted = isEncrypted;
21572178
}
@@ -2163,6 +2184,10 @@ public void onServiceStarted(SdlSession session, SessionType type, boolean isEnc
21632184

21642185
@Override
21652186
public void onServiceEnded(SdlSession session, SessionType type) {
2187+
if(_proxyDisposed){
2188+
DebugTool.logInfo("Ignoring end service packet, proxy is disposed");
2189+
return;
2190+
}
21662191
if (SessionType.RPC.equals(type)) {
21672192
rpcSecuredServiceStarted = false;
21682193
}
@@ -2174,6 +2199,10 @@ public void onServiceEnded(SdlSession session, SessionType type) {
21742199

21752200
@Override
21762201
public void onServiceError(SdlSession session, SessionType type, String reason) {
2202+
if(_proxyDisposed){
2203+
DebugTool.logInfo("Ignoring start service error, proxy is disposed");
2204+
return;
2205+
}
21772206
if (SessionType.RPC.equals(type)) {
21782207
rpcSecuredServiceStarted = false;
21792208
}
@@ -2653,21 +2682,7 @@ private void handleRPCMessage(Hashtable<String, Object> hash) {
26532682
}else{
26542683
rpcSpecVersion = MAX_SUPPORTED_RPC_VERSION;
26552684
}
2656-
2657-
if (minimumRPCVersion != null && minimumRPCVersion.isNewerThan(rpcSpecVersion) == 1){
2658-
Log.w(TAG, String.format("Disconnecting from head unit, the configured minimum RPC version %s is greater than the supported RPC version %s", minimumRPCVersion, rpcSpecVersion));
2659-
try {
2660-
unregisterAppInterfacePrivate(UNREGISTER_APP_INTERFACE_CORRELATION_ID);
2661-
} catch (SdlException e) {
2662-
e.printStackTrace();
2663-
}
2664-
try {
2665-
cleanProxy(SdlDisconnectedReason.MINIMUM_RPC_VERSION_HIGHER_THAN_SUPPORTED);
2666-
} catch (SdlException e) {
2667-
e.printStackTrace();
2668-
}
2669-
return;
2670-
}
2685+
DebugTool.logInfo("Negotiated RPC Spec version = " + rpcSpecVersion);
26712686

26722687
_vehicleType = msg.getVehicleType();
26732688
_systemSoftwareVersion = msg.getSystemSoftwareVersion();
@@ -2714,7 +2729,19 @@ private void handleRPCMessage(Hashtable<String, Object> hash) {
27142729
notifyProxyClosed("Unable to register app interface. Review values passed to the SdlProxy constructor. RegisterAppInterface result code: ",
27152730
new SdlException("Unable to register app interface. Review values passed to the SdlProxy constructor. RegisterAppInterface result code: " + msg.getResultCode(), SdlExceptionCause.SDL_REGISTRATION_ERROR), SdlDisconnectedReason.SDL_REGISTRATION_ERROR);
27162731
}
2717-
2732+
2733+
//If the RPC version is too low we should simply dispose this proxy
2734+
if (minimumRPCVersion != null && minimumRPCVersion.isNewerThan(rpcSpecVersion) == 1) {
2735+
Log.w(TAG, String.format("Disconnecting from head unit, the configured minimum RPC version %s is greater than the supported RPC version %s", minimumRPCVersion, rpcSpecVersion));
2736+
try {
2737+
disposeInternal(SdlDisconnectedReason.MINIMUM_RPC_VERSION_HIGHER_THAN_SUPPORTED);
2738+
} catch (SdlException e) {
2739+
e.printStackTrace();
2740+
}
2741+
return;
2742+
}
2743+
2744+
27182745
if (_callbackToUIThread) {
27192746
// Run in UI thread
27202747
_mainUIHandler.post(new Runnable() {
@@ -2819,7 +2846,13 @@ else if (functionName.equals(FunctionID.UNREGISTER_APP_INTERFACE.toString())) {
28192846
_sdlLanguage = msg.getLanguage();
28202847
_hmiDisplayLanguage = msg.getHmiDisplayLanguage();
28212848
_sdlMsgVersion = msg.getSdlMsgVersion();
2822-
rpcSpecVersion = new com.smartdevicelink.util.Version(_sdlMsgVersion.getMajorVersion(),_sdlMsgVersion.getMinorVersion(), _sdlMsgVersion.getPatchVersion());
2849+
if(_sdlMsgVersion != null){
2850+
rpcSpecVersion = new com.smartdevicelink.util.Version(_sdlMsgVersion.getMajorVersion(),_sdlMsgVersion.getMinorVersion(), _sdlMsgVersion.getPatchVersion());
2851+
} else {
2852+
rpcSpecVersion = MAX_SUPPORTED_RPC_VERSION;
2853+
}
2854+
DebugTool.logInfo("Negotiated RPC Spec version = " + rpcSpecVersion);
2855+
28232856
_vehicleType = msg.getVehicleType();
28242857
_systemSoftwareVersion = msg.getSystemSoftwareVersion();
28252858
_proxyVersionInfo = BuildConfig.VERSION_NAME;
@@ -2857,6 +2890,16 @@ else if (functionName.equals(FunctionID.UNREGISTER_APP_INTERFACE.toString())) {
28572890
notifyProxyClosed("Unable to register app interface. Review values passed to the SdlProxy constructor. RegisterAppInterface result code: ",
28582891
new SdlException("Unable to register app interface. Review values passed to the SdlProxy constructor. RegisterAppInterface result code: " + msg.getResultCode(), SdlExceptionCause.SDL_REGISTRATION_ERROR), SdlDisconnectedReason.SDL_REGISTRATION_ERROR);
28592892
}
2893+
//If the RPC version is too low we should simply dispose this proxy
2894+
if (minimumRPCVersion != null && minimumRPCVersion.isNewerThan(rpcSpecVersion) == 1) {
2895+
Log.w(TAG, String.format("Disconnecting from head unit, the configured minimum RPC version %s is greater than the supported RPC version %s", minimumRPCVersion, rpcSpecVersion));
2896+
try {
2897+
disposeInternal(SdlDisconnectedReason.MINIMUM_RPC_VERSION_HIGHER_THAN_SUPPORTED);
2898+
} catch (SdlException e) {
2899+
e.printStackTrace();
2900+
}
2901+
return;
2902+
}
28602903
} else {
28612904
if (_callbackToUIThread) {
28622905
// Run in UI thread

android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ public void close(long sessionId){
120120
@Override
121121
@Deprecated
122122
public void resetSession(){
123-
transport.resetSession();
123+
if(transport != null){
124+
transport.resetSession();
125+
}
124126
}
125127

126128
/**

0 commit comments

Comments
 (0)