diff options
author | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2020-09-09 14:11:01 -0400 |
---|---|---|
committer | Bilal Alsharifi <bilal.alsharifi@gmail.com> | 2020-09-09 14:11:01 -0400 |
commit | 8801e66d4116048fbe3e295a598288b7adfa84da (patch) | |
tree | f9a314b6f952beb8be944ad9c844fb7faba8f1de | |
parent | 6dfaf8a1a97b427f36af3584794b80e539d2cfbb (diff) | |
parent | e532c9dc612825ee905a8447063e48e0548fc605 (diff) | |
download | sdl_android-8801e66d4116048fbe3e295a598288b7adfa84da.tar.gz |
Merge branch 'develop' into feature/optimize_imports
6 files changed, 37 insertions, 172 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java index 3ed6320b4..d9af0faed 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RegisteredAppTests.java @@ -5,6 +5,8 @@ import android.os.Messenger; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.smartdevicelink.transport.enums.TransportType; + import org.junit.Test; import org.junit.runner.RunWith; @@ -31,10 +33,10 @@ public class RegisteredAppTests { // Instantiate SdlRouterService and Registered App class SdlRouterService router = new SdlRouterService(); - SdlRouterService.RegisteredApp app = router.new RegisteredApp(APP_ID, messenger); + SdlRouterService.RegisteredApp app = router.new RegisteredApp(APP_ID, 1, messenger); // Call Handle Message - app.handleMessage(TransportConstants.BYTES_TO_SEND_FLAG_LARGE_PACKET_START,bytes); + app.handleMessage(TransportConstants.BYTES_TO_SEND_FLAG_LARGE_PACKET_START,bytes, TransportType.BLUETOOTH); // Insure that the buffer is not null, if it is the test will fail assertNotNull(app.buffer); @@ -51,13 +53,13 @@ public class RegisteredAppTests { // Instantiate SdlRouterService and Registered App class SdlRouterService router = new SdlRouterService(); - SdlRouterService.RegisteredApp app = router.new RegisteredApp(APP_ID, messenger); + SdlRouterService.RegisteredApp app = router.new RegisteredApp(APP_ID, 1, messenger); // Force Null Buffer app.buffer = null; // Call Handle Message - Making sure it doesn't init buffer - app.handleMessage(TransportConstants.BYTES_TO_SEND_FLAG_NONE,bytes); + app.handleMessage(TransportConstants.BYTES_TO_SEND_FLAG_NONE, bytes, TransportType.BLUETOOTH); // Insure that the buffer is null. and no NPE assertNull(app.buffer); diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java index 0099f8e43..2ab12e51a 100644 --- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java +++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/transport/SdlRouterServiceTests.java @@ -188,8 +188,8 @@ public class SdlRouterServiceTests { // We need a registered app for this to work Message message = Message.obtain(); - SdlRouterService.RegisteredApp app1 = sdlRouterService.new RegisteredApp("12345",message.replyTo); - SdlRouterService.RegisteredApp app2 = sdlRouterService.new RegisteredApp("12344",message.replyTo); + SdlRouterService.RegisteredApp app1 = sdlRouterService.new RegisteredApp("12345", 1, message.replyTo); + SdlRouterService.RegisteredApp app2 = sdlRouterService.new RegisteredApp("12344", 1, message.replyTo); HashMap<String,SdlRouterService.RegisteredApp> registeredApps = new HashMap<>(); registeredApps.put(app1.getAppId(),app1); registeredApps.put(app2.getAppId(),app2); @@ -281,8 +281,8 @@ public class SdlRouterServiceTests { // We need a registered app for this to work Message message = Message.obtain(); - SdlRouterService.RegisteredApp app1 = sdlRouterService.new RegisteredApp("12345",message.replyTo); - SdlRouterService.RegisteredApp app2 = sdlRouterService.new RegisteredApp("12344",message.replyTo); + SdlRouterService.RegisteredApp app1 = sdlRouterService.new RegisteredApp("12345", 1, message.replyTo); + SdlRouterService.RegisteredApp app2 = sdlRouterService.new RegisteredApp("12344", 1, message.replyTo); HashMap<String,SdlRouterService.RegisteredApp> registeredApps = new HashMap<>(); registeredApps.put(app1.getAppId(),app1); registeredApps.put(app2.getAppId(),app2); @@ -689,7 +689,7 @@ public class SdlRouterServiceTests { private void addDummyRegisteredApp(SdlRouterService routerService, String appId, int sessionId) throws IllegalAccessException, NoSuchFieldException { Message message = Message.obtain(); - SdlRouterService.RegisteredApp app = routerService.new RegisteredApp(appId, message.replyTo); + SdlRouterService.RegisteredApp app = routerService.new RegisteredApp(appId, 1, message.replyTo); Field raf = routerService.getClass().getDeclaredField("registeredApps"); raf.setAccessible(true); 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 7d44fd2af..9ed6b9d03 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 @@ -153,11 +153,6 @@ public class SdlRouterService extends Service{ public static final String SDL_NOTIFICATION_FAQS_PAGE = "https://smartdevicelink.com/en/guides/android/frequently-asked-questions/sdl-notifications/"; - /** - * @deprecated use {@link TransportConstants#START_ROUTER_SERVICE_ACTION} instead - */ - @Deprecated - public static final String START_SERVICE_ACTION = "sdl.router.startservice"; public static final String REGISTER_WITH_ROUTER_ACTION = "com.sdl.android.register"; /** Message types sent from the BluetoothReadService Handler */ @@ -1611,12 +1606,6 @@ public class SdlRouterService extends Service{ *********************************************** Helper Methods ************************************************************** ****************************************************************************************************************************************/ - @SuppressWarnings("SameReturnValue") - @Deprecated - public String getConnectedDeviceName(){ - return null; - } - private ArrayList<TransportRecord> getConnectedTransports(){ ArrayList<TransportRecord> connected = new ArrayList<>(); if(bluetoothTransport != null && bluetoothTransport.isConnected()){ @@ -1734,11 +1723,6 @@ public class SdlRouterService extends Service{ } } - @Deprecated - public void onTransportConnected(final TransportType type){ - onTransportConnected(new TransportRecord(type,null)); - } - public void onTransportConnected(final TransportRecord record){ cancelForegroundTimeOut(); enterForeground(createConnectedNotificationText(),0,true); @@ -1799,11 +1783,6 @@ public class SdlRouterService extends Service{ } - @Deprecated - public void onTransportDisconnected(TransportType type) { - onTransportDisconnected(new TransportRecord(type,null)); - } - public void onTransportDisconnected(TransportRecord record){ cachedModuleVersion = -1; //Reset our cached version //Stop any current pings being sent before the proper state can be determined. @@ -1912,16 +1891,6 @@ public class SdlRouterService extends Service{ } } - @Deprecated - public void onTransportError(TransportType transportType){ - onTransportError(new TransportRecord(transportType,null), null); - } - - @Deprecated - public void onTransportError(TransportRecord record) { - onTransportError(record, null); - } - public void onTransportError(TransportRecord transport, Bundle errorBundle){ switch (transport.getType()){ case BLUETOOTH: @@ -2430,29 +2399,6 @@ public class SdlRouterService extends Service{ //************************************************************************************************************************************** //********************************************************* PREFERENCES **************************************************************** //************************************************************************************************************************************** - /** - * @deprecated - * This method will set the last known bluetooth connection method that worked with this phone. - * This helps speed up the process of connecting - * @param level The level of bluetooth connecting method that last worked - * @param prefLocation Where the preference should be stored - */ - @SuppressWarnings("DeprecatedIsStillUsed") - @Deprecated - public static void setBluetoothPrefs (int level, String prefLocation) { - DebugTool.logWarning(TAG, "This method is deprecated and will not take any action"); - } - - /** - * @deprecated - * This method has been deprecated as it was bad practice. - */ - @SuppressWarnings({"DeprecatedIsStillUsed", "SameReturnValue"}) - @Deprecated - public static int getBluetoothPrefs(String prefLocation) - { - return 0; - } /** * Set the connection establishment status of the particular device @@ -3076,24 +3022,6 @@ public class SdlRouterService extends Service{ /** * This is a simple class to hold onto a reference of a registered app. * @param appId the supplied id for this app that is attempting to register - * @param messenger the specific messenger that is tied to this app - */ - @Deprecated - public RegisteredApp(String appId, Messenger messenger){ - this.appId = appId; - this.messenger = messenger; - this.sessionIds = new Vector<Long>(); - this.queues = new ConcurrentHashMap<>(); - queueWaitHandler = new Handler(); - registeredTransports = new SparseArray<ArrayList<TransportType>>(); - awaitingSession = new Vector<>(); - setDeathNote(); - routerMessagingVersion = 1; - } - - /** - * This is a simple class to hold onto a reference of a registered app. - * @param appId the supplied id for this app that is attempting to register * @param routerMessagingVersion * @param messenger the specific messenger that is tied to this app */ @@ -3374,11 +3302,6 @@ public class SdlRouterService extends Service{ } } - @Deprecated - public void handleMessage(int flags, byte[] packet) { - handleMessage(flags,packet,null); - } - public void handleMessage(int flags, byte[] packet, TransportType transportType){ if(flags == TransportConstants.BYTES_TO_SEND_FLAG_LARGE_PACKET_START){ clearBuffer(); @@ -3515,12 +3438,6 @@ public class SdlRouterService extends Service{ private final long timestamp; final Bundle receivedBundle; TransportType transportType; - - @SuppressWarnings("SameParameterValue") - @Deprecated - public PacketWriteTask(byte[] bytes, int offset, int size, int priorityCoefficient) { - this(bytes, offset, size, priorityCoefficient,null); - } public PacketWriteTask(byte[] bytes, int offset, int size, int priorityCoefficient, TransportType transportType){ timestamp = System.currentTimeMillis(); diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java index 3851ab563..e2e3c1d87 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportBroker.java @@ -49,6 +49,9 @@ import android.os.Parcelable; import android.os.RemoteException; import android.os.TransactionTooLargeException; +import androidx.annotation.NonNull; +import androidx.annotation.RestrictTo; + import com.smartdevicelink.protocol.SdlPacket; import com.smartdevicelink.transport.enums.TransportType; import com.smartdevicelink.transport.utl.ByteAraryMessageAssembler; @@ -65,6 +68,7 @@ import java.util.List; import java.util.Locale; +@RestrictTo(RestrictTo.Scope.LIBRARY) public class TransportBroker { private static final String TAG = "SdlTransportBroker"; @@ -80,9 +84,9 @@ public class TransportBroker { private static final TransportRecord LEGACY_TRANSPORT_RECORD = new TransportRecord(TransportType.BLUETOOTH,null); private final String WHERE_TO_REPLY_PREFIX = "com.sdl.android."; - private String appId = null; - private String whereToReply = null; - private Context currentContext = null; + private String appId; + private String whereToReply; + private Context currentContext; private final Object INIT_LOCK = new Object(); private final Object MESSAGE_SEND_LOCK = new Object(); @@ -235,7 +239,6 @@ public class TransportBroker { broker.registeredWithRouterService = false; broker.enableLegacyMode(true); //We call this so we can start the process of legacy connection - //onHardwareDisconnected(TransportType.BLUETOOTH); broker.onLegacyModeEnabled(); break; default: @@ -251,7 +254,6 @@ public class TransportBroker { if (msg.arg1 == TransportConstants.UNREGISTRATION_RESPONSE_SUCESS) { // We've been unregistered. Now what? - } else { //We were denied our unregister request to the router service, let's see why DebugTool.logWarning(TAG, "Unregister request denied from router service. Reason - " + msg.arg1); //Do we care? @@ -263,7 +265,7 @@ public class TransportBroker { DebugTool.logWarning(TAG, "Received packet message from router service with no bundle"); return; } - //So the intent has a packet with it. PEFRECT! Let's send it through the library + //So the intent has a packet with it. PERFECT! Let's send it through the library int flags = bundle.getInt(TransportConstants.BYTES_TO_SEND_FLAGS, TransportConstants.BYTES_TO_SEND_FLAG_NONE); if (bundle.containsKey(TransportConstants.FORMED_PACKET_EXTRA_NAME)) { @@ -310,10 +312,8 @@ public class TransportBroker { broker.bufferedPacket = null; } } - //} - //} } else { - DebugTool.logWarning(TAG, "Flase positive packet reception"); + DebugTool.logWarning(TAG, "False positive packet reception"); } break; case TransportConstants.HARDWARE_CONNECTION_EVENT: @@ -393,25 +393,19 @@ public class TransportBroker { @SuppressLint("SimpleDateFormat") - public TransportBroker(Context context, String appId, ComponentName service) { + public TransportBroker(@NonNull Context context, @NonNull String appId, @NonNull ComponentName service) { synchronized (INIT_LOCK) { + this.appId = appId; + currentContext = context; + this.routerService = service; + clientMessenger = new Messenger(new ClientHandler(this)); initRouterConnection(); - //So the user should have set the AppId, lets define where the intents need to be sent + + //So the user should have set the AppId, lets define where the messages need to be sent SimpleDateFormat s = new SimpleDateFormat("hhmmssss"); //So we have a time stamp of the event String timeStamp = s.format(new Date(System.currentTimeMillis())); - if (whereToReply == null) { - if (appId == null) { //This should really just throw an error - whereToReply = WHERE_TO_REPLY_PREFIX + "." + timeStamp; - } else { - whereToReply = WHERE_TO_REPLY_PREFIX + appId + "." + timeStamp; - } - } - //this.appId = appId.concat(timeStamp); - this.appId = appId; - currentContext = context; - //Log.d(TAG, "Registering our reply receiver: " + whereToReply); - this.routerService = service; + whereToReply = WHERE_TO_REPLY_PREFIX + appId + "." + timeStamp; } } @@ -422,7 +416,7 @@ public class TransportBroker { //Log.d(TAG, "Starting up transport broker for " + whereToReply); synchronized (INIT_LOCK) { if (currentContext == null) { - throw new IllegalStateException("This instance can't be started since it's local reference of context is null. Ensure when suppling a context to the TransportBroker that it is valid"); + throw new IllegalStateException("This instance can't be started since it's local reference of context is null. Ensure when supplying a context to the TransportBroker that it is valid"); } if (routerConnection == null) { initRouterConnection(); @@ -479,31 +473,11 @@ public class TransportBroker { public void onServiceUnregsiteredFromRouterService(int unregisterCode) { } - @Deprecated - public void onHardwareDisconnected(TransportType type) { - stop(); - } public void onHardwareDisconnected(TransportRecord record, List<TransportRecord> connectedTransports) { } - /** - * WILL NO LONGER BE CALLED - * - * @param type - * @return - */ - @Deprecated - public boolean onHardwareConnected(TransportType type) { - synchronized (INIT_LOCK) { - if (routerServiceMessenger == null) { - return false; - } - return true; - } - } - public boolean onHardwareConnected(List<TransportRecord> transports) { synchronized (INIT_LOCK) { if (routerServiceMessenger == null && transports != null && transports.size() > 0) { @@ -525,30 +499,6 @@ public class TransportBroker { return routerServiceVersion; } - /** - * We want to check to see if the Router service is already up and running - * - * @param context - * @return - */ - private boolean isRouterServiceRunning(Context context) { - if (context == null) { - - return false; - } - ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); - for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { - //We will check to see if it contains this name, should be pretty specific - if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SdlBroadcastReceiver.SDL_ROUTER_SERVICE_CLASS_NAME)) { - this.routerClassName = service.service.getClassName(); - this.routerPackage = service.service.getPackageName(); - return true; - } - } - return false; - } - - public boolean sendPacketToRouterService(SdlPacket packet) { //We use ints because that is all that is supported by the outputstream class //Log.d(TAG,whereToReply + "Sending packet to router service"); @@ -617,16 +567,14 @@ public class TransportBroker { } //Make sure we know where to bind to if (this.routerService == null) { - if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.O) && !isRouterServiceRunning(getContext())) {//We should be able to ignore this case because of the validation now - DebugTool.logInfo(TAG, whereToReply + " found no router service. Shutting down."); - this.onHardwareDisconnected(null); - return false; - } - } else {//We were already told where to bind. This should be the case. - this.routerClassName = this.routerService.getClassName(); - this.routerPackage = this.routerService.getPackageName(); + DebugTool.logInfo(TAG, whereToReply + " has no router service reference; should shut down."); + return false; } + this.routerClassName = this.routerService.getClassName(); + this.routerPackage = this.routerService.getPackageName(); + + if (!sendBindingIntent()) { DebugTool.logError(TAG, "Something went wrong while trying to bind with the router service."); SdlBroadcastReceiver.queryForConnectedService(currentContext); diff --git a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java index c653c7d93..e3614faa9 100644 --- a/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java +++ b/android/sdl_android/src/main/java/com/smartdevicelink/transport/TransportManager.java @@ -97,7 +97,7 @@ public class TransportManager extends TransportManagerBase{ @Override public void onFinishedValidation(boolean valid, ComponentName name) { DebugTool.logInfo(TAG, "onFinishedValidation valid=" + valid + "; name=" + ((name == null)? "null" : name.getPackageName())); - if (valid) { + if (valid && name != null) { mConfig.service = name; transport = new TransportBrokerImpl(contextWeakReference.get(), mConfig.appId, mConfig.service); DebugTool.logInfo(TAG, "TransportManager start was called; transport=" + transport); diff --git a/base/src/main/java/com/smartdevicelink/transport/TransportConstants.java b/base/src/main/java/com/smartdevicelink/transport/TransportConstants.java index 19579c19b..7fbcde80d 100644 --- a/base/src/main/java/com/smartdevicelink/transport/TransportConstants.java +++ b/base/src/main/java/com/smartdevicelink/transport/TransportConstants.java @@ -65,8 +65,6 @@ public class TransportConstants { public static final String FORCE_TRANSPORT_CONNECTED = "force_connect"; //This is legacy, do not refactor this. public static final String ROUTER_SERVICE_VALIDATED = "router_service_validated"; - @Deprecated - public static final String REPLY_TO_INTENT_EXTRA = "ReplyAddress"; public static final String CONNECT_AS_CLIENT_BOOLEAN_EXTRA = "connectAsClient"; public static final String PACKAGE_NAME_STRING = "package.name"; public static final String APP_ID_EXTRA = "app.id";//Sent as a Long. This is no longer used @@ -78,7 +76,7 @@ public class TransportConstants { public static final String ENABLE_LEGACY_MODE_EXTRA = "ENABLE_LEGACY_MODE_EXTRA"; @Deprecated - public static final String HARDWARE_DISCONNECTED = "hardware.disconect"; + public static final String HARDWARE_DISCONNECTED = "hardware.disconect"; //This is legacy, do not refactor this. public static final String TRANSPORT_DISCONNECTED = "transport.disconect"; public static final String HARDWARE_CONNECTED = "hardware.connected"; public static final String CURRENT_HARDWARE_CONNECTED = "current.hardware.connected"; |