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; |
| 21 | import static android.net.ConnectivityManager.TYPE_WIMAX; |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 22 | import static android.net.NetworkPolicy.LIMIT_DISABLED; |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 23 | import static android.net.NetworkPolicyManager.EXTRA_NETWORK_TEMPLATE; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 24 | import static android.net.NetworkPolicyManager.POLICY_NONE; |
| 25 | import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 26 | import static android.net.NetworkPolicyManager.computeLastCycleBoundary; |
| 27 | import static android.net.NetworkPolicyManager.computeNextCycleBoundary; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 28 | import static android.net.NetworkStats.SET_DEFAULT; |
| 29 | import static android.net.NetworkStats.SET_FOREGROUND; |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 30 | import static android.net.NetworkStats.TAG_NONE; |
| 31 | import static android.net.NetworkStatsHistory.FIELD_RX_BYTES; |
| 32 | import static android.net.NetworkStatsHistory.FIELD_TX_BYTES; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 33 | import static android.net.NetworkTemplate.MATCH_MOBILE_3G_LOWER; |
| 34 | import static android.net.NetworkTemplate.MATCH_MOBILE_4G; |
| 35 | import static android.net.NetworkTemplate.MATCH_MOBILE_ALL; |
| 36 | import static android.net.NetworkTemplate.MATCH_WIFI; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 37 | import static android.net.NetworkTemplate.buildTemplateEthernet; |
| 38 | import static android.net.NetworkTemplate.buildTemplateMobile3gLower; |
| 39 | import static android.net.NetworkTemplate.buildTemplateMobile4g; |
| 40 | import static android.net.NetworkTemplate.buildTemplateMobileAll; |
| 41 | import static android.net.NetworkTemplate.buildTemplateWifi; |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 42 | import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH; |
| 43 | import static android.text.format.DateUtils.FORMAT_SHOW_DATE; |
| 44 | import static android.text.format.Time.TIMEZONE_UTC; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 45 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 46 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 47 | import android.animation.LayoutTransition; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 48 | import android.app.AlertDialog; |
| 49 | import android.app.Dialog; |
| 50 | import android.app.DialogFragment; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 51 | import android.app.Fragment; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 52 | import android.app.FragmentTransaction; |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 53 | import android.app.LoaderManager.LoaderCallbacks; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 54 | import android.content.ContentResolver; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 55 | import android.content.Context; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 56 | import android.content.DialogInterface; |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 57 | import android.content.Intent; |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 58 | import android.content.Loader; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 59 | import android.content.SharedPreferences; |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 60 | import android.content.pm.ApplicationInfo; |
| 61 | import android.content.pm.PackageInfo; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 62 | import android.content.pm.PackageManager; |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 63 | import android.content.pm.PackageManager.NameNotFoundException; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 64 | import android.content.res.Resources; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 65 | import android.graphics.Color; |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 66 | import android.graphics.drawable.Drawable; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 67 | import android.net.ConnectivityManager; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 68 | import android.net.INetworkPolicyManager; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 69 | import android.net.INetworkStatsService; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 70 | import android.net.NetworkPolicy; |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 71 | import android.net.NetworkPolicyManager; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 72 | import android.net.NetworkStats; |
| 73 | import android.net.NetworkStatsHistory; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 74 | import android.net.NetworkTemplate; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 75 | import android.net.TrafficStats; |
Jeff Sharkey | aa5260e | 2011-06-14 23:21:59 -0700 | [diff] [blame] | 76 | import android.os.AsyncTask; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 77 | import android.os.Bundle; |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 78 | import android.os.INetworkManagementService; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 79 | import android.os.RemoteException; |
| 80 | import android.os.ServiceManager; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 81 | import android.os.SystemProperties; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 82 | import android.preference.Preference; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 83 | import android.provider.Settings; |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 84 | import android.telephony.TelephonyManager; |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 85 | import android.text.TextUtils; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 86 | import android.text.format.DateUtils; |
| 87 | import android.text.format.Formatter; |
| 88 | import android.util.Log; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 89 | import android.util.SparseArray; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 90 | import android.view.LayoutInflater; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 91 | import android.view.Menu; |
| 92 | import android.view.MenuInflater; |
| 93 | import android.view.MenuItem; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 94 | import android.view.View; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 95 | import android.view.View.OnClickListener; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 96 | import android.view.ViewGroup; |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 97 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 98 | import android.widget.AdapterView; |
| 99 | import android.widget.AdapterView.OnItemClickListener; |
| 100 | import android.widget.AdapterView.OnItemSelectedListener; |
| 101 | import android.widget.ArrayAdapter; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 102 | import android.widget.BaseAdapter; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 103 | import android.widget.Button; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 104 | import android.widget.CheckBox; |
| 105 | import android.widget.CompoundButton; |
| 106 | import android.widget.CompoundButton.OnCheckedChangeListener; |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 107 | import android.widget.ImageView; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 108 | import android.widget.LinearLayout; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 109 | import android.widget.ListView; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 110 | import android.widget.NumberPicker; |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 111 | import android.widget.ProgressBar; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 112 | import android.widget.Spinner; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 113 | import android.widget.Switch; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 114 | import android.widget.TabHost; |
| 115 | import android.widget.TabHost.OnTabChangeListener; |
| 116 | import android.widget.TabHost.TabContentFactory; |
| 117 | import android.widget.TabHost.TabSpec; |
| 118 | import android.widget.TabWidget; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 119 | import android.widget.TextView; |
| 120 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 121 | import com.android.internal.telephony.Phone; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 122 | import com.android.settings.net.NetworkPolicyEditor; |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 123 | import com.android.settings.net.SummaryForAllUidLoader; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 124 | import com.android.settings.widget.DataUsageChartView; |
| 125 | import com.android.settings.widget.DataUsageChartView.DataUsageChartListener; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 126 | import com.android.settings.widget.PieChartView; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 127 | import com.google.android.collect.Lists; |
| 128 | |
| 129 | import java.util.ArrayList; |
| 130 | import java.util.Collections; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 131 | import java.util.Locale; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 132 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 133 | import libcore.util.Objects; |
| 134 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 135 | /** |
| 136 | * Panel show data usage history across various networks, including options to |
| 137 | * inspect based on usage cycle and control through {@link NetworkPolicy}. |
| 138 | */ |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 139 | public class DataUsageSummary extends Fragment { |
| 140 | private static final String TAG = "DataUsage"; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 141 | private static final boolean LOGD = true; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 142 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 143 | // TODO: remove this testing code |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 144 | private static final boolean TEST_ANIM = false; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 145 | private static final boolean TEST_RADIOS = false; |
| 146 | private static final String TEST_RADIOS_PROP = "test.radios"; |
| 147 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 148 | private static final String TAB_3G = "3g"; |
| 149 | private static final String TAB_4G = "4g"; |
| 150 | private static final String TAB_MOBILE = "mobile"; |
| 151 | private static final String TAB_WIFI = "wifi"; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 152 | private static final String TAB_ETHERNET = "ethernet"; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 153 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 154 | private static final String TAG_CONFIRM_ROAMING = "confirmRoaming"; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 155 | private static final String TAG_CONFIRM_LIMIT = "confirmLimit"; |
| 156 | private static final String TAG_CYCLE_EDITOR = "cycleEditor"; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 157 | private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict"; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 158 | private static final String TAG_CONFIRM_APP_RESTRICT = "confirmAppRestrict"; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 159 | private static final String TAG_APP_DETAILS = "appDetails"; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 160 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 161 | private static final int LOADER_SUMMARY = 2; |
| 162 | |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 163 | private static final long KB_IN_BYTES = 1024; |
| 164 | private static final long MB_IN_BYTES = KB_IN_BYTES * 1024; |
| 165 | private static final long GB_IN_BYTES = MB_IN_BYTES * 1024; |
| 166 | |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 167 | private INetworkManagementService mNetworkService; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 168 | private INetworkStatsService mStatsService; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 169 | private INetworkPolicyManager mPolicyService; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 170 | private ConnectivityManager mConnService; |
| 171 | |
| 172 | private static final String PREF_FILE = "data_usage"; |
| 173 | private static final String PREF_SHOW_WIFI = "show_wifi"; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 174 | private static final String PREF_SHOW_ETHERNET = "show_ethernet"; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 175 | |
| 176 | private SharedPreferences mPrefs; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 177 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 178 | private TabHost mTabHost; |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 179 | private ViewGroup mTabsContainer; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 180 | private TabWidget mTabWidget; |
| 181 | private ListView mListView; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 182 | private DataUsageAdapter mAdapter; |
| 183 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 184 | private ViewGroup mHeader; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 185 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 186 | private ViewGroup mNetworkSwitchesContainer; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 187 | private LinearLayout mNetworkSwitches; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 188 | private Switch mDataEnabled; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 189 | private View mDataEnabledView; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 190 | private CheckBox mDisableAtLimit; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 191 | private View mDisableAtLimitView; |
| 192 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 193 | private View mCycleView; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 194 | private Spinner mCycleSpinner; |
| 195 | private CycleAdapter mCycleAdapter; |
| 196 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 197 | private DataUsageChartView mChart; |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 198 | private TextView mUsageSummary; |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 199 | private TextView mEmpty; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 200 | |
| 201 | private View mAppDetail; |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 202 | private ImageView mAppIcon; |
| 203 | private ViewGroup mAppTitles; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 204 | private PieChartView mAppPieChart; |
| 205 | private TextView mAppForeground; |
| 206 | private TextView mAppBackground; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 207 | private Button mAppSettings; |
| 208 | |
| 209 | private LinearLayout mAppSwitches; |
| 210 | private CheckBox mAppRestrict; |
| 211 | private View mAppRestrictView; |
| 212 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 213 | private boolean mShowWifi = false; |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 214 | private boolean mShowEthernet = false; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 215 | |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 216 | private NetworkTemplate mTemplate = null; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 217 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 218 | private static final int UID_NONE = -1; |
| 219 | private int mUid = UID_NONE; |
| 220 | |
| 221 | private Intent mAppSettingsIntent; |
| 222 | |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 223 | private NetworkPolicyEditor mPolicyEditor; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 224 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 225 | private NetworkStatsHistory mHistory; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 226 | private NetworkStatsHistory mDetailHistory; |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 227 | private NetworkStatsHistory mDetailHistoryDefault; |
| 228 | private NetworkStatsHistory mDetailHistoryForeground; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 229 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 230 | private String mCurrentTab = null; |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 231 | private String mIntentTab = null; |
| 232 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 233 | private MenuItem mMenuDataRoaming; |
| 234 | private MenuItem mMenuRestrictBackground; |
| 235 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 236 | /** Flag used to ignore listeners during binding. */ |
| 237 | private boolean mBinding; |
| 238 | |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 239 | @Override |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 240 | public void onCreate(Bundle savedInstanceState) { |
| 241 | super.onCreate(savedInstanceState); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 242 | |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 243 | mNetworkService = INetworkManagementService.Stub.asInterface( |
| 244 | ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 245 | mStatsService = INetworkStatsService.Stub.asInterface( |
| 246 | ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 247 | mPolicyService = INetworkPolicyManager.Stub.asInterface( |
| 248 | ServiceManager.getService(Context.NETWORK_POLICY_SERVICE)); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 249 | mConnService = (ConnectivityManager) getActivity().getSystemService( |
| 250 | Context.CONNECTIVITY_SERVICE); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 251 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 252 | mPrefs = getActivity().getSharedPreferences(PREF_FILE, Context.MODE_PRIVATE); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 253 | |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 254 | mPolicyEditor = new NetworkPolicyEditor(mPolicyService); |
| 255 | mPolicyEditor.read(); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 256 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 257 | mShowWifi = mPrefs.getBoolean(PREF_SHOW_WIFI, false); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 258 | mShowEthernet = mPrefs.getBoolean(PREF_SHOW_ETHERNET, false); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 259 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 260 | setHasOptionsMenu(true); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 261 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 262 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 263 | @Override |
| 264 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 265 | Bundle savedInstanceState) { |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 266 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 267 | final Context context = inflater.getContext(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 268 | final View view = inflater.inflate(R.layout.data_usage_summary, container, false); |
| 269 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 270 | mTabHost = (TabHost) view.findViewById(android.R.id.tabhost); |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 271 | mTabsContainer = (ViewGroup) view.findViewById(R.id.tabs_container); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 272 | mTabWidget = (TabWidget) view.findViewById(android.R.id.tabs); |
| 273 | mListView = (ListView) view.findViewById(android.R.id.list); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 274 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 275 | mTabHost.setup(); |
| 276 | mTabHost.setOnTabChangedListener(mTabListener); |
| 277 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 278 | mHeader = (ViewGroup) inflater.inflate(R.layout.data_usage_header, mListView, false); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 279 | mListView.addHeaderView(mHeader, null, false); |
| 280 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 281 | { |
| 282 | // bind network switches |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 283 | mNetworkSwitchesContainer = (ViewGroup) mHeader.findViewById( |
| 284 | R.id.network_switches_container); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 285 | mNetworkSwitches = (LinearLayout) mHeader.findViewById(R.id.network_switches); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 286 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 287 | mDataEnabled = new Switch(inflater.getContext()); |
| 288 | mDataEnabledView = inflatePreference(inflater, mNetworkSwitches, mDataEnabled); |
| 289 | mDataEnabled.setOnCheckedChangeListener(mDataEnabledListener); |
| 290 | mNetworkSwitches.addView(mDataEnabledView); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 291 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 292 | mDisableAtLimit = new CheckBox(inflater.getContext()); |
| 293 | mDisableAtLimit.setClickable(false); |
| 294 | mDisableAtLimitView = inflatePreference(inflater, mNetworkSwitches, mDisableAtLimit); |
| 295 | mDisableAtLimitView.setOnClickListener(mDisableAtLimitListener); |
| 296 | mNetworkSwitches.addView(mDisableAtLimitView); |
| 297 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 298 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 299 | // bind cycle dropdown |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 300 | mCycleView = mHeader.findViewById(R.id.cycles); |
| 301 | mCycleSpinner = (Spinner) mCycleView.findViewById(R.id.cycles_spinner); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 302 | mCycleAdapter = new CycleAdapter(context); |
| 303 | mCycleSpinner.setAdapter(mCycleAdapter); |
| 304 | mCycleSpinner.setOnItemSelectedListener(mCycleListener); |
| 305 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 306 | mChart = (DataUsageChartView) mHeader.findViewById(R.id.chart); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 307 | mChart.setListener(mChartListener); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 308 | |
| 309 | { |
| 310 | // bind app detail controls |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 311 | mAppDetail = mHeader.findViewById(R.id.app_detail); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 312 | mAppIcon = (ImageView) mAppDetail.findViewById(R.id.app_icon); |
| 313 | mAppTitles = (ViewGroup) mAppDetail.findViewById(R.id.app_titles); |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 314 | mAppPieChart = (PieChartView) mAppDetail.findViewById(R.id.app_pie_chart); |
| 315 | mAppForeground = (TextView) mAppDetail.findViewById(R.id.app_foreground); |
| 316 | mAppBackground = (TextView) mAppDetail.findViewById(R.id.app_background); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 317 | mAppSwitches = (LinearLayout) mAppDetail.findViewById(R.id.app_switches); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 318 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 319 | mAppSettings = (Button) mAppDetail.findViewById(R.id.app_settings); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 320 | mAppSettings.setOnClickListener(mAppSettingsListener); |
| 321 | |
| 322 | mAppRestrict = new CheckBox(inflater.getContext()); |
| 323 | mAppRestrict.setClickable(false); |
| 324 | mAppRestrictView = inflatePreference(inflater, mAppSwitches, mAppRestrict); |
| 325 | setPreferenceTitle(mAppRestrictView, R.string.data_usage_app_restrict_background); |
| 326 | setPreferenceSummary( |
| 327 | mAppRestrictView, R.string.data_usage_app_restrict_background_summary); |
| 328 | mAppRestrictView.setOnClickListener(mAppRestrictListener); |
| 329 | mAppSwitches.addView(mAppRestrictView); |
| 330 | } |
| 331 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 332 | mUsageSummary = (TextView) mHeader.findViewById(R.id.usage_summary); |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 333 | mEmpty = (TextView) mHeader.findViewById(android.R.id.empty); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 334 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 335 | // only assign layout transitions once first layout is finished |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 336 | mListView.getViewTreeObserver().addOnGlobalLayoutListener(mFirstLayoutListener); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 337 | |
| 338 | mAdapter = new DataUsageAdapter(); |
| 339 | mListView.setOnItemClickListener(mListListener); |
| 340 | mListView.setAdapter(mAdapter); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 341 | |
| 342 | return view; |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public void onResume() { |
| 347 | super.onResume(); |
| 348 | |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 349 | // pick default tab based on incoming intent |
| 350 | final Intent intent = getActivity().getIntent(); |
| 351 | mIntentTab = computeTabFromIntent(intent); |
| 352 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 353 | // this kicks off chain reaction which creates tabs, binds the body to |
| 354 | // selected network, and binds chart, cycles and detail list. |
| 355 | updateTabs(); |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 356 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 357 | // kick off background task to update stats |
| 358 | new AsyncTask<Void, Void, Void>() { |
| 359 | @Override |
| 360 | protected Void doInBackground(Void... params) { |
| 361 | try { |
| 362 | mStatsService.forceUpdate(); |
| 363 | } catch (RemoteException e) { |
| 364 | } |
| 365 | return null; |
| 366 | } |
| 367 | |
| 368 | @Override |
| 369 | protected void onPostExecute(Void result) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 370 | if (isAdded()) { |
| 371 | updateBody(); |
| 372 | } |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 373 | } |
| 374 | }.execute(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 377 | @Override |
| 378 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
| 379 | inflater.inflate(R.menu.data_usage, menu); |
| 380 | } |
| 381 | |
| 382 | @Override |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 383 | public void onPrepareOptionsMenu(Menu menu) { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 384 | final Context context = getActivity(); |
| 385 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 386 | mMenuDataRoaming = menu.findItem(R.id.data_usage_menu_roaming); |
| 387 | mMenuDataRoaming.setVisible(hasMobileRadio(context)); |
| 388 | mMenuDataRoaming.setChecked(getDataRoaming()); |
| 389 | |
| 390 | mMenuRestrictBackground = menu.findItem(R.id.data_usage_menu_restrict_background); |
| 391 | mMenuRestrictBackground.setChecked(getRestrictBackground()); |
| 392 | |
| 393 | final MenuItem split4g = menu.findItem(R.id.data_usage_menu_split_4g); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 394 | split4g.setVisible(hasMobile4gRadio(context)); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 395 | split4g.setChecked(isMobilePolicySplit()); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 396 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 397 | final MenuItem showWifi = menu.findItem(R.id.data_usage_menu_show_wifi); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 398 | if (hasWifiRadio(context) && hasMobileRadio(context)) { |
| 399 | showWifi.setVisible(true); |
| 400 | showWifi.setChecked(mShowWifi); |
| 401 | } else { |
| 402 | showWifi.setVisible(false); |
| 403 | mShowWifi = true; |
| 404 | } |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 405 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 406 | final MenuItem showEthernet = menu.findItem(R.id.data_usage_menu_show_ethernet); |
| 407 | if (hasEthernet(context) && hasMobileRadio(context)) { |
| 408 | showEthernet.setVisible(true); |
| 409 | showEthernet.setChecked(mShowEthernet); |
| 410 | } else { |
| 411 | showEthernet.setVisible(false); |
| 412 | mShowEthernet = true; |
| 413 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 414 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 415 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 416 | @Override |
| 417 | public boolean onOptionsItemSelected(MenuItem item) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 418 | switch (item.getItemId()) { |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 419 | case R.id.data_usage_menu_roaming: { |
| 420 | final boolean dataRoaming = !item.isChecked(); |
| 421 | if (dataRoaming) { |
| 422 | ConfirmDataRoamingFragment.show(this); |
| 423 | } else { |
| 424 | // no confirmation to disable roaming |
| 425 | setDataRoaming(false); |
| 426 | } |
| 427 | return true; |
| 428 | } |
| 429 | case R.id.data_usage_menu_restrict_background: { |
| 430 | final boolean restrictBackground = !item.isChecked(); |
| 431 | if (restrictBackground) { |
| 432 | ConfirmRestrictFragment.show(this); |
| 433 | } else { |
| 434 | // no confirmation to drop restriction |
| 435 | setRestrictBackground(false); |
| 436 | } |
| 437 | return true; |
| 438 | } |
| 439 | case R.id.data_usage_menu_split_4g: { |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 440 | final boolean mobileSplit = !item.isChecked(); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 441 | setMobilePolicySplit(mobileSplit); |
| 442 | item.setChecked(isMobilePolicySplit()); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 443 | updateTabs(); |
| 444 | return true; |
| 445 | } |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 446 | case R.id.data_usage_menu_show_wifi: { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 447 | mShowWifi = !item.isChecked(); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 448 | mPrefs.edit().putBoolean(PREF_SHOW_WIFI, mShowWifi).apply(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 449 | item.setChecked(mShowWifi); |
| 450 | updateTabs(); |
| 451 | return true; |
| 452 | } |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 453 | case R.id.data_usage_menu_show_ethernet: { |
| 454 | mShowEthernet = !item.isChecked(); |
| 455 | mPrefs.edit().putBoolean(PREF_SHOW_ETHERNET, mShowEthernet).apply(); |
| 456 | item.setChecked(mShowEthernet); |
| 457 | updateTabs(); |
| 458 | return true; |
| 459 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 460 | } |
| 461 | return false; |
| 462 | } |
| 463 | |
Jeff Sharkey | 94a9095 | 2011-06-13 22:31:09 -0700 | [diff] [blame] | 464 | @Override |
| 465 | public void onDestroyView() { |
| 466 | super.onDestroyView(); |
| 467 | |
| 468 | mDataEnabledView = null; |
| 469 | mDisableAtLimitView = null; |
| 470 | } |
| 471 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 472 | /** |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 473 | * Listener to setup {@link LayoutTransition} after first layout pass. |
| 474 | */ |
| 475 | private OnGlobalLayoutListener mFirstLayoutListener = new OnGlobalLayoutListener() { |
| 476 | /** {@inheritDoc} */ |
| 477 | public void onGlobalLayout() { |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 478 | mListView.getViewTreeObserver().removeGlobalOnLayoutListener(mFirstLayoutListener); |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 479 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 480 | mTabsContainer.setLayoutTransition(buildLayoutTransition()); |
| 481 | mHeader.setLayoutTransition(buildLayoutTransition()); |
| 482 | mNetworkSwitchesContainer.setLayoutTransition(buildLayoutTransition()); |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 483 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 484 | final LayoutTransition chartTransition = buildLayoutTransition(); |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 485 | chartTransition.setStartDelay(LayoutTransition.APPEARING, 0); |
| 486 | chartTransition.setStartDelay(LayoutTransition.DISAPPEARING, 0); |
| 487 | mChart.setLayoutTransition(chartTransition); |
| 488 | } |
| 489 | }; |
| 490 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 491 | private static LayoutTransition buildLayoutTransition() { |
| 492 | final LayoutTransition transition = new LayoutTransition(); |
| 493 | if (TEST_ANIM) { |
| 494 | transition.setDuration(1500); |
| 495 | } |
| 496 | transition.setAnimateParentHierarchy(false); |
| 497 | return transition; |
| 498 | } |
| 499 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 500 | /** |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 501 | * Rebuild all tabs based on {@link NetworkPolicyEditor} and |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 502 | * {@link #mShowWifi}, hiding the tabs entirely when applicable. Selects |
| 503 | * first tab, and kicks off a full rebind of body contents. |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 504 | */ |
| 505 | private void updateTabs() { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 506 | final Context context = getActivity(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 507 | mTabHost.clearAllTabs(); |
| 508 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 509 | final boolean mobileSplit = isMobilePolicySplit(); |
| 510 | if (mobileSplit && hasMobile4gRadio(context)) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 511 | mTabHost.addTab(buildTabSpec(TAB_3G, R.string.data_usage_tab_3g)); |
| 512 | mTabHost.addTab(buildTabSpec(TAB_4G, R.string.data_usage_tab_4g)); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 513 | } else if (hasMobileRadio(context)) { |
| 514 | mTabHost.addTab(buildTabSpec(TAB_MOBILE, R.string.data_usage_tab_mobile)); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 515 | } |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 516 | if (mShowWifi && hasWifiRadio(context)) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 517 | mTabHost.addTab(buildTabSpec(TAB_WIFI, R.string.data_usage_tab_wifi)); |
| 518 | } |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 519 | if (mShowEthernet && hasEthernet(context)) { |
| 520 | mTabHost.addTab(buildTabSpec(TAB_ETHERNET, R.string.data_usage_tab_ethernet)); |
| 521 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 522 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 523 | final boolean multipleTabs = mTabWidget.getTabCount() > 1; |
| 524 | mTabWidget.setVisibility(multipleTabs ? View.VISIBLE : View.GONE); |
| 525 | if (mIntentTab != null) { |
| 526 | if (Objects.equal(mIntentTab, mTabHost.getCurrentTabTag())) { |
| 527 | updateBody(); |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 528 | } else { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 529 | mTabHost.setCurrentTabByTag(mIntentTab); |
| 530 | } |
| 531 | mIntentTab = null; |
| 532 | } else { |
| 533 | if (mTabHost.getCurrentTab() == 0) { |
| 534 | updateBody(); |
| 535 | } else { |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 536 | mTabHost.setCurrentTab(0); |
| 537 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 541 | /** |
| 542 | * Factory that provide empty {@link View} to make {@link TabHost} happy. |
| 543 | */ |
| 544 | private TabContentFactory mEmptyTabContent = new TabContentFactory() { |
| 545 | /** {@inheritDoc} */ |
| 546 | public View createTabContent(String tag) { |
| 547 | return new View(mTabHost.getContext()); |
| 548 | } |
| 549 | }; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 550 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 551 | /** |
| 552 | * Build {@link TabSpec} with thin indicator, and empty content. |
| 553 | */ |
| 554 | private TabSpec buildTabSpec(String tag, int titleRes) { |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 555 | return mTabHost.newTabSpec(tag).setIndicator(getText(titleRes)).setContent( |
| 556 | mEmptyTabContent); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | private OnTabChangeListener mTabListener = new OnTabChangeListener() { |
| 560 | /** {@inheritDoc} */ |
| 561 | public void onTabChanged(String tabId) { |
| 562 | // user changed tab; update body |
| 563 | updateBody(); |
| 564 | } |
| 565 | }; |
| 566 | |
| 567 | /** |
| 568 | * Update body content based on current tab. Loads |
| 569 | * {@link NetworkStatsHistory} and {@link NetworkPolicy} from system, and |
| 570 | * binds them to visible controls. |
| 571 | */ |
| 572 | private void updateBody() { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 573 | mBinding = true; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 574 | |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 575 | final Context context = getActivity(); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 576 | final String currentTab = mTabHost.getCurrentTabTag(); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 577 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 578 | if (currentTab == null) { |
| 579 | Log.w(TAG, "no tab selected; hiding body"); |
| 580 | mListView.setVisibility(View.GONE); |
| 581 | return; |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 582 | } else { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 583 | mListView.setVisibility(View.VISIBLE); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 584 | } |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 585 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 586 | final boolean tabChanged = !currentTab.equals(mCurrentTab); |
| 587 | mCurrentTab = currentTab; |
| 588 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 589 | if (LOGD) Log.d(TAG, "updateBody() with currentTab=" + currentTab); |
| 590 | |
| 591 | if (TAB_WIFI.equals(currentTab)) { |
| 592 | // wifi doesn't have any controls |
| 593 | mDataEnabledView.setVisibility(View.GONE); |
| 594 | mDisableAtLimitView.setVisibility(View.GONE); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 595 | mTemplate = buildTemplateWifi(); |
| 596 | |
| 597 | } else if (TAB_ETHERNET.equals(currentTab)) { |
| 598 | // ethernet doesn't have any controls |
| 599 | mDataEnabledView.setVisibility(View.GONE); |
| 600 | mDisableAtLimitView.setVisibility(View.GONE); |
| 601 | mTemplate = buildTemplateEthernet(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 602 | |
| 603 | } else { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 604 | mDataEnabledView.setVisibility(View.VISIBLE); |
| 605 | mDisableAtLimitView.setVisibility(View.VISIBLE); |
| 606 | } |
| 607 | |
| 608 | if (TAB_MOBILE.equals(currentTab)) { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 609 | setPreferenceTitle(mDataEnabledView, R.string.data_usage_enable_mobile); |
| 610 | setPreferenceTitle(mDisableAtLimitView, R.string.data_usage_disable_mobile_limit); |
| 611 | mDataEnabled.setChecked(mConnService.getMobileDataEnabled()); |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 612 | mTemplate = buildTemplateMobileAll(getActiveSubscriberId(context)); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 613 | |
| 614 | } else if (TAB_3G.equals(currentTab)) { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 615 | setPreferenceTitle(mDataEnabledView, R.string.data_usage_enable_3g); |
| 616 | setPreferenceTitle(mDisableAtLimitView, R.string.data_usage_disable_3g_limit); |
| 617 | // TODO: bind mDataEnabled to 3G radio state |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 618 | mTemplate = buildTemplateMobile3gLower(getActiveSubscriberId(context)); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 619 | |
| 620 | } else if (TAB_4G.equals(currentTab)) { |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 621 | setPreferenceTitle(mDataEnabledView, R.string.data_usage_enable_4g); |
| 622 | setPreferenceTitle(mDisableAtLimitView, R.string.data_usage_disable_4g_limit); |
| 623 | // TODO: bind mDataEnabled to 4G radio state |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 624 | mTemplate = buildTemplateMobile4g(getActiveSubscriberId(context)); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 627 | try { |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 628 | // load stats for current template |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 629 | mHistory = mStatsService.getHistoryForNetwork( |
| 630 | mTemplate, FIELD_RX_BYTES | FIELD_TX_BYTES); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 631 | } catch (RemoteException e) { |
| 632 | // since we can't do much without policy or history, and we don't |
| 633 | // want to leave with half-baked UI, we bail hard. |
| 634 | throw new RuntimeException("problem reading network policy or stats", e); |
| 635 | } |
| 636 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 637 | // bind chart to historical stats |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 638 | mChart.bindNetworkStats(mHistory); |
| 639 | |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 640 | // only update policy when switching tabs |
| 641 | updatePolicy(tabChanged); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 642 | updateAppDetail(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 643 | |
| 644 | // force scroll to top of body |
| 645 | mListView.smoothScrollToPosition(0); |
| 646 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 647 | mBinding = false; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 650 | private boolean isAppDetailMode() { |
| 651 | return mUid != UID_NONE; |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Update UID details panels to match {@link #mUid}, showing or hiding them |
| 656 | * depending on {@link #isAppDetailMode()}. |
| 657 | */ |
| 658 | private void updateAppDetail() { |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 659 | final Context context = getActivity(); |
| 660 | final PackageManager pm = context.getPackageManager(); |
| 661 | final LayoutInflater inflater = getActivity().getLayoutInflater(); |
| 662 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 663 | if (isAppDetailMode()) { |
| 664 | mAppDetail.setVisibility(View.VISIBLE); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 665 | mCycleAdapter.setChangeVisible(false); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 666 | } else { |
| 667 | mAppDetail.setVisibility(View.GONE); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 668 | mCycleAdapter.setChangeVisible(true); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 669 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 670 | mDetailHistory = null; |
| 671 | mDetailHistoryDefault = null; |
| 672 | mDetailHistoryForeground = null; |
| 673 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 674 | // hide detail stats when not in detail mode |
| 675 | mChart.bindDetailNetworkStats(null); |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | // remove warning/limit sweeps while in detail mode |
| 680 | mChart.bindNetworkPolicy(null); |
| 681 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 682 | // show icon and all labels appearing under this app |
| 683 | final UidDetail detail = resolveDetailForUid(context, mUid); |
| 684 | mAppIcon.setImageDrawable(detail.icon); |
| 685 | |
| 686 | mAppTitles.removeAllViews(); |
| 687 | if (detail.detailLabels != null) { |
| 688 | for (CharSequence label : detail.detailLabels) { |
| 689 | mAppTitles.addView(inflateAppTitle(inflater, mAppTitles, label)); |
| 690 | } |
| 691 | } else { |
| 692 | mAppTitles.addView(inflateAppTitle(inflater, mAppTitles, detail.label)); |
| 693 | } |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 694 | |
| 695 | // enable settings button when package provides it |
| 696 | // TODO: target torwards entire UID instead of just first package |
| 697 | final String[] packageNames = pm.getPackagesForUid(mUid); |
| 698 | if (packageNames != null && packageNames.length > 0) { |
| 699 | mAppSettingsIntent = new Intent(Intent.ACTION_MANAGE_NETWORK_USAGE); |
| 700 | mAppSettingsIntent.setPackage(packageNames[0]); |
| 701 | mAppSettingsIntent.addCategory(Intent.CATEGORY_DEFAULT); |
| 702 | |
| 703 | final boolean matchFound = pm.resolveActivity(mAppSettingsIntent, 0) != null; |
| 704 | mAppSettings.setEnabled(matchFound); |
| 705 | |
| 706 | } else { |
| 707 | mAppSettingsIntent = null; |
| 708 | mAppSettings.setEnabled(false); |
| 709 | } |
| 710 | |
| 711 | try { |
| 712 | // load stats for current uid and template |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 713 | mDetailHistoryDefault = mStatsService.getHistoryForUid( |
| 714 | mTemplate, mUid, SET_DEFAULT, TAG_NONE, FIELD_RX_BYTES | FIELD_TX_BYTES); |
| 715 | mDetailHistoryForeground = mStatsService.getHistoryForUid( |
| 716 | mTemplate, mUid, SET_FOREGROUND, TAG_NONE, FIELD_RX_BYTES | FIELD_TX_BYTES); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 717 | } catch (RemoteException e) { |
| 718 | // since we can't do much without history, and we don't want to |
| 719 | // leave with half-baked UI, we bail hard. |
| 720 | throw new RuntimeException("problem reading network stats", e); |
| 721 | } |
| 722 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 723 | mDetailHistory = new NetworkStatsHistory(mDetailHistoryForeground.getBucketDuration()); |
| 724 | mDetailHistory.recordEntireHistory(mDetailHistoryDefault); |
| 725 | mDetailHistory.recordEntireHistory(mDetailHistoryForeground); |
| 726 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 727 | // bind chart to historical stats |
| 728 | mChart.bindDetailNetworkStats(mDetailHistory); |
| 729 | |
| 730 | updateDetailData(); |
| 731 | |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 732 | if (NetworkPolicyManager.isUidValidForPolicy(context, mUid) && !getRestrictBackground() |
| 733 | && isBandwidthControlEnabled()) { |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 734 | mAppRestrictView.setVisibility(View.VISIBLE); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 735 | mAppRestrict.setChecked(getAppRestrictBackground()); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 736 | |
| 737 | } else { |
| 738 | mAppRestrictView.setVisibility(View.GONE); |
| 739 | } |
| 740 | |
| 741 | } |
| 742 | |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 743 | private void setPolicyCycleDay(int cycleDay) { |
| 744 | if (LOGD) Log.d(TAG, "setPolicyCycleDay()"); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 745 | mPolicyEditor.setPolicyCycleDay(mTemplate, cycleDay); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 746 | updatePolicy(true); |
| 747 | } |
| 748 | |
| 749 | private void setPolicyWarningBytes(long warningBytes) { |
| 750 | if (LOGD) Log.d(TAG, "setPolicyWarningBytes()"); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 751 | mPolicyEditor.setPolicyWarningBytes(mTemplate, warningBytes); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 752 | updatePolicy(false); |
| 753 | } |
| 754 | |
| 755 | private void setPolicyLimitBytes(long limitBytes) { |
| 756 | if (LOGD) Log.d(TAG, "setPolicyLimitBytes()"); |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 757 | mPolicyEditor.setPolicyLimitBytes(mTemplate, limitBytes); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 758 | updatePolicy(false); |
| 759 | } |
| 760 | |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 761 | private boolean isNetworkPolicyModifiable() { |
| 762 | return isBandwidthControlEnabled() && mDataEnabled.isChecked(); |
| 763 | } |
| 764 | |
| 765 | private boolean isBandwidthControlEnabled() { |
| 766 | try { |
| 767 | return mNetworkService.isBandwidthControlEnabled(); |
| 768 | } catch (RemoteException e) { |
| 769 | Log.w(TAG, "problem talking with INetworkManagementService: " + e); |
| 770 | return false; |
| 771 | } |
| 772 | } |
| 773 | |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 774 | private boolean getDataRoaming() { |
| 775 | final ContentResolver resolver = getActivity().getContentResolver(); |
| 776 | return Settings.Secure.getInt(resolver, Settings.Secure.DATA_ROAMING, 0) != 0; |
| 777 | } |
| 778 | |
| 779 | private void setDataRoaming(boolean enabled) { |
| 780 | // TODO: teach telephony DataConnectionTracker to watch and apply |
| 781 | // updates when changed. |
| 782 | final ContentResolver resolver = getActivity().getContentResolver(); |
| 783 | Settings.Secure.putInt(resolver, Settings.Secure.DATA_ROAMING, enabled ? 1 : 0); |
| 784 | mMenuDataRoaming.setChecked(enabled); |
| 785 | } |
| 786 | |
| 787 | private boolean getRestrictBackground() { |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 788 | try { |
| 789 | return mPolicyService.getRestrictBackground(); |
| 790 | } catch (RemoteException e) { |
| 791 | Log.w(TAG, "problem talking with policy service: " + e); |
| 792 | return false; |
| 793 | } |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | private void setRestrictBackground(boolean restrictBackground) { |
| 797 | if (LOGD) Log.d(TAG, "setRestrictBackground()"); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 798 | try { |
| 799 | mPolicyService.setRestrictBackground(restrictBackground); |
| 800 | mMenuRestrictBackground.setChecked(restrictBackground); |
| 801 | } catch (RemoteException e) { |
| 802 | Log.w(TAG, "problem talking with policy service: " + e); |
| 803 | } |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | private boolean getAppRestrictBackground() { |
| 807 | final int uidPolicy; |
| 808 | try { |
| 809 | uidPolicy = mPolicyService.getUidPolicy(mUid); |
| 810 | } catch (RemoteException e) { |
| 811 | // since we can't do much without policy, we bail hard. |
| 812 | throw new RuntimeException("problem reading network policy", e); |
| 813 | } |
| 814 | |
| 815 | return (uidPolicy & POLICY_REJECT_METERED_BACKGROUND) != 0; |
| 816 | } |
| 817 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 818 | private void setAppRestrictBackground(boolean restrictBackground) { |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 819 | if (LOGD) Log.d(TAG, "setAppRestrictBackground()"); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 820 | try { |
| 821 | mPolicyService.setUidPolicy( |
| 822 | mUid, restrictBackground ? POLICY_REJECT_METERED_BACKGROUND : POLICY_NONE); |
| 823 | } catch (RemoteException e) { |
| 824 | throw new RuntimeException("unable to save policy", e); |
| 825 | } |
| 826 | |
| 827 | mAppRestrict.setChecked(restrictBackground); |
| 828 | } |
| 829 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 830 | /** |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 831 | * Update chart sweeps and cycle list to reflect {@link NetworkPolicy} for |
| 832 | * current {@link #mTemplate}. |
| 833 | */ |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 834 | private void updatePolicy(boolean refreshCycle) { |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 835 | if (isAppDetailMode()) { |
| 836 | mNetworkSwitches.setVisibility(View.GONE); |
| 837 | // we fall through to update cycle list for detail mode |
| 838 | } else { |
| 839 | mNetworkSwitches.setVisibility(View.VISIBLE); |
Jeff Sharkey | 2af35fb | 2011-06-24 17:30:27 -0700 | [diff] [blame] | 840 | |
| 841 | // when heading back to summary without cycle refresh, kick details |
| 842 | // update to repopulate list. |
| 843 | if (!refreshCycle) { |
| 844 | updateDetailData(); |
| 845 | } |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 848 | final NetworkPolicy policy = mPolicyEditor.getPolicy(mTemplate); |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 849 | if (isNetworkPolicyModifiable()) { |
| 850 | mDisableAtLimitView.setVisibility(View.VISIBLE); |
| 851 | mDisableAtLimit.setChecked(policy != null && policy.limitBytes != LIMIT_DISABLED); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 852 | if (!isAppDetailMode()) { |
| 853 | mChart.bindNetworkPolicy(policy); |
| 854 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 855 | |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 856 | } else { |
| 857 | // controls are disabled; don't bind warning/limit sweeps |
| 858 | mDisableAtLimitView.setVisibility(View.GONE); |
| 859 | mChart.bindNetworkPolicy(null); |
| 860 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 861 | |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 862 | if (refreshCycle) { |
| 863 | // generate cycle list based on policy and available history |
| 864 | updateCycleList(policy); |
| 865 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | /** |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 869 | * Rebuild {@link #mCycleAdapter} based on {@link NetworkPolicy#cycleDay} |
| 870 | * and available {@link NetworkStatsHistory} data. Always selects the newest |
| 871 | * item, updating the inspection range on {@link #mChart}. |
| 872 | */ |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 873 | private void updateCycleList(NetworkPolicy policy) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 874 | mCycleAdapter.clear(); |
| 875 | |
| 876 | final Context context = mCycleSpinner.getContext(); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 877 | long historyStart = mHistory.getStart(); |
| 878 | long historyEnd = mHistory.getEnd(); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 879 | |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 880 | if (historyStart == Long.MAX_VALUE || historyEnd == Long.MIN_VALUE) { |
| 881 | historyStart = System.currentTimeMillis(); |
| 882 | historyEnd = System.currentTimeMillis(); |
| 883 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 884 | |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 885 | boolean hasCycles = false; |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 886 | if (policy != null) { |
| 887 | // find the next cycle boundary |
| 888 | long cycleEnd = computeNextCycleBoundary(historyEnd, policy); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 889 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 890 | int guardCount = 0; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 891 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 892 | // walk backwards, generating all valid cycle ranges |
| 893 | while (cycleEnd > historyStart) { |
| 894 | final long cycleStart = computeLastCycleBoundary(cycleEnd, policy); |
| 895 | Log.d(TAG, "generating cs=" + cycleStart + " to ce=" + cycleEnd + " waiting for hs=" |
| 896 | + historyStart); |
| 897 | mCycleAdapter.add(new CycleItem(context, cycleStart, cycleEnd)); |
| 898 | cycleEnd = cycleStart; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 899 | hasCycles = true; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 900 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 901 | // TODO: remove this guard once we have better testing |
| 902 | if (guardCount++ > 50) { |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 903 | Log.wtf(TAG, "stuck generating ranges for historyStart=" + historyStart |
| 904 | + ", historyEnd=" + historyEnd + " and policy=" + policy); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 905 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 906 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 907 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 908 | // one last cycle entry to modify policy cycle day |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 909 | mCycleAdapter.setChangePossible(isNetworkPolicyModifiable()); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 910 | } |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 911 | |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 912 | if (!hasCycles) { |
| 913 | // no valid cycles; show all data |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 914 | // TODO: offer simple ranges like "last week" etc |
| 915 | mCycleAdapter.add(new CycleItem(context, historyStart, historyEnd)); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 916 | mCycleAdapter.setChangePossible(false); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 917 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 918 | |
| 919 | // force pick the current cycle (first item) |
| 920 | mCycleSpinner.setSelection(0); |
| 921 | mCycleListener.onItemSelected(mCycleSpinner, null, 0, 0); |
| 922 | } |
| 923 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 924 | private OnCheckedChangeListener mDataEnabledListener = new OnCheckedChangeListener() { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 925 | /** {@inheritDoc} */ |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 926 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 927 | if (mBinding) return; |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 928 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 929 | final boolean dataEnabled = isChecked; |
| 930 | mDataEnabled.setChecked(dataEnabled); |
| 931 | |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 932 | final String currentTab = mCurrentTab; |
| 933 | if (TAB_MOBILE.equals(currentTab)) { |
| 934 | mConnService.setMobileDataEnabled(dataEnabled); |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 935 | } |
Jeff Sharkey | 1ae43f9 | 2011-08-03 17:16:09 -0700 | [diff] [blame] | 936 | |
| 937 | // rebind policy to match radio state |
| 938 | updatePolicy(true); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 939 | } |
| 940 | }; |
| 941 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 942 | private View.OnClickListener mDisableAtLimitListener = new View.OnClickListener() { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 943 | /** {@inheritDoc} */ |
| 944 | public void onClick(View v) { |
| 945 | final boolean disableAtLimit = !mDisableAtLimit.isChecked(); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 946 | if (disableAtLimit) { |
| 947 | // enabling limit; show confirmation dialog which eventually |
| 948 | // calls setPolicyLimitBytes() once user confirms. |
| 949 | ConfirmLimitFragment.show(DataUsageSummary.this); |
| 950 | } else { |
| 951 | setPolicyLimitBytes(LIMIT_DISABLED); |
| 952 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 953 | } |
| 954 | }; |
| 955 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 956 | private View.OnClickListener mAppRestrictListener = new View.OnClickListener() { |
| 957 | /** {@inheritDoc} */ |
| 958 | public void onClick(View v) { |
| 959 | final boolean restrictBackground = !mAppRestrict.isChecked(); |
| 960 | |
| 961 | if (restrictBackground) { |
| 962 | // enabling restriction; show confirmation dialog which |
| 963 | // eventually calls setRestrictBackground() once user confirms. |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 964 | ConfirmAppRestrictFragment.show(DataUsageSummary.this); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 965 | } else { |
| 966 | setAppRestrictBackground(false); |
| 967 | } |
| 968 | } |
| 969 | }; |
| 970 | |
| 971 | private OnClickListener mAppSettingsListener = new OnClickListener() { |
| 972 | /** {@inheritDoc} */ |
| 973 | public void onClick(View v) { |
| 974 | // TODO: target torwards entire UID instead of just first package |
| 975 | startActivity(mAppSettingsIntent); |
| 976 | } |
| 977 | }; |
| 978 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 979 | private OnItemClickListener mListListener = new OnItemClickListener() { |
| 980 | /** {@inheritDoc} */ |
| 981 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 982 | final AppUsageItem app = (AppUsageItem) parent.getItemAtPosition(position); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 983 | AppDetailsFragment.show(DataUsageSummary.this, app.uid); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 984 | } |
| 985 | }; |
| 986 | |
| 987 | private OnItemSelectedListener mCycleListener = new OnItemSelectedListener() { |
| 988 | /** {@inheritDoc} */ |
| 989 | public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
| 990 | final CycleItem cycle = (CycleItem) parent.getItemAtPosition(position); |
| 991 | if (cycle instanceof CycleChangeItem) { |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 992 | // show cycle editor; will eventually call setPolicyCycleDay() |
| 993 | // when user finishes editing. |
| 994 | CycleEditorFragment.show(DataUsageSummary.this); |
| 995 | |
| 996 | // reset spinner to something other than "change cycle..." |
| 997 | mCycleSpinner.setSelection(0); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 998 | |
| 999 | } else { |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1000 | if (LOGD) { |
| 1001 | Log.d(TAG, "showing cycle " + cycle + ", start=" + cycle.start + ", end=" |
| 1002 | + cycle.end + "]"); |
| 1003 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1004 | |
| 1005 | // update chart to show selected cycle, and update detail data |
| 1006 | // to match updated sweep bounds. |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1007 | mChart.setVisibleRange(cycle.start, cycle.end); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1008 | |
| 1009 | updateDetailData(); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | /** {@inheritDoc} */ |
| 1014 | public void onNothingSelected(AdapterView<?> parent) { |
| 1015 | // ignored |
| 1016 | } |
| 1017 | }; |
| 1018 | |
| 1019 | /** |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1020 | * Update details based on {@link #mChart} inspection range depending on |
| 1021 | * current mode. In network mode, updates {@link #mAdapter} with sorted list |
| 1022 | * of applications data usage, and when {@link #isAppDetailMode()} update |
| 1023 | * app details. |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1024 | */ |
| 1025 | private void updateDetailData() { |
| 1026 | if (LOGD) Log.d(TAG, "updateDetailData()"); |
| 1027 | |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1028 | final long start = mChart.getInspectStart(); |
| 1029 | final long end = mChart.getInspectEnd(); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1030 | final long now = System.currentTimeMillis(); |
| 1031 | |
| 1032 | final Context context = getActivity(); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1033 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1034 | NetworkStatsHistory.Entry entry = null; |
| 1035 | if (isAppDetailMode() && mDetailHistory != null) { |
| 1036 | // bind foreground/background to piechart and labels |
| 1037 | entry = mDetailHistoryDefault.getValues(start, end, now, entry); |
| 1038 | final long defaultBytes = entry.rxBytes + entry.txBytes; |
| 1039 | entry = mDetailHistoryForeground.getValues(start, end, now, entry); |
| 1040 | final long foregroundBytes = entry.rxBytes + entry.txBytes; |
| 1041 | |
| 1042 | mAppPieChart.setOriginAngle(175); |
| 1043 | |
| 1044 | mAppPieChart.removeAllSlices(); |
| 1045 | mAppPieChart.addSlice(foregroundBytes, Color.parseColor("#d88d3a")); |
| 1046 | mAppPieChart.addSlice(defaultBytes, Color.parseColor("#666666")); |
| 1047 | |
| 1048 | mAppPieChart.generatePath(); |
| 1049 | |
| 1050 | mAppBackground.setText(Formatter.formatFileSize(context, defaultBytes)); |
| 1051 | mAppForeground.setText(Formatter.formatFileSize(context, foregroundBytes)); |
| 1052 | |
| 1053 | // and finally leave with summary data for label below |
| 1054 | entry = mDetailHistory.getValues(start, end, now, null); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1055 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1056 | getLoaderManager().destroyLoader(LOADER_SUMMARY); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1057 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1058 | } else { |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1059 | entry = mHistory.getValues(start, end, now, null); |
| 1060 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1061 | // kick off loader for detailed stats |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1062 | getLoaderManager().restartLoader(LOADER_SUMMARY, |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1063 | SummaryForAllUidLoader.buildArgs(mTemplate, start, end), mSummaryForAllUid); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1064 | } |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1065 | |
| 1066 | final long totalBytes = entry != null ? entry.rxBytes + entry.txBytes : 0; |
| 1067 | final String totalPhrase = Formatter.formatFileSize(context, totalBytes); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1068 | final String rangePhrase = formatDateRange(context, start, end, false); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1069 | |
| 1070 | mUsageSummary.setText( |
| 1071 | getString(R.string.data_usage_total_during_range, totalPhrase, rangePhrase)); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | private final LoaderCallbacks<NetworkStats> mSummaryForAllUid = new LoaderCallbacks< |
| 1075 | NetworkStats>() { |
| 1076 | /** {@inheritDoc} */ |
| 1077 | public Loader<NetworkStats> onCreateLoader(int id, Bundle args) { |
| 1078 | return new SummaryForAllUidLoader(getActivity(), mStatsService, args); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1081 | /** {@inheritDoc} */ |
| 1082 | public void onLoadFinished(Loader<NetworkStats> loader, NetworkStats data) { |
| 1083 | mAdapter.bindStats(data); |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 1084 | updateEmptyVisible(); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1085 | } |
Jeff Sharkey | aa5260e | 2011-06-14 23:21:59 -0700 | [diff] [blame] | 1086 | |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1087 | /** {@inheritDoc} */ |
| 1088 | public void onLoaderReset(Loader<NetworkStats> loader) { |
| 1089 | mAdapter.bindStats(null); |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 1090 | updateEmptyVisible(); |
| 1091 | } |
| 1092 | |
| 1093 | private void updateEmptyVisible() { |
| 1094 | final boolean isEmpty = mAdapter.isEmpty() && !isAppDetailMode(); |
| 1095 | mEmpty.setVisibility(isEmpty ? View.VISIBLE : View.GONE); |
Jeff Sharkey | 398b18f | 2011-07-10 18:56:30 -0700 | [diff] [blame] | 1096 | } |
| 1097 | }; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1098 | |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1099 | private boolean isMobilePolicySplit() { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1100 | final Context context = getActivity(); |
| 1101 | if (hasMobileRadio(context)) { |
| 1102 | final String subscriberId = getActiveSubscriberId(context); |
| 1103 | return mPolicyEditor.isMobilePolicySplit(subscriberId); |
| 1104 | } else { |
| 1105 | return false; |
| 1106 | } |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | private void setMobilePolicySplit(boolean split) { |
| 1110 | final String subscriberId = getActiveSubscriberId(getActivity()); |
| 1111 | mPolicyEditor.setMobilePolicySplit(subscriberId, split); |
| 1112 | } |
| 1113 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1114 | private static String getActiveSubscriberId(Context context) { |
| 1115 | final TelephonyManager telephony = (TelephonyManager) context.getSystemService( |
| 1116 | Context.TELEPHONY_SERVICE); |
| 1117 | return telephony.getSubscriberId(); |
| 1118 | } |
| 1119 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1120 | private DataUsageChartListener mChartListener = new DataUsageChartListener() { |
| 1121 | /** {@inheritDoc} */ |
| 1122 | public void onInspectRangeChanged() { |
| 1123 | if (LOGD) Log.d(TAG, "onInspectRangeChanged()"); |
| 1124 | updateDetailData(); |
| 1125 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1126 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1127 | /** {@inheritDoc} */ |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1128 | public void onWarningChanged() { |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1129 | setPolicyWarningBytes(mChart.getWarningBytes()); |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1130 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1131 | |
Jeff Sharkey | 05cc0cc | 2011-06-12 23:11:24 -0700 | [diff] [blame] | 1132 | /** {@inheritDoc} */ |
| 1133 | public void onLimitChanged() { |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1134 | setPolicyLimitBytes(mChart.getLimitBytes()); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1135 | } |
| 1136 | }; |
| 1137 | |
| 1138 | |
| 1139 | /** |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1140 | * List item that reflects a specific data usage cycle. |
| 1141 | */ |
| 1142 | public static class CycleItem { |
| 1143 | public CharSequence label; |
| 1144 | public long start; |
| 1145 | public long end; |
| 1146 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1147 | CycleItem(CharSequence label) { |
| 1148 | this.label = label; |
| 1149 | } |
| 1150 | |
| 1151 | public CycleItem(Context context, long start, long end) { |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1152 | this.label = formatDateRange(context, start, end, true); |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1153 | this.start = start; |
| 1154 | this.end = end; |
| 1155 | } |
| 1156 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1157 | @Override |
| 1158 | public String toString() { |
| 1159 | return label.toString(); |
| 1160 | } |
| 1161 | } |
| 1162 | |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1163 | private static final StringBuilder sBuilder = new StringBuilder(50); |
| 1164 | private static final java.util.Formatter sFormatter = new java.util.Formatter( |
| 1165 | sBuilder, Locale.getDefault()); |
| 1166 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1167 | public static String formatDateRange(Context context, long start, long end, boolean utcTime) { |
| 1168 | final int flags = FORMAT_SHOW_DATE | FORMAT_ABBREV_MONTH; |
| 1169 | final String timezone = utcTime ? TIMEZONE_UTC : null; |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1170 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1171 | synchronized (sBuilder) { |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1172 | sBuilder.setLength(0); |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 1173 | return DateUtils |
| 1174 | .formatDateRange(context, sFormatter, start, end, flags, timezone).toString(); |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1175 | } |
| 1176 | } |
| 1177 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1178 | /** |
| 1179 | * Special-case data usage cycle that triggers dialog to change |
| 1180 | * {@link NetworkPolicy#cycleDay}. |
| 1181 | */ |
| 1182 | public static class CycleChangeItem extends CycleItem { |
| 1183 | public CycleChangeItem(Context context) { |
| 1184 | super(context.getString(R.string.data_usage_change_cycle)); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | public static class CycleAdapter extends ArrayAdapter<CycleItem> { |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1189 | private boolean mChangePossible = false; |
| 1190 | private boolean mChangeVisible = false; |
| 1191 | |
| 1192 | private final CycleChangeItem mChangeItem; |
| 1193 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1194 | public CycleAdapter(Context context) { |
| 1195 | super(context, android.R.layout.simple_spinner_item); |
| 1196 | setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1197 | mChangeItem = new CycleChangeItem(context); |
| 1198 | } |
| 1199 | |
| 1200 | public void setChangePossible(boolean possible) { |
| 1201 | mChangePossible = possible; |
| 1202 | updateChange(); |
| 1203 | } |
| 1204 | |
| 1205 | public void setChangeVisible(boolean visible) { |
| 1206 | mChangeVisible = visible; |
| 1207 | updateChange(); |
| 1208 | } |
| 1209 | |
| 1210 | private void updateChange() { |
| 1211 | remove(mChangeItem); |
| 1212 | if (mChangePossible && mChangeVisible) { |
| 1213 | add(mChangeItem); |
| 1214 | } |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
Jeff Sharkey | 4dfa660 | 2011-06-13 00:42:03 -0700 | [diff] [blame] | 1218 | private static class AppUsageItem implements Comparable<AppUsageItem> { |
| 1219 | public int uid; |
| 1220 | public long total; |
| 1221 | |
| 1222 | /** {@inheritDoc} */ |
| 1223 | public int compareTo(AppUsageItem another) { |
| 1224 | return Long.compare(another.total, total); |
| 1225 | } |
| 1226 | } |
| 1227 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1228 | /** |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1229 | * Adapter of applications, sorted by total usage descending. |
| 1230 | */ |
| 1231 | public static class DataUsageAdapter extends BaseAdapter { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1232 | private ArrayList<AppUsageItem> mItems = Lists.newArrayList(); |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1233 | private long mLargest; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1234 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1235 | /** |
| 1236 | * Bind the given {@link NetworkStats}, or {@code null} to clear list. |
| 1237 | */ |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1238 | public void bindStats(NetworkStats stats) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1239 | mItems.clear(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1240 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1241 | final AppUsageItem systemItem = new AppUsageItem(); |
| 1242 | systemItem.uid = android.os.Process.SYSTEM_UID; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1243 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1244 | final SparseArray<AppUsageItem> knownUids = new SparseArray<AppUsageItem>(); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1245 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1246 | NetworkStats.Entry entry = null; |
| 1247 | final int size = stats != null ? stats.size() : 0; |
| 1248 | for (int i = 0; i < size; i++) { |
| 1249 | entry = stats.getValues(i, entry); |
| 1250 | |
| 1251 | final int uid = entry.uid; |
| 1252 | final boolean isApp = uid >= android.os.Process.FIRST_APPLICATION_UID |
| 1253 | && uid <= android.os.Process.LAST_APPLICATION_UID; |
| 1254 | if (isApp || uid == TrafficStats.UID_REMOVED) { |
| 1255 | AppUsageItem item = knownUids.get(uid); |
| 1256 | if (item == null) { |
| 1257 | item = new AppUsageItem(); |
| 1258 | item.uid = uid; |
| 1259 | knownUids.put(uid, item); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1260 | mItems.add(item); |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1261 | } |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1262 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1263 | item.total += entry.rxBytes + entry.txBytes; |
| 1264 | } else { |
| 1265 | systemItem.total += entry.rxBytes + entry.txBytes; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1266 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 1269 | if (systemItem.total > 0) { |
| 1270 | mItems.add(systemItem); |
| 1271 | } |
| 1272 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1273 | Collections.sort(mItems); |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1274 | mLargest = (mItems.size() > 0) ? mItems.get(0).total : 0; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1275 | notifyDataSetChanged(); |
| 1276 | } |
| 1277 | |
| 1278 | @Override |
| 1279 | public int getCount() { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1280 | return mItems.size(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | @Override |
| 1284 | public Object getItem(int position) { |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1285 | return mItems.get(position); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | @Override |
| 1289 | public long getItemId(int position) { |
Jeff Sharkey | e2afc0f | 2011-08-01 15:29:30 -0700 | [diff] [blame] | 1290 | return mItems.get(position).uid; |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
| 1293 | @Override |
| 1294 | public View getView(int position, View convertView, ViewGroup parent) { |
| 1295 | if (convertView == null) { |
| 1296 | convertView = LayoutInflater.from(parent.getContext()).inflate( |
Jeff Sharkey | 52c3f44 | 2011-06-23 00:39:38 -0700 | [diff] [blame] | 1297 | R.layout.data_usage_item, parent, false); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | final Context context = parent.getContext(); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1301 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1302 | final ImageView icon = (ImageView) convertView.findViewById(android.R.id.icon); |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1303 | final TextView title = (TextView) convertView.findViewById(android.R.id.title); |
| 1304 | final TextView summary = (TextView) convertView.findViewById(android.R.id.summary); |
| 1305 | final ProgressBar progress = (ProgressBar) convertView.findViewById( |
| 1306 | android.R.id.progress); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1307 | |
Jeff Sharkey | 8a50364 | 2011-06-10 13:31:21 -0700 | [diff] [blame] | 1308 | final AppUsageItem item = mItems.get(position); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1309 | final UidDetail detail = resolveDetailForUid(context, item.uid); |
| 1310 | |
| 1311 | icon.setImageDrawable(detail.icon); |
| 1312 | title.setText(detail.label); |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1313 | summary.setText(Formatter.formatFileSize(context, item.total)); |
| 1314 | |
| 1315 | final int percentTotal = mLargest != 0 ? (int) (item.total * 100 / mLargest) : 0; |
| 1316 | progress.setProgress(percentTotal); |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1317 | |
| 1318 | return convertView; |
| 1319 | } |
| 1320 | |
| 1321 | } |
| 1322 | |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1323 | /** |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1324 | * Empty {@link Fragment} that controls display of UID details in |
| 1325 | * {@link DataUsageSummary}. |
| 1326 | */ |
| 1327 | public static class AppDetailsFragment extends Fragment { |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1328 | private static final String EXTRA_UID = "uid"; |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1329 | |
| 1330 | public static void show(DataUsageSummary parent, int uid) { |
| 1331 | final Bundle args = new Bundle(); |
| 1332 | args.putInt(EXTRA_UID, uid); |
| 1333 | |
| 1334 | final AppDetailsFragment fragment = new AppDetailsFragment(); |
| 1335 | fragment.setArguments(args); |
| 1336 | fragment.setTargetFragment(parent, 0); |
| 1337 | |
| 1338 | final FragmentTransaction ft = parent.getFragmentManager().beginTransaction(); |
| 1339 | ft.add(fragment, TAG_APP_DETAILS); |
| 1340 | ft.addToBackStack(TAG_APP_DETAILS); |
| 1341 | ft.commit(); |
| 1342 | } |
| 1343 | |
| 1344 | @Override |
| 1345 | public void onStart() { |
| 1346 | super.onStart(); |
| 1347 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1348 | target.mUid = getArguments().getInt(EXTRA_UID); |
| 1349 | target.updateBody(); |
| 1350 | } |
| 1351 | |
| 1352 | @Override |
| 1353 | public void onStop() { |
| 1354 | super.onStop(); |
| 1355 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1356 | target.mUid = UID_NONE; |
| 1357 | target.updateBody(); |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | /** |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1362 | * Dialog to request user confirmation before setting |
| 1363 | * {@link NetworkPolicy#limitBytes}. |
| 1364 | */ |
| 1365 | public static class ConfirmLimitFragment extends DialogFragment { |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1366 | private static final String EXTRA_MESSAGE_ID = "messageId"; |
| 1367 | private static final String EXTRA_LIMIT_BYTES = "limitBytes"; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1368 | |
| 1369 | public static void show(DataUsageSummary parent) { |
| 1370 | final Bundle args = new Bundle(); |
| 1371 | |
| 1372 | // TODO: customize default limits based on network template |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1373 | final String currentTab = parent.mCurrentTab; |
| 1374 | if (TAB_3G.equals(currentTab)) { |
| 1375 | args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_3g); |
| 1376 | args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES); |
| 1377 | } else if (TAB_4G.equals(currentTab)) { |
| 1378 | args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_4g); |
| 1379 | args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES); |
| 1380 | } else if (TAB_MOBILE.equals(currentTab)) { |
| 1381 | args.putInt(EXTRA_MESSAGE_ID, R.string.data_usage_limit_dialog_mobile); |
| 1382 | args.putLong(EXTRA_LIMIT_BYTES, 5 * GB_IN_BYTES); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | final ConfirmLimitFragment dialog = new ConfirmLimitFragment(); |
| 1386 | dialog.setArguments(args); |
| 1387 | dialog.setTargetFragment(parent, 0); |
| 1388 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_LIMIT); |
| 1389 | } |
| 1390 | |
| 1391 | @Override |
| 1392 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1393 | final Context context = getActivity(); |
| 1394 | |
| 1395 | final int messageId = getArguments().getInt(EXTRA_MESSAGE_ID); |
| 1396 | final long limitBytes = getArguments().getLong(EXTRA_LIMIT_BYTES); |
| 1397 | |
| 1398 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1399 | builder.setTitle(R.string.data_usage_limit_dialog_title); |
| 1400 | builder.setMessage(messageId); |
| 1401 | |
| 1402 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 1403 | public void onClick(DialogInterface dialog, int which) { |
| 1404 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1405 | if (target != null) { |
| 1406 | target.setPolicyLimitBytes(limitBytes); |
| 1407 | } |
| 1408 | } |
| 1409 | }); |
| 1410 | |
| 1411 | return builder.create(); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | /** |
| 1416 | * Dialog to edit {@link NetworkPolicy#cycleDay}. |
| 1417 | */ |
| 1418 | public static class CycleEditorFragment extends DialogFragment { |
Jeff Sharkey | 2412b0f | 2011-07-17 20:31:40 -0700 | [diff] [blame] | 1419 | private static final String EXTRA_CYCLE_DAY = "cycleDay"; |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1420 | |
| 1421 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1422 | final NetworkPolicy policy = parent.mPolicyEditor.getPolicy(parent.mTemplate); |
Jeff Sharkey | 4c72ae5 | 2011-06-14 15:01:18 -0700 | [diff] [blame] | 1423 | final Bundle args = new Bundle(); |
| 1424 | args.putInt(CycleEditorFragment.EXTRA_CYCLE_DAY, policy.cycleDay); |
| 1425 | |
| 1426 | final CycleEditorFragment dialog = new CycleEditorFragment(); |
| 1427 | dialog.setArguments(args); |
| 1428 | dialog.setTargetFragment(parent, 0); |
| 1429 | dialog.show(parent.getFragmentManager(), TAG_CYCLE_EDITOR); |
| 1430 | } |
| 1431 | |
| 1432 | @Override |
| 1433 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1434 | final Context context = getActivity(); |
| 1435 | |
| 1436 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1437 | final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext()); |
| 1438 | |
| 1439 | final View view = dialogInflater.inflate(R.layout.data_usage_cycle_editor, null, false); |
| 1440 | final NumberPicker cycleDayPicker = (NumberPicker) view.findViewById(R.id.cycle_day); |
| 1441 | |
| 1442 | final int oldCycleDay = getArguments().getInt(EXTRA_CYCLE_DAY, 1); |
| 1443 | |
| 1444 | cycleDayPicker.setMinValue(1); |
| 1445 | cycleDayPicker.setMaxValue(31); |
| 1446 | cycleDayPicker.setValue(oldCycleDay); |
| 1447 | cycleDayPicker.setWrapSelectorWheel(true); |
| 1448 | |
| 1449 | builder.setTitle(R.string.data_usage_cycle_editor_title); |
| 1450 | builder.setView(view); |
| 1451 | |
| 1452 | builder.setPositiveButton(R.string.data_usage_cycle_editor_positive, |
| 1453 | new DialogInterface.OnClickListener() { |
| 1454 | public void onClick(DialogInterface dialog, int which) { |
| 1455 | final int cycleDay = cycleDayPicker.getValue(); |
| 1456 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1457 | if (target != null) { |
| 1458 | target.setPolicyCycleDay(cycleDay); |
| 1459 | } |
| 1460 | } |
| 1461 | }); |
| 1462 | |
| 1463 | return builder.create(); |
| 1464 | } |
| 1465 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1466 | |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1467 | /** |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1468 | * Dialog to request user confirmation before setting |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1469 | * {@link Settings.Secure#DATA_ROAMING}. |
| 1470 | */ |
| 1471 | public static class ConfirmDataRoamingFragment extends DialogFragment { |
| 1472 | public static void show(DataUsageSummary parent) { |
| 1473 | final Bundle args = new Bundle(); |
| 1474 | |
| 1475 | final ConfirmDataRoamingFragment dialog = new ConfirmDataRoamingFragment(); |
| 1476 | dialog.setTargetFragment(parent, 0); |
| 1477 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_ROAMING); |
| 1478 | } |
| 1479 | |
| 1480 | @Override |
| 1481 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1482 | final Context context = getActivity(); |
| 1483 | |
| 1484 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
| 1485 | builder.setTitle(R.string.roaming_reenable_title); |
| 1486 | builder.setMessage(R.string.roaming_warning); |
| 1487 | |
| 1488 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 1489 | public void onClick(DialogInterface dialog, int which) { |
| 1490 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1491 | if (target != null) { |
| 1492 | target.setDataRoaming(true); |
| 1493 | } |
| 1494 | } |
| 1495 | }); |
| 1496 | builder.setNegativeButton(android.R.string.cancel, null); |
| 1497 | |
| 1498 | return builder.create(); |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | /** |
| 1503 | * Dialog to request user confirmation before setting |
Jeff Sharkey | d360e5e | 2011-07-26 19:30:26 -0700 | [diff] [blame] | 1504 | * {@link INetworkPolicyManager#setRestrictBackground(boolean)}. |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1505 | */ |
| 1506 | public static class ConfirmRestrictFragment extends DialogFragment { |
| 1507 | public static void show(DataUsageSummary parent) { |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1508 | final Bundle args = new Bundle(); |
| 1509 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1510 | final ConfirmRestrictFragment dialog = new ConfirmRestrictFragment(); |
| 1511 | dialog.setTargetFragment(parent, 0); |
| 1512 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_RESTRICT); |
| 1513 | } |
| 1514 | |
| 1515 | @Override |
| 1516 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1517 | final Context context = getActivity(); |
| 1518 | |
| 1519 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 1520 | builder.setTitle(R.string.data_usage_restrict_background_title); |
| 1521 | builder.setMessage(R.string.data_usage_restrict_background); |
| 1522 | |
| 1523 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 1524 | public void onClick(DialogInterface dialog, int which) { |
| 1525 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1526 | if (target != null) { |
| 1527 | target.setRestrictBackground(true); |
| 1528 | } |
| 1529 | } |
| 1530 | }); |
| 1531 | builder.setNegativeButton(android.R.string.cancel, null); |
| 1532 | |
| 1533 | return builder.create(); |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | /** |
| 1538 | * Dialog to request user confirmation before setting |
| 1539 | * {@link #POLICY_REJECT_METERED_BACKGROUND}. |
| 1540 | */ |
| 1541 | public static class ConfirmAppRestrictFragment extends DialogFragment { |
| 1542 | public static void show(DataUsageSummary parent) { |
| 1543 | final ConfirmAppRestrictFragment dialog = new ConfirmAppRestrictFragment(); |
| 1544 | dialog.setTargetFragment(parent, 0); |
| 1545 | dialog.show(parent.getFragmentManager(), TAG_CONFIRM_APP_RESTRICT); |
| 1546 | } |
| 1547 | |
| 1548 | @Override |
| 1549 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 1550 | final Context context = getActivity(); |
| 1551 | |
| 1552 | final AlertDialog.Builder builder = new AlertDialog.Builder(context); |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1553 | builder.setTitle(R.string.data_usage_app_restrict_dialog_title); |
| 1554 | builder.setMessage(R.string.data_usage_app_restrict_dialog); |
| 1555 | |
| 1556 | builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 1557 | public void onClick(DialogInterface dialog, int which) { |
| 1558 | final DataUsageSummary target = (DataUsageSummary) getTargetFragment(); |
| 1559 | if (target != null) { |
| 1560 | target.setAppRestrictBackground(true); |
| 1561 | } |
| 1562 | } |
| 1563 | }); |
| 1564 | builder.setNegativeButton(android.R.string.cancel, null); |
| 1565 | |
| 1566 | return builder.create(); |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | /** |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 1571 | * Compute default tab that should be selected, based on |
| 1572 | * {@link NetworkPolicyManager#EXTRA_NETWORK_TEMPLATE} extra. |
| 1573 | */ |
| 1574 | private static String computeTabFromIntent(Intent intent) { |
Jeff Sharkey | 271ec8a | 2011-07-20 16:59:16 -0700 | [diff] [blame] | 1575 | final NetworkTemplate template = intent.getParcelableExtra(EXTRA_NETWORK_TEMPLATE); |
| 1576 | if (template == null) return null; |
| 1577 | |
| 1578 | switch (template.getMatchRule()) { |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1579 | case MATCH_MOBILE_3G_LOWER: |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 1580 | return TAB_3G; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1581 | case MATCH_MOBILE_4G: |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 1582 | return TAB_4G; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1583 | case MATCH_MOBILE_ALL: |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 1584 | return TAB_MOBILE; |
Jeff Sharkey | a662e49 | 2011-06-18 21:57:06 -0700 | [diff] [blame] | 1585 | case MATCH_WIFI: |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 1586 | return TAB_WIFI; |
| 1587 | default: |
| 1588 | return null; |
| 1589 | } |
| 1590 | } |
| 1591 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1592 | public static class UidDetail { |
| 1593 | public CharSequence label; |
| 1594 | public CharSequence[] detailLabels; |
| 1595 | public Drawable icon; |
| 1596 | } |
| 1597 | |
Jeff Sharkey | dd6efe1 | 2011-06-15 10:31:41 -0700 | [diff] [blame] | 1598 | /** |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1599 | * Resolve best descriptive label for the given UID. |
| 1600 | */ |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1601 | public static UidDetail resolveDetailForUid(Context context, int uid) { |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1602 | final Resources res = context.getResources(); |
| 1603 | final PackageManager pm = context.getPackageManager(); |
| 1604 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1605 | final UidDetail detail = new UidDetail(); |
| 1606 | detail.label = pm.getNameForUid(uid); |
| 1607 | detail.icon = pm.getDefaultActivityIcon(); |
| 1608 | |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1609 | // handle special case labels |
| 1610 | switch (uid) { |
| 1611 | case android.os.Process.SYSTEM_UID: |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1612 | detail.label = res.getString(R.string.process_kernel_label); |
| 1613 | detail.icon = pm.getDefaultActivityIcon(); |
| 1614 | return detail; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1615 | case TrafficStats.UID_REMOVED: |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1616 | detail.label = res.getString(R.string.data_usage_uninstalled_apps); |
| 1617 | detail.icon = pm.getDefaultActivityIcon(); |
| 1618 | return detail; |
Jeff Sharkey | 518bc9d | 2011-07-12 20:20:46 -0700 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | // otherwise fall back to using packagemanager labels |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1622 | final String[] packageNames = pm.getPackagesForUid(uid); |
| 1623 | final int length = packageNames != null ? packageNames.length : 0; |
| 1624 | |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1625 | try { |
| 1626 | if (length == 1) { |
| 1627 | final ApplicationInfo info = pm.getApplicationInfo(packageNames[0], 0); |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1628 | detail.label = info.loadLabel(pm).toString(); |
| 1629 | detail.icon = info.loadIcon(pm); |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1630 | } else if (length > 1) { |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1631 | detail.detailLabels = new CharSequence[length]; |
| 1632 | for (int i = 0; i < length; i++) { |
| 1633 | final String packageName = packageNames[i]; |
| 1634 | final PackageInfo packageInfo = pm.getPackageInfo(packageName, 0); |
| 1635 | final ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0); |
| 1636 | |
| 1637 | detail.detailLabels[i] = appInfo.loadLabel(pm).toString(); |
| 1638 | if (packageInfo.sharedUserLabel != 0) { |
| 1639 | detail.label = pm.getText(packageName, packageInfo.sharedUserLabel, |
| 1640 | packageInfo.applicationInfo).toString(); |
| 1641 | detail.icon = appInfo.loadIcon(pm); |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | } catch (NameNotFoundException e) { |
| 1646 | } |
| 1647 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1648 | if (TextUtils.isEmpty(detail.label)) { |
| 1649 | detail.label = Integer.toString(uid); |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1650 | } |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1651 | return detail; |
Jeff Sharkey | 8e911d7 | 2011-06-14 22:41:21 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1654 | /** |
| 1655 | * Test if device has a mobile data radio. |
| 1656 | */ |
| 1657 | private static boolean hasMobileRadio(Context context) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1658 | if (TEST_RADIOS) { |
| 1659 | return SystemProperties.get(TEST_RADIOS_PROP).contains("mobile"); |
| 1660 | } |
| 1661 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1662 | final ConnectivityManager conn = (ConnectivityManager) context.getSystemService( |
| 1663 | Context.CONNECTIVITY_SERVICE); |
| 1664 | |
| 1665 | // mobile devices should have MOBILE network tracker regardless of |
| 1666 | // connection status. |
| 1667 | return conn.getNetworkInfo(TYPE_MOBILE) != null; |
| 1668 | } |
| 1669 | |
| 1670 | /** |
| 1671 | * Test if device has a mobile 4G data radio. |
| 1672 | */ |
| 1673 | private static boolean hasMobile4gRadio(Context context) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1674 | if (TEST_RADIOS) { |
| 1675 | return SystemProperties.get(TEST_RADIOS_PROP).contains("4g"); |
| 1676 | } |
| 1677 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1678 | final ConnectivityManager conn = (ConnectivityManager) context.getSystemService( |
| 1679 | Context.CONNECTIVITY_SERVICE); |
| 1680 | final TelephonyManager telephony = (TelephonyManager) context.getSystemService( |
| 1681 | Context.TELEPHONY_SERVICE); |
| 1682 | |
| 1683 | // WiMAX devices should have WiMAX network tracker regardless of |
| 1684 | // connection status. |
| 1685 | final boolean hasWimax = conn.getNetworkInfo(TYPE_WIMAX) != null; |
| 1686 | final boolean hasLte = telephony.getLteOnCdmaMode() == Phone.LTE_ON_CDMA_TRUE; |
| 1687 | return hasWimax || hasLte; |
| 1688 | } |
| 1689 | |
| 1690 | /** |
| 1691 | * Test if device has a Wi-Fi data radio. |
| 1692 | */ |
| 1693 | private static boolean hasWifiRadio(Context context) { |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1694 | if (TEST_RADIOS) { |
| 1695 | return SystemProperties.get(TEST_RADIOS_PROP).contains("wifi"); |
| 1696 | } |
| 1697 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1698 | return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI); |
| 1699 | } |
| 1700 | |
| 1701 | /** |
Jeff Sharkey | 9549e9f | 2011-07-14 20:01:13 -0700 | [diff] [blame] | 1702 | * Test if device has an ethernet network connection. |
| 1703 | */ |
| 1704 | private static boolean hasEthernet(Context context) { |
| 1705 | if (TEST_RADIOS) { |
| 1706 | return SystemProperties.get(TEST_RADIOS_PROP).contains("ethernet"); |
| 1707 | } |
| 1708 | |
| 1709 | final ConnectivityManager conn = (ConnectivityManager) context.getSystemService( |
| 1710 | Context.CONNECTIVITY_SERVICE); |
| 1711 | return conn.getNetworkInfo(TYPE_ETHERNET) != null; |
| 1712 | } |
| 1713 | |
| 1714 | /** |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1715 | * Inflate a {@link Preference} style layout, adding the given {@link View} |
| 1716 | * widget into {@link android.R.id#widget_frame}. |
| 1717 | */ |
| 1718 | private static View inflatePreference(LayoutInflater inflater, ViewGroup root, View widget) { |
| 1719 | final View view = inflater.inflate(R.layout.preference, root, false); |
| 1720 | final LinearLayout widgetFrame = (LinearLayout) view.findViewById( |
| 1721 | android.R.id.widget_frame); |
| 1722 | widgetFrame.addView(widget, new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); |
| 1723 | return view; |
| 1724 | } |
| 1725 | |
Jeff Sharkey | d39c6e4 | 2011-08-04 21:17:23 -0700 | [diff] [blame] | 1726 | private static View inflateAppTitle( |
| 1727 | LayoutInflater inflater, ViewGroup root, CharSequence label) { |
| 1728 | final TextView view = (TextView) inflater.inflate( |
| 1729 | R.layout.data_usage_app_title, root, false); |
| 1730 | view.setText(label); |
| 1731 | return view; |
| 1732 | } |
| 1733 | |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1734 | /** |
| 1735 | * Set {@link android.R.id#title} for a preference view inflated with |
Jeff Sharkey | 52c3f44 | 2011-06-23 00:39:38 -0700 | [diff] [blame] | 1736 | * {@link #inflatePreference(LayoutInflater, ViewGroup, View)}. |
Jeff Sharkey | 29d56b3 | 2011-06-20 17:06:52 -0700 | [diff] [blame] | 1737 | */ |
| 1738 | private static void setPreferenceTitle(View parent, int resId) { |
| 1739 | final TextView title = (TextView) parent.findViewById(android.R.id.title); |
| 1740 | title.setText(resId); |
| 1741 | } |
| 1742 | |
Jeff Sharkey | f54f435 | 2011-06-23 22:15:54 -0700 | [diff] [blame] | 1743 | /** |
| 1744 | * Set {@link android.R.id#summary} for a preference view inflated with |
| 1745 | * {@link #inflatePreference(LayoutInflater, ViewGroup, View)}. |
| 1746 | */ |
| 1747 | private static void setPreferenceSummary(View parent, int resId) { |
| 1748 | final TextView summary = (TextView) parent.findViewById(android.R.id.summary); |
| 1749 | summary.setVisibility(View.VISIBLE); |
| 1750 | summary.setText(resId); |
| 1751 | } |
Jeff Sharkey | ab2d8d3 | 2011-05-30 16:19:56 -0700 | [diff] [blame] | 1752 | } |