summaryrefslogtreecommitdiff
path: root/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java')
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java432
1 files changed, 227 insertions, 205 deletions
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 0054b7810..2934e5736 100644
--- a/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/lifecycle/BaseLifecycleManager.java
@@ -36,6 +36,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.RestrictTo;
import android.util.Log;
+import com.livio.taskmaster.Taskmaster;
import com.smartdevicelink.SdlConnection.ISdlConnectionListener;
import com.smartdevicelink.SdlConnection.SdlSession;
import com.smartdevicelink.exception.SdlException;
@@ -134,6 +135,7 @@ abstract class BaseLifecycleManager {
Version minimumProtocolVersion;
Version minimumRPCVersion;
BaseTransportConfig _transportConfig;
+ private Taskmaster taskmaster;
BaseLifecycleManager(AppConfig appConfig, BaseTransportConfig config, LifecycleListener listener) {
this.appConfig = appConfig;
@@ -141,7 +143,7 @@ abstract class BaseLifecycleManager {
this.lifecycleListener = listener;
this.minimumProtocolVersion = appConfig.getMinimumProtocolVersion();
this.minimumRPCVersion = appConfig.getMinimumRPCVersion();
- initializeProxy();
+ initialize();
}
public void start() {
@@ -161,8 +163,25 @@ abstract class BaseLifecycleManager {
}
}
- public void stop() {
- session.close();
+ public synchronized void stop() {
+ if(session != null) {
+ session.close();
+ session = null;
+ }
+ if (taskmaster != null) {
+ taskmaster.shutdown();
+ }
+ }
+
+ Taskmaster getTaskmaster() {
+ if (taskmaster == null) {
+ Taskmaster.Builder builder = new Taskmaster.Builder();
+ builder.setThreadCount(2);
+ builder.shouldBeDaemon(true);
+ taskmaster = builder.build();
+ taskmaster.start();
+ }
+ return taskmaster;
}
Version getProtocolVersion() {
@@ -326,10 +345,10 @@ abstract class BaseLifecycleManager {
return currentHMIStatus;
}
- void onClose(String info, Exception e) {
+ void onClose(String info, Exception e, SdlDisconnectedReason reason) {
Log.i(TAG, "onClose");
if (lifecycleListener != null) {
- lifecycleListener.onProxyClosed((LifecycleManager) this, info, e, null);
+ lifecycleListener.onClosed((LifecycleManager) this, info, e, reason);
}
}
@@ -383,7 +402,7 @@ abstract class BaseLifecycleManager {
UnregisterAppInterface msg = new UnregisterAppInterface();
msg.setCorrelationID(UNREGISTER_APP_INTERFACE_CORRELATION_ID);
sendRPCMessagePrivate(msg, true);
- cleanProxy();
+ clean();
return;
}
processRaiResponse(raiResponse);
@@ -394,7 +413,7 @@ abstract class BaseLifecycleManager {
boolean shouldInit = currentHMIStatus == null;
currentHMIStatus = (OnHMIStatus) message;
if (lifecycleListener != null && shouldInit) {
- lifecycleListener.onProxyConnected((LifecycleManager) BaseLifecycleManager.this);
+ lifecycleListener.onConnected((LifecycleManager) BaseLifecycleManager.this);
}
break;
case ON_HASH_CHANGE:
@@ -443,15 +462,15 @@ abstract class BaseLifecycleManager {
if (!onAppInterfaceUnregistered.getReason().equals(AppInterfaceUnregisteredReason.LANGUAGE_CHANGE)) {
Log.v(TAG, "on app interface unregistered");
- cleanProxy();
+ clean();
} else {
Log.v(TAG, "re-registering for language change");
- processLanguageChange();
+ cycle(SdlDisconnectedReason.LANGUAGE_CHANGE);
}
break;
case UNREGISTER_APP_INTERFACE:
Log.v(TAG, "unregister app interface");
- cleanProxy();
+ clean();
break;
}
}
@@ -460,19 +479,6 @@ abstract class BaseLifecycleManager {
};
- private void processLanguageChange() {
- if (session != null) {
- if (session.getIsConnected()) {
- session.close();
- }
- try {
- session.startSession();
- } catch (SdlException e) {
- e.printStackTrace();
- }
- }
- }
-
/* *******************************************************************************************************
********************************** INTERNAL - RPC LISTENERS !! END !! *********************************
*********************************************************************************************************/
@@ -856,7 +862,7 @@ abstract class BaseLifecycleManager {
final ISdlConnectionListener sdlConnectionListener = new ISdlConnectionListener() {
@Override
public void onTransportDisconnected(String info) {
- onClose(info, null);
+ onClose(info, null, null);
}
@@ -868,7 +874,7 @@ abstract class BaseLifecycleManager {
@Override
public void onTransportError(String info, Exception e) {
- onClose(info, e);
+ onClose(info, e, null);
}
@@ -916,24 +922,24 @@ abstract class BaseLifecycleManager {
@Override
public void onProtocolSessionStartedNACKed(SessionType sessionType, byte sessionID, byte version, String correlationID, List<String> rejectedParams) {
- Log.w(TAG, sessionType + " onProtocolSessionStartedNACKed " + sessionID + " RejectedParams: " + rejectedParams);
- BaseLifecycleManager.this.onProtocolSessionStartedNACKed(sessionType);
+ Log.w(TAG, sessionType.getName() + " onProtocolSessionStartedNACKed " + sessionID + " RejectedParams: " + rejectedParams);
+ BaseLifecycleManager.this.onStartServiceNACKed(sessionType);
}
@Override
public void onProtocolSessionStarted(SessionType sessionType, byte sessionID, byte version, String correlationID, int hashID, boolean isEncrypted) {
Log.i(TAG, "on protocol session started");
- BaseLifecycleManager.this.onProtocolSessionStarted(sessionType);
+ BaseLifecycleManager.this.onServiceStarted(sessionType);
}
@Override
public void onProtocolSessionEnded(SessionType sessionType, byte sessionID, String correlationID) {
- BaseLifecycleManager.this.onProtocolSessionEnded(sessionType);
+ //Currently not necessary
}
@Override
public void onProtocolSessionEndedNACKed(SessionType sessionType, byte sessionID, String correlationID) {
- BaseLifecycleManager.this.onProtocolSessionEndedNACKed(sessionType);
+ //Currently not necessary
}
@Override
@@ -1159,172 +1165,17 @@ abstract class BaseLifecycleManager {
public void startRPCEncryption() {
BaseLifecycleManager.this.startRPCEncryption();
}
+
+ @Override
+ public Taskmaster getTaskmaster() {
+ return BaseLifecycleManager.this.getTaskmaster();
+ }
};
/* *******************************************************************************************************
********************************************* ISdl - END ************************************************
*********************************************************************************************************/
- public interface LifecycleListener {
- void onProxyConnected(LifecycleManager lifeCycleManager);
-
- void onProxyClosed(LifecycleManager lifeCycleManager, String info, Exception e, SdlDisconnectedReason reason);
-
- void onServiceStarted(SessionType sessionType);
-
- void onServiceEnded(SessionType sessionType);
-
- void onError(LifecycleManager lifeCycleManager, String info, Exception e);
- }
-
- public static class AppConfig {
- private String appID, appName, ngnMediaScreenAppName;
- private Vector<TTSChunk> ttsName;
- private Vector<String> vrSynonyms;
- private boolean isMediaApp = false;
- private Language languageDesired, hmiDisplayLanguageDesired;
- private Vector<AppHMIType> appType;
- private TemplateColorScheme dayColorScheme, nightColorScheme;
- private Version minimumProtocolVersion;
- private Version minimumRPCVersion;
-
- private void prepare() {
- if (getNgnMediaScreenAppName() == null) {
- setNgnMediaScreenAppName(getAppName());
- }
-
- if (getLanguageDesired() == null) {
- setLanguageDesired(Language.EN_US);
- }
-
- if (getHmiDisplayLanguageDesired() == null) {
- setHmiDisplayLanguageDesired(Language.EN_US);
- }
-
- if (getVrSynonyms() == null) {
- setVrSynonyms(new Vector<String>());
- getVrSynonyms().add(getAppName());
- }
- }
-
- public String getAppID() {
- return appID;
- }
-
- public void setAppID(String appID) {
- this.appID = appID;
- }
-
- public String getAppName() {
- return appName;
- }
-
- public void setAppName(String appName) {
- this.appName = appName;
- }
-
- public String getNgnMediaScreenAppName() {
- return ngnMediaScreenAppName;
- }
-
- public void setNgnMediaScreenAppName(String ngnMediaScreenAppName) {
- this.ngnMediaScreenAppName = ngnMediaScreenAppName;
- }
-
- public Vector<TTSChunk> getTtsName() {
- return ttsName;
- }
-
- public void setTtsName(Vector<TTSChunk> ttsName) {
- this.ttsName = ttsName;
- }
-
- public Vector<String> getVrSynonyms() {
- return vrSynonyms;
- }
-
- public void setVrSynonyms(Vector<String> vrSynonyms) {
- this.vrSynonyms = vrSynonyms;
- }
-
- public boolean isMediaApp() {
- return isMediaApp;
- }
-
- public void setMediaApp(boolean mediaApp) {
- isMediaApp = mediaApp;
- }
-
- public Language getLanguageDesired() {
- return languageDesired;
- }
-
- public void setLanguageDesired(Language languageDesired) {
- this.languageDesired = languageDesired;
- }
-
- public Language getHmiDisplayLanguageDesired() {
- return hmiDisplayLanguageDesired;
- }
-
- public void setHmiDisplayLanguageDesired(Language hmiDisplayLanguageDesired) {
- this.hmiDisplayLanguageDesired = hmiDisplayLanguageDesired;
- }
-
- public Vector<AppHMIType> getAppType() {
- return appType;
- }
-
- public void setAppType(Vector<AppHMIType> appType) {
- this.appType = appType;
- }
-
- public TemplateColorScheme getDayColorScheme() {
- return dayColorScheme;
- }
-
- public void setDayColorScheme(TemplateColorScheme dayColorScheme) {
- this.dayColorScheme = dayColorScheme;
- }
-
- public TemplateColorScheme getNightColorScheme() {
- return nightColorScheme;
- }
-
- public void setNightColorScheme(TemplateColorScheme nightColorScheme) {
- this.nightColorScheme = nightColorScheme;
- }
-
- public Version getMinimumProtocolVersion() {
- return minimumProtocolVersion;
- }
-
- /**
- * Sets the minimum protocol version that will be permitted to connect.
- * If the protocol version of the head unit connected is below this version,
- * the app will disconnect with an EndService protocol message and will not register.
- *
- * @param minimumProtocolVersion a Version object with the minimally accepted Protocol version
- */
- public void setMinimumProtocolVersion(Version minimumProtocolVersion) {
- this.minimumProtocolVersion = minimumProtocolVersion;
- }
-
- public Version getMinimumRPCVersion() {
- return minimumRPCVersion;
- }
-
- /**
- * The minimum RPC version that will be permitted to connect.
- * If the RPC version of the head unit connected is below this version, an UnregisterAppInterface will be sent.
- *
- * @param minimumRPCVersion a Version object with the minimally accepted RPC spec version
- */
- public void setMinimumRPCVersion(Version minimumRPCVersion) {
- this.minimumRPCVersion = minimumRPCVersion;
- }
- }
-
/**
* Temporary method to bridge the new PLAY_PAUSE and OKAY button functionality with the old
* OK button name. This should be removed during the next major release
@@ -1378,7 +1229,7 @@ abstract class BaseLifecycleManager {
return null;
}
- void cleanProxy() {
+ void clean() {
firstTimeFull = true;
currentHMIStatus = null;
if (rpcListeners != null) {
@@ -1458,7 +1309,7 @@ abstract class BaseLifecycleManager {
********************************** Platform specific methods - START *************************************
*********************************************************************************************************/
- void initializeProxy() {
+ void initialize() {
this.rpcListeners = new HashMap<>();
this.rpcResponseListeners = new HashMap<>();
this.rpcNotificationListeners = new HashMap<>();
@@ -1467,12 +1318,12 @@ abstract class BaseLifecycleManager {
setupInternalRpcListeners();
}
- void onProtocolSessionStarted(SessionType sessionType) {
+ void onServiceStarted(SessionType sessionType) {
if (sessionType != null) {
if (minimumProtocolVersion != null && minimumProtocolVersion.isNewerThan(getProtocolVersion()) == 1) {
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()));
session.endService(sessionType, session.getSessionId());
- cleanProxy();
+ clean();
return;
}
@@ -1497,9 +1348,9 @@ abstract class BaseLifecycleManager {
rai.setAppHMIType(appConfig.getAppType());
rai.setDayColorScheme(appConfig.getDayColorScheme());
rai.setNightColorScheme(appConfig.getNightColorScheme());
+ rai.setHashID(appConfig.getResumeHash());
//Add device/system info in the future
- //TODO attach previous hash id
sendRPCMessagePrivate(rai, true);
} else {
@@ -1509,30 +1360,25 @@ abstract class BaseLifecycleManager {
}
}
- void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) {
- }
+ abstract void cycle(SdlDisconnectedReason disconnectedReason);
- void onProtocolSessionStartedNACKed(SessionType sessionType) {
+ void onTransportDisconnected(String info, boolean availablePrimary, BaseTransportConfig transportConfig) {
}
- void onProtocolSessionEnded(SessionType sessionType) {
+ void onStartServiceNACKed(SessionType sessionType) {
}
- void onProtocolSessionEndedNACKed(SessionType sessionType) {
- }
void startVideoService(boolean encrypted, VideoStreamingParameters parameters) {
}
- boolean endVideoStream() {
- return false;
+ void endVideoStream() {
}
void startAudioService(boolean encrypted) {
}
- boolean endAudioStream() {
- return false;
+ void endAudioStream() {
}
void setSdlSecurityStaticVars() {
@@ -1541,4 +1387,180 @@ abstract class BaseLifecycleManager {
/* *******************************************************************************************************
********************************** Platform specific methods - End *************************************
*********************************************************************************************************/
+
+ /* *******************************************************************************************************
+ ****************************** Inner Classes and Interfaces - Start *************************************
+ *********************************************************************************************************/
+
+ public interface LifecycleListener {
+ void onConnected(LifecycleManager lifeCycleManager);
+
+ void onClosed(LifecycleManager lifeCycleManager, String info, Exception e, SdlDisconnectedReason reason);
+
+ void onServiceStarted(SessionType sessionType);
+
+ void onServiceEnded(SessionType sessionType);
+
+ void onError(LifecycleManager lifeCycleManager, String info, Exception e);
+ }
+
+ public static class AppConfig {
+ private String appID, appName, ngnMediaScreenAppName, resumeHash;
+ private Vector<TTSChunk> ttsName;
+ private Vector<String> vrSynonyms;
+ private boolean isMediaApp = false;
+ private Language languageDesired, hmiDisplayLanguageDesired;
+ private Vector<AppHMIType> appType;
+ private TemplateColorScheme dayColorScheme, nightColorScheme;
+ private Version minimumProtocolVersion;
+ private Version minimumRPCVersion;
+
+ private void prepare() {
+ if (getNgnMediaScreenAppName() == null) {
+ setNgnMediaScreenAppName(getAppName());
+ }
+
+ if (getLanguageDesired() == null) {
+ setLanguageDesired(Language.EN_US);
+ }
+
+ if (getHmiDisplayLanguageDesired() == null) {
+ setHmiDisplayLanguageDesired(Language.EN_US);
+ }
+
+ if (getVrSynonyms() == null) {
+ setVrSynonyms(new Vector<String>());
+ getVrSynonyms().add(getAppName());
+ }
+ }
+
+ public String getAppID() {
+ return appID;
+ }
+
+ public void setAppID(String appID) {
+ this.appID = appID;
+ }
+
+ public String getAppName() {
+ return appName;
+ }
+
+ public void setAppName(String appName) {
+ this.appName = appName;
+ }
+
+ public String getNgnMediaScreenAppName() {
+ return ngnMediaScreenAppName;
+ }
+
+ public void setNgnMediaScreenAppName(String ngnMediaScreenAppName) {
+ this.ngnMediaScreenAppName = ngnMediaScreenAppName;
+ }
+
+ public Vector<TTSChunk> getTtsName() {
+ return ttsName;
+ }
+
+ public void setTtsName(Vector<TTSChunk> ttsName) {
+ this.ttsName = ttsName;
+ }
+
+ public Vector<String> getVrSynonyms() {
+ return vrSynonyms;
+ }
+
+ public void setVrSynonyms(Vector<String> vrSynonyms) {
+ this.vrSynonyms = vrSynonyms;
+ }
+
+ public boolean isMediaApp() {
+ return isMediaApp;
+ }
+
+ public void setMediaApp(boolean mediaApp) {
+ isMediaApp = mediaApp;
+ }
+
+ public Language getLanguageDesired() {
+ return languageDesired;
+ }
+
+ public void setLanguageDesired(Language languageDesired) {
+ this.languageDesired = languageDesired;
+ }
+
+ public Language getHmiDisplayLanguageDesired() {
+ return hmiDisplayLanguageDesired;
+ }
+
+ public void setHmiDisplayLanguageDesired(Language hmiDisplayLanguageDesired) {
+ this.hmiDisplayLanguageDesired = hmiDisplayLanguageDesired;
+ }
+
+ public Vector<AppHMIType> getAppType() {
+ return appType;
+ }
+
+ public void setAppType(Vector<AppHMIType> appType) {
+ this.appType = appType;
+ }
+
+ public String getResumeHash() {
+ return this.resumeHash;
+ }
+
+ public void setResumeHash(String resumeHash) {
+ this.resumeHash = resumeHash;
+ }
+
+ public TemplateColorScheme getDayColorScheme() {
+ return dayColorScheme;
+ }
+
+ public void setDayColorScheme(TemplateColorScheme dayColorScheme) {
+ this.dayColorScheme = dayColorScheme;
+ }
+
+ public TemplateColorScheme getNightColorScheme() {
+ return nightColorScheme;
+ }
+
+ public void setNightColorScheme(TemplateColorScheme nightColorScheme) {
+ this.nightColorScheme = nightColorScheme;
+ }
+
+ public Version getMinimumProtocolVersion() {
+ return minimumProtocolVersion;
+ }
+
+ /**
+ * Sets the minimum protocol version that will be permitted to connect.
+ * If the protocol version of the head unit connected is below this version,
+ * the app will disconnect with an EndService protocol message and will not register.
+ *
+ * @param minimumProtocolVersion a Version object with the minimally accepted Protocol version
+ */
+ public void setMinimumProtocolVersion(Version minimumProtocolVersion) {
+ this.minimumProtocolVersion = minimumProtocolVersion;
+ }
+
+ public Version getMinimumRPCVersion() {
+ return minimumRPCVersion;
+ }
+
+ /**
+ * The minimum RPC version that will be permitted to connect.
+ * If the RPC version of the head unit connected is below this version, an UnregisterAppInterface will be sent.
+ *
+ * @param minimumRPCVersion a Version object with the minimally accepted RPC spec version
+ */
+ public void setMinimumRPCVersion(Version minimumRPCVersion) {
+ this.minimumRPCVersion = minimumRPCVersion;
+ }
+ }
+
+ /* *******************************************************************************************************
+ ****************************** Inner Classes and Interfaces - End ***************************************
+ *********************************************************************************************************/
}