• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.net;
18 
19 import android.content.AsyncTaskLoader;
20 import android.content.Context;
21 import android.net.INetworkStatsService;
22 import android.net.NetworkStats;
23 import android.net.NetworkTemplate;
24 import android.os.Bundle;
25 import android.os.RemoteException;
26 
27 public class SummaryForAllUidLoader extends AsyncTaskLoader<NetworkStats> {
28     private static final String KEY_TEMPLATE = "template";
29     private static final String KEY_START = "start";
30     private static final String KEY_END = "end";
31 
32     private final INetworkStatsService mStatsService;
33     private final Bundle mArgs;
34 
buildArgs(NetworkTemplate template, long start, long end)35     public static Bundle buildArgs(NetworkTemplate template, long start, long end) {
36         final Bundle args = new Bundle();
37         args.putParcelable(KEY_TEMPLATE, template);
38         args.putLong(KEY_START, start);
39         args.putLong(KEY_END, end);
40         return args;
41     }
42 
SummaryForAllUidLoader( Context context, INetworkStatsService statsService, Bundle args)43     public SummaryForAllUidLoader(
44             Context context, INetworkStatsService statsService, Bundle args) {
45         super(context);
46         mStatsService = statsService;
47         mArgs = args;
48     }
49 
50     @Override
onStartLoading()51     protected void onStartLoading() {
52         super.onStartLoading();
53         forceLoad();
54     }
55 
56     @Override
loadInBackground()57     public NetworkStats loadInBackground() {
58         final NetworkTemplate template = mArgs.getParcelable(KEY_TEMPLATE);
59         final long start = mArgs.getLong(KEY_START);
60         final long end = mArgs.getLong(KEY_END);
61 
62         try {
63             return mStatsService.getSummaryForAllUid(template, start, end, false);
64         } catch (RemoteException e) {
65             return null;
66         }
67     }
68 
69     @Override
onStopLoading()70     protected void onStopLoading() {
71         super.onStopLoading();
72         cancelLoad();
73     }
74 
75     @Override
onReset()76     protected void onReset() {
77         super.onReset();
78         cancelLoad();
79     }
80 }
81