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