use of android.net.NetworkScorerAppManager.NetworkScorerAppData in project platform_frameworks_base by android.
the class NetworkScoreService method dump.
@Override
protected void dump(final FileDescriptor fd, final PrintWriter writer, final String[] args) {
mContext.enforceCallingOrSelfPermission(permission.DUMP, TAG);
NetworkScorerAppData currentScorer = mNetworkScorerAppManager.getActiveScorer();
if (currentScorer == null) {
writer.println("Scoring is disabled.");
return;
}
writer.println("Current scorer: " + currentScorer.packageName);
sendCallback(new Consumer<INetworkScoreCache>() {
@Override
public void accept(INetworkScoreCache networkScoreCache) {
try {
TransferPipe.dumpAsync(networkScoreCache.asBinder(), fd, args);
} catch (IOException | RemoteException e) {
writer.println("Failed to dump score cache: " + e);
}
}
}, getScoreCacheLists());
synchronized (mServiceConnectionLock) {
if (mServiceConnection != null) {
mServiceConnection.dump(fd, writer, args);
} else {
writer.println("ScoringServiceConnection: null");
}
}
writer.flush();
}
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);
}
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);
}
use of android.net.NetworkScorerAppManager.NetworkScorerAppData in project android_frameworks_base by AOSPA.
the class NetworkScoreService method dump.
@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
mContext.enforceCallingOrSelfPermission(permission.DUMP, TAG);
NetworkScorerAppData currentScorer = NetworkScorerAppManager.getActiveScorer(mContext);
if (currentScorer == null) {
writer.println("Scoring is disabled.");
return;
}
writer.println("Current scorer: " + currentScorer.mPackageName);
for (INetworkScoreCache scoreCache : getScoreCaches()) {
try {
scoreCache.asBinder().dump(fd, args);
} catch (RemoteException e) {
writer.println("Unable to dump score cache");
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "Unable to dump score cache", e);
}
}
}
if (mServiceConnection != null) {
mServiceConnection.dump(fd, writer, args);
} else {
writer.println("ScoringServiceConnection: null");
}
writer.flush();
}
use of android.net.NetworkScorerAppManager.NetworkScorerAppData in project android_frameworks_base by DirtyUnicorns.
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());
}
Aggregations