Skip to content

Commit a4cb87c

Browse files
authored
Merge pull request #1388 from smartdevicelink/feature/change_lang_reconnect
Fix app reconnection issue after language change
2 parents 6b52e38 + bdd7217 commit a4cb87c

6 files changed

Lines changed: 36 additions & 50 deletions

File tree

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.smartdevicelink.managers.screen.ScreenManager;
5050
import com.smartdevicelink.managers.video.VideoStreamManager;
5151
import com.smartdevicelink.proxy.rpc.enums.AppHMIType;
52-
import com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason;
5352
import com.smartdevicelink.transport.BaseTransportConfig;
5453
import com.smartdevicelink.transport.MultiplexTransportConfig;
5554
import com.smartdevicelink.transport.enums.TransportType;
@@ -211,18 +210,6 @@ public void run() {
211210
}
212211
}
213212

214-
@Override
215-
void onProxyClosed(SdlDisconnectedReason reason) {
216-
Log.i(TAG, "Proxy is closed.");
217-
if (managerListener != null) {
218-
managerListener.onDestroy();
219-
}
220-
221-
if (reason == null || !reason.equals(SdlDisconnectedReason.LANGUAGE_CHANGE)) {
222-
dispose();
223-
}
224-
}
225-
226213
/**
227214
* Dispose SdlManager and clean its resources
228215
* <strong>Note: new instance of SdlManager should be created on every connection. SdlManager cannot be reused after getting disposed.</strong>

android/sdl_android/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,20 @@ void initializeProxy() {
112112
}
113113
}
114114

115-
private void cycleProxy(SdlDisconnectedReason disconnectedReason) {
115+
@Override
116+
void cycleProxy(SdlDisconnectedReason disconnectedReason) {
116117
cleanProxy();
117118
initializeProxy();
118119
if (!SdlDisconnectedReason.LEGACY_BLUETOOTH_MODE_ENABLED.equals(disconnectedReason) && !SdlDisconnectedReason.PRIMARY_TRANSPORT_CYCLE_REQUEST.equals(disconnectedReason)) {
119120
//We don't want to alert higher if we are just cycling for legacy bluetooth
120-
onClose("Sdl Proxy Cycled", new SdlException("Sdl Proxy Cycled", SdlExceptionCause.SDL_PROXY_CYCLED));
121+
onClose("Sdl Proxy Cycled", new SdlException("Sdl Proxy Cycled", SdlExceptionCause.SDL_PROXY_CYCLED), disconnectedReason);
121122
}
122-
try {
123-
session.startSession();
124-
} catch (SdlException e) {
125-
e.printStackTrace();
123+
if (session != null) {
124+
try {
125+
session.startSession();
126+
} catch (SdlException e) {
127+
e.printStackTrace();
128+
}
126129
}
127130
}
128131

@@ -160,7 +163,7 @@ void onTransportDisconnected(String info, boolean availablePrimary, BaseTranspor
160163
Log.d(TAG, "notifying RPC session ended, but potential primary transport available");
161164
cycleProxy(SdlDisconnectedReason.PRIMARY_TRANSPORT_CYCLE_REQUEST);
162165
} else {
163-
onClose(info, null);
166+
onClose(info, null, null);
164167
}
165168
}
166169

base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ public void onServiceEnded(SessionType sessionType) {
142142

143143
@Override
144144
public void onProxyClosed(LifecycleManager lifeCycleManager, String info, Exception e, SdlDisconnectedReason reason) {
145-
BaseSdlManager.this.onProxyClosed(reason);
145+
Log.i(TAG, "Proxy is closed.");
146+
if (reason == null || !reason.equals(SdlDisconnectedReason.LANGUAGE_CHANGE)) {
147+
dispose();
148+
}
146149
}
147150

148151
@Override
@@ -165,8 +168,6 @@ public synchronized void onComplete(boolean success) {
165168
// ABSTRACT METHODS
166169
abstract void retryChangeRegistration();
167170

168-
abstract void onProxyClosed(SdlDisconnectedReason reason);
169-
170171
abstract void checkState();
171172

172173
abstract void initialize();

base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ public OnHMIStatus getCurrentHMIStatus() {
326326
return currentHMIStatus;
327327
}
328328

329-
void onClose(String info, Exception e) {
329+
void onClose(String info, Exception e, SdlDisconnectedReason reason) {
330330
Log.i(TAG, "onClose");
331331
if (lifecycleListener != null) {
332-
lifecycleListener.onProxyClosed((LifecycleManager) this, info, e, null);
332+
lifecycleListener.onProxyClosed((LifecycleManager) this, info, e, reason);
333333
}
334334
}
335335

@@ -446,7 +446,7 @@ public void run() {
446446
cleanProxy();
447447
} else {
448448
Log.v(TAG, "re-registering for language change");
449-
processLanguageChange();
449+
cycleProxy(SdlDisconnectedReason.LANGUAGE_CHANGE);
450450
}
451451
break;
452452
case UNREGISTER_APP_INTERFACE:
@@ -460,19 +460,6 @@ public void run() {
460460

461461
};
462462

463-
private void processLanguageChange() {
464-
if (session != null) {
465-
if (session.getIsConnected()) {
466-
session.close();
467-
}
468-
try {
469-
session.startSession();
470-
} catch (SdlException e) {
471-
e.printStackTrace();
472-
}
473-
}
474-
}
475-
476463
/* *******************************************************************************************************
477464
********************************** INTERNAL - RPC LISTENERS !! END !! *********************************
478465
*********************************************************************************************************/
@@ -856,7 +843,7 @@ private void sendRPCMessagePrivate(RPCMessage message, boolean isInternalMessage
856843
final ISdlConnectionListener sdlConnectionListener = new ISdlConnectionListener() {
857844
@Override
858845
public void onTransportDisconnected(String info) {
859-
onClose(info, null);
846+
onClose(info, null, null);
860847

861848
}
862849

@@ -868,7 +855,7 @@ public void onTransportDisconnected(String info, boolean availablePrimary, BaseT
868855

869856
@Override
870857
public void onTransportError(String info, Exception e) {
871-
onClose(info, e);
858+
onClose(info, e, null);
872859

873860
}
874861

@@ -1509,6 +1496,8 @@ void onProtocolSessionStarted(SessionType sessionType) {
15091496
}
15101497
}
15111498

1499+
abstract void cycleProxy(SdlDisconnectedReason disconnectedReason);
1500+
15121501
void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) {
15131502
}
15141503

javaSE/src/main/java/com/smartdevicelink/managers/SdlManager.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,6 @@ void retryChangeRegistration() {
141141
// Do nothing
142142
}
143143

144-
@Override
145-
void onProxyClosed(SdlDisconnectedReason reason) {
146-
Log.i(TAG, "Proxy is closed.");
147-
if (managerListener != null) {
148-
managerListener.onDestroy(SdlManager.this);
149-
}
150-
}
151-
152144
@Override
153145
public void dispose() {
154146
if (this.permissionManager != null) {

javaSE/src/main/java/com/smartdevicelink/managers/lifecycle/LifecycleManager.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import android.support.annotation.RestrictTo;
3636

3737
import com.smartdevicelink.SdlConnection.SdlSession;
38+
import com.smartdevicelink.exception.SdlException;
39+
import com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason;
3840
import com.smartdevicelink.transport.BaseTransportConfig;
3941

4042
/**
@@ -53,11 +55,23 @@ void initializeProxy() {
5355
this.session = new SdlSession(sdlConnectionListener, _transportConfig);
5456
}
5557

58+
@Override
59+
void cycleProxy(SdlDisconnectedReason disconnectedReason) {
60+
cleanProxy();
61+
if (session != null) {
62+
try {
63+
session.startSession();
64+
} catch (SdlException e) {
65+
e.printStackTrace();
66+
}
67+
}
68+
}
69+
5670
@Override
5771
void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) {
5872
super.onTransportDisconnected(info, availablePrimary, transportConfig);
5973
if (!availablePrimary) {
60-
onClose(info, null);
74+
onClose(info, null, null);
6175
}
6276
}
6377
}

0 commit comments

Comments
 (0)