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