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