Search in sources :

Example 1 with INetworkScoreCache

use of android.net.INetworkScoreCache in project android_frameworks_base by crdroidandroid.

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();
}
Also used : INetworkScoreCache(android.net.INetworkScoreCache) RemoteException(android.os.RemoteException) NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData)

Example 2 with INetworkScoreCache

use of android.net.INetworkScoreCache in project android_frameworks_base by crdroidandroid.

the class NetworkScoreService method updateScores.

@Override
public boolean updateScores(ScoredNetwork[] networks) {
    if (!NetworkScorerAppManager.isCallerActiveScorer(mContext, getCallingUid())) {
        throw new SecurityException("Caller with UID " + getCallingUid() + " is not the active scorer.");
    }
    // Separate networks by type.
    Map<Integer, List<ScoredNetwork>> networksByType = new HashMap<>();
    for (ScoredNetwork network : networks) {
        List<ScoredNetwork> networkList = networksByType.get(network.networkKey.type);
        if (networkList == null) {
            networkList = new ArrayList<>();
            networksByType.put(network.networkKey.type, networkList);
        }
        networkList.add(network);
    }
    // Pass the scores of each type down to the appropriate network scorer.
    for (Map.Entry<Integer, List<ScoredNetwork>> entry : networksByType.entrySet()) {
        INetworkScoreCache scoreCache = mScoreCaches.get(entry.getKey());
        if (scoreCache != null) {
            try {
                scoreCache.updateScores(entry.getValue());
            } catch (RemoteException e) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "Unable to update scores of type " + entry.getKey(), e);
                }
            }
        } else if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "No scorer registered for type " + entry.getKey() + ", discarding");
        }
    }
    return true;
}
Also used : INetworkScoreCache(android.net.INetworkScoreCache) HashMap(java.util.HashMap) ScoredNetwork(android.net.ScoredNetwork) ArrayList(java.util.ArrayList) List(java.util.List) RemoteException(android.os.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with INetworkScoreCache

use of android.net.INetworkScoreCache 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();
}
Also used : INetworkScoreCache(android.net.INetworkScoreCache) NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData)

Example 4 with INetworkScoreCache

use of android.net.INetworkScoreCache in project platform_frameworks_base by android.

the class NetworkScoreService method updateScores.

@Override
public boolean updateScores(ScoredNetwork[] networks) {
    if (!isCallerActiveScorer(getCallingUid())) {
        throw new SecurityException("Caller with UID " + getCallingUid() + " is not the active scorer.");
    }
    final long token = Binder.clearCallingIdentity();
    try {
        // Separate networks by type.
        Map<Integer, List<ScoredNetwork>> networksByType = new ArrayMap<>();
        for (ScoredNetwork network : networks) {
            List<ScoredNetwork> networkList = networksByType.get(network.networkKey.type);
            if (networkList == null) {
                networkList = new ArrayList<>();
                networksByType.put(network.networkKey.type, networkList);
            }
            networkList.add(network);
        }
        // Pass the scores of each type down to the appropriate network scorer.
        for (final Map.Entry<Integer, List<ScoredNetwork>> entry : networksByType.entrySet()) {
            final RemoteCallbackList<INetworkScoreCache> callbackList;
            final boolean isEmpty;
            synchronized (mScoreCaches) {
                callbackList = mScoreCaches.get(entry.getKey());
                isEmpty = callbackList == null || callbackList.getRegisteredCallbackCount() == 0;
            }
            if (isEmpty) {
                if (Log.isLoggable(TAG, Log.VERBOSE)) {
                    Log.v(TAG, "No scorer registered for type " + entry.getKey() + ", discarding");
                }
                continue;
            }
            sendCallback(new Consumer<INetworkScoreCache>() {

                @Override
                public void accept(INetworkScoreCache networkScoreCache) {
                    try {
                        networkScoreCache.updateScores(entry.getValue());
                    } catch (RemoteException e) {
                        if (Log.isLoggable(TAG, Log.VERBOSE)) {
                            Log.v(TAG, "Unable to update scores of type " + entry.getKey(), e);
                        }
                    }
                }
            }, Collections.singleton(callbackList));
        }
        return true;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
Also used : INetworkScoreCache(android.net.INetworkScoreCache) ScoredNetwork(android.net.ScoredNetwork) ArrayMap(android.util.ArrayMap) RemoteCallbackList(android.os.RemoteCallbackList) List(java.util.List) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException) Map(java.util.Map) ArrayMap(android.util.ArrayMap)

Example 5 with INetworkScoreCache

use of android.net.INetworkScoreCache 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();
}
Also used : INetworkScoreCache(android.net.INetworkScoreCache) RemoteException(android.os.RemoteException) NetworkScorerAppData(android.net.NetworkScorerAppManager.NetworkScorerAppData)

Aggregations

INetworkScoreCache (android.net.INetworkScoreCache)10 RemoteException (android.os.RemoteException)9 NetworkScorerAppData (android.net.NetworkScorerAppManager.NetworkScorerAppData)5 ScoredNetwork (android.net.ScoredNetwork)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 HashMap (java.util.HashMap)4 RemoteCallbackList (android.os.RemoteCallbackList)1 ArrayMap (android.util.ArrayMap)1