diff options
author | Austin Kirk <askirk@umich.edu> | 2017-06-14 14:44:01 -0400 |
---|---|---|
committer | Austin Kirk <askirk@umich.edu> | 2017-06-14 14:44:01 -0400 |
commit | 61f4a133c75742f630ae7961bbeab8b84caf1b00 (patch) | |
tree | 15a68e64f04fcb3f4883525185fc22858d2b0c3b | |
parent | e1dbf771546f0d66131b8fef5cb95c1ed5f9bbb7 (diff) | |
download | sdl_android-61f4a133c75742f630ae7961bbeab8b84caf1b00.tar.gz |
SystemCapabilityManager editsfeature/issue_486_improvements
-Adding CAN_REQUEST_FOR flag in SystemCapabilityType enums
-SystemCapabilityListener for callbacks when requesting a capability
-New callback approach for getSystemCapability()
4 files changed, 84 insertions, 51 deletions
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java index 1205827e4..0fec49ca2 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java +++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/SdlProxyBase.java @@ -80,6 +80,7 @@ import com.smartdevicelink.proxy.rpc.enums.SdlConnectionState; import com.smartdevicelink.proxy.rpc.enums.SdlDisconnectedReason;
import com.smartdevicelink.proxy.rpc.enums.SdlInterfaceAvailability;
import com.smartdevicelink.proxy.rpc.enums.SpeechCapabilities;
+import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
import com.smartdevicelink.proxy.rpc.enums.TextAlignment;
import com.smartdevicelink.proxy.rpc.enums.UpdateMode;
@@ -87,6 +88,7 @@ import com.smartdevicelink.proxy.rpc.enums.VrCapabilities; import com.smartdevicelink.proxy.rpc.listeners.OnPutFileUpdateListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
+import com.smartdevicelink.proxy.rpc.listeners.SystemCapabilityListener;
import com.smartdevicelink.security.SdlSecurityBase;
import com.smartdevicelink.streaming.StreamRPCPacketizer;
import com.smartdevicelink.trace.SdlTrace;
@@ -216,6 +218,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> protected String _proxyVersionInfo = null;
protected Boolean _bResumeSuccess = false;
protected List<Class<? extends SdlSecurityBase>> _secList = null;
+ protected SystemCapabilityManager _systemCapabilityManager;
private CopyOnWriteArrayList<IPutFileResponseListener> _putFileListenerList = new CopyOnWriteArrayList<IPutFileResponseListener>();
@@ -2027,6 +2030,7 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> _hmiCapabilities = msg.getHmiCapabilities();
_systemSoftwareVersion = msg.getSystemSoftwareVersion();
_proxyVersionInfo = msg.getProxyVersionInfo();
+ _systemCapabilityManager = new SystemCapabilityManager(msg);
if (_bAppResumeEnabled)
{
@@ -5610,5 +5614,9 @@ public abstract class SdlProxyBase<proxyListenerType extends IProxyListenerBase> {
return sPoliciesURL;
}
+
+ public void getSystemCapability(SystemCapabilityType systemCapabilityType, SystemCapabilityListener scListener){
+ _systemCapabilityManager.getSystemCapability(this, systemCapabilityType, scListener);
+ }
} // end-class
diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java index 0a03d0b56..7505bb511 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java +++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/SystemCapabilityManager.java @@ -3,80 +3,77 @@ package com.smartdevicelink.proxy; import com.smartdevicelink.exception.SdlException; import com.smartdevicelink.proxy.rpc.GetSystemCapability; import com.smartdevicelink.proxy.rpc.GetSystemCapabilityResponse; +import com.smartdevicelink.proxy.rpc.RegisterAppInterfaceResponse; import com.smartdevicelink.proxy.rpc.SystemCapability; import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType; import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener; +import com.smartdevicelink.proxy.rpc.listeners.SystemCapabilityListener; import com.smartdevicelink.util.CorrelationIdGenerator; import java.util.HashMap; -/** - * Created by austinkirk on 6/12/17. - */ - public class SystemCapabilityManager { - HashMap<String, Object> cachedSystemCapabilities = new HashMap<>(); - SdlProxyALM proxy = null; - final Object SYS_CAP_LOCK = new Object(); + HashMap<SystemCapabilityType, Object> cachedSystemCapabilities = new HashMap<>(); + RegisterAppInterfaceResponse raiResponse; - public SystemCapabilityManager(SdlProxyALM proxyALM){ - proxy = proxyALM; + public SystemCapabilityManager(RegisterAppInterfaceResponse raiResponse){ + this.raiResponse = raiResponse; } - public Object getSystemCapability(final SystemCapabilityType systemCapabilityType) throws SdlException { - Object obj = cachedSystemCapabilities.get(systemCapabilityType.toString()); + public void getSystemCapability(SdlProxyBase proxy, final SystemCapabilityType systemCapabilityType, final SystemCapabilityListener scListener){ + Object obj = cachedSystemCapabilities.get(systemCapabilityType); if(obj != null){ - return obj; + scListener.onCapabilityRetrieved(obj); } if(systemCapabilityType.equals(SystemCapabilityType.NAVIGATION)){ - if(!proxy.getHmiCapabilities().isNavigationAvailable()){ - return null; + if(!raiResponse.getHmiCapabilities().isNavigationAvailable()){ + scListener.onCapabilityRetrieved(null); + return; } }else if(systemCapabilityType.equals(SystemCapabilityType.PHONE_CALL)){ - if(!proxy.getHmiCapabilities().isPhoneCallAvailable()){ - return null; + if(!raiResponse.getHmiCapabilities().isPhoneCallAvailable()){ + scListener.onCapabilityRetrieved(null); + return; } }else if(systemCapabilityType.equals(SystemCapabilityType.VIDEO_STREAMING)){ - if(!proxy.getHmiCapabilities().isVideoStreamingAvailable()){ - return null; + if(!raiResponse.getHmiCapabilities().isVideoStreamingAvailable()){ + scListener.onCapabilityRetrieved(null); + return; } }else if(systemCapabilityType.equals(SystemCapabilityType.AUDIO_STREAMING)){ - if(!proxy.getHmiCapabilities().isAudioStreamingAvailable()){ - return null; + if(!raiResponse.getHmiCapabilities().isAudioStreamingAvailable()){ + scListener.onCapabilityRetrieved(null); + return; } + }else if(systemCapabilityType.equals(SystemCapabilityType.DISPLAY)){ + scListener.onCapabilityRetrieved(raiResponse.getDisplayCapabilities()); + return; } - final GetSystemCapability request = new GetSystemCapability(); - request.setSystemCapabilityType(systemCapabilityType); - request.setOnRPCResponseListener(new OnRPCResponseListener() { - @Override - public void onResponse(int correlationId, RPCResponse response) { - if(response.getSuccess()){ - SystemCapability systemCapability = ((GetSystemCapabilityResponse) response).getSystemCapability(); - Object capability = systemCapability.getCapabilityForType(systemCapabilityType); - if(capability != null) { - synchronized(SYS_CAP_LOCK){ - SYS_CAP_LOCK.notify(); - } - cachedSystemCapabilities.put(systemCapabilityType.toString(), capability); + if(systemCapabilityType.canRequestFor()){ + final GetSystemCapability request = new GetSystemCapability(); + request.setSystemCapabilityType(systemCapabilityType); + request.setOnRPCResponseListener(new OnRPCResponseListener() { + @Override + public void onResponse(int correlationId, RPCResponse response) { + if(response.getSuccess()){ + SystemCapability systemCapability = ((GetSystemCapabilityResponse) response).getSystemCapability(); + Object capability = systemCapability.getCapabilityForType(systemCapabilityType); + cachedSystemCapabilities.put(systemCapabilityType, capability); + scListener.onCapabilityRetrieved(capability); } } - } - }); - request.setCorrelationID(CorrelationIdGenerator.generateId()); - proxy.sendRPCRequest(request); - - synchronized(SYS_CAP_LOCK) { + }); + request.setCorrelationID(CorrelationIdGenerator.generateId()); try { - SYS_CAP_LOCK.wait(); - } catch (InterruptedException e) { + proxy.sendRPCRequest(request); + } catch (SdlException e) { e.printStackTrace(); } + }else{ + scListener.onCapabilityRetrieved(null); } - - obj = cachedSystemCapabilities.get(systemCapabilityType.toString()); - return obj; } } diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java index 54bd1f932..803856d48 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java +++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/enums/SystemCapabilityType.java @@ -1,23 +1,46 @@ package com.smartdevicelink.proxy.rpc.enums; +import java.util.EnumSet; + /** * The SystemCapabilityType indicates which type of capability information exists in a SystemCapability struct. */ public enum SystemCapabilityType { - NAVIGATION, + NAVIGATION("NAVIGATION", true), + + PHONE_CALL("PHONE_CALL", true), + + VIDEO_STREAMING("VIDEO_STREAMING", true), + + AUDIO_STREAMING("AUDIO_STREAMING", true), + + DISPLAY("DISPLAY", false); - PHONE_CALL, + private final String INTERNAL_NAME; + private final boolean CAN_REQUEST_FOR; - VIDEO_STREAMING, + private SystemCapabilityType(String internalName, boolean requestable){ + this.INTERNAL_NAME = internalName; + this.CAN_REQUEST_FOR = requestable; + } + + public String toString() { + return this.INTERNAL_NAME; + } - AUDIO_STREAMING; + public Boolean canRequestFor() {return this.CAN_REQUEST_FOR;} public static SystemCapabilityType valueForString(String value) { - try{ - return valueOf(value); - }catch(Exception e){ + if(value == null){ return null; } + + for (SystemCapabilityType anEnum : EnumSet.allOf(SystemCapabilityType.class)) { + if (anEnum.toString().equals(value)) { + return anEnum; + } + } + return null; } } diff --git a/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/listeners/SystemCapabilityListener.java b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/listeners/SystemCapabilityListener.java new file mode 100644 index 000000000..02934ce26 --- /dev/null +++ b/sdl_android/src/main/java/com/smartdevicelink/proxy/rpc/listeners/SystemCapabilityListener.java @@ -0,0 +1,5 @@ +package com.smartdevicelink.proxy.rpc.listeners; + +public abstract class SystemCapabilityListener { + public abstract void onCapabilityRetrieved(Object capability); +} |