Search in sources :

Example 11 with NetworkScorerAppData

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

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 12 with NetworkScorerAppData

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

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 13 with NetworkScorerAppData

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

the class NetworkScoreService method setScorerInternal.

/** Set the active scorer. Callers are responsible for checking permissions as appropriate. */
private boolean setScorerInternal(String packageName) {
    if (DBG)
        Log.d(TAG, "setScorerInternal(" + packageName + ")");
    long token = Binder.clearCallingIdentity();
    try {
        unbindFromScoringServiceIfNeeded();
        // 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();
        // Get the scorer that is about to be replaced, if any, so we can notify it directly.
        NetworkScorerAppData prevScorer = NetworkScorerAppManager.getActiveScorer(mContext);
        boolean result = NetworkScorerAppManager.setActiveScorer(mContext, packageName);
        // Unconditionally attempt to bind to the current scorer. If setActiveScorer() failed
        // then we'll attempt to restore the previous binding (if any), otherwise an attempt
        // will be made to bind to the new scorer.
        bindToScoringServiceIfNeeded();
        if (result) {
            // new scorer successfully set
            registerPackageMonitorIfNeeded();
            Intent intent = new Intent(NetworkScoreManager.ACTION_SCORER_CHANGED);
            if (prevScorer != null) {
                // Directly notify the old scorer.
                intent.setPackage(prevScorer.mPackageName);
                // TODO: Need to update when we support per-user scorers. http://b/23422763
                mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM);
            }
            if (packageName != null) {
                // Then notify the new scorer
                intent.putExtra(NetworkScoreManager.EXTRA_NEW_SCORER, packageName);
                intent.setPackage(packageName);
                // TODO: Need to update when we support per-user scorers. http://b/23422763
                mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM);
            }
        }
        return result;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : Intent(android.content.Intent) NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData)

Example 14 with NetworkScorerAppData

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

the class NetworkScorerAppManagerTest method testGetNetworkRecommendationProviderData_available.

public void testGetNetworkRecommendationProviderData_available() throws Exception {
    setNetworkRecommendationPackageNames("package1");
    mockScoreNetworksGranted("package1");
    mockRecommendationServiceAvailable("package1", 924);
    NetworkScorerAppData appData = mNetworkScorerAppManager.getNetworkRecommendationProviderData();
    assertNotNull(appData);
    assertEquals("package1", appData.packageName);
    assertEquals(924, appData.packageUid);
    assertEquals(".RecommendationService", appData.recommendationServiceClassName);
}
Also used : NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData)

Example 15 with NetworkScorerAppData

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

the class NetworkScorerAppManagerTest method testGetActiveScorer_providerNotAvailable.

public void testGetActiveScorer_providerNotAvailable() throws Exception {
    ContentResolver cr = mTargetContext.getContentResolver();
    Settings.Global.putInt(cr, Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED, 1);
    final NetworkScorerAppData activeScorer = mNetworkScorerAppManager.getActiveScorer();
    assertNull(activeScorer);
}
Also used : NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData) ContentResolver(android.content.ContentResolver)

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