blob: 33c8eca83e09d79c2746a306c88b42ce4ba12f4f [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 Zhang60f01072016-10-13 16:53:41 -070019import android.app.ActionBar;
Matthew Fritze7ac78f22016-10-03 13:26:07 -070020import android.app.ActivityManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080021import android.app.Fragment;
22import android.app.FragmentManager;
23import android.app.FragmentTransaction;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080024import android.content.BroadcastReceiver;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070025import android.content.ComponentName;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080026import android.content.Context;
27import android.content.Intent;
28import android.content.IntentFilter;
29import android.content.SharedPreferences;
30import android.content.pm.ActivityInfo;
31import android.content.pm.PackageManager;
32import android.content.pm.PackageManager.NameNotFoundException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080033import android.content.res.Configuration;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080034import android.nfc.NfcAdapter;
Jason Monkfd2c7222015-12-02 15:38:38 -050035import android.os.AsyncTask;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080036import android.os.Bundle;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080037import android.os.UserHandle;
38import android.os.UserManager;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080039import android.support.annotation.VisibleForTesting;
Jason Monk39b46742015-09-10 15:52:51 -040040import android.support.v14.preference.PreferenceFragment;
41import android.support.v7.preference.Preference;
42import android.support.v7.preference.PreferenceManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080043import android.text.TextUtils;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070044import android.transition.TransitionManager;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080045import android.util.Log;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070046import android.view.Menu;
47import android.view.MenuInflater;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080048import android.view.MenuItem;
49import android.view.View;
50import android.view.View.OnClickListener;
Fabrice Di Meglio59a40552014-05-23 16:46:50 -070051import android.view.ViewGroup;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080052import android.widget.Button;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070053import android.widget.SearchView;
Fan Zhang28691572016-03-23 15:31:08 -070054
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080055import com.android.internal.util.ArrayUtils;
Jason Monk4da79e02015-09-10 10:54:36 -040056import com.android.settings.Settings.WifiSettingsActivity;
Fan Zhanga3e8f5c2016-12-01 09:52:10 -080057import com.android.settings.core.gateway.SettingsGateway;
Fan Zhang5f79ae92016-08-18 16:04:19 -070058import com.android.settings.core.instrumentation.SharedPreferencesLogger;
Fan Zhang28691572016-03-23 15:31:08 -070059import com.android.settings.dashboard.DashboardContainerFragment;
Fan Zhanga96a2d82016-09-27 17:51:11 -070060import com.android.settings.dashboard.DashboardFeatureProvider;
61import com.android.settings.dashboard.DashboardSummary;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070062import com.android.settings.dashboard.SearchResultsSummary;
Fan Zhanga96a2d82016-09-27 17:51:11 -070063import com.android.settings.overlay.FeatureFactory;
Sunny Goyalbf9f2d22016-11-02 11:20:17 -070064import com.android.settings.qstile.DevelopmentModeTile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050065import com.android.settings.search.DynamicIndexableContentMonitor;
Matthew Fritze0ed37c32016-10-24 10:12:49 -070066import com.android.settings.search2.SearchFeatureProvider;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070067import com.android.settings.widget.SwitchBar;
Jason Monk4da79e02015-09-10 10:54:36 -040068import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040069import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -050070import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050071
Doris Ling26bf0032016-06-15 18:16:09 -070072import java.net.URISyntaxException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080073import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070075import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080076
Jason Monk4da79e02015-09-10 10:54:36 -040077public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080078 implements PreferenceManager.OnPreferenceTreeClickListener,
79 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010080 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070081 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010082 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080083
84 private static final String LOG_TAG = "Settings";
85
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080086 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
87
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080088 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070089 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070090 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
91 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070092 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070093 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080094
95 /**
96 * When starting this activity, the invoking Intent can contain this extra
97 * string to specify which fragment should be initially displayed.
98 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
99 * will call isValidFragment() to confirm that the fragment class name is valid for this
100 * activity.
101 */
102 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
103
104 /**
105 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
106 * this extra can also be specified to supply a Bundle of arguments to pass
107 * to that fragment when it is instantiated during the initial creation
108 * of the activity.
109 */
110 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
111
112 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700113 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
114 */
115 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
116
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800117 public static final String BACK_STACK_PREFS = ":settings:prefs";
118
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800119 // extras that allow any preference activity to be launched as part of a wizard
120
121 // show Back and Next buttons? takes boolean parameter
122 // Back will then return RESULT_CANCELED and Next RESULT_OK
123 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
124
125 // add a Skip button?
126 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
127
128 // specify custom text for the Back or Next buttons, or cause a button to not appear
129 // at all by setting it to null
130 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
131 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
132
133 /**
134 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700135 * 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 -0800136 * that fragment.
137 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700138 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100139 /**
140 * The package name used to resolve the title resource id.
141 */
142 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
143 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700144 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
145 ":settings:show_fragment_title_resid";
146 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
147 ":settings:show_fragment_as_shortcut";
148
149 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
150 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800151
Udam Saini92779ce2016-03-28 14:29:48 -0700152 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
153
Jason Monk30695812015-11-17 09:01:08 -0500154 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800155 "com.android.settings.FRAGMENT_CLASS";
156
157 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
158
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700159 private static final String EMPTY_QUERY = "";
160
Jason Monkd4f03ec2016-01-07 16:25:34 -0500161 private static final int REQUEST_SUGGESTION = 42;
162
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800163 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800164
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800165 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700166 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800167
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800168 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400169 private String[] SETTINGS_FOR_RESTRICTED = {
170 //wireless_section
171 WifiSettingsActivity.class.getName(),
172 Settings.BluetoothSettingsActivity.class.getName(),
173 Settings.DataUsageSummaryActivity.class.getName(),
174 Settings.SimSettingsActivity.class.getName(),
175 Settings.WirelessSettingsActivity.class.getName(),
176 //device_section
177 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500178 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400179 Settings.DisplaySettingsActivity.class.getName(),
180 Settings.StorageSettingsActivity.class.getName(),
181 Settings.ManageApplicationsActivity.class.getName(),
182 Settings.PowerUsageSummaryActivity.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700183 Settings.GestureSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400184 //personal_section
185 Settings.LocationSettingsActivity.class.getName(),
186 Settings.SecuritySettingsActivity.class.getName(),
187 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
188 Settings.UserSettingsActivity.class.getName(),
189 Settings.AccountSettingsActivity.class.getName(),
190 //system_section
191 Settings.DateTimeSettingsActivity.class.getName(),
192 Settings.DeviceInfoSettingsActivity.class.getName(),
193 Settings.AccessibilitySettingsActivity.class.getName(),
194 Settings.PrintSettingsActivity.class.getName(),
195 Settings.PaymentSettingsActivity.class.getName(),
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +0100196 Settings.EnterprisePrivacySettingsActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700197
198 // New IA
199 // Home page
Fan Zhangbb93dc02016-10-11 16:27:45 -0700200 Settings.NetworkDashboardActivity.class.getName(),
Fan Zhangf37be6a2016-10-20 12:47:52 -0700201 Settings.ConnectedDeviceDashboardActivity.class.getName(),
202 Settings.AppAndNotificationDashboardActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700203 "com.android.settings.Settings.BatteryDashboardAlias",
Fan Zhang66b573a2016-10-06 16:33:13 -0700204 "com.android.settings.Settings.DisplayDashboardAlias",
Doris Ling55578652016-10-18 13:08:29 -0700205 "com.android.settings.Settings.SoundDashboardAlias",
Fan Zhang8da6f882016-10-14 14:02:03 -0700206 "com.android.settings.Settings.SecurityDashboardAlias",
Doris Lingd7aae182016-10-21 11:33:54 -0700207 Settings.UserAndAccountDashboardActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700208 Settings.SystemDashboardActivity.class.getName(),
209 Settings.SupportDashboardActivity.class.getName(),
Fan Zhangcdacd1d2016-10-20 17:15:50 -0700210 // Home page > Apps & Notifications
211 "com.android.settings.Settings.ManageApplicationsDashboardAlias",
Fan Zhang4136d902016-10-21 14:23:56 -0700212 "com.android.settings.Settings.PaymentSettingsDashboardAlias",
Fan Zhangbb93dc02016-10-11 16:27:45 -0700213 // Home page > Network & Internet
214 "com.android.settings.Settings.WifiDashboardAlias",
215 "com.android.settings.Settings.DataUsageDashboardAlias",
Fan Zhang301fe802016-10-26 10:44:45 -0700216 // Home page > Security
217 "com.android.settings.Settings.LocationDashboardAlias",
Fan Zhangcc335d92016-09-29 14:37:14 -0700218 // Home page > System
Fan Zhanga1d1d672016-11-07 15:12:52 -0800219 Settings.LanguageAndRegionSettingsActivity.class.getName(),
220 Settings.InputAndGestureSettingsActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700221 "com.android.settings.Settings.DateTimeDashboardAlias",
222 "com.android.settings.Settings.AccessibilityDashboardAlias",
223 "com.android.settings.Settings.AboutDeviceDashboardAlias",
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800224 };
225
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700226 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
227 "android.settings.APPLICATION_DETAILS_SETTINGS"
228 };
229
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800230 private SharedPreferences mDevelopmentPreferences;
231 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
232
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800233 private boolean mBatteryPresent = true;
234 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800235 @Override
236 public void onReceive(Context context, Intent intent) {
237 String action = intent.getAction();
238 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
239 boolean batteryPresent = Utils.isBatteryPresent(intent);
240
241 if (mBatteryPresent != batteryPresent) {
242 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400243 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800244 }
245 }
246 }
247 };
248
Clara Bayarri6934a042015-10-14 11:07:35 +0100249 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
250 @Override
251 public void onReceive(Context context, Intent intent) {
252 String action = intent.getAction();
253 if (action.equals(Intent.ACTION_USER_ADDED)
254 || action.equals(Intent.ACTION_USER_REMOVED)) {
Matthew Fritze18fcb082016-12-08 09:54:13 -0800255 mSearchFeatureProvider.updateIndex(getApplicationContext());
Clara Bayarri6934a042015-10-14 11:07:35 +0100256 }
257 }
258 };
259
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800260 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700261
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700262 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700263 private SwitchBar mSwitchBar;
264
265 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700266
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700267 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700268 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700269
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700270 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700271 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700272
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700273 private ViewGroup mContent;
274
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700275 private SearchView mSearchView;
276 private MenuItem mSearchMenuItem;
277 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700278 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700279 private SearchFeatureProvider mSearchFeatureProvider;
280
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700281 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800282 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800283
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700284 private boolean mNeedToRevertToInitialFragment = false;
285
Fan Zhanga96a2d82016-09-27 17:51:11 -0700286 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700287 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500288 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700289
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800290 @VisibleForTesting
291 String mSearchQuery;
292
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700293 public SwitchBar getSwitchBar() {
294 return mSwitchBar;
295 }
296
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800297 @Override
298 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700299 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800300 null, 0);
301 return true;
302 }
303
304 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400305 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800306 return false;
307 }
308
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800309 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800310 public void onConfigurationChanged(Configuration newConfig) {
311 super.onConfigurationChanged(newConfig);
Matthew Fritze18fcb082016-12-08 09:54:13 -0800312 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800313 }
314
315 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700316 protected void onStart() {
317 super.onStart();
318
319 if (mNeedToRevertToInitialFragment) {
320 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800321 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800322 }
323
324 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700325 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700326 if (!mDisplaySearch) {
327 return false;
328 }
329
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700330 MenuInflater inflater = getMenuInflater();
Matthew Fritze9955db62016-12-20 09:37:21 -0800331 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700332 mSearchFeatureProvider.setUpSearchMenu(menu, this);
333 return true;
334 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700335 inflater.inflate(R.menu.options_menu, menu);
336
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700337
338 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700339 final String query = mSearchQuery;
340
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700341 mSearchMenuItem = menu.findItem(R.id.search);
342 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700343
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700344 if (mSearchMenuItem == null || mSearchView == null) {
345 return false;
346 }
347
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700348 if (mSearchResultsFragment != null) {
349 mSearchResultsFragment.setSearchView(mSearchView);
350 }
351
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700352 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700353 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700354 mSearchView.setOnQueryTextListener(this);
355 mSearchView.setOnCloseListener(this);
356
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700357 if (mSearchMenuItemExpanded) {
358 mSearchMenuItem.expandActionView();
359 }
360 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700361 return true;
362 }
363
Jason Monk31c7c322016-01-20 14:41:52 -0500364 @Override
365 public SharedPreferences getSharedPreferences(String name, int mode) {
366 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500367 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500368 }
369 return super.getSharedPreferences(name, mode);
370 }
371
Jason Monke4ebcd12016-02-21 09:37:41 -0500372 private String getMetricsTag() {
373 String tag = getClass().getName();
374 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
375 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
376 }
377 if (tag.startsWith("com.android.settings.")) {
378 tag = tag.replace("com.android.settings.", "");
379 }
380 return tag;
381 }
382
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700383 private static boolean isShortCutIntent(final Intent intent) {
384 Set<String> categories = intent.getCategories();
385 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
386 }
387
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700388 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700389 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700390 if (action == null) {
391 return false;
392 }
393 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
394 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
395 }
396 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700397 }
398
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700399 @Override
400 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700401 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500402 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700403
404 final FeatureFactory factory = FeatureFactory.getFactory(this);
405
406 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze9955db62016-12-20 09:37:21 -0800407 mSearchFeatureProvider = factory.getSearchFeatureProvider();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700408
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700409 // Should happen before any call to getIntent()
410 getMetaData();
411
412 final Intent intent = getIntent();
413 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
414 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800415 }
Udam Saini92779ce2016-03-28 14:29:48 -0700416 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
417 setIsDrawerPresent(false);
418 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800419
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800420 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
421 Context.MODE_PRIVATE);
422
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700423 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700424 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700425
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700426 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700427 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
428
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700429 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700430 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700431
Jason Monk4da79e02015-09-10 10:54:36 -0400432 mIsShowingDashboard = className.equals(Settings.class.getName())
433 || className.equals(Settings.WirelessSettings.class.getName())
434 || className.equals(Settings.DeviceSettings.class.getName())
435 || className.equals(Settings.PersonalSettings.class.getName())
436 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700437
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700438 // This is a "Sub Settings" when:
439 // - this is a real SubSettings
440 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700441 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700442 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
443
444 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
445 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700446 // Check also that we are not a Theme Dialog as we don't want to override them
447 final int themeResId = getThemeResId();
448 if (themeResId != R.style.Theme_DialogWhenLarge &&
449 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
450 setTheme(R.style.Theme_SubSettings);
451 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700452 }
453
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700454 setContentView(mIsShowingDashboard ?
455 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800456
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700457 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700458
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800459 getFragmentManager().addOnBackStackChangedListener(this);
460
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700461 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800462 // Run the Index update only if we have some space
463 if (!Utils.isLowStorage(this)) {
Fan Zhanga8759242017-01-06 09:18:59 -0800464 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800465 } else {
466 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
467 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700468 }
469
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700470 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700471 // We are restarting from a previous saved state; used that to initialize, instead
472 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700473 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
474 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700475 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800476
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700477 ArrayList<DashboardCategory> categories =
478 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
479 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700480 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700481 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700482 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800483 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700484
485 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700486 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700487
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800488 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700489 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400490 mDisplaySearch = false;
491 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700492 if (mIsShortcut) {
493 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700494 } else if (isSubSettings) {
495 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700496 } else {
497 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700498 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700499 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700500
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700501 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700502 switchToFragment(initialFragmentName, initialArguments, true, false,
503 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000504 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700505 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700506 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700507 // Show Search affordance
508 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700509 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700510
511 // add argument to indicate which settings tab should be initially selected
512 final Bundle args = new Bundle();
513 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
514 args.putString(extraName, intent.getStringExtra(extraName));
Fan Zhanga96a2d82016-09-27 17:51:11 -0700515 if (isDashboardFeatureEnabled()) {
516 switchToFragment(DashboardSummary.class.getName(), args, false, false,
517 mInitialTitleResId, mInitialTitle, false);
518 } else {
519 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
520 mInitialTitleResId, mInitialTitle, false);
521 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800522 }
523 }
524
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700525 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700526 if (mActionBar != null) {
527 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
528 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
529 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700530 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500531 if (mSwitchBar != null) {
532 mSwitchBar.setMetricsTag(getMetricsTag());
533 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700534
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800535 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800536 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
537
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700538 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800539 if (buttonBar != null) {
540 buttonBar.setVisibility(View.VISIBLE);
541
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700542 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800543 backButton.setOnClickListener(new OnClickListener() {
544 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700545 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800546 finish();
547 }
548 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700549 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800550 skipButton.setOnClickListener(new OnClickListener() {
551 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700552 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800553 finish();
554 }
555 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700556 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800557 mNextButton.setOnClickListener(new OnClickListener() {
558 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700559 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800560 finish();
561 }
562 });
563
564 // set our various button parameters
565 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
566 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
567 if (TextUtils.isEmpty(buttonText)) {
568 mNextButton.setVisibility(View.GONE);
569 }
570 else {
571 mNextButton.setText(buttonText);
572 }
573 }
574 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
575 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
576 if (TextUtils.isEmpty(buttonText)) {
577 backButton.setVisibility(View.GONE);
578 }
579 else {
580 backButton.setText(buttonText);
581 }
582 }
583 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
584 skipButton.setVisibility(View.VISIBLE);
585 }
586 }
587 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700588
Jason Monkfd2c7222015-12-02 15:38:38 -0500589 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
590 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700591 }
592
Fan Zhangece8ff62016-06-30 13:20:12 -0700593 public void setDisplaySearchMenu(boolean displaySearch) {
594 if (displaySearch != mDisplaySearch) {
595 mDisplaySearch = displaySearch;
596 invalidateOptionsMenu();
597 }
598 }
599
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700600 private void setTitleFromIntent(Intent intent) {
601 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
602 if (initialTitleResId > 0) {
603 mInitialTitle = null;
604 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100605
606 final String initialTitleResPackageName = intent.getStringExtra(
607 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
608 if (initialTitleResPackageName != null) {
609 try {
610 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
611 0 /* flags */, new UserHandle(UserHandle.myUserId()));
612 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
613 setTitle(mInitialTitle);
614 mInitialTitleResId = -1;
615 return;
616 } catch (NameNotFoundException e) {
617 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
618 }
619 } else {
620 setTitle(mInitialTitleResId);
621 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700622 } else {
623 mInitialTitleResId = -1;
624 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
625 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
626 setTitle(mInitialTitle);
627 }
628 }
629
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800630 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800631 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700632 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800633 }
634
Fan Zhang28691572016-03-23 15:31:08 -0700635 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800636 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700637
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800638 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700639 if (mInitialTitleResId > 0) {
640 setTitle(mInitialTitleResId);
641 } else {
642 setTitle(mInitialTitle);
643 }
Fan Zhang28691572016-03-23 15:31:08 -0700644 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800645 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700646
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800647 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
648 setTitleFromBackStackEntry(bse);
649 }
650
651 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
652 final CharSequence title;
653 final int titleRes = bse.getBreadCrumbTitleRes();
654 if (titleRes > 0) {
655 title = getText(titleRes);
656 } else {
657 title = bse.getBreadCrumbTitle();
658 }
659 if (title != null) {
660 setTitle(title);
661 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800662 }
663
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800664 @Override
665 protected void onSaveInstanceState(Bundle outState) {
666 super.onSaveInstanceState(outState);
667
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700668 if (mCategories.size() > 0) {
669 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800670 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700671
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700672 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700673 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700674
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700675 if (mDisplaySearch) {
676 // The option menus are created if the ActionBar is visible and they are also created
677 // asynchronously. If you launch Settings with an Intent action like
678 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
679 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
680 // menu item and search view are null.
681 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
682 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700683
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700684 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
685 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
686 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800687 }
688
689 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400690 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800691 super.onResume();
692
693 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
694 @Override
695 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400696 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800697 }
698 };
699 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
700 mDevelopmentPreferencesListener);
701
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800702 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100703 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
704 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800705 if (mDynamicIndexableContentMonitor == null) {
706 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
707 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800708 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700709
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700710 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700711 onQueryTextSubmit(mSearchQuery);
712 }
Jason Monk4da79e02015-09-10 10:54:36 -0400713 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800714 }
715
716 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400717 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800718 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800719 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000720 unregisterReceiver(mUserAddRemoveReceiver);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800721 if (mDynamicIndexableContentMonitor != null) {
Tadashi G. Takaokaa034fa52016-11-21 14:20:19 +0900722 mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800723 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800724 }
725
726 @Override
727 public void onDestroy() {
728 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700729
730 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
731 mDevelopmentPreferencesListener);
732 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800733 }
734
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800735 protected boolean isValidFragment(String fragmentName) {
736 // Almost all fragments are wrapped in this,
737 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800738 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
739 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800740 }
741 return false;
742 }
743
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800744 @Override
745 public Intent getIntent() {
746 Intent superIntent = super.getIntent();
747 String startingFragment = getStartingFragmentClass(superIntent);
748 // This is called from super.onCreate, isMultiPane() is not yet reliable
749 // Do not use onIsHidingHeaders either, which relies itself on this method
750 if (startingFragment != null) {
751 Intent modIntent = new Intent(superIntent);
752 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
753 Bundle args = superIntent.getExtras();
754 if (args != null) {
755 args = new Bundle(args);
756 } else {
757 args = new Bundle();
758 }
759 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100760 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800761 return modIntent;
762 }
763 return superIntent;
764 }
765
766 /**
767 * Checks if the component name in the intent is different from the Settings class and
768 * returns the class name to load as a fragment.
769 */
770 private String getStartingFragmentClass(Intent intent) {
771 if (mFragmentClass != null) return mFragmentClass;
772
773 String intentClass = intent.getComponent().getClassName();
774 if (intentClass.equals(getClass().getName())) return null;
775
776 if ("com.android.settings.ManageApplications".equals(intentClass)
777 || "com.android.settings.RunningServices".equals(intentClass)
778 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
779 // Old names of manage apps.
780 intentClass = com.android.settings.applications.ManageApplications.class.getName();
781 }
782
783 return intentClass;
784 }
785
786 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000787 * Start a new fragment containing a preference panel. If the preferences
788 * are being displayed in multi-pane mode, the given fragment class will
789 * be instantiated and placed in the appropriate pane. If running in
790 * single-pane mode, a new activity will be launched in which to show the
791 * fragment.
792 *
793 * @param fragmentClass Full name of the class implementing the fragment.
794 * @param args Any desired arguments to supply to the fragment.
795 * @param titleRes Optional resource identifier of the title of this
796 * fragment.
797 * @param titleText Optional text of the title of this fragment.
798 * @param resultTo Optional fragment that result data should be sent to.
799 * If non-null, resultTo.onActivityResult() will be called when this
800 * preference panel is done. The launched panel must use
801 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
802 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700803 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000804 */
805 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700806 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700807 String title = null;
808 if (titleRes < 0) {
809 if (titleText != null) {
810 title = titleText.toString();
811 } else {
812 // There not much we can do in that case
813 title = "";
814 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700815 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700816 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700817 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000818 }
819
820 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100821 * Start a new fragment in a new activity containing a preference panel for a given user. If the
822 * preferences are being displayed in multi-pane mode, the given fragment class will be
823 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
824 * activity will be launched in which to show the fragment.
825 *
826 * @param fragmentClass Full name of the class implementing the fragment.
827 * @param args Any desired arguments to supply to the fragment.
828 * @param titleRes Optional resource identifier of the title of this fragment.
829 * @param titleText Optional text of the title of this fragment.
830 * @param userHandle The user for which the panel has to be started.
831 */
832 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
833 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700834 // This is a workaround.
835 //
836 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
837 // starting the fragment could cause a native stack corruption. See b/17523189. However,
838 // adding that flag and start the preference panel with the same UserHandler will make it
839 // impossible to use back button to return to the previous screen. See b/20042570.
840 //
841 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
842 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
843 // when we're calling it as the same user.
844 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
845 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
846 } else {
847 String title = null;
848 if (titleRes < 0) {
849 if (titleText != null) {
850 title = titleText.toString();
851 } else {
852 // There not much we can do in that case
853 title = "";
854 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100855 }
Lifu Tangd0332852015-04-02 12:05:46 -0700856 Utils.startWithFragmentAsUser(this, fragmentClass, args,
857 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100858 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100859 }
860
861 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800862 * Called by a preference panel fragment to finish itself.
863 *
864 * @param caller The fragment that is asking to be finished.
865 * @param resultCode Optional result code to send back to the original
866 * launching fragment.
867 * @param resultData Optional result data to send back to the original
868 * launching fragment.
869 */
870 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
871 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700872 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800873 }
874
875 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000876 * Start a new fragment.
877 *
878 * @param fragment The fragment to start
879 * @param push If true, the current fragment will be pushed onto the back stack. If false,
880 * the current fragment will be replaced.
881 */
882 public void startPreferenceFragment(Fragment fragment, boolean push) {
883 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700884 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000885 if (push) {
886 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
887 transaction.addToBackStack(BACK_STACK_PREFS);
888 } else {
889 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
890 }
891 transaction.commitAllowingStateLoss();
892 }
893
894 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700895 * Switch to a specific Fragment with taking care of validation, Title and BackStack
896 */
897 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700898 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700899 if (validate && !isValidFragment(fragmentName)) {
900 throw new IllegalArgumentException("Invalid fragment for this activity: "
901 + fragmentName);
902 }
903 Fragment f = Fragment.instantiate(this, fragmentName, args);
904 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700905 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700906 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700907 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700908 }
909 if (addToBackStack) {
910 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
911 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700912 if (titleResId > 0) {
913 transaction.setBreadCrumbTitle(titleResId);
914 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700915 transaction.setBreadCrumbTitle(title);
916 }
917 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700918 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700919 return f;
920 }
921
Jason Monk4da79e02015-09-10 10:54:36 -0400922 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500923 // Generally the items that are will be changing from these updates will
924 // not be in the top list of tiles, so run it in the background and the
925 // SettingsDrawerActivity will pick up on the updates automatically.
926 AsyncTask.execute(new Runnable() {
927 @Override
928 public void run() {
929 doUpdateTilesList();
930 }
931 });
932 }
933
934 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400935 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700936 final UserManager um = UserManager.get(this);
937 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700938
Jason Monk4da79e02015-09-10 10:54:36 -0400939 String packageName = getPackageName();
940 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800941 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700942
Jason Monk4da79e02015-09-10 10:54:36 -0400943 setTileEnabled(new ComponentName(packageName,
944 Settings.BluetoothSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800945 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700946
Jason Monk4da79e02015-09-10 10:54:36 -0400947 setTileEnabled(new ComponentName(packageName,
948 Settings.DataUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800949 Utils.isBandwidthControlEnabled(), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700950
Jason Monk4da79e02015-09-10 10:54:36 -0400951 setTileEnabled(new ComponentName(packageName,
952 Settings.SimSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800953 Utils.showSimCardTile(this), isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700954
Jason Monk4da79e02015-09-10 10:54:36 -0400955 setTileEnabled(new ComponentName(packageName,
956 Settings.PowerUsageSummaryActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800957 mBatteryPresent, isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400958
959 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -0400960 Settings.UserSettingsActivity.class.getName()),
961 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
Fan Zhang224caad2017-01-06 11:42:48 -0800962 && !Utils.isMonkeyRunning(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400963
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700964 setTileEnabled(new ComponentName(packageName,
965 Settings.WirelessSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800966 !UserManager.isDeviceInDemoMode(this), isAdmin);
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700967
968 setTileEnabled(new ComponentName(packageName,
969 Settings.DateTimeSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800970 !UserManager.isDeviceInDemoMode(this), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400971 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
972 setTileEnabled(new ComponentName(packageName,
973 Settings.PaymentSettingsActivity.class.getName()),
974 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
975 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
Fan Zhang224caad2017-01-06 11:42:48 -0800976 && adapter != null && adapter.isEnabled(), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400977
978 setTileEnabled(new ComponentName(packageName,
979 Settings.PrintSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800980 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin);
Jason Monk4da79e02015-09-10 10:54:36 -0400981
982 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -0400983 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
984 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400985 setTileEnabled(new ComponentName(packageName,
986 Settings.DevelopmentSettingsActivity.class.getName()),
Fan Zhang224caad2017-01-06 11:42:48 -0800987 showDev, isAdmin);
Fan Zhangcc335d92016-09-29 14:37:14 -0700988 setTileEnabled(new ComponentName(packageName,
989 Settings.DevelopmentSettingsActivity.DASHBOARD_ALIAS),
Fan Zhang224caad2017-01-06 11:42:48 -0800990 showDev, isAdmin);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400991
992 // Reveal development-only quick settings tiles
Sunny Goyalbf9f2d22016-11-02 11:20:17 -0700993 setTileEnabled(new ComponentName(this, DevelopmentModeTile.class), showDev);
Jason Monk4da79e02015-09-10 10:54:36 -0400994
995 if (UserHandle.MU_ENABLED && !isAdmin) {
996 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhanga96a2d82016-09-27 17:51:11 -0700997 List<DashboardCategory> categories;
998 if (isDashboardFeatureEnabled()) {
999 categories = mDashboardFeatureProvider.getAllCategories();
1000 } else {
1001 categories = getDashboardCategories();
1002 }
1003
Jason Monk4da79e02015-09-10 10:54:36 -04001004 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001005 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001006 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001007 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001008 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
Fan Zhang224caad2017-01-06 11:42:48 -08001009 setTileEnabled(component, false, isAdmin);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001010 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001011 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001012 }
1013 }
Doris Ling26bf0032016-06-15 18:16:09 -07001014
1015 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
1016 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
1017 setTileEnabled(new ComponentName(packageName,
Fan Zhang224caad2017-01-06 11:42:48 -08001018 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin);
Fan Zhang0e8d0d12016-11-02 09:15:33 -07001019 setTileEnabled(new ComponentName(packageName,
1020 "com.android.settings.PrivacyDashboardAlias"),
Fan Zhang224caad2017-01-06 11:42:48 -08001021 useDefaultBackup, isAdmin);
Fan Zhang0e8d0d12016-11-02 09:15:33 -07001022
Doris Ling26bf0032016-06-15 18:16:09 -07001023 boolean hasBackupActivity = false;
1024 if (!useDefaultBackup) {
1025 try {
1026 Intent intent = Intent.parseUri(backupIntent, 0);
1027 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
1028 } catch (URISyntaxException e) {
1029 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
1030 }
1031 }
Fan Zhang10dd4652016-11-16 10:24:26 -08001032
Fan Zhang224caad2017-01-06 11:42:48 -08001033 // Enable/disable BackupSettingsActivity and its alias.
Doris Ling26bf0032016-06-15 18:16:09 -07001034 setTileEnabled(new ComponentName(packageName,
Fan Zhang224caad2017-01-06 11:42:48 -08001035 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin);
Fan Zhang10dd4652016-11-16 10:24:26 -08001036 setTileEnabled(new ComponentName(packageName,
Fan Zhang224caad2017-01-06 11:42:48 -08001037 "com.android.settings.BackupResetDashboardAlias"), hasBackupActivity, isAdmin);
Doris Ling26bf0032016-06-15 18:16:09 -07001038
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +01001039 setTileEnabled(new ComponentName(packageName,
1040 Settings.EnterprisePrivacySettingsActivity.class.getName()),
1041 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
Fan Zhang224caad2017-01-06 11:42:48 -08001042 .hasDeviceOwner(), isAdmin);
Fan Zhang10dd4652016-11-16 10:24:26 -08001043 setTileEnabled(new ComponentName(packageName,
1044 "com.android.settings.EnterprisePrivacyDashboardAlias"),
1045 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
Fan Zhang224caad2017-01-06 11:42:48 -08001046 .hasDeviceOwner(), isAdmin);
1047 // Final step, refresh categories.
1048 updateCategories();
Jason Monk2ebc8a02015-02-13 15:23:19 -05001049 }
1050
Fan Zhang224caad2017-01-06 11:42:48 -08001051 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin) {
Jason Monk5862c1e2016-06-07 14:02:33 -04001052 if (UserHandle.MU_ENABLED && !isAdmin && getPackageName().equals(component.getPackageName())
Jason Monk4da79e02015-09-10 10:54:36 -04001053 && !ArrayUtils.contains(SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1054 enabled = false;
1055 }
Jason Monk5862c1e2016-06-07 14:02:33 -04001056 setTileEnabled(component, enabled);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001057 }
1058
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001059 private void getMetaData() {
1060 try {
1061 ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
1062 PackageManager.GET_META_DATA);
1063 if (ai == null || ai.metaData == null) return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001064 mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
1065 } catch (NameNotFoundException nnfe) {
1066 // No recovery
1067 Log.d(LOG_TAG, "Cannot get Metadata for: " + getComponentName().toString());
1068 }
1069 }
1070
Fan Zhanga96a2d82016-09-27 17:51:11 -07001071 @Override
1072 protected boolean isDashboardFeatureEnabled() {
1073 if (mDashboardFeatureProvider == null) {
1074 mDashboardFeatureProvider =
1075 FeatureFactory.getFactory(this).getDashboardFeatureProvider(this);
1076 }
1077 return mDashboardFeatureProvider.isEnabled();
1078 }
1079
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001080 // give subclasses access to the Next button
1081 public boolean hasNextButton() {
1082 return mNextButton != null;
1083 }
1084
1085 public Button getNextButton() {
1086 return mNextButton;
1087 }
1088
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001089 @Override
1090 public boolean shouldUpRecreateTask(Intent targetIntent) {
1091 return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class));
1092 }
1093
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001094 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001095 @Override
1096 public boolean onQueryTextSubmit(String query) {
Matthew Fritze9955db62016-12-20 09:37:21 -08001097 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001098 return false;
1099 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001100 mSearchQuery = query;
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001101 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001102 return mSearchResultsFragment.onQueryTextSubmit(query);
1103 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001104
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001105 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001106 @Override
1107 public boolean onQueryTextChange(String newText) {
Fan Zhanga3e8f5c2016-12-01 09:52:10 -08001108 mSearchQuery = newText;
Matthew Fritze9955db62016-12-20 09:37:21 -08001109 if (mSearchFeatureProvider.isEnabled(this) || mSearchResultsFragment == null) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -07001110 return false;
1111 }
1112 return mSearchResultsFragment.onQueryTextChange(newText);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001113 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001114
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001115 @Override
1116 public boolean onClose() {
1117 return false;
1118 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001119
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001120 @Override
1121 public boolean onMenuItemActionExpand(MenuItem item) {
1122 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001123 switchToSearchResultsFragmentIfNeeded();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001124 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001125 return true;
1126 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001127
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001128 @Override
1129 public boolean onMenuItemActionCollapse(MenuItem item) {
1130 if (item.getItemId() == mSearchMenuItem.getItemId()) {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001131 if (mSearchMenuItemExpanded) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001132 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001133 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001134 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001135 return true;
1136 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001137
Jason Monk4da79e02015-09-10 10:54:36 -04001138 @Override
Jason Monkd4f03ec2016-01-07 16:25:34 -05001139 protected void onTileClicked(Tile tile) {
Jason Monk4da79e02015-09-10 10:54:36 -04001140 if (mIsShowingDashboard) {
1141 // If on dashboard, don't finish so the back comes back to here.
1142 openTile(tile);
1143 } else {
1144 super.onTileClicked(tile);
1145 }
1146 }
1147
Jason Monkaf001092015-11-04 13:16:18 -05001148 @Override
1149 public void onProfileTileOpen() {
1150 if (!mIsShowingDashboard) {
1151 finish();
1152 }
1153 }
1154
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001155 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001156 private void switchToSearchResultsFragmentIfNeeded() {
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001157 if (mSearchResultsFragment != null) {
1158 return;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001159 }
Anna Galusza6b1e9db2016-03-30 17:25:36 -07001160 Fragment current = getFragmentManager().findFragmentById(R.id.main_content);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001161 if (current != null && current instanceof SearchResultsSummary) {
1162 mSearchResultsFragment = (SearchResultsSummary) current;
1163 } else {
Fan Zhang28691572016-03-23 15:31:08 -07001164 setContentHeaderView(null);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001165 mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -07001166 SearchResultsSummary.class.getName(), null, false, true,
1167 R.string.search_results_title, null, true);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001168 }
Fabrice Di Megliod297a582014-04-22 17:23:23 -07001169 mSearchResultsFragment.setSearchView(mSearchView);
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001170 mSearchMenuItemExpanded = true;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001171 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001172
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001173 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001174 public void needToRevertToInitialFragment() {
1175 mNeedToRevertToInitialFragment = true;
1176 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001177
Matthew Fritze0ed37c32016-10-24 10:12:49 -07001178 @Deprecated
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001179 private void revertToInitialFragment() {
1180 mNeedToRevertToInitialFragment = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -07001181 mSearchResultsFragment = null;
Fabrice Di Megliobb16fd82014-04-04 14:48:05 -07001182 mSearchMenuItemExpanded = false;
1183 getFragmentManager().popBackStackImmediate(SettingsActivity.BACK_STACK_PREFS,
1184 FragmentManager.POP_BACK_STACK_INCLUSIVE);
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -07001185 if (mSearchMenuItem != null) {
1186 mSearchMenuItem.collapseActionView();
1187 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001188 }
Jim Miller0698a212014-10-16 19:49:07 -07001189
1190 public Intent getResultIntentData() {
1191 return mResultIntentData;
1192 }
1193
1194 public void setResultIntentData(Intent resultIntentData) {
1195 mResultIntentData = resultIntentData;
1196 }
Jason Monkd4f03ec2016-01-07 16:25:34 -05001197
1198 public void startSuggestion(Intent intent) {
Matthew Fritze7ac78f22016-10-03 13:26:07 -07001199 if (intent == null || ActivityManager.isUserAMonkey()) {
Matthew Fritze703dc602016-09-30 12:36:27 -07001200 return;
1201 }
Matthew Fritzef265dbc2016-10-04 13:39:27 -07001202 mCurrentSuggestion = intent.getComponent();
Jason Monkd4f03ec2016-01-07 16:25:34 -05001203 startActivityForResult(intent, REQUEST_SUGGESTION);
1204 }
1205
1206 @Override
1207 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1208 if (requestCode == REQUEST_SUGGESTION && mCurrentSuggestion != null
1209 && resultCode != RESULT_CANCELED) {
1210 getPackageManager().setComponentEnabledSetting(mCurrentSuggestion,
1211 PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
1212 }
1213 super.onActivityResult(requestCode, resultCode, data);
1214 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -08001215}