summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2017-07-27 15:05:39 -0400
committerGitHub <noreply@github.com>2017-07-27 15:05:39 -0400
commit6c8a2c1aaaa5aab1001a9c9cc0f2b29e790f2022 (patch)
treed71591e0d4bb4432a01ddaf1cf1892f59df4efcd
parent9295bf57bc78bd81f71a4cbdc6e6e6f6c3bbd661 (diff)
parent060a3ac7ab820f7631e515f6f3a21479648f4b4d (diff)
downloadsdl_android-6c8a2c1aaaa5aab1001a9c9cc0f2b29e790f2022.tar.gz
Merge pull request #571 from smartdevicelink/bugfix/issue_569
Bugfix/issue 569
-rw-r--r--sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java37
-rw-r--r--sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java5
2 files changed, 41 insertions, 1 deletions
diff --git a/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java b/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
index a6dfe613a..e40049afd 100644
--- a/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
+++ b/sdl_android/src/androidTest/java/com/smartdevicelink/transport/RSVTestCase.java
@@ -1,5 +1,8 @@
package com.smartdevicelink.transport;
+import android.app.ActivityManager;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.test.AndroidTestCase;
@@ -392,6 +395,38 @@ public class RSVTestCase extends AndroidTestCase {
releaseTListLock();
}
-
+
+ /**
+ * Test app's router validation. Validation should fail when the given context and ComponentName object are from different packages and security setting is not OFF
+ * and app is not on trusted list. Validation should pass when the given context and ComponentName object are from the same package.
+ */
+ public void testAppSelfValidation() {
+
+ class RouterServiceValidatorTest extends RouterServiceValidator{
+ public RouterServiceValidatorTest(Context context){
+ super(context);
+ }
+
+ public RouterServiceValidatorTest(Context context, ComponentName service){
+ super(context, service);
+ }
+
+ // Override this method and simply returning true for the purpose of this test
+ protected boolean isServiceRunning(Context context, ComponentName service){
+ return true;
+ }
+ }
+
+ // Fail, different package name for context and service and app security setting is not OFF and app is not on trusted list
+ RouterServiceValidatorTest rsvpFail = new RouterServiceValidatorTest(this.mContext, new ComponentName("anything", mContext.getClass().getSimpleName()));
+ rsvpFail.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
+ assertFalse(rsvpFail.validate());
+
+ // Success, same package name for context and service
+ RouterServiceValidatorTest rsvpPass = new RouterServiceValidatorTest(this.mContext, new ComponentName(mContext.getPackageName(), mContext.getClass().getSimpleName()));
+ rsvpPass.setSecurityLevel(MultiplexTransportConfig.FLAG_MULTI_SECURITY_HIGH);
+ assertTrue(rsvpPass.validate());
+ }
+
}
diff --git a/sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java b/sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java
index b42732d3a..66e415f29 100644
--- a/sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java
+++ b/sdl_android/src/main/java/com/smartdevicelink/transport/RouterServiceValidator.java
@@ -121,6 +121,11 @@ public class RouterServiceValidator {
//This means our service isn't actually running, so set to null. Hopefully we can find a real router service after this.
service = null;
Log.w(TAG, "Supplied service is not actually running.");
+ } else {
+ // If the running router service is created by this app, the validation is good by default
+ if (this.service.getPackageName().equals(context.getPackageName())) {
+ return true;
+ }
}
}
if(this.service == null){