The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 19 | import android.accounts.Account; |
| 20 | import android.accounts.AccountManager; |
| 21 | import android.accounts.OnAccountsUpdateListener; |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 22 | import android.app.admin.DevicePolicyManager; |
Jaewan Kim | a3fe77b | 2013-06-04 21:17:40 +0900 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 24 | import android.content.ComponentName; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 25 | import android.content.Context; |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 26 | import android.content.Intent; |
Jaewan Kim | a3fe77b | 2013-06-04 21:17:40 +0900 | [diff] [blame] | 27 | import android.content.IntentFilter; |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 28 | import android.content.SharedPreferences; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 29 | import android.content.pm.ActivityInfo; |
Christopher Tate | e238a47 | 2013-08-27 14:21:46 -0700 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
| 32 | import android.content.pm.PackageManager.NameNotFoundException; |
Christopher Tate | e238a47 | 2013-08-27 14:21:46 -0700 | [diff] [blame] | 33 | import android.content.pm.ResolveInfo; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 34 | import android.graphics.drawable.Drawable; |
Martijn Coenen | 81ab817 | 2013-09-30 12:07:02 -0700 | [diff] [blame^] | 35 | import android.nfc.NfcAdapter; |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 36 | import android.os.Bundle; |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 37 | import android.os.INetworkManagementService; |
| 38 | import android.os.RemoteException; |
| 39 | import android.os.ServiceManager; |
Dianne Hackborn | bb06a42 | 2012-08-16 11:01:57 -0700 | [diff] [blame] | 40 | import android.os.UserHandle; |
Jeff Sharkey | 4420246 | 2012-09-19 13:13:45 -0700 | [diff] [blame] | 41 | import android.os.UserManager; |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 42 | import android.preference.Preference; |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 43 | import android.preference.PreferenceActivity; |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 44 | import android.preference.PreferenceFragment; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 45 | import android.text.TextUtils; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 46 | import android.util.Log; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 47 | import android.view.LayoutInflater; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 48 | import android.view.View; |
| 49 | import android.view.View.OnClickListener; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 50 | import android.view.ViewGroup; |
| 51 | import android.widget.ArrayAdapter; |
Amith Yamasani | 9e3a470 | 2011-01-11 09:09:26 -0800 | [diff] [blame] | 52 | import android.widget.Button; |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 53 | import android.widget.ImageButton; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 54 | import android.widget.ImageView; |
| 55 | import android.widget.ListAdapter; |
| 56 | import android.widget.Switch; |
| 57 | import android.widget.TextView; |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 58 | |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 59 | import com.android.internal.util.ArrayUtils; |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 60 | import com.android.settings.accessibility.AccessibilitySettings; |
Alan Viverette | 341ff66 | 2013-07-18 17:49:33 -0700 | [diff] [blame] | 61 | import com.android.settings.accessibility.ToggleAccessibilityServicePreferenceFragment; |
Alan Viverette | 9b625f0 | 2013-09-11 13:03:14 -0700 | [diff] [blame] | 62 | import com.android.settings.accessibility.ToggleCaptioningPreferenceFragment; |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 63 | import com.android.settings.accounts.AccountSyncSettings; |
| 64 | import com.android.settings.accounts.AuthenticatorHelper; |
| 65 | import com.android.settings.accounts.ManageAccountsSettings; |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 66 | import com.android.settings.applications.AppOpsSummary; |
| 67 | import com.android.settings.applications.ManageApplications; |
Dianne Hackborn | c6d658e | 2013-08-08 12:57:53 -0700 | [diff] [blame] | 68 | import com.android.settings.applications.ProcessStatsUi; |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 69 | import com.android.settings.bluetooth.BluetoothEnabler; |
| 70 | import com.android.settings.bluetooth.BluetoothSettings; |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 71 | import com.android.settings.deviceinfo.Memory; |
| 72 | import com.android.settings.deviceinfo.UsbSettings; |
| 73 | import com.android.settings.fuelgauge.PowerUsageSummary; |
| 74 | import com.android.settings.inputmethod.InputMethodAndLanguageSettings; |
Amith Yamasani | 3a14ae2 | 2013-08-30 15:43:44 -0700 | [diff] [blame] | 75 | import com.android.settings.inputmethod.KeyboardLayoutPickerFragment; |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 76 | import com.android.settings.inputmethod.SpellCheckersSettings; |
| 77 | import com.android.settings.inputmethod.UserDictionaryList; |
Amith Yamasani | e990420 | 2013-08-01 10:26:14 -0700 | [diff] [blame] | 78 | import com.android.settings.location.LocationSettings; |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 79 | import com.android.settings.nfc.AndroidBeam; |
Martijn Coenen | 53083ab | 2013-08-09 13:37:38 -0700 | [diff] [blame] | 80 | import com.android.settings.nfc.PaymentSettings; |
Svetoslav | 2d53165 | 2013-09-03 21:32:40 -0700 | [diff] [blame] | 81 | import com.android.settings.print.PrintServiceSettingsFragment; |
| 82 | import com.android.settings.print.PrintSettingsFragment; |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 83 | import com.android.settings.tts.TextToSpeechSettings; |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 84 | import com.android.settings.users.UserSettings; |
| 85 | import com.android.settings.vpn2.VpnSettings; |
Jeff Sharkey | 0c3634c | 2013-02-20 12:35:16 -0800 | [diff] [blame] | 86 | import com.android.settings.wfd.WifiDisplaySettings; |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 87 | import com.android.settings.wifi.AdvancedWifiSettings; |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 88 | import com.android.settings.wifi.WifiEnabler; |
| 89 | import com.android.settings.wifi.WifiSettings; |
| 90 | import com.android.settings.wifi.p2p.WifiP2pSettings; |
| 91 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 92 | import java.util.ArrayList; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 93 | import java.util.Collections; |
| 94 | import java.util.Comparator; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 95 | import java.util.HashMap; |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 96 | import java.util.List; |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Top-level settings activity to handle single pane and double pane UI layout. |
| 100 | */ |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 101 | public class Settings extends PreferenceActivity |
| 102 | implements ButtonBarHandler, OnAccountsUpdateListener { |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 103 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 104 | private static final String LOG_TAG = "Settings"; |
Amith Yamasani | ea7b28c | 2012-06-20 13:51:40 -0700 | [diff] [blame] | 105 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 106 | private static final String META_DATA_KEY_HEADER_ID = |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 107 | "com.android.settings.TOP_LEVEL_HEADER_ID"; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 108 | private static final String META_DATA_KEY_FRAGMENT_CLASS = |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 109 | "com.android.settings.FRAGMENT_CLASS"; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 110 | private static final String META_DATA_KEY_PARENT_TITLE = |
| 111 | "com.android.settings.PARENT_FRAGMENT_TITLE"; |
| 112 | private static final String META_DATA_KEY_PARENT_FRAGMENT_CLASS = |
| 113 | "com.android.settings.PARENT_FRAGMENT_CLASS"; |
| 114 | |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 115 | private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 116 | |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 117 | private static final String SAVE_KEY_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER"; |
| 118 | private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_HEADER"; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 119 | |
| 120 | private String mFragmentClass; |
| 121 | private int mTopLevelHeaderId; |
Amith Yamasani | 3965ae6 | 2010-11-15 14:45:19 -0800 | [diff] [blame] | 122 | private Header mFirstHeader; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 123 | private Header mCurrentHeader; |
| 124 | private Header mParentHeader; |
| 125 | private boolean mInLocalHeaderSwitch; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 126 | |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 127 | // Show only these settings for restricted users |
| 128 | private int[] SETTINGS_FOR_RESTRICTED = { |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 129 | R.id.wireless_section, |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 130 | R.id.wifi_settings, |
| 131 | R.id.bluetooth_settings, |
Jeff Sharkey | 38305fb | 2012-09-14 16:26:51 -0700 | [diff] [blame] | 132 | R.id.data_usage_settings, |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 133 | R.id.wireless_settings, |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 134 | R.id.device_section, |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 135 | R.id.sound_settings, |
| 136 | R.id.display_settings, |
Jeff Sharkey | 90c8b20 | 2012-08-30 15:20:10 -0700 | [diff] [blame] | 137 | R.id.storage_settings, |
Dianne Hackborn | 271c8b0 | 2012-08-20 17:24:39 -0700 | [diff] [blame] | 138 | R.id.application_settings, |
Dianne Hackborn | 52e56a2 | 2012-09-12 17:02:23 -0700 | [diff] [blame] | 139 | R.id.battery_settings, |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 140 | R.id.personal_section, |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 141 | R.id.location_settings, |
Amith Yamasani | 3deeeb7 | 2012-04-05 14:44:48 -0700 | [diff] [blame] | 142 | R.id.security_settings, |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 143 | R.id.language_settings, |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 144 | R.id.user_settings, |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 145 | R.id.account_settings, |
Amith Yamasani | 3263039 | 2012-08-10 19:31:39 -0700 | [diff] [blame] | 146 | R.id.account_add, |
| 147 | R.id.system_section, |
Amith Yamasani | 9627a8e | 2012-09-23 12:54:14 -0700 | [diff] [blame] | 148 | R.id.date_time_settings, |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 149 | R.id.about_settings, |
Svetoslav Ganov | d4c7b49 | 2013-06-11 21:15:11 -0700 | [diff] [blame] | 150 | R.id.accessibility_settings, |
Martijn Coenen | 26515da | 2013-08-01 18:13:33 -0700 | [diff] [blame] | 151 | R.id.print_settings, |
Christopher Tate | e238a47 | 2013-08-27 14:21:46 -0700 | [diff] [blame] | 152 | R.id.nfc_payment_settings, |
| 153 | R.id.home_settings |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 156 | private SharedPreferences mDevelopmentPreferences; |
| 157 | private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; |
| 158 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 159 | // TODO: Update Call Settings based on airplane mode state. |
Amith Yamasani | b61cf51 | 2010-09-12 08:17:50 -0700 | [diff] [blame] | 160 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 161 | protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>(); |
| 162 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 163 | private AuthenticatorHelper mAuthenticatorHelper; |
| 164 | private Header mLastHeader; |
Amith Yamasani | 86708a8 | 2012-06-06 20:23:08 -0700 | [diff] [blame] | 165 | private boolean mListeningToAccountUpdates; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 166 | |
Jaewan Kim | a3fe77b | 2013-06-04 21:17:40 +0900 | [diff] [blame] | 167 | private boolean mBatteryPresent = true; |
| 168 | private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { |
| 169 | |
| 170 | @Override |
| 171 | public void onReceive(Context context, Intent intent) { |
| 172 | String action = intent.getAction(); |
| 173 | if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 174 | boolean batteryPresent = Utils.isBatteryPresent(intent); |
| 175 | |
| 176 | if (mBatteryPresent != batteryPresent) { |
| 177 | mBatteryPresent = batteryPresent; |
| 178 | invalidateHeaders(); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | }; |
| 183 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 184 | @Override |
| 185 | protected void onCreate(Bundle savedInstanceState) { |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 186 | if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) { |
| 187 | getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0)); |
Jeff Sharkey | 54d0af5 | 2011-08-11 18:26:57 -0700 | [diff] [blame] | 188 | } |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 189 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 190 | mAuthenticatorHelper = new AuthenticatorHelper(); |
| 191 | mAuthenticatorHelper.updateAuthDescriptions(this); |
| 192 | mAuthenticatorHelper.onAccountsUpdated(this, null); |
| 193 | |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 194 | mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, |
| 195 | Context.MODE_PRIVATE); |
| 196 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 197 | getMetaData(); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 198 | mInLocalHeaderSwitch = true; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 199 | super.onCreate(savedInstanceState); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 200 | mInLocalHeaderSwitch = false; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 201 | |
Gilles Debunne | 3661b62 | 2011-06-27 11:19:16 -0700 | [diff] [blame] | 202 | if (!onIsHidingHeaders() && onIsMultiPane()) { |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 203 | highlightHeader(mTopLevelHeaderId); |
Amith Yamasani | 72aa19d | 2010-12-09 06:07:12 -0800 | [diff] [blame] | 204 | // Force the title so that it doesn't get overridden by a direct launch of |
| 205 | // a specific settings screen. |
| 206 | setTitle(R.string.settings_label); |
| 207 | } |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 208 | |
| 209 | // Retrieve any saved state |
| 210 | if (savedInstanceState != null) { |
| 211 | mCurrentHeader = savedInstanceState.getParcelable(SAVE_KEY_CURRENT_HEADER); |
| 212 | mParentHeader = savedInstanceState.getParcelable(SAVE_KEY_PARENT_HEADER); |
| 213 | } |
| 214 | |
| 215 | // If the current header was saved, switch to it |
| 216 | if (savedInstanceState != null && mCurrentHeader != null) { |
| 217 | //switchToHeaderLocal(mCurrentHeader); |
| 218 | showBreadCrumbs(mCurrentHeader.title, null); |
| 219 | } |
| 220 | |
| 221 | if (mParentHeader != null) { |
| 222 | setParentTitle(mParentHeader.title, null, new OnClickListener() { |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 223 | @Override |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 224 | public void onClick(View v) { |
| 225 | switchToParent(mParentHeader.fragment); |
| 226 | } |
| 227 | }); |
| 228 | } |
Gilles Debunne | dc7101f | 2011-06-27 12:00:49 -0700 | [diff] [blame] | 229 | |
Amith Yamasani | 3d384f4 | 2012-05-11 15:22:04 -0700 | [diff] [blame] | 230 | // Override up navigation for multi-pane, since we handle it in the fragment breadcrumbs |
| 231 | if (onIsMultiPane()) { |
| 232 | getActionBar().setDisplayHomeAsUpEnabled(false); |
| 233 | getActionBar().setHomeButtonEnabled(false); |
| 234 | } |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | @Override |
| 238 | protected void onSaveInstanceState(Bundle outState) { |
| 239 | super.onSaveInstanceState(outState); |
| 240 | |
| 241 | // Save the current fragment, if it is the same as originally launched |
| 242 | if (mCurrentHeader != null) { |
| 243 | outState.putParcelable(SAVE_KEY_CURRENT_HEADER, mCurrentHeader); |
| 244 | } |
| 245 | if (mParentHeader != null) { |
| 246 | outState.putParcelable(SAVE_KEY_PARENT_HEADER, mParentHeader); |
| 247 | } |
| 248 | } |
| 249 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 250 | @Override |
| 251 | public void onResume() { |
| 252 | super.onResume(); |
| 253 | |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 254 | mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { |
| 255 | @Override |
| 256 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
| 257 | invalidateHeaders(); |
| 258 | } |
| 259 | }; |
| 260 | mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( |
| 261 | mDevelopmentPreferencesListener); |
| 262 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 263 | ListAdapter listAdapter = getListAdapter(); |
| 264 | if (listAdapter instanceof HeaderAdapter) { |
| 265 | ((HeaderAdapter) listAdapter).resume(); |
| 266 | } |
Amith Yamasani | ea7b28c | 2012-06-20 13:51:40 -0700 | [diff] [blame] | 267 | invalidateHeaders(); |
Jaewan Kim | a3fe77b | 2013-06-04 21:17:40 +0900 | [diff] [blame] | 268 | |
| 269 | registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | @Override |
| 273 | public void onPause() { |
| 274 | super.onPause(); |
| 275 | |
Jaewan Kim | a3fe77b | 2013-06-04 21:17:40 +0900 | [diff] [blame] | 276 | unregisterReceiver(mBatteryInfoReceiver); |
| 277 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 278 | ListAdapter listAdapter = getListAdapter(); |
| 279 | if (listAdapter instanceof HeaderAdapter) { |
| 280 | ((HeaderAdapter) listAdapter).pause(); |
Amith Yamasani | 86708a8 | 2012-06-06 20:23:08 -0700 | [diff] [blame] | 281 | } |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 282 | |
| 283 | mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( |
| 284 | mDevelopmentPreferencesListener); |
| 285 | mDevelopmentPreferencesListener = null; |
Amith Yamasani | 86708a8 | 2012-06-06 20:23:08 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | @Override |
| 289 | public void onDestroy() { |
| 290 | super.onDestroy(); |
| 291 | if (mListeningToAccountUpdates) { |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 292 | AccountManager.get(this).removeOnAccountsUpdatedListener(this); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Amith Yamasani | 56f51a8 | 2013-08-05 10:07:23 -0700 | [diff] [blame] | 296 | @Override |
| 297 | public boolean onIsMultiPane() { |
| 298 | return false; |
| 299 | } |
| 300 | |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 301 | private static final String[] ENTRY_FRAGMENTS = { |
| 302 | WirelessSettings.class.getName(), |
| 303 | WifiSettings.class.getName(), |
| 304 | AdvancedWifiSettings.class.getName(), |
| 305 | BluetoothSettings.class.getName(), |
| 306 | TetherSettings.class.getName(), |
| 307 | WifiP2pSettings.class.getName(), |
| 308 | VpnSettings.class.getName(), |
| 309 | DateTimeSettings.class.getName(), |
| 310 | LocalePicker.class.getName(), |
| 311 | InputMethodAndLanguageSettings.class.getName(), |
| 312 | SpellCheckersSettings.class.getName(), |
| 313 | UserDictionaryList.class.getName(), |
| 314 | UserDictionarySettings.class.getName(), |
| 315 | SoundSettings.class.getName(), |
| 316 | DisplaySettings.class.getName(), |
| 317 | DeviceInfoSettings.class.getName(), |
| 318 | ManageApplications.class.getName(), |
Dianne Hackborn | c6d658e | 2013-08-08 12:57:53 -0700 | [diff] [blame] | 319 | ProcessStatsUi.class.getName(), |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 320 | NotificationStation.class.getName(), |
| 321 | AppOpsSummary.class.getName(), |
| 322 | LocationSettings.class.getName(), |
| 323 | SecuritySettings.class.getName(), |
| 324 | PrivacySettings.class.getName(), |
| 325 | DeviceAdminSettings.class.getName(), |
| 326 | AccessibilitySettings.class.getName(), |
Alan Viverette | 9b625f0 | 2013-09-11 13:03:14 -0700 | [diff] [blame] | 327 | ToggleCaptioningPreferenceFragment.class.getName(), |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 328 | TextToSpeechSettings.class.getName(), |
| 329 | Memory.class.getName(), |
| 330 | DevelopmentSettings.class.getName(), |
| 331 | UsbSettings.class.getName(), |
| 332 | AndroidBeam.class.getName(), |
| 333 | WifiDisplaySettings.class.getName(), |
| 334 | PowerUsageSummary.class.getName(), |
| 335 | AccountSyncSettings.class.getName(), |
| 336 | CryptKeeperSettings.class.getName(), |
| 337 | DataUsageSummary.class.getName(), |
| 338 | DreamSettings.class.getName(), |
| 339 | UserSettings.class.getName(), |
| 340 | NotificationAccessSettings.class.getName(), |
Amith Yamasani | ee226f9 | 2013-08-05 11:02:16 -0700 | [diff] [blame] | 341 | ManageAccountsSettings.class.getName(), |
Svetoslav | 2d53165 | 2013-09-03 21:32:40 -0700 | [diff] [blame] | 342 | PrintSettingsFragment.class.getName(), |
Martijn Coenen | 53083ab | 2013-08-09 13:37:38 -0700 | [diff] [blame] | 343 | TrustedCredentialsSettings.class.getName(), |
Amith Yamasani | 3a14ae2 | 2013-08-30 15:43:44 -0700 | [diff] [blame] | 344 | PaymentSettings.class.getName(), |
| 345 | KeyboardLayoutPickerFragment.class.getName() |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 346 | }; |
| 347 | |
| 348 | @Override |
| 349 | protected boolean isValidFragment(String fragmentName) { |
| 350 | // Almost all fragments are wrapped in this, |
| 351 | // except for a few that have their own activities. |
| 352 | for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { |
| 353 | if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; |
| 354 | } |
| 355 | return false; |
| 356 | } |
| 357 | |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 358 | private void switchToHeaderLocal(Header header) { |
| 359 | mInLocalHeaderSwitch = true; |
| 360 | switchToHeader(header); |
| 361 | mInLocalHeaderSwitch = false; |
| 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public void switchToHeader(Header header) { |
| 366 | if (!mInLocalHeaderSwitch) { |
| 367 | mCurrentHeader = null; |
| 368 | mParentHeader = null; |
| 369 | } |
| 370 | super.switchToHeader(header); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * Switch to parent fragment and store the grand parent's info |
Jake Hamby | 2748fc2 | 2011-01-12 15:06:28 -0800 | [diff] [blame] | 375 | * @param className name of the activity wrapper for the parent fragment. |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 376 | */ |
| 377 | private void switchToParent(String className) { |
| 378 | final ComponentName cn = new ComponentName(this, className); |
| 379 | try { |
| 380 | final PackageManager pm = getPackageManager(); |
| 381 | final ActivityInfo parentInfo = pm.getActivityInfo(cn, PackageManager.GET_META_DATA); |
| 382 | |
| 383 | if (parentInfo != null && parentInfo.metaData != null) { |
| 384 | String fragmentClass = parentInfo.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
| 385 | CharSequence fragmentTitle = parentInfo.loadLabel(pm); |
| 386 | Header parentHeader = new Header(); |
| 387 | parentHeader.fragment = fragmentClass; |
| 388 | parentHeader.title = fragmentTitle; |
| 389 | mCurrentHeader = parentHeader; |
| 390 | |
| 391 | switchToHeaderLocal(parentHeader); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 392 | highlightHeader(mTopLevelHeaderId); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 393 | |
| 394 | mParentHeader = new Header(); |
| 395 | mParentHeader.fragment |
| 396 | = parentInfo.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS); |
| 397 | mParentHeader.title = parentInfo.metaData.getString(META_DATA_KEY_PARENT_TITLE); |
| 398 | } |
| 399 | } catch (NameNotFoundException nnfe) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 400 | Log.w(LOG_TAG, "Could not find parent activity : " + className); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 401 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Amith Yamasani | 3965ae6 | 2010-11-15 14:45:19 -0800 | [diff] [blame] | 404 | @Override |
| 405 | public void onNewIntent(Intent intent) { |
| 406 | super.onNewIntent(intent); |
| 407 | |
| 408 | // If it is not launched from history, then reset to top-level |
Amith Yamasani | ef61723 | 2012-10-09 16:57:25 -0700 | [diff] [blame] | 409 | if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == 0) { |
| 410 | if (mFirstHeader != null && !onIsHidingHeaders() && onIsMultiPane()) { |
| 411 | switchToHeaderLocal(mFirstHeader); |
| 412 | } |
| 413 | getListView().setSelectionFromTop(0, 0); |
Amith Yamasani | 3965ae6 | 2010-11-15 14:45:19 -0800 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 417 | private void highlightHeader(int id) { |
| 418 | if (id != 0) { |
| 419 | Integer index = mHeaderIndexMap.get(id); |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 420 | if (index != null) { |
| 421 | getListView().setItemChecked(index, true); |
Amith Yamasani | ef61723 | 2012-10-09 16:57:25 -0700 | [diff] [blame] | 422 | if (isMultiPane()) { |
| 423 | getListView().smoothScrollToPosition(index); |
| 424 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 429 | @Override |
| 430 | public Intent getIntent() { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 431 | Intent superIntent = super.getIntent(); |
| 432 | String startingFragment = getStartingFragmentClass(superIntent); |
Gilles Debunne | 3661b62 | 2011-06-27 11:19:16 -0700 | [diff] [blame] | 433 | // This is called from super.onCreate, isMultiPane() is not yet reliable |
| 434 | // Do not use onIsHidingHeaders either, which relies itself on this method |
| 435 | if (startingFragment != null && !onIsMultiPane()) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 436 | Intent modIntent = new Intent(superIntent); |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 437 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 438 | Bundle args = superIntent.getExtras(); |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 439 | if (args != null) { |
| 440 | args = new Bundle(args); |
| 441 | } else { |
| 442 | args = new Bundle(); |
| 443 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 444 | args.putParcelable("intent", superIntent); |
| 445 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, superIntent.getExtras()); |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 446 | return modIntent; |
| 447 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 448 | return superIntent; |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 451 | /** |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 452 | * Checks if the component name in the intent is different from the Settings class and |
| 453 | * returns the class name to load as a fragment. |
| 454 | */ |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 455 | protected String getStartingFragmentClass(Intent intent) { |
| 456 | if (mFragmentClass != null) return mFragmentClass; |
| 457 | |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 458 | String intentClass = intent.getComponent().getClassName(); |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 459 | if (intentClass.equals(getClass().getName())) return null; |
| 460 | |
Dianne Hackborn | ee29379 | 2010-11-01 12:32:33 -0700 | [diff] [blame] | 461 | if ("com.android.settings.ManageApplications".equals(intentClass) |
| 462 | || "com.android.settings.RunningServices".equals(intentClass) |
| 463 | || "com.android.settings.applications.StorageUse".equals(intentClass)) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 464 | // Old names of manage apps. |
Dianne Hackborn | f4eb85b | 2010-10-29 16:53:04 -0700 | [diff] [blame] | 465 | intentClass = com.android.settings.applications.ManageApplications.class.getName(); |
| 466 | } |
| 467 | |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 468 | return intentClass; |
| 469 | } |
| 470 | |
| 471 | /** |
| 472 | * Override initial header when an activity-alias is causing Settings to be launched |
| 473 | * for a specific fragment encoded in the android:name parameter. |
| 474 | */ |
| 475 | @Override |
| 476 | public Header onGetInitialHeader() { |
| 477 | String fragmentClass = getStartingFragmentClass(super.getIntent()); |
| 478 | if (fragmentClass != null) { |
| 479 | Header header = new Header(); |
| 480 | header.fragment = fragmentClass; |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 481 | header.title = getTitle(); |
Amith Yamasani | e0e4fc2 | 2010-10-05 11:49:51 -0700 | [diff] [blame] | 482 | header.fragmentArguments = getIntent().getExtras(); |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 483 | mCurrentHeader = header; |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 484 | return header; |
| 485 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 486 | |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 487 | return mFirstHeader; |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Dianne Hackborn | b725818 | 2011-03-15 16:23:55 -0700 | [diff] [blame] | 490 | @Override |
Dianne Hackborn | 48147dc | 2011-03-18 12:29:41 -0700 | [diff] [blame] | 491 | public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args, |
| 492 | int titleRes, int shortTitleRes) { |
| 493 | Intent intent = super.onBuildStartFragmentIntent(fragmentName, args, |
| 494 | titleRes, shortTitleRes); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 495 | |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 496 | // Some fragments want split ActionBar; these should stay in sync with |
| 497 | // uiOptions for fragments also defined as activities in manifest. |
| 498 | if (WifiSettings.class.getName().equals(fragmentName) || |
| 499 | WifiP2pSettings.class.getName().equals(fragmentName) || |
Jeff Sharkey | 0c3634c | 2013-02-20 12:35:16 -0800 | [diff] [blame] | 500 | WifiDisplaySettings.class.getName().equals(fragmentName) || |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 501 | BluetoothSettings.class.getName().equals(fragmentName) || |
| 502 | DreamSettings.class.getName().equals(fragmentName) || |
Lifu Tang | d5fbbc4 | 2013-08-01 17:23:10 -0700 | [diff] [blame] | 503 | LocationSettings.class.getName().equals(fragmentName) || |
Svetoslav | 2d53165 | 2013-09-03 21:32:40 -0700 | [diff] [blame] | 504 | ToggleAccessibilityServicePreferenceFragment.class.getName().equals(fragmentName) || |
| 505 | PrintSettingsFragment.class.getName().equals(fragmentName) || |
| 506 | PrintServiceSettingsFragment.class.getName().equals(fragmentName)) { |
Jeff Sharkey | cc0d26b | 2012-11-27 16:42:27 -0800 | [diff] [blame] | 507 | intent.putExtra(EXTRA_UI_OPTIONS, ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); |
Jeff Sharkey | 9fab0da | 2011-07-09 17:52:31 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Dianne Hackborn | b725818 | 2011-03-15 16:23:55 -0700 | [diff] [blame] | 510 | intent.setClass(this, SubSettings.class); |
| 511 | return intent; |
| 512 | } |
Amith Yamasani | ea7b28c | 2012-06-20 13:51:40 -0700 | [diff] [blame] | 513 | |
Amith Yamasani | 379d9b0 | 2010-09-27 12:03:59 -0700 | [diff] [blame] | 514 | /** |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 515 | * Populate the activity with the top-level headers. |
| 516 | */ |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 517 | @Override |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 518 | public void onBuildHeaders(List<Header> headers) { |
| 519 | loadHeadersFromResource(R.xml.settings_headers, headers); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 520 | updateHeaderList(headers); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 521 | } |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 522 | |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 523 | private void updateHeaderList(List<Header> target) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 524 | final boolean showDev = mDevelopmentPreferences.getBoolean( |
| 525 | DevelopmentSettings.PREF_SHOW, |
| 526 | android.os.Build.TYPE.equals("eng")); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 527 | int i = 0; |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 528 | |
| 529 | final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 530 | mHeaderIndexMap.clear(); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 531 | while (i < target.size()) { |
| 532 | Header header = target.get(i); |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 533 | // Ids are integers, so downcasting |
| 534 | int id = (int) header.id; |
Chris Wren | 2bc32ae | 2012-09-24 14:23:46 -0400 | [diff] [blame] | 535 | if (id == R.id.operator_settings || id == R.id.manufacturer_settings) { |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 536 | Utils.updateHeaderToSpecificActivityFromMetaDataOrRemove(this, target, header); |
Gilles Debunne | 2454f49 | 2011-06-21 16:16:06 -0700 | [diff] [blame] | 537 | } else if (id == R.id.wifi_settings) { |
| 538 | // Remove WiFi Settings if WiFi service is not available. |
| 539 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 540 | target.remove(i); |
Gilles Debunne | 2454f49 | 2011-06-21 16:16:06 -0700 | [diff] [blame] | 541 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 542 | } else if (id == R.id.bluetooth_settings) { |
| 543 | // Remove Bluetooth Settings if Bluetooth service is not available. |
Gilles Debunne | 2454f49 | 2011-06-21 16:16:06 -0700 | [diff] [blame] | 544 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 545 | target.remove(i); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 546 | } |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 547 | } else if (id == R.id.data_usage_settings) { |
| 548 | // Remove data usage when kernel module not enabled |
| 549 | final INetworkManagementService netManager = INetworkManagementService.Stub |
| 550 | .asInterface(ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE)); |
| 551 | try { |
| 552 | if (!netManager.isBandwidthControlEnabled()) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 553 | target.remove(i); |
Jeff Sharkey | 34e964d | 2012-04-21 15:41:48 -0700 | [diff] [blame] | 554 | } |
| 555 | } catch (RemoteException e) { |
| 556 | // ignored |
| 557 | } |
Jaewan Kim | a3fe77b | 2013-06-04 21:17:40 +0900 | [diff] [blame] | 558 | } else if (id == R.id.battery_settings) { |
| 559 | // Remove battery settings when battery is not available. (e.g. TV) |
| 560 | |
| 561 | if (!mBatteryPresent) { |
| 562 | target.remove(i); |
| 563 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 564 | } else if (id == R.id.account_settings) { |
| 565 | int headerIndex = i + 1; |
| 566 | i = insertAccountsHeaders(target, headerIndex); |
Christopher Tate | e238a47 | 2013-08-27 14:21:46 -0700 | [diff] [blame] | 567 | } else if (id == R.id.home_settings) { |
Christopher Tate | 8243c9a | 2013-09-19 14:59:17 -0700 | [diff] [blame] | 568 | if (!updateHomeSettingHeaders(header)) { |
| 569 | target.remove(i); |
| 570 | } |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 571 | } else if (id == R.id.user_settings) { |
Amith Yamasani | dc6bfa6 | 2012-09-06 18:04:06 -0700 | [diff] [blame] | 572 | if (!UserHandle.MU_ENABLED |
Jeff Sharkey | 4420246 | 2012-09-19 13:13:45 -0700 | [diff] [blame] | 573 | || !UserManager.supportsMultipleUsers() |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 574 | || Utils.isMonkeyRunning()) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 575 | target.remove(i); |
| 576 | } |
Martijn Coenen | 26515da | 2013-08-01 18:13:33 -0700 | [diff] [blame] | 577 | } else if (id == R.id.nfc_payment_settings) { |
Martijn Coenen | 81ab817 | 2013-09-30 12:07:02 -0700 | [diff] [blame^] | 578 | if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) { |
Martijn Coenen | 26515da | 2013-08-01 18:13:33 -0700 | [diff] [blame] | 579 | target.remove(i); |
Martijn Coenen | 81ab817 | 2013-09-30 12:07:02 -0700 | [diff] [blame^] | 580 | } else { |
| 581 | // Only show if NFC is on and we have the HCE feature |
| 582 | NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); |
| 583 | if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature( |
| 584 | PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) { |
| 585 | target.remove(i); |
| 586 | } |
Martijn Coenen | 26515da | 2013-08-01 18:13:33 -0700 | [diff] [blame] | 587 | } |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 588 | } else if (id == R.id.development_settings) { |
| 589 | if (!showDev) { |
| 590 | target.remove(i); |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 591 | } |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 592 | } else if (id == R.id.account_add) { |
| 593 | if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) { |
| 594 | target.remove(i); |
| 595 | } |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 596 | } |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 597 | |
Jaewan Kim | bb0e621 | 2013-02-04 15:36:17 +0900 | [diff] [blame] | 598 | if (i < target.size() && target.get(i) == header |
Amith Yamasani | b99f864 | 2012-10-10 21:41:12 -0700 | [diff] [blame] | 599 | && UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 |
Amith Yamasani | b810a0d | 2012-03-25 10:12:26 -0700 | [diff] [blame] | 600 | && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, id)) { |
Dianne Hackborn | caefa9b | 2012-10-10 15:05:42 -0700 | [diff] [blame] | 601 | target.remove(i); |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 602 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 603 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 604 | // Increment if the current one wasn't removed by the Utils code. |
Jaewan Kim | bb0e621 | 2013-02-04 15:36:17 +0900 | [diff] [blame] | 605 | if (i < target.size() && target.get(i) == header) { |
Amith Yamasani | 3965ae6 | 2010-11-15 14:45:19 -0800 | [diff] [blame] | 606 | // Hold on to the first header, when we need to reset to the top-level |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 607 | if (mFirstHeader == null && |
| 608 | HeaderAdapter.getHeaderType(header) != HeaderAdapter.HEADER_TYPE_CATEGORY) { |
| 609 | mFirstHeader = header; |
| 610 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 611 | mHeaderIndexMap.put(id, i); |
Amith Yamasani | 02cf71a | 2010-09-21 15:48:52 -0700 | [diff] [blame] | 612 | i++; |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 613 | } |
Amith Yamasani | d799347 | 2010-08-18 13:59:28 -0700 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 617 | private int insertAccountsHeaders(List<Header> target, int headerIndex) { |
| 618 | String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes(); |
| 619 | List<Header> accountHeaders = new ArrayList<Header>(accountTypes.length); |
| 620 | for (String accountType : accountTypes) { |
| 621 | CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType); |
Brian Muramatsu | c28af52 | 2012-06-28 14:25:14 -0700 | [diff] [blame] | 622 | if (label == null) { |
| 623 | continue; |
| 624 | } |
| 625 | |
Amith Yamasani | 3882c2e | 2012-06-07 17:03:20 -0700 | [diff] [blame] | 626 | Account[] accounts = AccountManager.get(this).getAccountsByType(accountType); |
| 627 | boolean skipToAccount = accounts.length == 1 |
| 628 | && !mAuthenticatorHelper.hasAccountPreferences(accountType); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 629 | Header accHeader = new Header(); |
| 630 | accHeader.title = label; |
| 631 | if (accHeader.extras == null) { |
| 632 | accHeader.extras = new Bundle(); |
| 633 | } |
Amith Yamasani | 3882c2e | 2012-06-07 17:03:20 -0700 | [diff] [blame] | 634 | if (skipToAccount) { |
| 635 | accHeader.breadCrumbTitleRes = R.string.account_sync_settings_title; |
| 636 | accHeader.breadCrumbShortTitleRes = R.string.account_sync_settings_title; |
| 637 | accHeader.fragment = AccountSyncSettings.class.getName(); |
| 638 | accHeader.fragmentArguments = new Bundle(); |
| 639 | // Need this for the icon |
| 640 | accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); |
| 641 | accHeader.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]); |
| 642 | accHeader.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY, |
| 643 | accounts[0]); |
| 644 | } else { |
| 645 | accHeader.breadCrumbTitle = label; |
| 646 | accHeader.breadCrumbShortTitle = label; |
| 647 | accHeader.fragment = ManageAccountsSettings.class.getName(); |
| 648 | accHeader.fragmentArguments = new Bundle(); |
| 649 | accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); |
| 650 | accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, |
| 651 | accountType); |
| 652 | if (!isMultiPane()) { |
| 653 | accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL, |
| 654 | label.toString()); |
| 655 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 656 | } |
| 657 | accountHeaders.add(accHeader); |
| 658 | } |
| 659 | |
| 660 | // Sort by label |
| 661 | Collections.sort(accountHeaders, new Comparator<Header>() { |
| 662 | @Override |
| 663 | public int compare(Header h1, Header h2) { |
| 664 | return h1.title.toString().compareTo(h2.title.toString()); |
| 665 | } |
| 666 | }); |
| 667 | |
| 668 | for (Header header : accountHeaders) { |
| 669 | target.add(headerIndex++, header); |
| 670 | } |
Amith Yamasani | 86708a8 | 2012-06-06 20:23:08 -0700 | [diff] [blame] | 671 | if (!mListeningToAccountUpdates) { |
| 672 | AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); |
| 673 | mListeningToAccountUpdates = true; |
| 674 | } |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 675 | return headerIndex; |
| 676 | } |
| 677 | |
Christopher Tate | 8243c9a | 2013-09-19 14:59:17 -0700 | [diff] [blame] | 678 | private boolean updateHomeSettingHeaders(Header header) { |
Christopher Tate | e238a47 | 2013-08-27 14:21:46 -0700 | [diff] [blame] | 679 | try { |
Jeff Sharkey | d572a03 | 2013-09-23 17:41:16 -0700 | [diff] [blame] | 680 | final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>(); |
| 681 | getPackageManager().getHomeActivities(homeApps); |
Christopher Tate | 8243c9a | 2013-09-19 14:59:17 -0700 | [diff] [blame] | 682 | if (homeApps.size() < 2) { |
| 683 | // When there's only one available home app, omit this settings |
| 684 | // category entirely at the top level UI. |
| 685 | return false; |
| 686 | } |
Christopher Tate | e238a47 | 2013-08-27 14:21:46 -0700 | [diff] [blame] | 687 | } catch (Exception e) { |
| 688 | // Can't look up the home activity; bail on configuring the icon |
| 689 | Log.w(LOG_TAG, "Problem looking up home activity!", e); |
| 690 | } |
Christopher Tate | 8243c9a | 2013-09-19 14:59:17 -0700 | [diff] [blame] | 691 | return true; |
Christopher Tate | e238a47 | 2013-08-27 14:21:46 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 694 | private void getMetaData() { |
| 695 | try { |
| 696 | ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), |
| 697 | PackageManager.GET_META_DATA); |
| 698 | if (ai == null || ai.metaData == null) return; |
| 699 | mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID); |
| 700 | mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 701 | |
Amith Yamasani | c9fdfa8 | 2010-12-14 14:38:16 -0800 | [diff] [blame] | 702 | // Check if it has a parent specified and create a Header object |
| 703 | final int parentHeaderTitleRes = ai.metaData.getInt(META_DATA_KEY_PARENT_TITLE); |
| 704 | String parentFragmentClass = ai.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS); |
| 705 | if (parentFragmentClass != null) { |
| 706 | mParentHeader = new Header(); |
| 707 | mParentHeader.fragment = parentFragmentClass; |
| 708 | if (parentHeaderTitleRes != 0) { |
| 709 | mParentHeader.title = getResources().getString(parentHeaderTitleRes); |
| 710 | } |
| 711 | } |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 712 | } catch (NameNotFoundException nnfe) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 713 | // No recovery |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 714 | } |
| 715 | } |
| 716 | |
Amith Yamasani | 9e3a470 | 2011-01-11 09:09:26 -0800 | [diff] [blame] | 717 | @Override |
| 718 | public boolean hasNextButton() { |
| 719 | return super.hasNextButton(); |
| 720 | } |
| 721 | |
| 722 | @Override |
| 723 | public Button getNextButton() { |
| 724 | return super.getNextButton(); |
| 725 | } |
| 726 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 727 | private static class HeaderAdapter extends ArrayAdapter<Header> { |
| 728 | static final int HEADER_TYPE_CATEGORY = 0; |
| 729 | static final int HEADER_TYPE_NORMAL = 1; |
| 730 | static final int HEADER_TYPE_SWITCH = 2; |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 731 | static final int HEADER_TYPE_BUTTON = 3; |
| 732 | private static final int HEADER_TYPE_COUNT = HEADER_TYPE_BUTTON + 1; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 733 | |
| 734 | private final WifiEnabler mWifiEnabler; |
| 735 | private final BluetoothEnabler mBluetoothEnabler; |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 736 | private AuthenticatorHelper mAuthHelper; |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 737 | private DevicePolicyManager mDevicePolicyManager; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 738 | |
| 739 | private static class HeaderViewHolder { |
| 740 | ImageView icon; |
| 741 | TextView title; |
| 742 | TextView summary; |
| 743 | Switch switch_; |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 744 | ImageButton button_; |
| 745 | View divider_; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | private LayoutInflater mInflater; |
| 749 | |
| 750 | static int getHeaderType(Header header) { |
| 751 | if (header.fragment == null && header.intent == null) { |
| 752 | return HEADER_TYPE_CATEGORY; |
| 753 | } else if (header.id == R.id.wifi_settings || header.id == R.id.bluetooth_settings) { |
| 754 | return HEADER_TYPE_SWITCH; |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 755 | } else if (header.id == R.id.security_settings) { |
| 756 | return HEADER_TYPE_BUTTON; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 757 | } else { |
| 758 | return HEADER_TYPE_NORMAL; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | @Override |
| 763 | public int getItemViewType(int position) { |
| 764 | Header header = getItem(position); |
| 765 | return getHeaderType(header); |
| 766 | } |
| 767 | |
| 768 | @Override |
| 769 | public boolean areAllItemsEnabled() { |
| 770 | return false; // because of categories |
| 771 | } |
| 772 | |
| 773 | @Override |
| 774 | public boolean isEnabled(int position) { |
| 775 | return getItemViewType(position) != HEADER_TYPE_CATEGORY; |
| 776 | } |
| 777 | |
| 778 | @Override |
| 779 | public int getViewTypeCount() { |
| 780 | return HEADER_TYPE_COUNT; |
| 781 | } |
| 782 | |
| 783 | @Override |
| 784 | public boolean hasStableIds() { |
| 785 | return true; |
| 786 | } |
| 787 | |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 788 | public HeaderAdapter(Context context, List<Header> objects, |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 789 | AuthenticatorHelper authenticatorHelper, DevicePolicyManager dpm) { |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 790 | super(context, 0, objects); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 791 | |
| 792 | mAuthHelper = authenticatorHelper; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 793 | mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 794 | |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 795 | // Temp Switches provided as placeholder until the adapter replaces these with actual |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 796 | // Switches inflated from their layouts. Must be done before adapter is set in super |
| 797 | mWifiEnabler = new WifiEnabler(context, new Switch(context)); |
| 798 | mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context)); |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 799 | mDevicePolicyManager = dpm; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | @Override |
| 803 | public View getView(int position, View convertView, ViewGroup parent) { |
| 804 | HeaderViewHolder holder; |
| 805 | Header header = getItem(position); |
| 806 | int headerType = getHeaderType(header); |
| 807 | View view = null; |
| 808 | |
| 809 | if (convertView == null) { |
| 810 | holder = new HeaderViewHolder(); |
| 811 | switch (headerType) { |
| 812 | case HEADER_TYPE_CATEGORY: |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 813 | view = new TextView(getContext(), null, |
| 814 | android.R.attr.listSeparatorTextViewStyle); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 815 | holder.title = (TextView) view; |
| 816 | break; |
| 817 | |
| 818 | case HEADER_TYPE_SWITCH: |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 819 | view = mInflater.inflate(R.layout.preference_header_switch_item, parent, |
| 820 | false); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 821 | holder.icon = (ImageView) view.findViewById(R.id.icon); |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 822 | holder.title = (TextView) |
| 823 | view.findViewById(com.android.internal.R.id.title); |
| 824 | holder.summary = (TextView) |
| 825 | view.findViewById(com.android.internal.R.id.summary); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 826 | holder.switch_ = (Switch) view.findViewById(R.id.switchWidget); |
| 827 | break; |
| 828 | |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 829 | case HEADER_TYPE_BUTTON: |
| 830 | view = mInflater.inflate(R.layout.preference_header_button_item, parent, |
| 831 | false); |
| 832 | holder.icon = (ImageView) view.findViewById(R.id.icon); |
| 833 | holder.title = (TextView) |
| 834 | view.findViewById(com.android.internal.R.id.title); |
| 835 | holder.summary = (TextView) |
| 836 | view.findViewById(com.android.internal.R.id.summary); |
| 837 | holder.button_ = (ImageButton) view.findViewById(R.id.buttonWidget); |
| 838 | holder.divider_ = view.findViewById(R.id.divider); |
| 839 | break; |
| 840 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 841 | case HEADER_TYPE_NORMAL: |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 842 | view = mInflater.inflate( |
Amith Yamasani | c8a9317 | 2012-06-08 13:35:47 -0700 | [diff] [blame] | 843 | R.layout.preference_header_item, parent, |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 844 | false); |
Amith Yamasani | c8a9317 | 2012-06-08 13:35:47 -0700 | [diff] [blame] | 845 | holder.icon = (ImageView) view.findViewById(R.id.icon); |
Gilles Debunne | b396c9b | 2011-06-22 16:07:29 -0700 | [diff] [blame] | 846 | holder.title = (TextView) |
| 847 | view.findViewById(com.android.internal.R.id.title); |
| 848 | holder.summary = (TextView) |
| 849 | view.findViewById(com.android.internal.R.id.summary); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 850 | break; |
| 851 | } |
| 852 | view.setTag(holder); |
| 853 | } else { |
| 854 | view = convertView; |
| 855 | holder = (HeaderViewHolder) view.getTag(); |
| 856 | } |
| 857 | |
| 858 | // All view fields must be updated every time, because the view may be recycled |
| 859 | switch (headerType) { |
| 860 | case HEADER_TYPE_CATEGORY: |
| 861 | holder.title.setText(header.getTitle(getContext().getResources())); |
| 862 | break; |
| 863 | |
| 864 | case HEADER_TYPE_SWITCH: |
| 865 | // Would need a different treatment if the main menu had more switches |
| 866 | if (header.id == R.id.wifi_settings) { |
| 867 | mWifiEnabler.setSwitch(holder.switch_); |
| 868 | } else { |
| 869 | mBluetoothEnabler.setSwitch(holder.switch_); |
| 870 | } |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 871 | updateCommonHeaderView(header, holder); |
| 872 | break; |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 873 | |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 874 | case HEADER_TYPE_BUTTON: |
| 875 | if (header.id == R.id.security_settings) { |
| 876 | boolean hasCert = DevicePolicyManager.hasAnyCaCertsInstalled(); |
| 877 | if (hasCert) { |
| 878 | holder.button_.setVisibility(View.VISIBLE); |
| 879 | holder.divider_.setVisibility(View.VISIBLE); |
| 880 | boolean isManaged = mDevicePolicyManager.getDeviceOwner() != null; |
| 881 | if (isManaged) { |
| 882 | holder.button_.setImageResource(R.drawable.ic_qs_certificate_info); |
| 883 | } else { |
| 884 | holder.button_.setImageResource( |
| 885 | android.R.drawable.stat_notify_error); |
| 886 | } |
| 887 | holder.button_.setOnClickListener(new OnClickListener() { |
| 888 | @Override |
| 889 | public void onClick(View v) { |
| 890 | Intent intent = new Intent( |
| 891 | android.provider.Settings.ACTION_MONITORING_CERT_INFO); |
| 892 | getContext().startActivity(intent); |
| 893 | } |
| 894 | }); |
| 895 | } else { |
| 896 | holder.button_.setVisibility(View.GONE); |
| 897 | holder.divider_.setVisibility(View.GONE); |
| 898 | } |
| 899 | } |
| 900 | updateCommonHeaderView(header, holder); |
| 901 | break; |
| 902 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 903 | case HEADER_TYPE_NORMAL: |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 904 | updateCommonHeaderView(header, holder); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 905 | break; |
| 906 | } |
| 907 | |
| 908 | return view; |
| 909 | } |
| 910 | |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 911 | private void updateCommonHeaderView(Header header, HeaderViewHolder holder) { |
| 912 | if (header.extras != null |
| 913 | && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) { |
| 914 | String accType = header.extras.getString( |
| 915 | ManageAccountsSettings.KEY_ACCOUNT_TYPE); |
| 916 | Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType); |
| 917 | setHeaderIcon(holder, icon); |
| 918 | } else if (header.extras != null && |
| 919 | header.extras.containsKey(HomeSettings.CURRENT_HOME)) { |
| 920 | ActivityInfo ai = header.extras.getParcelable(HomeSettings.CURRENT_HOME); |
| 921 | Drawable icon = ai.loadIcon(getContext().getPackageManager()); |
| 922 | setHeaderIcon(holder, icon); |
| 923 | } else { |
| 924 | holder.icon.setImageResource(header.iconRes); |
| 925 | } |
| 926 | holder.title.setText(header.getTitle(getContext().getResources())); |
| 927 | CharSequence summary = header.getSummary(getContext().getResources()); |
| 928 | if (!TextUtils.isEmpty(summary)) { |
| 929 | holder.summary.setVisibility(View.VISIBLE); |
| 930 | holder.summary.setText(summary); |
| 931 | } else { |
| 932 | holder.summary.setVisibility(View.GONE); |
| 933 | } |
| 934 | } |
| 935 | |
Christopher Tate | e238a47 | 2013-08-27 14:21:46 -0700 | [diff] [blame] | 936 | private void setHeaderIcon(HeaderViewHolder holder, Drawable icon) { |
| 937 | ViewGroup.LayoutParams lp = holder.icon.getLayoutParams(); |
| 938 | lp.width = getContext().getResources().getDimensionPixelSize( |
| 939 | R.dimen.header_icon_width); |
| 940 | lp.height = lp.width; |
| 941 | holder.icon.setLayoutParams(lp); |
| 942 | holder.icon.setImageDrawable(icon); |
| 943 | } |
| 944 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 945 | public void resume() { |
| 946 | mWifiEnabler.resume(); |
| 947 | mBluetoothEnabler.resume(); |
| 948 | } |
Brian Muramatsu | c28af52 | 2012-06-28 14:25:14 -0700 | [diff] [blame] | 949 | |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 950 | public void pause() { |
| 951 | mWifiEnabler.pause(); |
| 952 | mBluetoothEnabler.pause(); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | @Override |
Amith Yamasani | d1ab828 | 2012-05-18 09:50:08 -0700 | [diff] [blame] | 957 | public void onHeaderClick(Header header, int position) { |
| 958 | boolean revert = false; |
| 959 | if (header.id == R.id.account_add) { |
| 960 | revert = true; |
| 961 | } |
| 962 | |
| 963 | super.onHeaderClick(header, position); |
| 964 | |
| 965 | if (revert && mLastHeader != null) { |
| 966 | highlightHeader((int) mLastHeader.id); |
| 967 | } else { |
| 968 | mLastHeader = header; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | @Override |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 973 | public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { |
| 974 | // Override the fragment title for Wallpaper settings |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 975 | int titleRes = pref.getTitleRes(); |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 976 | if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { |
Amith Yamasani | dfb6543 | 2011-11-29 16:38:14 -0800 | [diff] [blame] | 977 | titleRes = R.string.wallpaper_settings_fragment_title; |
Amith Yamasani | 8666b9e | 2012-09-27 14:50:13 -0700 | [diff] [blame] | 978 | } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName()) |
| 979 | && UserHandle.myUserId() != UserHandle.USER_OWNER) { |
Amith Yamasani | b017171 | 2013-04-28 22:13:22 -0700 | [diff] [blame] | 980 | if (UserManager.get(this).isLinkedUser()) { |
| 981 | titleRes = R.string.profile_info_settings_title; |
| 982 | } else { |
| 983 | titleRes = R.string.user_info_settings_title; |
| 984 | } |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 985 | } |
Jean Chalard | 7dabe45 | 2012-05-10 18:08:07 +0900 | [diff] [blame] | 986 | startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(), |
| 987 | null, 0); |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 988 | return true; |
| 989 | } |
| 990 | |
Maggie Benthall | 0c5a401 | 2013-03-14 17:41:27 -0400 | [diff] [blame] | 991 | @Override |
Amith Yamasani | 3d384f4 | 2012-05-11 15:22:04 -0700 | [diff] [blame] | 992 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 993 | return super.shouldUpRecreateTask(new Intent(this, Settings.class)); |
| 994 | } |
| 995 | |
Amith Yamasani | a4379d6 | 2011-07-22 10:34:58 -0700 | [diff] [blame] | 996 | @Override |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 997 | public void setListAdapter(ListAdapter adapter) { |
Amith Yamasani | ea7b28c | 2012-06-20 13:51:40 -0700 | [diff] [blame] | 998 | if (adapter == null) { |
| 999 | super.setListAdapter(null); |
| 1000 | } else { |
Maggie Benthall | 9d6c40e | 2013-09-05 15:33:58 -0400 | [diff] [blame] | 1001 | DevicePolicyManager dpm = |
| 1002 | (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); |
| 1003 | super.setListAdapter(new HeaderAdapter(this, getHeaders(), mAuthenticatorHelper, dpm)); |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1004 | } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 1007 | @Override |
| 1008 | public void onAccountsUpdated(Account[] accounts) { |
Jeff Sharkey | 9ff79c1 | 2012-10-03 16:48:17 -0700 | [diff] [blame] | 1009 | // TODO: watch for package upgrades to invalidate cache; see 7206643 |
| 1010 | mAuthenticatorHelper.updateAuthDescriptions(this); |
Amith Yamasani | 56821db | 2012-06-05 13:20:45 -0700 | [diff] [blame] | 1011 | mAuthenticatorHelper.onAccountsUpdated(this, accounts); |
| 1012 | invalidateHeaders(); |
| 1013 | } |
| 1014 | |
Amith Yamasani | 5203bdf | 2010-11-04 09:59:44 -0700 | [diff] [blame] | 1015 | /* |
| 1016 | * Settings subclasses for launching independently. |
| 1017 | */ |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1018 | public static class BluetoothSettingsActivity extends Settings { /* empty */ } |
| 1019 | public static class WirelessSettingsActivity extends Settings { /* empty */ } |
| 1020 | public static class TetherSettingsActivity extends Settings { /* empty */ } |
| 1021 | public static class VpnSettingsActivity extends Settings { /* empty */ } |
| 1022 | public static class DateTimeSettingsActivity extends Settings { /* empty */ } |
| 1023 | public static class StorageSettingsActivity extends Settings { /* empty */ } |
| 1024 | public static class WifiSettingsActivity extends Settings { /* empty */ } |
repo sync | b98463f | 2011-06-30 10:58:43 -0700 | [diff] [blame] | 1025 | public static class WifiP2pSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1026 | public static class InputMethodAndLanguageSettingsActivity extends Settings { /* empty */ } |
Jeff Brown | e46c5f3 | 2012-04-05 11:42:18 -0700 | [diff] [blame] | 1027 | public static class KeyboardLayoutPickerActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1028 | public static class InputMethodAndSubtypeEnablerActivity extends Settings { /* empty */ } |
satok | e077d2b | 2011-07-25 09:38:11 +0900 | [diff] [blame] | 1029 | public static class SpellCheckersSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1030 | public static class LocalePickerActivity extends Settings { /* empty */ } |
| 1031 | public static class UserDictionarySettingsActivity extends Settings { /* empty */ } |
| 1032 | public static class SoundSettingsActivity extends Settings { /* empty */ } |
| 1033 | public static class DisplaySettingsActivity extends Settings { /* empty */ } |
| 1034 | public static class DeviceInfoSettingsActivity extends Settings { /* empty */ } |
| 1035 | public static class ApplicationSettingsActivity extends Settings { /* empty */ } |
| 1036 | public static class ManageApplicationsActivity extends Settings { /* empty */ } |
Dianne Hackborn | a522a8e | 2013-01-15 19:02:05 -0800 | [diff] [blame] | 1037 | public static class AppOpsSummaryActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1038 | public static class StorageUseActivity extends Settings { /* empty */ } |
| 1039 | public static class DevelopmentSettingsActivity extends Settings { /* empty */ } |
| 1040 | public static class AccessibilitySettingsActivity extends Settings { /* empty */ } |
Alan Viverette | 9b625f0 | 2013-09-11 13:03:14 -0700 | [diff] [blame] | 1041 | public static class CaptioningSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1042 | public static class SecuritySettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | a6a8a14 | 2011-06-09 11:56:17 -0700 | [diff] [blame] | 1043 | public static class LocationSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1044 | public static class PrivacySettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | e78c187 | 2011-06-20 15:00:07 -0700 | [diff] [blame] | 1045 | public static class RunningServicesActivity extends Settings { /* empty */ } |
| 1046 | public static class ManageAccountsSettingsActivity extends Settings { /* empty */ } |
| 1047 | public static class PowerUsageSummaryActivity extends Settings { /* empty */ } |
| 1048 | public static class AccountSyncSettingsActivity extends Settings { /* empty */ } |
| 1049 | public static class AccountSyncSettingsInAddAccountActivity extends Settings { /* empty */ } |
| 1050 | public static class CryptKeeperSettingsActivity extends Settings { /* empty */ } |
| 1051 | public static class DeviceAdminSettingsActivity extends Settings { /* empty */ } |
| 1052 | public static class DataUsageSummaryActivity extends Settings { /* empty */ } |
Gilles Debunne | ab189bd | 2011-07-06 13:10:16 -0700 | [diff] [blame] | 1053 | public static class AdvancedWifiSettingsActivity extends Settings { /* empty */ } |
Gilles Debunne | ab189bd | 2011-07-06 13:10:16 -0700 | [diff] [blame] | 1054 | public static class TextToSpeechSettingsActivity extends Settings { /* empty */ } |
Jeff Hamilton | 3d670de | 2011-09-21 16:44:36 -0500 | [diff] [blame] | 1055 | public static class AndroidBeamSettingsActivity extends Settings { /* empty */ } |
Jeff Brown | 9e143f5 | 2012-09-19 20:46:07 -0700 | [diff] [blame] | 1056 | public static class WifiDisplaySettingsActivity extends Settings { /* empty */ } |
Daniel Sandler | 7dee75c | 2012-11-27 22:41:30 -0500 | [diff] [blame] | 1057 | public static class DreamSettingsActivity extends Settings { /* empty */ } |
Daniel Sandler | 328e2d2 | 2013-01-17 13:14:02 -0500 | [diff] [blame] | 1058 | public static class NotificationStationActivity extends Settings { /* empty */ } |
Amith Yamasani | 233592b | 2013-03-01 17:05:23 -0800 | [diff] [blame] | 1059 | public static class UserSettingsActivity extends Settings { /* empty */ } |
Daniel Sandler | 79b9bfe | 2013-04-04 14:30:04 -0400 | [diff] [blame] | 1060 | public static class NotificationAccessSettingsActivity extends Settings { /* empty */ } |
Amith Yamasani | a677ee2 | 2013-07-26 13:38:41 -0700 | [diff] [blame] | 1061 | public static class UsbSettingsActivity extends Settings { /* empty */ } |
Geoffrey Borggaard | fc6bc20 | 2013-08-09 11:44:42 -0400 | [diff] [blame] | 1062 | public static class TrustedCredentialsSettingsActivity extends Settings { /* empty */ } |
Martijn Coenen | 53083ab | 2013-08-09 13:37:38 -0700 | [diff] [blame] | 1063 | public static class PaymentSettingsActivity extends Settings { /* empty */ } |
Svetoslav Ganov | 74648ac | 2013-09-04 23:52:28 -0700 | [diff] [blame] | 1064 | public static class PrintSettingsActivity extends Settings { /* empty */ } |
The Android Open Source Project | afc4ab2 | 2009-03-03 19:32:34 -0800 | [diff] [blame] | 1065 | } |