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