1398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey/* 2398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * Copyright (C) 2011 The Android Open Source Project 3398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * 4398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * Licensed under the Apache License, Version 2.0 (the "License"); 5398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * you may not use this file except in compliance with the License. 6398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * You may obtain a copy of the License at 7398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * 8398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * http://www.apache.org/licenses/LICENSE-2.0 9398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * 10398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * Unless required by applicable law or agreed to in writing, software 11398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * distributed under the License is distributed on an "AS IS" BASIS, 12398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * See the License for the specific language governing permissions and 14398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey * limitations under the License. 15398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey */ 16398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 17398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkeypackage com.android.settings.net; 18398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 19398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkeyimport android.content.AsyncTaskLoader; 20398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkeyimport android.content.Context; 2108ce99e224145759904bbd6ae36e0b2bf4b0e4e6Jeff Sharkeyimport android.net.INetworkStatsSession; 22398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkeyimport android.net.NetworkStats; 23398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkeyimport android.net.NetworkTemplate; 24398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkeyimport android.os.Bundle; 25398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkeyimport android.os.RemoteException; 26398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 27398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkeypublic class SummaryForAllUidLoader extends AsyncTaskLoader<NetworkStats> { 28398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey private static final String KEY_TEMPLATE = "template"; 29398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey private static final String KEY_START = "start"; 30398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey private static final String KEY_END = "end"; 31398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 3208ce99e224145759904bbd6ae36e0b2bf4b0e4e6Jeff Sharkey private final INetworkStatsSession mSession; 33398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey private final Bundle mArgs; 34398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 35398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey public static Bundle buildArgs(NetworkTemplate template, long start, long end) { 36398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey final Bundle args = new Bundle(); 37398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey args.putParcelable(KEY_TEMPLATE, template); 38398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey args.putLong(KEY_START, start); 39398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey args.putLong(KEY_END, end); 40398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey return args; 41398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey } 42398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 4308ce99e224145759904bbd6ae36e0b2bf4b0e4e6Jeff Sharkey public SummaryForAllUidLoader(Context context, INetworkStatsSession session, Bundle args) { 44398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey super(context); 4508ce99e224145759904bbd6ae36e0b2bf4b0e4e6Jeff Sharkey mSession = session; 46398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey mArgs = args; 47398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey } 48398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 49398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey @Override 50398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey protected void onStartLoading() { 51398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey super.onStartLoading(); 52398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey forceLoad(); 53398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey } 54398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 55398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey @Override 56398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey public NetworkStats loadInBackground() { 57398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey final NetworkTemplate template = mArgs.getParcelable(KEY_TEMPLATE); 58398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey final long start = mArgs.getLong(KEY_START); 59398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey final long end = mArgs.getLong(KEY_END); 60398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 61398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey try { 6208ce99e224145759904bbd6ae36e0b2bf4b0e4e6Jeff Sharkey return mSession.getSummaryForAllUid(template, start, end, false); 63398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey } catch (RemoteException e) { 64398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey return null; 65398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey } 66398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey } 67398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 68398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey @Override 69398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey protected void onStopLoading() { 70398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey super.onStopLoading(); 71398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey cancelLoad(); 72398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey } 73398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey 74398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey @Override 75398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey protected void onReset() { 76398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey super.onReset(); 77398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey cancelLoad(); 78398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey } 79398b18fca74ec45b9293bf1e1c39ca073018cb27Jeff Sharkey} 80