Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 19 | import android.app.ActionBar; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 20 | import android.app.Fragment; |
| 21 | import android.app.FragmentManager; |
| 22 | import android.app.FragmentTransaction; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 24 | import android.content.ComponentName; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.content.IntentFilter; |
| 28 | import android.content.SharedPreferences; |
| 29 | import android.content.pm.ActivityInfo; |
| 30 | import android.content.pm.PackageManager; |
| 31 | import android.content.pm.PackageManager.NameNotFoundException; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 32 | import android.content.res.Configuration; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 33 | import android.nfc.NfcAdapter; |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 34 | import android.os.AsyncTask; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 35 | import android.os.Bundle; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 36 | import android.os.UserHandle; |
| 37 | import android.os.UserManager; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 38 | import android.support.v14.preference.PreferenceFragment; |
| 39 | import android.support.v7.preference.Preference; |
| 40 | import android.support.v7.preference.PreferenceManager; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 41 | import android.text.TextUtils; |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 42 | import android.transition.TransitionManager; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 43 | import android.util.Log; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 44 | import android.view.Menu; |
| 45 | import android.view.MenuInflater; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 46 | import android.view.MenuItem; |
| 47 | import android.view.View; |
| 48 | import android.view.View.OnClickListener; |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 49 | import android.view.ViewGroup; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 50 | import android.widget.Button; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 51 | import android.widget.SearchView; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 52 | import com.android.internal.util.ArrayUtils; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 53 | import com.android.settings.Settings.WifiSettingsActivity; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 54 | import com.android.settings.accessibility.AccessibilitySettings; |
Anna Galusza | b1795f5 | 2016-01-08 14:37:16 -0800 | [diff] [blame] | 55 | import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 56 | import com.android.settings.accessibility.CaptionPropertiesFragment; |
Alexandra Gherghina | 6d83987 | 2014-07-22 12:04:58 +0000 | [diff] [blame] | 57 | import com.android.settings.accounts.AccountSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 58 | import com.android.settings.accounts.AccountSyncSettings; |
Billy Lau | fee7856 | 2015-07-27 12:57:07 +0100 | [diff] [blame] | 59 | import com.android.settings.applications.DrawOverlayDetails; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 60 | import com.android.settings.applications.InstalledAppDetails; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 61 | import com.android.settings.applications.ManageApplications; |
Xiyuan Xia | 86a5540 | 2015-06-02 14:55:32 -0700 | [diff] [blame] | 62 | import com.android.settings.applications.ManageAssist; |
Julia Reynolds | 2e1e0b7 | 2015-12-14 08:32:46 -0500 | [diff] [blame] | 63 | import com.android.settings.applications.ManageDefaultApps; |
Jason Monk | 2cdafc6 | 2015-06-12 12:32:50 -0400 | [diff] [blame] | 64 | import com.android.settings.applications.ProcessStatsSummary; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 65 | import com.android.settings.applications.ProcessStatsUi; |
Jason Monk | d8da51c | 2015-04-17 14:34:12 -0400 | [diff] [blame] | 66 | import com.android.settings.applications.UsageAccessDetails; |
Billy Lau | fee7856 | 2015-07-27 12:57:07 +0100 | [diff] [blame] | 67 | import com.android.settings.applications.WriteSettingsDetails; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 68 | import com.android.settings.bluetooth.BluetoothSettings; |
| 69 | import com.android.settings.dashboard.DashboardSummary; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 70 | import com.android.settings.dashboard.SearchResultsSummary; |
Jason Monk | b37e288 | 2016-01-11 14:27:20 -0500 | [diff] [blame] | 71 | import com.android.settings.datausage.DataUsageSummary; |
Jeff Sharkey | a16257d | 2015-04-28 13:41:01 -0700 | [diff] [blame] | 72 | import com.android.settings.deviceinfo.PrivateVolumeForget; |
Jeff Sharkey | e77f068 | 2015-04-29 11:24:57 -0700 | [diff] [blame] | 73 | import com.android.settings.deviceinfo.PrivateVolumeSettings; |
Jeff Sharkey | 42833b2 | 2015-04-11 21:27:33 -0700 | [diff] [blame] | 74 | import com.android.settings.deviceinfo.PublicVolumeSettings; |
| 75 | import com.android.settings.deviceinfo.StorageSettings; |
John Spurlock | c7f8e8c | 2014-06-04 19:11:22 -0400 | [diff] [blame] | 76 | import com.android.settings.fuelgauge.BatterySaverSettings; |
Jason Monk | 1eb54eb | 2015-04-29 12:46:42 -0400 | [diff] [blame] | 77 | import com.android.settings.fuelgauge.PowerUsageDetail; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 78 | import com.android.settings.fuelgauge.PowerUsageSummary; |
Abodunrinwa Toki | 976bb3f | 2016-01-20 18:43:20 +0000 | [diff] [blame] | 79 | import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 80 | import com.android.settings.inputmethod.InputMethodAndLanguageSettings; |
| 81 | import com.android.settings.inputmethod.KeyboardLayoutPickerFragment; |
Abodunrinwa Toki | 5f0b59b | 2016-01-25 23:02:23 +0000 | [diff] [blame] | 82 | import com.android.settings.inputmethod.KeyboardLayoutPickerFragment2; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 83 | import com.android.settings.inputmethod.SpellCheckersSettings; |
| 84 | import com.android.settings.inputmethod.UserDictionaryList; |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 85 | import com.android.settings.localepicker.LocaleListEditor; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 86 | import com.android.settings.location.LocationSettings; |
| 87 | import com.android.settings.nfc.AndroidBeam; |
| 88 | import com.android.settings.nfc.PaymentSettings; |
John Spurlock | 802ddf9 | 2014-07-18 11:51:13 -0400 | [diff] [blame] | 89 | import com.android.settings.notification.AppNotificationSettings; |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 90 | import com.android.settings.notification.ConfigureNotificationSettings; |
John Spurlock | 4a35051 | 2014-04-08 14:08:21 -0400 | [diff] [blame] | 91 | import com.android.settings.notification.NotificationAccessSettings; |
John Spurlock | 4a35051 | 2014-04-08 14:08:21 -0400 | [diff] [blame] | 92 | import com.android.settings.notification.NotificationStation; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 93 | import com.android.settings.notification.OtherSoundSettings; |
Jason Monk | b37e288 | 2016-01-11 14:27:20 -0500 | [diff] [blame] | 94 | import com.android.settings.notification.SoundSettings; |
John Spurlock | 08531a8 | 2015-05-07 17:45:43 -0400 | [diff] [blame] | 95 | import com.android.settings.notification.ZenAccessSettings; |
John Spurlock | 533a566 | 2015-06-19 10:47:36 -0400 | [diff] [blame] | 96 | import com.android.settings.notification.ZenModeAutomationSettings; |
John Spurlock | f57bad7 | 2015-04-30 09:26:15 -0400 | [diff] [blame] | 97 | import com.android.settings.notification.ZenModeEventRuleSettings; |
John Spurlock | c1df2aa | 2015-04-13 20:57:06 -0400 | [diff] [blame] | 98 | import com.android.settings.notification.ZenModePrioritySettings; |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 99 | import com.android.settings.notification.ZenModeScheduleRuleSettings; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 100 | import com.android.settings.notification.ZenModeSettings; |
Julia Reynolds | 5555d26 | 2015-11-09 10:52:17 -0500 | [diff] [blame] | 101 | import com.android.settings.notification.ZenModeVisualInterruptionSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 102 | import com.android.settings.print.PrintJobSettingsFragment; |
| 103 | import com.android.settings.print.PrintSettingsFragment; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 104 | import com.android.settings.search.DynamicIndexableContentMonitor; |
| 105 | import com.android.settings.search.Index; |
PauloftheWest | 3815561 | 2014-06-30 10:02:36 -0700 | [diff] [blame] | 106 | import com.android.settings.sim.SimSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 107 | import com.android.settings.tts.TextToSpeechSettings; |
| 108 | import com.android.settings.users.UserSettings; |
| 109 | import com.android.settings.vpn2.VpnSettings; |
| 110 | import com.android.settings.wfd.WifiDisplaySettings; |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 111 | import com.android.settings.widget.SwitchBar; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 112 | import com.android.settings.wifi.AdvancedWifiSettings; |
PauloftheWest | 7837b99 | 2014-06-24 07:42:27 -0700 | [diff] [blame] | 113 | import com.android.settings.wifi.SavedAccessPointsWifiSettings; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 114 | import com.android.settings.wifi.WifiSettings; |
| 115 | import com.android.settings.wifi.p2p.WifiP2pSettings; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 116 | import com.android.settingslib.drawer.DashboardCategory; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 117 | import com.android.settingslib.drawer.SettingsDrawerActivity; |
Jason Monk | 7ea14c5 | 2016-01-22 14:28:02 -0500 | [diff] [blame] | 118 | import com.android.settingslib.drawer.Tile; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 119 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 120 | import java.util.ArrayList; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 121 | import java.util.List; |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 122 | import java.util.Set; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 123 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 124 | public class SettingsActivity extends SettingsDrawerActivity |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 125 | implements PreferenceManager.OnPreferenceTreeClickListener, |
| 126 | PreferenceFragment.OnPreferenceStartFragmentCallback, |
Alexandra Gherghina | cfc7f9d | 2014-07-04 12:25:38 +0100 | [diff] [blame] | 127 | ButtonBarHandler, FragmentManager.OnBackStackChangedListener, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 128 | SearchView.OnQueryTextListener, SearchView.OnCloseListener, |
Alexandra Gherghina | cfc7f9d | 2014-07-04 12:25:38 +0100 | [diff] [blame] | 129 | MenuItem.OnActionExpandListener { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 130 | |
| 131 | private static final String LOG_TAG = "Settings"; |
| 132 | |
| 133 | // Constants for state save/restore |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 134 | private static final String SAVE_KEY_CATEGORIES = ":settings:categories"; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 135 | private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded"; |
| 136 | private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query"; |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 137 | private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up"; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 138 | private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search"; |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 139 | private static final String SAVE_KEY_HOME_ACTIVITIES_COUNT = ":settings:home_activities_count"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * When starting this activity, the invoking Intent can contain this extra |
| 143 | * string to specify which fragment should be initially displayed. |
| 144 | * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity |
| 145 | * will call isValidFragment() to confirm that the fragment class name is valid for this |
| 146 | * activity. |
| 147 | */ |
| 148 | public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; |
| 149 | |
| 150 | /** |
| 151 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
| 152 | * this extra can also be specified to supply a Bundle of arguments to pass |
| 153 | * to that fragment when it is instantiated during the initial creation |
| 154 | * of the activity. |
| 155 | */ |
| 156 | public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; |
| 157 | |
| 158 | /** |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 159 | * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS} |
| 160 | */ |
| 161 | public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; |
| 162 | |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 163 | public static final String BACK_STACK_PREFS = ":settings:prefs"; |
| 164 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 165 | // extras that allow any preference activity to be launched as part of a wizard |
| 166 | |
| 167 | // show Back and Next buttons? takes boolean parameter |
| 168 | // Back will then return RESULT_CANCELED and Next RESULT_OK |
| 169 | protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
| 170 | |
| 171 | // add a Skip button? |
| 172 | private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip"; |
| 173 | |
| 174 | // specify custom text for the Back or Next buttons, or cause a button to not appear |
| 175 | // at all by setting it to null |
| 176 | protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; |
| 177 | protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; |
| 178 | |
| 179 | /** |
| 180 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 181 | * those extra can also be specify to supply the title or title res id to be shown for |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 182 | * that fragment. |
| 183 | */ |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 184 | public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; |
Alexandra Gherghina | 62464b8 | 2014-08-11 12:40:13 +0100 | [diff] [blame] | 185 | /** |
| 186 | * The package name used to resolve the title resource id. |
| 187 | */ |
| 188 | public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME = |
| 189 | ":settings:show_fragment_title_res_package_name"; |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 190 | public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = |
| 191 | ":settings:show_fragment_title_resid"; |
| 192 | public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = |
| 193 | ":settings:show_fragment_as_shortcut"; |
| 194 | |
| 195 | public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING = |
| 196 | ":settings:show_fragment_as_subsetting"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 197 | |
Jason Monk | 3069581 | 2015-11-17 09:01:08 -0500 | [diff] [blame] | 198 | public static final String META_DATA_KEY_FRAGMENT_CLASS = |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 199 | "com.android.settings.FRAGMENT_CLASS"; |
| 200 | |
| 201 | private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; |
| 202 | |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 203 | private static final String EMPTY_QUERY = ""; |
| 204 | |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 205 | private static final int REQUEST_SUGGESTION = 42; |
| 206 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 207 | private String mFragmentClass; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 208 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 209 | private CharSequence mInitialTitle; |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 210 | private int mInitialTitleResId; |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 211 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 212 | // Show only these settings for restricted users |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 213 | private String[] SETTINGS_FOR_RESTRICTED = { |
| 214 | //wireless_section |
| 215 | WifiSettingsActivity.class.getName(), |
| 216 | Settings.BluetoothSettingsActivity.class.getName(), |
| 217 | Settings.DataUsageSummaryActivity.class.getName(), |
| 218 | Settings.SimSettingsActivity.class.getName(), |
| 219 | Settings.WirelessSettingsActivity.class.getName(), |
| 220 | //device_section |
| 221 | Settings.HomeSettingsActivity.class.getName(), |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 222 | Settings.SoundSettingsActivity.class.getName(), |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 223 | Settings.DisplaySettingsActivity.class.getName(), |
| 224 | Settings.StorageSettingsActivity.class.getName(), |
| 225 | Settings.ManageApplicationsActivity.class.getName(), |
| 226 | Settings.PowerUsageSummaryActivity.class.getName(), |
| 227 | //personal_section |
| 228 | Settings.LocationSettingsActivity.class.getName(), |
| 229 | Settings.SecuritySettingsActivity.class.getName(), |
| 230 | Settings.InputMethodAndLanguageSettingsActivity.class.getName(), |
| 231 | Settings.UserSettingsActivity.class.getName(), |
| 232 | Settings.AccountSettingsActivity.class.getName(), |
| 233 | //system_section |
| 234 | Settings.DateTimeSettingsActivity.class.getName(), |
| 235 | Settings.DeviceInfoSettingsActivity.class.getName(), |
| 236 | Settings.AccessibilitySettingsActivity.class.getName(), |
| 237 | Settings.PrintSettingsActivity.class.getName(), |
| 238 | Settings.PaymentSettingsActivity.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | private static final String[] ENTRY_FRAGMENTS = { |
| 242 | WirelessSettings.class.getName(), |
| 243 | WifiSettings.class.getName(), |
| 244 | AdvancedWifiSettings.class.getName(), |
PauloftheWest | 7837b99 | 2014-06-24 07:42:27 -0700 | [diff] [blame] | 245 | SavedAccessPointsWifiSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 246 | BluetoothSettings.class.getName(), |
PauloftheWest | 3815561 | 2014-06-30 10:02:36 -0700 | [diff] [blame] | 247 | SimSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 248 | TetherSettings.class.getName(), |
| 249 | WifiP2pSettings.class.getName(), |
| 250 | VpnSettings.class.getName(), |
| 251 | DateTimeSettings.class.getName(), |
Mihai Nita | d7d48fd | 2016-01-12 08:55:05 -0800 | [diff] [blame] | 252 | LocaleListEditor.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 253 | InputMethodAndLanguageSettings.class.getName(), |
Abodunrinwa Toki | 976bb3f | 2016-01-20 18:43:20 +0000 | [diff] [blame] | 254 | AvailableVirtualKeyboardFragment.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 255 | SpellCheckersSettings.class.getName(), |
| 256 | UserDictionaryList.class.getName(), |
| 257 | UserDictionarySettings.class.getName(), |
Amith Yamasani | 3033ce0 | 2014-07-14 18:03:15 -0700 | [diff] [blame] | 258 | HomeSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 259 | DisplaySettings.class.getName(), |
| 260 | DeviceInfoSettings.class.getName(), |
| 261 | ManageApplications.class.getName(), |
Xiyuan Xia | 86a5540 | 2015-06-02 14:55:32 -0700 | [diff] [blame] | 262 | ManageAssist.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 263 | ProcessStatsUi.class.getName(), |
| 264 | NotificationStation.class.getName(), |
| 265 | LocationSettings.class.getName(), |
| 266 | SecuritySettings.class.getName(), |
Jason Monk | d8da51c | 2015-04-17 14:34:12 -0400 | [diff] [blame] | 267 | UsageAccessDetails.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 268 | PrivacySettings.class.getName(), |
| 269 | DeviceAdminSettings.class.getName(), |
| 270 | AccessibilitySettings.class.getName(), |
Anna Galusza | b1795f5 | 2016-01-08 14:37:16 -0800 | [diff] [blame] | 271 | AccessibilitySettingsForSetupWizard.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 272 | CaptionPropertiesFragment.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 273 | com.android.settings.accessibility.ToggleDaltonizerPreferenceFragment.class.getName(), |
| 274 | TextToSpeechSettings.class.getName(), |
Jeff Sharkey | 42833b2 | 2015-04-11 21:27:33 -0700 | [diff] [blame] | 275 | StorageSettings.class.getName(), |
Jeff Sharkey | a16257d | 2015-04-28 13:41:01 -0700 | [diff] [blame] | 276 | PrivateVolumeForget.class.getName(), |
Jeff Sharkey | e77f068 | 2015-04-29 11:24:57 -0700 | [diff] [blame] | 277 | PrivateVolumeSettings.class.getName(), |
| 278 | PublicVolumeSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 279 | DevelopmentSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 280 | AndroidBeam.class.getName(), |
| 281 | WifiDisplaySettings.class.getName(), |
| 282 | PowerUsageSummary.class.getName(), |
| 283 | AccountSyncSettings.class.getName(), |
Alexandra Gherghina | 6d83987 | 2014-07-22 12:04:58 +0000 | [diff] [blame] | 284 | AccountSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 285 | CryptKeeperSettings.class.getName(), |
| 286 | DataUsageSummary.class.getName(), |
| 287 | DreamSettings.class.getName(), |
| 288 | UserSettings.class.getName(), |
| 289 | NotificationAccessSettings.class.getName(), |
John Spurlock | 08531a8 | 2015-05-07 17:45:43 -0400 | [diff] [blame] | 290 | ZenAccessSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 291 | PrintSettingsFragment.class.getName(), |
| 292 | PrintJobSettingsFragment.class.getName(), |
| 293 | TrustedCredentialsSettings.class.getName(), |
| 294 | PaymentSettings.class.getName(), |
| 295 | KeyboardLayoutPickerFragment.class.getName(), |
Abodunrinwa Toki | 5f0b59b | 2016-01-25 23:02:23 +0000 | [diff] [blame] | 296 | KeyboardLayoutPickerFragment2.class.getName(), |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 297 | ZenModeSettings.class.getName(), |
Julia Reynolds | 8c0a423 | 2015-11-24 10:08:14 -0500 | [diff] [blame] | 298 | SoundSettings.class.getName(), |
| 299 | ConfigureNotificationSettings.class.getName(), |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 300 | ChooseLockPassword.ChooseLockPasswordFragment.class.getName(), |
| 301 | ChooseLockPattern.ChooseLockPatternFragment.class.getName(), |
John Spurlock | c7f8e8c | 2014-06-04 19:11:22 -0400 | [diff] [blame] | 302 | InstalledAppDetails.class.getName(), |
| 303 | BatterySaverSettings.class.getName(), |
Fabrice Di Meglio | dcf59dd | 2014-07-21 11:22:20 -0700 | [diff] [blame] | 304 | AppNotificationSettings.class.getName(), |
Fabrice Di Meglio | e3ff4d8 | 2014-07-23 20:03:20 -0700 | [diff] [blame] | 305 | OtherSoundSettings.class.getName(), |
Narayan Kamath | 33acb15 | 2015-03-16 12:48:05 +0000 | [diff] [blame] | 306 | ApnSettings.class.getName(), |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 307 | WifiCallingSettings.class.getName(), |
John Spurlock | c1df2aa | 2015-04-13 20:57:06 -0400 | [diff] [blame] | 308 | ZenModePrioritySettings.class.getName(), |
John Spurlock | 533a566 | 2015-06-19 10:47:36 -0400 | [diff] [blame] | 309 | ZenModeAutomationSettings.class.getName(), |
John Spurlock | 45fa140 | 2015-04-09 12:50:04 -0400 | [diff] [blame] | 310 | ZenModeScheduleRuleSettings.class.getName(), |
John Spurlock | f57bad7 | 2015-04-30 09:26:15 -0400 | [diff] [blame] | 311 | ZenModeEventRuleSettings.class.getName(), |
Julia Reynolds | 5555d26 | 2015-11-09 10:52:17 -0500 | [diff] [blame] | 312 | ZenModeVisualInterruptionSettings.class.getName(), |
Jason Monk | 2583fc1 | 2015-03-25 09:46:30 -0400 | [diff] [blame] | 313 | ProcessStatsUi.class.getName(), |
Jason Monk | 1eb54eb | 2015-04-29 12:46:42 -0400 | [diff] [blame] | 314 | PowerUsageDetail.class.getName(), |
Jason Monk | 2cdafc6 | 2015-06-12 12:32:50 -0400 | [diff] [blame] | 315 | ProcessStatsSummary.class.getName(), |
Billy Lau | fee7856 | 2015-07-27 12:57:07 +0100 | [diff] [blame] | 316 | DrawOverlayDetails.class.getName(), |
| 317 | WriteSettingsDetails.class.getName(), |
Julia Reynolds | 2e1e0b7 | 2015-12-14 08:32:46 -0500 | [diff] [blame] | 318 | ManageDefaultApps.class.getName(), |
Jason Monk | b9e5d23 | 2016-01-26 17:43:57 -0500 | [diff] [blame] | 319 | WallpaperTypeSettings.class.getName(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 320 | }; |
| 321 | |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 322 | |
| 323 | private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = { |
| 324 | "android.settings.APPLICATION_DETAILS_SETTINGS" |
| 325 | }; |
| 326 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 327 | private SharedPreferences mDevelopmentPreferences; |
| 328 | private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; |
| 329 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 330 | private boolean mBatteryPresent = true; |
| 331 | private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 332 | @Override |
| 333 | public void onReceive(Context context, Intent intent) { |
| 334 | String action = intent.getAction(); |
| 335 | if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 336 | boolean batteryPresent = Utils.isBatteryPresent(intent); |
| 337 | |
| 338 | if (mBatteryPresent != batteryPresent) { |
| 339 | mBatteryPresent = batteryPresent; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 340 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
| 344 | }; |
| 345 | |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 346 | private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() { |
| 347 | @Override |
| 348 | public void onReceive(Context context, Intent intent) { |
| 349 | String action = intent.getAction(); |
| 350 | if (action.equals(Intent.ACTION_USER_ADDED) |
| 351 | || action.equals(Intent.ACTION_USER_REMOVED)) { |
| 352 | Index.getInstance(getApplicationContext()).update(); |
| 353 | } |
| 354 | } |
| 355 | }; |
| 356 | |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 357 | private final DynamicIndexableContentMonitor mDynamicIndexableContentMonitor = |
| 358 | new DynamicIndexableContentMonitor(); |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 359 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 360 | private ActionBar mActionBar; |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 361 | private SwitchBar mSwitchBar; |
| 362 | |
| 363 | private Button mNextButton; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 364 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 365 | private boolean mDisplayHomeAsUpEnabled; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 366 | private boolean mDisplaySearch; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 367 | |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 368 | private boolean mIsShowingDashboard; |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 369 | private boolean mIsShortcut; |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 370 | |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 371 | private ViewGroup mContent; |
| 372 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 373 | private SearchView mSearchView; |
| 374 | private MenuItem mSearchMenuItem; |
| 375 | private boolean mSearchMenuItemExpanded = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 376 | private SearchResultsSummary mSearchResultsFragment; |
| 377 | private String mSearchQuery; |
| 378 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 379 | // Categories |
| 380 | private ArrayList<DashboardCategory> mCategories = new ArrayList<DashboardCategory>(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 381 | |
Fabrice Di Meglio | b0a464f | 2014-07-23 18:15:42 -0700 | [diff] [blame] | 382 | private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 383 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 384 | private boolean mNeedToRevertToInitialFragment = false; |
| 385 | |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 386 | private Intent mResultIntentData; |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 387 | private ComponentName mCurrentSuggestion; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 388 | |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 389 | public SwitchBar getSwitchBar() { |
| 390 | return mSwitchBar; |
| 391 | } |
| 392 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 393 | @Override |
| 394 | public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { |
| 395 | // Override the fragment title for Wallpaper settings |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 396 | CharSequence title = pref.getTitle(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 397 | if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) { |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 398 | title = getString(R.string.wallpaper_settings_fragment_title); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 399 | } |
Jason Monk | b1dd5c9 | 2015-12-16 16:13:54 -0500 | [diff] [blame] | 400 | startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, title, |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 401 | null, 0); |
| 402 | return true; |
| 403 | } |
| 404 | |
| 405 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 406 | public boolean onPreferenceTreeClick(Preference preference) { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 407 | return false; |
| 408 | } |
| 409 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 410 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 411 | public void onConfigurationChanged(Configuration newConfig) { |
| 412 | super.onConfigurationChanged(newConfig); |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 413 | Index.getInstance(this).update(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 417 | protected void onStart() { |
| 418 | super.onStart(); |
| 419 | |
| 420 | if (mNeedToRevertToInitialFragment) { |
| 421 | revertToInitialFragment(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 422 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 426 | public boolean onCreateOptionsMenu(Menu menu) { |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 427 | if (!mDisplaySearch) { |
| 428 | return false; |
| 429 | } |
| 430 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 431 | MenuInflater inflater = getMenuInflater(); |
| 432 | inflater.inflate(R.menu.options_menu, menu); |
| 433 | |
| 434 | // Cache the search query (can be overriden by the OnQueryTextListener) |
| 435 | final String query = mSearchQuery; |
| 436 | |
Fabrice Di Meglio | 9593782 | 2014-03-31 19:46:42 -0700 | [diff] [blame] | 437 | mSearchMenuItem = menu.findItem(R.id.search); |
| 438 | mSearchView = (SearchView) mSearchMenuItem.getActionView(); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 439 | |
Fabrice Di Meglio | 23ae00c | 2014-04-21 12:43:20 -0700 | [diff] [blame] | 440 | if (mSearchMenuItem == null || mSearchView == null) { |
| 441 | return false; |
| 442 | } |
| 443 | |
Fabrice Di Meglio | 8c3b0ce | 2014-05-12 18:54:32 -0700 | [diff] [blame] | 444 | if (mSearchResultsFragment != null) { |
| 445 | mSearchResultsFragment.setSearchView(mSearchView); |
| 446 | } |
| 447 | |
Fabrice Di Meglio | 9593782 | 2014-03-31 19:46:42 -0700 | [diff] [blame] | 448 | mSearchMenuItem.setOnActionExpandListener(this); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 449 | mSearchView.setOnQueryTextListener(this); |
| 450 | mSearchView.setOnCloseListener(this); |
| 451 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 452 | if (mSearchMenuItemExpanded) { |
| 453 | mSearchMenuItem.expandActionView(); |
| 454 | } |
| 455 | mSearchView.setQuery(query, true /* submit */); |
| 456 | |
| 457 | return true; |
| 458 | } |
| 459 | |
Jason Monk | 31c7c32 | 2016-01-20 14:41:52 -0500 | [diff] [blame^] | 460 | @Override |
| 461 | public SharedPreferences getSharedPreferences(String name, int mode) { |
| 462 | if (name.equals(getPackageName() + "_preferences")) { |
| 463 | String tag = getClass().getName(); |
| 464 | if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) { |
| 465 | tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); |
| 466 | } |
| 467 | if (tag.startsWith("com.android.settings.")) { |
| 468 | tag = tag.replace("com.android.settings.", ""); |
| 469 | } |
| 470 | return new SharedPreferencesLogger(this, tag); |
| 471 | } |
| 472 | return super.getSharedPreferences(name, mode); |
| 473 | } |
| 474 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 475 | private static boolean isShortCutIntent(final Intent intent) { |
| 476 | Set<String> categories = intent.getCategories(); |
| 477 | return (categories != null) && categories.contains("com.android.settings.SHORTCUT"); |
| 478 | } |
| 479 | |
Fabrice Di Meglio | 5b3c3c0 | 2014-06-30 15:18:08 -0700 | [diff] [blame] | 480 | private static boolean isLikeShortCutIntent(final Intent intent) { |
Fabrice Di Meglio | 5b7a100 | 2014-06-23 17:54:40 -0700 | [diff] [blame] | 481 | String action = intent.getAction(); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 482 | if (action == null) { |
| 483 | return false; |
| 484 | } |
| 485 | for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) { |
| 486 | if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true; |
| 487 | } |
| 488 | return false; |
Fabrice Di Meglio | 5b7a100 | 2014-06-23 17:54:40 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 491 | @Override |
| 492 | protected void onCreate(Bundle savedState) { |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 493 | super.onCreate(savedState); |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 494 | long startTime = System.currentTimeMillis(); |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 495 | |
| 496 | // Should happen before any call to getIntent() |
| 497 | getMetaData(); |
| 498 | |
| 499 | final Intent intent = getIntent(); |
| 500 | if (intent.hasExtra(EXTRA_UI_OPTIONS)) { |
| 501 | getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 502 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 503 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 504 | mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, |
| 505 | Context.MODE_PRIVATE); |
| 506 | |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 507 | // Getting Intent properties can only be done after the super.onCreate(...) |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 508 | final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 509 | |
Fabrice Di Meglio | 5b3c3c0 | 2014-06-30 15:18:08 -0700 | [diff] [blame] | 510 | mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 511 | intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); |
| 512 | |
Fabrice Di Meglio | e817a66 | 2014-07-16 19:51:06 -0700 | [diff] [blame] | 513 | final ComponentName cn = intent.getComponent(); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 514 | final String className = cn.getClassName(); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 515 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 516 | mIsShowingDashboard = className.equals(Settings.class.getName()) |
| 517 | || className.equals(Settings.WirelessSettings.class.getName()) |
| 518 | || className.equals(Settings.DeviceSettings.class.getName()) |
| 519 | || className.equals(Settings.PersonalSettings.class.getName()) |
| 520 | || className.equals(Settings.WirelessSettings.class.getName()); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 521 | |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 522 | // This is a "Sub Settings" when: |
| 523 | // - this is a real SubSettings |
| 524 | // - or :settings:show_fragment_as_subsetting is passed to the Intent |
Jorim Jaggi | 4dfcb82 | 2015-04-29 17:21:32 -0700 | [diff] [blame] | 525 | final boolean isSubSettings = this instanceof SubSettings || |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 526 | intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); |
| 527 | |
| 528 | // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets |
| 529 | if (isSubSettings) { |
Fabrice Di Meglio | 712df6c | 2014-07-18 17:44:37 -0700 | [diff] [blame] | 530 | // Check also that we are not a Theme Dialog as we don't want to override them |
| 531 | final int themeResId = getThemeResId(); |
| 532 | if (themeResId != R.style.Theme_DialogWhenLarge && |
| 533 | themeResId != R.style.Theme_SubSettingsDialogWhenLarge) { |
| 534 | setTheme(R.style.Theme_SubSettings); |
| 535 | } |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 538 | setContentView(mIsShowingDashboard ? |
| 539 | R.layout.settings_main_dashboard : R.layout.settings_main_prefs); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 540 | |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 541 | mContent = (ViewGroup) findViewById(R.id.main_content); |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 542 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 543 | getFragmentManager().addOnBackStackChangedListener(this); |
| 544 | |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 545 | if (mIsShowingDashboard) { |
Fabrice Di Meglio | dff3faa | 2015-02-27 11:14:11 -0800 | [diff] [blame] | 546 | // Run the Index update only if we have some space |
| 547 | if (!Utils.isLowStorage(this)) { |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 548 | long indexStartTime = System.currentTimeMillis(); |
| 549 | AsyncTask.execute(new Runnable() { |
| 550 | @Override |
| 551 | public void run() { |
| 552 | Index.getInstance(getApplicationContext()).update(); |
| 553 | } |
| 554 | }); |
| 555 | if (DEBUG_TIMING) Log.d(LOG_TAG, "Index.update() took " |
| 556 | + (System.currentTimeMillis() - indexStartTime) + " ms"); |
Fabrice Di Meglio | dff3faa | 2015-02-27 11:14:11 -0800 | [diff] [blame] | 557 | } else { |
| 558 | Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!"); |
| 559 | } |
Fabrice Di Meglio | 5cda21b | 2014-04-21 10:14:28 -0700 | [diff] [blame] | 560 | } |
| 561 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 562 | if (savedState != null) { |
Fabrice Di Meglio | 1800a9f | 2014-04-03 19:31:07 -0700 | [diff] [blame] | 563 | // We are restarting from a previous saved state; used that to initialize, instead |
| 564 | // of starting fresh. |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 565 | mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED); |
| 566 | mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 567 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 568 | setTitleFromIntent(intent); |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 569 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 570 | ArrayList<DashboardCategory> categories = |
| 571 | savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); |
| 572 | if (categories != null) { |
Fabrice Di Meglio | 5f99572 | 2014-05-19 19:51:31 -0700 | [diff] [blame] | 573 | mCategories.clear(); |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 574 | mCategories.addAll(categories); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 575 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 576 | } |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 577 | |
| 578 | mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 579 | mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 580 | } else { |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 581 | if (!mIsShowingDashboard) { |
Jason Monk | ea8b1a7 | 2015-06-02 16:46:34 -0400 | [diff] [blame] | 582 | mDisplaySearch = false; |
| 583 | // UP will be shown only if it is a sub settings |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 584 | if (mIsShortcut) { |
| 585 | mDisplayHomeAsUpEnabled = isSubSettings; |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 586 | } else if (isSubSettings) { |
| 587 | mDisplayHomeAsUpEnabled = true; |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 588 | } else { |
| 589 | mDisplayHomeAsUpEnabled = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 590 | } |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 591 | setTitleFromIntent(intent); |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 592 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 593 | Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 594 | switchToFragment(initialFragmentName, initialArguments, true, false, |
| 595 | mInitialTitleResId, mInitialTitle, false); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 596 | } else { |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 597 | // No UP affordance if we are displaying the main Dashboard |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 598 | mDisplayHomeAsUpEnabled = false; |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 599 | // Show Search affordance |
| 600 | mDisplaySearch = true; |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 601 | mInitialTitleResId = R.string.dashboard_title; |
Fabrice Di Meglio | 42c4b0a | 2014-05-22 10:30:03 -0700 | [diff] [blame] | 602 | switchToFragment(DashboardSummary.class.getName(), null, false, false, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 603 | mInitialTitleResId, mInitialTitle, false); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 607 | mActionBar = getActionBar(); |
Fabrice Di Meglio | d8aec08 | 2014-05-20 10:49:50 -0700 | [diff] [blame] | 608 | if (mActionBar != null) { |
| 609 | mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); |
| 610 | mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); |
| 611 | } |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 612 | mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar); |
| 613 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 614 | // see if we should show Back/Next buttons |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 615 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { |
| 616 | |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 617 | View buttonBar = findViewById(R.id.button_bar); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 618 | if (buttonBar != null) { |
| 619 | buttonBar.setVisibility(View.VISIBLE); |
| 620 | |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 621 | Button backButton = (Button)findViewById(R.id.back_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 622 | backButton.setOnClickListener(new OnClickListener() { |
| 623 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 624 | setResult(RESULT_CANCELED, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 625 | finish(); |
| 626 | } |
| 627 | }); |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 628 | Button skipButton = (Button)findViewById(R.id.skip_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 629 | skipButton.setOnClickListener(new OnClickListener() { |
| 630 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 631 | setResult(RESULT_OK, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 632 | finish(); |
| 633 | } |
| 634 | }); |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 635 | mNextButton = (Button)findViewById(R.id.next_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 636 | mNextButton.setOnClickListener(new OnClickListener() { |
| 637 | public void onClick(View v) { |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 638 | setResult(RESULT_OK, getResultIntentData()); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 639 | finish(); |
| 640 | } |
| 641 | }); |
| 642 | |
| 643 | // set our various button parameters |
| 644 | if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { |
| 645 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); |
| 646 | if (TextUtils.isEmpty(buttonText)) { |
| 647 | mNextButton.setVisibility(View.GONE); |
| 648 | } |
| 649 | else { |
| 650 | mNextButton.setText(buttonText); |
| 651 | } |
| 652 | } |
| 653 | if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { |
| 654 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); |
| 655 | if (TextUtils.isEmpty(buttonText)) { |
| 656 | backButton.setVisibility(View.GONE); |
| 657 | } |
| 658 | else { |
| 659 | backButton.setText(buttonText); |
| 660 | } |
| 661 | } |
| 662 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { |
| 663 | skipButton.setVisibility(View.VISIBLE); |
| 664 | } |
| 665 | } |
| 666 | } |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 667 | |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 668 | if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) |
| 669 | + " ms"); |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 670 | } |
| 671 | |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 672 | private void setTitleFromIntent(Intent intent) { |
| 673 | final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1); |
| 674 | if (initialTitleResId > 0) { |
| 675 | mInitialTitle = null; |
| 676 | mInitialTitleResId = initialTitleResId; |
Alexandra Gherghina | 62464b8 | 2014-08-11 12:40:13 +0100 | [diff] [blame] | 677 | |
| 678 | final String initialTitleResPackageName = intent.getStringExtra( |
| 679 | EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME); |
| 680 | if (initialTitleResPackageName != null) { |
| 681 | try { |
| 682 | Context authContext = createPackageContextAsUser(initialTitleResPackageName, |
| 683 | 0 /* flags */, new UserHandle(UserHandle.myUserId())); |
| 684 | mInitialTitle = authContext.getResources().getText(mInitialTitleResId); |
| 685 | setTitle(mInitialTitle); |
| 686 | mInitialTitleResId = -1; |
| 687 | return; |
| 688 | } catch (NameNotFoundException e) { |
| 689 | Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName); |
| 690 | } |
| 691 | } else { |
| 692 | setTitle(mInitialTitleResId); |
| 693 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 694 | } else { |
| 695 | mInitialTitleResId = -1; |
| 696 | final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); |
| 697 | mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); |
| 698 | setTitle(mInitialTitle); |
| 699 | } |
| 700 | } |
| 701 | |
Fabrice Di Meglio | c95be4f | 2014-03-07 12:57:38 -0800 | [diff] [blame] | 702 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 703 | public void onBackStackChanged() { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 704 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 705 | } |
| 706 | |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 707 | private int setTitleFromBackStack() { |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 708 | final int count = getFragmentManager().getBackStackEntryCount(); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 709 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 710 | if (count == 0) { |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 711 | if (mInitialTitleResId > 0) { |
| 712 | setTitle(mInitialTitleResId); |
| 713 | } else { |
| 714 | setTitle(mInitialTitle); |
| 715 | } |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 716 | return 0; |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 717 | } |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 718 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 719 | FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); |
| 720 | setTitleFromBackStackEntry(bse); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 721 | |
| 722 | return count; |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { |
| 726 | final CharSequence title; |
| 727 | final int titleRes = bse.getBreadCrumbTitleRes(); |
| 728 | if (titleRes > 0) { |
| 729 | title = getText(titleRes); |
| 730 | } else { |
| 731 | title = bse.getBreadCrumbTitle(); |
| 732 | } |
| 733 | if (title != null) { |
| 734 | setTitle(title); |
| 735 | } |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 736 | } |
| 737 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 738 | @Override |
| 739 | protected void onSaveInstanceState(Bundle outState) { |
| 740 | super.onSaveInstanceState(outState); |
| 741 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 742 | if (mCategories.size() > 0) { |
| 743 | outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 744 | } |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 745 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 746 | outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled); |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 747 | outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch); |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 748 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 749 | if (mDisplaySearch) { |
| 750 | // The option menus are created if the ActionBar is visible and they are also created |
| 751 | // asynchronously. If you launch Settings with an Intent action like |
| 752 | // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked |
| 753 | // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search |
| 754 | // menu item and search view are null. |
| 755 | boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded(); |
| 756 | outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded); |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 757 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 758 | String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY; |
| 759 | outState.putString(SAVE_KEY_SEARCH_QUERY, query); |
| 760 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 764 | protected void onResume() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 765 | super.onResume(); |
| 766 | |
| 767 | mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { |
| 768 | @Override |
| 769 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 770 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 771 | } |
| 772 | }; |
| 773 | mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( |
| 774 | mDevelopmentPreferencesListener); |
| 775 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 776 | registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
Clara Bayarri | 6934a04 | 2015-10-14 11:07:35 +0100 | [diff] [blame] | 777 | registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED)); |
| 778 | registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED)); |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 779 | |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 780 | mDynamicIndexableContentMonitor.register(this); |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 781 | |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 782 | if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) { |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 783 | onQueryTextSubmit(mSearchQuery); |
| 784 | } |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 785 | updateTilesList(); |
Jason Monk | 478c592 | 2016-01-22 15:20:20 -0500 | [diff] [blame] | 786 | if (mIsShowingDashboard) { |
| 787 | showMenuIcon(); |
| 788 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 792 | protected void onPause() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 793 | super.onPause(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 794 | unregisterReceiver(mBatteryInfoReceiver); |
Clara Bayarri | 8c9521f | 2016-01-12 14:10:45 +0000 | [diff] [blame] | 795 | unregisterReceiver(mUserAddRemoveReceiver); |
Svetoslav | 990159a | 2014-04-14 17:14:59 -0700 | [diff] [blame] | 796 | mDynamicIndexableContentMonitor.unregister(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | @Override |
| 800 | public void onDestroy() { |
| 801 | super.onDestroy(); |
Fabrice Di Meglio | 680b064 | 2014-05-20 15:19:29 -0700 | [diff] [blame] | 802 | |
| 803 | mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( |
| 804 | mDevelopmentPreferencesListener); |
| 805 | mDevelopmentPreferencesListener = null; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 806 | } |
| 807 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 808 | protected boolean isValidFragment(String fragmentName) { |
| 809 | // Almost all fragments are wrapped in this, |
| 810 | // except for a few that have their own activities. |
| 811 | for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { |
| 812 | if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; |
| 813 | } |
| 814 | return false; |
| 815 | } |
| 816 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 817 | @Override |
| 818 | public Intent getIntent() { |
| 819 | Intent superIntent = super.getIntent(); |
| 820 | String startingFragment = getStartingFragmentClass(superIntent); |
| 821 | // This is called from super.onCreate, isMultiPane() is not yet reliable |
| 822 | // Do not use onIsHidingHeaders either, which relies itself on this method |
| 823 | if (startingFragment != null) { |
| 824 | Intent modIntent = new Intent(superIntent); |
| 825 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
| 826 | Bundle args = superIntent.getExtras(); |
| 827 | if (args != null) { |
| 828 | args = new Bundle(args); |
| 829 | } else { |
| 830 | args = new Bundle(); |
| 831 | } |
| 832 | args.putParcelable("intent", superIntent); |
Kenny Guy | ac1e20e | 2014-06-24 14:34:14 +0100 | [diff] [blame] | 833 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 834 | return modIntent; |
| 835 | } |
| 836 | return superIntent; |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * Checks if the component name in the intent is different from the Settings class and |
| 841 | * returns the class name to load as a fragment. |
| 842 | */ |
| 843 | private String getStartingFragmentClass(Intent intent) { |
| 844 | if (mFragmentClass != null) return mFragmentClass; |
| 845 | |
| 846 | String intentClass = intent.getComponent().getClassName(); |
| 847 | if (intentClass.equals(getClass().getName())) return null; |
| 848 | |
| 849 | if ("com.android.settings.ManageApplications".equals(intentClass) |
| 850 | || "com.android.settings.RunningServices".equals(intentClass) |
| 851 | || "com.android.settings.applications.StorageUse".equals(intentClass)) { |
| 852 | // Old names of manage apps. |
| 853 | intentClass = com.android.settings.applications.ManageApplications.class.getName(); |
| 854 | } |
| 855 | |
| 856 | return intentClass; |
| 857 | } |
| 858 | |
| 859 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 860 | * Start a new fragment containing a preference panel. If the preferences |
| 861 | * are being displayed in multi-pane mode, the given fragment class will |
| 862 | * be instantiated and placed in the appropriate pane. If running in |
| 863 | * single-pane mode, a new activity will be launched in which to show the |
| 864 | * fragment. |
| 865 | * |
| 866 | * @param fragmentClass Full name of the class implementing the fragment. |
| 867 | * @param args Any desired arguments to supply to the fragment. |
| 868 | * @param titleRes Optional resource identifier of the title of this |
| 869 | * fragment. |
| 870 | * @param titleText Optional text of the title of this fragment. |
| 871 | * @param resultTo Optional fragment that result data should be sent to. |
| 872 | * If non-null, resultTo.onActivityResult() will be called when this |
| 873 | * preference panel is done. The launched panel must use |
| 874 | * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. |
| 875 | * @param resultRequestCode If resultTo is non-null, this is the caller's |
Fabrice Di Meglio | 58146c2 | 2014-06-26 16:20:26 -0700 | [diff] [blame] | 876 | * request code to be received with the result. |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 877 | */ |
| 878 | public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 879 | CharSequence titleText, Fragment resultTo, int resultRequestCode) { |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 880 | String title = null; |
| 881 | if (titleRes < 0) { |
| 882 | if (titleText != null) { |
| 883 | title = titleText.toString(); |
| 884 | } else { |
| 885 | // There not much we can do in that case |
| 886 | title = ""; |
| 887 | } |
Fabrice Di Meglio | 911fb2a | 2014-04-04 17:55:57 -0700 | [diff] [blame] | 888 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 889 | Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 890 | titleRes, title, mIsShortcut); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | /** |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 894 | * Start a new fragment in a new activity containing a preference panel for a given user. If the |
| 895 | * preferences are being displayed in multi-pane mode, the given fragment class will be |
| 896 | * instantiated and placed in the appropriate pane. If running in single-pane mode, a new |
| 897 | * activity will be launched in which to show the fragment. |
| 898 | * |
| 899 | * @param fragmentClass Full name of the class implementing the fragment. |
| 900 | * @param args Any desired arguments to supply to the fragment. |
| 901 | * @param titleRes Optional resource identifier of the title of this fragment. |
| 902 | * @param titleText Optional text of the title of this fragment. |
| 903 | * @param userHandle The user for which the panel has to be started. |
| 904 | */ |
| 905 | public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes, |
| 906 | CharSequence titleText, UserHandle userHandle) { |
Lifu Tang | d033285 | 2015-04-02 12:05:46 -0700 | [diff] [blame] | 907 | // This is a workaround. |
| 908 | // |
| 909 | // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent |
| 910 | // starting the fragment could cause a native stack corruption. See b/17523189. However, |
| 911 | // adding that flag and start the preference panel with the same UserHandler will make it |
| 912 | // impossible to use back button to return to the previous screen. See b/20042570. |
| 913 | // |
| 914 | // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing |
| 915 | // another check here to call startPreferencePanel() instead of startWithFragmentAsUser() |
| 916 | // when we're calling it as the same user. |
| 917 | if (userHandle.getIdentifier() == UserHandle.myUserId()) { |
| 918 | startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0); |
| 919 | } else { |
| 920 | String title = null; |
| 921 | if (titleRes < 0) { |
| 922 | if (titleText != null) { |
| 923 | title = titleText.toString(); |
| 924 | } else { |
| 925 | // There not much we can do in that case |
| 926 | title = ""; |
| 927 | } |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 928 | } |
Lifu Tang | d033285 | 2015-04-02 12:05:46 -0700 | [diff] [blame] | 929 | Utils.startWithFragmentAsUser(this, fragmentClass, args, |
| 930 | titleRes, title, mIsShortcut, userHandle); |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 931 | } |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | /** |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 935 | * Called by a preference panel fragment to finish itself. |
| 936 | * |
| 937 | * @param caller The fragment that is asking to be finished. |
| 938 | * @param resultCode Optional result code to send back to the original |
| 939 | * launching fragment. |
| 940 | * @param resultData Optional result data to send back to the original |
| 941 | * launching fragment. |
| 942 | */ |
| 943 | public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { |
| 944 | setResult(resultCode, resultData); |
Fabrice Di Meglio | 58146c2 | 2014-06-26 16:20:26 -0700 | [diff] [blame] | 945 | finish(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 949 | * Start a new fragment. |
| 950 | * |
| 951 | * @param fragment The fragment to start |
| 952 | * @param push If true, the current fragment will be pushed onto the back stack. If false, |
| 953 | * the current fragment will be replaced. |
| 954 | */ |
| 955 | public void startPreferenceFragment(Fragment fragment, boolean push) { |
| 956 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 957 | transaction.replace(R.id.main_content, fragment); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 958 | if (push) { |
| 959 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 960 | transaction.addToBackStack(BACK_STACK_PREFS); |
| 961 | } else { |
| 962 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
| 963 | } |
| 964 | transaction.commitAllowingStateLoss(); |
| 965 | } |
| 966 | |
| 967 | /** |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 968 | * Switch to a specific Fragment with taking care of validation, Title and BackStack |
| 969 | */ |
| 970 | private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 971 | boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 972 | if (validate && !isValidFragment(fragmentName)) { |
| 973 | throw new IllegalArgumentException("Invalid fragment for this activity: " |
| 974 | + fragmentName); |
| 975 | } |
| 976 | Fragment f = Fragment.instantiate(this, fragmentName, args); |
| 977 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 978 | transaction.replace(R.id.main_content, f); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 979 | if (withTransition) { |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 980 | TransitionManager.beginDelayedTransition(mContent); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 981 | } |
| 982 | if (addToBackStack) { |
| 983 | transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); |
| 984 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 985 | if (titleResId > 0) { |
| 986 | transaction.setBreadCrumbTitle(titleResId); |
| 987 | } else if (title != null) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 988 | transaction.setBreadCrumbTitle(title); |
| 989 | } |
| 990 | transaction.commitAllowingStateLoss(); |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 991 | getFragmentManager().executePendingTransactions(); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 992 | return f; |
| 993 | } |
| 994 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 995 | private void updateTilesList() { |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 996 | // Generally the items that are will be changing from these updates will |
| 997 | // not be in the top list of tiles, so run it in the background and the |
| 998 | // SettingsDrawerActivity will pick up on the updates automatically. |
| 999 | AsyncTask.execute(new Runnable() { |
| 1000 | @Override |
| 1001 | public void run() { |
| 1002 | doUpdateTilesList(); |
| 1003 | } |
| 1004 | }); |
| 1005 | } |
| 1006 | |
| 1007 | private void doUpdateTilesList() { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1008 | PackageManager pm = getPackageManager(); |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 1009 | final UserManager um = UserManager.get(this); |
| 1010 | final boolean isAdmin = um.isAdminUser(); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1011 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1012 | String packageName = getPackageName(); |
| 1013 | setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()), |
| 1014 | pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1015 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1016 | setTileEnabled(new ComponentName(packageName, |
| 1017 | Settings.BluetoothSettingsActivity.class.getName()), |
| 1018 | pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1019 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1020 | setTileEnabled(new ComponentName(packageName, |
| 1021 | Settings.DataUsageSummaryActivity.class.getName()), |
| 1022 | Utils.isBandwidthControlEnabled(), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1023 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1024 | setTileEnabled(new ComponentName(packageName, |
| 1025 | Settings.SimSettingsActivity.class.getName()), |
| 1026 | Utils.showSimCardTile(this), isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1027 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1028 | setTileEnabled(new ComponentName(packageName, |
| 1029 | Settings.PowerUsageSummaryActivity.class.getName()), |
| 1030 | mBatteryPresent, isAdmin, pm); |
| 1031 | |
| 1032 | setTileEnabled(new ComponentName(packageName, |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1033 | Settings.UserSettingsActivity.class.getName()), |
| 1034 | UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers() |
| 1035 | && !Utils.isMonkeyRunning(), isAdmin, pm); |
| 1036 | |
| 1037 | NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); |
| 1038 | setTileEnabled(new ComponentName(packageName, |
| 1039 | Settings.PaymentSettingsActivity.class.getName()), |
| 1040 | pm.hasSystemFeature(PackageManager.FEATURE_NFC) |
| 1041 | && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION) |
| 1042 | && adapter != null && adapter.isEnabled(), isAdmin, pm); |
| 1043 | |
| 1044 | setTileEnabled(new ComponentName(packageName, |
| 1045 | Settings.PrintSettingsActivity.class.getName()), |
| 1046 | pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm); |
| 1047 | |
| 1048 | final boolean showDev = mDevelopmentPreferences.getBoolean( |
| 1049 | DevelopmentSettings.PREF_SHOW, |
| 1050 | android.os.Build.TYPE.equals("eng")); |
| 1051 | setTileEnabled(new ComponentName(packageName, |
| 1052 | Settings.DevelopmentSettingsActivity.class.getName()), |
| 1053 | showDev && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES), |
| 1054 | isAdmin, pm); |
| 1055 | |
| 1056 | if (UserHandle.MU_ENABLED && !isAdmin) { |
| 1057 | // When on restricted users, disable all extra categories (but only the settings ones). |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 1058 | List<DashboardCategory> categories = getDashboardCategories(); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1059 | for (DashboardCategory category : categories) { |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 1060 | for (Tile tile : category.tiles) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1061 | ComponentName component = tile.intent.getComponent(); |
| 1062 | if (packageName.equals(component)&& !ArrayUtils.contains( |
| 1063 | SETTINGS_FOR_RESTRICTED, component.getClassName())) { |
| 1064 | setTileEnabled(component, false, isAdmin, pm); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1065 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1066 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 1067 | } |
| 1068 | } |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 1069 | } |
| 1070 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1071 | private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin, |
| 1072 | PackageManager pm) { |
| 1073 | if (UserHandle.MU_ENABLED && !isAdmin |
| 1074 | && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) { |
| 1075 | enabled = false; |
| 1076 | } |
| 1077 | int state = pm.getComponentEnabledSetting(component); |
| 1078 | boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT |
| 1079 | || state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; |
| 1080 | if (isEnabled != enabled) { |
| 1081 | pm.setComponentEnabledSetting(component, enabled |
| 1082 | ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED |
| 1083 | : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, |
| 1084 | PackageManager.DONT_KILL_APP); |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1088 | private void getMetaData() { |
| 1089 | try { |
| 1090 | ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), |
| 1091 | PackageManager.GET_META_DATA); |
| 1092 | if (ai == null || ai.metaData == null) return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1093 | mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
| 1094 | } catch (NameNotFoundException nnfe) { |
| 1095 | // No recovery |
| 1096 | Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | // give subclasses access to the Next button |
| 1101 | public boolean hasNextButton() { |
| 1102 | return mNextButton != null; |
| 1103 | } |
| 1104 | |
| 1105 | public Button getNextButton() { |
| 1106 | return mNextButton; |
| 1107 | } |
| 1108 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1109 | @Override |
| 1110 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 1111 | return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); |
| 1112 | } |
| 1113 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1114 | @Override |
| 1115 | public boolean onQueryTextSubmit(String query) { |
| 1116 | switchToSearchResultsFragmentIfNeeded(); |
| 1117 | mSearchQuery = query; |
| 1118 | return mSearchResultsFragment.onQueryTextSubmit(query); |
| 1119 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1120 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1121 | @Override |
| 1122 | public boolean onQueryTextChange(String newText) { |
| 1123 | mSearchQuery = newText; |
Fabrice Di Meglio | 7e4855e | 2014-05-23 16:03:43 -0700 | [diff] [blame] | 1124 | if (mSearchResultsFragment == null) { |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 1125 | return false; |
| 1126 | } |
| 1127 | return mSearchResultsFragment.onQueryTextChange(newText); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1128 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1129 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1130 | @Override |
| 1131 | public boolean onClose() { |
| 1132 | return false; |
| 1133 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1134 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1135 | @Override |
| 1136 | public boolean onMenuItemActionExpand(MenuItem item) { |
| 1137 | if (item.getItemId() == mSearchMenuItem.getItemId()) { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1138 | switchToSearchResultsFragmentIfNeeded(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1139 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1140 | return true; |
| 1141 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1142 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1143 | @Override |
| 1144 | public boolean onMenuItemActionCollapse(MenuItem item) { |
| 1145 | if (item.getItemId() == mSearchMenuItem.getItemId()) { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1146 | if (mSearchMenuItemExpanded) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1147 | revertToInitialFragment(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1148 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1149 | } |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1150 | return true; |
| 1151 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1152 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1153 | @Override |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 1154 | protected void onTileClicked(Tile tile) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 1155 | if (mIsShowingDashboard) { |
| 1156 | // If on dashboard, don't finish so the back comes back to here. |
| 1157 | openTile(tile); |
| 1158 | } else { |
| 1159 | super.onTileClicked(tile); |
| 1160 | } |
| 1161 | } |
| 1162 | |
Jason Monk | af00109 | 2015-11-04 13:16:18 -0500 | [diff] [blame] | 1163 | @Override |
| 1164 | public void onProfileTileOpen() { |
| 1165 | if (!mIsShowingDashboard) { |
| 1166 | finish(); |
| 1167 | } |
| 1168 | } |
| 1169 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1170 | private void switchToSearchResultsFragmentIfNeeded() { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1171 | if (mSearchResultsFragment != null) { |
| 1172 | return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1173 | } |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 1174 | Fragment current = getFragmentManager().findFragmentById(R.id.main_content); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1175 | if (current != null && current instanceof SearchResultsSummary) { |
| 1176 | mSearchResultsFragment = (SearchResultsSummary) current; |
| 1177 | } else { |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1178 | mSearchResultsFragment = (SearchResultsSummary) switchToFragment( |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 1179 | SearchResultsSummary.class.getName(), null, false, true, |
| 1180 | R.string.search_results_title, null, true); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1181 | } |
Fabrice Di Meglio | d297a58 | 2014-04-22 17:23:23 -0700 | [diff] [blame] | 1182 | mSearchResultsFragment.setSearchView(mSearchView); |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1183 | mSearchMenuItemExpanded = true; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1184 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1185 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1186 | public void needToRevertToInitialFragment() { |
| 1187 | mNeedToRevertToInitialFragment = true; |
| 1188 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1189 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1190 | private void revertToInitialFragment() { |
| 1191 | mNeedToRevertToInitialFragment = false; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 1192 | mSearchResultsFragment = null; |
Fabrice Di Meglio | bb16fd8 | 2014-04-04 14:48:05 -0700 | [diff] [blame] | 1193 | mSearchMenuItemExpanded = false; |
| 1194 | getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS, |
| 1195 | FragmentManager.POP_BACK_STACK_INCLUSIVE); |
Fabrice Di Meglio | 23ae00c | 2014-04-21 12:43:20 -0700 | [diff] [blame] | 1196 | if (mSearchMenuItem != null) { |
| 1197 | mSearchMenuItem.collapseActionView(); |
| 1198 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1199 | } |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 1200 | |
| 1201 | public Intent getResultIntentData() { |
| 1202 | return mResultIntentData; |
| 1203 | } |
| 1204 | |
| 1205 | public void setResultIntentData(Intent resultIntentData) { |
| 1206 | mResultIntentData = resultIntentData; |
| 1207 | } |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 1208 | |
| 1209 | public void startSuggestion(Intent intent) { |
| 1210 | mCurrentSuggestion = intent.getComponent(); |
| 1211 | startActivityForResult(intent, REQUEST_SUGGESTION); |
| 1212 | } |
| 1213 | |
| 1214 | @Override |
| 1215 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 1216 | if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null |
| 1217 | && resultCode != RESULT_CANCELED) { |
| 1218 | getPackageManager().setComponentEnabledSetting(mCurrentSuggestion, |
| 1219 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); |
| 1220 | } |
| 1221 | super.onActivityResult(requestCode, resultCode, data); |
| 1222 | } |
| 1223 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 1224 | } |