diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-04-06 11:21:28 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2012-04-06 11:47:25 -0700 |
commit | 08ce99e224145759904bbd6ae36e0b2bf4b0e4e6 (patch) | |
tree | 5edaca2a7df78690817e2639eda0de529487a836 /src/com | |
parent | 11ca81e1f0f95e6ace612045c14ebd38e00fd819 (diff) | |
download | packages_apps_Settings-08ce99e224145759904bbd6ae36e0b2bf4b0e4e6.tar.gz packages_apps_Settings-08ce99e224145759904bbd6ae36e0b2bf4b0e4e6.tar.bz2 packages_apps_Settings-08ce99e224145759904bbd6ae36e0b2bf4b0e4e6.zip |
Move to INetworkStatsSession with lifecycle.
Explicitly communicate lifecycle, enabling system_server to cache
stats when actively being used.
Bug: 6236498
Change-Id: Ieecc4b1d4fd46aeb5207c4ba9b450e04e9438d00
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/settings/DataUsageSummary.java | 16 | ||||
-rw-r--r-- | src/com/android/settings/net/ChartDataLoader.java | 12 | ||||
-rw-r--r-- | src/com/android/settings/net/SummaryForAllUidLoader.java | 11 |
3 files changed, 25 insertions, 14 deletions
diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java index 656288a83..d127204bb 100644 --- a/src/com/android/settings/DataUsageSummary.java +++ b/src/com/android/settings/DataUsageSummary.java @@ -69,11 +69,13 @@ import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.INetworkPolicyManager; import android.net.INetworkStatsService; +import android.net.INetworkStatsSession; import android.net.NetworkPolicy; import android.net.NetworkPolicyManager; import android.net.NetworkStats; import android.net.NetworkStatsHistory; import android.net.NetworkTemplate; +import android.net.TrafficStats; import android.os.AsyncTask; import android.os.Bundle; import android.os.INetworkManagementService; @@ -186,6 +188,8 @@ public class DataUsageSummary extends Fragment { private NetworkPolicyManager mPolicyManager; private ConnectivityManager mConnService; + private INetworkStatsSession mStatsSession; + private static final String PREF_FILE = "data_usage"; private static final String PREF_SHOW_WIFI = "show_wifi"; private static final String PREF_SHOW_ETHERNET = "show_ethernet"; @@ -285,6 +289,12 @@ public class DataUsageSummary extends Fragment { mUidDetailProvider = new UidDetailProvider(context); + try { + mStatsSession = mStatsService.openSession(); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + mTabHost = (TabHost) view.findViewById(android.R.id.tabhost); mTabsContainer = (ViewGroup) view.findViewById(R.id.tabs_container); mTabWidget = (TabWidget) view.findViewById(android.R.id.tabs); @@ -533,6 +543,8 @@ public class DataUsageSummary extends Fragment { mUidDetailProvider.clearCache(); mUidDetailProvider = null; + + TrafficStats.closeQuietly(mStatsSession); } @Override @@ -1139,7 +1151,7 @@ public class DataUsageSummary extends Fragment { ChartData>() { /** {@inheritDoc} */ public Loader<ChartData> onCreateLoader(int id, Bundle args) { - return new ChartDataLoader(getActivity(), mStatsService, args); + return new ChartDataLoader(getActivity(), mStatsSession, args); } /** {@inheritDoc} */ @@ -1170,7 +1182,7 @@ public class DataUsageSummary extends Fragment { NetworkStats>() { /** {@inheritDoc} */ public Loader<NetworkStats> onCreateLoader(int id, Bundle args) { - return new SummaryForAllUidLoader(getActivity(), mStatsService, args); + return new SummaryForAllUidLoader(getActivity(), mStatsSession, args); } /** {@inheritDoc} */ diff --git a/src/com/android/settings/net/ChartDataLoader.java b/src/com/android/settings/net/ChartDataLoader.java index 172d37734..830d00649 100644 --- a/src/com/android/settings/net/ChartDataLoader.java +++ b/src/com/android/settings/net/ChartDataLoader.java @@ -24,7 +24,7 @@ import static android.net.NetworkStatsHistory.FIELD_TX_BYTES; import android.content.AsyncTaskLoader; import android.content.Context; -import android.net.INetworkStatsService; +import android.net.INetworkStatsSession; import android.net.NetworkStatsHistory; import android.net.NetworkTemplate; import android.os.Bundle; @@ -40,7 +40,7 @@ public class ChartDataLoader extends AsyncTaskLoader<ChartData> { private static final String KEY_APP = "app"; private static final String KEY_FIELDS = "fields"; - private final INetworkStatsService mStatsService; + private final INetworkStatsSession mSession; private final Bundle mArgs; public static Bundle buildArgs(NetworkTemplate template, AppItem app) { @@ -55,9 +55,9 @@ public class ChartDataLoader extends AsyncTaskLoader<ChartData> { return args; } - public ChartDataLoader(Context context, INetworkStatsService statsService, Bundle args) { + public ChartDataLoader(Context context, INetworkStatsSession session, Bundle args) { super(context); - mStatsService = statsService; + mSession = session; mArgs = args; } @@ -85,7 +85,7 @@ public class ChartDataLoader extends AsyncTaskLoader<ChartData> { private ChartData loadInBackground(NetworkTemplate template, AppItem app, int fields) throws RemoteException { final ChartData data = new ChartData(); - data.network = mStatsService.getHistoryForNetwork(template, fields); + data.network = mSession.getHistoryForNetwork(template, fields); if (app != null) { data.detailDefault = null; @@ -128,7 +128,7 @@ public class ChartDataLoader extends AsyncTaskLoader<ChartData> { private NetworkStatsHistory collectHistoryForUid( NetworkTemplate template, int uid, int set, NetworkStatsHistory existing) throws RemoteException { - final NetworkStatsHistory history = mStatsService.getHistoryForUid( + final NetworkStatsHistory history = mSession.getHistoryForUid( template, uid, set, TAG_NONE, FIELD_RX_BYTES | FIELD_TX_BYTES); if (existing != null) { diff --git a/src/com/android/settings/net/SummaryForAllUidLoader.java b/src/com/android/settings/net/SummaryForAllUidLoader.java index c01de4539..68dc79920 100644 --- a/src/com/android/settings/net/SummaryForAllUidLoader.java +++ b/src/com/android/settings/net/SummaryForAllUidLoader.java @@ -18,7 +18,7 @@ package com.android.settings.net; import android.content.AsyncTaskLoader; import android.content.Context; -import android.net.INetworkStatsService; +import android.net.INetworkStatsSession; import android.net.NetworkStats; import android.net.NetworkTemplate; import android.os.Bundle; @@ -29,7 +29,7 @@ public class SummaryForAllUidLoader extends AsyncTaskLoader<NetworkStats> { private static final String KEY_START = "start"; private static final String KEY_END = "end"; - private final INetworkStatsService mStatsService; + private final INetworkStatsSession mSession; private final Bundle mArgs; public static Bundle buildArgs(NetworkTemplate template, long start, long end) { @@ -40,10 +40,9 @@ public class SummaryForAllUidLoader extends AsyncTaskLoader<NetworkStats> { return args; } - public SummaryForAllUidLoader( - Context context, INetworkStatsService statsService, Bundle args) { + public SummaryForAllUidLoader(Context context, INetworkStatsSession session, Bundle args) { super(context); - mStatsService = statsService; + mSession = session; mArgs = args; } @@ -60,7 +59,7 @@ public class SummaryForAllUidLoader extends AsyncTaskLoader<NetworkStats> { final long end = mArgs.getLong(KEY_END); try { - return mStatsService.getSummaryForAllUid(template, start, end, false); + return mSession.getSummaryForAllUid(template, start, end, false); } catch (RemoteException e) { return null; } |