summaryrefslogtreecommitdiff
path: root/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java')
-rw-r--r--android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java109
1 files changed, 78 insertions, 31 deletions
diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java
index af63c9219..9d24ddfec 100644
--- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java
+++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java
@@ -89,6 +89,7 @@ import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.protocol.enums.MessageType;
import com.smartdevicelink.protocol.enums.SessionType;
import com.smartdevicelink.proxy.rpc.UnregisterAppInterface;
+import com.smartdevicelink.proxy.rpc.VehicleType;
import com.smartdevicelink.transport.enums.TransportType;
import com.smartdevicelink.transport.utl.ByteAraryMessageAssembler;
import com.smartdevicelink.transport.utl.ByteArrayMessageSpliter;
@@ -141,7 +142,7 @@ public class SdlRouterService extends Service {
/**
* <b> NOTE: DO NOT MODIFY THIS UNLESS YOU KNOW WHAT YOU'RE DOING.</b>
*/
- protected static final int ROUTER_SERVICE_VERSION_NUMBER = 14;
+ protected static final int ROUTER_SERVICE_VERSION_NUMBER = 15;
private static final String ROUTER_SERVICE_PROCESS = "com.smartdevicelink.router";
@@ -201,6 +202,7 @@ public class SdlRouterService extends Service {
private boolean wrongProcess = false;
private boolean initPassed = false;
private boolean hasCalledStartForeground = false;
+ boolean firstStart = true;
public static HashMap<String, RegisteredApp> registeredApps;
private SparseArray<String> bluetoothSessionMap, usbSessionMap, tcpSessionMap;
@@ -212,6 +214,7 @@ public class SdlRouterService extends Service {
private static Messenger altTransportService = null;
private boolean startSequenceComplete = false;
+ private VehicleType receivedVehicleType;
private ExecutorService packetExecutor = null;
ConcurrentHashMap<TransportType, PacketWriteTaskMaster> packetWriteTaskMasterMap = null;
@@ -1096,6 +1099,28 @@ public class SdlRouterService extends Service {
DebugTool.logError(TAG, "Service isn't exported. Shutting down");
return false;
}
+
+ ComponentName name = new ComponentName(this, this.getClass());
+ SdlAppInfo currentAppInfo = null;
+
+ List<SdlAppInfo> sdlAppInfoList = AndroidTools.querySdlAppInfo(getApplicationContext(), new SdlAppInfo.BestRouterComparator(), null);
+ for (SdlAppInfo appInfo : sdlAppInfoList) {
+ if (appInfo.getRouterServiceComponentName().equals(name)) {
+ currentAppInfo = appInfo;
+ break;
+ }
+ }
+
+ if (currentAppInfo == null) {
+ DebugTool.logError(TAG, "AppInfo for current package is not available. Shutting down");
+ return false;
+ }
+
+ if (!SdlAppInfo.checkIfVehicleSupported(currentAppInfo.getSupportedVehicles(), receivedVehicleType)) {
+ DebugTool.logError(TAG, "Received vehicle data is not supported. Shutting down");
+ return false;
+ }
+
return true;
}
@@ -1118,37 +1143,13 @@ public class SdlRouterService extends Service {
hasCalledStartForeground = true;
resetForegroundTimeOut(FOREGROUND_TIMEOUT / 1000);
}
-
-
- if (!initCheck()) { // Run checks on process and permissions
- deployNextRouterService();
- closeSelf();
- return;
- }
- initPassed = true;
-
-
- synchronized (REGISTERED_APPS_LOCK) {
- registeredApps = new HashMap<String, RegisteredApp>();
- }
- closing = false;
-
- synchronized (SESSION_LOCK) {
- this.bluetoothSessionMap = new SparseArray<String>();
- this.sessionHashIdMap = new SparseIntArray();
- this.cleanedSessionMap = new SparseIntArray();
- }
-
- packetExecutor = Executors.newSingleThreadExecutor();
-
- startUpSequence();
}
/**
* The method will attempt to start up the next router service in line based on the sorting criteria of best router service.
*/
protected void deployNextRouterService() {
- List<SdlAppInfo> sdlAppInfoList = AndroidTools.querySdlAppInfo(getApplicationContext(), new SdlAppInfo.BestRouterComparator());
+ List<SdlAppInfo> sdlAppInfoList = AndroidTools.querySdlAppInfo(getApplicationContext(), new SdlAppInfo.BestRouterComparator(), null);
if (sdlAppInfoList != null && !sdlAppInfoList.isEmpty()) {
ComponentName name = new ComponentName(this, this.getClass());
SdlAppInfo info;
@@ -1250,6 +1251,37 @@ public class SdlRouterService extends Service {
@SuppressLint({"NewApi", "MissingPermission"})
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+ if (intent != null && intent.hasExtra(TransportConstants.VEHICLE_INFO_EXTRA)) {
+ receivedVehicleType = new VehicleType(
+ (HashMap<String, Object>) intent.getSerializableExtra(TransportConstants.VEHICLE_INFO_EXTRA)
+ );
+ }
+ // Only trusting the first intent received to start the RouterService and run initial checks to avoid a case where an app could send incorrect data after the spp connection has started.
+ if (firstStart) {
+ firstStart = false;
+ if (!initCheck()) { // Run checks on process and permissions
+ deployNextRouterService();
+ closeSelf();
+ return START_REDELIVER_INTENT;
+ }
+ initPassed = true;
+
+
+ synchronized (REGISTERED_APPS_LOCK) {
+ registeredApps = new HashMap<String, RegisteredApp>();
+ }
+ closing = false;
+
+ synchronized (SESSION_LOCK) {
+ this.bluetoothSessionMap = new SparseArray<String>();
+ this.sessionHashIdMap = new SparseIntArray();
+ this.cleanedSessionMap = new SparseIntArray();
+ }
+
+ packetExecutor = Executors.newSingleThreadExecutor();
+
+ startUpSequence();
+ }
if (intent != null) {
if (intent.getBooleanExtra(FOREGROUND_EXTRA, false)) {
hasCalledStartForeground = false;
@@ -1410,7 +1442,10 @@ public class SdlRouterService extends Service {
public void resetForegroundTimeOut(long delay) {
synchronized (FOREGROUND_NOTIFICATION_LOCK) {
if (foregroundTimeoutHandler == null) {
- foregroundTimeoutHandler = new Handler();
+ if (Looper.myLooper() == null) {
+ Looper.prepare();
+ }
+ foregroundTimeoutHandler = new Handler(Looper.myLooper());
}
if (foregroundTimeoutRunnable == null) {
foregroundTimeoutRunnable = new Runnable() {
@@ -1756,6 +1791,9 @@ public class SdlRouterService extends Service {
startService.putExtra(TransportConstants.FORCE_TRANSPORT_CONNECTED, true);
startService.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_APP_PACKAGE, getBaseContext().getPackageName());
startService.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME, new ComponentName(this, this.getClass()));
+ if (receivedVehicleType != null) {
+ startService.putExtra(TransportConstants.VEHICLE_INFO_EXTRA, receivedVehicleType.getStore());
+ }
if (record != null && record.getType() != null) {
startService.putExtra(TransportConstants.START_ROUTER_SERVICE_TRANSPORT_CONNECTED, record.getType().toString());
@@ -2416,7 +2454,7 @@ public class SdlRouterService extends Service {
/**
* Set the connection establishment status of the particular device
*
- * @param address address of the device in quesiton
+ * @param address address of the device in question
* @param hasSDLConnected true if a connection has been established, false if not
*/
protected void setSDLConnectedStatus(String address, boolean hasSDLConnected) {
@@ -2501,7 +2539,10 @@ public class SdlRouterService extends Service {
* This method is used to check for the newest version of this class to make sure the latest and greatest is up and running.
*/
private void startAltTransportTimer() {
- altTransportTimerHandler = new Handler();
+ if (Looper.myLooper() == null) {
+ Looper.prepare();
+ }
+ altTransportTimerHandler = new Handler(Looper.myLooper());
altTransportTimerRunnable = new Runnable() {
public void run() {
altTransportTimerHandler = null;
@@ -2833,6 +2874,9 @@ public class SdlRouterService extends Service {
pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_APP_PACKAGE, getBaseContext().getPackageName());
pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_CMP_NAME, new ComponentName(SdlRouterService.this, SdlRouterService.this.getClass()));
pingIntent.putExtra(TransportConstants.START_ROUTER_SERVICE_SDL_ENABLED_PING, true);
+ if (receivedVehicleType != null) {
+ pingIntent.putExtra(TransportConstants.VEHICLE_INFO_EXTRA, receivedVehicleType.getStore());
+ }
}
private void startClientPings() {
@@ -3057,7 +3101,10 @@ public class SdlRouterService extends Service {
this.messenger = messenger;
this.sessionIds = new Vector<Long>();
this.queues = new ConcurrentHashMap<>();
- queueWaitHandler = new Handler();
+ if (Looper.myLooper() == null) {
+ Looper.prepare();
+ }
+ queueWaitHandler = new Handler(Looper.myLooper());
registeredTransports = new SparseArray<ArrayList<TransportType>>();
awaitingSession = new Vector<>();
setDeathNote(); //messaging Version
@@ -3272,7 +3319,7 @@ public class SdlRouterService extends Service {
try {
List<TransportType> transportTypes = (List<TransportType>) obj;
if (transportTypes != null) {
- if (transportTypes.get(0) != null) {
+ if (transportTypes.size() > 0 && transportTypes.get(0) != null) {
return transportTypes.get(0);
}
}