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