summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/NetworkScoreService.java6
-rw-r--r--services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java38
2 files changed, 41 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/NetworkScoreService.java b/services/core/java/com/android/server/NetworkScoreService.java
index 46c9f25dbccf..78c0fe620dda 100644
--- a/services/core/java/com/android/server/NetworkScoreService.java
+++ b/services/core/java/com/android/server/NetworkScoreService.java
@@ -667,7 +667,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
@Override
public boolean setActiveScorer(String packageName) {
// Only the system can set the active scorer
- if (!isCallerSystemProcess(getCallingUid()) || !callerCanRequestScores()) {
+ if (!isCallerSystemProcess(getCallingUid()) && !callerCanRequestScores()) {
throw new SecurityException(
"Caller is neither the system process nor a score requester.");
}
@@ -736,7 +736,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
@Override
public List<NetworkScorerAppData> getAllValidScorers() {
// Only the system can access this data.
- if (!isCallerSystemProcess(getCallingUid()) || !callerCanRequestScores()) {
+ if (!isCallerSystemProcess(getCallingUid()) && !callerCanRequestScores()) {
throw new SecurityException(
"Caller is neither the system process nor a score requester.");
}
@@ -747,7 +747,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
@Override
public void disableScoring() {
// Only the active scorer or the system should be allowed to disable scoring.
- if (!isCallerActiveScorer(getCallingUid()) || !callerCanRequestScores()) {
+ if (!isCallerActiveScorer(getCallingUid()) && !callerCanRequestScores()) {
throw new SecurityException(
"Caller is neither the active scorer nor the scorer manager.");
}
diff --git a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
index 6cca771539ea..a9c69f6bd3d2 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java
@@ -563,6 +563,14 @@ public class NetworkScoreServiceTest {
}
@Test
+ public void testSetActiveScorer_requestNetworkScoresPermission() {
+ when(mContext.checkCallingOrSelfPermission(permission.REQUEST_NETWORK_SCORES))
+ .thenReturn(PackageManager.PERMISSION_GRANTED);
+
+ mNetworkScoreService.setActiveScorer(null);
+ }
+
+ @Test
public void testDisableScoring_notActiveScorer_noRequestNetworkScoresPermission() {
bindToScorer(false /*callerIsScorer*/);
when(mContext.checkCallingOrSelfPermission(permission.REQUEST_NETWORK_SCORES))
@@ -577,6 +585,36 @@ public class NetworkScoreServiceTest {
}
@Test
+ public void testDisableScoring_activeScorer_noRequestNetworkScoresPermission() {
+ bindToScorer(true /*callerIsScorer*/);
+ when(mContext.checkCallingOrSelfPermission(permission.REQUEST_NETWORK_SCORES))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
+
+ mNetworkScoreService.disableScoring();
+ }
+
+ @Test
+ public void testGetAllValidScorer_noRequestNetworkScoresPermission() {
+ when(mContext.checkCallingOrSelfPermission(permission.REQUEST_NETWORK_SCORES))
+ .thenReturn(PackageManager.PERMISSION_DENIED);
+
+ try {
+ mNetworkScoreService.getAllValidScorers();
+ fail("SecurityException expected");
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+ @Test
+ public void testGetAllValidScorer_requestNetworkScoresPermission() {
+ when(mContext.checkCallingOrSelfPermission(permission.REQUEST_NETWORK_SCORES))
+ .thenReturn(PackageManager.PERMISSION_GRANTED);
+
+ mNetworkScoreService.getAllValidScorers();
+ }
+
+ @Test
public void testRegisterNetworkScoreCache_noRequestNetworkScoresPermission() {
doThrow(new SecurityException()).when(mContext).enforceCallingOrSelfPermission(
eq(permission.REQUEST_NETWORK_SCORES), anyString());