diff options
4 files changed, 73 insertions, 25 deletions
diff --git a/packages/ConnectivityT/framework-t/src/android/app/usage/NetworkStatsManager.java b/packages/ConnectivityT/framework-t/src/android/app/usage/NetworkStatsManager.java index ca8330921620..40b6371da72b 100644 --- a/packages/ConnectivityT/framework-t/src/android/app/usage/NetworkStatsManager.java +++ b/packages/ConnectivityT/framework-t/src/android/app/usage/NetworkStatsManager.java @@ -170,16 +170,44 @@ public class NetworkStatsManager { } } - /** @hide */ - public Bucket querySummaryForDevice(NetworkTemplate template, - long startTime, long endTime) throws SecurityException, RemoteException { - Bucket bucket = null; - NetworkStats stats = new NetworkStats(mContext, template, mFlags, startTime, endTime, - mService); - bucket = stats.getDeviceSummaryForNetwork(); - - stats.close(); - return bucket; + /** + * Query network usage statistics summaries. + * + * Result is summarised data usage for the whole + * device. Result is a single Bucket aggregated over time, state, uid, tag, metered, and + * roaming. This means the bucket's start and end timestamp will be the same as the + * 'startTime' and 'endTime' arguments. State is going to be + * {@link NetworkStats.Bucket#STATE_ALL}, uid {@link NetworkStats.Bucket#UID_ALL}, + * tag {@link NetworkStats.Bucket#TAG_NONE}, + * default network {@link NetworkStats.Bucket#DEFAULT_NETWORK_ALL}, + * metered {@link NetworkStats.Bucket#METERED_ALL}, + * and roaming {@link NetworkStats.Bucket#ROAMING_ALL}. + * This may take a long time, and apps should avoid calling this on their main thread. + * + * @param template Template used to match networks. See {@link NetworkTemplate}. + * @param startTime Start of period, in milliseconds since the Unix epoch, see + * {@link java.lang.System#currentTimeMillis}. + * @param endTime End of period, in milliseconds since the Unix epoch, see + * {@link java.lang.System#currentTimeMillis}. + * @return Bucket Summarised data usage. + * + * @hide + */ + @NonNull + @WorkerThread + // @SystemApi(client = MODULE_LIBRARIES) + public Bucket querySummaryForDevice(@NonNull NetworkTemplate template, + long startTime, long endTime) { + try { + NetworkStats stats = + new NetworkStats(mContext, template, mFlags, startTime, endTime, mService); + Bucket bucket = stats.getDeviceSummaryForNetwork(); + stats.close(); + return bucket; + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + return null; // To make the compiler happy. } /** @@ -323,14 +351,37 @@ public class NetworkStatsManager { return querySummary(template, startTime, endTime); } - /** @hide */ - public NetworkStats querySummary(NetworkTemplate template, long startTime, - long endTime) throws SecurityException, RemoteException { - NetworkStats result; - result = new NetworkStats(mContext, template, mFlags, startTime, endTime, mService); - result.startSummaryEnumeration(); - - return result; + /** + * Query network usage statistics summaries. + * + * The results will only include traffic made by UIDs belonging to the calling user profile. + * The results are aggregated over time, so that all buckets will have the same start and + * end timestamps as the passed arguments. Not aggregated over state, uid, default network, + * metered, or roaming. + * This may take a long time, and apps should avoid calling this on their main thread. + * + * @param template Template used to match networks. See {@link NetworkTemplate}. + * @param startTime Start of period, in milliseconds since the Unix epoch, see + * {@link java.lang.System#currentTimeMillis}. + * @param endTime End of period, in milliseconds since the Unix epoch, see + * {@link java.lang.System#currentTimeMillis}. + * @return Statistics which is described above. + * @hide + */ + @Nullable + // @SystemApi(client = MODULE_LIBRARIES) + @WorkerThread + public NetworkStats querySummary(@NonNull NetworkTemplate template, long startTime, + long endTime) throws SecurityException { + try { + NetworkStats result = + new NetworkStats(mContext, template, mFlags, startTime, endTime, mService); + result.startSummaryEnumeration(); + return result; + } catch (RemoteException e) { + e.rethrowFromSystemServer(); + } + return null; // To make the compiler happy. } /** diff --git a/packages/SettingsLib/src/com/android/settingslib/net/DataUsageController.java b/packages/SettingsLib/src/com/android/settingslib/net/DataUsageController.java index 18c38c5a6494..011ca0b38e5d 100644 --- a/packages/SettingsLib/src/com/android/settingslib/net/DataUsageController.java +++ b/packages/SettingsLib/src/com/android/settingslib/net/DataUsageController.java @@ -32,7 +32,6 @@ import android.net.INetworkStatsSession; import android.net.NetworkPolicy; import android.net.NetworkPolicyManager; import android.net.NetworkTemplate; -import android.os.RemoteException; import android.os.ServiceManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; @@ -172,7 +171,7 @@ public class DataUsageController { return bucket.getRxBytes() + bucket.getTxBytes(); } Log.w(TAG, "Failed to get data usage, no entry data"); - } catch (RemoteException e) { + } catch (RuntimeException e) { Log.w(TAG, "Failed to get data usage, remote call failed"); } return -1L; diff --git a/packages/SettingsLib/src/com/android/settingslib/net/NetworkCycleChartDataLoader.java b/packages/SettingsLib/src/com/android/settingslib/net/NetworkCycleChartDataLoader.java index 787dc55e60f4..42e710080983 100644 --- a/packages/SettingsLib/src/com/android/settingslib/net/NetworkCycleChartDataLoader.java +++ b/packages/SettingsLib/src/com/android/settingslib/net/NetworkCycleChartDataLoader.java @@ -18,7 +18,6 @@ package com.android.settingslib.net; import android.app.usage.NetworkStats; import android.content.Context; -import android.os.RemoteException; import android.util.Log; import java.util.ArrayList; @@ -54,7 +53,7 @@ public class NetworkCycleChartDataLoader .setTotalUsage(total); mData.add(builder.build()); } - } catch (RemoteException e) { + } catch (RuntimeException e) { Log.e(TAG, "Exception querying network detail.", e); } } @@ -85,7 +84,7 @@ public class NetworkCycleChartDataLoader if (bucket != null) { usage = bucket.getRxBytes() + bucket.getTxBytes(); } - } catch (RemoteException e) { + } catch (RuntimeException e) { Log.e(TAG, "Exception querying network detail.", e); } data.add(new NetworkCycleData.Builder() diff --git a/packages/SettingsLib/src/com/android/settingslib/net/NetworkStatsSummaryLoader.java b/packages/SettingsLib/src/com/android/settingslib/net/NetworkStatsSummaryLoader.java index ed093629686c..54d5c3d63a5d 100644 --- a/packages/SettingsLib/src/com/android/settingslib/net/NetworkStatsSummaryLoader.java +++ b/packages/SettingsLib/src/com/android/settingslib/net/NetworkStatsSummaryLoader.java @@ -20,7 +20,6 @@ import android.app.usage.NetworkStats; import android.app.usage.NetworkStatsManager; import android.content.Context; import android.net.NetworkTemplate; -import android.os.RemoteException; import android.util.Log; import androidx.loader.content.AsyncTaskLoader; @@ -55,7 +54,7 @@ public class NetworkStatsSummaryLoader extends AsyncTaskLoader<NetworkStats> { public NetworkStats loadInBackground() { try { return mNetworkStatsManager.querySummary(mNetworkTemplate, mStart, mEnd); - } catch (RemoteException e) { + } catch (RuntimeException e) { Log.e(TAG, "Exception querying network detail.", e); return null; } |