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