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.settingslib.net;
18 
19 import android.app.usage.NetworkStats;
20 import android.app.usage.NetworkStatsManager;
21 import android.content.AsyncTaskLoader;
22 import android.content.Context;
23 import android.net.NetworkTemplate;
24 import android.os.Bundle;
25 
26 /**
27  * Framework loader is deprecated, use the compat version instead.
28  *
29  * @deprecated
30  */
31 @Deprecated
32 public class SummaryForAllUidLoader extends AsyncTaskLoader<NetworkStats> {
33     private static final String KEY_TEMPLATE = "template";
34     private static final String KEY_START = "start";
35     private static final String KEY_END = "end";
36 
37     private final NetworkStatsManager mNetworkStatsManager;
38     private final Bundle mArgs;
39 
buildArgs(NetworkTemplate template, long start, long end)40     public static Bundle buildArgs(NetworkTemplate template, long start, long end) {
41         final Bundle args = new Bundle();
42         args.putParcelable(KEY_TEMPLATE, template);
43         args.putLong(KEY_START, start);
44         args.putLong(KEY_END, end);
45         return args;
46     }
47 
SummaryForAllUidLoader(Context context, Bundle args)48     public SummaryForAllUidLoader(Context context, Bundle args) {
49         super(context);
50         mNetworkStatsManager = context.getSystemService(NetworkStatsManager.class);
51         mArgs = args;
52     }
53 
54     @Override
onStartLoading()55     protected void onStartLoading() {
56         super.onStartLoading();
57         forceLoad();
58     }
59 
60     @Override
loadInBackground()61     public NetworkStats loadInBackground() {
62         final NetworkTemplate template = mArgs.getParcelable(KEY_TEMPLATE);
63         final long start = mArgs.getLong(KEY_START);
64         final long end = mArgs.getLong(KEY_END);
65         return mNetworkStatsManager.querySummary(template, start, end);
66     }
67 
68     @Override
onStopLoading()69     protected void onStopLoading() {
70         super.onStopLoading();
71         cancelLoad();
72     }
73 
74     @Override
onReset()75     protected void onReset() {
76         super.onReset();
77         cancelLoad();
78     }
79 }
80