Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 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; |
| 18 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 19 | import static android.net.ConnectivityManager.TYPE_ETHERNET; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 20 | import static android.net.ConnectivityManager.TYPE_MOBILE; |
Jeff Sharkey | bdf98e8 | 2011-11-10 17:17:24 -0800 | [diff] [blame] | 21 | import static android.net.ConnectivityManager.TYPE_WIFI; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 22 | import static android.net.ConnectivityManager.TYPE_WIMAX; |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 23 | import static android.net.NetworkPolicy.LIMIT_DISABLED; |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 24 | import static android.net.NetworkPolicy.WARNING_DISABLED; |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 25 | import static android.net.NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 26 | import static android.net.NetworkPolicyManager.POLICY_NONE; |
| 27 | import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 28 | import static android.net.NetworkPolicyManager.computeLastCycleBoundary; |
| 29 | import static android.net.NetworkPolicyManager.computeNextCycleBoundary; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 30 | import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER; |
| 31 | import static android.net.NetworkTemplate.MATCH_MOBILE_4G; |
| 32 | import static android.net.NetworkTemplate.MATCH_MOBILE_ALL; |
| 33 | import static android.net.NetworkTemplate.MATCH_WIFI; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 34 | import static android.net.NetworkTemplate.buildTemplateEthernet; |
| 35 | import static android.net.NetworkTemplate.buildTemplateMobile3gLower; |
| 36 | import static android.net.NetworkTemplate.buildTemplateMobile4g; |
| 37 | import static android.net.NetworkTemplate.buildTemplateMobileAll; |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 38 | import static android.net.NetworkTemplate.buildTemplateWifiWildcard; |
Jeff Sharkey | 77dae91 | 2012-02-03 14:50:33 -0800 | [diff] [blame] | 39 | import static android.net.TrafficStats.GB_IN_BYTES; |
| 40 | import static android.net.TrafficStats.MB_IN_BYTES; |
Jeff Sharkey | a83a24f | 2011-09-16 01:52:39 -0700 | [diff] [blame] | 41 | import static android.net.TrafficStats.UID_REMOVED; |
| 42 | import static android.net.TrafficStats.UID_TETHERING; |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 43 | import static android.telephony.TelephonyManager.SIM_STATE_READY; |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 44 | import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH; |
| 45 | import static android.text.format.DateUtils.FORMAT_SHOW_DATE; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 46 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 47 | import static com.android.internal.util.Preconditions.checkNotNull; |
Jeff Sharkey | b654cbb | 2011-08-18 11:59:19 -0700 | [diff] [blame] | 48 | import static com.android.settings.Utils.prepareCustomPreferencesList; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 49 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 50 | import android.animation.LayoutTransition; |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 51 | import android.app.ActivityManager; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 52 | import android.app.AlertDialog; |
| 53 | import android.app.Dialog; |
| 54 | import android.app.DialogFragment; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 55 | import android.app.Fragment; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 56 | import android.app.FragmentTransaction; |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 57 | import android.app.LoaderManager.LoaderCallbacks; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 58 | import android.content.ContentResolver; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 59 | import android.content.Context; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 60 | import android.content.DialogInterface; |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 61 | import android.content.Intent; |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 62 | import android.content.Loader; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 63 | import android.content.SharedPreferences; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 64 | import android.content.pm.PackageManager; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 65 | import android.content.res.Resources; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 66 | import android.graphics.Color; |
Jeff Sharkey | 5d70679 | 2011-09-08 18:57:17 -0700 | [diff] [blame] | 67 | import android.graphics.drawable.ColorDrawable; |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 68 | import android.graphics.drawable.Drawable; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 69 | import android.net.ConnectivityManager; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 70 | import android.net.INetworkPolicyManager; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 71 | import android.net.INetworkStatsService; |
Jeff Sharkey | 08ce99e | 2012-04-06 11:21:28 -0700 | [diff] [blame] | 72 | import android.net.INetworkStatsSession; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 73 | import android.net.NetworkPolicy; |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 74 | import android.net.NetworkPolicyManager; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 75 | import android.net.NetworkStats; |
| 76 | import android.net.NetworkStatsHistory; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 77 | import android.net.NetworkTemplate; |
Jeff Sharkey | 08ce99e | 2012-04-06 11:21:28 -0700 | [diff] [blame] | 78 | import android.net.TrafficStats; |
Jeff Sharkey | aa5260e | 2011-06-14 23:21:59 -0700 | [diff] [blame] | 79 | import android.os.AsyncTask; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 80 | import android.os.Bundle; |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 81 | import android.os.INetworkManagementService; |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 82 | import android.os.Parcel; |
| 83 | import android.os.Parcelable; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 84 | import android.os.RemoteException; |
| 85 | import android.os.ServiceManager; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 86 | import android.os.SystemProperties; |
Dianne Hackborn | bb06a42 | 2012-08-16 11:01:57 -0700 | [diff] [blame] | 87 | import android.os.UserHandle; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 88 | import android.preference.Preference; |
Fabrice Di Meglio | 758c3ff | 2014-04-10 13:47:30 -0700 | [diff] [blame^] | 89 | import android.provider.SearchIndexableResource; |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 90 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 91 | import android.text.TextUtils; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 92 | import android.text.format.DateUtils; |
| 93 | import android.text.format.Formatter; |
Jeff Sharkey | e5223a0 | 2012-03-09 17:11:14 -0800 | [diff] [blame] | 94 | import android.text.format.Time; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 95 | import android.util.Log; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 96 | import android.util.SparseArray; |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 97 | import android.util.SparseBooleanArray; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 98 | import android.view.LayoutInflater; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 99 | import android.view.Menu; |
| 100 | import android.view.MenuInflater; |
| 101 | import android.view.MenuItem; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 102 | import android.view.View; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 103 | import android.view.View.OnClickListener; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 104 | import android.view.ViewGroup; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 105 | import android.widget.AdapterView; |
| 106 | import android.widget.AdapterView.OnItemClickListener; |
| 107 | import android.widget.AdapterView.OnItemSelectedListener; |
| 108 | import android.widget.ArrayAdapter; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 109 | import android.widget.BaseAdapter; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 110 | import android.widget.Button; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 111 | import android.widget.CheckBox; |
| 112 | import android.widget.CompoundButton; |
| 113 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 114 | import android.widget.ImageView; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 115 | import android.widget.LinearLayout; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 116 | import android.widget.ListView; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 117 | import android.widget.NumberPicker; |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 118 | import android.widget.ProgressBar; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 119 | import android.widget.Spinner; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 120 | import android.widget.Switch; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 121 | import android.widget.TabHost; |
| 122 | import android.widget.TabHost.OnTabChangeListener; |
| 123 | import android.widget.TabHost.TabContentFactory; |
| 124 | import android.widget.TabHost.TabSpec; |
| 125 | import android.widget.TabWidget; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 126 | import android.widget.TextView; |
| 127 | |
Wink Saville | 5543404 | 2012-06-14 12:33:43 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.PhoneConstants; |
Jeff Sharkey | 5d70679 | 2011-09-08 18:57:17 -0700 | [diff] [blame] | 129 | import com.android.settings.drawable.InsetBoundsDrawable; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 130 | import com.android.settings.net.ChartData; |
| 131 | import com.android.settings.net.ChartDataLoader; |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 132 | import com.android.settings.net.DataUsageMeteredSettings; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 133 | import com.android.settings.net.NetworkPolicyEditor; |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 134 | import com.android.settings.net.SummaryForAllUidLoader; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 135 | import com.android.settings.net.UidDetail; |
| 136 | import com.android.settings.net.UidDetailProvider; |
Fabrice Di Meglio | 758c3ff | 2014-04-10 13:47:30 -0700 | [diff] [blame^] | 137 | import com.android.settings.search.Indexable; |
| 138 | import com.android.settings.search.SearchIndexableRaw; |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 139 | import com.android.settings.widget.ChartDataUsageView; |
| 140 | import com.android.settings.widget.ChartDataUsageView.DataUsageChartListener; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 141 | import com.android.settings.widget.PieChartView; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 142 | import com.google.android.collect.Lists; |
| 143 | |
Jeff Sharkey | 78ff1b8 | 2013-09-09 18:42:33 -0700 | [diff] [blame] | 144 | import libcore.util.Objects; |
| 145 | |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 146 | import java.util.ArrayList; |
| 147 | import java.util.Collections; |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 148 | import java.util.List; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 149 | import java.util.Locale; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 150 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 151 | /** |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 152 | * Panel showing data usage history across various networks, including options |
| 153 | * to inspect based on usage cycle and control through {@link NetworkPolicy}. |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 154 | */ |
Fabrice Di Meglio | 758c3ff | 2014-04-10 13:47:30 -0700 | [diff] [blame^] | 155 | public class DataUsageSummary extends Fragment implements Indexable { |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 156 | private static final String TAG = "DataUsage"; |
Jeff Sharkey | bdf98e8 | 2011-11-10 17:17:24 -0800 | [diff] [blame] | 157 | private static final boolean LOGD = false; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 158 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 159 | // TODO: remove this testing code |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 160 | private static final boolean TEST_ANIM = false; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 161 | private static final boolean TEST_RADIOS = false; |
Jeff Sharkey | f3871fb | 2012-02-03 19:27:07 -0800 | [diff] [blame] | 162 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 163 | private static final String TEST_RADIOS_PROP = "test.radios"; |
Jeff Sharkey | f3871fb | 2012-02-03 19:27:07 -0800 | [diff] [blame] | 164 | private static final String TEST_SUBSCRIBER_PROP = "test.subscriberid"; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 165 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 166 | private static final String TAB_3G = "3g"; |
| 167 | private static final String TAB_4G = "4g"; |
| 168 | private static final String TAB_MOBILE = "mobile"; |
| 169 | private static final String TAB_WIFI = "wifi"; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 170 | private static final String TAB_ETHERNET = "ethernet"; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 171 | |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 172 | private static final String TAG_CONFIRM_DATA_DISABLE = "confirmDataDisable"; |
| 173 | private static final String TAG_CONFIRM_DATA_ROAMING = "confirmDataRoaming"; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 174 | private static final String TAG_CONFIRM_LIMIT = "confirmLimit"; |
| 175 | private static final String TAG_CYCLE_EDITOR = "cycleEditor"; |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 176 | private static final String TAG_WARNING_EDITOR = "warningEditor"; |
| 177 | private static final String TAG_LIMIT_EDITOR = "limitEditor"; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 178 | private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict"; |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 179 | private static final String TAG_DENIED_RESTRICT = "deniedRestrict"; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 180 | private static final String TAG_CONFIRM_APP_RESTRICT = "confirmAppRestrict"; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 181 | private static final String TAG_CONFIRM_AUTO_SYNC_CHANGE = "confirmAutoSyncChange"; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 182 | private static final String TAG_APP_DETAILS = "appDetails"; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 183 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 184 | private static final int LOADER_CHART_DATA = 2; |
| 185 | private static final int LOADER_SUMMARY = 3; |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 186 | |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 187 | private INetworkManagementService mNetworkService; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 188 | private INetworkStatsService mStatsService; |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 189 | private NetworkPolicyManager mPolicyManager; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 190 | private ConnectivityManager mConnService; |
| 191 | |
Jeff Sharkey | 08ce99e | 2012-04-06 11:21:28 -0700 | [diff] [blame] | 192 | private INetworkStatsSession mStatsSession; |
| 193 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 194 | private static final String PREF_FILE = "data_usage"; |
| 195 | private static final String PREF_SHOW_WIFI = "show_wifi"; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 196 | private static final String PREF_SHOW_ETHERNET = "show_ethernet"; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 197 | |
| 198 | private SharedPreferences mPrefs; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 199 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 200 | private TabHost mTabHost; |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 201 | private ViewGroup mTabsContainer; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 202 | private TabWidget mTabWidget; |
| 203 | private ListView mListView; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 204 | private DataUsageAdapter mAdapter; |
| 205 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 206 | /** Distance to inset content from sides, when needed. */ |
| 207 | private int mInsetSide = 0; |
| 208 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 209 | private ViewGroup mHeader; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 210 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 211 | private ViewGroup mNetworkSwitchesContainer; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 212 | private LinearLayout mNetworkSwitches; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 213 | private Switch mDataEnabled; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 214 | private View mDataEnabledView; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 215 | private CheckBox mDisableAtLimit; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 216 | private View mDisableAtLimitView; |
| 217 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 218 | private View mCycleView; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 219 | private Spinner mCycleSpinner; |
| 220 | private CycleAdapter mCycleAdapter; |
| 221 | |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 222 | private ChartDataUsageView mChart; |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 223 | private TextView mUsageSummary; |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 224 | private TextView mEmpty; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 225 | |
| 226 | private View mAppDetail; |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 227 | private ImageView mAppIcon; |
| 228 | private ViewGroup mAppTitles; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 229 | private PieChartView mAppPieChart; |
| 230 | private TextView mAppForeground; |
| 231 | private TextView mAppBackground; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 232 | private Button mAppSettings; |
| 233 | |
| 234 | private LinearLayout mAppSwitches; |
| 235 | private CheckBox mAppRestrict; |
| 236 | private View mAppRestrictView; |
| 237 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 238 | private boolean mShowWifi = false; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 239 | private boolean mShowEthernet = false; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 240 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 241 | private NetworkTemplate mTemplate; |
| 242 | private ChartData mChartData; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 243 | |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 244 | private AppItem mCurrentApp = null; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 245 | |
| 246 | private Intent mAppSettingsIntent; |
| 247 | |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 248 | private NetworkPolicyEditor mPolicyEditor; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 249 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 250 | private String mCurrentTab = null; |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 251 | private String mIntentTab = null; |
| 252 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 253 | private MenuItem mMenuDataRoaming; |
| 254 | private MenuItem mMenuRestrictBackground; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 255 | private MenuItem mMenuAutoSync; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 256 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 257 | /** Flag used to ignore listeners during binding. */ |
| 258 | private boolean mBinding; |
| 259 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 260 | private UidDetailProvider mUidDetailProvider; |
| 261 | |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 262 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 263 | public void onCreate(Bundle savedInstanceState) { |
| 264 | super.onCreate(savedInstanceState); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 265 | final Context context = getActivity(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 266 | |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 267 | mNetworkService = INetworkManagementService.Stub.asInterface( |
| 268 | ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 269 | mStatsService = INetworkStatsService.Stub.asInterface( |
| 270 | ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 271 | mPolicyManager = NetworkPolicyManager.from(context); |
| 272 | mConnService = ConnectivityManager.from(context); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 273 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 274 | mPrefs = getActivity().getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 275 | |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 276 | mPolicyEditor = new NetworkPolicyEditor(mPolicyManager); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 277 | mPolicyEditor.read(); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 278 | |
Jaewan Kim | ffce9c1 | 2013-03-19 16:53:45 +0900 | [diff] [blame] | 279 | try { |
Jeff Sharkey | 78ff1b8 | 2013-09-09 18:42:33 -0700 | [diff] [blame] | 280 | if (!mNetworkService.isBandwidthControlEnabled()) { |
| 281 | Log.w(TAG, "No bandwidth control; leaving"); |
| 282 | getActivity().finish(); |
| 283 | } |
| 284 | } catch (RemoteException e) { |
| 285 | Log.w(TAG, "No bandwidth control; leaving"); |
| 286 | getActivity().finish(); |
| 287 | } |
| 288 | |
| 289 | try { |
Jaewan Kim | ffce9c1 | 2013-03-19 16:53:45 +0900 | [diff] [blame] | 290 | mStatsSession = mStatsService.openSession(); |
| 291 | } catch (RemoteException e) { |
| 292 | throw new RuntimeException(e); |
| 293 | } |
| 294 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 295 | mShowWifi = mPrefs.getBoolean(PREF_SHOW_WIFI, false); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 296 | mShowEthernet = mPrefs.getBoolean(PREF_SHOW_ETHERNET, false); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 297 | |
Jeff Sharkey | 0bc5b93 | 2012-05-03 15:02:06 -0700 | [diff] [blame] | 298 | // override preferences when no mobile radio |
| 299 | if (!hasReadyMobileRadio(context)) { |
Jaewan Kim | ffce9c1 | 2013-03-19 16:53:45 +0900 | [diff] [blame] | 300 | mShowWifi = true; |
| 301 | mShowEthernet = true; |
Jeff Sharkey | 0bc5b93 | 2012-05-03 15:02:06 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 304 | setHasOptionsMenu(true); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 305 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 306 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 307 | @Override |
| 308 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 309 | Bundle savedInstanceState) { |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 310 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 311 | final Context context = inflater.getContext(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 312 | final View view = inflater.inflate(R.layout.data_usage_summary, container, false); |
| 313 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 314 | mUidDetailProvider = new UidDetailProvider(context); |
| 315 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 316 | mTabHost = (TabHost) view.findViewById(android.R.id.tabhost); |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 317 | mTabsContainer = (ViewGroup) view.findViewById(R.id.tabs_container); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 318 | mTabWidget = (TabWidget) view.findViewById(android.R.id.tabs); |
| 319 | mListView = (ListView) view.findViewById(android.R.id.list); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 320 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 321 | // decide if we need to manually inset our content, or if we should rely |
| 322 | // on parent container for inset. |
| 323 | final boolean shouldInset = mListView.getScrollBarStyle() |
| 324 | == View.SCROLLBARS_OUTSIDE_OVERLAY; |
Amith Yamasani | 56f51a8 | 2013-08-05 10:07:23 -0700 | [diff] [blame] | 325 | mInsetSide = 0; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 326 | |
Jeff Sharkey | b654cbb | 2011-08-18 11:59:19 -0700 | [diff] [blame] | 327 | // adjust padding around tabwidget as needed |
Amith Yamasani | 56f51a8 | 2013-08-05 10:07:23 -0700 | [diff] [blame] | 328 | prepareCustomPreferencesList(container, view, mListView, false); |
Jeff Sharkey | 5d70679 | 2011-09-08 18:57:17 -0700 | [diff] [blame] | 329 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 330 | mTabHost.setup(); |
| 331 | mTabHost.setOnTabChangedListener(mTabListener); |
| 332 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 333 | mHeader = (ViewGroup) inflater.inflate(R.layout.data_usage_header, mListView, false); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 334 | mHeader.setClickable(true); |
| 335 | |
Jeff Sharkey | 92b518c | 2013-03-25 16:13:00 -0700 | [diff] [blame] | 336 | mListView.addHeaderView(new View(context), null, true); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 337 | mListView.addHeaderView(mHeader, null, true); |
| 338 | mListView.setItemsCanFocus(true); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 339 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 340 | if (mInsetSide > 0) { |
| 341 | // inset selector and divider drawables |
| 342 | insetListViewDrawables(mListView, mInsetSide); |
Fabrice Di Meglio | b27223f | 2013-01-15 18:54:11 -0800 | [diff] [blame] | 343 | mHeader.setPaddingRelative(mInsetSide, 0, mInsetSide, 0); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 346 | { |
| 347 | // bind network switches |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 348 | mNetworkSwitchesContainer = (ViewGroup) mHeader.findViewById( |
| 349 | R.id.network_switches_container); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 350 | mNetworkSwitches = (LinearLayout) mHeader.findViewById(R.id.network_switches); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 351 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 352 | mDataEnabled = new Switch(inflater.getContext()); |
| 353 | mDataEnabledView = inflatePreference(inflater, mNetworkSwitches, mDataEnabled); |
| 354 | mDataEnabled.setOnCheckedChangeListener(mDataEnabledListener); |
| 355 | mNetworkSwitches.addView(mDataEnabledView); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 356 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 357 | mDisableAtLimit = new CheckBox(inflater.getContext()); |
| 358 | mDisableAtLimit.setClickable(false); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 359 | mDisableAtLimit.setFocusable(false); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 360 | mDisableAtLimitView = inflatePreference(inflater, mNetworkSwitches, mDisableAtLimit); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 361 | mDisableAtLimitView.setClickable(true); |
| 362 | mDisableAtLimitView.setFocusable(true); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 363 | mDisableAtLimitView.setOnClickListener(mDisableAtLimitListener); |
| 364 | mNetworkSwitches.addView(mDisableAtLimitView); |
| 365 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 366 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 367 | // bind cycle dropdown |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 368 | mCycleView = mHeader.findViewById(R.id.cycles); |
| 369 | mCycleSpinner = (Spinner) mCycleView.findViewById(R.id.cycles_spinner); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 370 | mCycleAdapter = new CycleAdapter(context); |
| 371 | mCycleSpinner.setAdapter(mCycleAdapter); |
| 372 | mCycleSpinner.setOnItemSelectedListener(mCycleListener); |
| 373 | |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 374 | mChart = (ChartDataUsageView) mHeader.findViewById(R.id.chart); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 375 | mChart.setListener(mChartListener); |
Jeff Sharkey | bdf98e8 | 2011-11-10 17:17:24 -0800 | [diff] [blame] | 376 | mChart.bindNetworkPolicy(null); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 377 | |
| 378 | { |
| 379 | // bind app detail controls |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 380 | mAppDetail = mHeader.findViewById(R.id.app_detail); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 381 | mAppIcon = (ImageView) mAppDetail.findViewById(R.id.app_icon); |
| 382 | mAppTitles = (ViewGroup) mAppDetail.findViewById(R.id.app_titles); |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 383 | mAppPieChart = (PieChartView) mAppDetail.findViewById(R.id.app_pie_chart); |
| 384 | mAppForeground = (TextView) mAppDetail.findViewById(R.id.app_foreground); |
| 385 | mAppBackground = (TextView) mAppDetail.findViewById(R.id.app_background); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 386 | mAppSwitches = (LinearLayout) mAppDetail.findViewById(R.id.app_switches); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 387 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 388 | mAppSettings = (Button) mAppDetail.findViewById(R.id.app_settings); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 389 | mAppSettings.setOnClickListener(mAppSettingsListener); |
| 390 | |
| 391 | mAppRestrict = new CheckBox(inflater.getContext()); |
| 392 | mAppRestrict.setClickable(false); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 393 | mAppRestrict.setFocusable(false); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 394 | mAppRestrictView = inflatePreference(inflater, mAppSwitches, mAppRestrict); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 395 | mAppRestrictView.setClickable(true); |
| 396 | mAppRestrictView.setFocusable(true); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 397 | mAppRestrictView.setOnClickListener(mAppRestrictListener); |
| 398 | mAppSwitches.addView(mAppRestrictView); |
| 399 | } |
| 400 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 401 | mUsageSummary = (TextView) mHeader.findViewById(R.id.usage_summary); |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 402 | mEmpty = (TextView) mHeader.findViewById(android.R.id.empty); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 403 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 404 | mAdapter = new DataUsageAdapter(mUidDetailProvider, mInsetSide); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 405 | mListView.setOnItemClickListener(mListListener); |
| 406 | mListView.setAdapter(mAdapter); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 407 | |
| 408 | return view; |
| 409 | } |
| 410 | |
| 411 | @Override |
| 412 | public void onResume() { |
| 413 | super.onResume(); |
| 414 | |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 415 | // pick default tab based on incoming intent |
| 416 | final Intent intent = getActivity().getIntent(); |
| 417 | mIntentTab = computeTabFromIntent(intent); |
| 418 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 419 | // this kicks off chain reaction which creates tabs, binds the body to |
| 420 | // selected network, and binds chart, cycles and detail list. |
| 421 | updateTabs(); |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 422 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 423 | // kick off background task to update stats |
| 424 | new AsyncTask<Void, Void, Void>() { |
| 425 | @Override |
| 426 | protected Void doInBackground(Void... params) { |
| 427 | try { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 428 | // wait a few seconds before kicking off |
| 429 | Thread.sleep(2 * DateUtils.SECOND_IN_MILLIS); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 430 | mStatsService.forceUpdate(); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 431 | } catch (InterruptedException e) { |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 432 | } catch (RemoteException e) { |
| 433 | } |
| 434 | return null; |
| 435 | } |
| 436 | |
| 437 | @Override |
| 438 | protected void onPostExecute(Void result) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 439 | if (isAdded()) { |
| 440 | updateBody(); |
| 441 | } |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 442 | } |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 443 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 446 | @Override |
| 447 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
| 448 | inflater.inflate(R.menu.data_usage, menu); |
| 449 | } |
| 450 | |
| 451 | @Override |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 452 | public void onPrepareOptionsMenu(Menu menu) { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 453 | final Context context = getActivity(); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 454 | final boolean appDetailMode = isAppDetailMode(); |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 455 | final boolean isOwner = ActivityManager.getCurrentUser() == UserHandle.USER_OWNER; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 456 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 457 | mMenuDataRoaming = menu.findItem(R.id.data_usage_menu_roaming); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 458 | mMenuDataRoaming.setVisible(hasReadyMobileRadio(context) && !appDetailMode); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 459 | mMenuDataRoaming.setChecked(getDataRoaming()); |
| 460 | |
| 461 | mMenuRestrictBackground = menu.findItem(R.id.data_usage_menu_restrict_background); |
Jeff Sharkey | 92b518c | 2013-03-25 16:13:00 -0700 | [diff] [blame] | 462 | mMenuRestrictBackground.setVisible( |
| 463 | hasReadyMobileRadio(context) && isOwner && !appDetailMode); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 464 | mMenuRestrictBackground.setChecked(mPolicyManager.getRestrictBackground()); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 465 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 466 | mMenuAutoSync = menu.findItem(R.id.data_usage_menu_auto_sync); |
| 467 | mMenuAutoSync.setChecked(ContentResolver.getMasterSyncAutomatically()); |
Jeff Sharkey | fda48e3 | 2012-09-18 15:03:47 -0700 | [diff] [blame] | 468 | mMenuAutoSync.setVisible(!appDetailMode); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 469 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 470 | final MenuItem split4g = menu.findItem(R.id.data_usage_menu_split_4g); |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 471 | split4g.setVisible(hasReadyMobile4gRadio(context) && isOwner && !appDetailMode); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 472 | split4g.setChecked(isMobilePolicySplit()); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 473 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 474 | final MenuItem showWifi = menu.findItem(R.id.data_usage_menu_show_wifi); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 475 | if (hasWifiRadio(context) && hasReadyMobileRadio(context)) { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 476 | showWifi.setVisible(!appDetailMode); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 477 | showWifi.setChecked(mShowWifi); |
| 478 | } else { |
| 479 | showWifi.setVisible(false); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 480 | } |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 481 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 482 | final MenuItem showEthernet = menu.findItem(R.id.data_usage_menu_show_ethernet); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 483 | if (hasEthernet(context) && hasReadyMobileRadio(context)) { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 484 | showEthernet.setVisible(!appDetailMode); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 485 | showEthernet.setChecked(mShowEthernet); |
| 486 | } else { |
| 487 | showEthernet.setVisible(false); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 488 | } |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 489 | |
| 490 | final MenuItem metered = menu.findItem(R.id.data_usage_menu_metered); |
| 491 | if (hasReadyMobileRadio(context) || hasWifiRadio(context)) { |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 492 | metered.setVisible(!appDetailMode); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 493 | } else { |
| 494 | metered.setVisible(false); |
| 495 | } |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 496 | |
| 497 | final MenuItem help = menu.findItem(R.id.data_usage_menu_help); |
| 498 | String helpUrl; |
| 499 | if (!TextUtils.isEmpty(helpUrl = getResources().getString(R.string.help_url_data_usage))) { |
Amith Yamasani | aeb57ed | 2012-12-06 14:40:51 -0800 | [diff] [blame] | 500 | HelpUtils.prepareHelpMenuItem(context, help, helpUrl); |
Amith Yamasani | b0b37ae | 2012-04-23 15:35:36 -0700 | [diff] [blame] | 501 | } else { |
| 502 | help.setVisible(false); |
| 503 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 504 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 505 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 506 | @Override |
| 507 | public boolean onOptionsItemSelected(MenuItem item) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 508 | switch (item.getItemId()) { |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 509 | case R.id.data_usage_menu_roaming: { |
| 510 | final boolean dataRoaming = !item.isChecked(); |
| 511 | if (dataRoaming) { |
| 512 | ConfirmDataRoamingFragment.show(this); |
| 513 | } else { |
| 514 | // no confirmation to disable roaming |
| 515 | setDataRoaming(false); |
| 516 | } |
| 517 | return true; |
| 518 | } |
| 519 | case R.id.data_usage_menu_restrict_background: { |
| 520 | final boolean restrictBackground = !item.isChecked(); |
| 521 | if (restrictBackground) { |
Jeff Sharkey | 3038c52 | 2011-11-30 15:37:51 -0800 | [diff] [blame] | 522 | ConfirmRestrictFragment.show(this); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 523 | } else { |
| 524 | // no confirmation to drop restriction |
| 525 | setRestrictBackground(false); |
| 526 | } |
| 527 | return true; |
| 528 | } |
| 529 | case R.id.data_usage_menu_split_4g: { |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 530 | final boolean mobileSplit = !item.isChecked(); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 531 | setMobilePolicySplit(mobileSplit); |
| 532 | item.setChecked(isMobilePolicySplit()); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 533 | updateTabs(); |
| 534 | return true; |
| 535 | } |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 536 | case R.id.data_usage_menu_show_wifi: { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 537 | mShowWifi = !item.isChecked(); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 538 | mPrefs.edit().putBoolean(PREF_SHOW_WIFI, mShowWifi).apply(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 539 | item.setChecked(mShowWifi); |
| 540 | updateTabs(); |
| 541 | return true; |
| 542 | } |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 543 | case R.id.data_usage_menu_show_ethernet: { |
| 544 | mShowEthernet = !item.isChecked(); |
| 545 | mPrefs.edit().putBoolean(PREF_SHOW_ETHERNET, mShowEthernet).apply(); |
| 546 | item.setChecked(mShowEthernet); |
| 547 | updateTabs(); |
| 548 | return true; |
| 549 | } |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 550 | case R.id.data_usage_menu_metered: { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 551 | final SettingsActivity sa = (SettingsActivity) getActivity(); |
| 552 | sa.startPreferencePanel(DataUsageMeteredSettings.class.getCanonicalName(), null, |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 553 | R.string.data_usage_metered_title, null, this, 0); |
| 554 | return true; |
| 555 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 556 | case R.id.data_usage_menu_auto_sync: { |
Guang Zhu | 167ba2a | 2012-10-19 17:55:05 -0700 | [diff] [blame] | 557 | if (ActivityManager.isUserAMonkey()) { |
| 558 | Log.d("SyncState", "ignoring monkey's attempt to flip global sync state"); |
| 559 | } else { |
| 560 | ConfirmAutoSyncChangeFragment.show(this, !item.isChecked()); |
| 561 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 562 | return true; |
| 563 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 564 | } |
| 565 | return false; |
| 566 | } |
| 567 | |
Jeff Sharkey | 94a9095 | 2011-06-13 22:31:09 -0700 | [diff] [blame] | 568 | @Override |
Jeff Sharkey | 02b327e | 2012-05-15 11:33:59 -0700 | [diff] [blame] | 569 | public void onDestroy() { |
Jeff Sharkey | 94a9095 | 2011-06-13 22:31:09 -0700 | [diff] [blame] | 570 | mDataEnabledView = null; |
| 571 | mDisableAtLimitView = null; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 572 | |
| 573 | mUidDetailProvider.clearCache(); |
| 574 | mUidDetailProvider = null; |
Jeff Sharkey | 08ce99e | 2012-04-06 11:21:28 -0700 | [diff] [blame] | 575 | |
| 576 | TrafficStats.closeQuietly(mStatsSession); |
Jeff Sharkey | 94a9095 | 2011-06-13 22:31:09 -0700 | [diff] [blame] | 577 | |
Amith Yamasani | 5ba0a02 | 2011-11-07 12:29:00 -0800 | [diff] [blame] | 578 | super.onDestroy(); |
| 579 | } |
| 580 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 581 | /** |
Jeff Sharkey | 9281182 | 2012-05-04 11:47:29 -0700 | [diff] [blame] | 582 | * Build and assign {@link LayoutTransition} to various containers. Should |
| 583 | * only be assigned after initial layout is complete. |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 584 | */ |
Jeff Sharkey | 9281182 | 2012-05-04 11:47:29 -0700 | [diff] [blame] | 585 | private void ensureLayoutTransitions() { |
| 586 | // skip when already setup |
| 587 | if (mChart.getLayoutTransition() != null) return; |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 588 | |
Jeff Sharkey | 9281182 | 2012-05-04 11:47:29 -0700 | [diff] [blame] | 589 | mTabsContainer.setLayoutTransition(buildLayoutTransition()); |
| 590 | mHeader.setLayoutTransition(buildLayoutTransition()); |
| 591 | mNetworkSwitchesContainer.setLayoutTransition(buildLayoutTransition()); |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 592 | |
Jeff Sharkey | 9281182 | 2012-05-04 11:47:29 -0700 | [diff] [blame] | 593 | final LayoutTransition chartTransition = buildLayoutTransition(); |
| 594 | chartTransition.disableTransitionType(LayoutTransition.APPEARING); |
| 595 | chartTransition.disableTransitionType(LayoutTransition.DISAPPEARING); |
| 596 | mChart.setLayoutTransition(chartTransition); |
| 597 | } |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 598 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 599 | private static LayoutTransition buildLayoutTransition() { |
| 600 | final LayoutTransition transition = new LayoutTransition(); |
| 601 | if (TEST_ANIM) { |
| 602 | transition.setDuration(1500); |
| 603 | } |
| 604 | transition.setAnimateParentHierarchy(false); |
| 605 | return transition; |
| 606 | } |
| 607 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 608 | /** |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 609 | * Rebuild all tabs based on {@link NetworkPolicyEditor} and |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 610 | * {@link #mShowWifi}, hiding the tabs entirely when applicable. Selects |
| 611 | * first tab, and kicks off a full rebind of body contents. |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 612 | */ |
| 613 | private void updateTabs() { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 614 | final Context context = getActivity(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 615 | mTabHost.clearAllTabs(); |
| 616 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 617 | final boolean mobileSplit = isMobilePolicySplit(); |
Jeff Sharkey | ad17de3 | 2012-04-11 11:03:25 -0700 | [diff] [blame] | 618 | if (mobileSplit && hasReadyMobile4gRadio(context)) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 619 | mTabHost.addTab(buildTabSpec(TAB_3G, R.string.data_usage_tab_3g)); |
| 620 | mTabHost.addTab(buildTabSpec(TAB_4G, R.string.data_usage_tab_4g)); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 621 | } else if (hasReadyMobileRadio(context)) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 622 | mTabHost.addTab(buildTabSpec(TAB_MOBILE, R.string.data_usage_tab_mobile)); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 623 | } |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 624 | if (mShowWifi && hasWifiRadio(context)) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 625 | mTabHost.addTab(buildTabSpec(TAB_WIFI, R.string.data_usage_tab_wifi)); |
| 626 | } |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 627 | if (mShowEthernet && hasEthernet(context)) { |
| 628 | mTabHost.addTab(buildTabSpec(TAB_ETHERNET, R.string.data_usage_tab_ethernet)); |
| 629 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 630 | |
Jeff Sharkey | ad17de3 | 2012-04-11 11:03:25 -0700 | [diff] [blame] | 631 | final boolean noTabs = mTabWidget.getTabCount() == 0; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 632 | final boolean multipleTabs = mTabWidget.getTabCount() > 1; |
| 633 | mTabWidget.setVisibility(multipleTabs ? View.VISIBLE : View.GONE); |
| 634 | if (mIntentTab != null) { |
| 635 | if (Objects.equal(mIntentTab, mTabHost.getCurrentTabTag())) { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 636 | // already hit updateBody() when added; ignore |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 637 | updateBody(); |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 638 | } else { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 639 | mTabHost.setCurrentTabByTag(mIntentTab); |
| 640 | } |
| 641 | mIntentTab = null; |
Jeff Sharkey | ad17de3 | 2012-04-11 11:03:25 -0700 | [diff] [blame] | 642 | } else if (noTabs) { |
| 643 | // no usable tabs, so hide body |
| 644 | updateBody(); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 645 | } else { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 646 | // already hit updateBody() when added; ignore |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 650 | /** |
| 651 | * Factory that provide empty {@link View} to make {@link TabHost} happy. |
| 652 | */ |
| 653 | private TabContentFactory mEmptyTabContent = new TabContentFactory() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 654 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 655 | public View createTabContent(String tag) { |
| 656 | return new View(mTabHost.getContext()); |
| 657 | } |
| 658 | }; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 659 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 660 | /** |
| 661 | * Build {@link TabSpec} with thin indicator, and empty content. |
| 662 | */ |
| 663 | private TabSpec buildTabSpec(String tag, int titleRes) { |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 664 | return mTabHost.newTabSpec(tag).setIndicator(getText(titleRes)).setContent( |
| 665 | mEmptyTabContent); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | private OnTabChangeListener mTabListener = new OnTabChangeListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 669 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 670 | public void onTabChanged(String tabId) { |
| 671 | // user changed tab; update body |
| 672 | updateBody(); |
| 673 | } |
| 674 | }; |
| 675 | |
| 676 | /** |
| 677 | * Update body content based on current tab. Loads |
| 678 | * {@link NetworkStatsHistory} and {@link NetworkPolicy} from system, and |
| 679 | * binds them to visible controls. |
| 680 | */ |
| 681 | private void updateBody() { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 682 | mBinding = true; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 683 | if (!isAdded()) return; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 684 | |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 685 | final Context context = getActivity(); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 686 | final String currentTab = mTabHost.getCurrentTabTag(); |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 687 | final boolean isOwner = ActivityManager.getCurrentUser() == UserHandle.USER_OWNER; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 688 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 689 | if (currentTab == null) { |
| 690 | Log.w(TAG, "no tab selected; hiding body"); |
| 691 | mListView.setVisibility(View.GONE); |
| 692 | return; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 693 | } else { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 694 | mListView.setVisibility(View.VISIBLE); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 695 | } |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 696 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 697 | mCurrentTab = currentTab; |
| 698 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 699 | if (LOGD) Log.d(TAG, "updateBody() with currentTab=" + currentTab); |
| 700 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 701 | mDataEnabledView.setVisibility(isOwner ? View.VISIBLE : View.GONE); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 702 | |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 703 | // TODO: remove mobile tabs when SIM isn't ready |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 704 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 705 | if (TAB_MOBILE.equals(currentTab)) { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 706 | setPreferenceTitle(mDataEnabledView, R.string.data_usage_enable_mobile); |
| 707 | setPreferenceTitle(mDisableAtLimitView, R.string.data_usage_disable_mobile_limit); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 708 | mTemplate = buildTemplateMobileAll(getActiveSubscriberId(context)); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 709 | |
| 710 | } else if (TAB_3G.equals(currentTab)) { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 711 | setPreferenceTitle(mDataEnabledView, R.string.data_usage_enable_3g); |
| 712 | setPreferenceTitle(mDisableAtLimitView, R.string.data_usage_disable_3g_limit); |
| 713 | // TODO: bind mDataEnabled to 3G radio state |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 714 | mTemplate = buildTemplateMobile3gLower(getActiveSubscriberId(context)); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 715 | |
| 716 | } else if (TAB_4G.equals(currentTab)) { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 717 | setPreferenceTitle(mDataEnabledView, R.string.data_usage_enable_4g); |
| 718 | setPreferenceTitle(mDisableAtLimitView, R.string.data_usage_disable_4g_limit); |
| 719 | // TODO: bind mDataEnabled to 4G radio state |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 720 | mTemplate = buildTemplateMobile4g(getActiveSubscriberId(context)); |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 721 | |
| 722 | } else if (TAB_WIFI.equals(currentTab)) { |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 723 | // wifi doesn't have any controls |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 724 | mDataEnabledView.setVisibility(View.GONE); |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 725 | mDisableAtLimitView.setVisibility(View.GONE); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 726 | mTemplate = buildTemplateWifiWildcard(); |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 727 | |
| 728 | } else if (TAB_ETHERNET.equals(currentTab)) { |
| 729 | // ethernet doesn't have any controls |
| 730 | mDataEnabledView.setVisibility(View.GONE); |
| 731 | mDisableAtLimitView.setVisibility(View.GONE); |
| 732 | mTemplate = buildTemplateEthernet(); |
| 733 | |
| 734 | } else { |
| 735 | throw new IllegalStateException("unknown tab: " + currentTab); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 738 | // kick off loader for network history |
| 739 | // TODO: consider chaining two loaders together instead of reloading |
| 740 | // network history when showing app detail. |
| 741 | getLoaderManager().restartLoader(LOADER_CHART_DATA, |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 742 | ChartDataLoader.buildArgs(mTemplate, mCurrentApp), mChartDataCallbacks); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 743 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 744 | // detail mode can change visible menus, invalidate |
| 745 | getActivity().invalidateOptionsMenu(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 746 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 747 | mBinding = false; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 750 | private boolean isAppDetailMode() { |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 751 | return mCurrentApp != null; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /** |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 755 | * Update UID details panels to match {@link #mCurrentApp}, showing or |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 756 | * hiding them depending on {@link #isAppDetailMode()}. |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 757 | */ |
| 758 | private void updateAppDetail() { |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 759 | final Context context = getActivity(); |
| 760 | final PackageManager pm = context.getPackageManager(); |
| 761 | final LayoutInflater inflater = getActivity().getLayoutInflater(); |
| 762 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 763 | if (isAppDetailMode()) { |
| 764 | mAppDetail.setVisibility(View.VISIBLE); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 765 | mCycleAdapter.setChangeVisible(false); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 766 | } else { |
| 767 | mAppDetail.setVisibility(View.GONE); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 768 | mCycleAdapter.setChangeVisible(true); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 769 | |
| 770 | // hide detail stats when not in detail mode |
| 771 | mChart.bindDetailNetworkStats(null); |
| 772 | return; |
| 773 | } |
| 774 | |
| 775 | // remove warning/limit sweeps while in detail mode |
| 776 | mChart.bindNetworkPolicy(null); |
| 777 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 778 | // show icon and all labels appearing under this app |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 779 | final int uid = mCurrentApp.key; |
| 780 | final UidDetail detail = mUidDetailProvider.getUidDetail(uid, true); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 781 | mAppIcon.setImageDrawable(detail.icon); |
| 782 | |
| 783 | mAppTitles.removeAllViews(); |
| 784 | if (detail.detailLabels != null) { |
| 785 | for (CharSequence label : detail.detailLabels) { |
| 786 | mAppTitles.addView(inflateAppTitle(inflater, mAppTitles, label)); |
| 787 | } |
| 788 | } else { |
| 789 | mAppTitles.addView(inflateAppTitle(inflater, mAppTitles, detail.label)); |
| 790 | } |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 791 | |
| 792 | // enable settings button when package provides it |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 793 | final String[] packageNames = pm.getPackagesForUid(uid); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 794 | if (packageNames != null && packageNames.length > 0) { |
| 795 | mAppSettingsIntent = new Intent(Intent.ACTION_MANAGE_NETWORK_USAGE); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 796 | mAppSettingsIntent.addCategory(Intent.CATEGORY_DEFAULT); |
| 797 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 798 | // Search for match across all packages |
| 799 | boolean matchFound = false; |
| 800 | for (String packageName : packageNames) { |
| 801 | mAppSettingsIntent.setPackage(packageName); |
| 802 | if (pm.resolveActivity(mAppSettingsIntent, 0) != null) { |
| 803 | matchFound = true; |
| 804 | break; |
| 805 | } |
| 806 | } |
| 807 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 808 | mAppSettings.setEnabled(matchFound); |
Jeff Sharkey | d92e041 | 2012-04-24 11:35:43 -0700 | [diff] [blame] | 809 | mAppSettings.setVisibility(View.VISIBLE); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 810 | |
| 811 | } else { |
| 812 | mAppSettingsIntent = null; |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 813 | mAppSettings.setVisibility(View.GONE); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 816 | updateDetailData(); |
| 817 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 818 | if (UserHandle.isApp(uid) && !mPolicyManager.getRestrictBackground() |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 819 | && isBandwidthControlEnabled() && hasReadyMobileRadio(context)) { |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 820 | setPreferenceTitle(mAppRestrictView, R.string.data_usage_app_restrict_background); |
Jeff Sharkey | 3038c52 | 2011-11-30 15:37:51 -0800 | [diff] [blame] | 821 | setPreferenceSummary(mAppRestrictView, |
| 822 | getString(R.string.data_usage_app_restrict_background_summary)); |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 823 | |
| 824 | mAppRestrictView.setVisibility(View.VISIBLE); |
| 825 | mAppRestrict.setChecked(getAppRestrictBackground()); |
| 826 | |
| 827 | } else { |
| 828 | mAppRestrictView.setVisibility(View.GONE); |
| 829 | } |
| 830 | } |
| 831 | |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 832 | private void setPolicyWarningBytes(long warningBytes) { |
| 833 | if (LOGD) Log.d(TAG, "setPolicyWarningBytes()"); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 834 | mPolicyEditor.setPolicyWarningBytes(mTemplate, warningBytes); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 835 | updatePolicy(false); |
| 836 | } |
| 837 | |
| 838 | private void setPolicyLimitBytes(long limitBytes) { |
| 839 | if (LOGD) Log.d(TAG, "setPolicyLimitBytes()"); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 840 | mPolicyEditor.setPolicyLimitBytes(mTemplate, limitBytes); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 841 | updatePolicy(false); |
| 842 | } |
| 843 | |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 844 | /** |
| 845 | * Local cache of value, used to work around delay when |
| 846 | * {@link ConnectivityManager#setMobileDataEnabled(boolean)} is async. |
| 847 | */ |
| 848 | private Boolean mMobileDataEnabled; |
| 849 | |
| 850 | private boolean isMobileDataEnabled() { |
| 851 | if (mMobileDataEnabled != null) { |
| 852 | // TODO: deprecate and remove this once enabled flag is on policy |
| 853 | return mMobileDataEnabled; |
| 854 | } else { |
| 855 | return mConnService.getMobileDataEnabled(); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | private void setMobileDataEnabled(boolean enabled) { |
| 860 | if (LOGD) Log.d(TAG, "setMobileDataEnabled()"); |
| 861 | mConnService.setMobileDataEnabled(enabled); |
| 862 | mMobileDataEnabled = enabled; |
| 863 | updatePolicy(false); |
| 864 | } |
| 865 | |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 866 | private boolean isNetworkPolicyModifiable(NetworkPolicy policy) { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 867 | return policy != null && isBandwidthControlEnabled() && mDataEnabled.isChecked() |
| 868 | && ActivityManager.getCurrentUser() == UserHandle.USER_OWNER; |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | private boolean isBandwidthControlEnabled() { |
| 872 | try { |
| 873 | return mNetworkService.isBandwidthControlEnabled(); |
| 874 | } catch (RemoteException e) { |
| 875 | Log.w(TAG, "problem talking with INetworkManagementService: " + e); |
| 876 | return false; |
| 877 | } |
| 878 | } |
| 879 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 880 | private boolean getDataRoaming() { |
| 881 | final ContentResolver resolver = getActivity().getContentResolver(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 882 | return android.provider.Settings.Global.getInt(resolver, |
| 883 | android.provider.Settings.Global.DATA_ROAMING, 0) != 0; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | private void setDataRoaming(boolean enabled) { |
| 887 | // TODO: teach telephony DataConnectionTracker to watch and apply |
| 888 | // updates when changed. |
| 889 | final ContentResolver resolver = getActivity().getContentResolver(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 890 | android.provider.Settings.Global.putInt(resolver, |
| 891 | android.provider.Settings.Global.DATA_ROAMING, enabled ? 1 : 0); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 892 | mMenuDataRoaming.setChecked(enabled); |
| 893 | } |
| 894 | |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 895 | public void setRestrictBackground(boolean restrictBackground) { |
| 896 | mPolicyManager.setRestrictBackground(restrictBackground); |
| 897 | mMenuRestrictBackground.setChecked(restrictBackground); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | private boolean getAppRestrictBackground() { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 901 | final int uid = mCurrentApp.key; |
| 902 | final int uidPolicy = mPolicyManager.getUidPolicy(uid); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 903 | return (uidPolicy & POLICY_REJECT_METERED_BACKGROUND) != 0; |
| 904 | } |
| 905 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 906 | private void setAppRestrictBackground(boolean restrictBackground) { |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 907 | if (LOGD) Log.d(TAG, "setAppRestrictBackground()"); |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 908 | final int uid = mCurrentApp.key; |
| 909 | mPolicyManager.setUidPolicy( |
| 910 | uid, restrictBackground ? POLICY_REJECT_METERED_BACKGROUND : POLICY_NONE); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 911 | mAppRestrict.setChecked(restrictBackground); |
| 912 | } |
| 913 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 914 | /** |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 915 | * Update chart sweeps and cycle list to reflect {@link NetworkPolicy} for |
| 916 | * current {@link #mTemplate}. |
| 917 | */ |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 918 | private void updatePolicy(boolean refreshCycle) { |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 919 | if (isAppDetailMode()) { |
| 920 | mNetworkSwitches.setVisibility(View.GONE); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 921 | } else { |
| 922 | mNetworkSwitches.setVisibility(View.VISIBLE); |
| 923 | } |
| 924 | |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 925 | // TODO: move enabled state directly into policy |
| 926 | if (TAB_MOBILE.equals(mCurrentTab)) { |
| 927 | mBinding = true; |
| 928 | mDataEnabled.setChecked(isMobileDataEnabled()); |
| 929 | mBinding = false; |
| 930 | } |
| 931 | |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 932 | final NetworkPolicy policy = mPolicyEditor.getPolicy(mTemplate); |
| 933 | if (isNetworkPolicyModifiable(policy)) { |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 934 | mDisableAtLimitView.setVisibility(View.VISIBLE); |
| 935 | mDisableAtLimit.setChecked(policy != null && policy.limitBytes != LIMIT_DISABLED); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 936 | if (!isAppDetailMode()) { |
| 937 | mChart.bindNetworkPolicy(policy); |
| 938 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 939 | |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 940 | } else { |
| 941 | // controls are disabled; don't bind warning/limit sweeps |
| 942 | mDisableAtLimitView.setVisibility(View.GONE); |
| 943 | mChart.bindNetworkPolicy(null); |
| 944 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 945 | |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 946 | if (refreshCycle) { |
| 947 | // generate cycle list based on policy and available history |
| 948 | updateCycleList(policy); |
| 949 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | /** |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 953 | * Rebuild {@link #mCycleAdapter} based on {@link NetworkPolicy#cycleDay} |
| 954 | * and available {@link NetworkStatsHistory} data. Always selects the newest |
| 955 | * item, updating the inspection range on {@link #mChart}. |
| 956 | */ |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 957 | private void updateCycleList(NetworkPolicy policy) { |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 958 | // stash away currently selected cycle to try restoring below |
| 959 | final CycleItem previousItem = (CycleItem) mCycleSpinner.getSelectedItem(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 960 | mCycleAdapter.clear(); |
| 961 | |
| 962 | final Context context = mCycleSpinner.getContext(); |
| 963 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 964 | long historyStart = Long.MAX_VALUE; |
| 965 | long historyEnd = Long.MIN_VALUE; |
| 966 | if (mChartData != null) { |
| 967 | historyStart = mChartData.network.getStart(); |
| 968 | historyEnd = mChartData.network.getEnd(); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 969 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 970 | |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 971 | final long now = System.currentTimeMillis(); |
| 972 | if (historyStart == Long.MAX_VALUE) historyStart = now; |
| 973 | if (historyEnd == Long.MIN_VALUE) historyEnd = now + 1; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 974 | |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 975 | boolean hasCycles = false; |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 976 | if (policy != null) { |
| 977 | // find the next cycle boundary |
| 978 | long cycleEnd = computeNextCycleBoundary(historyEnd, policy); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 979 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 980 | // walk backwards, generating all valid cycle ranges |
| 981 | while (cycleEnd > historyStart) { |
| 982 | final long cycleStart = computeLastCycleBoundary(cycleEnd, policy); |
| 983 | Log.d(TAG, "generating cs=" + cycleStart + " to ce=" + cycleEnd + " waiting for hs=" |
| 984 | + historyStart); |
| 985 | mCycleAdapter.add(new CycleItem(context, cycleStart, cycleEnd)); |
| 986 | cycleEnd = cycleStart; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 987 | hasCycles = true; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 988 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 989 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 990 | // one last cycle entry to modify policy cycle day |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 991 | mCycleAdapter.setChangePossible(isNetworkPolicyModifiable(policy)); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 992 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 993 | |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 994 | if (!hasCycles) { |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 995 | // no policy defined cycles; show entry for each four-week period |
| 996 | long cycleEnd = historyEnd; |
| 997 | while (cycleEnd > historyStart) { |
| 998 | final long cycleStart = cycleEnd - (DateUtils.WEEK_IN_MILLIS * 4); |
| 999 | mCycleAdapter.add(new CycleItem(context, cycleStart, cycleEnd)); |
| 1000 | cycleEnd = cycleStart; |
| 1001 | } |
| 1002 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1003 | mCycleAdapter.setChangePossible(false); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1004 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1005 | |
| 1006 | // force pick the current cycle (first item) |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 1007 | if (mCycleAdapter.getCount() > 0) { |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1008 | final int position = mCycleAdapter.findNearestPosition(previousItem); |
| 1009 | mCycleSpinner.setSelection(position); |
| 1010 | |
| 1011 | // only force-update cycle when changed; skipping preserves any |
| 1012 | // user-defined inspection region. |
| 1013 | final CycleItem selectedItem = mCycleAdapter.getItem(position); |
| 1014 | if (!Objects.equal(selectedItem, previousItem)) { |
| 1015 | mCycleListener.onItemSelected(mCycleSpinner, null, position, 0); |
| 1016 | } else { |
| 1017 | // but still kick off loader for detailed list |
| 1018 | updateDetailData(); |
| 1019 | } |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 1020 | } else { |
| 1021 | updateDetailData(); |
| 1022 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1025 | private OnCheckedChangeListener mDataEnabledListener = new OnCheckedChangeListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1026 | @Override |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1027 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 1028 | if (mBinding) return; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1029 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1030 | final boolean dataEnabled = isChecked; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1031 | final String currentTab = mCurrentTab; |
| 1032 | if (TAB_MOBILE.equals(currentTab)) { |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 1033 | if (dataEnabled) { |
| 1034 | setMobileDataEnabled(true); |
| 1035 | } else { |
| 1036 | // disabling data; show confirmation dialog which eventually |
| 1037 | // calls setMobileDataEnabled() once user confirms. |
| 1038 | ConfirmDataDisableFragment.show(DataUsageSummary.this); |
| 1039 | } |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1040 | } |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 1041 | |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 1042 | updatePolicy(false); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1043 | } |
| 1044 | }; |
| 1045 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1046 | private View.OnClickListener mDisableAtLimitListener = new View.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1047 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1048 | public void onClick(View v) { |
| 1049 | final boolean disableAtLimit = !mDisableAtLimit.isChecked(); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1050 | if (disableAtLimit) { |
| 1051 | // enabling limit; show confirmation dialog which eventually |
| 1052 | // calls setPolicyLimitBytes() once user confirms. |
| 1053 | ConfirmLimitFragment.show(DataUsageSummary.this); |
| 1054 | } else { |
| 1055 | setPolicyLimitBytes(LIMIT_DISABLED); |
| 1056 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1057 | } |
| 1058 | }; |
| 1059 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1060 | private View.OnClickListener mAppRestrictListener = new View.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1061 | @Override |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1062 | public void onClick(View v) { |
| 1063 | final boolean restrictBackground = !mAppRestrict.isChecked(); |
| 1064 | |
| 1065 | if (restrictBackground) { |
Jeff Sharkey | 3038c52 | 2011-11-30 15:37:51 -0800 | [diff] [blame] | 1066 | // enabling restriction; show confirmation dialog which |
| 1067 | // eventually calls setRestrictBackground() once user |
| 1068 | // confirms. |
| 1069 | ConfirmAppRestrictFragment.show(DataUsageSummary.this); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1070 | } else { |
| 1071 | setAppRestrictBackground(false); |
| 1072 | } |
| 1073 | } |
| 1074 | }; |
| 1075 | |
| 1076 | private OnClickListener mAppSettingsListener = new OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1077 | @Override |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1078 | public void onClick(View v) { |
Jeff Sharkey | d92e041 | 2012-04-24 11:35:43 -0700 | [diff] [blame] | 1079 | if (!isAdded()) return; |
| 1080 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1081 | // TODO: target torwards entire UID instead of just first package |
| 1082 | startActivity(mAppSettingsIntent); |
| 1083 | } |
| 1084 | }; |
| 1085 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1086 | private OnItemClickListener mListListener = new OnItemClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1087 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1088 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 1089 | final Context context = view.getContext(); |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1090 | final AppItem app = (AppItem) parent.getItemAtPosition(position); |
Jeff Sharkey | 3da415f | 2012-05-18 14:00:10 -0700 | [diff] [blame] | 1091 | |
| 1092 | // TODO: sigh, remove this hack once we understand 6450986 |
| 1093 | if (mUidDetailProvider == null || app == null) return; |
| 1094 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1095 | final UidDetail detail = mUidDetailProvider.getUidDetail(app.key, true); |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1096 | AppDetailsFragment.show(DataUsageSummary.this, app, detail.label); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1097 | } |
| 1098 | }; |
| 1099 | |
| 1100 | private OnItemSelectedListener mCycleListener = new OnItemSelectedListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1101 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1102 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 1103 | final CycleItem cycle = (CycleItem) parent.getItemAtPosition(position); |
| 1104 | if (cycle instanceof CycleChangeItem) { |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1105 | // show cycle editor; will eventually call setPolicyCycleDay() |
| 1106 | // when user finishes editing. |
| 1107 | CycleEditorFragment.show(DataUsageSummary.this); |
| 1108 | |
| 1109 | // reset spinner to something other than "change cycle..." |
| 1110 | mCycleSpinner.setSelection(0); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1111 | |
| 1112 | } else { |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1113 | if (LOGD) { |
| 1114 | Log.d(TAG, "showing cycle " + cycle + ", start=" + cycle.start + ", end=" |
| 1115 | + cycle.end + "]"); |
| 1116 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1117 | |
| 1118 | // update chart to show selected cycle, and update detail data |
| 1119 | // to match updated sweep bounds. |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1120 | mChart.setVisibleRange(cycle.start, cycle.end); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1121 | |
| 1122 | updateDetailData(); |
| 1123 | } |
| 1124 | } |
| 1125 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1126 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1127 | public void onNothingSelected(AdapterView<?> parent) { |
| 1128 | // ignored |
| 1129 | } |
| 1130 | }; |
| 1131 | |
| 1132 | /** |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1133 | * Update details based on {@link #mChart} inspection range depending on |
| 1134 | * current mode. In network mode, updates {@link #mAdapter} with sorted list |
| 1135 | * of applications data usage, and when {@link #isAppDetailMode()} update |
| 1136 | * app details. |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1137 | */ |
| 1138 | private void updateDetailData() { |
| 1139 | if (LOGD) Log.d(TAG, "updateDetailData()"); |
| 1140 | |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1141 | final long start = mChart.getInspectStart(); |
| 1142 | final long end = mChart.getInspectEnd(); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1143 | final long now = System.currentTimeMillis(); |
| 1144 | |
| 1145 | final Context context = getActivity(); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1146 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1147 | NetworkStatsHistory.Entry entry = null; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1148 | if (isAppDetailMode() && mChartData != null && mChartData.detail != null) { |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1149 | // bind foreground/background to piechart and labels |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1150 | entry = mChartData.detailDefault.getValues(start, end, now, entry); |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1151 | final long defaultBytes = entry.rxBytes + entry.txBytes; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1152 | entry = mChartData.detailForeground.getValues(start, end, now, entry); |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1153 | final long foregroundBytes = entry.rxBytes + entry.txBytes; |
| 1154 | |
| 1155 | mAppPieChart.setOriginAngle(175); |
| 1156 | |
| 1157 | mAppPieChart.removeAllSlices(); |
| 1158 | mAppPieChart.addSlice(foregroundBytes, Color.parseColor("#d88d3a")); |
| 1159 | mAppPieChart.addSlice(defaultBytes, Color.parseColor("#666666")); |
| 1160 | |
| 1161 | mAppPieChart.generatePath(); |
| 1162 | |
| 1163 | mAppBackground.setText(Formatter.formatFileSize(context, defaultBytes)); |
| 1164 | mAppForeground.setText(Formatter.formatFileSize(context, foregroundBytes)); |
| 1165 | |
| 1166 | // and finally leave with summary data for label below |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1167 | entry = mChartData.detail.getValues(start, end, now, null); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1168 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1169 | getLoaderManager().destroyLoader(LOADER_SUMMARY); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1170 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1171 | } else { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1172 | if (mChartData != null) { |
| 1173 | entry = mChartData.network.getValues(start, end, now, null); |
| 1174 | } |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1175 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1176 | // kick off loader for detailed stats |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1177 | getLoaderManager().restartLoader(LOADER_SUMMARY, |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1178 | SummaryForAllUidLoader.buildArgs(mTemplate, start, end), mSummaryCallbacks); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1179 | } |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1180 | |
| 1181 | final long totalBytes = entry != null ? entry.rxBytes + entry.txBytes : 0; |
| 1182 | final String totalPhrase = Formatter.formatFileSize(context, totalBytes); |
Jeff Sharkey | e5223a0 | 2012-03-09 17:11:14 -0800 | [diff] [blame] | 1183 | final String rangePhrase = formatDateRange(context, start, end); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1184 | |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1185 | final int summaryRes; |
László Dávid | 0b8bf4e | 2012-10-24 23:31:47 +0200 | [diff] [blame] | 1186 | if (TAB_MOBILE.equals(mCurrentTab) || TAB_3G.equals(mCurrentTab) |
| 1187 | || TAB_4G.equals(mCurrentTab)) { |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1188 | summaryRes = R.string.data_usage_total_during_range_mobile; |
| 1189 | } else { |
| 1190 | summaryRes = R.string.data_usage_total_during_range; |
| 1191 | } |
| 1192 | |
| 1193 | mUsageSummary.setText(getString(summaryRes, totalPhrase, rangePhrase)); |
Jeff Sharkey | 9281182 | 2012-05-04 11:47:29 -0700 | [diff] [blame] | 1194 | |
| 1195 | // initial layout is finished above, ensure we have transitions |
| 1196 | ensureLayoutTransitions(); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1199 | private final LoaderCallbacks<ChartData> mChartDataCallbacks = new LoaderCallbacks< |
| 1200 | ChartData>() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1201 | @Override |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1202 | public Loader<ChartData> onCreateLoader(int id, Bundle args) { |
Jeff Sharkey | 08ce99e | 2012-04-06 11:21:28 -0700 | [diff] [blame] | 1203 | return new ChartDataLoader(getActivity(), mStatsSession, args); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1204 | } |
| 1205 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1206 | @Override |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1207 | public void onLoadFinished(Loader<ChartData> loader, ChartData data) { |
| 1208 | mChartData = data; |
| 1209 | mChart.bindNetworkStats(mChartData.network); |
| 1210 | mChart.bindDetailNetworkStats(mChartData.detail); |
| 1211 | |
| 1212 | // calcuate policy cycles based on available data |
| 1213 | updatePolicy(true); |
| 1214 | updateAppDetail(); |
| 1215 | |
| 1216 | // force scroll to top of body when showing detail |
| 1217 | if (mChartData.detail != null) { |
| 1218 | mListView.smoothScrollToPosition(0); |
| 1219 | } |
| 1220 | } |
| 1221 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1222 | @Override |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1223 | public void onLoaderReset(Loader<ChartData> loader) { |
| 1224 | mChartData = null; |
| 1225 | mChart.bindNetworkStats(null); |
| 1226 | mChart.bindDetailNetworkStats(null); |
| 1227 | } |
| 1228 | }; |
| 1229 | |
| 1230 | private final LoaderCallbacks<NetworkStats> mSummaryCallbacks = new LoaderCallbacks< |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1231 | NetworkStats>() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1232 | @Override |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1233 | public Loader<NetworkStats> onCreateLoader(int id, Bundle args) { |
Jeff Sharkey | 08ce99e | 2012-04-06 11:21:28 -0700 | [diff] [blame] | 1234 | return new SummaryForAllUidLoader(getActivity(), mStatsSession, args); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1237 | @Override |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1238 | public void onLoadFinished(Loader<NetworkStats> loader, NetworkStats data) { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1239 | final int[] restrictedUids = mPolicyManager.getUidsWithPolicy( |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1240 | POLICY_REJECT_METERED_BACKGROUND); |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1241 | mAdapter.bindStats(data, restrictedUids); |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 1242 | updateEmptyVisible(); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1243 | } |
Jeff Sharkey | aa5260e | 2011-06-14 23:21:59 -0700 | [diff] [blame] | 1244 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1245 | @Override |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1246 | public void onLoaderReset(Loader<NetworkStats> loader) { |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1247 | mAdapter.bindStats(null, new int[0]); |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 1248 | updateEmptyVisible(); |
| 1249 | } |
| 1250 | |
| 1251 | private void updateEmptyVisible() { |
| 1252 | final boolean isEmpty = mAdapter.isEmpty() && !isAppDetailMode(); |
| 1253 | mEmpty.setVisibility(isEmpty ? View.VISIBLE : View.GONE); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1254 | } |
| 1255 | }; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1256 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1257 | @Deprecated |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1258 | private boolean isMobilePolicySplit() { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1259 | final Context context = getActivity(); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 1260 | if (hasReadyMobileRadio(context)) { |
| 1261 | final TelephonyManager tele = TelephonyManager.from(context); |
| 1262 | return mPolicyEditor.isMobilePolicySplit(getActiveSubscriberId(context)); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1263 | } else { |
| 1264 | return false; |
| 1265 | } |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1268 | @Deprecated |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1269 | private void setMobilePolicySplit(boolean split) { |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 1270 | final Context context = getActivity(); |
| 1271 | if (hasReadyMobileRadio(context)) { |
| 1272 | final TelephonyManager tele = TelephonyManager.from(context); |
| 1273 | mPolicyEditor.setMobilePolicySplit(getActiveSubscriberId(context), split); |
| 1274 | } |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1277 | private static String getActiveSubscriberId(Context context) { |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 1278 | final TelephonyManager tele = TelephonyManager.from(context); |
| 1279 | final String actualSubscriberId = tele.getSubscriberId(); |
Jeff Sharkey | f3871fb | 2012-02-03 19:27:07 -0800 | [diff] [blame] | 1280 | return SystemProperties.get(TEST_SUBSCRIBER_PROP, actualSubscriberId); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1283 | private DataUsageChartListener mChartListener = new DataUsageChartListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1284 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1285 | public void onInspectRangeChanged() { |
| 1286 | if (LOGD) Log.d(TAG, "onInspectRangeChanged()"); |
| 1287 | updateDetailData(); |
| 1288 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1289 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1290 | @Override |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1291 | public void onWarningChanged() { |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1292 | setPolicyWarningBytes(mChart.getWarningBytes()); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1293 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1294 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1295 | @Override |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1296 | public void onLimitChanged() { |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1297 | setPolicyLimitBytes(mChart.getLimitBytes()); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1298 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1299 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1300 | @Override |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1301 | public void requestWarningEdit() { |
| 1302 | WarningEditorFragment.show(DataUsageSummary.this); |
| 1303 | } |
| 1304 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1305 | @Override |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1306 | public void requestLimitEdit() { |
| 1307 | LimitEditorFragment.show(DataUsageSummary.this); |
| 1308 | } |
| 1309 | }; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1310 | |
| 1311 | /** |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1312 | * List item that reflects a specific data usage cycle. |
| 1313 | */ |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1314 | public static class CycleItem implements Comparable<CycleItem> { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1315 | public CharSequence label; |
| 1316 | public long start; |
| 1317 | public long end; |
| 1318 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1319 | CycleItem(CharSequence label) { |
| 1320 | this.label = label; |
| 1321 | } |
| 1322 | |
| 1323 | public CycleItem(Context context, long start, long end) { |
Jeff Sharkey | e5223a0 | 2012-03-09 17:11:14 -0800 | [diff] [blame] | 1324 | this.label = formatDateRange(context, start, end); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1325 | this.start = start; |
| 1326 | this.end = end; |
| 1327 | } |
| 1328 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1329 | @Override |
| 1330 | public String toString() { |
| 1331 | return label.toString(); |
| 1332 | } |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1333 | |
| 1334 | @Override |
| 1335 | public boolean equals(Object o) { |
| 1336 | if (o instanceof CycleItem) { |
| 1337 | final CycleItem another = (CycleItem) o; |
| 1338 | return start == another.start && end == another.end; |
| 1339 | } |
| 1340 | return false; |
| 1341 | } |
| 1342 | |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1343 | @Override |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1344 | public int compareTo(CycleItem another) { |
| 1345 | return Long.compare(start, another.start); |
| 1346 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1349 | private static final StringBuilder sBuilder = new StringBuilder(50); |
| 1350 | private static final java.util.Formatter sFormatter = new java.util.Formatter( |
| 1351 | sBuilder, Locale.getDefault()); |
| 1352 | |
Jeff Sharkey | e5223a0 | 2012-03-09 17:11:14 -0800 | [diff] [blame] | 1353 | public static String formatDateRange(Context context, long start, long end) { |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1354 | final int flags = FORMAT_SHOW_DATE | FORMAT_ABBREV_MONTH; |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1355 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1356 | synchronized (sBuilder) { |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1357 | sBuilder.setLength(0); |
Jeff Sharkey | e5223a0 | 2012-03-09 17:11:14 -0800 | [diff] [blame] | 1358 | return DateUtils.formatDateRange(context, sFormatter, start, end, flags, null) |
| 1359 | .toString(); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1363 | /** |
| 1364 | * Special-case data usage cycle that triggers dialog to change |
| 1365 | * {@link NetworkPolicy#cycleDay}. |
| 1366 | */ |
| 1367 | public static class CycleChangeItem extends CycleItem { |
| 1368 | public CycleChangeItem(Context context) { |
| 1369 | super(context.getString(R.string.data_usage_change_cycle)); |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | public static class CycleAdapter extends ArrayAdapter<CycleItem> { |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1374 | private boolean mChangePossible = false; |
| 1375 | private boolean mChangeVisible = false; |
| 1376 | |
| 1377 | private final CycleChangeItem mChangeItem; |
| 1378 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1379 | public CycleAdapter(Context context) { |
| 1380 | super(context, android.R.layout.simple_spinner_item); |
| 1381 | setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1382 | mChangeItem = new CycleChangeItem(context); |
| 1383 | } |
| 1384 | |
| 1385 | public void setChangePossible(boolean possible) { |
| 1386 | mChangePossible = possible; |
| 1387 | updateChange(); |
| 1388 | } |
| 1389 | |
| 1390 | public void setChangeVisible(boolean visible) { |
| 1391 | mChangeVisible = visible; |
| 1392 | updateChange(); |
| 1393 | } |
| 1394 | |
| 1395 | private void updateChange() { |
| 1396 | remove(mChangeItem); |
| 1397 | if (mChangePossible && mChangeVisible) { |
| 1398 | add(mChangeItem); |
| 1399 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1400 | } |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1401 | |
| 1402 | /** |
| 1403 | * Find position of {@link CycleItem} in this adapter which is nearest |
| 1404 | * the given {@link CycleItem}. |
| 1405 | */ |
| 1406 | public int findNearestPosition(CycleItem target) { |
| 1407 | if (target != null) { |
| 1408 | final int count = getCount(); |
| 1409 | for (int i = count - 1; i >= 0; i--) { |
| 1410 | final CycleItem item = getItem(i); |
| 1411 | if (item instanceof CycleChangeItem) { |
| 1412 | continue; |
| 1413 | } else if (item.compareTo(target) >= 0) { |
| 1414 | return i; |
| 1415 | } |
| 1416 | } |
| 1417 | } |
| 1418 | return 0; |
| 1419 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1422 | public static class AppItem implements Comparable<AppItem>, Parcelable { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1423 | public final int key; |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1424 | public boolean restricted; |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1425 | public SparseBooleanArray uids = new SparseBooleanArray(); |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 1426 | public long total; |
| 1427 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1428 | public AppItem(int key) { |
| 1429 | this.key = key; |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | public AppItem(Parcel parcel) { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1433 | key = parcel.readInt(); |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1434 | uids = parcel.readSparseBooleanArray(); |
| 1435 | total = parcel.readLong(); |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | public void addUid(int uid) { |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1439 | uids.put(uid, true); |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1442 | @Override |
| 1443 | public void writeToParcel(Parcel dest, int flags) { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1444 | dest.writeInt(key); |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1445 | dest.writeSparseBooleanArray(uids); |
| 1446 | dest.writeLong(total); |
| 1447 | } |
| 1448 | |
| 1449 | @Override |
| 1450 | public int describeContents() { |
| 1451 | return 0; |
| 1452 | } |
| 1453 | |
| 1454 | @Override |
| 1455 | public int compareTo(AppItem another) { |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 1456 | return Long.compare(another.total, total); |
| 1457 | } |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1458 | |
| 1459 | public static final Creator<AppItem> CREATOR = new Creator<AppItem>() { |
| 1460 | @Override |
| 1461 | public AppItem createFromParcel(Parcel in) { |
| 1462 | return new AppItem(in); |
| 1463 | } |
| 1464 | |
| 1465 | @Override |
| 1466 | public AppItem[] newArray(int size) { |
| 1467 | return new AppItem[size]; |
| 1468 | } |
| 1469 | }; |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 1470 | } |
| 1471 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1472 | /** |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1473 | * Adapter of applications, sorted by total usage descending. |
| 1474 | */ |
| 1475 | public static class DataUsageAdapter extends BaseAdapter { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1476 | private final UidDetailProvider mProvider; |
| 1477 | private final int mInsetSide; |
| 1478 | |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1479 | private ArrayList<AppItem> mItems = Lists.newArrayList(); |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1480 | private long mLargest; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1481 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1482 | public DataUsageAdapter(UidDetailProvider provider, int insetSide) { |
| 1483 | mProvider = checkNotNull(provider); |
| 1484 | mInsetSide = insetSide; |
| 1485 | } |
| 1486 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1487 | /** |
| 1488 | * Bind the given {@link NetworkStats}, or {@code null} to clear list. |
| 1489 | */ |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1490 | public void bindStats(NetworkStats stats, int[] restrictedUids) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1491 | mItems.clear(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1492 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1493 | final int currentUserId = ActivityManager.getCurrentUser(); |
| 1494 | final SparseArray<AppItem> knownItems = new SparseArray<AppItem>(); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1495 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1496 | NetworkStats.Entry entry = null; |
| 1497 | final int size = stats != null ? stats.size() : 0; |
| 1498 | for (int i = 0; i < size; i++) { |
| 1499 | entry = stats.getValues(i, entry); |
| 1500 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1501 | // Decide how to collapse items together |
| 1502 | final int uid = entry.uid; |
| 1503 | final int collapseKey; |
| 1504 | if (UserHandle.isApp(uid)) { |
| 1505 | if (UserHandle.getUserId(uid) == currentUserId) { |
| 1506 | collapseKey = uid; |
| 1507 | } else { |
| 1508 | collapseKey = UidDetailProvider.buildKeyForUser(UserHandle.getUserId(uid)); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1509 | } |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1510 | } else if (uid == UID_REMOVED || uid == UID_TETHERING) { |
| 1511 | collapseKey = uid; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1512 | } else { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1513 | collapseKey = android.os.Process.SYSTEM_UID; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1514 | } |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1515 | |
| 1516 | AppItem item = knownItems.get(collapseKey); |
| 1517 | if (item == null) { |
| 1518 | item = new AppItem(collapseKey); |
| 1519 | mItems.add(item); |
| 1520 | knownItems.put(item.key, item); |
| 1521 | } |
| 1522 | item.addUid(uid); |
| 1523 | item.total += entry.rxBytes + entry.txBytes; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1526 | for (int uid : restrictedUids) { |
| 1527 | // Only splice in restricted state for current user |
| 1528 | if (UserHandle.getUserId(uid) != currentUserId) continue; |
| 1529 | |
| 1530 | AppItem item = knownItems.get(uid); |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1531 | if (item == null) { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1532 | item = new AppItem(uid); |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1533 | item.total = -1; |
| 1534 | mItems.add(item); |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1535 | knownItems.put(item.key, item); |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1536 | } |
| 1537 | item.restricted = true; |
| 1538 | } |
| 1539 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1540 | Collections.sort(mItems); |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1541 | mLargest = (mItems.size() > 0) ? mItems.get(0).total : 0; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1542 | notifyDataSetChanged(); |
| 1543 | } |
| 1544 | |
| 1545 | @Override |
| 1546 | public int getCount() { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1547 | return mItems.size(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | @Override |
| 1551 | public Object getItem(int position) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1552 | return mItems.get(position); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | @Override |
| 1556 | public long getItemId(int position) { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 1557 | return mItems.get(position).key; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | @Override |
| 1561 | public View getView(int position, View convertView, ViewGroup parent) { |
| 1562 | if (convertView == null) { |
| 1563 | convertView = LayoutInflater.from(parent.getContext()).inflate( |
Jeff Sharkey | 5d70679 | 2011-09-08 18:57:17 -0700 | [diff] [blame] | 1564 | R.layout.data_usage_item, parent, false); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1565 | |
| 1566 | if (mInsetSide > 0) { |
Fabrice Di Meglio | b27223f | 2013-01-15 18:54:11 -0800 | [diff] [blame] | 1567 | convertView.setPaddingRelative(mInsetSide, 0, mInsetSide, 0); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1568 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | final Context context = parent.getContext(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1572 | |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 1573 | final TextView text1 = (TextView) convertView.findViewById(android.R.id.text1); |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1574 | final ProgressBar progress = (ProgressBar) convertView.findViewById( |
| 1575 | android.R.id.progress); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1576 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1577 | // kick off async load of app details |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1578 | final AppItem item = mItems.get(position); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 1579 | UidDetailTask.bindView(mProvider, item, convertView); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1580 | |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1581 | if (item.restricted && item.total <= 0) { |
| 1582 | text1.setText(R.string.data_usage_app_restricted); |
| 1583 | progress.setVisibility(View.GONE); |
| 1584 | } else { |
| 1585 | text1.setText(Formatter.formatFileSize(context, item.total)); |
| 1586 | progress.setVisibility(View.VISIBLE); |
| 1587 | } |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1588 | |
| 1589 | final int percentTotal = mLargest != 0 ? (int) (item.total * 100 / mLargest) : 0; |
| 1590 | progress.setProgress(percentTotal); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1591 | |
| 1592 | return convertView; |
| 1593 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1596 | /** |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1597 | * Empty {@link Fragment} that controls display of UID details in |
| 1598 | * {@link DataUsageSummary}. |
| 1599 | */ |
| 1600 | public static class AppDetailsFragment extends Fragment { |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1601 | private static final String EXTRA_APP = "app"; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1602 | |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1603 | public static void show(DataUsageSummary parent, AppItem app, CharSequence label) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1604 | if (!parent.isAdded()) return; |
| 1605 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1606 | final Bundle args = new Bundle(); |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1607 | args.putParcelable(EXTRA_APP, app); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1608 | |
| 1609 | final AppDetailsFragment fragment = new AppDetailsFragment(); |
| 1610 | fragment.setArguments(args); |
| 1611 | fragment.setTargetFragment(parent, 0); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1612 | final FragmentTransaction ft = parent.getFragmentManager().beginTransaction(); |
| 1613 | ft.add(fragment, TAG_APP_DETAILS); |
| 1614 | ft.addToBackStack(TAG_APP_DETAILS); |
Jeff Sharkey | 55d18a5 | 2011-08-27 17:09:43 -0700 | [diff] [blame] | 1615 | ft.setBreadCrumbTitle(label); |
Jeff Sharkey | 3235ddb | 2012-03-15 16:40:31 -0700 | [diff] [blame] | 1616 | ft.commitAllowingStateLoss(); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | @Override |
| 1620 | public void onStart() { |
| 1621 | super.onStart(); |
| 1622 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1623 | target.mCurrentApp = getArguments().getParcelable(EXTRA_APP); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1624 | target.updateBody(); |
| 1625 | } |
| 1626 | |
| 1627 | @Override |
| 1628 | public void onStop() { |
| 1629 | super.onStop(); |
| 1630 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 1631 | target.mCurrentApp = null; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1632 | target.updateBody(); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | /** |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1637 | * Dialog to request user confirmation before setting |
| 1638 | * {@link NetworkPolicy#limitBytes}. |
| 1639 | */ |
| 1640 | public static class ConfirmLimitFragment extends DialogFragment { |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 1641 | private static final String EXTRA_MESSAGE = "message"; |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1642 | private static final String EXTRA_LIMIT_BYTES = "limitBytes"; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1643 | |
| 1644 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1645 | if (!parent.isAdded()) return; |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 1646 | |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1647 | final Resources res = parent.getResources(); |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 1648 | final CharSequence message; |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 1649 | final long minLimitBytes = (long) ( |
| 1650 | parent.mPolicyEditor.getPolicy(parent.mTemplate).warningBytes * 1.2f); |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 1651 | final long limitBytes; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1652 | |
| 1653 | // TODO: customize default limits based on network template |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1654 | final String currentTab = parent.mCurrentTab; |
| 1655 | if (TAB_3G.equals(currentTab)) { |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1656 | message = res.getString(R.string.data_usage_limit_dialog_mobile); |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 1657 | limitBytes = Math.max(5 * GB_IN_BYTES, minLimitBytes); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1658 | } else if (TAB_4G.equals(currentTab)) { |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1659 | message = res.getString(R.string.data_usage_limit_dialog_mobile); |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 1660 | limitBytes = Math.max(5 * GB_IN_BYTES, minLimitBytes); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1661 | } else if (TAB_MOBILE.equals(currentTab)) { |
Jeff Sharkey | e557c33 | 2012-04-13 16:04:07 -0700 | [diff] [blame] | 1662 | message = res.getString(R.string.data_usage_limit_dialog_mobile); |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 1663 | limitBytes = Math.max(5 * GB_IN_BYTES, minLimitBytes); |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 1664 | } else { |
| 1665 | throw new IllegalArgumentException("unknown current tab: " + currentTab); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1666 | } |
| 1667 | |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 1668 | final Bundle args = new Bundle(); |
| 1669 | args.putCharSequence(EXTRA_MESSAGE, message); |
| 1670 | args.putLong(EXTRA_LIMIT_BYTES, limitBytes); |
| 1671 | |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1672 | final ConfirmLimitFragment dialog = new ConfirmLimitFragment(); |
| 1673 | dialog.setArguments(args); |
| 1674 | dialog.setTargetFragment(parent, 0); |
| 1675 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_LIMIT); |
| 1676 | } |
| 1677 | |
| 1678 | @Override |
| 1679 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1680 | final Context context = getActivity(); |
| 1681 | |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 1682 | final CharSequence message = getArguments().getCharSequence(EXTRA_MESSAGE); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1683 | final long limitBytes = getArguments().getLong(EXTRA_LIMIT_BYTES); |
| 1684 | |
| 1685 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1686 | builder.setTitle(R.string.data_usage_limit_dialog_title); |
Jeff Sharkey | 131f9d6 | 2011-08-17 17:08:19 -0700 | [diff] [blame] | 1687 | builder.setMessage(message); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1688 | |
| 1689 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1690 | @Override |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1691 | public void onClick(DialogInterface dialog, int which) { |
| 1692 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1693 | if (target != null) { |
| 1694 | target.setPolicyLimitBytes(limitBytes); |
| 1695 | } |
| 1696 | } |
| 1697 | }); |
| 1698 | |
| 1699 | return builder.create(); |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | /** |
| 1704 | * Dialog to edit {@link NetworkPolicy#cycleDay}. |
| 1705 | */ |
| 1706 | public static class CycleEditorFragment extends DialogFragment { |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1707 | private static final String EXTRA_TEMPLATE = "template"; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1708 | |
| 1709 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1710 | if (!parent.isAdded()) return; |
| 1711 | |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1712 | final Bundle args = new Bundle(); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1713 | args.putParcelable(EXTRA_TEMPLATE, parent.mTemplate); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1714 | |
| 1715 | final CycleEditorFragment dialog = new CycleEditorFragment(); |
| 1716 | dialog.setArguments(args); |
| 1717 | dialog.setTargetFragment(parent, 0); |
| 1718 | dialog.show(parent.getFragmentManager(), TAG_CYCLE_EDITOR); |
| 1719 | } |
| 1720 | |
| 1721 | @Override |
| 1722 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1723 | final Context context = getActivity(); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1724 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1725 | final NetworkPolicyEditor editor = target.mPolicyEditor; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1726 | |
| 1727 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1728 | final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext()); |
| 1729 | |
| 1730 | final View view = dialogInflater.inflate(R.layout.data_usage_cycle_editor, null, false); |
| 1731 | final NumberPicker cycleDayPicker = (NumberPicker) view.findViewById(R.id.cycle_day); |
| 1732 | |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1733 | final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE); |
| 1734 | final int cycleDay = editor.getPolicyCycleDay(template); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1735 | |
| 1736 | cycleDayPicker.setMinValue(1); |
| 1737 | cycleDayPicker.setMaxValue(31); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1738 | cycleDayPicker.setValue(cycleDay); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1739 | cycleDayPicker.setWrapSelectorWheel(true); |
| 1740 | |
| 1741 | builder.setTitle(R.string.data_usage_cycle_editor_title); |
| 1742 | builder.setView(view); |
| 1743 | |
| 1744 | builder.setPositiveButton(R.string.data_usage_cycle_editor_positive, |
| 1745 | new DialogInterface.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1746 | @Override |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1747 | public void onClick(DialogInterface dialog, int which) { |
Jeff Sharkey | d277de9 | 2013-03-25 15:11:25 -0700 | [diff] [blame] | 1748 | // clear focus to finish pending text edits |
| 1749 | cycleDayPicker.clearFocus(); |
| 1750 | |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1751 | final int cycleDay = cycleDayPicker.getValue(); |
Jeff Sharkey | e5223a0 | 2012-03-09 17:11:14 -0800 | [diff] [blame] | 1752 | final String cycleTimezone = new Time().timezone; |
| 1753 | editor.setPolicyCycleDay(template, cycleDay, cycleTimezone); |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1754 | target.updatePolicy(true); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1755 | } |
| 1756 | }); |
| 1757 | |
| 1758 | return builder.create(); |
| 1759 | } |
| 1760 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1761 | |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1762 | /** |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1763 | * Dialog to edit {@link NetworkPolicy#warningBytes}. |
| 1764 | */ |
| 1765 | public static class WarningEditorFragment extends DialogFragment { |
| 1766 | private static final String EXTRA_TEMPLATE = "template"; |
| 1767 | |
| 1768 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1769 | if (!parent.isAdded()) return; |
| 1770 | |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1771 | final Bundle args = new Bundle(); |
| 1772 | args.putParcelable(EXTRA_TEMPLATE, parent.mTemplate); |
| 1773 | |
| 1774 | final WarningEditorFragment dialog = new WarningEditorFragment(); |
| 1775 | dialog.setArguments(args); |
| 1776 | dialog.setTargetFragment(parent, 0); |
| 1777 | dialog.show(parent.getFragmentManager(), TAG_WARNING_EDITOR); |
| 1778 | } |
| 1779 | |
| 1780 | @Override |
| 1781 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1782 | final Context context = getActivity(); |
| 1783 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1784 | final NetworkPolicyEditor editor = target.mPolicyEditor; |
| 1785 | |
| 1786 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1787 | final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext()); |
| 1788 | |
| 1789 | final View view = dialogInflater.inflate(R.layout.data_usage_bytes_editor, null, false); |
| 1790 | final NumberPicker bytesPicker = (NumberPicker) view.findViewById(R.id.bytes); |
| 1791 | |
| 1792 | final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE); |
| 1793 | final long warningBytes = editor.getPolicyWarningBytes(template); |
| 1794 | final long limitBytes = editor.getPolicyLimitBytes(template); |
| 1795 | |
| 1796 | bytesPicker.setMinValue(0); |
| 1797 | if (limitBytes != LIMIT_DISABLED) { |
| 1798 | bytesPicker.setMaxValue((int) (limitBytes / MB_IN_BYTES) - 1); |
| 1799 | } else { |
| 1800 | bytesPicker.setMaxValue(Integer.MAX_VALUE); |
| 1801 | } |
| 1802 | bytesPicker.setValue((int) (warningBytes / MB_IN_BYTES)); |
| 1803 | bytesPicker.setWrapSelectorWheel(false); |
| 1804 | |
| 1805 | builder.setTitle(R.string.data_usage_warning_editor_title); |
| 1806 | builder.setView(view); |
| 1807 | |
| 1808 | builder.setPositiveButton(R.string.data_usage_cycle_editor_positive, |
| 1809 | new DialogInterface.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1810 | @Override |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1811 | public void onClick(DialogInterface dialog, int which) { |
| 1812 | // clear focus to finish pending text edits |
| 1813 | bytesPicker.clearFocus(); |
| 1814 | |
| 1815 | final long bytes = bytesPicker.getValue() * MB_IN_BYTES; |
| 1816 | editor.setPolicyWarningBytes(template, bytes); |
| 1817 | target.updatePolicy(false); |
| 1818 | } |
| 1819 | }); |
| 1820 | |
| 1821 | return builder.create(); |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * Dialog to edit {@link NetworkPolicy#limitBytes}. |
| 1827 | */ |
| 1828 | public static class LimitEditorFragment extends DialogFragment { |
| 1829 | private static final String EXTRA_TEMPLATE = "template"; |
| 1830 | |
| 1831 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1832 | if (!parent.isAdded()) return; |
| 1833 | |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1834 | final Bundle args = new Bundle(); |
| 1835 | args.putParcelable(EXTRA_TEMPLATE, parent.mTemplate); |
| 1836 | |
| 1837 | final LimitEditorFragment dialog = new LimitEditorFragment(); |
| 1838 | dialog.setArguments(args); |
| 1839 | dialog.setTargetFragment(parent, 0); |
| 1840 | dialog.show(parent.getFragmentManager(), TAG_LIMIT_EDITOR); |
| 1841 | } |
| 1842 | |
| 1843 | @Override |
| 1844 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1845 | final Context context = getActivity(); |
| 1846 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1847 | final NetworkPolicyEditor editor = target.mPolicyEditor; |
| 1848 | |
| 1849 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1850 | final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext()); |
| 1851 | |
| 1852 | final View view = dialogInflater.inflate(R.layout.data_usage_bytes_editor, null, false); |
| 1853 | final NumberPicker bytesPicker = (NumberPicker) view.findViewById(R.id.bytes); |
| 1854 | |
| 1855 | final NetworkTemplate template = getArguments().getParcelable(EXTRA_TEMPLATE); |
| 1856 | final long warningBytes = editor.getPolicyWarningBytes(template); |
| 1857 | final long limitBytes = editor.getPolicyLimitBytes(template); |
| 1858 | |
| 1859 | bytesPicker.setMaxValue(Integer.MAX_VALUE); |
Shuhrat Dehkanov | f9237f6 | 2012-01-26 23:04:02 +0900 | [diff] [blame] | 1860 | if (warningBytes != WARNING_DISABLED && limitBytes > 0) { |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1861 | bytesPicker.setMinValue((int) (warningBytes / MB_IN_BYTES) + 1); |
| 1862 | } else { |
| 1863 | bytesPicker.setMinValue(0); |
| 1864 | } |
| 1865 | bytesPicker.setValue((int) (limitBytes / MB_IN_BYTES)); |
| 1866 | bytesPicker.setWrapSelectorWheel(false); |
| 1867 | |
| 1868 | builder.setTitle(R.string.data_usage_limit_editor_title); |
| 1869 | builder.setView(view); |
| 1870 | |
| 1871 | builder.setPositiveButton(R.string.data_usage_cycle_editor_positive, |
| 1872 | new DialogInterface.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1873 | @Override |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 1874 | public void onClick(DialogInterface dialog, int which) { |
| 1875 | // clear focus to finish pending text edits |
| 1876 | bytesPicker.clearFocus(); |
| 1877 | |
| 1878 | final long bytes = bytesPicker.getValue() * MB_IN_BYTES; |
| 1879 | editor.setPolicyLimitBytes(template, bytes); |
| 1880 | target.updatePolicy(false); |
| 1881 | } |
| 1882 | }); |
| 1883 | |
| 1884 | return builder.create(); |
| 1885 | } |
| 1886 | } |
| 1887 | /** |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 1888 | * Dialog to request user confirmation before disabling data. |
| 1889 | */ |
| 1890 | public static class ConfirmDataDisableFragment extends DialogFragment { |
| 1891 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1892 | if (!parent.isAdded()) return; |
| 1893 | |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 1894 | final ConfirmDataDisableFragment dialog = new ConfirmDataDisableFragment(); |
| 1895 | dialog.setTargetFragment(parent, 0); |
| 1896 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_DATA_DISABLE); |
| 1897 | } |
| 1898 | |
| 1899 | @Override |
| 1900 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1901 | final Context context = getActivity(); |
| 1902 | |
| 1903 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1904 | builder.setMessage(R.string.data_usage_disable_mobile); |
| 1905 | |
| 1906 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1907 | @Override |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 1908 | public void onClick(DialogInterface dialog, int which) { |
| 1909 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1910 | if (target != null) { |
| 1911 | // TODO: extend to modify policy enabled flag. |
| 1912 | target.setMobileDataEnabled(false); |
| 1913 | } |
| 1914 | } |
| 1915 | }); |
| 1916 | builder.setNegativeButton(android.R.string.cancel, null); |
| 1917 | |
| 1918 | return builder.create(); |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | /** |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1923 | * Dialog to request user confirmation before setting |
Christopher Tate | 5a64c73 | 2012-09-07 13:35:31 -0700 | [diff] [blame] | 1924 | * {@link android.provider.Settings.Global#DATA_ROAMING}. |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1925 | */ |
| 1926 | public static class ConfirmDataRoamingFragment extends DialogFragment { |
| 1927 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1928 | if (!parent.isAdded()) return; |
| 1929 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1930 | final ConfirmDataRoamingFragment dialog = new ConfirmDataRoamingFragment(); |
| 1931 | dialog.setTargetFragment(parent, 0); |
Jeff Sharkey | 28130d9 | 2011-09-02 16:10:24 -0700 | [diff] [blame] | 1932 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_DATA_ROAMING); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | @Override |
| 1936 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1937 | final Context context = getActivity(); |
| 1938 | |
| 1939 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1940 | builder.setTitle(R.string.roaming_reenable_title); |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 1941 | if (Utils.hasMultipleUsers(context)) { |
| 1942 | builder.setMessage(R.string.roaming_warning_multiuser); |
| 1943 | } else { |
| 1944 | builder.setMessage(R.string.roaming_warning); |
| 1945 | } |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1946 | |
| 1947 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1948 | @Override |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1949 | public void onClick(DialogInterface dialog, int which) { |
| 1950 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1951 | if (target != null) { |
| 1952 | target.setDataRoaming(true); |
| 1953 | } |
| 1954 | } |
| 1955 | }); |
| 1956 | builder.setNegativeButton(android.R.string.cancel, null); |
| 1957 | |
| 1958 | return builder.create(); |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | /** |
| 1963 | * Dialog to request user confirmation before setting |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1964 | * {@link INetworkPolicyManager#setRestrictBackground(boolean)}. |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1965 | */ |
| 1966 | public static class ConfirmRestrictFragment extends DialogFragment { |
| 1967 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 1968 | if (!parent.isAdded()) return; |
| 1969 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1970 | final ConfirmRestrictFragment dialog = new ConfirmRestrictFragment(); |
| 1971 | dialog.setTargetFragment(parent, 0); |
| 1972 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_RESTRICT); |
| 1973 | } |
| 1974 | |
| 1975 | @Override |
| 1976 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1977 | final Context context = getActivity(); |
| 1978 | |
| 1979 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1980 | builder.setTitle(R.string.data_usage_restrict_background_title); |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 1981 | if (Utils.hasMultipleUsers(context)) { |
| 1982 | builder.setMessage(R.string.data_usage_restrict_background_multiuser); |
| 1983 | } else { |
| 1984 | builder.setMessage(R.string.data_usage_restrict_background); |
| 1985 | } |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1986 | |
| 1987 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 1988 | @Override |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1989 | public void onClick(DialogInterface dialog, int which) { |
| 1990 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1991 | if (target != null) { |
| 1992 | target.setRestrictBackground(true); |
| 1993 | } |
| 1994 | } |
| 1995 | }); |
| 1996 | builder.setNegativeButton(android.R.string.cancel, null); |
| 1997 | |
| 1998 | return builder.create(); |
| 1999 | } |
| 2000 | } |
| 2001 | |
| 2002 | /** |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 2003 | * Dialog to inform user that {@link #POLICY_REJECT_METERED_BACKGROUND} |
| 2004 | * change has been denied, usually based on |
| 2005 | * {@link DataUsageSummary#hasLimitedNetworks()}. |
| 2006 | */ |
| 2007 | public static class DeniedRestrictFragment extends DialogFragment { |
| 2008 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 2009 | if (!parent.isAdded()) return; |
| 2010 | |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 2011 | final DeniedRestrictFragment dialog = new DeniedRestrictFragment(); |
| 2012 | dialog.setTargetFragment(parent, 0); |
| 2013 | dialog.show(parent.getFragmentManager(), TAG_DENIED_RESTRICT); |
| 2014 | } |
| 2015 | |
| 2016 | @Override |
| 2017 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 2018 | final Context context = getActivity(); |
| 2019 | |
| 2020 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 2021 | builder.setTitle(R.string.data_usage_app_restrict_background); |
| 2022 | builder.setMessage(R.string.data_usage_restrict_denied_dialog); |
| 2023 | builder.setPositiveButton(android.R.string.ok, null); |
| 2024 | |
| 2025 | return builder.create(); |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | /** |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 2030 | * Dialog to request user confirmation before setting |
| 2031 | * {@link #POLICY_REJECT_METERED_BACKGROUND}. |
| 2032 | */ |
| 2033 | public static class ConfirmAppRestrictFragment extends DialogFragment { |
| 2034 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 461842a | 2011-09-25 18:22:48 -0700 | [diff] [blame] | 2035 | if (!parent.isAdded()) return; |
| 2036 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 2037 | final ConfirmAppRestrictFragment dialog = new ConfirmAppRestrictFragment(); |
| 2038 | dialog.setTargetFragment(parent, 0); |
| 2039 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_APP_RESTRICT); |
| 2040 | } |
| 2041 | |
| 2042 | @Override |
| 2043 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 2044 | final Context context = getActivity(); |
| 2045 | |
| 2046 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 2047 | builder.setTitle(R.string.data_usage_app_restrict_dialog_title); |
| 2048 | builder.setMessage(R.string.data_usage_app_restrict_dialog); |
| 2049 | |
| 2050 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
Jeff Sharkey | 76c5ed4 | 2012-04-09 10:53:09 -0700 | [diff] [blame] | 2051 | @Override |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 2052 | public void onClick(DialogInterface dialog, int which) { |
| 2053 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 2054 | if (target != null) { |
| 2055 | target.setAppRestrictBackground(true); |
| 2056 | } |
| 2057 | } |
| 2058 | }); |
| 2059 | builder.setNegativeButton(android.R.string.cancel, null); |
| 2060 | |
| 2061 | return builder.create(); |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | /** |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 2066 | * Dialog to inform user about changing auto-sync setting |
| 2067 | */ |
| 2068 | public static class ConfirmAutoSyncChangeFragment extends DialogFragment { |
Amith Yamasani | 665235f | 2012-06-07 19:58:34 -0700 | [diff] [blame] | 2069 | private static final String SAVE_ENABLING = "enabling"; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 2070 | private boolean mEnabling; |
| 2071 | |
| 2072 | public static void show(DataUsageSummary parent, boolean enabling) { |
| 2073 | if (!parent.isAdded()) return; |
| 2074 | |
| 2075 | final ConfirmAutoSyncChangeFragment dialog = new ConfirmAutoSyncChangeFragment(); |
| 2076 | dialog.mEnabling = enabling; |
| 2077 | dialog.setTargetFragment(parent, 0); |
| 2078 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_AUTO_SYNC_CHANGE); |
| 2079 | } |
| 2080 | |
| 2081 | @Override |
| 2082 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 2083 | final Context context = getActivity(); |
Amith Yamasani | 665235f | 2012-06-07 19:58:34 -0700 | [diff] [blame] | 2084 | if (savedInstanceState != null) { |
| 2085 | mEnabling = savedInstanceState.getBoolean(SAVE_ENABLING); |
| 2086 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 2087 | |
| 2088 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 2089 | if (!mEnabling) { |
| 2090 | builder.setTitle(R.string.data_usage_auto_sync_off_dialog_title); |
| 2091 | builder.setMessage(R.string.data_usage_auto_sync_off_dialog); |
| 2092 | } else { |
| 2093 | builder.setTitle(R.string.data_usage_auto_sync_on_dialog_title); |
| 2094 | builder.setMessage(R.string.data_usage_auto_sync_on_dialog); |
| 2095 | } |
| 2096 | |
| 2097 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 2098 | @Override |
| 2099 | public void onClick(DialogInterface dialog, int which) { |
| 2100 | ContentResolver.setMasterSyncAutomatically(mEnabling); |
| 2101 | } |
| 2102 | }); |
| 2103 | builder.setNegativeButton(android.R.string.cancel, null); |
| 2104 | |
| 2105 | return builder.create(); |
| 2106 | } |
Amith Yamasani | 665235f | 2012-06-07 19:58:34 -0700 | [diff] [blame] | 2107 | |
| 2108 | @Override |
| 2109 | public void onSaveInstanceState(Bundle outState) { |
| 2110 | super.onSaveInstanceState(outState); |
| 2111 | outState.putBoolean(SAVE_ENABLING, mEnabling); |
| 2112 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | /** |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 2116 | * Compute default tab that should be selected, based on |
| 2117 | * {@link NetworkPolicyManager#EXTRA_NETWORK_TEMPLATE} extra. |
| 2118 | */ |
| 2119 | private static String computeTabFromIntent(Intent intent) { |
Jeff Sharkey | 271ec8a | 2011-07-20 16:59:16 -0700 | [diff] [blame] | 2120 | final NetworkTemplate template = intent.getParcelableExtra(EXTRA_NETWORK_TEMPLATE); |
| 2121 | if (template == null) return null; |
| 2122 | |
| 2123 | switch (template.getMatchRule()) { |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 2124 | case MATCH_MOBILE_3G_LOWER: |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 2125 | return TAB_3G; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 2126 | case MATCH_MOBILE_4G: |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 2127 | return TAB_4G; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 2128 | case MATCH_MOBILE_ALL: |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 2129 | return TAB_MOBILE; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 2130 | case MATCH_WIFI: |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 2131 | return TAB_WIFI; |
| 2132 | default: |
| 2133 | return null; |
| 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | /** |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2138 | * Background task that loads {@link UidDetail}, binding to |
| 2139 | * {@link DataUsageAdapter} row item when finished. |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 2140 | */ |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2141 | private static class UidDetailTask extends AsyncTask<Void, Void, UidDetail> { |
| 2142 | private final UidDetailProvider mProvider; |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 2143 | private final AppItem mItem; |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2144 | private final View mTarget; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 2145 | |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 2146 | private UidDetailTask(UidDetailProvider provider, AppItem item, View target) { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2147 | mProvider = checkNotNull(provider); |
| 2148 | mItem = checkNotNull(item); |
| 2149 | mTarget = checkNotNull(target); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2152 | public static void bindView( |
Jeff Sharkey | ef6e1ff | 2012-03-21 17:09:07 -0700 | [diff] [blame] | 2153 | UidDetailProvider provider, AppItem item, View target) { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2154 | final UidDetailTask existing = (UidDetailTask) target.getTag(); |
| 2155 | if (existing != null) { |
| 2156 | existing.cancel(false); |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 2157 | } |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2158 | |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 2159 | final UidDetail cachedDetail = provider.getUidDetail(item.key, false); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2160 | if (cachedDetail != null) { |
| 2161 | bindView(cachedDetail, target); |
| 2162 | } else { |
| 2163 | target.setTag(new UidDetailTask(provider, item, target).executeOnExecutor( |
| 2164 | AsyncTask.THREAD_POOL_EXECUTOR)); |
| 2165 | } |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2168 | private static void bindView(UidDetail detail, View target) { |
| 2169 | final ImageView icon = (ImageView) target.findViewById(android.R.id.icon); |
| 2170 | final TextView title = (TextView) target.findViewById(android.R.id.title); |
| 2171 | |
| 2172 | if (detail != null) { |
| 2173 | icon.setImageDrawable(detail.icon); |
| 2174 | title.setText(detail.label); |
| 2175 | } else { |
| 2176 | icon.setImageDrawable(null); |
| 2177 | title.setText(null); |
| 2178 | } |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 2179 | } |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2180 | |
| 2181 | @Override |
| 2182 | protected void onPreExecute() { |
| 2183 | bindView(null, mTarget); |
| 2184 | } |
| 2185 | |
| 2186 | @Override |
| 2187 | protected UidDetail doInBackground(Void... params) { |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 2188 | return mProvider.getUidDetail(mItem.key, true); |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | @Override |
| 2192 | protected void onPostExecute(UidDetail result) { |
| 2193 | bindView(result, mTarget); |
| 2194 | } |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2197 | /** |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2198 | * Test if device has a mobile data radio with SIM in ready state. |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2199 | */ |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2200 | public static boolean hasReadyMobileRadio(Context context) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 2201 | if (TEST_RADIOS) { |
| 2202 | return SystemProperties.get(TEST_RADIOS_PROP).contains("mobile"); |
| 2203 | } |
| 2204 | |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2205 | final ConnectivityManager conn = ConnectivityManager.from(context); |
| 2206 | final TelephonyManager tele = TelephonyManager.from(context); |
| 2207 | |
| 2208 | // require both supported network and ready SIM |
| 2209 | return conn.isNetworkSupported(TYPE_MOBILE) && tele.getSimState() == SIM_STATE_READY; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | /** |
| 2213 | * Test if device has a mobile 4G data radio. |
| 2214 | */ |
Jeff Sharkey | ad17de3 | 2012-04-11 11:03:25 -0700 | [diff] [blame] | 2215 | public static boolean hasReadyMobile4gRadio(Context context) { |
Jeff Sharkey | b98c55b | 2011-09-11 17:29:49 -0700 | [diff] [blame] | 2216 | if (!NetworkPolicyEditor.ENABLE_SPLIT_POLICIES) { |
| 2217 | return false; |
| 2218 | } |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 2219 | if (TEST_RADIOS) { |
| 2220 | return SystemProperties.get(TEST_RADIOS_PROP).contains("4g"); |
| 2221 | } |
| 2222 | |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2223 | final ConnectivityManager conn = ConnectivityManager.from(context); |
| 2224 | final TelephonyManager tele = TelephonyManager.from(context); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2225 | |
Jeff Sharkey | bdf98e8 | 2011-11-10 17:17:24 -0800 | [diff] [blame] | 2226 | final boolean hasWimax = conn.isNetworkSupported(TYPE_WIMAX); |
Wink Saville | 5543404 | 2012-06-14 12:33:43 -0700 | [diff] [blame] | 2227 | final boolean hasLte = (tele.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE) |
Jeff Sharkey | ad17de3 | 2012-04-11 11:03:25 -0700 | [diff] [blame] | 2228 | && hasReadyMobileRadio(context); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2229 | return hasWimax || hasLte; |
| 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * Test if device has a Wi-Fi data radio. |
| 2234 | */ |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2235 | public static boolean hasWifiRadio(Context context) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 2236 | if (TEST_RADIOS) { |
| 2237 | return SystemProperties.get(TEST_RADIOS_PROP).contains("wifi"); |
| 2238 | } |
| 2239 | |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2240 | final ConnectivityManager conn = ConnectivityManager.from(context); |
Jeff Sharkey | bdf98e8 | 2011-11-10 17:17:24 -0800 | [diff] [blame] | 2241 | return conn.isNetworkSupported(TYPE_WIFI); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | /** |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 2245 | * Test if device has an ethernet network connection. |
| 2246 | */ |
Jeff Sharkey | b67c4a8 | 2012-05-24 11:01:29 -0700 | [diff] [blame] | 2247 | public boolean hasEthernet(Context context) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 2248 | if (TEST_RADIOS) { |
| 2249 | return SystemProperties.get(TEST_RADIOS_PROP).contains("ethernet"); |
| 2250 | } |
| 2251 | |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2252 | final ConnectivityManager conn = ConnectivityManager.from(context); |
Jeff Sharkey | b67c4a8 | 2012-05-24 11:01:29 -0700 | [diff] [blame] | 2253 | final boolean hasEthernet = conn.isNetworkSupported(TYPE_ETHERNET); |
| 2254 | |
| 2255 | final long ethernetBytes; |
Jeff Sharkey | d878909 | 2012-05-29 10:19:50 -0700 | [diff] [blame] | 2256 | if (mStatsSession != null) { |
| 2257 | try { |
| 2258 | ethernetBytes = mStatsSession.getSummaryForNetwork( |
| 2259 | NetworkTemplate.buildTemplateEthernet(), Long.MIN_VALUE, Long.MAX_VALUE) |
| 2260 | .getTotalBytes(); |
| 2261 | } catch (RemoteException e) { |
| 2262 | throw new RuntimeException(e); |
| 2263 | } |
| 2264 | } else { |
| 2265 | ethernetBytes = 0; |
Jeff Sharkey | b67c4a8 | 2012-05-24 11:01:29 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
Jeff Sharkey | d878909 | 2012-05-29 10:19:50 -0700 | [diff] [blame] | 2268 | // only show ethernet when both hardware present and traffic has occurred |
Jeff Sharkey | b67c4a8 | 2012-05-24 11:01:29 -0700 | [diff] [blame] | 2269 | return hasEthernet && ethernetBytes > 0; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | /** |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2273 | * Inflate a {@link Preference} style layout, adding the given {@link View} |
| 2274 | * widget into {@link android.R.id#widget_frame}. |
| 2275 | */ |
| 2276 | private static View inflatePreference(LayoutInflater inflater, ViewGroup root, View widget) { |
| 2277 | final View view = inflater.inflate(R.layout.preference, root, false); |
| 2278 | final LinearLayout widgetFrame = (LinearLayout) view.findViewById( |
| 2279 | android.R.id.widget_frame); |
| 2280 | widgetFrame.addView(widget, new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); |
| 2281 | return view; |
| 2282 | } |
| 2283 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 2284 | private static View inflateAppTitle( |
| 2285 | LayoutInflater inflater, ViewGroup root, CharSequence label) { |
| 2286 | final TextView view = (TextView) inflater.inflate( |
| 2287 | R.layout.data_usage_app_title, root, false); |
| 2288 | view.setText(label); |
| 2289 | return view; |
| 2290 | } |
| 2291 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2292 | /** |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 2293 | * Test if any networks are currently limited. |
| 2294 | */ |
| 2295 | private boolean hasLimitedNetworks() { |
| 2296 | return !buildLimitedNetworksList().isEmpty(); |
| 2297 | } |
| 2298 | |
| 2299 | /** |
Jeff Sharkey | 30dde0f | 2011-08-17 15:08:12 -0700 | [diff] [blame] | 2300 | * Build string describing currently limited networks, which defines when |
| 2301 | * background data is restricted. |
| 2302 | */ |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2303 | @Deprecated |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 2304 | private CharSequence buildLimitedNetworksString() { |
| 2305 | final List<CharSequence> limited = buildLimitedNetworksList(); |
| 2306 | |
| 2307 | // handle case where no networks limited |
| 2308 | if (limited.isEmpty()) { |
| 2309 | limited.add(getText(R.string.data_usage_list_none)); |
| 2310 | } |
| 2311 | |
| 2312 | return TextUtils.join(limited); |
| 2313 | } |
| 2314 | |
| 2315 | /** |
| 2316 | * Build list of currently limited networks, which defines when background |
| 2317 | * data is restricted. |
| 2318 | */ |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2319 | @Deprecated |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 2320 | private List<CharSequence> buildLimitedNetworksList() { |
Jeff Sharkey | 30dde0f | 2011-08-17 15:08:12 -0700 | [diff] [blame] | 2321 | final Context context = getActivity(); |
Jeff Sharkey | 30dde0f | 2011-08-17 15:08:12 -0700 | [diff] [blame] | 2322 | |
| 2323 | // build combined list of all limited networks |
| 2324 | final ArrayList<CharSequence> limited = Lists.newArrayList(); |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2325 | |
| 2326 | final TelephonyManager tele = TelephonyManager.from(context); |
| 2327 | if (tele.getSimState() == SIM_STATE_READY) { |
| 2328 | final String subscriberId = getActiveSubscriberId(context); |
| 2329 | if (mPolicyEditor.hasLimitedPolicy(buildTemplateMobileAll(subscriberId))) { |
| 2330 | limited.add(getText(R.string.data_usage_list_mobile)); |
| 2331 | } |
| 2332 | if (mPolicyEditor.hasLimitedPolicy(buildTemplateMobile3gLower(subscriberId))) { |
| 2333 | limited.add(getText(R.string.data_usage_tab_3g)); |
| 2334 | } |
| 2335 | if (mPolicyEditor.hasLimitedPolicy(buildTemplateMobile4g(subscriberId))) { |
| 2336 | limited.add(getText(R.string.data_usage_tab_4g)); |
| 2337 | } |
Jeff Sharkey | 30dde0f | 2011-08-17 15:08:12 -0700 | [diff] [blame] | 2338 | } |
Jeff Sharkey | 313f7d8 | 2012-04-03 21:13:25 -0700 | [diff] [blame] | 2339 | |
| 2340 | if (mPolicyEditor.hasLimitedPolicy(buildTemplateWifiWildcard())) { |
Jeff Sharkey | 30dde0f | 2011-08-17 15:08:12 -0700 | [diff] [blame] | 2341 | limited.add(getText(R.string.data_usage_tab_wifi)); |
| 2342 | } |
| 2343 | if (mPolicyEditor.hasLimitedPolicy(buildTemplateEthernet())) { |
| 2344 | limited.add(getText(R.string.data_usage_tab_ethernet)); |
| 2345 | } |
| 2346 | |
Jeff Sharkey | a53188f | 2011-09-13 19:56:45 -0700 | [diff] [blame] | 2347 | return limited; |
Jeff Sharkey | 30dde0f | 2011-08-17 15:08:12 -0700 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | /** |
Jeff Sharkey | 5d70679 | 2011-09-08 18:57:17 -0700 | [diff] [blame] | 2351 | * Inset both selector and divider {@link Drawable} on the given |
| 2352 | * {@link ListView} by the requested dimensions. |
| 2353 | */ |
| 2354 | private static void insetListViewDrawables(ListView view, int insetSide) { |
| 2355 | final Drawable selector = view.getSelector(); |
| 2356 | final Drawable divider = view.getDivider(); |
| 2357 | |
| 2358 | // fully unregister these drawables so callbacks can be maintained after |
| 2359 | // wrapping below. |
| 2360 | final Drawable stub = new ColorDrawable(Color.TRANSPARENT); |
| 2361 | view.setSelector(stub); |
| 2362 | view.setDivider(stub); |
| 2363 | |
| 2364 | view.setSelector(new InsetBoundsDrawable(selector, insetSide)); |
| 2365 | view.setDivider(new InsetBoundsDrawable(divider, insetSide)); |
| 2366 | } |
| 2367 | |
| 2368 | /** |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2369 | * Set {@link android.R.id#title} for a preference view inflated with |
Jeff Sharkey | 52c3f44 | 2011-06-23 00:39:38 -0700 | [diff] [blame] | 2370 | * {@link #inflatePreference(LayoutInflater, ViewGroup, View)}. |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 2371 | */ |
| 2372 | private static void setPreferenceTitle(View parent, int resId) { |
| 2373 | final TextView title = (TextView) parent.findViewById(android.R.id.title); |
| 2374 | title.setText(resId); |
| 2375 | } |
| 2376 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 2377 | /** |
| 2378 | * Set {@link android.R.id#summary} for a preference view inflated with |
| 2379 | * {@link #inflatePreference(LayoutInflater, ViewGroup, View)}. |
| 2380 | */ |
Jeff Sharkey | 30dde0f | 2011-08-17 15:08:12 -0700 | [diff] [blame] | 2381 | private static void setPreferenceSummary(View parent, CharSequence string) { |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 2382 | final TextView summary = (TextView) parent.findViewById(android.R.id.summary); |
| 2383 | summary.setVisibility(View.VISIBLE); |
Jeff Sharkey | 30dde0f | 2011-08-17 15:08:12 -0700 | [diff] [blame] | 2384 | summary.setText(string); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 2385 | } |
Fabrice Di Meglio | 758c3ff | 2014-04-10 13:47:30 -0700 | [diff] [blame^] | 2386 | |
| 2387 | /** |
| 2388 | * For search |
| 2389 | */ |
| 2390 | public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 2391 | new SearchIndexProvider() { |
| 2392 | |
| 2393 | @Override |
| 2394 | public List<SearchIndexableResource> getXmlResourcesToIndex( |
| 2395 | Context context, boolean enabled) { |
| 2396 | return null; |
| 2397 | } |
| 2398 | |
| 2399 | @Override |
| 2400 | public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) { |
| 2401 | final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>(); |
| 2402 | |
| 2403 | final Resources res = context.getResources(); |
| 2404 | |
| 2405 | // Add fragment title |
| 2406 | SearchIndexableRaw data = new SearchIndexableRaw(context); |
| 2407 | data.title = res.getString(R.string.data_usage_summary_title); |
| 2408 | data.screenTitle = res.getString(R.string.data_usage_summary_title); |
| 2409 | result.add(data); |
| 2410 | |
| 2411 | // Mobile data |
| 2412 | data = new SearchIndexableRaw(context); |
| 2413 | data.title = res.getString(R.string.data_usage_enable_mobile); |
| 2414 | data.screenTitle = res.getString(R.string.data_usage_summary_title); |
| 2415 | result.add(data); |
| 2416 | |
| 2417 | // Set mobile data limit |
| 2418 | data = new SearchIndexableRaw(context); |
| 2419 | data.title = res.getString(R.string.data_usage_disable_mobile_limit); |
| 2420 | data.screenTitle = res.getString(R.string.data_usage_summary_title); |
| 2421 | result.add(data); |
| 2422 | |
| 2423 | // Data usage cycke |
| 2424 | data = new SearchIndexableRaw(context); |
| 2425 | data.title = res.getString(R.string.data_usage_cycle); |
| 2426 | data.screenTitle = res.getString(R.string.data_usage_summary_title); |
| 2427 | result.add(data); |
| 2428 | |
| 2429 | return result; |
| 2430 | } |
| 2431 | }; |
| 2432 | |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 2433 | } |