blob: b822a832634c731b59823e0b52b254d08f4e724b [file] [log] [blame]
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001/*
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
17package com.android.settings;
18
Vinit Nayakf7d423d2019-07-01 13:24:39 -070019import static com.android.settings.applications.appinfo.AppButtonsPreferenceController.KEY_REMOVE_TASK_WHEN_FINISHING;
20
Fan Zhang60f01072016-10-13 16:53:41 -070021import android.app.ActionBar;
Matthew Fritze7ac78f22016-10-03 13:26:07 -070022import android.app.ActivityManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080023import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070024import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080025import android.content.Context;
26import android.content.Intent;
27import android.content.IntentFilter;
28import android.content.SharedPreferences;
29import android.content.pm.ActivityInfo;
30import android.content.pm.PackageManager;
31import android.content.pm.PackageManager.NameNotFoundException;
pastychangfefc6682019-03-21 19:42:39 +080032import android.content.res.Resources.Theme;
Jason Monkfd2c7222015-12-02 15:38:38 -050033import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080034import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080035import android.os.UserHandle;
36import android.os.UserManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.text.TextUtils;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080038import android.util.Log;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080039import android.view.View;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080040import android.widget.Button;
Fan Zhang4c26da92017-09-08 15:29:54 -070041
Fan Zhang60243e62018-08-03 09:13:53 -070042import androidx.annotation.Nullable;
43import androidx.annotation.VisibleForTesting;
44import androidx.fragment.app.Fragment;
45import androidx.fragment.app.FragmentManager;
46import androidx.fragment.app.FragmentTransaction;
47import androidx.localbroadcastmanager.content.LocalBroadcastManager;
48import androidx.preference.Preference;
49import androidx.preference.PreferenceFragmentCompat;
50import androidx.preference.PreferenceManager;
51
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040053import com.android.settings.Settings.WifiSettingsActivity;
Fan Zhanga8cac7a2017-10-11 16:44:41 -070054import com.android.settings.applications.manageapplications.ManageApplications;
Chandan Nath4d626f62019-03-12 10:52:53 +000055import com.android.settings.backup.UserBackupSettingsActivity;
Fan Zhangaf32e722018-07-17 10:12:30 -070056import com.android.settings.core.OnActivityResultListener;
tmfangd97fba52018-06-14 14:48:35 +080057import com.android.settings.core.SettingsBaseActivity;
Fan Zhang615563d2018-02-15 15:19:33 -080058import com.android.settings.core.SubSettingLauncher;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080059import com.android.settings.core.gateway.SettingsGateway;
Fan Zhanga96a2d82016-09-27 17:51:11 -070060import com.android.settings.dashboard.DashboardFeatureProvider;
Fan Zhang21526c12018-09-06 15:44:26 -070061import com.android.settings.homepage.TopLevelSettings;
Fan Zhanga96a2d82016-09-27 17:51:11 -070062import com.android.settings.overlay.FeatureFactory;
Fan Zhang4fcd5ed2017-03-10 12:25:35 -080063import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070064import com.android.settings.widget.SwitchBar;
Fan Zhang7cf99f52018-02-16 10:37:37 -080065import com.android.settingslib.core.instrumentation.Instrumentable;
Leif Hendrik Wilden28dee1f2018-01-11 10:15:36 -080066import com.android.settingslib.core.instrumentation.SharedPreferencesLogger;
Tony Mantler3d84d562017-07-31 10:48:55 -070067import com.android.settingslib.development.DevelopmentSettingsEnabler;
Jason Monk4da79e02015-09-10 10:54:36 -040068import com.android.settingslib.drawer.DashboardCategory;
Fan Zhang4c26da92017-09-08 15:29:54 -070069
cnchen3eee5cf2019-05-06 10:19:10 +080070import com.google.android.setupcompat.util.WizardManagerHelper;
71
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080072import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080073import java.util.List;
74
tmfangd97fba52018-06-14 14:48:35 +080075
76public class SettingsActivity extends SettingsBaseActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077 implements PreferenceManager.OnPreferenceTreeClickListener,
tmfang27c84de2018-06-28 11:39:05 +080078 PreferenceFragmentCompat.OnPreferenceStartFragmentCallback,
Fan Zhangff4da232017-11-09 14:07:23 -080079 ButtonBarHandler, FragmentManager.OnBackStackChangedListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080
Fan Zhang22230502018-03-27 14:14:13 -070081 private static final String LOG_TAG = "SettingsActivity";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080082
83 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070084 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080085
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 Meglioc1457322014-04-04 19:07:50 -0700104 * 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 Meglio263bcc82014-01-17 19:17:58 -0800108 // extras that allow any preference activity to be launched as part of a wizard
109
110 // show Back and Next buttons? takes boolean parameter
111 // Back will then return RESULT_CANCELED and Next RESULT_OK
112 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
113
114 // add a Skip button?
115 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
116
117 // specify custom text for the Back or Next buttons, or cause a button to not appear
118 // at all by setting it to null
119 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
120 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
121
122 /**
123 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700124 * those extra can also be specify to supply the title or title res id to be shown for
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800125 * that fragment.
126 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700127 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100128 /**
129 * The package name used to resolve the title resource id.
130 */
131 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
132 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700133 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
134 ":settings:show_fragment_title_resid";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700135
136 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
137 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800138
Jason Monk30695812015-11-17 09:01:08 -0500139 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fan Zhangf11c8852018-02-06 14:21:01 -0800140 "com.android.settings.FRAGMENT_CLASS";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800141
142 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
143
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800144 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800145
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800146 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700147 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800148
Tony Mantler3d84d562017-07-31 10:48:55 -0700149 private BroadcastReceiver mDevelopmentSettingsListener;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800150
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800151 private boolean mBatteryPresent = true;
152 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800153 @Override
154 public void onReceive(Context context, Intent intent) {
155 String action = intent.getAction();
156 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
157 boolean batteryPresent = Utils.isBatteryPresent(intent);
158
159 if (mBatteryPresent != batteryPresent) {
160 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400161 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800162 }
163 }
164 }
165 };
166
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700167 private SwitchBar mSwitchBar;
168
169 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700170
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700171 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800172 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800173
Fan Zhanga96a2d82016-09-27 17:51:11 -0700174 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700175
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700176 public SwitchBar getSwitchBar() {
177 return mSwitchBar;
178 }
179
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800180 @Override
tmfang27c84de2018-06-28 11:39:05 +0800181 public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
Fan Zhang7cf99f52018-02-16 10:37:37 -0800182 new SubSettingLauncher(this)
183 .setDestination(pref.getFragment())
184 .setArguments(pref.getExtras())
185 .setSourceMetricsCategory(caller instanceof Instrumentable
186 ? ((Instrumentable) caller).getMetricsCategory()
187 : Instrumentable.METRICS_CATEGORY_UNKNOWN)
hjchangliaoe86eec02018-05-02 13:01:07 +0800188 .setTitleRes(-1)
Fan Zhang7cf99f52018-02-16 10:37:37 -0800189 .launch();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800190 return true;
191 }
192
193 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400194 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800195 return false;
196 }
197
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800198 @Override
Jason Monk31c7c322016-01-20 14:41:52 -0500199 public SharedPreferences getSharedPreferences(String name, int mode) {
200 if (name.equals(getPackageName() + "_preferences")) {
Leif Hendrik Wilden28dee1f2018-01-11 10:15:36 -0800201 return new SharedPreferencesLogger(this, getMetricsTag(),
202 FeatureFactory.getFactory(this).getMetricsFeatureProvider());
Jason Monk31c7c322016-01-20 14:41:52 -0500203 }
204 return super.getSharedPreferences(name, mode);
205 }
206
Jason Monke4ebcd12016-02-21 09:37:41 -0500207 private String getMetricsTag() {
208 String tag = getClass().getName();
209 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
210 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
211 }
212 if (tag.startsWith("com.android.settings.")) {
213 tag = tag.replace("com.android.settings.", "");
214 }
215 return tag;
216 }
217
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700218 @Override
219 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700220 super.onCreate(savedState);
Fan Zhang22230502018-03-27 14:14:13 -0700221 Log.d(LOG_TAG, "Starting onCreate");
Jason Monkfd2c7222015-12-02 15:38:38 -0500222 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700223
224 final FeatureFactory factory = FeatureFactory.getFactory(this);
225
226 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700227
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700228 // Should happen before any call to getIntent()
229 getMetaData();
230
231 final Intent intent = getIntent();
232 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
233 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800234 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800235
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700236 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700237 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700238
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700239 // This is a "Sub Settings" when:
240 // - this is a real SubSettings
241 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700242 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700243 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
244
Fan Zhang92f1e942017-01-21 10:07:26 -0800245 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content
cnchen3eee5cf2019-05-06 10:19:10 +0800246 // insets.
247 // If this is in setup flow, don't apply theme. Because light theme needs to be applied
248 // in SettingsBaseActivity#onCreate().
249 if (isSubSettings && !WizardManagerHelper.isAnySetupWizard(getIntent())) {
Fan Zhang92f1e942017-01-21 10:07:26 -0800250 setTheme(R.style.Theme_SubSettings);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700251 }
252
Fan Zhang4df9bfa2019-02-22 13:53:09 -0800253 setContentView(R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800254
tmfang27c84de2018-06-28 11:39:05 +0800255 getSupportFragmentManager().addOnBackStackChangedListener(this);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800256
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700257 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700258 // We are restarting from a previous saved state; used that to initialize, instead
259 // of starting fresh.
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700260 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800261
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700262 ArrayList<DashboardCategory> categories =
263 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
264 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700265 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700266 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700267 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800268 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800269 } else {
Fan Zhang8e14ca02018-11-27 13:06:44 -0800270 launchSettingFragment(initialFragmentName, intent);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800271 }
272
Doris Ling882bef32018-07-31 14:04:44 -0700273 final boolean deviceProvisioned = Utils.isDeviceProvisioned(this);
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700274
Fan Zhang4df9bfa2019-02-22 13:53:09 -0800275 final ActionBar actionBar = getActionBar();
Andrew Sappersteina2dd9972017-06-25 13:51:08 -0700276 if (actionBar != null) {
Tony Make226b382018-03-02 18:23:35 +0000277 actionBar.setDisplayHomeAsUpEnabled(deviceProvisioned);
278 actionBar.setHomeButtonEnabled(deviceProvisioned);
Fan Zhang4df9bfa2019-02-22 13:53:09 -0800279 actionBar.setDisplayShowTitleEnabled(true);
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700280 }
Andrew Sappersteina2dd9972017-06-25 13:51:08 -0700281 mSwitchBar = findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500282 if (mSwitchBar != null) {
283 mSwitchBar.setMetricsTag(getMetricsTag());
284 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700285
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800286 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800287 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
288
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700289 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800290 if (buttonBar != null) {
291 buttonBar.setVisibility(View.VISIBLE);
292
Fan Zhange994d462018-12-04 12:43:14 -0800293 Button backButton = findViewById(R.id.back_button);
294 backButton.setOnClickListener(v -> {
295 setResult(RESULT_CANCELED, null);
296 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800297 });
Fan Zhange994d462018-12-04 12:43:14 -0800298 Button skipButton = findViewById(R.id.skip_button);
299 skipButton.setOnClickListener(v -> {
300 setResult(RESULT_OK, null);
301 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800302 });
Fan Zhange994d462018-12-04 12:43:14 -0800303 mNextButton = findViewById(R.id.next_button);
304 mNextButton.setOnClickListener(v -> {
305 setResult(RESULT_OK, null);
306 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800307 });
308
309 // set our various button parameters
310 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
311 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
312 if (TextUtils.isEmpty(buttonText)) {
313 mNextButton.setVisibility(View.GONE);
Fan Zhangf11c8852018-02-06 14:21:01 -0800314 } else {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800315 mNextButton.setText(buttonText);
316 }
317 }
318 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
319 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
320 if (TextUtils.isEmpty(buttonText)) {
321 backButton.setVisibility(View.GONE);
Fan Zhangf11c8852018-02-06 14:21:01 -0800322 } else {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800323 backButton.setText(buttonText);
324 }
325 }
326 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
327 skipButton.setVisibility(View.VISIBLE);
328 }
329 }
330 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700331
Fan Zhangefba6b42017-02-07 17:40:59 -0800332 if (DEBUG_TIMING) {
333 Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
334 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700335 }
336
Fan Zhangaf32e722018-07-17 10:12:30 -0700337 @Override
pastychangfefc6682019-03-21 19:42:39 +0800338 protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
339 theme.applyStyle(R.style.SetupWizardPartnerResource, true);
340 super.onApplyThemeResource(theme, resid, first);
341 }
342
343 @Override
Fan Zhangaf32e722018-07-17 10:12:30 -0700344 protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
345 super.onActivityResult(requestCode, resultCode, data);
346 final List<Fragment> fragments = getSupportFragmentManager().getFragments();
347 if (fragments != null) {
348 for (Fragment fragment : fragments) {
349 if (fragment instanceof OnActivityResultListener) {
350 fragment.onActivityResult(requestCode, resultCode, data);
351 }
352 }
353 }
354 }
355
Doris Lingcb69baf2017-02-23 17:50:03 -0800356 @VisibleForTesting
Fan Zhang8e14ca02018-11-27 13:06:44 -0800357 void launchSettingFragment(String initialFragmentName, Intent intent) {
358 if (initialFragmentName != null) {
Doris Lingcb69baf2017-02-23 17:50:03 -0800359 setTitleFromIntent(intent);
360
361 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fan Zhang39d9d7c2019-01-23 16:38:24 -0800362 switchToFragment(initialFragmentName, initialArguments, true,
363 mInitialTitleResId, mInitialTitle);
Doris Lingcb69baf2017-02-23 17:50:03 -0800364 } else {
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700365 // Show search icon as up affordance if we are displaying the main Dashboard
Doris Lingcb69baf2017-02-23 17:50:03 -0800366 mInitialTitleResId = R.string.dashboard_title;
Fan Zhang39d9d7c2019-01-23 16:38:24 -0800367 switchToFragment(TopLevelSettings.class.getName(), null /* args */, false,
368 mInitialTitleResId, mInitialTitle);
Doris Lingcb69baf2017-02-23 17:50:03 -0800369 }
370 }
371
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700372 private void setTitleFromIntent(Intent intent) {
Fan Zhang22230502018-03-27 14:14:13 -0700373 Log.d(LOG_TAG, "Starting to set activity title");
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700374 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
375 if (initialTitleResId > 0) {
376 mInitialTitle = null;
377 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100378
379 final String initialTitleResPackageName = intent.getStringExtra(
380 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
381 if (initialTitleResPackageName != null) {
382 try {
383 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
384 0 /* flags */, new UserHandle(UserHandle.myUserId()));
385 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
386 setTitle(mInitialTitle);
387 mInitialTitleResId = -1;
388 return;
389 } catch (NameNotFoundException e) {
390 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
391 }
392 } else {
393 setTitle(mInitialTitleResId);
394 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700395 } else {
396 mInitialTitleResId = -1;
397 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
398 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
399 setTitle(mInitialTitle);
400 }
Fan Zhang22230502018-03-27 14:14:13 -0700401 Log.d(LOG_TAG, "Done setting title");
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700402 }
403
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800404 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800405 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700406 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800407 }
408
Fan Zhang28691572016-03-23 15:31:08 -0700409 private void setTitleFromBackStack() {
tmfang27c84de2018-06-28 11:39:05 +0800410 final int count = getSupportFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700411
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800412 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700413 if (mInitialTitleResId > 0) {
414 setTitle(mInitialTitleResId);
415 } else {
416 setTitle(mInitialTitle);
417 }
Fan Zhang28691572016-03-23 15:31:08 -0700418 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800419 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700420
tmfang27c84de2018-06-28 11:39:05 +0800421 FragmentManager.BackStackEntry bse = getSupportFragmentManager().
422 getBackStackEntryAt(count - 1);
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800423 setTitleFromBackStackEntry(bse);
424 }
425
426 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
427 final CharSequence title;
428 final int titleRes = bse.getBreadCrumbTitleRes();
429 if (titleRes > 0) {
430 title = getText(titleRes);
431 } else {
432 title = bse.getBreadCrumbTitle();
433 }
434 if (title != null) {
435 setTitle(title);
436 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800437 }
438
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800439 @Override
440 protected void onSaveInstanceState(Bundle outState) {
441 super.onSaveInstanceState(outState);
Matthew Fritze7d48ae82017-03-23 08:59:15 -0700442 saveState(outState);
443 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800444
Matthew Fritze7d48ae82017-03-23 08:59:15 -0700445 /**
446 * For testing purposes to avoid crashes from final variables in Activity's onSaveInstantState.
447 */
448 @VisibleForTesting
449 void saveState(Bundle outState) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700450 if (mCategories.size() > 0) {
451 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800452 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800453 }
454
455 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400456 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800457 super.onResume();
458
Tony Mantler3d84d562017-07-31 10:48:55 -0700459 mDevelopmentSettingsListener = new BroadcastReceiver() {
460 @Override
461 public void onReceive(Context context, Intent intent) {
462 updateTilesList();
463 }
464 };
465 LocalBroadcastManager.getInstance(this).registerReceiver(mDevelopmentSettingsListener,
466 new IntentFilter(DevelopmentSettingsEnabler.DEVELOPMENT_SETTINGS_CHANGED_ACTION));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800467
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800468 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700469
Jason Monk4da79e02015-09-10 10:54:36 -0400470 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800471 }
472
473 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400474 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800475 super.onPause();
Tony Mantler3d84d562017-07-31 10:48:55 -0700476 LocalBroadcastManager.getInstance(this).unregisterReceiver(mDevelopmentSettingsListener);
477 mDevelopmentSettingsListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800478 unregisterReceiver(mBatteryInfoReceiver);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800479 }
480
481 @Override
jackqdyulei6c355f52017-03-01 17:37:23 -0800482 public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
Sunny Goyal3c846752018-07-03 11:39:00 -0700483 taskDescription.setIcon(R.drawable.ic_launcher_settings);
jackqdyulei6c355f52017-03-01 17:37:23 -0800484 super.setTaskDescription(taskDescription);
485 }
486
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800487 protected boolean isValidFragment(String fragmentName) {
488 // Almost all fragments are wrapped in this,
489 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800490 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
491 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800492 }
493 return false;
494 }
495
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800496 @Override
497 public Intent getIntent() {
498 Intent superIntent = super.getIntent();
499 String startingFragment = getStartingFragmentClass(superIntent);
500 // This is called from super.onCreate, isMultiPane() is not yet reliable
501 // Do not use onIsHidingHeaders either, which relies itself on this method
502 if (startingFragment != null) {
503 Intent modIntent = new Intent(superIntent);
504 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
Fan Zhange8666c62018-03-02 11:01:15 -0800505 Bundle args = superIntent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800506 if (args != null) {
507 args = new Bundle(args);
508 } else {
509 args = new Bundle();
510 }
511 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100512 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800513 return modIntent;
514 }
515 return superIntent;
516 }
517
518 /**
519 * Checks if the component name in the intent is different from the Settings class and
520 * returns the class name to load as a fragment.
521 */
522 private String getStartingFragmentClass(Intent intent) {
523 if (mFragmentClass != null) return mFragmentClass;
524
525 String intentClass = intent.getComponent().getClassName();
526 if (intentClass.equals(getClass().getName())) return null;
527
Fan Zhanga8cac7a2017-10-11 16:44:41 -0700528 if ("com.android.settings.RunningServices".equals(intentClass)
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800529 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
530 // Old names of manage apps.
Fan Zhanga8cac7a2017-10-11 16:44:41 -0700531 intentClass = ManageApplications.class.getName();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800532 }
533
534 return intentClass;
535 }
536
537 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800538 * Called by a preference panel fragment to finish itself.
539 *
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800540 * @param resultCode Optional result code to send back to the original
Fan Zhangf11c8852018-02-06 14:21:01 -0800541 * launching fragment.
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800542 * @param resultData Optional result data to send back to the original
Fan Zhangf11c8852018-02-06 14:21:01 -0800543 * launching fragment.
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800544 */
Fan Zhang47854c22018-02-19 13:54:09 -0800545 public void finishPreferencePanel(int resultCode, Intent resultData) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800546 setResult(resultCode, resultData);
Vinit Nayakf7d423d2019-07-01 13:24:39 -0700547 if (resultData != null &&
548 resultData.getBooleanExtra(KEY_REMOVE_TASK_WHEN_FINISHING, false)) {
549 finishAndRemoveTask();
550 } else {
551 finish();
552 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800553 }
554
555 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700556 * Switch to a specific Fragment with taking care of validation, Title and BackStack
557 */
558 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fan Zhang39d9d7c2019-01-23 16:38:24 -0800559 int titleResId, CharSequence title) {
Fan Zhang22230502018-03-27 14:14:13 -0700560 Log.d(LOG_TAG, "Switching to fragment " + fragmentName);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700561 if (validate && !isValidFragment(fragmentName)) {
562 throw new IllegalArgumentException("Invalid fragment for this activity: "
563 + fragmentName);
564 }
565 Fragment f = Fragment.instantiate(this, fragmentName, args);
tmfang27c84de2018-06-28 11:39:05 +0800566 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700567 transaction.replace(R.id.main_content, f);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700568 if (titleResId > 0) {
569 transaction.setBreadCrumbTitle(titleResId);
570 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700571 transaction.setBreadCrumbTitle(title);
572 }
573 transaction.commitAllowingStateLoss();
tmfang27c84de2018-06-28 11:39:05 +0800574 getSupportFragmentManager().executePendingTransactions();
Fan Zhang22230502018-03-27 14:14:13 -0700575 Log.d(LOG_TAG, "Executed frag manager pendingTransactions");
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700576 return f;
577 }
578
Jason Monk4da79e02015-09-10 10:54:36 -0400579 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500580 // Generally the items that are will be changing from these updates will
581 // not be in the top list of tiles, so run it in the background and the
tmfangd97fba52018-06-14 14:48:35 +0800582 // SettingsBaseActivity will pick up on the updates automatically.
Jason Monkfd2c7222015-12-02 15:38:38 -0500583 AsyncTask.execute(new Runnable() {
584 @Override
585 public void run() {
586 doUpdateTilesList();
587 }
588 });
589 }
590
591 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400592 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700593 final UserManager um = UserManager.get(this);
594 final boolean isAdmin = um.isAdminUser();
Fan Zhangaeb94f02017-07-05 13:46:04 -0700595 boolean somethingChanged = false;
Fan Zhang22230502018-03-27 14:14:13 -0700596 final String packageName = getPackageName();
597 final StringBuilder changedList = new StringBuilder();
598 somethingChanged = setTileEnabled(changedList,
Fan Zhangaeb94f02017-07-05 13:46:04 -0700599 new ComponentName(packageName, WifiSettingsActivity.class.getName()),
600 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin) || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700601
Fan Zhang22230502018-03-27 14:14:13 -0700602 somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800603 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700604 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin)
605 || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700606
Rajeev Kumar4a5e3dc2017-07-18 19:21:34 -0700607 // Enable DataUsageSummaryActivity if the data plan feature flag is turned on otherwise
608 // enable DataPlanUsageSummaryActivity.
Fan Zhang22230502018-03-27 14:14:13 -0700609 somethingChanged = setTileEnabled(changedList,
Fan Zhang3ed55b12018-02-07 13:50:09 -0800610 new ComponentName(packageName, Settings.DataUsageSummaryActivity.class.getName()),
Rajeev Kumar4a5e3dc2017-07-18 19:21:34 -0700611 Utils.isBandwidthControlEnabled() /* enabled */,
612 isAdmin) || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700613
Fan Zhang22230502018-03-27 14:14:13 -0700614 somethingChanged = setTileEnabled(changedList,
jackqdyulei76ba0f72017-11-17 14:14:51 -0800615 new ComponentName(packageName,
616 Settings.ConnectedDeviceDashboardActivity.class.getName()),
Jerry Zhang40bd5702018-02-23 14:43:58 -0800617 !UserManager.isDeviceInDemoMode(this) /* enabled */,
jackqdyulei76ba0f72017-11-17 14:14:51 -0800618 isAdmin) || somethingChanged;
619
Fan Zhang22230502018-03-27 14:14:13 -0700620 somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800621 Settings.PowerUsageSummaryActivity.class.getName()),
Lei Yu68ffee12018-03-26 14:31:57 -0700622 mBatteryPresent, isAdmin) || somethingChanged;
Jason Monk4da79e02015-09-10 10:54:36 -0400623
Fan Zhang22230502018-03-27 14:14:13 -0700624 somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Eric Schwarzenbach98998a22018-02-06 15:57:01 -0800625 Settings.DataUsageSummaryActivity.class.getName()),
Fan Zhangcd21cb82018-06-11 09:28:02 -0700626 Utils.isBandwidthControlEnabled(), isAdmin)
Eric Schwarzenbach98998a22018-02-06 15:57:01 -0800627 || somethingChanged;
628
Fan Zhang22230502018-03-27 14:14:13 -0700629 somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800630 Settings.UserSettingsActivity.class.getName()),
Jason Monk4da79e02015-09-10 10:54:36 -0400631 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhangaeb94f02017-07-05 13:46:04 -0700632 && !Utils.isMonkeyRunning(), isAdmin)
633 || somethingChanged;
Jason Monk4da79e02015-09-10 10:54:36 -0400634
Tony Mantler3d84d562017-07-31 10:48:55 -0700635 final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
Fan Zhang831f6302017-11-22 13:07:50 -0800636 && !Utils.isMonkeyRunning();
Fan Zhang22230502018-03-27 14:14:13 -0700637 somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Fan Zhang4c26da92017-09-08 15:29:54 -0700638 Settings.DevelopmentSettingsDashboardActivity.class.getName()),
Christine Franks986d02f2018-04-23 11:19:57 -0700639 showDev, isAdmin)
Fan Zhangaeb94f02017-07-05 13:46:04 -0700640 || somethingChanged;
Dan Sandler12c4ba42016-03-28 11:13:40 -0400641
Chandan Nath4d626f62019-03-12 10:52:53 +0000642 somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Chandan Nathf94033d2019-04-24 18:58:50 +0100643 UserBackupSettingsActivity.class.getName()), true, isAdmin)
Chandan Nath4d626f62019-03-12 10:52:53 +0000644 || somethingChanged;
645
Fan Zhang22230502018-03-27 14:14:13 -0700646 somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
Fan Zhang4fcd5ed2017-03-10 12:25:35 -0800647 Settings.WifiDisplaySettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700648 WifiDisplaySettings.isAvailable(this), isAdmin)
649 || somethingChanged;
Fan Zhang4fcd5ed2017-03-10 12:25:35 -0800650
Jason Monk4da79e02015-09-10 10:54:36 -0400651 if (UserHandle.MU_ENABLED && !isAdmin) {
Fan Zhanga6986e72017-03-08 09:24:45 -0800652
Jason Monk4da79e02015-09-10 10:54:36 -0400653 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhang78ab9f92017-02-27 16:10:05 -0800654 final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
Fan Zhanga6986e72017-03-08 09:24:45 -0800655 synchronized (categories) {
656 for (DashboardCategory category : categories) {
Fan Zhang7c8f8a02017-03-17 12:54:24 -0700657 final int tileCount = category.getTilesCount();
658 for (int i = 0; i < tileCount; i++) {
Fan Zhang3506b742018-08-07 13:52:52 -0700659 final ComponentName component = category.getTile(i)
660 .getIntent().getComponent();
Fan Zhanga6986e72017-03-08 09:24:45 -0800661 final String name = component.getClassName();
662 final boolean isEnabledForRestricted = ArrayUtils.contains(
Christine Franks986d02f2018-04-23 11:19:57 -0700663 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
Fan Zhanga6986e72017-03-08 09:24:45 -0800664 if (packageName.equals(component.getPackageName())
665 && !isEnabledForRestricted) {
Fan Zhang22230502018-03-27 14:14:13 -0700666 somethingChanged =
667 setTileEnabled(changedList, component, false, isAdmin)
668 || somethingChanged;
Fan Zhanga6986e72017-03-08 09:24:45 -0800669 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700670 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700671 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700672 }
673 }
Doris Ling26bf0032016-06-15 18:16:09 -0700674
Fan Zhang224caad2017-01-06 11:42:48 -0800675 // Final step, refresh categories.
Fan Zhangaeb94f02017-07-05 13:46:04 -0700676 if (somethingChanged) {
Fan Zhang22230502018-03-27 14:14:13 -0700677 Log.d(LOG_TAG, "Enabled state changed for some tiles, reloading all categories "
678 + changedList.toString());
Fan Zhangaeb94f02017-07-05 13:46:04 -0700679 updateCategories();
680 } else {
681 Log.d(LOG_TAG, "No enabled state changed, skipping updateCategory call");
682 }
Jason Monk2ebc8a02015-02-13 15:23:19 -0500683 }
684
Fan Zhangaeb94f02017-07-05 13:46:04 -0700685 /**
686 * @return whether or not the enabled state actually changed.
687 */
Fan Zhang22230502018-03-27 14:14:13 -0700688 private boolean setTileEnabled(StringBuilder changedList, ComponentName component,
689 boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -0400690 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Fan Zhang9ec45362017-01-10 11:55:45 -0800691 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
692 component.getClassName())) {
Jason Monk4da79e02015-09-10 10:54:36 -0400693 enabled = false;
694 }
Fan Zhang22230502018-03-27 14:14:13 -0700695 boolean changed = setTileEnabled(component, enabled);
696 if (changed) {
697 changedList.append(component.toShortString()).append(",");
698 }
699 return changed;
Jason Monk2ebc8a02015-02-13 15:23:19 -0500700 }
701
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800702 private void getMetaData() {
703 try {
704 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
705 PackageManager.GET_META_DATA);
706 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800707 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
708 } catch (NameNotFoundException nnfe) {
709 // No recovery
710 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
711 }
712 }
713
714 // give subclasses access to the Next button
715 public boolean hasNextButton() {
716 return mNextButton != null;
717 }
718
719 public Button getNextButton() {
720 return mNextButton;
721 }
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700722}