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