Loading core/java/android/net/INetworkScoreService.aidl +6 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,12 @@ interface INetworkScoreService */ boolean setActiveScorer(in String packageName); /** * Disable the current active scorer and clear existing scores. * @throws SecurityException if the caller is not the current scorer or the system. */ void disableScoring(); /** * Register a network subsystem for scoring. * Loading core/java/android/net/NetworkScoreManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,20 @@ public class NetworkScoreManager { } } /** * Turn off network scoring. * * <p>May only be called by the current scorer app, or the system. * * @throws SecurityException if the caller is neither the active scorer nor the system. */ public void disableScoring() throws SecurityException { try { mService.disableScoring(); } catch (RemoteException e) { } } /** * Request scoring for networks. * Loading services/core/java/com/android/server/NetworkScoreService.java +38 −10 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.net.NetworkScoreManager; import android.net.NetworkScorerAppManager; import android.net.NetworkScorerAppManager.NetworkScorerAppData; import android.net.ScoredNetwork; import android.os.Binder; import android.os.RemoteException; import android.text.TextUtils; import android.util.Log; Loading Loading @@ -131,9 +132,33 @@ public class NetworkScoreService extends INetworkScoreService.Stub { @Override public boolean setActiveScorer(String packageName) { mContext.enforceCallingOrSelfPermission(permission.BROADCAST_SCORE_NETWORKS, TAG); // Preemptively clear scores even though the set operation could fail. We do this for safety // as scores should never be compared across apps; in practice, Settings should only be // allowing valid apps to be set as scorers, so failure here should be rare. return setScorerInternal(packageName); } @Override public void disableScoring() { // Only the active scorer or the system (who can broadcast BROADCAST_SCORE_NETOWRKS) should // be allowed to disable scoring. if (NetworkScorerAppManager.isCallerActiveScorer(mContext, getCallingUid()) || mContext.checkCallingOrSelfPermission(permission.BROADCAST_SCORE_NETWORKS) == PackageManager.PERMISSION_GRANTED) { // The return value is discarded here because at this point, the call should always // succeed. The only reason for failure is if the new package is not a valid scorer, but // we're disabling scoring altogether here. setScorerInternal(null /* packageName */); } else { throw new SecurityException( "Caller is neither the active scorer nor the scorer manager."); } } /** Set the active scorer. Callers are responsible for checking permissions as appropriate. */ private boolean setScorerInternal(String packageName) { long token = Binder.clearCallingIdentity(); try { // Preemptively clear scores even though the set operation could fail. We do this for // safety as scores should never be compared across apps; in practice, Settings should // only be allowing valid apps to be set as scorers, so failure here should be rare. clearInternal(); boolean result = NetworkScorerAppManager.setActiveScorer(mContext, packageName); if (result) { Loading @@ -142,6 +167,9 @@ public class NetworkScoreService extends INetworkScoreService.Stub { mContext.sendBroadcast(intent); } return result; } finally { Binder.restoreCallingIdentity(token); } } /** Clear scores. Callers are responsible for checking permissions as appropriate. */ Loading Loading
core/java/android/net/INetworkScoreService.aidl +6 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,12 @@ interface INetworkScoreService */ boolean setActiveScorer(in String packageName); /** * Disable the current active scorer and clear existing scores. * @throws SecurityException if the caller is not the current scorer or the system. */ void disableScoring(); /** * Register a network subsystem for scoring. * Loading
core/java/android/net/NetworkScoreManager.java +14 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,20 @@ public class NetworkScoreManager { } } /** * Turn off network scoring. * * <p>May only be called by the current scorer app, or the system. * * @throws SecurityException if the caller is neither the active scorer nor the system. */ public void disableScoring() throws SecurityException { try { mService.disableScoring(); } catch (RemoteException e) { } } /** * Request scoring for networks. * Loading
services/core/java/com/android/server/NetworkScoreService.java +38 −10 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.net.NetworkScoreManager; import android.net.NetworkScorerAppManager; import android.net.NetworkScorerAppManager.NetworkScorerAppData; import android.net.ScoredNetwork; import android.os.Binder; import android.os.RemoteException; import android.text.TextUtils; import android.util.Log; Loading Loading @@ -131,9 +132,33 @@ public class NetworkScoreService extends INetworkScoreService.Stub { @Override public boolean setActiveScorer(String packageName) { mContext.enforceCallingOrSelfPermission(permission.BROADCAST_SCORE_NETWORKS, TAG); // Preemptively clear scores even though the set operation could fail. We do this for safety // as scores should never be compared across apps; in practice, Settings should only be // allowing valid apps to be set as scorers, so failure here should be rare. return setScorerInternal(packageName); } @Override public void disableScoring() { // Only the active scorer or the system (who can broadcast BROADCAST_SCORE_NETOWRKS) should // be allowed to disable scoring. if (NetworkScorerAppManager.isCallerActiveScorer(mContext, getCallingUid()) || mContext.checkCallingOrSelfPermission(permission.BROADCAST_SCORE_NETWORKS) == PackageManager.PERMISSION_GRANTED) { // The return value is discarded here because at this point, the call should always // succeed. The only reason for failure is if the new package is not a valid scorer, but // we're disabling scoring altogether here. setScorerInternal(null /* packageName */); } else { throw new SecurityException( "Caller is neither the active scorer nor the scorer manager."); } } /** Set the active scorer. Callers are responsible for checking permissions as appropriate. */ private boolean setScorerInternal(String packageName) { long token = Binder.clearCallingIdentity(); try { // Preemptively clear scores even though the set operation could fail. We do this for // safety as scores should never be compared across apps; in practice, Settings should // only be allowing valid apps to be set as scorers, so failure here should be rare. clearInternal(); boolean result = NetworkScorerAppManager.setActiveScorer(mContext, packageName); if (result) { Loading @@ -142,6 +167,9 @@ public class NetworkScoreService extends INetworkScoreService.Stub { mContext.sendBroadcast(intent); } return result; } finally { Binder.restoreCallingIdentity(token); } } /** Clear scores. Callers are responsible for checking permissions as appropriate. */ Loading