2 * Copyright (C) 2014 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings;
19 import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO;
21 import android.app.ActionBar;
22 import android.app.ActivityManager;
23 import android.app.Fragment;
24 import android.app.FragmentManager;
25 import android.app.FragmentTransaction;
26 import android.content.BroadcastReceiver;
27 import android.content.ComponentName;
28 import android.content.Context;
29 import android.content.Intent;
30 import android.content.IntentFilter;
31 import android.content.SharedPreferences;
32 import android.content.pm.ActivityInfo;
33 import android.content.pm.PackageManager;
34 import android.content.pm.PackageManager.NameNotFoundException;
35 import android.graphics.Bitmap;
36 import android.graphics.Canvas;
37 import android.graphics.drawable.Drawable;
38 import android.os.AsyncTask;
39 import android.os.Bundle;
40 import android.os.UserHandle;
41 import android.os.UserManager;
42 import android.support.annotation.VisibleForTesting;
43 import android.support.v14.preference.PreferenceFragment;
44 import android.support.v4.content.LocalBroadcastManager;
45 import android.support.v7.preference.Preference;
46 import android.support.v7.preference.PreferenceManager;
47 import android.text.TextUtils;
48 import android.transition.TransitionManager;
49 import android.util.FeatureFlagUtils;
50 import android.util.Log;
51 import android.view.View;
52 import android.view.View.OnClickListener;
53 import android.view.ViewGroup;
54 import android.widget.Button;
55 import android.widget.Toolbar;
57 import com.android.internal.util.ArrayUtils;
58 import com.android.settings.Settings.WifiSettingsActivity;
59 import com.android.settings.applications.manageapplications.ManageApplications;
60 import com.android.settings.backup.BackupSettingsActivity;
61 import com.android.settings.core.FeatureFlags;
62 import com.android.settings.core.SubSettingLauncher;
63 import com.android.settings.core.gateway.SettingsGateway;
64 import com.android.settings.dashboard.DashboardFeatureProvider;
65 import com.android.settings.dashboard.DashboardSummary;
66 import com.android.settings.development.DevelopmentSettingsDashboardFragment;
67 import com.android.settings.overlay.FeatureFactory;
68 import com.android.settings.search.DeviceIndexFeatureProvider;
69 import com.android.settings.wfd.WifiDisplaySettings;
70 import com.android.settings.widget.SwitchBar;
71 import com.android.settingslib.core.instrumentation.Instrumentable;
72 import com.android.settingslib.core.instrumentation.SharedPreferencesLogger;
73 import com.android.settingslib.development.DevelopmentSettingsEnabler;
74 import com.android.settingslib.drawer.DashboardCategory;
75 import com.android.settingslib.drawer.SettingsDrawerActivity;
76 import com.android.settingslib.utils.ThreadUtils;
78 import java.util.ArrayList;
79 import java.util.List;
81 public class SettingsActivity extends SettingsDrawerActivity
82 implements PreferenceManager.OnPreferenceTreeClickListener,
83 PreferenceFragment.OnPreferenceStartFragmentCallback,
84 ButtonBarHandler, FragmentManager.OnBackStackChangedListener {
86 private static final String LOG_TAG = "Settings";
88 // Constants for state save/restore
89 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
92 * When starting this activity, the invoking Intent can contain this extra
93 * string to specify which fragment should be initially displayed.
94 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
95 * will call isValidFragment() to confirm that the fragment class name is valid for this
98 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
101 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
102 * this extra can also be specified to supply a Bundle of arguments to pass
103 * to that fragment when it is instantiated during the initial creation
106 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
109 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
111 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
113 public static final String BACK_STACK_PREFS = ":settings:prefs";
115 // extras that allow any preference activity to be launched as part of a wizard
117 // show Back and Next buttons? takes boolean parameter
118 // Back will then return RESULT_CANCELED and Next RESULT_OK
119 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
121 // add a Skip button?
122 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
124 // specify custom text for the Back or Next buttons, or cause a button to not appear
125 // at all by setting it to null
126 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
127 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
130 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
131 * those extra can also be specify to supply the title or title res id to be shown for
134 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
136 * The package name used to resolve the title resource id.
138 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
139 ":settings:show_fragment_title_res_package_name";
140 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
141 ":settings:show_fragment_title_resid";
142 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
143 ":settings:show_fragment_as_shortcut";
145 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
146 ":settings:show_fragment_as_subsetting";
149 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
151 public static final String META_DATA_KEY_FRAGMENT_CLASS =
152 "com.android.settings.FRAGMENT_CLASS";
154 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
156 private String mFragmentClass;
158 private CharSequence mInitialTitle;
159 private int mInitialTitleResId;
161 private BroadcastReceiver mDevelopmentSettingsListener;
163 private boolean mBatteryPresent = true;
164 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
166 public void onReceive(Context context, Intent intent) {
167 String action = intent.getAction();
168 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
169 boolean batteryPresent = Utils.isBatteryPresent(intent);
171 if (mBatteryPresent != batteryPresent) {
172 mBatteryPresent = batteryPresent;
179 private SwitchBar mSwitchBar;
181 private Button mNextButton;
183 private boolean mIsShowingDashboard;
185 private ViewGroup mContent;
188 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
190 private DashboardFeatureProvider mDashboardFeatureProvider;
192 public SwitchBar getSwitchBar() {
197 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
198 new SubSettingLauncher(this)
199 .setDestination(pref.getFragment())
200 .setArguments(pref.getExtras())
201 .setSourceMetricsCategory(caller instanceof Instrumentable
202 ? ((Instrumentable) caller).getMetricsCategory()
203 : Instrumentable.METRICS_CATEGORY_UNKNOWN)
210 public boolean onPreferenceTreeClick(Preference preference) {
215 public SharedPreferences getSharedPreferences(String name, int mode) {
216 if (name.equals(getPackageName() + "_preferences")) {
217 return new SharedPreferencesLogger(this, getMetricsTag(),
218 FeatureFactory.getFactory(this).getMetricsFeatureProvider());
220 return super.getSharedPreferences(name, mode);
223 private String getMetricsTag() {
224 String tag = getClass().getName();
225 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
226 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
228 if (tag.startsWith("com.android.settings.")) {
229 tag = tag.replace("com.android.settings.", "");
235 protected void onCreate(Bundle savedState) {
236 super.onCreate(savedState);
237 long startTime = System.currentTimeMillis();
239 final FeatureFactory factory = FeatureFactory.getFactory(this);
241 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
243 // Should happen before any call to getIntent()
246 final Intent intent = getIntent();
247 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
248 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
251 // Getting Intent properties can only be done after the super.onCreate(...)
252 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
254 final ComponentName cn = intent.getComponent();
255 final String className = cn.getClassName();
257 mIsShowingDashboard = className.equals(Settings.class.getName());
259 // This is a "Sub Settings" when:
260 // - this is a real SubSettings
261 // - or :settings:show_fragment_as_subsetting is passed to the Intent
262 final boolean isSubSettings = this instanceof SubSettings ||
263 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
265 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content
268 setTheme(R.style.Theme_SubSettings);
271 setContentView(mIsShowingDashboard ?
272 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
274 mContent = findViewById(R.id.main_content);
276 getFragmentManager().addOnBackStackChangedListener(this);
278 if (savedState != null) {
279 // We are restarting from a previous saved state; used that to initialize, instead
280 // of starting fresh.
281 setTitleFromIntent(intent);
283 ArrayList<DashboardCategory> categories =
284 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
285 if (categories != null) {
287 mCategories.addAll(categories);
288 setTitleFromBackStack();
291 launchSettingFragment(initialFragmentName, isSubSettings, intent);
294 if (mIsShowingDashboard) {
295 findViewById(R.id.search_bar).setVisibility(View.VISIBLE);
296 findViewById(R.id.action_bar).setVisibility(View.GONE);
297 final Toolbar toolbar = findViewById(R.id.search_action_bar);
298 FeatureFactory.getFactory(this).getSearchFeatureProvider()
299 .initSearchToolbar(this, toolbar);
300 setActionBar(toolbar);
302 // Please forgive me for what I am about to do.
304 // Need to make the navigation icon non-clickable so that the entire card is clickable
305 // and goes to the search UI. Also set the background to null so there's no ripple.
306 View navView = toolbar.getNavigationView();
307 navView.setClickable(false);
308 navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
309 navView.setBackground(null);
312 ActionBar actionBar = getActionBar();
313 if (actionBar != null) {
314 boolean deviceProvisioned = Utils.isDeviceProvisioned(this);
315 actionBar.setDisplayHomeAsUpEnabled(deviceProvisioned);
316 actionBar.setHomeButtonEnabled(deviceProvisioned);
317 actionBar.setDisplayShowTitleEnabled(!mIsShowingDashboard);
319 mSwitchBar = findViewById(R.id.switch_bar);
320 if (mSwitchBar != null) {
321 mSwitchBar.setMetricsTag(getMetricsTag());
324 // see if we should show Back/Next buttons
325 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
327 View buttonBar = findViewById(R.id.button_bar);
328 if (buttonBar != null) {
329 buttonBar.setVisibility(View.VISIBLE);
331 Button backButton = (Button) findViewById(R.id.back_button);
332 backButton.setOnClickListener(new OnClickListener() {
333 public void onClick(View v) {
334 setResult(RESULT_CANCELED, null);
338 Button skipButton = (Button) findViewById(R.id.skip_button);
339 skipButton.setOnClickListener(new OnClickListener() {
340 public void onClick(View v) {
341 setResult(RESULT_OK, null);
345 mNextButton = (Button) findViewById(R.id.next_button);
346 mNextButton.setOnClickListener(new OnClickListener() {
347 public void onClick(View v) {
348 setResult(RESULT_OK, null);
353 // set our various button parameters
354 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
355 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
356 if (TextUtils.isEmpty(buttonText)) {
357 mNextButton.setVisibility(View.GONE);
359 mNextButton.setText(buttonText);
362 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
363 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
364 if (TextUtils.isEmpty(buttonText)) {
365 backButton.setVisibility(View.GONE);
367 backButton.setText(buttonText);
370 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
371 skipButton.setVisibility(View.VISIBLE);
377 Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
382 void launchSettingFragment(String initialFragmentName, boolean isSubSettings, Intent intent) {
383 if (!mIsShowingDashboard && initialFragmentName != null) {
384 setTitleFromIntent(intent);
386 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
387 switchToFragment(initialFragmentName, initialArguments, true, false,
388 mInitialTitleResId, mInitialTitle, false);
390 // Show search icon as up affordance if we are displaying the main Dashboard
391 mInitialTitleResId = R.string.dashboard_title;
393 switchToFragment(DashboardSummary.class.getName(), null /* args */, false, false,
394 mInitialTitleResId, mInitialTitle, false);
398 private void setTitleFromIntent(Intent intent) {
399 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
400 if (initialTitleResId > 0) {
401 mInitialTitle = null;
402 mInitialTitleResId = initialTitleResId;
404 final String initialTitleResPackageName = intent.getStringExtra(
405 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
406 if (initialTitleResPackageName != null) {
408 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
409 0 /* flags */, new UserHandle(UserHandle.myUserId()));
410 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
411 setTitle(mInitialTitle);
412 mInitialTitleResId = -1;
414 } catch (NameNotFoundException e) {
415 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
418 setTitle(mInitialTitleResId);
421 mInitialTitleResId = -1;
422 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
423 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
424 setTitle(mInitialTitle);
429 public void onBackStackChanged() {
430 setTitleFromBackStack();
433 private void setTitleFromBackStack() {
434 final int count = getFragmentManager().getBackStackEntryCount();
437 if (mInitialTitleResId > 0) {
438 setTitle(mInitialTitleResId);
440 setTitle(mInitialTitle);
445 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
446 setTitleFromBackStackEntry(bse);
449 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
450 final CharSequence title;
451 final int titleRes = bse.getBreadCrumbTitleRes();
453 title = getText(titleRes);
455 title = bse.getBreadCrumbTitle();
463 protected void onSaveInstanceState(Bundle outState) {
464 super.onSaveInstanceState(outState);
469 * For testing purposes to avoid crashes from final variables in Activity's onSaveInstantState.
472 void saveState(Bundle outState) {
473 if (mCategories.size() > 0) {
474 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
479 protected void onResume() {
482 mDevelopmentSettingsListener = new BroadcastReceiver() {
484 public void onReceive(Context context, Intent intent) {
488 LocalBroadcastManager.getInstance(this).registerReceiver(mDevelopmentSettingsListener,
489 new IntentFilter(DevelopmentSettingsEnabler.DEVELOPMENT_SETTINGS_CHANGED_ACTION));
491 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
498 protected void onPause() {
500 LocalBroadcastManager.getInstance(this).unregisterReceiver(mDevelopmentSettingsListener);
501 mDevelopmentSettingsListener = null;
502 unregisterReceiver(mBatteryInfoReceiver);
506 public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
507 final Bitmap icon = getBitmapFromXmlResource(R.drawable.ic_launcher_settings);
508 taskDescription.setIcon(icon);
509 super.setTaskDescription(taskDescription);
512 protected boolean isValidFragment(String fragmentName) {
513 // Almost all fragments are wrapped in this,
514 // except for a few that have their own activities.
515 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
516 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
522 public Intent getIntent() {
523 Intent superIntent = super.getIntent();
524 String startingFragment = getStartingFragmentClass(superIntent);
525 // This is called from super.onCreate, isMultiPane() is not yet reliable
526 // Do not use onIsHidingHeaders either, which relies itself on this method
527 if (startingFragment != null) {
528 Intent modIntent = new Intent(superIntent);
529 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
530 Bundle args = superIntent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
532 args = new Bundle(args);
536 args.putParcelable("intent", superIntent);
537 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
544 * Checks if the component name in the intent is different from the Settings class and
545 * returns the class name to load as a fragment.
547 private String getStartingFragmentClass(Intent intent) {
548 if (mFragmentClass != null) return mFragmentClass;
550 String intentClass = intent.getComponent().getClassName();
551 if (intentClass.equals(getClass().getName())) return null;
553 if ("com.android.settings.RunningServices".equals(intentClass)
554 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
555 // Old names of manage apps.
556 intentClass = ManageApplications.class.getName();
563 * Called by a preference panel fragment to finish itself.
565 * @param resultCode Optional result code to send back to the original
566 * launching fragment.
567 * @param resultData Optional result data to send back to the original
568 * launching fragment.
570 public void finishPreferencePanel(int resultCode, Intent resultData) {
571 setResult(resultCode, resultData);
576 * Switch to a specific Fragment with taking care of validation, Title and BackStack
578 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
579 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
580 if (validate && !isValidFragment(fragmentName)) {
581 throw new IllegalArgumentException("Invalid fragment for this activity: "
584 Fragment f = Fragment.instantiate(this, fragmentName, args);
585 FragmentTransaction transaction = getFragmentManager().beginTransaction();
586 transaction.replace(R.id.main_content, f);
587 if (withTransition) {
588 TransitionManager.beginDelayedTransition(mContent);
590 if (addToBackStack) {
591 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
593 if (titleResId > 0) {
594 transaction.setBreadCrumbTitle(titleResId);
595 } else if (title != null) {
596 transaction.setBreadCrumbTitle(title);
598 transaction.commitAllowingStateLoss();
599 getFragmentManager().executePendingTransactions();
603 private void updateTilesList() {
604 // Generally the items that are will be changing from these updates will
605 // not be in the top list of tiles, so run it in the background and the
606 // SettingsDrawerActivity will pick up on the updates automatically.
607 AsyncTask.execute(new Runnable() {
615 private void updateDeviceIndex() {
616 DeviceIndexFeatureProvider indexProvider = FeatureFactory.getFactory(
617 this).getDeviceIndexFeatureProvider();
619 ThreadUtils.postOnBackgroundThread(
620 () -> indexProvider.updateIndex(SettingsActivity.this, false /* force */));
623 private void doUpdateTilesList() {
624 PackageManager pm = getPackageManager();
625 final UserManager um = UserManager.get(this);
626 final boolean isAdmin = um.isAdminUser();
627 final FeatureFactory featureFactory = FeatureFactory.getFactory(this);
628 boolean somethingChanged = false;
629 String packageName = getPackageName();
630 somethingChanged = setTileEnabled(
631 new ComponentName(packageName, WifiSettingsActivity.class.getName()),
632 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin) || somethingChanged;
634 somethingChanged = setTileEnabled(new ComponentName(packageName,
635 Settings.BluetoothSettingsActivity.class.getName()),
636 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin)
640 // Enable DataUsageSummaryActivity if the data plan feature flag is turned on otherwise
641 // enable DataPlanUsageSummaryActivity.
642 somethingChanged = setTileEnabled(
643 new ComponentName(packageName, Settings.DataUsageSummaryActivity.class.getName()),
644 Utils.isBandwidthControlEnabled() /* enabled */,
645 isAdmin) || somethingChanged;
647 somethingChanged = setTileEnabled(
648 new ComponentName(packageName,
649 Settings.ConnectedDeviceDashboardActivity.class.getName()),
650 !UserManager.isDeviceInDemoMode(this) /* enabled */,
651 isAdmin) || somethingChanged;
653 somethingChanged = setTileEnabled(new ComponentName(packageName,
654 Settings.SimSettingsActivity.class.getName()),
655 Utils.showSimCardTile(this), isAdmin)
658 somethingChanged = setTileEnabled(new ComponentName(packageName,
659 Settings.PowerUsageSummaryActivity.class.getName()),
660 mBatteryPresent, isAdmin) || somethingChanged;
662 final boolean isDataUsageSettingsV2Enabled =
663 FeatureFlagUtils.isEnabled(this, FeatureFlags.DATA_USAGE_SETTINGS_V2);
664 // Enable new data usage page if v2 enabled
665 somethingChanged = setTileEnabled(new ComponentName(packageName,
666 Settings.DataUsageSummaryActivity.class.getName()),
667 Utils.isBandwidthControlEnabled() && isDataUsageSettingsV2Enabled, isAdmin)
669 // Enable legacy data usage page if v2 disabled
670 somethingChanged = setTileEnabled(new ComponentName(packageName,
671 Settings.DataUsageSummaryLegacyActivity.class.getName()),
672 Utils.isBandwidthControlEnabled() && !isDataUsageSettingsV2Enabled, isAdmin)
675 somethingChanged = setTileEnabled(new ComponentName(packageName,
676 Settings.UserSettingsActivity.class.getName()),
677 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
678 && !Utils.isMonkeyRunning(), isAdmin)
681 somethingChanged = setTileEnabled(new ComponentName(packageName,
682 Settings.NetworkDashboardActivity.class.getName()),
683 !UserManager.isDeviceInDemoMode(this), isAdmin)
686 somethingChanged = setTileEnabled(new ComponentName(packageName,
687 Settings.DateTimeSettingsActivity.class.getName()),
688 !UserManager.isDeviceInDemoMode(this), isAdmin)
691 final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)
692 && !Utils.isMonkeyRunning();
693 final boolean isAdminOrDemo = um.isAdminUser() || um.isDemoUser();
694 somethingChanged = setTileEnabled(new ComponentName(packageName,
695 Settings.DevelopmentSettingsDashboardActivity.class.getName()),
696 showDev, isAdminOrDemo)
699 // Enable/disable backup settings depending on whether the user is admin.
700 somethingChanged = setTileEnabled(new ComponentName(packageName,
701 BackupSettingsActivity.class.getName()), true, isAdmin)
704 somethingChanged = setTileEnabled(new ComponentName(packageName,
705 Settings.WifiDisplaySettingsActivity.class.getName()),
706 WifiDisplaySettings.isAvailable(this), isAdmin)
709 // Enable/disable the Me Card page.
710 final boolean aboutPhoneV2Enabled = featureFactory
711 .getAccountFeatureProvider()
712 .isAboutPhoneV2Enabled(this);
713 somethingChanged = setTileEnabled(new ComponentName(packageName,
714 Settings.MyDeviceInfoActivity.class.getName()),
715 aboutPhoneV2Enabled, isAdmin)
717 somethingChanged = setTileEnabled(new ComponentName(packageName,
718 Settings.DeviceInfoSettingsActivity.class.getName()),
719 !aboutPhoneV2Enabled, isAdmin)
722 if (UserHandle.MU_ENABLED && !isAdmin) {
724 // When on restricted users, disable all extra categories (but only the settings ones).
725 final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
726 synchronized (categories) {
727 for (DashboardCategory category : categories) {
728 final int tileCount = category.getTilesCount();
729 for (int i = 0; i < tileCount; i++) {
730 final ComponentName component = category.getTile(i).intent.getComponent();
731 final String name = component.getClassName();
732 final boolean isEnabledForRestricted = ArrayUtils.contains(
733 SettingsGateway.SETTINGS_FOR_RESTRICTED, name) || (isAdminOrDemo
734 && Settings.DevelopmentSettingsDashboardActivity.class.getName()
736 if (packageName.equals(component.getPackageName())
737 && !isEnabledForRestricted) {
738 somethingChanged = setTileEnabled(component, false, isAdmin)
746 // Final step, refresh categories.
747 if (somethingChanged) {
748 Log.d(LOG_TAG, "Enabled state changed for some tiles, reloading all categories");
751 Log.d(LOG_TAG, "No enabled state changed, skipping updateCategory call");
756 * @return whether or not the enabled state actually changed.
758 private boolean setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
759 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
760 && !ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED,
761 component.getClassName())) {
764 return setTileEnabled(component, enabled);
767 private void getMetaData() {
769 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
770 PackageManager.GET_META_DATA);
771 if (ai == null || ai.metaData == null) return;
772 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
773 } catch (NameNotFoundException nnfe) {
775 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
779 // give subclasses access to the Next button
780 public boolean hasNextButton() {
781 return mNextButton != null;
784 public Button getNextButton() {
789 Bitmap getBitmapFromXmlResource(int drawableRes) {
790 Drawable drawable = getResources().getDrawable(drawableRes, getTheme());
791 Canvas canvas = new Canvas();
792 Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
793 drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
794 canvas.setBitmap(bitmap);
795 drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
796 drawable.draw(canvas);