diff options
author | Joey Grover <joeygrover@gmail.com> | 2018-09-04 12:17:45 -0400 |
---|---|---|
committer | Joey Grover <joeygrover@gmail.com> | 2018-09-04 12:17:45 -0400 |
commit | f034581393cd31cb7ca2f602e0d259b0b658b50e (patch) | |
tree | ecd2980ed9cb5d3bfcea85a112853709d2b40580 | |
parent | 945138507b464d1c4f31c0d0699f29fe1c89ba30 (diff) | |
download | sdl_android-f034581393cd31cb7ca2f602e0d259b0b658b50e.tar.gz |
Additional improvements to RS notificaiton
5 files changed, 42 insertions, 14 deletions
diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBaseTransport.java b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBaseTransport.java index eed5a524e..b7b7e3883 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBaseTransport.java +++ b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBaseTransport.java @@ -55,7 +55,9 @@ public abstract class MultiplexBaseTransport { protected final TransportType transportType; protected TransportRecord transportRecord; + @Deprecated public static String currentlyConnectedDevice = null; + protected String connectedDeviceName = null; public String connectedDeviceAddress = null; @@ -81,6 +83,10 @@ public abstract class MultiplexBaseTransport { return connectedDeviceAddress; } + public String getDeviceName(){ + return connectedDeviceName; + } + /** * Should only be called after a connection has been established * @return @@ -100,7 +106,7 @@ public abstract class MultiplexBaseTransport { public boolean isConnected() { - return !(mState == STATE_NONE); + return (mState == STATE_CONNECTED); } public synchronized void stop() { diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java index c0160d9d2..982eb0199 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java +++ b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexBluetoothTransport.java @@ -233,7 +233,7 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ //Store a static name of the device that is connected. if(device != null){ - currentlyConnectedDevice = device.getName(); + connectedDeviceName = device.getName(); connectedDeviceAddress = device.getAddress(); if(connectedDeviceAddress!=null){ //Update the transport record with the address @@ -244,8 +244,8 @@ public class MultiplexBluetoothTransport extends MultiplexBaseTransport{ // Send the name of the connected device back to the UI Activity Message msg = handler.obtainMessage(SdlRouterService.MESSAGE_DEVICE_NAME); Bundle bundle = new Bundle(); - if(currentlyConnectedDevice != null) { - bundle.putString(DEVICE_NAME, currentlyConnectedDevice); + if(connectedDeviceName != null) { + bundle.putString(DEVICE_NAME, connectedDeviceName); bundle.putString(DEVICE_ADDRESS, connectedDeviceAddress); } msg.setData(bundle); diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTcpTransport.java b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTcpTransport.java index 088008928..c4e2720bc 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTcpTransport.java +++ b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexTcpTransport.java @@ -71,7 +71,7 @@ public class MultiplexTcpTransport extends MultiplexBaseTransport { // Send the name of the connected device back to the UI Activity Message msg = handler.obtainMessage(SdlRouterService.MESSAGE_DEVICE_NAME); Bundle bundle = new Bundle(); - bundle.putString(DEVICE_NAME, currentlyConnectedDevice); + bundle.putString(DEVICE_NAME, connectedDeviceName); bundle.putString(DEVICE_ADDRESS, connectedDeviceAddress); msg.setData(bundle); handler.sendMessage(msg); diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexUsbTransport.java b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexUsbTransport.java index 64d9a6e5a..dcf763954 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexUsbTransport.java +++ b/sdl_android/src/main/java/com/smartdevicelink/transport/MultiplexUsbTransport.java @@ -74,7 +74,7 @@ public class MultiplexUsbTransport extends MultiplexBaseTransport{ throw new ExceptionInInitializerError("ParcelFileDescriptor can't be null"); }else{ this.parcelFileDescriptor = parcelFileDescriptor; - currentlyConnectedDevice = "USB"; + connectedDeviceName = "USB"; deviceInfo = bundle; if(deviceInfo != null){ //Fill in info @@ -108,7 +108,7 @@ public class MultiplexUsbTransport extends MultiplexBaseTransport{ // Send the name of the connected device back to the UI Activity Message msg = handler.obtainMessage(SdlRouterService.MESSAGE_DEVICE_NAME); Bundle bundle = new Bundle(); - bundle.putString(DEVICE_NAME, currentlyConnectedDevice); + bundle.putString(DEVICE_NAME, connectedDeviceName); bundle.putString(DEVICE_ADDRESS, connectedDeviceAddress); msg.setData(bundle); handler.sendMessage(msg); diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java b/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java index 490bb9434..73eee1a18 100644 --- a/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java +++ b/sdl_android/src/main/java/com/smartdevicelink/transport/SdlRouterService.java @@ -426,8 +426,8 @@ public class SdlRouterService extends Service{ returnBundle.putParcelableArrayList(TransportConstants.CURRENT_HARDWARE_CONNECTED, records); } - if(MultiplexBluetoothTransport.currentlyConnectedDevice!=null){ - returnBundle.putString(CONNECTED_DEVICE_STRING_EXTRA_NAME, MultiplexBluetoothTransport.currentlyConnectedDevice); + if(service.bluetoothTransport != null){ + returnBundle.putString(CONNECTED_DEVICE_STRING_EXTRA_NAME, service.bluetoothTransport.getDeviceName()); } } //Add the version of this router service @@ -1031,6 +1031,12 @@ public class SdlRouterService extends Service{ @Override public void onCreate() { super.onCreate(); + //This must be done regardless of if this service shuts down or not + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + enterForeground("Waiting for connection...", FOREGROUND_TIMEOUT/1000, false); + resetForegroundTimeOut(FOREGROUND_TIMEOUT/1000); + } + if(!initCheck()){ // Run checks on process and permissions deployNextRouterService(); @@ -1039,6 +1045,7 @@ public class SdlRouterService extends Service{ } initPassed = true; + synchronized(REGISTERED_APPS_LOCK){ registeredApps = new HashMap<String,RegisteredApp>(); } @@ -1146,6 +1153,8 @@ public class SdlRouterService extends Service{ int timeout = getNotificationTimeout(address); enterForeground("Waiting for connection...", timeout, false); resetForegroundTimeOut(timeout); + }else{ + enterForeground(createConnectedNotificationText(),0,true); } } if(intent.hasExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA)){ @@ -1415,16 +1424,29 @@ public class SdlRouterService extends Service{ } + /** + * Creates a notification message to attach to the foreground service notification. + * + * @return string to be used as the message + */ private String createConnectedNotificationText(){ StringBuilder builder = new StringBuilder(); builder.append("Connected to "); if(bluetoothTransport!= null && bluetoothTransport.isConnected()){ - builder.append(TransportType.BLUETOOTH.name().toLowerCase()); + if(bluetoothTransport.getDeviceName() != null){ + builder.append(bluetoothTransport.getDeviceName()); + if(0 == (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) { + //If this is production, just the device name is fine + return builder.toString(); + } + }else{ + builder.append(TransportType.BLUETOOTH.name().toLowerCase()); + } } if(usbTransport != null && usbTransport.isConnected()){ - if(builder.length() > 0){ + if(builder.length() > 13){ //13 characters for initial Connected to string builder.append(" & "); } builder.append(TransportType.USB.name()); @@ -1557,7 +1579,7 @@ public class SdlRouterService extends Service{ } } - + //public void onTransportConnected(final TransportType type){ //TODO // } @@ -1608,8 +1630,8 @@ public class SdlRouterService extends Service{ bundle.putString(TransportConstants.HARDWARE_CONNECTED, record.getType().name()); bundle.putParcelableArrayList(TransportConstants.CURRENT_HARDWARE_CONNECTED, getConnectedTransports()); - if(MultiplexBluetoothTransport.currentlyConnectedDevice!=null){ - bundle.putString(CONNECTED_DEVICE_STRING_EXTRA_NAME, MultiplexBluetoothTransport.currentlyConnectedDevice); + if(bluetoothTransport != null){ + bundle.putString(CONNECTED_DEVICE_STRING_EXTRA_NAME, bluetoothTransport.getDeviceName()); } message.setData(bundle); |