Merge "Move getActiveScorerPackage() to the score service."

This commit is contained in:
Treehugger Robot
2017-01-11 19:40:44 +00:00
committed by Gerrit Code Review
4 changed files with 44 additions and 4 deletions

View File

@@ -109,4 +109,12 @@ interface INetworkScoreService
* @hide * @hide
*/ */
boolean isCallerActiveScorer(int callingUid); boolean isCallerActiveScorer(int callingUid);
/**
* Obtain the package name of the current active network scorer.
*
* @return the full package name of the current active scorer, or null if there is no active
* scorer.
*/
String getActiveScorerPackage();
} }

View File

@@ -170,11 +170,11 @@ public class NetworkScoreManager {
* scorer. * scorer.
*/ */
public String getActiveScorerPackage() { public String getActiveScorerPackage() {
NetworkScorerAppData app = new NetworkScorerAppManager(mContext).getActiveScorer(); try {
if (app == null) { return mService.getActiveScorerPackage();
return null; } catch (RemoteException e) {
throw e.rethrowFromSystemServer();
} }
return app.packageName;
} }
/** /**

View File

@@ -432,6 +432,22 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
} }
} }
/**
* Obtain the package name of the current active network scorer.
*
* @return the full package name of the current active scorer, or null if there is no active
* scorer.
*/
@Override
public String getActiveScorerPackage() {
synchronized (mServiceConnectionLock) {
if (mServiceConnection != null) {
return mServiceConnection.mComponentName.getPackageName();
}
}
return null;
}
@Override @Override
public void disableScoring() { public void disableScoring() {
// Only the active scorer or the system should be allowed to disable scoring. // Only the active scorer or the system should be allowed to disable scoring.

View File

@@ -23,6 +23,7 @@ import static android.net.NetworkScoreManager.CACHE_FILTER_NONE;
import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail; import static junit.framework.Assert.fail;
@@ -470,6 +471,21 @@ public class NetworkScoreServiceTest {
assertTrue(mNetworkScoreService.isCallerActiveScorer(Binder.getCallingUid())); assertTrue(mNetworkScoreService.isCallerActiveScorer(Binder.getCallingUid()));
} }
@Test
public void testGetActiveScorerPackage_notActive() throws Exception {
mNetworkScoreService.systemRunning();
assertNull(mNetworkScoreService.getActiveScorerPackage());
}
@Test
public void testGetActiveScorerPackage_active() throws Exception {
when(mNetworkScorerAppManager.getActiveScorer()).thenReturn(NEW_SCORER);
mNetworkScoreService.systemRunning();
assertEquals(NEW_SCORER.packageName, mNetworkScoreService.getActiveScorerPackage());
}
// "injects" the mock INetworkRecommendationProvider into the NetworkScoreService. // "injects" the mock INetworkRecommendationProvider into the NetworkScoreService.
private void injectProvider() { private void injectProvider() {
final ComponentName componentName = new ComponentName(NEW_SCORER.packageName, final ComponentName componentName = new ComponentName(NEW_SCORER.packageName,