Skip to content

Commit b51cda0

Browse files
author
Robert Henigan
authored
Merge pull request #1786 from smartdevicelink/bugfix/issue_1783
Attepted fix of NPE in #1783
2 parents 3d1e54e + e816eec commit b51cda0

2 files changed

Lines changed: 74 additions & 52 deletions

File tree

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ public class SdlManager extends BaseSdlManager {
9191
private VideoStreamManager videoStreamManager;
9292
private AudioStreamManager audioStreamManager;
9393

94+
private Handler handler = new Handler(Looper.getMainLooper());
95+
private Runnable changeRegistrationRunnable = new Runnable() {
96+
@Override
97+
public void run() {
98+
checkLifecycleConfiguration();
99+
DebugTool.logInfo(TAG, "Retry Change Registration Count: " + changeRegistrationRetry);
100+
}
101+
};
102+
103+
public SdlManager() {
104+
DebugTool.logWarning(TAG, "SdlManager must be created with SdlManager.Builder");
105+
}
106+
94107
/**
95108
* Starts up a SdlManager, and calls provided callback called once all BaseSubManagers are done setting up
96109
*/
@@ -211,14 +224,9 @@ private void notifyDevListener(String info) {
211224
void retryChangeRegistration() {
212225
changeRegistrationRetry++;
213226
if (changeRegistrationRetry < MAX_RETRY) {
214-
final Handler handler = new Handler(Looper.getMainLooper());
215-
handler.postDelayed(new Runnable() {
216-
@Override
217-
public void run() {
218-
checkLifecycleConfiguration();
219-
DebugTool.logInfo(TAG, "Retry Change Registration Count: " + changeRegistrationRetry);
220-
}
221-
}, 3000);
227+
if (handler != null && changeRegistrationRunnable != null) {
228+
handler.postDelayed(changeRegistrationRunnable, 3000);
229+
}
222230
}
223231
}
224232

@@ -258,6 +266,15 @@ public synchronized void dispose() {
258266
this.lifecycleManager.stop();
259267
}
260268

269+
if (handler != null) {
270+
if (changeRegistrationRunnable != null) {
271+
handler.removeCallbacks(changeRegistrationRunnable);
272+
changeRegistrationRunnable = null;
273+
}
274+
275+
handler = null;
276+
}
277+
261278
if (managerListener != null) {
262279
managerListener.onDestroy();
263280
managerListener = null;

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

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -188,52 +188,57 @@ protected void checkLifecycleConfiguration() {
188188

189189
if ((actualLanguage != null && !actualLanguage.equals(language)) || (actualHMILanguage != null && !actualHMILanguage.equals(hmiLanguage))) {
190190

191-
final LifecycleConfigurationUpdate lcu = managerListener.managerShouldUpdateLifecycle(actualLanguage, actualHMILanguage);
192-
193-
ChangeRegistration changeRegistration;
194-
changeRegistration = new ChangeRegistration(actualLanguage, actualHMILanguage);
195-
196-
if (lcu != null) {
197-
changeRegistration.setAppName(lcu.getAppName());
198-
changeRegistration.setNgnMediaScreenAppName(lcu.getShortAppName());
199-
changeRegistration.setTtsName(lcu.getTtsName());
200-
changeRegistration.setVrSynonyms(lcu.getVoiceRecognitionCommandNames());
201-
changeRegistration.setOnRPCResponseListener(new OnRPCResponseListener() {
202-
@Override
203-
public void onResponse(int correlationId, RPCResponse response) {
204-
if (response.getSuccess()) {
205-
try {
206-
DebugTool.logInfo(TAG, response.serializeJSON().toString());
207-
} catch (JSONException e) {
208-
DebugTool.logError(TAG, "Error attempting to serialize ChangeRegistrationResponse", e);
209-
}
210-
211-
// go through and change sdlManager properties that were changed via the LCU update
212-
hmiLanguage = actualHMILanguage;
213-
language = actualLanguage;
214-
215-
if (lcu.getAppName() != null) {
216-
appName = lcu.getAppName();
217-
}
218-
219-
if (lcu.getShortAppName() != null) {
220-
shortAppName = lcu.getShortAppName();
191+
if(managerListener != null) {
192+
final LifecycleConfigurationUpdate lcu = managerListener.managerShouldUpdateLifecycle(actualLanguage, actualHMILanguage);
193+
194+
ChangeRegistration changeRegistration;
195+
changeRegistration = new ChangeRegistration(actualLanguage, actualHMILanguage);
196+
197+
if (lcu != null) {
198+
changeRegistration.setAppName(lcu.getAppName());
199+
changeRegistration.setNgnMediaScreenAppName(lcu.getShortAppName());
200+
changeRegistration.setTtsName(lcu.getTtsName());
201+
changeRegistration.setVrSynonyms(lcu.getVoiceRecognitionCommandNames());
202+
changeRegistration.setOnRPCResponseListener(new OnRPCResponseListener() {
203+
@Override
204+
public void onResponse(int correlationId, RPCResponse response) {
205+
if (response.getSuccess()) {
206+
try {
207+
DebugTool.logInfo(TAG, response.serializeJSON().toString());
208+
} catch (JSONException e) {
209+
DebugTool.logError(TAG, "Error attempting to serialize ChangeRegistrationResponse", e);
210+
}
211+
212+
// go through and change sdlManager properties that were changed via the LCU update
213+
hmiLanguage = actualHMILanguage;
214+
language = actualLanguage;
215+
216+
if (lcu.getAppName() != null) {
217+
appName = lcu.getAppName();
218+
}
219+
220+
if (lcu.getShortAppName() != null) {
221+
shortAppName = lcu.getShortAppName();
222+
}
223+
224+
if (lcu.getTtsName() != null) {
225+
ttsChunks = lcu.getTtsName();
226+
}
227+
228+
if (lcu.getVoiceRecognitionCommandNames() != null) {
229+
vrSynonyms = lcu.getVoiceRecognitionCommandNames();
230+
}
231+
} else {
232+
DebugTool.logError(TAG, "Change Registration onError: " + response.getResultCode() + " | Info: " + response.getInfo());
233+
retryChangeRegistration();
221234
}
222-
223-
if (lcu.getTtsName() != null) {
224-
ttsChunks = lcu.getTtsName();
225-
}
226-
227-
if (lcu.getVoiceRecognitionCommandNames() != null) {
228-
vrSynonyms = lcu.getVoiceRecognitionCommandNames();
229-
}
230-
} else {
231-
DebugTool.logError(TAG, "Change Registration onError: " + response.getResultCode() + " | Info: " + response.getInfo());
232-
retryChangeRegistration();
233235
}
234-
}
235-
});
236-
this.sendRPC(changeRegistration);
236+
});
237+
this.sendRPC(changeRegistration);
238+
}
239+
}
240+
else {
241+
DebugTool.logError(TAG, "SdlManagerListener is null");
237242
}
238243
}
239244
}

0 commit comments

Comments
 (0)