Search in sources :

Example 1 with NetworkScorerAppData

use of android.net.NetworkScorerAppManager.NetworkScorerAppData in project platform_frameworks_base by android.

the class NetworkScorerAppManagerTest method testGetActiveScorer_providerAvailable.

public void testGetActiveScorer_providerAvailable() throws Exception {
    setNetworkRecommendationPackageNames("package1");
    mockScoreNetworksGranted("package1");
    mockRecommendationServiceAvailable("package1", 924);
    ContentResolver cr = mTargetContext.getContentResolver();
    Settings.Global.putInt(cr, Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 1);
    final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer();
    assertNotNull(activeScorer);
    assertEquals("package1", activeScorer.packageName);
    assertEquals(924, activeScorer.packageUid);
    assertEquals(".RecommendationService", activeScorer.recommendationServiceClassName);
}
Also used : NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData) ContentResolver(android.content.ContentResolver)

Example 2 with NetworkScorerAppData

use of android.net.NetworkScorerAppManager.NetworkScorerAppData in project platform_frameworks_base by android.

the class NetworkScorerAppManagerTest method testGetActiveScorer_recommendationsDisabled.

public void testGetActiveScorer_recommendationsDisabled() throws Exception {
    setNetworkRecommendationPackageNames("package1");
    mockScoreNetworksGranted("package1");
    mockRecommendationServiceAvailable("package1", 924);
    ContentResolver cr = mTargetContext.getContentResolver();
    Settings.Global.putInt(cr, Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 0);
    final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer();
    assertNull(activeScorer);
}
Also used : NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData) ContentResolver(android.content.ContentResolver)

Example 3 with NetworkScorerAppData

use of android.net.NetworkScorerAppManager.NetworkScorerAppData in project android_frameworks_base by DirtyUnicorns.

the class NetworkScoreService method registerPackageMonitorIfNeeded.

private void registerPackageMonitorIfNeeded() {
    if (DBG)
        Log.d(TAG, "registerPackageMonitorIfNeeded");
    NetworkScorerAppData scorer = NetworkScorerAppManager.getActiveScorer(mContext);
    synchronized (mPackageMonitorLock) {
        // Unregister the current monitor if needed.
        if (mPackageMonitor != null) {
            if (DBG) {
                Log.d(TAG, "Unregistering package monitor for " + mPackageMonitor.mRegisteredPackage);
            }
            mPackageMonitor.unregister();
            mPackageMonitor = null;
        }
        // Create and register the monitor if a scorer is active.
        if (scorer != null) {
            mPackageMonitor = new NetworkScorerPackageMonitor(scorer.mPackageName);
            // TODO: Need to update when we support per-user scorers. http://b/23422763
            mPackageMonitor.register(mContext, null, /* thread */
            UserHandle.SYSTEM, false);
            if (DBG) {
                Log.d(TAG, "Registered package monitor for " + mPackageMonitor.mRegisteredPackage);
            }
        }
    }
}
Also used : NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData)

Example 4 with NetworkScorerAppData

use of android.net.NetworkScorerAppManager.NetworkScorerAppData in project android_frameworks_base by DirtyUnicorns.

the class NetworkScoreService method bindToScoringServiceIfNeeded.

private void bindToScoringServiceIfNeeded() {
    if (DBG)
        Log.d(TAG, "bindToScoringServiceIfNeeded");
    NetworkScorerAppData scorerData = NetworkScorerAppManager.getActiveScorer(mContext);
    bindToScoringServiceIfNeeded(scorerData);
}
Also used : NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData)

Example 5 with NetworkScorerAppData

use of android.net.NetworkScorerAppManager.NetworkScorerAppData in project android_frameworks_base by AOSPA.

the class NetworkScorerAppManagerTest method testGetAllValidScorers.

public void testGetAllValidScorers() throws Exception {
    // Package 1 - Valid scorer.
    ResolveInfoHolder package1 = buildResolveInfo("package1", 1, true, true, false, false);
    // Package 2 - Receiver does not have BROADCAST_NETWORK_PRIVILEGED permission.
    ResolveInfoHolder package2 = buildResolveInfo("package2", 2, false, true, false, false);
    // Package 3 - App does not have SCORE_NETWORKS permission.
    ResolveInfoHolder package3 = buildResolveInfo("package3", 3, true, false, false, false);
    // Package 4 - Valid scorer w/ optional config activity.
    ResolveInfoHolder package4 = buildResolveInfo("package4", 4, true, true, true, false);
    // Package 5 - Valid scorer w/ optional service to bind to.
    ResolveInfoHolder package5 = buildResolveInfo("package5", 5, true, true, false, true);
    List<ResolveInfoHolder> scorers = new ArrayList<>();
    scorers.add(package1);
    scorers.add(package2);
    scorers.add(package3);
    scorers.add(package4);
    scorers.add(package5);
    setScorers(scorers);
    Iterator<NetworkScorerAppData> result = NetworkScorerAppManager.getAllValidScorers(mMockContext).iterator();
    assertTrue(result.hasNext());
    NetworkScorerAppData next = result.next();
    assertEquals("package1", next.mPackageName);
    assertEquals(1, next.mPackageUid);
    assertNull(next.mConfigurationActivityClassName);
    assertTrue(result.hasNext());
    next = result.next();
    assertEquals("package4", next.mPackageName);
    assertEquals(4, next.mPackageUid);
    assertEquals(".ConfigActivity", next.mConfigurationActivityClassName);
    assertTrue(result.hasNext());
    next = result.next();
    assertEquals("package5", next.mPackageName);
    assertEquals(5, next.mPackageUid);
    assertEquals(".ScoringService", next.mScoringServiceClassName);
    assertFalse(result.hasNext());
}
Also used : ArrayList(java.util.ArrayList) NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData)

Aggregations

NetworkScorerAppData (android.net.NetworkScorerAppManager.NetworkScorerAppData)28 Intent (android.content.Intent)5 INetworkScoreCache (android.net.INetworkScoreCache)5 RemoteException (android.os.RemoteException)4 ArrayList (java.util.ArrayList)4 ContentResolver (android.content.ContentResolver)3 ServiceConnection (android.content.ServiceConnection)1 UserHandle (android.os.UserHandle)1 AlertController (com.android.internal.app.AlertController)1