blob: 8b71df19f502fb3750125868ec689c77f6f8cc57 [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
Fan Zhang6013a952018-02-06 11:36:07 -080019import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO;
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.app.Fragment;
24import android.app.FragmentManager;
25import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080026import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070027import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080028import android.content.Context;
29import android.content.Intent;
30import android.content.IntentFilter;
31import android.content.SharedPreferences;
32import android.content.pm.ActivityInfo;
33import android.content.pm.PackageManager;
34import android.content.pm.PackageManager.NameNotFoundException;
jackqdyulei6c355f52017-03-01 17:37:23 -080035import android.graphics.Bitmap;
jackqdyulei6c355f52017-03-01 17:37:23 -080036import android.graphics.Canvas;
37import android.graphics.drawable.Drawable;
Jason Monkfd2c7222015-12-02 15:38:38 -050038import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080039import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080040import android.os.UserHandle;
41import android.os.UserManager;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080042import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040043import android.support.v14.preference.PreferenceFragment;
Tony Mantler3d84d562017-07-31 10:48:55 -070044import android.support.v4.content.LocalBroadcastManager;
Jason Monk39b46742015-09-10 15:52:51 -040045import android.support.v7.preference.Preference;
46import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080047import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070048import android.transition.TransitionManager;
Eric Schwarzenbach98998a22018-02-06 15:57:01 -080049import android.util.FeatureFlagUtils;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080050import android.util.Log;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080051import android.view.View;
52import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070053import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080054import android.widget.Button;
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -070055import android.widget.Toolbar;
Fan Zhang4c26da92017-09-08 15:29:54 -070056
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080057import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040058import com.android.settings.Settings.WifiSettingsActivity;
Fan Zhanga8cac7a2017-10-11 16:44:41 -070059import com.android.settings.applications.manageapplications.ManageApplications;
Anton Philippovadfec552017-01-25 20:37:36 +000060import com.android.settings.backup.BackupSettingsActivity;
Eric Schwarzenbach98998a22018-02-06 15:57:01 -080061import com.android.settings.core.FeatureFlags;
Fan Zhang615563d2018-02-15 15:19:33 -080062import com.android.settings.core.SubSettingLauncher;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080063import com.android.settings.core.gateway.SettingsGateway;
Fan Zhanga96a2d82016-09-27 17:51:11 -070064import com.android.settings.dashboard.DashboardFeatureProvider;
65import com.android.settings.dashboard.DashboardSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070066import com.android.settings.overlay.FeatureFactory;
Fan Zhang4fcd5ed2017-03-10 12:25:35 -080067import com.android.settings.wfd.WifiDisplaySettings;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070068import com.android.settings.widget.SwitchBar;
Fan Zhang7cf99f52018-02-16 10:37:37 -080069import com.android.settingslib.core.instrumentation.Instrumentable;
Leif Hendrik Wilden28dee1f2018-01-11 10:15:36 -080070import com.android.settingslib.core.instrumentation.SharedPreferencesLogger;
Tony Mantler3d84d562017-07-31 10:48:55 -070071import com.android.settingslib.development.DevelopmentSettingsEnabler;
Jason Monk4da79e02015-09-10 10:54:36 -040072import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040073import com.android.settingslib.drawer.SettingsDrawerActivity;
Fan Zhang4c26da92017-09-08 15:29:54 -070074
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080075import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076import java.util.List;
77
Jason Monk4da79e02015-09-10 10:54:36 -040078public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080079 implements PreferenceManager.OnPreferenceTreeClickListener,
80 PreferenceFragment.OnPreferenceStartFragmentCallback,
Fan Zhangff4da232017-11-09 14:07:23 -080081 ButtonBarHandler, FragmentManager.OnBackStackChangedListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080082
83 private static final String LOG_TAG = "Settings";
84
85 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070086 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080087
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 Meglioc1457322014-04-04 19:07:50 -0700106 * 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 Meglio6f0739a2014-02-03 18:12:25 -0800110 public static final String BACK_STACK_PREFS = ":settings:prefs";
111
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800112 // 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 Meglioa9e77992014-06-09 12:52:24 -0700128 * 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 -0800129 * that fragment.
130 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700131 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100132 /**
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 Meglio61a1fec2014-08-13 16:22:38 -0700137 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 Meglio263bcc82014-01-17 19:17:58 -0800144
Fan Zhang78ab9f92017-02-27 16:10:05 -0800145 @Deprecated
Udam Saini92779ce2016-03-28 14:29:48 -0700146 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
147
Jason Monk30695812015-11-17 09:01:08 -0500148 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fan Zhangf11c8852018-02-06 14:21:01 -0800149 "com.android.settings.FRAGMENT_CLASS";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800150
151 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
152
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800153 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800154
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800155 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700156 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800157
Tony Mantler3d84d562017-07-31 10:48:55 -0700158 private BroadcastReceiver mDevelopmentSettingsListener;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800159
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800160 private boolean mBatteryPresent = true;
161 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800162 @Override
163 public void onReceive(Context context, Intent intent) {
164 String action = intent.getAction();
165 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
166 boolean batteryPresent = Utils.isBatteryPresent(intent);
167
168 if (mBatteryPresent != batteryPresent) {
169 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400170 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800171 }
172 }
173 }
174 };
175
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700176 private SwitchBar mSwitchBar;
177
178 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700179
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700180 private boolean mIsShowingDashboard;
181
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700182 private ViewGroup mContent;
183
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700184 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800185 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800186
Fan Zhanga96a2d82016-09-27 17:51:11 -0700187 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700188
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700189 public SwitchBar getSwitchBar() {
190 return mSwitchBar;
191 }
192
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800193 @Override
194 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Fan Zhang7cf99f52018-02-16 10:37:37 -0800195 new SubSettingLauncher(this)
196 .setDestination(pref.getFragment())
197 .setArguments(pref.getExtras())
198 .setSourceMetricsCategory(caller instanceof Instrumentable
199 ? ((Instrumentable) caller).getMetricsCategory()
200 : Instrumentable.METRICS_CATEGORY_UNKNOWN)
201 .setTitle(-1)
202 .launch();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800203 return true;
204 }
205
206 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400207 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800208 return false;
209 }
210
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800211 @Override
Jason Monk31c7c322016-01-20 14:41:52 -0500212 public SharedPreferences getSharedPreferences(String name, int mode) {
213 if (name.equals(getPackageName() + "_preferences")) {
Leif Hendrik Wilden28dee1f2018-01-11 10:15:36 -0800214 return new SharedPreferencesLogger(this, getMetricsTag(),
215 FeatureFactory.getFactory(this).getMetricsFeatureProvider());
Jason Monk31c7c322016-01-20 14:41:52 -0500216 }
217 return super.getSharedPreferences(name, mode);
218 }
219
Jason Monke4ebcd12016-02-21 09:37:41 -0500220 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 Megliod25314d2014-03-21 19:24:43 -0700231 @Override
232 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700233 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500234 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700235
236 final FeatureFactory factory = FeatureFactory.getFactory(this);
237
238 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700239
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700240 // Should happen before any call to getIntent()
241 getMetaData();
242
243 final Intent intent = getIntent();
244 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
245 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800246 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800247
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700248 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700249 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700250
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700251 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700252 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700253
Doris Ling1694d4b2017-03-03 14:21:37 -0800254 mIsShowingDashboard = className.equals(Settings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700255
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700256 // This is a "Sub Settings" when:
257 // - this is a real SubSettings
258 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700259 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700260 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
261
Fan Zhang92f1e942017-01-21 10:07:26 -0800262 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content
263 // insets
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700264 if (isSubSettings) {
Fan Zhang92f1e942017-01-21 10:07:26 -0800265 setTheme(R.style.Theme_SubSettings);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700266 }
267
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700268 setContentView(mIsShowingDashboard ?
269 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800270
Andrew Sappersteina2dd9972017-06-25 13:51:08 -0700271 mContent = findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700272
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800273 getFragmentManager().addOnBackStackChangedListener(this);
274
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700275 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700276 // We are restarting from a previous saved state; used that to initialize, instead
277 // of starting fresh.
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700278 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800279
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700280 ArrayList<DashboardCategory> categories =
281 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
282 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700283 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700284 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700285 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800286 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800287 } else {
Doris Lingcb69baf2017-02-23 17:50:03 -0800288 launchSettingFragment(initialFragmentName, isSubSettings, intent);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800289 }
290
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700291 if (mIsShowingDashboard) {
292 findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
293 findViewById(R.id.action_bar).setVisibility(View.GONE);
Fan Zhangff4da232017-11-09 14:07:23 -0800294 final Toolbar toolbar = findViewById(R.id.search_action_bar);
295 FeatureFactory.getFactory(this).getSearchFeatureProvider()
296 .initSearchToolbar(this, toolbar);
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700297 setActionBar(toolbar);
Andrew Sappersteinc2174642017-06-25 15:18:46 -0700298
299 // Please forgive me for what I am about to do.
300 //
301 // Need to make the navigation icon non-clickable so that the entire card is clickable
302 // and goes to the search UI. Also set the background to null so there's no ripple.
303 View navView = toolbar.getNavigationView();
304 navView.setClickable(false);
Fan Zhang6013a952018-02-06 11:36:07 -0800305 navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
Andrew Sappersteinc2174642017-06-25 15:18:46 -0700306 navView.setBackground(null);
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700307 }
308
Andrew Sappersteina2dd9972017-06-25 13:51:08 -0700309 ActionBar actionBar = getActionBar();
310 if (actionBar != null) {
Tony Make226b382018-03-02 18:23:35 +0000311 boolean deviceProvisioned = Utils.isDeviceProvisioned(this);
312 actionBar.setDisplayHomeAsUpEnabled(deviceProvisioned);
313 actionBar.setHomeButtonEnabled(deviceProvisioned);
Fan Zhange096ae72017-11-30 14:41:04 -0800314 actionBar.setDisplayShowTitleEnabled(!mIsShowingDashboard);
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700315 }
Andrew Sappersteina2dd9972017-06-25 13:51:08 -0700316 mSwitchBar = findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500317 if (mSwitchBar != null) {
318 mSwitchBar.setMetricsTag(getMetricsTag());
319 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700320
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800321 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800322 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
323
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700324 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800325 if (buttonBar != null) {
326 buttonBar.setVisibility(View.VISIBLE);
327
Fan Zhangf11c8852018-02-06 14:21:01 -0800328 Button backButton = (Button) findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800329 backButton.setOnClickListener(new OnClickListener() {
330 public void onClick(View v) {
Matthew Fritze0b431fc2017-03-16 13:19:20 -0700331 setResult(RESULT_CANCELED, null);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800332 finish();
333 }
334 });
Fan Zhangf11c8852018-02-06 14:21:01 -0800335 Button skipButton = (Button) findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800336 skipButton.setOnClickListener(new OnClickListener() {
337 public void onClick(View v) {
Matthew Fritze0b431fc2017-03-16 13:19:20 -0700338 setResult(RESULT_OK, null);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800339 finish();
340 }
341 });
Fan Zhangf11c8852018-02-06 14:21:01 -0800342 mNextButton = (Button) findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800343 mNextButton.setOnClickListener(new OnClickListener() {
344 public void onClick(View v) {
Matthew Fritze0b431fc2017-03-16 13:19:20 -0700345 setResult(RESULT_OK, null);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800346 finish();
347 }
348 });
349
350 // set our various button parameters
351 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
352 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
353 if (TextUtils.isEmpty(buttonText)) {
354 mNextButton.setVisibility(View.GONE);
Fan Zhangf11c8852018-02-06 14:21:01 -0800355 } else {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800356 mNextButton.setText(buttonText);
357 }
358 }
359 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
360 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
361 if (TextUtils.isEmpty(buttonText)) {
362 backButton.setVisibility(View.GONE);
Fan Zhangf11c8852018-02-06 14:21:01 -0800363 } else {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800364 backButton.setText(buttonText);
365 }
366 }
367 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
368 skipButton.setVisibility(View.VISIBLE);
369 }
370 }
371 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700372
Fan Zhangefba6b42017-02-07 17:40:59 -0800373 if (DEBUG_TIMING) {
374 Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
375 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700376 }
377
Doris Lingcb69baf2017-02-23 17:50:03 -0800378 @VisibleForTesting
379 void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) {
380 if (!mIsShowingDashboard && initialFragmentName != null) {
Doris Lingcb69baf2017-02-23 17:50:03 -0800381 setTitleFromIntent(intent);
382
383 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
384 switchToFragment(initialFragmentName, initialArguments, true, false,
Fan Zhangf11c8852018-02-06 14:21:01 -0800385 mInitialTitleResId, mInitialTitle, false);
Doris Lingcb69baf2017-02-23 17:50:03 -0800386 } else {
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700387 // Show search icon as up affordance if we are displaying the main Dashboard
Doris Lingcb69baf2017-02-23 17:50:03 -0800388 mInitialTitleResId = R.string.dashboard_title;
389
390 switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
Fan Zhangf11c8852018-02-06 14:21:01 -0800391 mInitialTitleResId, mInitialTitle, false);
Doris Lingcb69baf2017-02-23 17:50:03 -0800392 }
393 }
394
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700395 private void setTitleFromIntent(Intent intent) {
396 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
397 if (initialTitleResId > 0) {
398 mInitialTitle = null;
399 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100400
401 final String initialTitleResPackageName = intent.getStringExtra(
402 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
403 if (initialTitleResPackageName != null) {
404 try {
405 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
406 0 /* flags */, new UserHandle(UserHandle.myUserId()));
407 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
408 setTitle(mInitialTitle);
409 mInitialTitleResId = -1;
410 return;
411 } catch (NameNotFoundException e) {
412 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
413 }
414 } else {
415 setTitle(mInitialTitleResId);
416 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700417 } else {
418 mInitialTitleResId = -1;
419 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
420 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
421 setTitle(mInitialTitle);
422 }
423 }
424
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800425 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800426 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700427 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800428 }
429
Fan Zhang28691572016-03-23 15:31:08 -0700430 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800431 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700432
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800433 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700434 if (mInitialTitleResId > 0) {
435 setTitle(mInitialTitleResId);
436 } else {
437 setTitle(mInitialTitle);
438 }
Fan Zhang28691572016-03-23 15:31:08 -0700439 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800440 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700441
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800442 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
443 setTitleFromBackStackEntry(bse);
444 }
445
446 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
447 final CharSequence title;
448 final int titleRes = bse.getBreadCrumbTitleRes();
449 if (titleRes > 0) {
450 title = getText(titleRes);
451 } else {
452 title = bse.getBreadCrumbTitle();
453 }
454 if (title != null) {
455 setTitle(title);
456 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800457 }
458
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800459 @Override
460 protected void onSaveInstanceState(Bundle outState) {
461 super.onSaveInstanceState(outState);
Matthew Fritze7d48ae82017-03-23 08:59:15 -0700462 saveState(outState);
463 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800464
Matthew Fritze7d48ae82017-03-23 08:59:15 -0700465 /**
466 * For testing purposes to avoid crashes from final variables in Activity's onSaveInstantState.
467 */
468 @VisibleForTesting
469 void saveState(Bundle outState) {
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700470 if (mCategories.size() > 0) {
471 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800472 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800473 }
474
475 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400476 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800477 super.onResume();
478
Tony Mantler3d84d562017-07-31 10:48:55 -0700479 mDevelopmentSettingsListener = new BroadcastReceiver() {
480 @Override
481 public void onReceive(Context context, Intent intent) {
482 updateTilesList();
483 }
484 };
485 LocalBroadcastManager.getInstance(this).registerReceiver(mDevelopmentSettingsListener,
486 new IntentFilter(DevelopmentSettingsEnabler.DEVELOPMENT_SETTINGS_CHANGED_ACTION));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800487
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800488 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700489
Jason Monk4da79e02015-09-10 10:54:36 -0400490 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800491 }
492
493 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400494 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800495 super.onPause();
Tony Mantler3d84d562017-07-31 10:48:55 -0700496 LocalBroadcastManager.getInstance(this).unregisterReceiver(mDevelopmentSettingsListener);
497 mDevelopmentSettingsListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800498 unregisterReceiver(mBatteryInfoReceiver);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800499 }
500
501 @Override
jackqdyulei6c355f52017-03-01 17:37:23 -0800502 public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
503 final Bitmap icon = getBitmapFromXmlResource(R.drawable.ic_launcher_settings);
504 taskDescription.setIcon(icon);
505 super.setTaskDescription(taskDescription);
506 }
507
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800508 protected boolean isValidFragment(String fragmentName) {
509 // Almost all fragments are wrapped in this,
510 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800511 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
512 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800513 }
514 return false;
515 }
516
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800517 @Override
518 public Intent getIntent() {
519 Intent superIntent = super.getIntent();
520 String startingFragment = getStartingFragmentClass(superIntent);
521 // This is called from super.onCreate, isMultiPane() is not yet reliable
522 // Do not use onIsHidingHeaders either, which relies itself on this method
523 if (startingFragment != null) {
524 Intent modIntent = new Intent(superIntent);
525 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
526 Bundle args = superIntent.getExtras();
527 if (args != null) {
528 args = new Bundle(args);
529 } else {
530 args = new Bundle();
531 }
532 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100533 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800534 return modIntent;
535 }
536 return superIntent;
537 }
538
539 /**
540 * Checks if the component name in the intent is different from the Settings class and
541 * returns the class name to load as a fragment.
542 */
543 private String getStartingFragmentClass(Intent intent) {
544 if (mFragmentClass != null) return mFragmentClass;
545
546 String intentClass = intent.getComponent().getClassName();
547 if (intentClass.equals(getClass().getName())) return null;
548
Fan Zhanga8cac7a2017-10-11 16:44:41 -0700549 if ("com.android.settings.RunningServices".equals(intentClass)
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800550 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
551 // Old names of manage apps.
Fan Zhanga8cac7a2017-10-11 16:44:41 -0700552 intentClass = ManageApplications.class.getName();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800553 }
554
555 return intentClass;
556 }
557
558 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800559 * Called by a preference panel fragment to finish itself.
560 *
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800561 * @param resultCode Optional result code to send back to the original
Fan Zhangf11c8852018-02-06 14:21:01 -0800562 * launching fragment.
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800563 * @param resultData Optional result data to send back to the original
Fan Zhangf11c8852018-02-06 14:21:01 -0800564 * launching fragment.
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800565 */
Fan Zhang47854c22018-02-19 13:54:09 -0800566 public void finishPreferencePanel(int resultCode, Intent resultData) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800567 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700568 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800569 }
570
571 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700572 * Switch to a specific Fragment with taking care of validation, Title and BackStack
573 */
574 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700575 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700576 if (validate && !isValidFragment(fragmentName)) {
577 throw new IllegalArgumentException("Invalid fragment for this activity: "
578 + fragmentName);
579 }
580 Fragment f = Fragment.instantiate(this, fragmentName, args);
581 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700582 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700583 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700584 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700585 }
586 if (addToBackStack) {
587 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
588 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700589 if (titleResId > 0) {
590 transaction.setBreadCrumbTitle(titleResId);
591 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700592 transaction.setBreadCrumbTitle(title);
593 }
594 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700595 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700596 return f;
597 }
598
Jason Monk4da79e02015-09-10 10:54:36 -0400599 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500600 // Generally the items that are will be changing from these updates will
601 // not be in the top list of tiles, so run it in the background and the
602 // SettingsDrawerActivity will pick up on the updates automatically.
603 AsyncTask.execute(new Runnable() {
604 @Override
605 public void run() {
606 doUpdateTilesList();
607 }
608 });
609 }
610
611 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400612 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700613 final UserManager um = UserManager.get(this);
614 final boolean isAdmin = um.isAdminUser();
Fan Zhangf3144942017-12-22 09:59:37 -0800615 final FeatureFactory featureFactory = FeatureFactory.getFactory(this);
Fan Zhangaeb94f02017-07-05 13:46:04 -0700616 boolean somethingChanged = false;
Jason Monk4da79e02015-09-10 10:54:36 -0400617 String packageName = getPackageName();
Fan Zhangaeb94f02017-07-05 13:46:04 -0700618 somethingChanged = setTileEnabled(
619 new ComponentName(packageName, WifiSettingsActivity.class.getName()),
620 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin) || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700621
Fan Zhangaeb94f02017-07-05 13:46:04 -0700622 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800623 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700624 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin)
625 || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700626
Rajeev Kumar4a5e3dc2017-07-18 19:21:34 -0700627
628 // Enable DataUsageSummaryActivity if the data plan feature flag is turned on otherwise
629 // enable DataPlanUsageSummaryActivity.
630 somethingChanged = setTileEnabled(
Fan Zhang3ed55b12018-02-07 13:50:09 -0800631 new ComponentName(packageName, Settings.DataUsageSummaryActivity.class.getName()),
Rajeev Kumar4a5e3dc2017-07-18 19:21:34 -0700632 Utils.isBandwidthControlEnabled() /* enabled */,
633 isAdmin) || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700634
jackqdyulei76ba0f72017-11-17 14:14:51 -0800635 somethingChanged = setTileEnabled(
636 new ComponentName(packageName,
637 Settings.ConnectedDeviceDashboardActivity.class.getName()),
Jerry Zhang40bd5702018-02-23 14:43:58 -0800638 !UserManager.isDeviceInDemoMode(this) /* enabled */,
jackqdyulei76ba0f72017-11-17 14:14:51 -0800639 isAdmin) || somethingChanged;
640
Fan Zhangaeb94f02017-07-05 13:46:04 -0700641 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800642 Settings.SimSettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700643 Utils.showSimCardTile(this), isAdmin)
644 || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700645
Fan Zhangf3144942017-12-22 09:59:37 -0800646 final boolean isBatterySettingsV2Enabled = featureFactory
jackqdyulei166102c2017-11-27 13:49:19 -0800647 .getPowerUsageFeatureProvider(this)
648 .isBatteryV2Enabled();
649 // Enable new battery page if v2 enabled
Fan Zhangaeb94f02017-07-05 13:46:04 -0700650 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800651 Settings.PowerUsageSummaryActivity.class.getName()),
jackqdyulei166102c2017-11-27 13:49:19 -0800652 mBatteryPresent && isBatterySettingsV2Enabled, isAdmin) || somethingChanged;
653 // Enable legacy battery page if v2 disabled
654 somethingChanged = setTileEnabled(new ComponentName(packageName,
655 Settings.PowerUsageSummaryLegacyActivity.class.getName()),
656 mBatteryPresent && !isBatterySettingsV2Enabled, isAdmin) || somethingChanged;
Jason Monk4da79e02015-09-10 10:54:36 -0400657
Eric Schwarzenbach98998a22018-02-06 15:57:01 -0800658 final boolean isDataUsageSettingsV2Enabled =
659 FeatureFlagUtils.isEnabled(this, FeatureFlags.DATA_USAGE_SETTINGS_V2);
660 // Enable new data usage page if v2 enabled
661 somethingChanged = setTileEnabled(new ComponentName(packageName,
662 Settings.DataUsageSummaryActivity.class.getName()),
663 Utils.isBandwidthControlEnabled() && isDataUsageSettingsV2Enabled, isAdmin)
664 || somethingChanged;
665 // Enable legacy data usage page if v2 disabled
666 somethingChanged = setTileEnabled(new ComponentName(packageName,
667 Settings.DataUsageSummaryLegacyActivity.class.getName()),
668 Utils.isBandwidthControlEnabled() && !isDataUsageSettingsV2Enabled, isAdmin)
669 || somethingChanged;
670
Fan Zhangaeb94f02017-07-05 13:46:04 -0700671 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800672 Settings.UserSettingsActivity.class.getName()),
Jason Monk4da79e02015-09-10 10:54:36 -0400673 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhangaeb94f02017-07-05 13:46:04 -0700674 && !Utils.isMonkeyRunning(), isAdmin)
675 || somethingChanged;
Jason Monk4da79e02015-09-10 10:54:36 -0400676
Fan Zhangaeb94f02017-07-05 13:46:04 -0700677 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800678 Settings.NetworkDashboardActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700679 !UserManager.isDeviceInDemoMode(this), isAdmin)
680 || somethingChanged;
Doris Ling26208222017-03-03 11:28:05 -0800681
Fan Zhangaeb94f02017-07-05 13:46:04 -0700682 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700683 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700684 !UserManager.isDeviceInDemoMode(this), isAdmin)
685 || somethingChanged;
Jason Monk4da79e02015-09-10 10:54:36 -0400686
Tony Mantler3d84d562017-07-31 10:48:55 -0700687 final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
Fan Zhang831f6302017-11-22 13:07:50 -0800688 && !Utils.isMonkeyRunning();
jeffreyhuangcb823d52017-11-17 11:19:44 -0800689
Fan Zhang4c26da92017-09-08 15:29:54 -0700690 somethingChanged = setTileEnabled(new ComponentName(packageName,
691 Settings.DevelopmentSettingsDashboardActivity.class.getName()),
jeffreyhuangcb823d52017-11-17 11:19:44 -0800692 showDev, isAdmin)
Fan Zhangaeb94f02017-07-05 13:46:04 -0700693 || somethingChanged;
Dan Sandler12c4ba42016-03-28 11:13:40 -0400694
Fan Zhanga6986e72017-03-08 09:24:45 -0800695 // Enable/disable backup settings depending on whether the user is admin.
Fan Zhangaeb94f02017-07-05 13:46:04 -0700696 somethingChanged = setTileEnabled(new ComponentName(packageName,
697 BackupSettingsActivity.class.getName()), true, isAdmin)
698 || somethingChanged;
Fan Zhanga6986e72017-03-08 09:24:45 -0800699
Fan Zhangaeb94f02017-07-05 13:46:04 -0700700 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhang4fcd5ed2017-03-10 12:25:35 -0800701 Settings.WifiDisplaySettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700702 WifiDisplaySettings.isAvailable(this), isAdmin)
703 || somethingChanged;
Fan Zhang4fcd5ed2017-03-10 12:25:35 -0800704
Daniel Nishi1e620952017-12-19 10:15:14 -0800705 // Enable/disable the Me Card page.
Fan Zhangcfd79a92018-02-28 10:03:43 -0800706 final boolean aboutPhoneV2Enabled = featureFactory
Daniel Nishi1e620952017-12-19 10:15:14 -0800707 .getAccountFeatureProvider()
Fan Zhangcfd79a92018-02-28 10:03:43 -0800708 .isAboutPhoneV2Enabled(this);
Daniel Nishi1e620952017-12-19 10:15:14 -0800709 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhang881d5792018-01-26 10:15:56 -0800710 Settings.MyDeviceInfoActivity.class.getName()),
Fan Zhangcfd79a92018-02-28 10:03:43 -0800711 aboutPhoneV2Enabled, isAdmin)
Daniel Nishi1e620952017-12-19 10:15:14 -0800712 || somethingChanged;
713 somethingChanged = setTileEnabled(new ComponentName(packageName,
714 Settings.DeviceInfoSettingsActivity.class.getName()),
Fan Zhangcfd79a92018-02-28 10:03:43 -0800715 !aboutPhoneV2Enabled, isAdmin)
Daniel Nishi1e620952017-12-19 10:15:14 -0800716 || somethingChanged;
717
Jason Monk4da79e02015-09-10 10:54:36 -0400718 if (UserHandle.MU_ENABLED && !isAdmin) {
Fan Zhanga6986e72017-03-08 09:24:45 -0800719
Jason Monk4da79e02015-09-10 10:54:36 -0400720 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhang78ab9f92017-02-27 16:10:05 -0800721 final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
Fan Zhanga6986e72017-03-08 09:24:45 -0800722 synchronized (categories) {
723 for (DashboardCategory category : categories) {
Fan Zhang7c8f8a02017-03-17 12:54:24 -0700724 final int tileCount = category.getTilesCount();
725 for (int i = 0; i < tileCount; i++) {
726 final ComponentName component = category.getTile(i).intent.getComponent();
727
Fan Zhanga6986e72017-03-08 09:24:45 -0800728 final String name = component.getClassName();
729 final boolean isEnabledForRestricted = ArrayUtils.contains(
730 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
731 if (packageName.equals(component.getPackageName())
732 && !isEnabledForRestricted) {
Fan Zhangaeb94f02017-07-05 13:46:04 -0700733 somethingChanged = setTileEnabled(component, false, isAdmin)
734 || somethingChanged;
Fan Zhanga6986e72017-03-08 09:24:45 -0800735 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700736 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700737 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700738 }
739 }
Doris Ling26bf0032016-06-15 18:16:09 -0700740
Fan Zhang224caad2017-01-06 11:42:48 -0800741 // Final step, refresh categories.
Fan Zhangaeb94f02017-07-05 13:46:04 -0700742 if (somethingChanged) {
743 Log.d(LOG_TAG, "Enabled state changed for some tiles, reloading all categories");
744 updateCategories();
745 } else {
746 Log.d(LOG_TAG, "No enabled state changed, skipping updateCategory call");
747 }
Jason Monk2ebc8a02015-02-13 15:23:19 -0500748 }
749
Fan Zhangaeb94f02017-07-05 13:46:04 -0700750 /**
751 * @return whether or not the enabled state actually changed.
752 */
753 private boolean setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -0400754 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Fan Zhang9ec45362017-01-10 11:55:45 -0800755 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
756 component.getClassName())) {
Jason Monk4da79e02015-09-10 10:54:36 -0400757 enabled = false;
758 }
Fan Zhangaeb94f02017-07-05 13:46:04 -0700759 return setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -0500760 }
761
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800762 private void getMetaData() {
763 try {
764 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
765 PackageManager.GET_META_DATA);
766 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800767 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
768 } catch (NameNotFoundException nnfe) {
769 // No recovery
770 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
771 }
772 }
773
774 // give subclasses access to the Next button
775 public boolean hasNextButton() {
776 return mNextButton != null;
777 }
778
779 public Button getNextButton() {
780 return mNextButton;
781 }
782
jackqdyulei6c355f52017-03-01 17:37:23 -0800783 @VisibleForTesting
784 Bitmap getBitmapFromXmlResource(int drawableRes) {
785 Drawable drawable = getResources().getDrawable(drawableRes, getTheme());
786 Canvas canvas = new Canvas();
787 Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
788 drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
789 canvas.setBitmap(bitmap);
790 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
791 drawable.draw(canvas);
792
793 return bitmap;
794 }
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700795}