// upgrade any legacy stats, migrating them to rotated files maybeUpgradeLegacyStatsLocked();
// read historical network stats from disk, since policy service // might need them right away. mXtStatsCached = mXtRecorder.getOrLoadCompleteLocked();
// bootstrap initial stats to prevent double-counting later bootstrapStatsLocked(); }
// watch for tethering changes finalIntentFiltertetherFilter=newIntentFilter(ACTION_TETHER_STATE_CHANGED); mContext.registerReceiver(mTetherReceiver, tetherFilter, null, mHandler);
// listen for uid removal to clean stats finalIntentFilterremovedFilter=newIntentFilter(ACTION_UID_REMOVED); mContext.registerReceiver(mRemovedReceiver, removedFilter, null, mHandler);
// listen for user changes to clean stats finalIntentFilteruserFilter=newIntentFilter(ACTION_USER_REMOVED); mContext.registerReceiver(mUserReceiver, userFilter, null, mHandler);
// persist stats during clean shutdown finalIntentFiltershutdownFilter=newIntentFilter(ACTION_SHUTDOWN); mContext.registerReceiver(mShutdownReceiver, shutdownFilter);
try { mNetworkManager.registerObserver(mAlertObserver); } catch (RemoteException e) { // ignored; service lives in system_server }
/** * Default tag value for {@link DownloadManager} traffic. * * @hide */ publicstaticfinalintTAG_SYSTEM_DOWNLOAD=0xFFFFFF01;
/** * Default tag value for {@link MediaPlayer} traffic. * * @hide */ publicstaticfinalintTAG_SYSTEM_MEDIA=0xFFFFFF02;
/** * Default tag value for {@link BackupManager} backup traffic; that is, * traffic from the device to the storage backend. * * @hide */ publicstaticfinalintTAG_SYSTEM_BACKUP=0xFFFFFF03;
/** * Default tag value for {@link BackupManager} restore traffic; that is, * app data retrieved from the storage backend at install time. * * @hide */ publicstaticfinalintTAG_SYSTEM_RESTORE=0xFFFFFF04;
/** * Default tag value for code (typically APKs) downloaded by an app store on * behalf of the app, such as updates. * * @hide */ publicstaticfinalintTAG_SYSTEM_APP=0xFFFFFF05;
/** * Set active tag to use when accounting {@link Socket} traffic originating * from the current thread. Only one active tag per thread is supported. * <p> * Changes only take effect during subsequent calls to * {@link #tagSocket(Socket)}. * <p> * Tags between {@code 0xFFFFFF00} and {@code 0xFFFFFFFF} are reserved and * used internally by system services like {@link DownloadManager} when * performing traffic on behalf of an application. * * @see #clearThreadStatsTag() */ publicstaticvoidsetThreadStatsTag(int tag) { NetworkManagementSocketTagger.setThreadSocketStatsTag(tag); }
/** * Set active tag to use when accounting {@link Socket} traffic originating * from the current thread. Only one active tag per thread is supported. * <p> * Changes only take effect during subsequent calls to * {@link #tagSocket(Socket)}. * <p> * Tags between {@code 0xFFFFFF00} and {@code 0xFFFFFFFF} are reserved and * used internally by system services like {@link DownloadManager} when * performing traffic on behalf of an application. * * @return the current tag for the calling thread, which can be used to * restore any existing values after a nested operation is finished */ publicstaticintgetAndSetThreadStatsTag(int tag) { return NetworkManagementSocketTagger.setThreadSocketStatsTag(tag); }
}
...
/** * Tag the given {@link Socket} with any statistics parameters active for * the current thread. Subsequent calls always replace any existing * parameters. When finished, call {@link #untagSocket(Socket)} to remove * statistics parameters. * * @see #setThreadStatsTag(int) */ publicstaticvoidtagSocket(Socket socket)throws SocketException { SocketTagger.get().tag(socket); }
/** * Remove any statistics parameters from the given {@link Socket}. * <p> * In Android 8.1 (API level 27) and lower, a socket is automatically * untagged when it's sent to another process using binder IPC with a * {@code ParcelFileDescriptor} container. In Android 9.0 (API level 28) * and higher, the socket tag is kept when the socket is sent to another * process using binder IPC. You can mimic the previous behavior by * calling {@code untagSocket()} before sending the socket to another * process. */ publicstaticvoiduntagSocket(Socket socket)throws SocketException { SocketTagger.get().untag(socket); }