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