blob: d5920e525838dd615f0e82d7fced4c1452d5e297 [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;
66import com.android.settings.search.Index;
Matthew Fritze0ed37c32016-10-24 10:12:49 -070067import com.android.settings.search2.SearchFeatureProvider;
Fabrice Di Meglio41937762014-05-13 19:51:59 -070068import com.android.settings.widget.SwitchBar;
Jason Monk4da79e02015-09-10 10:54:36 -040069import com.android.settingslib.drawer.DashboardCategory;
Jason Monk4da79e02015-09-10 10:54:36 -040070import com.android.settingslib.drawer.SettingsDrawerActivity;
Jason Monk7ea14c52016-01-22 14:28:02 -050071import com.android.settingslib.drawer.Tile;
Jason Monk2ebc8a02015-02-13 15:23:19 -050072
Doris Ling26bf0032016-06-15 18:16:09 -070073import java.net.URISyntaxException;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080074import java.util.ArrayList;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080075import java.util.List;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -070076import java.util.Set;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080077
Jason Monk4da79e02015-09-10 10:54:36 -040078public class SettingsActivity extends SettingsDrawerActivity
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080079 implements PreferenceManager.OnPreferenceTreeClickListener,
80 PreferenceFragment.OnPreferenceStartFragmentCallback,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010081 ButtonBarHandler, FragmentManager.OnBackStackChangedListener,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070082 SearchView.OnQueryTextListener, SearchView.OnCloseListener,
Alexandra Gherghinacfc7f9d2014-07-04 12:25:38 +010083 MenuItem.OnActionExpandListener {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080084
85 private static final String LOG_TAG = "Settings";
86
Philip P. Moltmannd9779db2016-02-24 12:11:05 -080087 private static final int LOADER_ID_INDEXABLE_CONTENT_MONITOR = 1;
88
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080089 // Constants for state save/restore
Fabrice Di Meglio769630c2014-04-24 14:48:48 -070090 private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
Fabrice Di Megliod25314d2014-03-21 19:24:43 -070091 private static final String SAVE_KEY_SEARCH_MENU_EXPANDED = ":settings:search_menu_expanded";
92 private static final String SAVE_KEY_SEARCH_QUERY = ":settings:search_query";
Fabrice Di Megliob731dd02014-04-03 18:40:38 -070093 private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -070094 private static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -080095
96 /**
97 * When starting this activity, the invoking Intent can contain this extra
98 * string to specify which fragment should be initially displayed.
99 * <p/>Starting from Key Lime Pie, when this argument is passed in, the activity
100 * will call isValidFragment() to confirm that the fragment class name is valid for this
101 * activity.
102 */
103 public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
104
105 /**
106 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
107 * this extra can also be specified to supply a Bundle of arguments to pass
108 * to that fragment when it is instantiated during the initial creation
109 * of the activity.
110 */
111 public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
112
113 /**
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700114 * Fragment "key" argument passed thru {@link #EXTRA_SHOW_FRAGMENT_ARGUMENTS}
115 */
116 public static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
117
Fabrice Di Meglio6f0739a2014-02-03 18:12:25 -0800118 public static final String BACK_STACK_PREFS = ":settings:prefs";
119
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800120 // extras that allow any preference activity to be launched as part of a wizard
121
122 // show Back and Next buttons? takes boolean parameter
123 // Back will then return RESULT_CANCELED and Next RESULT_OK
124 protected static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";
125
126 // add a Skip button?
127 private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip";
128
129 // specify custom text for the Back or Next buttons, or cause a button to not appear
130 // at all by setting it to null
131 protected static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
132 protected static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";
133
134 /**
135 * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700136 * 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 -0800137 * that fragment.
138 */
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700139 public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100140 /**
141 * The package name used to resolve the title resource id.
142 */
143 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME =
144 ":settings:show_fragment_title_res_package_name";
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700145 public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID =
146 ":settings:show_fragment_title_resid";
147 public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT =
148 ":settings:show_fragment_as_shortcut";
149
150 public static final String EXTRA_SHOW_FRAGMENT_AS_SUBSETTING =
151 ":settings:show_fragment_as_subsetting";
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800152
Udam Saini92779ce2016-03-28 14:29:48 -0700153 public static final String EXTRA_HIDE_DRAWER = ":settings:hide_drawer";
154
Jason Monk30695812015-11-17 09:01:08 -0500155 public static final String META_DATA_KEY_FRAGMENT_CLASS =
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800156 "com.android.settings.FRAGMENT_CLASS";
157
158 private static final String EXTRA_UI_OPTIONS = "settings:ui_options";
159
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700160 private static final String EMPTY_QUERY = "";
161
Jason Monkd4f03ec2016-01-07 16:25:34 -0500162 private static final int REQUEST_SUGGESTION = 42;
163
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800164 private String mFragmentClass;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800165
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800166 private CharSequence mInitialTitle;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700167 private int mInitialTitleResId;
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800168
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800169 // Show only these settings for restricted users
Jason Monk4da79e02015-09-10 10:54:36 -0400170 private String[] SETTINGS_FOR_RESTRICTED = {
171 //wireless_section
172 WifiSettingsActivity.class.getName(),
173 Settings.BluetoothSettingsActivity.class.getName(),
174 Settings.DataUsageSummaryActivity.class.getName(),
175 Settings.SimSettingsActivity.class.getName(),
176 Settings.WirelessSettingsActivity.class.getName(),
177 //device_section
178 Settings.HomeSettingsActivity.class.getName(),
Julia Reynolds8c0a4232015-11-24 10:08:14 -0500179 Settings.SoundSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400180 Settings.DisplaySettingsActivity.class.getName(),
181 Settings.StorageSettingsActivity.class.getName(),
182 Settings.ManageApplicationsActivity.class.getName(),
183 Settings.PowerUsageSummaryActivity.class.getName(),
Doris Ling91365232016-05-23 17:06:26 -0700184 Settings.GestureSettingsActivity.class.getName(),
Jason Monk4da79e02015-09-10 10:54:36 -0400185 //personal_section
186 Settings.LocationSettingsActivity.class.getName(),
187 Settings.SecuritySettingsActivity.class.getName(),
188 Settings.InputMethodAndLanguageSettingsActivity.class.getName(),
189 Settings.UserSettingsActivity.class.getName(),
190 Settings.AccountSettingsActivity.class.getName(),
191 //system_section
192 Settings.DateTimeSettingsActivity.class.getName(),
193 Settings.DeviceInfoSettingsActivity.class.getName(),
194 Settings.AccessibilitySettingsActivity.class.getName(),
195 Settings.PrintSettingsActivity.class.getName(),
196 Settings.PaymentSettingsActivity.class.getName(),
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +0100197 Settings.EnterprisePrivacySettingsActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700198
199 // New IA
200 // Home page
Fan Zhangbb93dc02016-10-11 16:27:45 -0700201 Settings.NetworkDashboardActivity.class.getName(),
Fan Zhangf37be6a2016-10-20 12:47:52 -0700202 Settings.ConnectedDeviceDashboardActivity.class.getName(),
203 Settings.AppAndNotificationDashboardActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700204 "com.android.settings.Settings.BatteryDashboardAlias",
Fan Zhang66b573a2016-10-06 16:33:13 -0700205 "com.android.settings.Settings.DisplayDashboardAlias",
Doris Ling55578652016-10-18 13:08:29 -0700206 "com.android.settings.Settings.SoundDashboardAlias",
Fan Zhang8da6f882016-10-14 14:02:03 -0700207 "com.android.settings.Settings.SecurityDashboardAlias",
Doris Lingd7aae182016-10-21 11:33:54 -0700208 Settings.UserAndAccountDashboardActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700209 Settings.SystemDashboardActivity.class.getName(),
210 Settings.SupportDashboardActivity.class.getName(),
Fan Zhangcdacd1d2016-10-20 17:15:50 -0700211 // Home page > Apps & Notifications
212 "com.android.settings.Settings.ManageApplicationsDashboardAlias",
Fan Zhang4136d902016-10-21 14:23:56 -0700213 "com.android.settings.Settings.PaymentSettingsDashboardAlias",
Fan Zhangbb93dc02016-10-11 16:27:45 -0700214 // Home page > Network & Internet
215 "com.android.settings.Settings.WifiDashboardAlias",
216 "com.android.settings.Settings.DataUsageDashboardAlias",
Fan Zhang301fe802016-10-26 10:44:45 -0700217 // Home page > Security
218 "com.android.settings.Settings.LocationDashboardAlias",
Fan Zhangcc335d92016-09-29 14:37:14 -0700219 // Home page > System
Fan Zhanga1d1d672016-11-07 15:12:52 -0800220 Settings.LanguageAndRegionSettingsActivity.class.getName(),
221 Settings.InputAndGestureSettingsActivity.class.getName(),
Fan Zhangcc335d92016-09-29 14:37:14 -0700222 "com.android.settings.Settings.DateTimeDashboardAlias",
223 "com.android.settings.Settings.AccessibilityDashboardAlias",
224 "com.android.settings.Settings.AboutDeviceDashboardAlias",
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800225 };
226
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700227 private static final String[] LIKE_SHORTCUT_INTENT_ACTION_ARRAY = {
228 "android.settings.APPLICATION_DETAILS_SETTINGS"
229 };
230
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800231 private SharedPreferences mDevelopmentPreferences;
232 private SharedPreferences.OnSharedPreferenceChangeListener mDevelopmentPreferencesListener;
233
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800234 private boolean mBatteryPresent = true;
235 private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800236 @Override
237 public void onReceive(Context context, Intent intent) {
238 String action = intent.getAction();
239 if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
240 boolean batteryPresent = Utils.isBatteryPresent(intent);
241
242 if (mBatteryPresent != batteryPresent) {
243 mBatteryPresent = batteryPresent;
Jason Monk4da79e02015-09-10 10:54:36 -0400244 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800245 }
246 }
247 }
248 };
249
Clara Bayarri6934a042015-10-14 11:07:35 +0100250 private final BroadcastReceiver mUserAddRemoveReceiver = new BroadcastReceiver() {
251 @Override
252 public void onReceive(Context context, Intent intent) {
253 String action = intent.getAction();
254 if (action.equals(Intent.ACTION_USER_ADDED)
255 || action.equals(Intent.ACTION_USER_REMOVED)) {
Matthew Fritze18fcb082016-12-08 09:54:13 -0800256 mSearchFeatureProvider.updateIndex(getApplicationContext());
Clara Bayarri6934a042015-10-14 11:07:35 +0100257 }
258 }
259 };
260
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800261 private DynamicIndexableContentMonitor mDynamicIndexableContentMonitor;
Svetoslav853e4712014-04-14 10:10:25 -0700262
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700263 private ActionBar mActionBar;
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700264 private SwitchBar mSwitchBar;
265
266 private Button mNextButton;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700267
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700268 private boolean mDisplayHomeAsUpEnabled;
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700269 private boolean mDisplaySearch;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700270
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700271 private boolean mIsShowingDashboard;
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700272 private boolean mIsShortcut;
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700273
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700274 private ViewGroup mContent;
275
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700276 private SearchView mSearchView;
277 private MenuItem mSearchMenuItem;
278 private boolean mSearchMenuItemExpanded = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700279 private SearchResultsSummary mSearchResultsFragment;
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700280 private SearchFeatureProvider mSearchFeatureProvider;
281
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700282 // Categories
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800283 private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800284
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700285 private boolean mNeedToRevertToInitialFragment = false;
286
Fan Zhanga96a2d82016-09-27 17:51:11 -0700287 private DashboardFeatureProvider mDashboardFeatureProvider;
Jim Miller0698a212014-10-16 19:49:07 -0700288 private Intent mResultIntentData;
Jason Monkd4f03ec2016-01-07 16:25:34 -0500289 private ComponentName mCurrentSuggestion;
Jim Miller0698a212014-10-16 19:49:07 -0700290
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800291 @VisibleForTesting
292 String mSearchQuery;
293
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700294 public SwitchBar getSwitchBar() {
295 return mSwitchBar;
296 }
297
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800298 @Override
299 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
Sunny Goyal21ef89f2016-05-25 12:41:16 -0700300 startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800301 null, 0);
302 return true;
303 }
304
305 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400306 public boolean onPreferenceTreeClick(Preference preference) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800307 return false;
308 }
309
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800310 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800311 public void onConfigurationChanged(Configuration newConfig) {
312 super.onConfigurationChanged(newConfig);
Matthew Fritze18fcb082016-12-08 09:54:13 -0800313 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800314 }
315
316 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700317 protected void onStart() {
318 super.onStart();
319
320 if (mNeedToRevertToInitialFragment) {
321 revertToInitialFragment();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800322 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800323 }
324
325 @Override
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700326 public boolean onCreateOptionsMenu(Menu menu) {
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700327 if (!mDisplaySearch) {
328 return false;
329 }
330
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700331 MenuInflater inflater = getMenuInflater();
Matthew Fritze9955db62016-12-20 09:37:21 -0800332 if (mSearchFeatureProvider.isEnabled(this)) {
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700333 mSearchFeatureProvider.setUpSearchMenu(menu, this);
334 return true;
335 }
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700336 inflater.inflate(R.menu.options_menu, menu);
337
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700338
339 // Cache the search query (can be overridden by the OnQueryTextListener)
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700340 final String query = mSearchQuery;
341
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700342 mSearchMenuItem = menu.findItem(R.id.search);
343 mSearchView = (SearchView) mSearchMenuItem.getActionView();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700344
Fabrice Di Meglio23ae00c2014-04-21 12:43:20 -0700345 if (mSearchMenuItem == null || mSearchView == null) {
346 return false;
347 }
348
Fabrice Di Meglio8c3b0ce2014-05-12 18:54:32 -0700349 if (mSearchResultsFragment != null) {
350 mSearchResultsFragment.setSearchView(mSearchView);
351 }
352
Fabrice Di Meglio95937822014-03-31 19:46:42 -0700353 mSearchMenuItem.setOnActionExpandListener(this);
Fan Zhangb9239182016-08-22 13:59:59 -0700354 mSearchView.setMaxWidth(Integer.MAX_VALUE);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700355 mSearchView.setOnQueryTextListener(this);
356 mSearchView.setOnCloseListener(this);
357
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700358 if (mSearchMenuItemExpanded) {
359 mSearchMenuItem.expandActionView();
360 }
361 mSearchView.setQuery(query, true /* submit */);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700362 return true;
363 }
364
Jason Monk31c7c322016-01-20 14:41:52 -0500365 @Override
366 public SharedPreferences getSharedPreferences(String name, int mode) {
367 if (name.equals(getPackageName() + "_preferences")) {
Jason Monke4ebcd12016-02-21 09:37:41 -0500368 return new SharedPreferencesLogger(this, getMetricsTag());
Jason Monk31c7c322016-01-20 14:41:52 -0500369 }
370 return super.getSharedPreferences(name, mode);
371 }
372
Jason Monke4ebcd12016-02-21 09:37:41 -0500373 private String getMetricsTag() {
374 String tag = getClass().getName();
375 if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
376 tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
377 }
378 if (tag.startsWith("com.android.settings.")) {
379 tag = tag.replace("com.android.settings.", "");
380 }
381 return tag;
382 }
383
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700384 private static boolean isShortCutIntent(final Intent intent) {
385 Set<String> categories = intent.getCategories();
386 return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
387 }
388
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700389 private static boolean isLikeShortCutIntent(final Intent intent) {
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700390 String action = intent.getAction();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700391 if (action == null) {
392 return false;
393 }
394 for (int i = 0; i < LIKE_SHORTCUT_INTENT_ACTION_ARRAY.length; i++) {
395 if (LIKE_SHORTCUT_INTENT_ACTION_ARRAY[i].equals(action)) return true;
396 }
397 return false;
Fabrice Di Meglio5b7a1002014-06-23 17:54:40 -0700398 }
399
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700400 @Override
401 protected void onCreate(Bundle savedState) {
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700402 super.onCreate(savedState);
Jason Monkfd2c7222015-12-02 15:38:38 -0500403 long startTime = System.currentTimeMillis();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700404
405 final FeatureFactory factory = FeatureFactory.getFactory(this);
406
407 mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
Matthew Fritze9955db62016-12-20 09:37:21 -0800408 mSearchFeatureProvider = factory.getSearchFeatureProvider();
Matthew Fritze0ed37c32016-10-24 10:12:49 -0700409
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700410 // Should happen before any call to getIntent()
411 getMetaData();
412
413 final Intent intent = getIntent();
414 if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
415 getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800416 }
Udam Saini92779ce2016-03-28 14:29:48 -0700417 if (intent.getBooleanExtra(EXTRA_HIDE_DRAWER, false)) {
418 setIsDrawerPresent(false);
419 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800420
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800421 mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
422 Context.MODE_PRIVATE);
423
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700424 // Getting Intent properties can only be done after the super.onCreate(...)
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700425 final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700426
Fabrice Di Meglio5b3c3c02014-06-30 15:18:08 -0700427 mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent) ||
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700428 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
429
Fabrice Di Meglioe817a662014-07-16 19:51:06 -0700430 final ComponentName cn = intent.getComponent();
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700431 final String className = cn.getClassName();
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700432
Jason Monk4da79e02015-09-10 10:54:36 -0400433 mIsShowingDashboard = className.equals(Settings.class.getName())
434 || className.equals(Settings.WirelessSettings.class.getName())
435 || className.equals(Settings.DeviceSettings.class.getName())
436 || className.equals(Settings.PersonalSettings.class.getName())
437 || className.equals(Settings.WirelessSettings.class.getName());
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700438
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700439 // This is a "Sub Settings" when:
440 // - this is a real SubSettings
441 // - or :settings:show_fragment_as_subsetting is passed to the Intent
Jorim Jaggi4dfcb822015-04-29 17:21:32 -0700442 final boolean isSubSettings = this instanceof SubSettings ||
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700443 intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
444
445 // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
446 if (isSubSettings) {
Fabrice Di Meglio712df6c2014-07-18 17:44:37 -0700447 // Check also that we are not a Theme Dialog as we don't want to override them
448 final int themeResId = getThemeResId();
449 if (themeResId != R.style.Theme_DialogWhenLarge &&
450 themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
451 setTheme(R.style.Theme_SubSettings);
452 }
Fabrice Di Meglioda8baba2014-06-10 17:12:51 -0700453 }
454
Fabrice Di Megliod40dd452014-07-18 15:20:34 -0700455 setContentView(mIsShowingDashboard ?
456 R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800457
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700458 mContent = (ViewGroup) findViewById(R.id.main_content);
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700459
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800460 getFragmentManager().addOnBackStackChangedListener(this);
461
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700462 if (mIsShowingDashboard) {
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800463 // Run the Index update only if we have some space
464 if (!Utils.isLowStorage(this)) {
Fan Zhanga8759242017-01-06 09:18:59 -0800465 mSearchFeatureProvider.updateIndex(getApplicationContext());
Fabrice Di Megliodff3faa2015-02-27 11:14:11 -0800466 } else {
467 Log.w(LOG_TAG, "Cannot update the Indexer as we are running low on storage space!");
468 }
Fabrice Di Meglio5cda21b2014-04-21 10:14:28 -0700469 }
470
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700471 if (savedState != null) {
Fabrice Di Meglio1800a9f2014-04-03 19:31:07 -0700472 // We are restarting from a previous saved state; used that to initialize, instead
473 // of starting fresh.
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700474 mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
475 mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700476 setTitleFromIntent(intent);
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800477
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700478 ArrayList<DashboardCategory> categories =
479 savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
480 if (categories != null) {
Fabrice Di Meglio5f995722014-05-19 19:51:31 -0700481 mCategories.clear();
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700482 mCategories.addAll(categories);
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700483 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800484 }
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700485
486 mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700487 mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
Salvador Martinez2368e542016-07-25 18:16:47 -0700488
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800489 } else {
Fabrice Di Meglio35062d62014-05-13 14:39:41 -0700490 if (!mIsShowingDashboard) {
Jason Monkea8b1a72015-06-02 16:46:34 -0400491 mDisplaySearch = false;
492 // UP will be shown only if it is a sub settings
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700493 if (mIsShortcut) {
494 mDisplayHomeAsUpEnabled = isSubSettings;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700495 } else if (isSubSettings) {
496 mDisplayHomeAsUpEnabled = true;
Fabrice Di Meglio61a1fec2014-08-13 16:22:38 -0700497 } else {
498 mDisplayHomeAsUpEnabled = false;
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700499 }
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700500 setTitleFromIntent(intent);
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700501
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700502 Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700503 switchToFragment(initialFragmentName, initialArguments, true, false,
504 mInitialTitleResId, mInitialTitle, false);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000505 } else {
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700506 // No UP affordance if we are displaying the main Dashboard
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700507 mDisplayHomeAsUpEnabled = false;
Fabrice Di Meglio5a62d942014-07-01 17:18:40 -0700508 // Show Search affordance
509 mDisplaySearch = true;
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700510 mInitialTitleResId = R.string.dashboard_title;
Salvador Martinez2368e542016-07-25 18:16:47 -0700511
512 // add argument to indicate which settings tab should be initially selected
513 final Bundle args = new Bundle();
514 final String extraName = DashboardContainerFragment.EXTRA_SELECT_SETTINGS_TAB;
515 args.putString(extraName, intent.getStringExtra(extraName));
Fan Zhanga96a2d82016-09-27 17:51:11 -0700516 if (isDashboardFeatureEnabled()) {
517 switchToFragment(DashboardSummary.class.getName(), args, false, false,
518 mInitialTitleResId, mInitialTitle, false);
519 } else {
520 switchToFragment(DashboardContainerFragment.class.getName(), args, false, false,
521 mInitialTitleResId, mInitialTitle, false);
522 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800523 }
524 }
525
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700526 mActionBar = getActionBar();
Fabrice Di Megliod8aec082014-05-20 10:49:50 -0700527 if (mActionBar != null) {
528 mActionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
529 mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
530 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700531 mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
Jason Monke4ebcd12016-02-21 09:37:41 -0500532 if (mSwitchBar != null) {
533 mSwitchBar.setMetricsTag(getMetricsTag());
534 }
Fabrice Di Meglio41937762014-05-13 19:51:59 -0700535
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800536 // see if we should show Back/Next buttons
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800537 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
538
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700539 View buttonBar = findViewById(R.id.button_bar);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800540 if (buttonBar != null) {
541 buttonBar.setVisibility(View.VISIBLE);
542
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700543 Button backButton = (Button)findViewById(R.id.back_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800544 backButton.setOnClickListener(new OnClickListener() {
545 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700546 setResult(RESULT_CANCELED, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800547 finish();
548 }
549 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700550 Button skipButton = (Button)findViewById(R.id.skip_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800551 skipButton.setOnClickListener(new OnClickListener() {
552 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700553 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800554 finish();
555 }
556 });
Fabrice Di Megliod2b64f32014-05-20 12:55:15 -0700557 mNextButton = (Button)findViewById(R.id.next_button);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800558 mNextButton.setOnClickListener(new OnClickListener() {
559 public void onClick(View v) {
Jim Miller0698a212014-10-16 19:49:07 -0700560 setResult(RESULT_OK, getResultIntentData());
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800561 finish();
562 }
563 });
564
565 // set our various button parameters
566 if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
567 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
568 if (TextUtils.isEmpty(buttonText)) {
569 mNextButton.setVisibility(View.GONE);
570 }
571 else {
572 mNextButton.setText(buttonText);
573 }
574 }
575 if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
576 String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
577 if (TextUtils.isEmpty(buttonText)) {
578 backButton.setVisibility(View.GONE);
579 }
580 else {
581 backButton.setText(buttonText);
582 }
583 }
584 if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
585 skipButton.setVisibility(View.VISIBLE);
586 }
587 }
588 }
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700589
Jason Monkfd2c7222015-12-02 15:38:38 -0500590 if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
591 + " ms");
Fabrice Di Meglioceb335f2014-07-23 16:25:30 -0700592 }
593
Fan Zhangece8ff62016-06-30 13:20:12 -0700594 public void setDisplaySearchMenu(boolean displaySearch) {
595 if (displaySearch != mDisplaySearch) {
596 mDisplaySearch = displaySearch;
597 invalidateOptionsMenu();
598 }
599 }
600
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700601 private void setTitleFromIntent(Intent intent) {
602 final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
603 if (initialTitleResId > 0) {
604 mInitialTitle = null;
605 mInitialTitleResId = initialTitleResId;
Alexandra Gherghina62464b82014-08-11 12:40:13 +0100606
607 final String initialTitleResPackageName = intent.getStringExtra(
608 EXTRA_SHOW_FRAGMENT_TITLE_RES_PACKAGE_NAME);
609 if (initialTitleResPackageName != null) {
610 try {
611 Context authContext = createPackageContextAsUser(initialTitleResPackageName,
612 0 /* flags */, new UserHandle(UserHandle.myUserId()));
613 mInitialTitle = authContext.getResources().getText(mInitialTitleResId);
614 setTitle(mInitialTitle);
615 mInitialTitleResId = -1;
616 return;
617 } catch (NameNotFoundException e) {
618 Log.w(LOG_TAG, "Could not find package" + initialTitleResPackageName);
619 }
620 } else {
621 setTitle(mInitialTitleResId);
622 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700623 } else {
624 mInitialTitleResId = -1;
625 final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
626 mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
627 setTitle(mInitialTitle);
628 }
629 }
630
Fabrice Di Meglioc95be4f2014-03-07 12:57:38 -0800631 @Override
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800632 public void onBackStackChanged() {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700633 setTitleFromBackStack();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800634 }
635
Fan Zhang28691572016-03-23 15:31:08 -0700636 private void setTitleFromBackStack() {
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800637 final int count = getFragmentManager().getBackStackEntryCount();
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700638
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800639 if (count == 0) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700640 if (mInitialTitleResId > 0) {
641 setTitle(mInitialTitleResId);
642 } else {
643 setTitle(mInitialTitle);
644 }
Fan Zhang28691572016-03-23 15:31:08 -0700645 return;
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800646 }
Fabrice Di Megliob643cbf2014-03-10 12:18:39 -0700647
Fabrice Di Meglio8eb3f0f2014-02-27 15:51:46 -0800648 FragmentManager.BackStackEntry bse = getFragmentManager().getBackStackEntryAt(count - 1);
649 setTitleFromBackStackEntry(bse);
650 }
651
652 private void setTitleFromBackStackEntry(FragmentManager.BackStackEntry bse) {
653 final CharSequence title;
654 final int titleRes = bse.getBreadCrumbTitleRes();
655 if (titleRes > 0) {
656 title = getText(titleRes);
657 } else {
658 title = bse.getBreadCrumbTitle();
659 }
660 if (title != null) {
661 setTitle(title);
662 }
Fabrice Di Meglio5529d292014-02-11 19:52:28 -0800663 }
664
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800665 @Override
666 protected void onSaveInstanceState(Bundle outState) {
667 super.onSaveInstanceState(outState);
668
Fabrice Di Meglio769630c2014-04-24 14:48:48 -0700669 if (mCategories.size() > 0) {
670 outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800671 }
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700672
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700673 outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700674 outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
Fabrice Di Megliob731dd02014-04-03 18:40:38 -0700675
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700676 if (mDisplaySearch) {
677 // The option menus are created if the ActionBar is visible and they are also created
678 // asynchronously. If you launch Settings with an Intent action like
679 // android.intent.action.POWER_USAGE_SUMMARY and at the same time your device is locked
680 // thru a LockScreen, onCreateOptionsMenu() is not yet called and references to the search
681 // menu item and search view are null.
682 boolean isExpanded = (mSearchMenuItem != null) && mSearchMenuItem.isActionViewExpanded();
683 outState.putBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED, isExpanded);
Fabrice Di Megliod6985df2014-04-03 16:43:26 -0700684
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700685 String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
686 outState.putString(SAVE_KEY_SEARCH_QUERY, query);
687 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800688 }
689
690 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400691 protected void onResume() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800692 super.onResume();
693
694 mDevelopmentPreferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
695 @Override
696 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Jason Monk4da79e02015-09-10 10:54:36 -0400697 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800698 }
699 };
700 mDevelopmentPreferences.registerOnSharedPreferenceChangeListener(
701 mDevelopmentPreferencesListener);
702
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800703 registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
Clara Bayarri6934a042015-10-14 11:07:35 +0100704 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_ADDED));
705 registerReceiver(mUserAddRemoveReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800706 if (mDynamicIndexableContentMonitor == null) {
707 mDynamicIndexableContentMonitor = new DynamicIndexableContentMonitor();
708 }
Philip P. Moltmannd9779db2016-02-24 12:11:05 -0800709 mDynamicIndexableContentMonitor.register(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700710
Fabrice Di Meglio3d35ec72014-06-06 12:13:29 -0700711 if(mDisplaySearch && !TextUtils.isEmpty(mSearchQuery)) {
Fabrice Di Meglioa3270762014-04-16 16:54:56 -0700712 onQueryTextSubmit(mSearchQuery);
713 }
Jason Monk4da79e02015-09-10 10:54:36 -0400714 updateTilesList();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800715 }
716
717 @Override
Jason Monk39b46742015-09-10 15:52:51 -0400718 protected void onPause() {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800719 super.onPause();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800720 unregisterReceiver(mBatteryInfoReceiver);
Clara Bayarri8c9521f2016-01-12 14:10:45 +0000721 unregisterReceiver(mUserAddRemoveReceiver);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800722 if (mDynamicIndexableContentMonitor != null) {
Tadashi G. Takaokaa034fa52016-11-21 14:20:19 +0900723 mDynamicIndexableContentMonitor.unregister(this, LOADER_ID_INDEXABLE_CONTENT_MONITOR);
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800724 }
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800725 }
726
727 @Override
728 public void onDestroy() {
729 super.onDestroy();
Fabrice Di Meglio680b0642014-05-20 15:19:29 -0700730
731 mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener(
732 mDevelopmentPreferencesListener);
733 mDevelopmentPreferencesListener = null;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800734 }
735
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800736 protected boolean isValidFragment(String fragmentName) {
737 // Almost all fragments are wrapped in this,
738 // except for a few that have their own activities.
Fan Zhanga3e8f5c2016-12-01 09:52:10 -0800739 for (int i = 0; i < SettingsGateway.ENTRY_FRAGMENTS.length; i++) {
740 if (SettingsGateway.ENTRY_FRAGMENTS[i].equals(fragmentName)) return true;
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800741 }
742 return false;
743 }
744
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800745 @Override
746 public Intent getIntent() {
747 Intent superIntent = super.getIntent();
748 String startingFragment = getStartingFragmentClass(superIntent);
749 // This is called from super.onCreate, isMultiPane() is not yet reliable
750 // Do not use onIsHidingHeaders either, which relies itself on this method
751 if (startingFragment != null) {
752 Intent modIntent = new Intent(superIntent);
753 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, startingFragment);
754 Bundle args = superIntent.getExtras();
755 if (args != null) {
756 args = new Bundle(args);
757 } else {
758 args = new Bundle();
759 }
760 args.putParcelable("intent", superIntent);
Kenny Guyac1e20e2014-06-24 14:34:14 +0100761 modIntent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800762 return modIntent;
763 }
764 return superIntent;
765 }
766
767 /**
768 * Checks if the component name in the intent is different from the Settings class and
769 * returns the class name to load as a fragment.
770 */
771 private String getStartingFragmentClass(Intent intent) {
772 if (mFragmentClass != null) return mFragmentClass;
773
774 String intentClass = intent.getComponent().getClassName();
775 if (intentClass.equals(getClass().getName())) return null;
776
777 if ("com.android.settings.ManageApplications".equals(intentClass)
778 || "com.android.settings.RunningServices".equals(intentClass)
779 || "com.android.settings.applications.StorageUse".equals(intentClass)) {
780 // Old names of manage apps.
781 intentClass = com.android.settings.applications.ManageApplications.class.getName();
782 }
783
784 return intentClass;
785 }
786
787 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000788 * Start a new fragment containing a preference panel. If the preferences
789 * are being displayed in multi-pane mode, the given fragment class will
790 * be instantiated and placed in the appropriate pane. If running in
791 * single-pane mode, a new activity will be launched in which to show the
792 * fragment.
793 *
794 * @param fragmentClass Full name of the class implementing the fragment.
795 * @param args Any desired arguments to supply to the fragment.
796 * @param titleRes Optional resource identifier of the title of this
797 * fragment.
798 * @param titleText Optional text of the title of this fragment.
799 * @param resultTo Optional fragment that result data should be sent to.
800 * If non-null, resultTo.onActivityResult() will be called when this
801 * preference panel is done. The launched panel must use
802 * {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
803 * @param resultRequestCode If resultTo is non-null, this is the caller's
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700804 * request code to be received with the result.
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000805 */
806 public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700807 CharSequence titleText, Fragment resultTo, int resultRequestCode) {
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700808 String title = null;
809 if (titleRes < 0) {
810 if (titleText != null) {
811 title = titleText.toString();
812 } else {
813 // There not much we can do in that case
814 title = "";
815 }
Fabrice Di Meglio911fb2a2014-04-04 17:55:57 -0700816 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700817 Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
Fabrice Di Meglio0d643fd2014-06-16 20:11:27 -0700818 titleRes, title, mIsShortcut);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000819 }
820
821 /**
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100822 * Start a new fragment in a new activity containing a preference panel for a given user. If the
823 * preferences are being displayed in multi-pane mode, the given fragment class will be
824 * instantiated and placed in the appropriate pane. If running in single-pane mode, a new
825 * activity will be launched in which to show the fragment.
826 *
827 * @param fragmentClass Full name of the class implementing the fragment.
828 * @param args Any desired arguments to supply to the fragment.
829 * @param titleRes Optional resource identifier of the title of this fragment.
830 * @param titleText Optional text of the title of this fragment.
831 * @param userHandle The user for which the panel has to be started.
832 */
833 public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
834 CharSequence titleText, UserHandle userHandle) {
Lifu Tangd0332852015-04-02 12:05:46 -0700835 // This is a workaround.
836 //
837 // Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
838 // starting the fragment could cause a native stack corruption. See b/17523189. However,
839 // adding that flag and start the preference panel with the same UserHandler will make it
840 // impossible to use back button to return to the previous screen. See b/20042570.
841 //
842 // We work around this issue by adding FLAG_ACTIVITY_NEW_TASK to the intent, while doing
843 // another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
844 // when we're calling it as the same user.
845 if (userHandle.getIdentifier() == UserHandle.myUserId()) {
846 startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
847 } else {
848 String title = null;
849 if (titleRes < 0) {
850 if (titleText != null) {
851 title = titleText.toString();
852 } else {
853 // There not much we can do in that case
854 title = "";
855 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100856 }
Lifu Tangd0332852015-04-02 12:05:46 -0700857 Utils.startWithFragmentAsUser(this, fragmentClass, args,
858 titleRes, title, mIsShortcut, userHandle);
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100859 }
Zoltan Szatmary-Ban7a2ccf22014-09-18 10:26:11 +0100860 }
861
862 /**
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800863 * Called by a preference panel fragment to finish itself.
864 *
865 * @param caller The fragment that is asking to be finished.
866 * @param resultCode Optional result code to send back to the original
867 * launching fragment.
868 * @param resultData Optional result data to send back to the original
869 * launching fragment.
870 */
871 public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) {
872 setResult(resultCode, resultData);
Fabrice Di Meglio58146c22014-06-26 16:20:26 -0700873 finish();
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800874 }
875
876 /**
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000877 * Start a new fragment.
878 *
879 * @param fragment The fragment to start
880 * @param push If true, the current fragment will be pushed onto the back stack. If false,
881 * the current fragment will be replaced.
882 */
883 public void startPreferenceFragment(Fragment fragment, boolean push) {
884 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700885 transaction.replace(R.id.main_content, fragment);
Fabrice Di Meglio10afdb82014-02-11 19:50:56 +0000886 if (push) {
887 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
888 transaction.addToBackStack(BACK_STACK_PREFS);
889 } else {
890 transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
891 }
892 transaction.commitAllowingStateLoss();
893 }
894
895 /**
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700896 * Switch to a specific Fragment with taking care of validation, Title and BackStack
897 */
898 private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700899 boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700900 if (validate && !isValidFragment(fragmentName)) {
901 throw new IllegalArgumentException("Invalid fragment for this activity: "
902 + fragmentName);
903 }
904 Fragment f = Fragment.instantiate(this, fragmentName, args);
905 FragmentTransaction transaction = getFragmentManager().beginTransaction();
Anna Galusza6b1e9db2016-03-30 17:25:36 -0700906 transaction.replace(R.id.main_content, f);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700907 if (withTransition) {
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700908 TransitionManager.beginDelayedTransition(mContent);
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700909 }
910 if (addToBackStack) {
911 transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
912 }
Fabrice Di Meglioa9e77992014-06-09 12:52:24 -0700913 if (titleResId > 0) {
914 transaction.setBreadCrumbTitle(titleResId);
915 } else if (title != null) {
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700916 transaction.setBreadCrumbTitle(title);
917 }
918 transaction.commitAllowingStateLoss();
Fabrice Di Meglio59a40552014-05-23 16:46:50 -0700919 getFragmentManager().executePendingTransactions();
Fabrice Di Megliod25314d2014-03-21 19:24:43 -0700920 return f;
921 }
922
Jason Monk4da79e02015-09-10 10:54:36 -0400923 private void updateTilesList() {
Jason Monkfd2c7222015-12-02 15:38:38 -0500924 // Generally the items that are will be changing from these updates will
925 // not be in the top list of tiles, so run it in the background and the
926 // SettingsDrawerActivity will pick up on the updates automatically.
927 AsyncTask.execute(new Runnable() {
928 @Override
929 public void run() {
930 doUpdateTilesList();
931 }
932 });
933 }
934
935 private void doUpdateTilesList() {
Jason Monk4da79e02015-09-10 10:54:36 -0400936 PackageManager pm = getPackageManager();
Xiaohui Chen44879a32015-07-22 13:53:22 -0700937 final UserManager um = UserManager.get(this);
938 final boolean isAdmin = um.isAdminUser();
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700939
Jason Monk4da79e02015-09-10 10:54:36 -0400940 String packageName = getPackageName();
941 setTileEnabled(new ComponentName(packageName, WifiSettingsActivity.class.getName()),
942 pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700943
Jason Monk4da79e02015-09-10 10:54:36 -0400944 setTileEnabled(new ComponentName(packageName,
945 Settings.BluetoothSettingsActivity.class.getName()),
946 pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700947
Jason Monk4da79e02015-09-10 10:54:36 -0400948 setTileEnabled(new ComponentName(packageName,
949 Settings.DataUsageSummaryActivity.class.getName()),
950 Utils.isBandwidthControlEnabled(), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700951
Jason Monk4da79e02015-09-10 10:54:36 -0400952 setTileEnabled(new ComponentName(packageName,
953 Settings.SimSettingsActivity.class.getName()),
954 Utils.showSimCardTile(this), isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -0700955
Jason Monk4da79e02015-09-10 10:54:36 -0400956 setTileEnabled(new ComponentName(packageName,
957 Settings.PowerUsageSummaryActivity.class.getName()),
958 mBatteryPresent, isAdmin, pm);
959
960 setTileEnabled(new ComponentName(packageName,
Jason Monk4da79e02015-09-10 10:54:36 -0400961 Settings.UserSettingsActivity.class.getName()),
962 UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
963 && !Utils.isMonkeyRunning(), isAdmin, pm);
964
Fyodor Kupolovca060e32016-06-24 13:01:11 -0700965 setTileEnabled(new ComponentName(packageName,
966 Settings.WirelessSettingsActivity.class.getName()),
967 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
968
969 setTileEnabled(new ComponentName(packageName,
970 Settings.DateTimeSettingsActivity.class.getName()),
971 !UserManager.isDeviceInDemoMode(this), isAdmin, pm);
Jason Monk4da79e02015-09-10 10:54:36 -0400972 NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
973 setTileEnabled(new ComponentName(packageName,
974 Settings.PaymentSettingsActivity.class.getName()),
975 pm.hasSystemFeature(PackageManager.FEATURE_NFC)
976 && pm.hasSystemFeature(PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)
977 && adapter != null && adapter.isEnabled(), isAdmin, pm);
978
979 setTileEnabled(new ComponentName(packageName,
980 Settings.PrintSettingsActivity.class.getName()),
981 pm.hasSystemFeature(PackageManager.FEATURE_PRINTING), isAdmin, pm);
982
983 final boolean showDev = mDevelopmentPreferences.getBoolean(
Dan Sandler12c4ba42016-03-28 11:13:40 -0400984 DevelopmentSettings.PREF_SHOW, android.os.Build.TYPE.equals("eng"))
985 && !um.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
Jason Monk4da79e02015-09-10 10:54:36 -0400986 setTileEnabled(new ComponentName(packageName,
987 Settings.DevelopmentSettingsActivity.class.getName()),
Dan Sandler12c4ba42016-03-28 11:13:40 -0400988 showDev, isAdmin, pm);
Fan Zhangcc335d92016-09-29 14:37:14 -0700989 setTileEnabled(new ComponentName(packageName,
990 Settings.DevelopmentSettingsActivity.DASHBOARD_ALIAS),
991 showDev, isAdmin, pm);
Dan Sandler12c4ba42016-03-28 11:13:40 -0400992
993 // Reveal development-only quick settings tiles
Sunny Goyalbf9f2d22016-11-02 11:20:17 -0700994 setTileEnabled(new ComponentName(this, DevelopmentModeTile.class), showDev);
Jason Monk4da79e02015-09-10 10:54:36 -0400995
996 if (UserHandle.MU_ENABLED && !isAdmin) {
997 // When on restricted users, disable all extra categories (but only the settings ones).
Fan Zhanga96a2d82016-09-27 17:51:11 -0700998 List<DashboardCategory> categories;
999 if (isDashboardFeatureEnabled()) {
1000 categories = mDashboardFeatureProvider.getAllCategories();
1001 } else {
1002 categories = getDashboardCategories();
1003 }
1004
Jason Monk4da79e02015-09-10 10:54:36 -04001005 for (DashboardCategory category : categories) {
Jason Monkd4f03ec2016-01-07 16:25:34 -05001006 for (Tile tile : category.tiles) {
Jason Monk4da79e02015-09-10 10:54:36 -04001007 ComponentName component = tile.intent.getComponent();
Jason Monk5862c1e2016-06-07 14:02:33 -04001008 if (packageName.equals(component.getPackageName()) && !ArrayUtils.contains(
Jason Monk4da79e02015-09-10 10:54:36 -04001009 SETTINGS_FOR_RESTRICTED, component.getClassName())) {
1010 setTileEnabled(component, false, isAdmin, pm);
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001011 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001012 }
Fabrice Di Meglio63bbb8e2014-04-23 16:44:30 -07001013 }
1014 }
Doris Ling26bf0032016-06-15 18:16:09 -07001015
1016 String backupIntent = getResources().getString(R.string.config_backup_settings_intent);
1017 boolean useDefaultBackup = TextUtils.isEmpty(backupIntent);
1018 setTileEnabled(new ComponentName(packageName,
1019 Settings.PrivacySettingsActivity.class.getName()), useDefaultBackup, isAdmin, pm);
Fan Zhang0e8d0d12016-11-02 09:15:33 -07001020 setTileEnabled(new ComponentName(packageName,
1021 "com.android.settings.PrivacyDashboardAlias"),
1022 useDefaultBackup, isAdmin, pm);
1023
Doris Ling26bf0032016-06-15 18:16:09 -07001024 boolean hasBackupActivity = false;
1025 if (!useDefaultBackup) {
1026 try {
1027 Intent intent = Intent.parseUri(backupIntent, 0);
1028 hasBackupActivity = !getPackageManager().queryIntentActivities(intent, 0).isEmpty();
1029 } catch (URISyntaxException e) {
1030 Log.e(LOG_TAG, "Invalid backup intent URI!", e);
1031 }
1032 }
Fan Zhang10dd4652016-11-16 10:24:26 -08001033
1034 // Enable/disble BackupSettingsActivity and its alias.
Doris Ling26bf0032016-06-15 18:16:09 -07001035 setTileEnabled(new ComponentName(packageName,
1036 BackupSettingsActivity.class.getName()), hasBackupActivity, isAdmin, pm);
Fan Zhang10dd4652016-11-16 10:24:26 -08001037 setTileEnabled(new ComponentName(packageName,
1038 "com.android.settings.BackupResetDashboardAlias"), hasBackupActivity, isAdmin, pm);
Doris Ling26bf0032016-06-15 18:16:09 -07001039
Bartosz Fabianowski05061fc2016-11-14 12:04:49 +01001040 setTileEnabled(new ComponentName(packageName,
1041 Settings.EnterprisePrivacySettingsActivity.class.getName()),
1042 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
1043 .hasDeviceOwner(), isAdmin, pm);
Fan Zhang10dd4652016-11-16 10:24:26 -08001044 setTileEnabled(new ComponentName(packageName,
1045 "com.android.settings.EnterprisePrivacyDashboardAlias"),
1046 FeatureFactory.getFactory(this).getEnterprisePrivacyFeatureProvider(this)
1047 .hasDeviceOwner(), isAdmin, pm);
Jason Monk2ebc8a02015-02-13 15:23:19 -05001048 }
1049
Jason Monk4da79e02015-09-10 10:54:36 -04001050 private void setTileEnabled(ComponentName component, boolean enabled, boolean isAdmin,
Fan Zhang10dd4652016-11-16 10:24:26 -08001051 PackageManager pm) {
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}