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