Loading services/core/java/com/android/server/NetworkScoreService.java +3 −3 Original line number Diff line number Diff line Loading @@ -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."); } Loading Loading @@ -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."); } Loading @@ -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."); } Loading services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -562,6 +562,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*/); Loading @@ -576,6 +584,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( Loading Loading
services/core/java/com/android/server/NetworkScoreService.java +3 −3 Original line number Diff line number Diff line Loading @@ -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."); } Loading Loading @@ -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."); } Loading @@ -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."); } Loading
services/tests/servicestests/src/com/android/server/NetworkScoreServiceTest.java +38 −0 Original line number Diff line number Diff line Loading @@ -562,6 +562,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*/); Loading @@ -576,6 +584,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( Loading