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