blob: a21153d38f7b46dcbdb8f21e353de8fc5e23ccc4 [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.MetricsFeatureProvider;
71import com.android.settingslib.core.instrumentation.SharedPreferencesLogger;
Tony Mantler3d84d562017-07-31 10:48:55 -070072import com.android.settingslib.development.DevelopmentSettingsEnabler;
Jason Monk4da79e02015-09-10 10:54:36 -040073import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040074import com.android.settingslib.drawer.SettingsDrawerActivity;
Fan Zhang4c26da92017-09-08 15:29:54 -070075
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077import java.util.List;
78
Jason Monk4da79e02015-09-10 10:54:36 -040079public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080080 implements PreferenceManager.OnPreferenceTreeClickListener,
81 PreferenceFragment.OnPreferenceStartFragmentCallback,
Fan Zhangff4da232017-11-09 14:07:23 -080082 ButtonBarHandler, FragmentManager.OnBackStackChangedListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080083
84 private static final String LOG_TAG = "Settings";
85
86 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070087 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080088
89 /**
90 * When starting this activity, the invoking Intent can contain this extra
91 * string to specify which fragment should be initially displayed.
92 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
93 * will call isValidFragment() to confirm that the fragment class name is valid for this
94 * activity.
95 */
96 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
97
98 /**
99 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
100 * this extra can also be specified to supply a Bundle of arguments to pass
101 * to that fragment when it is instantiated during the initial creation
102 * of the activity.
103 */
104 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
105
106 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700107 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
108 */
109 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
110
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800111 public static final String BACK_STACK_PREFS = ":settings:prefs";
112
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800113 // extras that allow any preference activity to be launched as part of a wizard
114
115 // show Back and Next buttons? takes boolean parameter
116 // Back will then return RESULT_CANCELED and Next RESULT_OK
117 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
118
119 // add a Skip button?
120 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
121
122 // specify custom text for the Back or Next buttons, or cause a button to not appear
123 // at all by setting it to null
124 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
125 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
126
127 /**
128 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700129 * 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 -0800130 * that fragment.
131 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700132 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100133 /**
134 * The package name used to resolve the title resource id.
135 */
136 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
137 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700138 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
139 ":settings:show_fragment_title_resid";
140 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
141 ":settings:show_fragment_as_shortcut";
142
143 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
144 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800145
Fan Zhang78ab9f92017-02-27 16:10:05 -0800146 @Deprecated
Udam Saini92779ce2016-03-28 14:29:48 -0700147 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
148
Jason Monk30695812015-11-17 09:01:08 -0500149 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fan Zhangf11c8852018-02-06 14:21:01 -0800150 "com.android.settings.FRAGMENT_CLASS";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800151
152 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
153
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800154 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800155
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800156 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700157 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800158
Tony Mantler3d84d562017-07-31 10:48:55 -0700159 private BroadcastReceiver mDevelopmentSettingsListener;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800160
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800161 private boolean mBatteryPresent = true;
162 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800163 @Override
164 public void onReceive(Context context, Intent intent) {
165 String action = intent.getAction();
166 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
167 boolean batteryPresent = Utils.isBatteryPresent(intent);
168
169 if (mBatteryPresent != batteryPresent) {
170 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400171 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800172 }
173 }
174 }
175 };
176
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700177 private SwitchBar mSwitchBar;
178
179 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700180
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700181 private boolean mIsShowingDashboard;
182
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700183 private ViewGroup mContent;
184
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700185 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800186 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800187
Fan Zhanga96a2d82016-09-27 17:51:11 -0700188 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700189
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700190 public SwitchBar getSwitchBar() {
191 return mSwitchBar;
192 }
193
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800194 @Override
195 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Fan Zhang7cf99f52018-02-16 10:37:37 -0800196 new SubSettingLauncher(this)
197 .setDestination(pref.getFragment())
198 .setArguments(pref.getExtras())
199 .setSourceMetricsCategory(caller instanceof Instrumentable
200 ? ((Instrumentable) caller).getMetricsCategory()
201 : Instrumentable.METRICS_CATEGORY_UNKNOWN)
202 .setTitle(-1)
203 .launch();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800204 return true;
205 }
206
207 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400208 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800209 return false;
210 }
211
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800212 @Override
Jason Monk31c7c322016-01-20 14:41:52 -0500213 public SharedPreferences getSharedPreferences(String name, int mode) {
214 if (name.equals(getPackageName() + "_preferences")) {
Leif Hendrik Wilden28dee1f2018-01-11 10:15:36 -0800215 return new SharedPreferencesLogger(this, getMetricsTag(),
216 FeatureFactory.getFactory(this).getMetricsFeatureProvider());
Jason Monk31c7c322016-01-20 14:41:52 -0500217 }
218 return super.getSharedPreferences(name, mode);
219 }
220
Jason Monke4ebcd12016-02-21 09:37:41 -0500221 private String getMetricsTag() {
222 String tag = getClass().getName();
223 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
224 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
225 }
226 if (tag.startsWith("com.android.settings.")) {
227 tag = tag.replace("com.android.settings.", "");
228 }
229 return tag;
230 }
231
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700232 @Override
233 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700234 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500235 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700236
237 final FeatureFactory factory = FeatureFactory.getFactory(this);
238
239 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700240
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700241 // Should happen before any call to getIntent()
242 getMetaData();
243
244 final Intent intent = getIntent();
245 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
246 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800247 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800248
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700249 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700250 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700251
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700252 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700253 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700254
Doris Ling1694d4b2017-03-03 14:21:37 -0800255 mIsShowingDashboard = className.equals(Settings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700256
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700257 // This is a "Sub Settings" when:
258 // - this is a real SubSettings
259 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700260 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700261 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
262
Fan Zhang92f1e942017-01-21 10:07:26 -0800263 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content
264 // insets
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700265 if (isSubSettings) {
Fan Zhang92f1e942017-01-21 10:07:26 -0800266 setTheme(R.style.Theme_SubSettings);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700267 }
268
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700269 setContentView(mIsShowingDashboard ?
270 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800271
Andrew Sappersteina2dd9972017-06-25 13:51:08 -0700272 mContent = findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700273
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800274 getFragmentManager().addOnBackStackChangedListener(this);
275
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700276 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700277 // We are restarting from a previous saved state; used that to initialize, instead
278 // of starting fresh.
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700279 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800280
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700281 ArrayList<DashboardCategory> categories =
282 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
283 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700284 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700285 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700286 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800287 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800288 } else {
Doris Lingcb69baf2017-02-23 17:50:03 -0800289 launchSettingFragment(initialFragmentName, isSubSettings, intent);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800290 }
291
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700292 if (mIsShowingDashboard) {
293 findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
294 findViewById(R.id.action_bar).setVisibility(View.GONE);
Fan Zhangff4da232017-11-09 14:07:23 -0800295 final Toolbar toolbar = findViewById(R.id.search_action_bar);
296 FeatureFactory.getFactory(this).getSearchFeatureProvider()
297 .initSearchToolbar(this, toolbar);
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700298 setActionBar(toolbar);
Andrew Sappersteinc2174642017-06-25 15:18:46 -0700299
300 // Please forgive me for what I am about to do.
301 //
302 // Need to make the navigation icon non-clickable so that the entire card is clickable
303 // and goes to the search UI. Also set the background to null so there's no ripple.
304 View navView = toolbar.getNavigationView();
305 navView.setClickable(false);
Fan Zhang6013a952018-02-06 11:36:07 -0800306 navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
Andrew Sappersteinc2174642017-06-25 15:18:46 -0700307 navView.setBackground(null);
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700308 }
309
Andrew Sappersteina2dd9972017-06-25 13:51:08 -0700310 ActionBar actionBar = getActionBar();
311 if (actionBar != null) {
Fan Zhangf11c8852018-02-06 14:21:01 -0800312 actionBar.setDisplayHomeAsUpEnabled(true);
313 actionBar.setHomeButtonEnabled(true);
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 *
Fan Zhangf11c8852018-02-06 14:21:01 -0800561 * @param caller The fragment that is asking to be finished.
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800562 * @param resultCode Optional result code to send back to the original
Fan Zhangf11c8852018-02-06 14:21:01 -0800563 * launching fragment.
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800564 * @param resultData Optional result data to send back to the original
Fan Zhangf11c8852018-02-06 14:21:01 -0800565 * launching fragment.
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800566 */
567 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
568 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700569 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800570 }
571
572 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000573 * Start a new fragment.
574 *
575 * @param fragment The fragment to start
Fan Zhangf11c8852018-02-06 14:21:01 -0800576 * @param push If true, the current fragment will be pushed onto the back stack. If false,
577 * the current fragment will be replaced.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000578 */
579 public void startPreferenceFragment(Fragment fragment, boolean push) {
580 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700581 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000582 if (push) {
583 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
584 transaction.addToBackStack(BACK_STACK_PREFS);
585 } else {
586 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
587 }
588 transaction.commitAllowingStateLoss();
589 }
590
591 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700592 * Switch to a specific Fragment with taking care of validation, Title and BackStack
593 */
594 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700595 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700596 if (validate && !isValidFragment(fragmentName)) {
597 throw new IllegalArgumentException("Invalid fragment for this activity: "
598 + fragmentName);
599 }
600 Fragment f = Fragment.instantiate(this, fragmentName, args);
601 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700602 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700603 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700604 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700605 }
606 if (addToBackStack) {
607 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
608 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700609 if (titleResId > 0) {
610 transaction.setBreadCrumbTitle(titleResId);
611 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700612 transaction.setBreadCrumbTitle(title);
613 }
614 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700615 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700616 return f;
617 }
618
Jason Monk4da79e02015-09-10 10:54:36 -0400619 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500620 // Generally the items that are will be changing from these updates will
621 // not be in the top list of tiles, so run it in the background and the
622 // SettingsDrawerActivity will pick up on the updates automatically.
623 AsyncTask.execute(new Runnable() {
624 @Override
625 public void run() {
626 doUpdateTilesList();
627 }
628 });
629 }
630
631 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400632 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700633 final UserManager um = UserManager.get(this);
634 final boolean isAdmin = um.isAdminUser();
Fan Zhangf3144942017-12-22 09:59:37 -0800635 final FeatureFactory featureFactory = FeatureFactory.getFactory(this);
Fan Zhangaeb94f02017-07-05 13:46:04 -0700636 boolean somethingChanged = false;
Jason Monk4da79e02015-09-10 10:54:36 -0400637 String packageName = getPackageName();
Fan Zhangaeb94f02017-07-05 13:46:04 -0700638 somethingChanged = setTileEnabled(
639 new ComponentName(packageName, WifiSettingsActivity.class.getName()),
640 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin) || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700641
Fan Zhangaeb94f02017-07-05 13:46:04 -0700642 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800643 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700644 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin)
645 || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700646
Rajeev Kumar4a5e3dc2017-07-18 19:21:34 -0700647
648 // Enable DataUsageSummaryActivity if the data plan feature flag is turned on otherwise
649 // enable DataPlanUsageSummaryActivity.
650 somethingChanged = setTileEnabled(
Fan Zhang3ed55b12018-02-07 13:50:09 -0800651 new ComponentName(packageName, Settings.DataUsageSummaryActivity.class.getName()),
Rajeev Kumar4a5e3dc2017-07-18 19:21:34 -0700652 Utils.isBandwidthControlEnabled() /* enabled */,
653 isAdmin) || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700654
jackqdyulei76ba0f72017-11-17 14:14:51 -0800655 final boolean isConnectedDeviceV2Enabled =
656 Settings.ConnectedDeviceDashboardActivity.isEnabled();
657 // Enable new connected page if v2 enabled
658 somethingChanged = setTileEnabled(
659 new ComponentName(packageName,
660 Settings.ConnectedDeviceDashboardActivity.class.getName()),
661 isConnectedDeviceV2Enabled && !UserManager.isDeviceInDemoMode(this) /* enabled */,
662 isAdmin) || somethingChanged;
663 // Enable old connected page if v2 disabled
664 somethingChanged = setTileEnabled(
665 new ComponentName(packageName,
666 Settings.ConnectedDeviceDashboardActivityOld.class.getName()),
667 !isConnectedDeviceV2Enabled && !UserManager.isDeviceInDemoMode(this) /* enabled */,
668 isAdmin) || somethingChanged;
669
Fan Zhangaeb94f02017-07-05 13:46:04 -0700670 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800671 Settings.SimSettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700672 Utils.showSimCardTile(this), isAdmin)
673 || somethingChanged;
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700674
Fan Zhangf3144942017-12-22 09:59:37 -0800675 final boolean isBatterySettingsV2Enabled = featureFactory
jackqdyulei166102c2017-11-27 13:49:19 -0800676 .getPowerUsageFeatureProvider(this)
677 .isBatteryV2Enabled();
678 // Enable new battery page if v2 enabled
Fan Zhangaeb94f02017-07-05 13:46:04 -0700679 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800680 Settings.PowerUsageSummaryActivity.class.getName()),
jackqdyulei166102c2017-11-27 13:49:19 -0800681 mBatteryPresent && isBatterySettingsV2Enabled, isAdmin) || somethingChanged;
682 // Enable legacy battery page if v2 disabled
683 somethingChanged = setTileEnabled(new ComponentName(packageName,
684 Settings.PowerUsageSummaryLegacyActivity.class.getName()),
685 mBatteryPresent && !isBatterySettingsV2Enabled, isAdmin) || somethingChanged;
Jason Monk4da79e02015-09-10 10:54:36 -0400686
Eric Schwarzenbach98998a22018-02-06 15:57:01 -0800687 final boolean isDataUsageSettingsV2Enabled =
688 FeatureFlagUtils.isEnabled(this, FeatureFlags.DATA_USAGE_SETTINGS_V2);
689 // Enable new data usage page if v2 enabled
690 somethingChanged = setTileEnabled(new ComponentName(packageName,
691 Settings.DataUsageSummaryActivity.class.getName()),
692 Utils.isBandwidthControlEnabled() && isDataUsageSettingsV2Enabled, isAdmin)
693 || somethingChanged;
694 // Enable legacy data usage page if v2 disabled
695 somethingChanged = setTileEnabled(new ComponentName(packageName,
696 Settings.DataUsageSummaryLegacyActivity.class.getName()),
697 Utils.isBandwidthControlEnabled() && !isDataUsageSettingsV2Enabled, isAdmin)
698 || somethingChanged;
699
Fan Zhangaeb94f02017-07-05 13:46:04 -0700700 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800701 Settings.UserSettingsActivity.class.getName()),
Jason Monk4da79e02015-09-10 10:54:36 -0400702 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhangaeb94f02017-07-05 13:46:04 -0700703 && !Utils.isMonkeyRunning(), isAdmin)
704 || somethingChanged;
Jason Monk4da79e02015-09-10 10:54:36 -0400705
Fan Zhangaeb94f02017-07-05 13:46:04 -0700706 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhanga6986e72017-03-08 09:24:45 -0800707 Settings.NetworkDashboardActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700708 !UserManager.isDeviceInDemoMode(this), isAdmin)
709 || somethingChanged;
Doris Ling26208222017-03-03 11:28:05 -0800710
Fan Zhangaeb94f02017-07-05 13:46:04 -0700711 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700712 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700713 !UserManager.isDeviceInDemoMode(this), isAdmin)
714 || somethingChanged;
Jason Monk4da79e02015-09-10 10:54:36 -0400715
Tony Mantler3d84d562017-07-31 10:48:55 -0700716 final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
Fan Zhang831f6302017-11-22 13:07:50 -0800717 && !Utils.isMonkeyRunning();
jeffreyhuangcb823d52017-11-17 11:19:44 -0800718
Fan Zhang4c26da92017-09-08 15:29:54 -0700719 somethingChanged = setTileEnabled(new ComponentName(packageName,
720 Settings.DevelopmentSettingsDashboardActivity.class.getName()),
jeffreyhuangcb823d52017-11-17 11:19:44 -0800721 showDev, isAdmin)
Fan Zhangaeb94f02017-07-05 13:46:04 -0700722 || somethingChanged;
Dan Sandler12c4ba42016-03-28 11:13:40 -0400723
Fan Zhanga6986e72017-03-08 09:24:45 -0800724 // Enable/disable backup settings depending on whether the user is admin.
Fan Zhangaeb94f02017-07-05 13:46:04 -0700725 somethingChanged = setTileEnabled(new ComponentName(packageName,
726 BackupSettingsActivity.class.getName()), true, isAdmin)
727 || somethingChanged;
Fan Zhanga6986e72017-03-08 09:24:45 -0800728
Fan Zhangaeb94f02017-07-05 13:46:04 -0700729 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhang4fcd5ed2017-03-10 12:25:35 -0800730 Settings.WifiDisplaySettingsActivity.class.getName()),
Fan Zhangaeb94f02017-07-05 13:46:04 -0700731 WifiDisplaySettings.isAvailable(this), isAdmin)
732 || somethingChanged;
Fan Zhang4fcd5ed2017-03-10 12:25:35 -0800733
Daniel Nishi1e620952017-12-19 10:15:14 -0800734 // Enable/disable the Me Card page.
735 final boolean isMeCardEnabled = featureFactory
736 .getAccountFeatureProvider()
737 .isMeCardEnabled(this);
738 somethingChanged = setTileEnabled(new ComponentName(packageName,
Fan Zhang881d5792018-01-26 10:15:56 -0800739 Settings.MyDeviceInfoActivity.class.getName()),
Daniel Nishi1e620952017-12-19 10:15:14 -0800740 isMeCardEnabled, isAdmin)
741 || somethingChanged;
742 somethingChanged = setTileEnabled(new ComponentName(packageName,
743 Settings.DeviceInfoSettingsActivity.class.getName()),
744 !isMeCardEnabled, isAdmin)
745 || somethingChanged;
746
Jason Monk4da79e02015-09-10 10:54:36 -0400747 if (UserHandle.MU_ENABLED && !isAdmin) {
Fan Zhanga6986e72017-03-08 09:24:45 -0800748
Jason Monk4da79e02015-09-10 10:54:36 -0400749 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhang78ab9f92017-02-27 16:10:05 -0800750 final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
Fan Zhanga6986e72017-03-08 09:24:45 -0800751 synchronized (categories) {
752 for (DashboardCategory category : categories) {
Fan Zhang7c8f8a02017-03-17 12:54:24 -0700753 final int tileCount = category.getTilesCount();
754 for (int i = 0; i < tileCount; i++) {
755 final ComponentName component = category.getTile(i).intent.getComponent();
756
Fan Zhanga6986e72017-03-08 09:24:45 -0800757 final String name = component.getClassName();
758 final boolean isEnabledForRestricted = ArrayUtils.contains(
759 SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
760 if (packageName.equals(component.getPackageName())
761 && !isEnabledForRestricted) {
Fan Zhangaeb94f02017-07-05 13:46:04 -0700762 somethingChanged = setTileEnabled(component, false, isAdmin)
763 || somethingChanged;
Fan Zhanga6986e72017-03-08 09:24:45 -0800764 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700765 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700766 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700767 }
768 }
Doris Ling26bf0032016-06-15 18:16:09 -0700769
Fan Zhang224caad2017-01-06 11:42:48 -0800770 // Final step, refresh categories.
Fan Zhangaeb94f02017-07-05 13:46:04 -0700771 if (somethingChanged) {
772 Log.d(LOG_TAG, "Enabled state changed for some tiles, reloading all categories");
773 updateCategories();
774 } else {
775 Log.d(LOG_TAG, "No enabled state changed, skipping updateCategory call");
776 }
Jason Monk2ebc8a02015-02-13 15:23:19 -0500777 }
778
Fan Zhangaeb94f02017-07-05 13:46:04 -0700779 /**
780 * @return whether or not the enabled state actually changed.
781 */
782 private boolean setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -0400783 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Fan Zhang9ec45362017-01-10 11:55:45 -0800784 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
785 component.getClassName())) {
Jason Monk4da79e02015-09-10 10:54:36 -0400786 enabled = false;
787 }
Fan Zhangaeb94f02017-07-05 13:46:04 -0700788 return setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -0500789 }
790
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800791 private void getMetaData() {
792 try {
793 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
794 PackageManager.GET_META_DATA);
795 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800796 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
797 } catch (NameNotFoundException nnfe) {
798 // No recovery
799 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
800 }
801 }
802
803 // give subclasses access to the Next button
804 public boolean hasNextButton() {
805 return mNextButton != null;
806 }
807
808 public Button getNextButton() {
809 return mNextButton;
810 }
811
jackqdyulei6c355f52017-03-01 17:37:23 -0800812 @VisibleForTesting
813 Bitmap getBitmapFromXmlResource(int drawableRes) {
814 Drawable drawable = getResources().getDrawable(drawableRes, getTheme());
815 Canvas canvas = new Canvas();
816 Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
817 drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
818 canvas.setBitmap(bitmap);
819 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
820 drawable.draw(canvas);
821
822 return bitmap;
823 }
Andrew Sapperstein048f6fb2017-05-28 12:20:10 -0700824}