if ?(mEndTime > mStartTime && mUid >? 0 ?&& Build.VERSION.SDK_INT >=? 23 ) { ???? final ?AppOpsManager appOps = (AppOpsManager) mAppContext.getSystemService(Context.APP_OPS_SERVICE); ???? NetworkStatsManager networkStatsManager = (NetworkStatsManager) mAppContext.getSystemService(Context.NETWORK_STATS_SERVICE); ???? TelephonyManager tm = (TelephonyManager) mAppContext.getSystemService(Context.TELEPHONY_SERVICE); ???? String subId = tm.getSubscriberId(); ???? NetworkStats summaryStats; ???? long ?summaryRx =? 0 ; ???? NetworkStats.Bucket summaryBucket =? new ?NetworkStats.Bucket(); ???? try ?{ ???????? summaryStats = networkStatsManager.querySummary(ConnectivityManager.TYPE_WIFI, subId, mStartTime, mEndTime); ???????? do ?{ ???????????? summaryStats.getNextBucket(summaryBucket); ???????????? int ?summaryUid = summaryBucket.getUid(); ???????????? if ?(mUid == summaryUid) { ???????????????? summaryRx += summaryBucket.getRxBytes(); ???????????? } ???????? }? while ?(summaryStats.hasNextBucket()); ???????? Log.i(TAG,? "[BandWidth] uid: " ?+ mUid +? ", rx: " ?+ summaryRx +? ", timediff: " ?+ (mEndTime - mStartTime) + ", speed: " ?+ summaryRx / (mEndTime - mStartTime) +? "KB/s" ); ???? }? catch ?(Exception e) { ???????? e.printStackTrace(); ???? } } |