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