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