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