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