Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ public class SdlManager extends BaseSdlManager {
private VideoStreamManager videoStreamManager;
private AudioStreamManager audioStreamManager;

private Handler handler = new Handler(Looper.getMainLooper());
private Runnable changeRegistrationRunnable = new Runnable() {
@Override
public void run() {
checkLifecycleConfiguration();
DebugTool.logInfo(TAG, "Retry Change Registration Count: " + changeRegistrationRetry);
}
};

public SdlManager() {
DebugTool.logWarning(TAG, "SdlManager must be created with SdlManager.Builder");
}

/**
* Starts up a SdlManager, and calls provided callback called once all BaseSubManagers are done setting up
*/
Expand Down Expand Up @@ -211,14 +224,9 @@ private void notifyDevListener(String info) {
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(TAG, "Retry Change Registration Count: " + changeRegistrationRetry);
}
}, 3000);
if (handler != null && changeRegistrationRunnable != null) {
handler.postDelayed(changeRegistrationRunnable, 3000);
}
}
}

Expand Down Expand Up @@ -258,6 +266,15 @@ public synchronized void dispose() {
this.lifecycleManager.stop();
}

if (handler != null) {
if (changeRegistrationRunnable != null) {
handler.removeCallbacks(changeRegistrationRunnable);
changeRegistrationRunnable = null;
}

handler = null;
}

if (managerListener != null) {
managerListener.onDestroy();
managerListener = null;
Expand Down
93 changes: 49 additions & 44 deletions base/src/main/java/com/smartdevicelink/managers/BaseSdlManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,52 +188,57 @@ protected void checkLifecycleConfiguration() {

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

final LifecycleConfigurationUpdate lcu = managerListener.managerShouldUpdateLifecycle(actualLanguage, actualHMILanguage);

ChangeRegistration changeRegistration;
changeRegistration = new ChangeRegistration(actualLanguage, actualHMILanguage);

if (lcu != null) {
changeRegistration.setAppName(lcu.getAppName());
changeRegistration.setNgnMediaScreenAppName(lcu.getShortAppName());
changeRegistration.setTtsName(lcu.getTtsName());
changeRegistration.setVrSynonyms(lcu.getVoiceRecognitionCommandNames());
changeRegistration.setOnRPCResponseListener(new OnRPCResponseListener() {
@Override
public void onResponse(int correlationId, RPCResponse response) {
if (response.getSuccess()) {
try {
DebugTool.logInfo(TAG, response.serializeJSON().toString());
} catch (JSONException e) {
DebugTool.logError(TAG, "Error attempting to serialize ChangeRegistrationResponse", e);
}

// go through and change sdlManager properties that were changed via the LCU update
hmiLanguage = actualHMILanguage;
language = actualLanguage;

if (lcu.getAppName() != null) {
appName = lcu.getAppName();
}

if (lcu.getShortAppName() != null) {
shortAppName = lcu.getShortAppName();
if(managerListener != null) {
final LifecycleConfigurationUpdate lcu = managerListener.managerShouldUpdateLifecycle(actualLanguage, actualHMILanguage);

ChangeRegistration changeRegistration;
changeRegistration = new ChangeRegistration(actualLanguage, actualHMILanguage);

if (lcu != null) {
changeRegistration.setAppName(lcu.getAppName());
changeRegistration.setNgnMediaScreenAppName(lcu.getShortAppName());
changeRegistration.setTtsName(lcu.getTtsName());
changeRegistration.setVrSynonyms(lcu.getVoiceRecognitionCommandNames());
changeRegistration.setOnRPCResponseListener(new OnRPCResponseListener() {
@Override
public void onResponse(int correlationId, RPCResponse response) {
if (response.getSuccess()) {
try {
DebugTool.logInfo(TAG, response.serializeJSON().toString());
} catch (JSONException e) {
DebugTool.logError(TAG, "Error attempting to serialize ChangeRegistrationResponse", e);
}

// go through and change sdlManager properties that were changed via the LCU update
hmiLanguage = actualHMILanguage;
language = actualLanguage;

if (lcu.getAppName() != null) {
appName = lcu.getAppName();
}

if (lcu.getShortAppName() != null) {
shortAppName = lcu.getShortAppName();
}

if (lcu.getTtsName() != null) {
ttsChunks = lcu.getTtsName();
}

if (lcu.getVoiceRecognitionCommandNames() != null) {
vrSynonyms = lcu.getVoiceRecognitionCommandNames();
}
} else {
DebugTool.logError(TAG, "Change Registration onError: " + response.getResultCode() + " | Info: " + response.getInfo());
retryChangeRegistration();
}

if (lcu.getTtsName() != null) {
ttsChunks = lcu.getTtsName();
}

if (lcu.getVoiceRecognitionCommandNames() != null) {
vrSynonyms = lcu.getVoiceRecognitionCommandNames();
}
} else {
DebugTool.logError(TAG, "Change Registration onError: " + response.getResultCode() + " | Info: " + response.getInfo());
retryChangeRegistration();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this code was missed, this should not be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

}
}
});
this.sendRPC(changeRegistration);
});
this.sendRPC(changeRegistration);
}
}
else {
DebugTool.logError(TAG, "SdlManagerListener is null");
}
}
}
Expand Down