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; |
jackqdyulei | 6c355f5 | 2017-03-01 17:37:23 -0800 | [diff] [blame] | 33 | import android.graphics.Bitmap; |
jackqdyulei | 6c355f5 | 2017-03-01 17:37:23 -0800 | [diff] [blame] | 34 | import android.graphics.Canvas; |
| 35 | import android.graphics.drawable.Drawable; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 36 | import android.nfc.NfcAdapter; |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 37 | import android.os.AsyncTask; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 38 | import android.os.Bundle; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 39 | import android.os.UserHandle; |
| 40 | import android.os.UserManager; |
Fan Zhang | a3e8f5c | 2016-12-01 09:52:10 -0800 | [diff] [blame] | 41 | import android.support.annotation.VisibleForTesting; |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 42 | import android.support.v14.preference.PreferenceFragment; |
| 43 | import android.support.v7.preference.Preference; |
| 44 | import android.support.v7.preference.PreferenceManager; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 45 | import android.text.TextUtils; |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 46 | import android.transition.TransitionManager; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 47 | import android.util.Log; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 48 | import android.view.Menu; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 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; |
Fan Zhang | 2869157 | 2016-03-23 15:31:08 -0700 | [diff] [blame] | 53 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 54 | import com.android.internal.util.ArrayUtils; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 55 | import com.android.settings.Settings.WifiSettingsActivity; |
Anton Philippov | adfec55 | 2017-01-25 20:37:36 +0000 | [diff] [blame] | 56 | import com.android.settings.backup.BackupSettingsActivity; |
Fan Zhang | a3e8f5c | 2016-12-01 09:52:10 -0800 | [diff] [blame] | 57 | import com.android.settings.core.gateway.SettingsGateway; |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 58 | import com.android.settings.core.instrumentation.MetricsFeatureProvider; |
Fan Zhang | 5f79ae9 | 2016-08-18 16:04:19 -0700 | [diff] [blame] | 59 | import com.android.settings.core.instrumentation.SharedPreferencesLogger; |
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; |
Fan Zhang | 11d2d68 | 2017-03-17 16:19:26 -0700 | [diff] [blame] | 62 | import com.android.settings.development.DevelopmentSettings; |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 63 | import com.android.settings.overlay.FeatureFactory; |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 64 | import com.android.settings.search.DynamicIndexableContentMonitor; |
Matthew Fritze | 0ed37c3 | 2016-10-24 10:12:49 -0700 | [diff] [blame] | 65 | import com.android.settings.search2.SearchFeatureProvider; |
Fan Zhang | 4fcd5ed | 2017-03-10 12:25:35 -0800 | [diff] [blame] | 66 | import com.android.settings.wfd.WifiDisplaySettings; |
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 | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 70 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 71 | import java.util.ArrayList; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 72 | import java.util.List; |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 73 | import java.util.Set; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 74 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 75 | public class SettingsActivity extends SettingsDrawerActivity |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 76 | implements PreferenceManager.OnPreferenceTreeClickListener, |
| 77 | PreferenceFragment.OnPreferenceStartFragmentCallback, |
Matthew Fritze | 0b431fc | 2017-03-16 13:19:20 -0700 | [diff] [blame] | 78 | ButtonBarHandler, FragmentManager.OnBackStackChangedListener { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 79 | |
| 80 | private static final String LOG_TAG = "Settings"; |
| 81 | |
Matthew Fritze | be0989c | 2017-04-25 09:38:56 -0700 | [diff] [blame^] | 82 | public static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1; |
Philip P. Moltmann | d9779db | 2016-02-24 12:11:05 -0800 | [diff] [blame] | 83 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 84 | // Constants for state save/restore |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 85 | private static final String SAVE_KEY_CATEGORIES = ":settings:categories"; |
Matthew Fritze | 7d48ae8 | 2017-03-23 08:59:15 -0700 | [diff] [blame] | 86 | @VisibleForTesting |
| 87 | static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up"; |
| 88 | @VisibleForTesting |
| 89 | static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * When starting this activity, the invoking Intent can contain this extra |
| 93 | * string to specify which fragment should be initially displayed. |
| 94 | * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity |
| 95 | * will call isValidFragment() to confirm that the fragment class name is valid for this |
| 96 | * activity. |
| 97 | */ |
| 98 | public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment"; |
| 99 | |
| 100 | /** |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 101 | * The metrics category constant for logging source when a setting fragment is opened. |
| 102 | */ |
| 103 | public static final String EXTRA_SOURCE_METRICS_CATEGORY = ":settings:source_metrics"; |
| 104 | |
| 105 | /** |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 106 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
| 107 | * this extra can also be specified to supply a Bundle of arguments to pass |
| 108 | * to that fragment when it is instantiated during the initial creation |
| 109 | * of the activity. |
| 110 | */ |
| 111 | public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; |
| 112 | |
| 113 | /** |
Fabrice Di Meglio | c145732 | 2014-04-04 19:07:50 -0700 | [diff] [blame] | 114 | * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS} |
| 115 | */ |
| 116 | public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; |
| 117 | |
Fabrice Di Meglio | 6f0739a | 2014-02-03 18:12:25 -0800 | [diff] [blame] | 118 | public static final String BACK_STACK_PREFS = ":settings:prefs"; |
| 119 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 120 | // extras that allow any preference activity to be launched as part of a wizard |
| 121 | |
| 122 | // show Back and Next buttons? takes boolean parameter |
| 123 | // Back will then return RESULT_CANCELED and Next RESULT_OK |
| 124 | protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
| 125 | |
| 126 | // add a Skip button? |
| 127 | private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip"; |
| 128 | |
| 129 | // specify custom text for the Back or Next buttons, or cause a button to not appear |
| 130 | // at all by setting it to null |
| 131 | protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; |
| 132 | protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; |
| 133 | |
| 134 | /** |
| 135 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 136 | * 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] | 137 | * that fragment. |
| 138 | */ |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 139 | public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; |
Alexandra Gherghina | 62464b8 | 2014-08-11 12:40:13 +0100 | [diff] [blame] | 140 | /** |
| 141 | * The package name used to resolve the title resource id. |
| 142 | */ |
| 143 | public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME = |
| 144 | ":settings:show_fragment_title_res_package_name"; |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 145 | public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = |
| 146 | ":settings:show_fragment_title_resid"; |
| 147 | public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = |
| 148 | ":settings:show_fragment_as_shortcut"; |
| 149 | |
| 150 | public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING = |
| 151 | ":settings:show_fragment_as_subsetting"; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 152 | |
Fan Zhang | 78ab9f9 | 2017-02-27 16:10:05 -0800 | [diff] [blame] | 153 | @Deprecated |
Udam Saini | 92779ce | 2016-03-28 14:29:48 -0700 | [diff] [blame] | 154 | public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer"; |
| 155 | |
Jason Monk | 3069581 | 2015-11-17 09:01:08 -0500 | [diff] [blame] | 156 | public static final String META_DATA_KEY_FRAGMENT_CLASS = |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 157 | "com.android.settings.FRAGMENT_CLASS"; |
| 158 | |
| 159 | private static final String EXTRA_UI_OPTIONS = "settings:ui_options"; |
| 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 | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 168 | private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = { |
| 169 | "android.settings.APPLICATION_DETAILS_SETTINGS" |
| 170 | }; |
| 171 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 172 | private SharedPreferences mDevelopmentPreferences; |
| 173 | private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener; |
| 174 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 175 | private boolean mBatteryPresent = true; |
| 176 | private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 177 | @Override |
| 178 | public void onReceive(Context context, Intent intent) { |
| 179 | String action = intent.getAction(); |
| 180 | if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
| 181 | boolean batteryPresent = Utils.isBatteryPresent(intent); |
| 182 | |
| 183 | if (mBatteryPresent != batteryPresent) { |
| 184 | mBatteryPresent = batteryPresent; |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 185 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | } |
| 189 | }; |
| 190 | |
Fan Zhang | a3e8f5c | 2016-12-01 09:52:10 -0800 | [diff] [blame] | 191 | private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor; |
Svetoslav | 853e471 | 2014-04-14 10:10:25 -0700 | [diff] [blame] | 192 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 193 | private ActionBar mActionBar; |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 194 | private SwitchBar mSwitchBar; |
| 195 | |
| 196 | private Button mNextButton; |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 197 | |
Matthew Fritze | 7d48ae8 | 2017-03-23 08:59:15 -0700 | [diff] [blame] | 198 | @VisibleForTesting |
| 199 | boolean mDisplayHomeAsUpEnabled; |
| 200 | @VisibleForTesting |
| 201 | boolean mDisplaySearch; |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 202 | |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 203 | private boolean mIsShowingDashboard; |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 204 | private boolean mIsShortcut; |
Fabrice Di Meglio | 35062d6 | 2014-05-13 14:39:41 -0700 | [diff] [blame] | 205 | |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 206 | private ViewGroup mContent; |
| 207 | |
Matthew Fritze | 0ed37c3 | 2016-10-24 10:12:49 -0700 | [diff] [blame] | 208 | private SearchFeatureProvider mSearchFeatureProvider; |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 209 | private MetricsFeatureProvider mMetricsFeatureProvider; |
Matthew Fritze | 0ed37c3 | 2016-10-24 10:12:49 -0700 | [diff] [blame] | 210 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 211 | // Categories |
Fan Zhang | a3e8f5c | 2016-12-01 09:52:10 -0800 | [diff] [blame] | 212 | private ArrayList<DashboardCategory> mCategories = new ArrayList<>(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 213 | |
Fan Zhang | a96a2d8 | 2016-09-27 17:51:11 -0700 | [diff] [blame] | 214 | private DashboardFeatureProvider mDashboardFeatureProvider; |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 215 | private ComponentName mCurrentSuggestion; |
Jim Miller | 0698a21 | 2014-10-16 19:49:07 -0700 | [diff] [blame] | 216 | |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 217 | public SwitchBar getSwitchBar() { |
| 218 | return mSwitchBar; |
| 219 | } |
| 220 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 221 | @Override |
| 222 | public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 223 | startPreferencePanel(caller, pref.getFragment(), pref.getExtras(), -1, pref.getTitle(), |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 224 | null, 0); |
| 225 | return true; |
| 226 | } |
| 227 | |
| 228 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 229 | public boolean onPreferenceTreeClick(Preference preference) { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 230 | return false; |
| 231 | } |
| 232 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 233 | @Override |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 234 | public boolean onCreateOptionsMenu(Menu menu) { |
Fabrice Di Meglio | 3d35ec7 | 2014-06-06 12:13:29 -0700 | [diff] [blame] | 235 | if (!mDisplaySearch) { |
| 236 | return false; |
| 237 | } |
Matthew Fritze | 0b431fc | 2017-03-16 13:19:20 -0700 | [diff] [blame] | 238 | mSearchFeatureProvider.setUpSearchMenu(menu, this); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 239 | return true; |
| 240 | } |
| 241 | |
Jason Monk | 31c7c32 | 2016-01-20 14:41:52 -0500 | [diff] [blame] | 242 | @Override |
| 243 | public SharedPreferences getSharedPreferences(String name, int mode) { |
| 244 | if (name.equals(getPackageName() + "_preferences")) { |
Jason Monk | e4ebcd1 | 2016-02-21 09:37:41 -0500 | [diff] [blame] | 245 | return new SharedPreferencesLogger(this, getMetricsTag()); |
Jason Monk | 31c7c32 | 2016-01-20 14:41:52 -0500 | [diff] [blame] | 246 | } |
| 247 | return super.getSharedPreferences(name, mode); |
| 248 | } |
| 249 | |
Jason Monk | e4ebcd1 | 2016-02-21 09:37:41 -0500 | [diff] [blame] | 250 | private String getMetricsTag() { |
| 251 | String tag = getClass().getName(); |
| 252 | if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) { |
| 253 | tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); |
| 254 | } |
| 255 | if (tag.startsWith("com.android.settings.")) { |
| 256 | tag = tag.replace("com.android.settings.", ""); |
| 257 | } |
| 258 | return tag; |
| 259 | } |
| 260 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 261 | private static boolean isShortCutIntent(final Intent intent) { |
| 262 | Set<String> categories = intent.getCategories(); |
| 263 | return (categories != null) && categories.contains("com.android.settings.SHORTCUT"); |
| 264 | } |
| 265 | |
Fabrice Di Meglio | 5b3c3c0 | 2014-06-30 15:18:08 -0700 | [diff] [blame] | 266 | private static boolean isLikeShortCutIntent(final Intent intent) { |
Fabrice Di Meglio | 5b7a100 | 2014-06-23 17:54:40 -0700 | [diff] [blame] | 267 | String action = intent.getAction(); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 268 | if (action == null) { |
| 269 | return false; |
| 270 | } |
| 271 | for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) { |
| 272 | if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true; |
| 273 | } |
| 274 | return false; |
Fabrice Di Meglio | 5b7a100 | 2014-06-23 17:54:40 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 277 | @Override |
| 278 | protected void onCreate(Bundle savedState) { |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 279 | super.onCreate(savedState); |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 280 | long startTime = System.currentTimeMillis(); |
Matthew Fritze | 0ed37c3 | 2016-10-24 10:12:49 -0700 | [diff] [blame] | 281 | |
| 282 | final FeatureFactory factory = FeatureFactory.getFactory(this); |
| 283 | |
| 284 | mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this); |
Matthew Fritze | 9955db6 | 2016-12-20 09:37:21 -0800 | [diff] [blame] | 285 | mSearchFeatureProvider = factory.getSearchFeatureProvider(); |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 286 | mMetricsFeatureProvider = factory.getMetricsFeatureProvider(); |
Matthew Fritze | 0ed37c3 | 2016-10-24 10:12:49 -0700 | [diff] [blame] | 287 | |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 288 | // Should happen before any call to getIntent() |
| 289 | getMetaData(); |
| 290 | |
| 291 | final Intent intent = getIntent(); |
| 292 | if (intent.hasExtra(EXTRA_UI_OPTIONS)) { |
| 293 | getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 294 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 295 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 296 | mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, |
| 297 | Context.MODE_PRIVATE); |
| 298 | |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 299 | // Getting Intent properties can only be done after the super.onCreate(...) |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 300 | final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 301 | |
Fabrice Di Meglio | 5b3c3c0 | 2014-06-30 15:18:08 -0700 | [diff] [blame] | 302 | mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) || |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 303 | intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false); |
| 304 | |
Fabrice Di Meglio | e817a66 | 2014-07-16 19:51:06 -0700 | [diff] [blame] | 305 | final ComponentName cn = intent.getComponent(); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 306 | final String className = cn.getClassName(); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 307 | |
Doris Ling | 1694d4b | 2017-03-03 14:21:37 -0800 | [diff] [blame] | 308 | mIsShowingDashboard = className.equals(Settings.class.getName()); |
Fabrice Di Meglio | 5a62d94 | 2014-07-01 17:18:40 -0700 | [diff] [blame] | 309 | |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 310 | // This is a "Sub Settings" when: |
| 311 | // - this is a real SubSettings |
| 312 | // - or :settings:show_fragment_as_subsetting is passed to the Intent |
Jorim Jaggi | 4dfcb82 | 2015-04-29 17:21:32 -0700 | [diff] [blame] | 313 | final boolean isSubSettings = this instanceof SubSettings || |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 314 | intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false); |
| 315 | |
Fan Zhang | 92f1e94 | 2017-01-21 10:07:26 -0800 | [diff] [blame] | 316 | // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content |
| 317 | // insets |
Fabrice Di Meglio | 61a1fec | 2014-08-13 16:22:38 -0700 | [diff] [blame] | 318 | if (isSubSettings) { |
Fan Zhang | 92f1e94 | 2017-01-21 10:07:26 -0800 | [diff] [blame] | 319 | setTheme(R.style.Theme_SubSettings); |
Fabrice Di Meglio | da8baba | 2014-06-10 17:12:51 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Fabrice Di Meglio | d40dd45 | 2014-07-18 15:20:34 -0700 | [diff] [blame] | 322 | setContentView(mIsShowingDashboard ? |
| 323 | R.layout.settings_main_dashboard : R.layout.settings_main_prefs); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 324 | |
Anna Galusza | 6b1e9db | 2016-03-30 17:25:36 -0700 | [diff] [blame] | 325 | mContent = (ViewGroup) findViewById(R.id.main_content); |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 326 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 327 | getFragmentManager().addOnBackStackChangedListener(this); |
| 328 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 329 | if (savedState != null) { |
Fabrice Di Meglio | 1800a9f | 2014-04-03 19:31:07 -0700 | [diff] [blame] | 330 | // We are restarting from a previous saved state; used that to initialize, instead |
| 331 | // of starting fresh. |
Fabrice Di Meglio | 0d643fd | 2014-06-16 20:11:27 -0700 | [diff] [blame] | 332 | setTitleFromIntent(intent); |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 333 | |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 334 | ArrayList<DashboardCategory> categories = |
| 335 | savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); |
| 336 | if (categories != null) { |
Fabrice Di Meglio | 5f99572 | 2014-05-19 19:51:31 -0700 | [diff] [blame] | 337 | mCategories.clear(); |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 338 | mCategories.addAll(categories); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 339 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 340 | } |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 341 | |
| 342 | mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); |
Salvador Martinez | 2368e54 | 2016-07-25 18:16:47 -0700 | [diff] [blame] | 343 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 344 | } else { |
Doris Ling | cb69baf | 2017-02-23 17:50:03 -0800 | [diff] [blame] | 345 | launchSettingFragment(initialFragmentName, isSubSettings, intent); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 346 | } |
| 347 | |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 348 | mActionBar = getActionBar(); |
Fabrice Di Meglio | d8aec08 | 2014-05-20 10:49:50 -0700 | [diff] [blame] | 349 | if (mActionBar != null) { |
| 350 | mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled); |
| 351 | mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled); |
| 352 | } |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 353 | mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar); |
Jason Monk | e4ebcd1 | 2016-02-21 09:37:41 -0500 | [diff] [blame] | 354 | if (mSwitchBar != null) { |
| 355 | mSwitchBar.setMetricsTag(getMetricsTag()); |
| 356 | } |
Fabrice Di Meglio | 4193776 | 2014-05-13 19:51:59 -0700 | [diff] [blame] | 357 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 358 | // see if we should show Back/Next buttons |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 359 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { |
| 360 | |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 361 | View buttonBar = findViewById(R.id.button_bar); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 362 | if (buttonBar != null) { |
| 363 | buttonBar.setVisibility(View.VISIBLE); |
| 364 | |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 365 | Button backButton = (Button)findViewById(R.id.back_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 366 | backButton.setOnClickListener(new OnClickListener() { |
| 367 | public void onClick(View v) { |
Matthew Fritze | 0b431fc | 2017-03-16 13:19:20 -0700 | [diff] [blame] | 368 | setResult(RESULT_CANCELED, null); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 369 | finish(); |
| 370 | } |
| 371 | }); |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 372 | Button skipButton = (Button)findViewById(R.id.skip_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 373 | skipButton.setOnClickListener(new OnClickListener() { |
| 374 | public void onClick(View v) { |
Matthew Fritze | 0b431fc | 2017-03-16 13:19:20 -0700 | [diff] [blame] | 375 | setResult(RESULT_OK, null); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 376 | finish(); |
| 377 | } |
| 378 | }); |
Fabrice Di Meglio | d2b64f3 | 2014-05-20 12:55:15 -0700 | [diff] [blame] | 379 | mNextButton = (Button)findViewById(R.id.next_button); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 380 | mNextButton.setOnClickListener(new OnClickListener() { |
| 381 | public void onClick(View v) { |
Matthew Fritze | 0b431fc | 2017-03-16 13:19:20 -0700 | [diff] [blame] | 382 | setResult(RESULT_OK, null); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 383 | finish(); |
| 384 | } |
| 385 | }); |
| 386 | |
| 387 | // set our various button parameters |
| 388 | if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { |
| 389 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); |
| 390 | if (TextUtils.isEmpty(buttonText)) { |
| 391 | mNextButton.setVisibility(View.GONE); |
| 392 | } |
| 393 | else { |
| 394 | mNextButton.setText(buttonText); |
| 395 | } |
| 396 | } |
| 397 | if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { |
| 398 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); |
| 399 | if (TextUtils.isEmpty(buttonText)) { |
| 400 | backButton.setVisibility(View.GONE); |
| 401 | } |
| 402 | else { |
| 403 | backButton.setText(buttonText); |
| 404 | } |
| 405 | } |
| 406 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { |
| 407 | skipButton.setVisibility(View.VISIBLE); |
| 408 | } |
| 409 | } |
| 410 | } |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 411 | |
Fan Zhang | efba6b4 | 2017-02-07 17:40:59 -0800 | [diff] [blame] | 412 | if (DEBUG_TIMING) { |
| 413 | Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms"); |
| 414 | } |
Fabrice Di Meglio | ceb335f | 2014-07-23 16:25:30 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Doris Ling | cb69baf | 2017-02-23 17:50:03 -0800 | [diff] [blame] | 417 | @VisibleForTesting |
| 418 | void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) { |
| 419 | if (!mIsShowingDashboard && initialFragmentName != null) { |
| 420 | mDisplaySearch = false; |
| 421 | // UP will be shown only if it is a sub settings |
| 422 | if (mIsShortcut) { |
| 423 | mDisplayHomeAsUpEnabled = isSubSettings; |
| 424 | } else if (isSubSettings) { |
| 425 | mDisplayHomeAsUpEnabled = true; |
| 426 | } else { |
| 427 | mDisplayHomeAsUpEnabled = false; |
| 428 | } |
| 429 | setTitleFromIntent(intent); |
| 430 | |
| 431 | Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); |
| 432 | switchToFragment(initialFragmentName, initialArguments, true, false, |
| 433 | mInitialTitleResId, mInitialTitle, false); |
| 434 | } else { |
| 435 | // No UP affordance if we are displaying the main Dashboard |
| 436 | mDisplayHomeAsUpEnabled = false; |
| 437 | // Show Search affordance |
| 438 | mDisplaySearch = true; |
| 439 | mInitialTitleResId = R.string.dashboard_title; |
| 440 | |
| 441 | switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false, |
| 442 | mInitialTitleResId, mInitialTitle, false); |
| 443 | } |
| 444 | } |
| 445 | |
Fan Zhang | ece8ff6 | 2016-06-30 13:20:12 -0700 | [diff] [blame] | 446 | public void setDisplaySearchMenu(boolean displaySearch) { |
| 447 | if (displaySearch != mDisplaySearch) { |
| 448 | mDisplaySearch = displaySearch; |
| 449 | invalidateOptionsMenu(); |
| 450 | } |
| 451 | } |
| 452 | |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 453 | private void setTitleFromIntent(Intent intent) { |
| 454 | final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1); |
| 455 | if (initialTitleResId > 0) { |
| 456 | mInitialTitle = null; |
| 457 | mInitialTitleResId = initialTitleResId; |
Alexandra Gherghina | 62464b8 | 2014-08-11 12:40:13 +0100 | [diff] [blame] | 458 | |
| 459 | final String initialTitleResPackageName = intent.getStringExtra( |
| 460 | EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME); |
| 461 | if (initialTitleResPackageName != null) { |
| 462 | try { |
| 463 | Context authContext = createPackageContextAsUser(initialTitleResPackageName, |
| 464 | 0 /* flags */, new UserHandle(UserHandle.myUserId())); |
| 465 | mInitialTitle = authContext.getResources().getText(mInitialTitleResId); |
| 466 | setTitle(mInitialTitle); |
| 467 | mInitialTitleResId = -1; |
| 468 | return; |
| 469 | } catch (NameNotFoundException e) { |
| 470 | Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName); |
| 471 | } |
| 472 | } else { |
| 473 | setTitle(mInitialTitleResId); |
| 474 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 475 | } else { |
| 476 | mInitialTitleResId = -1; |
| 477 | final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); |
| 478 | mInitialTitle = (initialTitle != null) ? initialTitle : getTitle(); |
| 479 | setTitle(mInitialTitle); |
| 480 | } |
| 481 | } |
| 482 | |
Fabrice Di Meglio | c95be4f | 2014-03-07 12:57:38 -0800 | [diff] [blame] | 483 | @Override |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 484 | public void onBackStackChanged() { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 485 | setTitleFromBackStack(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Fan Zhang | 2869157 | 2016-03-23 15:31:08 -0700 | [diff] [blame] | 488 | private void setTitleFromBackStack() { |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 489 | final int count = getFragmentManager().getBackStackEntryCount(); |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 490 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 491 | if (count == 0) { |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 492 | if (mInitialTitleResId > 0) { |
| 493 | setTitle(mInitialTitleResId); |
| 494 | } else { |
| 495 | setTitle(mInitialTitle); |
| 496 | } |
Fan Zhang | 2869157 | 2016-03-23 15:31:08 -0700 | [diff] [blame] | 497 | return; |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 498 | } |
Fabrice Di Meglio | b643cbf | 2014-03-10 12:18:39 -0700 | [diff] [blame] | 499 | |
Fabrice Di Meglio | 8eb3f0f | 2014-02-27 15:51:46 -0800 | [diff] [blame] | 500 | FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1); |
| 501 | setTitleFromBackStackEntry(bse); |
| 502 | } |
| 503 | |
| 504 | private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) { |
| 505 | final CharSequence title; |
| 506 | final int titleRes = bse.getBreadCrumbTitleRes(); |
| 507 | if (titleRes > 0) { |
| 508 | title = getText(titleRes); |
| 509 | } else { |
| 510 | title = bse.getBreadCrumbTitle(); |
| 511 | } |
| 512 | if (title != null) { |
| 513 | setTitle(title); |
| 514 | } |
Fabrice Di Meglio | 5529d29 | 2014-02-11 19:52:28 -0800 | [diff] [blame] | 515 | } |
| 516 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 517 | @Override |
| 518 | protected void onSaveInstanceState(Bundle outState) { |
| 519 | super.onSaveInstanceState(outState); |
Matthew Fritze | 7d48ae8 | 2017-03-23 08:59:15 -0700 | [diff] [blame] | 520 | saveState(outState); |
| 521 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 522 | |
Matthew Fritze | 7d48ae8 | 2017-03-23 08:59:15 -0700 | [diff] [blame] | 523 | /** |
| 524 | * For testing purposes to avoid crashes from final variables in Activity's onSaveInstantState. |
| 525 | */ |
| 526 | @VisibleForTesting |
| 527 | void saveState(Bundle outState) { |
Fabrice Di Meglio | 769630c | 2014-04-24 14:48:48 -0700 | [diff] [blame] | 528 | if (mCategories.size() > 0) { |
| 529 | outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 530 | } |
Fabrice Di Meglio | d6985df | 2014-04-03 16:43:26 -0700 | [diff] [blame] | 531 | |
Fabrice Di Meglio | b731dd0 | 2014-04-03 18:40:38 -0700 | [diff] [blame] | 532 | outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled); |
Matthew Fritze | 7d48ae8 | 2017-03-23 08:59:15 -0700 | [diff] [blame] | 533 | outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch); |
| 534 | } |
| 535 | |
| 536 | @Override |
| 537 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 538 | super.onRestoreInstanceState(savedInstanceState); |
| 539 | |
| 540 | mDisplayHomeAsUpEnabled = savedInstanceState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP); |
| 541 | mDisplaySearch = savedInstanceState.getBoolean(SAVE_KEY_SHOW_SEARCH); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 545 | protected void onResume() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 546 | super.onResume(); |
| 547 | |
| 548 | mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() { |
| 549 | @Override |
| 550 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 551 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 552 | } |
| 553 | }; |
| 554 | mDevelopmentPreferences.registerOnSharedPreferenceChangeListener( |
| 555 | mDevelopmentPreferencesListener); |
| 556 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 557 | registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); |
Fan Zhang | a3e8f5c | 2016-12-01 09:52:10 -0800 | [diff] [blame] | 558 | if (mDynamicIndexableContentMonitor == null) { |
| 559 | mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor(); |
| 560 | } |
Philip P. Moltmann | d9779db | 2016-02-24 12:11:05 -0800 | [diff] [blame] | 561 | mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR); |
Fabrice Di Meglio | a327076 | 2014-04-16 16:54:56 -0700 | [diff] [blame] | 562 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 563 | updateTilesList(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 567 | protected void onPause() { |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 568 | super.onPause(); |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 569 | mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( |
| 570 | mDevelopmentPreferencesListener); |
| 571 | mDevelopmentPreferencesListener = null; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 572 | unregisterReceiver(mBatteryInfoReceiver); |
Fan Zhang | a3e8f5c | 2016-12-01 09:52:10 -0800 | [diff] [blame] | 573 | if (mDynamicIndexableContentMonitor != null) { |
Tadashi G. Takaoka | a034fa5 | 2016-11-21 14:20:19 +0900 | [diff] [blame] | 574 | mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR); |
Fan Zhang | a3e8f5c | 2016-12-01 09:52:10 -0800 | [diff] [blame] | 575 | } |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | @Override |
jackqdyulei | 6c355f5 | 2017-03-01 17:37:23 -0800 | [diff] [blame] | 579 | public void setTaskDescription(ActivityManager.TaskDescription taskDescription) { |
| 580 | final Bitmap icon = getBitmapFromXmlResource(R.drawable.ic_launcher_settings); |
| 581 | taskDescription.setIcon(icon); |
| 582 | super.setTaskDescription(taskDescription); |
| 583 | } |
| 584 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 585 | protected boolean isValidFragment(String fragmentName) { |
| 586 | // Almost all fragments are wrapped in this, |
| 587 | // except for a few that have their own activities. |
Fan Zhang | a3e8f5c | 2016-12-01 09:52:10 -0800 | [diff] [blame] | 588 | for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) { |
| 589 | if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 590 | } |
| 591 | return false; |
| 592 | } |
| 593 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 594 | @Override |
| 595 | public Intent getIntent() { |
| 596 | Intent superIntent = super.getIntent(); |
| 597 | String startingFragment = getStartingFragmentClass(superIntent); |
| 598 | // This is called from super.onCreate, isMultiPane() is not yet reliable |
| 599 | // Do not use onIsHidingHeaders either, which relies itself on this method |
| 600 | if (startingFragment != null) { |
| 601 | Intent modIntent = new Intent(superIntent); |
| 602 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment); |
| 603 | Bundle args = superIntent.getExtras(); |
| 604 | if (args != null) { |
| 605 | args = new Bundle(args); |
| 606 | } else { |
| 607 | args = new Bundle(); |
| 608 | } |
| 609 | args.putParcelable("intent", superIntent); |
Kenny Guy | ac1e20e | 2014-06-24 14:34:14 +0100 | [diff] [blame] | 610 | modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 611 | return modIntent; |
| 612 | } |
| 613 | return superIntent; |
| 614 | } |
| 615 | |
| 616 | /** |
| 617 | * Checks if the component name in the intent is different from the Settings class and |
| 618 | * returns the class name to load as a fragment. |
| 619 | */ |
| 620 | private String getStartingFragmentClass(Intent intent) { |
| 621 | if (mFragmentClass != null) return mFragmentClass; |
| 622 | |
| 623 | String intentClass = intent.getComponent().getClassName(); |
| 624 | if (intentClass.equals(getClass().getName())) return null; |
| 625 | |
| 626 | if ("com.android.settings.ManageApplications".equals(intentClass) |
| 627 | || "com.android.settings.RunningServices".equals(intentClass) |
| 628 | || "com.android.settings.applications.StorageUse".equals(intentClass)) { |
| 629 | // Old names of manage apps. |
| 630 | intentClass = com.android.settings.applications.ManageApplications.class.getName(); |
| 631 | } |
| 632 | |
| 633 | return intentClass; |
| 634 | } |
| 635 | |
| 636 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 637 | * Start a new fragment containing a preference panel. If the preferences |
| 638 | * are being displayed in multi-pane mode, the given fragment class will |
| 639 | * be instantiated and placed in the appropriate pane. If running in |
| 640 | * single-pane mode, a new activity will be launched in which to show the |
| 641 | * fragment. |
| 642 | * |
| 643 | * @param fragmentClass Full name of the class implementing the fragment. |
| 644 | * @param args Any desired arguments to supply to the fragment. |
| 645 | * @param titleRes Optional resource identifier of the title of this |
| 646 | * fragment. |
| 647 | * @param titleText Optional text of the title of this fragment. |
| 648 | * @param resultTo Optional fragment that result data should be sent to. |
| 649 | * If non-null, resultTo.onActivityResult() will be called when this |
| 650 | * preference panel is done. The launched panel must use |
| 651 | * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. |
| 652 | * @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] | 653 | * request code to be received with the result. |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 654 | */ |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 655 | public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args, |
| 656 | int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) { |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 657 | String title = null; |
| 658 | if (titleRes < 0) { |
| 659 | if (titleText != null) { |
| 660 | title = titleText.toString(); |
| 661 | } else { |
| 662 | // There not much we can do in that case |
| 663 | title = ""; |
| 664 | } |
Fabrice Di Meglio | 911fb2a | 2014-04-04 17:55:57 -0700 | [diff] [blame] | 665 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 666 | Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 667 | titleRes, title, mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller)); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /** |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 671 | * Start a new fragment in a new activity containing a preference panel for a given user. If the |
| 672 | * preferences are being displayed in multi-pane mode, the given fragment class will be |
| 673 | * instantiated and placed in the appropriate pane. If running in single-pane mode, a new |
| 674 | * activity will be launched in which to show the fragment. |
| 675 | * |
| 676 | * @param fragmentClass Full name of the class implementing the fragment. |
| 677 | * @param args Any desired arguments to supply to the fragment. |
| 678 | * @param titleRes Optional resource identifier of the title of this fragment. |
| 679 | * @param titleText Optional text of the title of this fragment. |
| 680 | * @param userHandle The user for which the panel has to be started. |
| 681 | */ |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 682 | public void startPreferencePanelAsUser(Fragment caller, String fragmentClass, |
| 683 | Bundle args, int titleRes, CharSequence titleText, UserHandle userHandle) { |
Lifu Tang | d033285 | 2015-04-02 12:05:46 -0700 | [diff] [blame] | 684 | // This is a workaround. |
| 685 | // |
| 686 | // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent |
| 687 | // starting the fragment could cause a native stack corruption. See b/17523189. However, |
| 688 | // adding that flag and start the preference panel with the same UserHandler will make it |
| 689 | // impossible to use back button to return to the previous screen. See b/20042570. |
| 690 | // |
| 691 | // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing |
| 692 | // another check here to call startPreferencePanel() instead of startWithFragmentAsUser() |
| 693 | // when we're calling it as the same user. |
| 694 | if (userHandle.getIdentifier() == UserHandle.myUserId()) { |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 695 | startPreferencePanel(caller, fragmentClass, args, titleRes, titleText, null, 0); |
Lifu Tang | d033285 | 2015-04-02 12:05:46 -0700 | [diff] [blame] | 696 | } else { |
| 697 | String title = null; |
| 698 | if (titleRes < 0) { |
| 699 | if (titleText != null) { |
| 700 | title = titleText.toString(); |
| 701 | } else { |
| 702 | // There not much we can do in that case |
| 703 | title = ""; |
| 704 | } |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 705 | } |
Fan Zhang | c6ca314 | 2017-02-14 15:02:35 -0800 | [diff] [blame] | 706 | Utils.startWithFragmentAsUser(this, fragmentClass, args, titleRes, title, |
| 707 | mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller), userHandle); |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 708 | } |
Zoltan Szatmary-Ban | 7a2ccf2 | 2014-09-18 10:26:11 +0100 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /** |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 712 | * Called by a preference panel fragment to finish itself. |
| 713 | * |
| 714 | * @param caller The fragment that is asking to be finished. |
| 715 | * @param resultCode Optional result code to send back to the original |
| 716 | * launching fragment. |
| 717 | * @param resultData Optional result data to send back to the original |
| 718 | * launching fragment. |
| 719 | */ |
| 720 | public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { |
| 721 | setResult(resultCode, resultData); |
Fabrice Di Meglio | 58146c2 | 2014-06-26 16:20:26 -0700 | [diff] [blame] | 722 | finish(); |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /** |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 726 | * Start a new fragment. |
| 727 | * |
| 728 | * @param fragment The fragment to start |
| 729 | * @param push If true, the current fragment will be pushed onto the back stack. If false, |
| 730 | * the current fragment will be replaced. |
| 731 | */ |
| 732 | public void startPreferenceFragment(Fragment fragment, boolean push) { |
| 733 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Anna Galusza | 6b1e9db | 2016-03-30 17:25:36 -0700 | [diff] [blame] | 734 | transaction.replace(R.id.main_content, fragment); |
Fabrice Di Meglio | 10afdb8 | 2014-02-11 19:50:56 +0000 | [diff] [blame] | 735 | if (push) { |
| 736 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 737 | transaction.addToBackStack(BACK_STACK_PREFS); |
| 738 | } else { |
| 739 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); |
| 740 | } |
| 741 | transaction.commitAllowingStateLoss(); |
| 742 | } |
| 743 | |
| 744 | /** |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 745 | * Switch to a specific Fragment with taking care of validation, Title and BackStack |
| 746 | */ |
| 747 | private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 748 | boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 749 | if (validate && !isValidFragment(fragmentName)) { |
| 750 | throw new IllegalArgumentException("Invalid fragment for this activity: " |
| 751 | + fragmentName); |
| 752 | } |
| 753 | Fragment f = Fragment.instantiate(this, fragmentName, args); |
| 754 | FragmentTransaction transaction = getFragmentManager().beginTransaction(); |
Anna Galusza | 6b1e9db | 2016-03-30 17:25:36 -0700 | [diff] [blame] | 755 | transaction.replace(R.id.main_content, f); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 756 | if (withTransition) { |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 757 | TransitionManager.beginDelayedTransition(mContent); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 758 | } |
| 759 | if (addToBackStack) { |
| 760 | transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); |
| 761 | } |
Fabrice Di Meglio | a9e7799 | 2014-06-09 12:52:24 -0700 | [diff] [blame] | 762 | if (titleResId > 0) { |
| 763 | transaction.setBreadCrumbTitle(titleResId); |
| 764 | } else if (title != null) { |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 765 | transaction.setBreadCrumbTitle(title); |
| 766 | } |
| 767 | transaction.commitAllowingStateLoss(); |
Fabrice Di Meglio | 59a4055 | 2014-05-23 16:46:50 -0700 | [diff] [blame] | 768 | getFragmentManager().executePendingTransactions(); |
Fabrice Di Meglio | d25314d | 2014-03-21 19:24:43 -0700 | [diff] [blame] | 769 | return f; |
| 770 | } |
| 771 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 772 | private void updateTilesList() { |
Jason Monk | fd2c722 | 2015-12-02 15:38:38 -0500 | [diff] [blame] | 773 | // Generally the items that are will be changing from these updates will |
| 774 | // not be in the top list of tiles, so run it in the background and the |
| 775 | // SettingsDrawerActivity will pick up on the updates automatically. |
| 776 | AsyncTask.execute(new Runnable() { |
| 777 | @Override |
| 778 | public void run() { |
| 779 | doUpdateTilesList(); |
| 780 | } |
| 781 | }); |
| 782 | } |
| 783 | |
| 784 | private void doUpdateTilesList() { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 785 | PackageManager pm = getPackageManager(); |
Xiaohui Chen | 44879a3 | 2015-07-22 13:53:22 -0700 | [diff] [blame] | 786 | final UserManager um = UserManager.get(this); |
| 787 | final boolean isAdmin = um.isAdminUser(); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 788 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 789 | String packageName = getPackageName(); |
| 790 | setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 791 | pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 792 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 793 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 794 | Settings.BluetoothSettingsActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 795 | pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 796 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 797 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 798 | Settings.DataUsageSummaryActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 799 | Utils.isBandwidthControlEnabled(), isAdmin); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 800 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 801 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 802 | Settings.SimSettingsActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 803 | Utils.showSimCardTile(this), isAdmin); |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 804 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 805 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 806 | Settings.PowerUsageSummaryActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 807 | mBatteryPresent, isAdmin); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 808 | |
| 809 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 810 | Settings.UserSettingsActivity.class.getName()), |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 811 | UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers() |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 812 | && !Utils.isMonkeyRunning(), isAdmin); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 813 | |
Fyodor Kupolov | ca060e3 | 2016-06-24 13:01:11 -0700 | [diff] [blame] | 814 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 815 | Settings.NetworkDashboardActivity.class.getName()), |
Doris Ling | 2620822 | 2017-03-03 11:28:05 -0800 | [diff] [blame] | 816 | !UserManager.isDeviceInDemoMode(this), isAdmin); |
| 817 | |
| 818 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 819 | Settings.ConnectedDeviceDashboardActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 820 | !UserManager.isDeviceInDemoMode(this), isAdmin); |
Fyodor Kupolov | ca060e3 | 2016-06-24 13:01:11 -0700 | [diff] [blame] | 821 | |
| 822 | setTileEnabled(new ComponentName(packageName, |
| 823 | Settings.DateTimeSettingsActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 824 | !UserManager.isDeviceInDemoMode(this), isAdmin); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 825 | NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); |
| 826 | setTileEnabled(new ComponentName(packageName, |
| 827 | Settings.PaymentSettingsActivity.class.getName()), |
| 828 | pm.hasSystemFeature(PackageManager.FEATURE_NFC) |
| 829 | && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION) |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 830 | && adapter != null && adapter.isEnabled(), isAdmin); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 831 | |
| 832 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 833 | Settings.PrintSettingsActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 834 | pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 835 | |
| 836 | final boolean showDev = mDevelopmentPreferences.getBoolean( |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 837 | DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng")) |
Dan Sandler | 12c4ba4 | 2016-03-28 11:13:40 -0400 | [diff] [blame] | 838 | && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES); |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 839 | setTileEnabled(new ComponentName(packageName, |
| 840 | Settings.DevelopmentSettingsActivity.class.getName()), |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 841 | showDev, isAdmin); |
Dan Sandler | 12c4ba4 | 2016-03-28 11:13:40 -0400 | [diff] [blame] | 842 | |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 843 | // Enable/disable backup settings depending on whether the user is admin. |
| 844 | setTileEnabled(new ComponentName(packageName, |
| 845 | BackupSettingsActivity.class.getName()), true, |
| 846 | isAdmin || Utils.isCarrierDemoUser(this)); |
| 847 | |
| 848 | setTileEnabled(new ComponentName(packageName, |
Fan Zhang | 4fcd5ed | 2017-03-10 12:25:35 -0800 | [diff] [blame] | 849 | Settings.WifiDisplaySettingsActivity.class.getName()), |
| 850 | WifiDisplaySettings.isAvailable(this), isAdmin); |
| 851 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 852 | if (UserHandle.MU_ENABLED && !isAdmin) { |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 853 | |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 854 | // When on restricted users, disable all extra categories (but only the settings ones). |
Fan Zhang | 78ab9f9 | 2017-02-27 16:10:05 -0800 | [diff] [blame] | 855 | final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories(); |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 856 | synchronized (categories) { |
| 857 | for (DashboardCategory category : categories) { |
Fan Zhang | 7c8f8a0 | 2017-03-17 12:54:24 -0700 | [diff] [blame] | 858 | final int tileCount = category.getTilesCount(); |
| 859 | for (int i = 0; i < tileCount; i++) { |
| 860 | final ComponentName component = category.getTile(i).intent.getComponent(); |
| 861 | |
Fan Zhang | a6986e7 | 2017-03-08 09:24:45 -0800 | [diff] [blame] | 862 | final String name = component.getClassName(); |
| 863 | final boolean isEnabledForRestricted = ArrayUtils.contains( |
| 864 | SettingsGateway.SETTINGS_FOR_RESTRICTED, name); |
| 865 | if (packageName.equals(component.getPackageName()) |
| 866 | && !isEnabledForRestricted) { |
| 867 | setTileEnabled(component, false, isAdmin); |
| 868 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 869 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 870 | } |
Fabrice Di Meglio | 63bbb8e | 2014-04-23 16:44:30 -0700 | [diff] [blame] | 871 | } |
| 872 | } |
Doris Ling | 26bf003 | 2016-06-15 18:16:09 -0700 | [diff] [blame] | 873 | |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 874 | // Final step, refresh categories. |
| 875 | updateCategories(); |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 876 | } |
| 877 | |
Fan Zhang | 224caad | 2017-01-06 11:42:48 -0800 | [diff] [blame] | 878 | private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) { |
Jason Monk | 5862c1e | 2016-06-07 14:02:33 -0400 | [diff] [blame] | 879 | if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName()) |
Fan Zhang | 9ec4536 | 2017-01-10 11:55:45 -0800 | [diff] [blame] | 880 | && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED, |
| 881 | component.getClassName())) { |
Jason Monk | 4da79e0 | 2015-09-10 10:54:36 -0400 | [diff] [blame] | 882 | enabled = false; |
| 883 | } |
Jason Monk | 5862c1e | 2016-06-07 14:02:33 -0400 | [diff] [blame] | 884 | setTileEnabled(component, enabled); |
Jason Monk | 2ebc8a0 | 2015-02-13 15:23:19 -0500 | [diff] [blame] | 885 | } |
| 886 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 887 | private void getMetaData() { |
| 888 | try { |
| 889 | ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), |
| 890 | PackageManager.GET_META_DATA); |
| 891 | if (ai == null || ai.metaData == null) return; |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 892 | mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS); |
| 893 | } catch (NameNotFoundException nnfe) { |
| 894 | // No recovery |
| 895 | Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString()); |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | // give subclasses access to the Next button |
| 900 | public boolean hasNextButton() { |
| 901 | return mNextButton != null; |
| 902 | } |
| 903 | |
| 904 | public Button getNextButton() { |
| 905 | return mNextButton; |
| 906 | } |
| 907 | |
Fabrice Di Meglio | 263bcc8 | 2014-01-17 19:17:58 -0800 | [diff] [blame] | 908 | @Override |
| 909 | public boolean shouldUpRecreateTask(Intent targetIntent) { |
| 910 | return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); |
| 911 | } |
| 912 | |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 913 | public void startSuggestion(Intent intent) { |
Matthew Fritze | 7ac78f2 | 2016-10-03 13:26:07 -0700 | [diff] [blame] | 914 | if (intent == null || ActivityManager.isUserAMonkey()) { |
Matthew Fritze | 703dc60 | 2016-09-30 12:36:27 -0700 | [diff] [blame] | 915 | return; |
| 916 | } |
Matthew Fritze | f265dbc | 2016-10-04 13:39:27 -0700 | [diff] [blame] | 917 | mCurrentSuggestion = intent.getComponent(); |
Jason Monk | d4f03ec | 2016-01-07 16:25:34 -0500 | [diff] [blame] | 918 | startActivityForResult(intent, REQUEST_SUGGESTION); |
| 919 | } |
| 920 | |
| 921 | @Override |
| 922 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 923 | if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null |
| 924 | && resultCode != RESULT_CANCELED) { |
| 925 | getPackageManager().setComponentEnabledSetting(mCurrentSuggestion, |
| 926 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); |
| 927 | } |
| 928 | super.onActivityResult(requestCode, resultCode, data); |
| 929 | } |
jackqdyulei | 6c355f5 | 2017-03-01 17:37:23 -0800 | [diff] [blame] | 930 | |
| 931 | @VisibleForTesting |
| 932 | Bitmap getBitmapFromXmlResource(int drawableRes) { |
| 933 | Drawable drawable = getResources().getDrawable(drawableRes, getTheme()); |
| 934 | Canvas canvas = new Canvas(); |
| 935 | Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), |
| 936 | drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); |
| 937 | canvas.setBitmap(bitmap); |
| 938 | drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); |
| 939 | drawable.draw(canvas); |
| 940 | |
| 941 | return bitmap; |
| 942 | } |
Matthew Fritze | 0b431fc | 2017-03-16 13:19:20 -0700 | [diff] [blame] | 943 | } |