From 4cab12d91d120ee93e135050b78edb335e9ac91b Mon Sep 17 00:00:00 2001 From: Shirish Kalele Date: Thu, 6 Aug 2015 12:34:22 -0700 Subject: Fix check for caller being the active network scorer Compare caller and scorer uids to decide if caller is the active scorer instead of calling AppOps.checkPackage(). Bug: 23000690 Change-Id: I64285f965716f3aceb24f193d86ab9d6be7202c5 --- .../src/android/net/NetworkScorerAppManagerTest.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'core/tests') diff --git a/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java b/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java index 9bb44d0..605f067 100644 --- a/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java +++ b/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java @@ -57,16 +57,19 @@ public class NetworkScorerAppManagerTest extends InstrumentationTestCase { public void testGetAllValidScorers() throws Exception { // Package 1 - Valid scorer. - Pair package1 = buildResolveInfo("package1", true, true, false); + Pair package1 = buildResolveInfo("package1", 1, true, true, + false); // Package 2 - Receiver does not have BROADCAST_NETWORK_PRIVILEGED permission. - Pair package2 = buildResolveInfo("package2", false, true, false); + Pair package2 = buildResolveInfo("package2", 2, false, true, + false); // Package 3 - App does not have SCORE_NETWORKS permission. - Pair package3 = buildResolveInfo("package3", true, false, false); + Pair package3 = buildResolveInfo("package3", 3, true, false, + false); // Package 4 - Valid scorer w/ optional config activity. - Pair package4 = buildResolveInfo("package4", true, true, true); + Pair package4 = buildResolveInfo("package4", 4, true, true, true); List> scorers = new ArrayList<>(); scorers.add(package1); @@ -81,11 +84,13 @@ public class NetworkScorerAppManagerTest extends InstrumentationTestCase { assertTrue(result.hasNext()); NetworkScorerAppData next = result.next(); assertEquals("package1", next.mPackageName); + assertEquals(1, next.mPackageUid); assertNull(next.mConfigurationActivityClassName); assertTrue(result.hasNext()); next = result.next(); assertEquals("package4", next.mPackageName); + assertEquals(4, next.mPackageUid); assertEquals(".ConfigActivity", next.mConfigurationActivityClassName); assertFalse(result.hasNext()); @@ -122,7 +127,7 @@ public class NetworkScorerAppManagerTest extends InstrumentationTestCase { .thenReturn(receivers); } - private Pair buildResolveInfo(String packageName, + private Pair buildResolveInfo(String packageName, int packageUid, boolean hasReceiverPermission, boolean hasScorePermission, boolean hasConfigActivity) throws Exception { Mockito.when(mMockPm.checkPermission(permission.SCORE_NETWORKS, packageName)) @@ -133,6 +138,7 @@ public class NetworkScorerAppManagerTest extends InstrumentationTestCase { resolveInfo.activityInfo = new ActivityInfo(); resolveInfo.activityInfo.packageName = packageName; resolveInfo.activityInfo.applicationInfo = new ApplicationInfo(); + resolveInfo.activityInfo.applicationInfo.uid = packageUid; if (hasReceiverPermission) { resolveInfo.activityInfo.permission = permission.BROADCAST_NETWORK_PRIVILEGED; } -- cgit v1.1