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