Load app usage on background thread.

Since stats service loads as needed, this may touch disk, and should
run on background thread.

Change-Id: I1d1d2583250314efa4d3d8f4faa9016c746c29d0
This commit is contained in:
Jeff Sharkey
2011-06-14 23:21:59 -07:00
parent 8e911d7b1a
commit aa5260e40a

View File

@@ -41,6 +41,7 @@ import android.net.INetworkStatsService;
import android.net.NetworkPolicy;
import android.net.NetworkStats;
import android.net.NetworkStatsHistory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -568,14 +569,25 @@ public class DataUsageSummary extends Fragment {
private void updateDetailData() {
if (LOGD) Log.d(TAG, "updateDetailData()");
try {
final long[] range = mChart.getInspectRange();
final NetworkStats stats = mStatsService.getSummaryForAllUid(
range[0], range[1], mTemplate);
mAdapter.bindStats(stats);
} catch (RemoteException e) {
Log.w(TAG, "problem reading stats");
}
new AsyncTask<Void, Void, NetworkStats>() {
@Override
protected NetworkStats doInBackground(Void... params) {
try {
final long[] range = mChart.getInspectRange();
return mStatsService.getSummaryForAllUid(range[0], range[1], mTemplate);
} catch (RemoteException e) {
Log.w(TAG, "problem reading stats");
}
return null;
}
@Override
protected void onPostExecute(NetworkStats stats) {
if (stats != null) {
mAdapter.bindStats(stats);
}
}
}.execute();
}
private static String getActiveSubscriberId(Context context) {