New internal interface method to get the active scorer metadata.
Returns the cached NetworkScorerAppData from the connected service.
Test: runtest frameworks-services -c com.android.server.NetworkScoreServiceTest
Bug: 34773276
Change-Id: Ia8986e770c4ede0c0f7e2ad4f5bc0a0117a9ae2b
diff --git a/services/core/java/com/android/server/NetworkScoreService.java b/services/core/java/com/android/server/NetworkScoreService.java
index 5fe8b1a..0ac51b9 100644
--- a/services/core/java/com/android/server/NetworkScoreService.java
+++ b/services/core/java/com/android/server/NetworkScoreService.java
@@ -53,6 +53,7 @@
import android.os.IRemoteCallback;
import android.os.Looper;
import android.os.Message;
+import android.os.Process;
import android.os.RemoteCallback;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@@ -676,6 +677,10 @@
}
}
+ private boolean isCallerSystemProcess(int callingUid) {
+ return callingUid == Process.SYSTEM_UID;
+ }
+
/**
* Obtain the package name of the current active network scorer.
*
@@ -692,6 +697,27 @@
return null;
}
+
+ /**
+ * Returns metadata about the active scorer or <code>null</code> if there is no active scorer.
+ */
+ @Override
+ public NetworkScorerAppData getActiveScorer() {
+ // Only the system can access this data.
+ if (isCallerSystemProcess(getCallingUid()) || callerCanRequestScores()) {
+ synchronized (mServiceConnectionLock) {
+ if (mServiceConnection != null) {
+ return mServiceConnection.mAppData;
+ }
+ }
+ } else {
+ throw new SecurityException(
+ "Caller is neither the system process nor a score requester.");
+ }
+
+ return null;
+ }
+
@Override
public void disableScoring() {
// Only the active scorer or the system should be allowed to disable scoring.