summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2018-07-19 14:52:28 -0400
committerGitHub <noreply@github.com>2018-07-19 14:52:28 -0400
commit9eb6a1f4b39a4f5cac5d06826c52867e1d52ba5e (patch)
treee51cbac97e527e7167ac1871cad29e062c18fce0
parent641370971f169459c5193365298286f435c4c81d (diff)
parent682988f2661608fbc8286914abb14cdc41b14e04 (diff)
downloadsdl_android-9eb6a1f4b39a4f5cac5d06826c52867e1d52ba5e.tar.gz
Merge pull request #819 from smartdevicelink/feature/manager_ready_callback
WIP: Feature/manager ready callback
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/api/BaseSubManager.java22
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/api/ProxyBridge.java24
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/api/SdlManager.java143
3 files changed, 145 insertions, 44 deletions
diff --git a/sdl_android/src/main/java/com/smartdevicelink/api/BaseSubManager.java b/sdl_android/src/main/java/com/smartdevicelink/api/BaseSubManager.java
index ac7e020f9..66c7f309a 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/api/BaseSubManager.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/api/BaseSubManager.java
@@ -18,8 +18,9 @@ public abstract class BaseSubManager {
// states - if this gets more complicated we can move elsewhere
private int state;
private final Object STATE_LOCK = new Object();
- public static final int SETTING_UP = 0x00, READY = 0x30, SHUTDOWN = 0x60;
+ public static final int SETTING_UP = 0x00, READY = 0x30, SHUTDOWN = 0x60, ERROR = 0x90;
protected final ISdl internalInterface;
+ private CompletionListener completionListener;
public BaseSubManager(@NonNull ISdl internalInterface){
this.internalInterface = internalInterface;
@@ -27,6 +28,18 @@ public abstract class BaseSubManager {
}
/**
+ * Starts up a BaseSubManager, and calls provided callback once BaseSubManager is done setting up or failed setup.
+ * @param listener CompletionListener that is called once the BaseSubManager's state is READY or ERROR
+ */
+ public void start(CompletionListener listener){
+ this.completionListener = listener;
+ if((state == READY || state == ERROR) && completionListener != null){
+ completionListener.onComplete(state == READY);
+ completionListener = null;
+ }
+ }
+
+ /**
* <p>Called when manager is being torn down</p>
*/
public void dispose(){
@@ -37,6 +50,13 @@ public abstract class BaseSubManager {
synchronized (STATE_LOCK) {
this.state = state;
}
+ if(state == READY && completionListener != null){
+ completionListener.onComplete(true);
+ completionListener = null;
+ }else if(state == ERROR && completionListener != null){
+ completionListener.onComplete(false);
+ completionListener = null;
+ }
}
public int getState() {
diff --git a/sdl_android/src/main/java/com/smartdevicelink/api/ProxyBridge.java b/sdl_android/src/main/java/com/smartdevicelink/api/ProxyBridge.java
index 4dadad170..e5f049126 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/api/ProxyBridge.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/api/ProxyBridge.java
@@ -3,10 +3,10 @@ package com.smartdevicelink.api;
import android.util.SparseArray;
import com.smartdevicelink.protocol.enums.FunctionID;
+import com.smartdevicelink.proxy.IProxyListener;
import com.smartdevicelink.proxy.RPCMessage;
import com.smartdevicelink.proxy.callbacks.OnServiceEnded;
import com.smartdevicelink.proxy.callbacks.OnServiceNACKed;
-import com.smartdevicelink.proxy.interfaces.IProxyListenerBase;
import com.smartdevicelink.proxy.rpc.AddCommandResponse;
import com.smartdevicelink.proxy.rpc.AddSubMenuResponse;
import com.smartdevicelink.proxy.rpc.AlertManeuverResponse;
@@ -28,6 +28,7 @@ import com.smartdevicelink.proxy.rpc.GetSystemCapabilityResponse;
import com.smartdevicelink.proxy.rpc.GetVehicleDataResponse;
import com.smartdevicelink.proxy.rpc.GetWayPointsResponse;
import com.smartdevicelink.proxy.rpc.ListFilesResponse;
+import com.smartdevicelink.proxy.rpc.OnAppInterfaceUnregistered;
import com.smartdevicelink.proxy.rpc.OnAudioPassThru;
import com.smartdevicelink.proxy.rpc.OnButtonEvent;
import com.smartdevicelink.proxy.rpc.OnButtonPress;
@@ -50,6 +51,7 @@ import com.smartdevicelink.proxy.rpc.PerformAudioPassThruResponse;
import com.smartdevicelink.proxy.rpc.PerformInteractionResponse;
import com.smartdevicelink.proxy.rpc.PutFileResponse;
import com.smartdevicelink.proxy.rpc.ReadDIDResponse;
+import com.smartdevicelink.proxy.rpc.RegisterAppInterfaceResponse;
import com.smartdevicelink.proxy.rpc.ResetGlobalPropertiesResponse;
import com.smartdevicelink.proxy.rpc.ScrollableMessageResponse;
import com.smartdevicelink.proxy.rpc.SendHapticDataResponse;
@@ -68,6 +70,7 @@ import com.smartdevicelink.proxy.rpc.SubscribeButtonResponse;
import com.smartdevicelink.proxy.rpc.SubscribeVehicleDataResponse;
import com.smartdevicelink.proxy.rpc.SubscribeWayPointsResponse;
import com.smartdevicelink.proxy.rpc.SystemRequestResponse;
+import com.smartdevicelink.proxy.rpc.UnregisterAppInterfaceResponse;
import com.smartdevicelink.proxy.rpc.UnsubscribeButtonResponse;
import com.smartdevicelink.proxy.rpc.UnsubscribeVehicleDataResponse;
import com.smartdevicelink.proxy.rpc.UnsubscribeWayPointsResponse;
@@ -76,16 +79,33 @@ import com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason;
import java.util.concurrent.CopyOnWriteArrayList;
-public class ProxyBridge implements IProxyListenerBase{
+public class ProxyBridge implements IProxyListener{
private final Object RPC_LISTENER_LOCK = new Object();
protected SparseArray<CopyOnWriteArrayList<OnRPCListener>> rpcListeners = null;
final LifecycleListener lifecycleListener;
+ @Override
+ public void onProxyOpened() {}
+
+ @Override
+ public void onRegisterAppInterfaceResponse(RegisterAppInterfaceResponse response) {
+ if(response.getSuccess()){
+ lifecycleListener.onProxyConnected();
+ }
+ }
+
+ @Override
+ public void onOnAppInterfaceUnregistered(OnAppInterfaceUnregistered notification) {}
+
+ @Override
+ public void onUnregisterAppInterfaceResponse(UnregisterAppInterfaceResponse response) {}
+
public interface OnRPCListener {
void onRpcReceived(int functionID, RPCMessage message);
}
protected interface LifecycleListener{
+ void onProxyConnected();
void onProxyClosed(String info, Exception e, SdlDisconnectedReason reason);
void onServiceEnded(OnServiceEnded serviceEnded);
void onServiceNACKed(OnServiceNACKed serviceNACKed);
diff --git a/sdl_android/src/main/java/com/smartdevicelink/api/SdlManager.java b/sdl_android/src/main/java/com/smartdevicelink/api/SdlManager.java
index 5c2516969..924971237 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/api/SdlManager.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/api/SdlManager.java
@@ -2,6 +2,7 @@ package com.smartdevicelink.api;
import android.content.Context;
import android.support.annotation.NonNull;
+import android.util.Log;
import com.smartdevicelink.exception.SdlException;
import com.smartdevicelink.protocol.enums.FunctionID;
@@ -46,7 +47,7 @@ import java.util.Vector;
* 3. Sending Requests <br>
* 4. Helper methods
*/
-public class SdlManager implements ProxyBridge.LifecycleListener {
+public class SdlManager{
private static String TAG = "Sdl Manager";
private SdlProxyBase proxy;
@@ -62,10 +63,13 @@ public class SdlManager implements ProxyBridge.LifecycleListener {
private Vector<TTSChunk> ttsChunks;
private TemplateColorScheme dayColorScheme, nightColorScheme;
- private final ProxyBridge proxyBridge= new ProxyBridge(this);
+ private CompletionListener initListener;
+ private int state = -1;
//public LockScreenConfig lockScreenConfig;
+
// Managers
+
/*
private FileManager fileManager;
private VideoStreamingManager videoStreamingManager;
@@ -75,17 +79,81 @@ public class SdlManager implements ProxyBridge.LifecycleListener {
private PermissionManager permissionManager;
*/
+ // Initialize proxyBridge with anonymous lifecycleListener
+ private final ProxyBridge proxyBridge= new ProxyBridge(new ProxyBridge.LifecycleListener() {
+ @Override
+ public void onProxyConnected() {
+ Log.d(TAG, "Proxy is connected. Now initializing.");
+ initialize();
+ }
+
+ @Override
+ public void onProxyClosed(String info, Exception e, SdlDisconnectedReason reason){
+ dispose();
+ }
+
+ @Override
+ public void onServiceEnded(OnServiceEnded serviceEnded){
+
+ }
+
+ @Override
+ public void onServiceNACKed(OnServiceNACKed serviceNACKed){
+
+ }
+
+ @Override
+ public void onError(String info, Exception e){
+
+ }
+ });
+
+ // Sub manager listener
+ private final CompletionListener subManagerListener = new CompletionListener() {
+ @Override
+ public synchronized void onComplete(boolean success) {
+ if(!success){
+ Log.d(TAG, "Sub manager failed to initialize");
+ }
+ if(
+ true
+ /*
+ fileManager.getState() != BaseSubManager.SETTING_UP &&
+ videoStreamingManager.getState() != BaseSubManager.SETTING_UP &&
+ audioStreamManager.getState() != BaseSubManager.SETTING_UP &&
+ lockscreenManager.getState() != BaseSubManager.SETTING_UP &&
+ screenManager.getState() != BaseSubManager.SETTING_UP
+ permissionManager.getState() != BaseSubManager.SETTING_UP
+ */ ){
+ state = BaseSubManager.READY;
+ if(initListener != null){
+ initListener.onComplete(true);
+ initListener = null;
+ }
+ }
+ }
+ };
+
private void initialize(){
// instantiate managers
/*
this.fileManager = new FileManager(_internalInterface, context);
+ this.fileManager.start(subManagerListener);
this.lockscreenManager = new LockscreenManager(lockScreenConfig, context, _internalInterface);
+ this.lockscreenManager.start(subManagerListener);
this.screenManager = new ScreenManager(_internalInterface, this.fileManager);
+ this.screenManager.start(subManagerListener);
this.permissionManager = new PermissionManager(_internalInterface);
+ this.permissionManager.start(subManagerListener);
this.videoStreamingManager = new VideoStreamingManager(context, _internalInterface);
+ this.videoStreamingManager.start(subManagerListener);
this.audioStreamManager = new AudioStreamManager(_internalInterface);
+ this.audioStreamManager.start(subManagerListener);
*/
+
+ // If no managers, just call subManagerListener's onComplete
+ subManagerListener.onComplete(true);
}
private void dispose() {
@@ -230,34 +298,28 @@ public class SdlManager implements ProxyBridge.LifecycleListener {
return this;
}
- @SuppressWarnings("unchecked")
public SdlManager build() {
- try {
+ if (sdlManager.appName == null) {
+ throw new IllegalArgumentException("You must specify an app name by calling setAppName");
+ }
- if (sdlManager.appName == null) {
- throw new IllegalArgumentException("You must specify an app name by calling setAppName");
- }
+ if (sdlManager.appId == null) {
+ throw new IllegalArgumentException("You must specify an app ID by calling setAppId");
+ }
- if (sdlManager.appId == null) {
- throw new IllegalArgumentException("You must specify an app ID by calling setAppId");
- }
+ if (sdlManager.hmiTypes == null) {
+ Vector<AppHMIType> hmiTypesDefault = new Vector<>();
+ hmiTypesDefault.add(AppHMIType.DEFAULT);
+ sdlManager.hmiTypes = hmiTypesDefault;
+ sdlManager.isMediaApp = false;
+ }
- if (sdlManager.hmiTypes == null) {
- Vector<AppHMIType> hmiTypesDefault = new Vector<>();
- hmiTypesDefault.add(AppHMIType.DEFAULT);
- sdlManager.hmiTypes = hmiTypesDefault;
- sdlManager.isMediaApp = false;
- }
+ if (sdlManager.hmiLanguage == null){
+ sdlManager.hmiLanguage = Language.EN_US;
+ }
- if (sdlManager.hmiLanguage == null){
- sdlManager.hmiLanguage = Language.EN_US;
- }
+ sdlManager.state = BaseSubManager.SETTING_UP;
- sdlManager.initialize();
- sdlManager.proxy = new SdlProxyBase(sdlManager.proxyBridge, sdlManager.appName, sdlManager.shortAppName, sdlManager.isMediaApp, sdlManager.hmiLanguage, sdlManager.hmiLanguage, sdlManager.hmiTypes, sdlManager.appId, sdlManager.transport, sdlManager.vrSynonyms, sdlManager.ttsChunks, sdlManager.dayColorScheme, sdlManager.nightColorScheme) {};
- } catch (SdlException e) {
- e.printStackTrace();
- }
return sdlManager;
}
}
@@ -380,24 +442,23 @@ public class SdlManager implements ProxyBridge.LifecycleListener {
// LIFECYCLE / OTHER
- @Override
- public void onProxyClosed(String info, Exception e, SdlDisconnectedReason reason){
- this.dispose();
- }
-
- @Override
- public void onServiceEnded(OnServiceEnded serviceEnded){
-
- }
-
- @Override
- public void onServiceNACKed(OnServiceNACKed serviceNACKed){
-
- }
-
- @Override
- public void onError(String info, Exception e){
+ // STARTUP
+ /**
+ * Starts up a SdlManager, and calls provided callback called once all BaseSubManagers are done setting up
+ * @param listener CompletionListener that is called once the SdlManager state transitions
+ * from SETTING_UP to READY or ERROR
+ */
+ @SuppressWarnings("unchecked")
+ public void start(@NonNull CompletionListener listener){
+ initListener = listener;
+ try {
+ proxy = new SdlProxyBase(proxyBridge, appName, shortAppName, isMediaApp, hmiLanguage,
+ hmiLanguage, hmiTypes, appId, transport, vrSynonyms, ttsChunks, dayColorScheme,
+ nightColorScheme) {};
+ } catch (SdlException e) {
+ listener.onComplete(false);
+ }
}
// INTERNAL INTERFACE