Remove Index.java from old Search and its dependents
Test: make RunSettingsRoboTests Bug: 35763944, 36192909 Change-Id: If216e1eeb4c29e7372720c6228fa4e99ea2a9904
This commit is contained in:
@@ -2068,8 +2068,6 @@
|
|||||||
|
|
||||||
<!-- Sound and alerts settings -->
|
<!-- Sound and alerts settings -->
|
||||||
<skip/>
|
<skip/>
|
||||||
<!-- Main Settings screen setting option name to go into the display settings screen -->
|
|
||||||
<string name="home_settings">Home</string>
|
|
||||||
<string name="display_settings_title">Display</string>
|
<string name="display_settings_title">Display</string>
|
||||||
<!-- Sound settings screen heading -->
|
<!-- Sound settings screen heading -->
|
||||||
<string name="sound_settings">Sound</string>
|
<string name="sound_settings">Sound</string>
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2013 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:title="@string/home_settings"
|
|
||||||
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
|
|
||||||
android:key="home"
|
|
||||||
android:order="0">
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
@@ -1,430 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2013 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.content.pm.UserInfo;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.graphics.ColorFilter;
|
|
||||||
import android.graphics.ColorMatrix;
|
|
||||||
import android.graphics.ColorMatrixColorFilter;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.support.v7.preference.Preference;
|
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
|
||||||
import android.support.v7.preference.PreferenceViewHolder;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.RadioButton;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
|
||||||
import com.android.settings.search.Index;
|
|
||||||
import com.android.settings.search.Indexable;
|
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class HomeSettings extends SettingsPreferenceFragment implements Indexable {
|
|
||||||
static final String TAG = "HomeSettings";
|
|
||||||
|
|
||||||
// Boolean extra, indicates only launchers that support managed profiles should be shown.
|
|
||||||
// Note: must match the constant defined in ManagedProvisioning
|
|
||||||
private static final String EXTRA_SUPPORT_MANAGED_PROFILES = "support_managed_profiles";
|
|
||||||
|
|
||||||
static final int REQUESTING_UNINSTALL = 10;
|
|
||||||
|
|
||||||
public static final String HOME_PREFS = "home_prefs";
|
|
||||||
public static final String HOME_PREFS_DO_SHOW = "do_show";
|
|
||||||
|
|
||||||
public static final String HOME_SHOW_NOTICE = "show";
|
|
||||||
|
|
||||||
private class HomePackageReceiver extends BroadcastReceiver {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
buildHomeActivitiesList();
|
|
||||||
Index.getInstance(context).updateFromClassNameResource(
|
|
||||||
HomeSettings.class.getName(), true, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private PreferenceGroup mPrefGroup;
|
|
||||||
private PackageManager mPm;
|
|
||||||
private ComponentName[] mHomeComponentSet;
|
|
||||||
private ArrayList<HomeAppPreference> mPrefs;
|
|
||||||
private HomeAppPreference mCurrentHome = null;
|
|
||||||
private final IntentFilter mHomeFilter;
|
|
||||||
private boolean mShowNotice;
|
|
||||||
private HomePackageReceiver mHomePackageReceiver = new HomePackageReceiver();
|
|
||||||
|
|
||||||
public HomeSettings() {
|
|
||||||
mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
|
|
||||||
mHomeFilter.addCategory(Intent.CATEGORY_HOME);
|
|
||||||
mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
OnClickListener mHomeClickListener = new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
int index = (Integer)v.getTag();
|
|
||||||
HomeAppPreference pref = mPrefs.get(index);
|
|
||||||
if (!pref.isChecked) {
|
|
||||||
makeCurrentHome(pref);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
OnClickListener mDeleteClickListener = new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
int index = (Integer)v.getTag();
|
|
||||||
uninstallApp(mPrefs.get(index));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void makeCurrentHome(HomeAppPreference newHome) {
|
|
||||||
if (mCurrentHome != null) {
|
|
||||||
mCurrentHome.setChecked(false);
|
|
||||||
}
|
|
||||||
newHome.setChecked(true);
|
|
||||||
mCurrentHome = newHome;
|
|
||||||
|
|
||||||
mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,
|
|
||||||
mHomeComponentSet, newHome.activityName);
|
|
||||||
|
|
||||||
getActivity().setResult(Activity.RESULT_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
void uninstallApp(HomeAppPreference pref) {
|
|
||||||
// Uninstallation is done by asking the OS to do it
|
|
||||||
Uri packageURI = Uri.parse("package:" + pref.uninstallTarget);
|
|
||||||
Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
|
|
||||||
uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
|
|
||||||
int requestCode = REQUESTING_UNINSTALL + (pref.isChecked ? 1 : 0);
|
|
||||||
startActivityForResult(uninstallIntent, requestCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
|
|
||||||
// Rebuild the list now that we might have nuked something
|
|
||||||
buildHomeActivitiesList();
|
|
||||||
|
|
||||||
// if the previous home app is now gone, fall back to the system one
|
|
||||||
if (requestCode > REQUESTING_UNINSTALL) {
|
|
||||||
// if mCurrentHome has gone null, it means we didn't find the previously-
|
|
||||||
// default home app when rebuilding the list, i.e. it was the one we
|
|
||||||
// just uninstalled. When that happens we make the system-bundled
|
|
||||||
// home app the active default.
|
|
||||||
if (mCurrentHome == null) {
|
|
||||||
for (int i = 0; i < mPrefs.size(); i++) {
|
|
||||||
HomeAppPreference pref = mPrefs.get(i);
|
|
||||||
if (pref.isSystem) {
|
|
||||||
makeCurrentHome(pref);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildHomeActivitiesList() {
|
|
||||||
ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
|
|
||||||
ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
|
|
||||||
|
|
||||||
Context context = getPrefContext();
|
|
||||||
mCurrentHome = null;
|
|
||||||
mPrefGroup.removeAll();
|
|
||||||
mPrefs = new ArrayList<HomeAppPreference>();
|
|
||||||
mHomeComponentSet = new ComponentName[homeActivities.size()];
|
|
||||||
int prefIndex = 0;
|
|
||||||
boolean supportManagedProfilesExtra =
|
|
||||||
getActivity().getIntent().getBooleanExtra(EXTRA_SUPPORT_MANAGED_PROFILES, false);
|
|
||||||
boolean mustSupportManagedProfile = hasManagedProfile()
|
|
||||||
|| supportManagedProfilesExtra;
|
|
||||||
for (int i = 0; i < homeActivities.size(); i++) {
|
|
||||||
final ResolveInfo candidate = homeActivities.get(i);
|
|
||||||
final ActivityInfo info = candidate.activityInfo;
|
|
||||||
ComponentName activityName = new ComponentName(info.packageName, info.name);
|
|
||||||
mHomeComponentSet[i] = activityName;
|
|
||||||
try {
|
|
||||||
Drawable icon = info.loadIcon(mPm);
|
|
||||||
CharSequence name = info.loadLabel(mPm);
|
|
||||||
HomeAppPreference pref;
|
|
||||||
|
|
||||||
if (mustSupportManagedProfile && !launcherHasManagedProfilesFeature(candidate)) {
|
|
||||||
pref = new HomeAppPreference(context, activityName, prefIndex,
|
|
||||||
icon, name, this, info, false /* not enabled */,
|
|
||||||
getResources().getString(R.string.home_work_profile_not_supported));
|
|
||||||
} else {
|
|
||||||
pref = new HomeAppPreference(context, activityName, prefIndex,
|
|
||||||
icon, name, this, info, true /* enabled */, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
mPrefs.add(pref);
|
|
||||||
mPrefGroup.addPreference(pref);
|
|
||||||
if (activityName.equals(currentDefaultHome)) {
|
|
||||||
mCurrentHome = pref;
|
|
||||||
}
|
|
||||||
prefIndex++;
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.v(TAG, "Problem dealing with activity " + activityName, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mCurrentHome != null) {
|
|
||||||
if (mCurrentHome.isEnabled()) {
|
|
||||||
getActivity().setResult(Activity.RESULT_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
new Handler().post(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
mCurrentHome.setChecked(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasManagedProfile() {
|
|
||||||
Context context = getActivity();
|
|
||||||
UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
|
|
||||||
List<UserInfo> profiles = userManager.getProfiles(context.getUserId());
|
|
||||||
for (UserInfo userInfo : profiles) {
|
|
||||||
if (userInfo.isManagedProfile()) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean launcherHasManagedProfilesFeature(ResolveInfo resolveInfo) {
|
|
||||||
try {
|
|
||||||
ApplicationInfo appInfo = getPackageManager().getApplicationInfo(
|
|
||||||
resolveInfo.activityInfo.packageName, 0 /* default flags */);
|
|
||||||
return versionNumberAtLeastL(appInfo.targetSdkVersion);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean versionNumberAtLeastL(int versionNumber) {
|
|
||||||
return versionNumber >= Build.VERSION_CODES.LOLLIPOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return MetricsEvent.HOME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
addPreferencesFromResource(R.xml.home_selection);
|
|
||||||
|
|
||||||
mPm = getPackageManager();
|
|
||||||
mPrefGroup = (PreferenceGroup) findPreference("home");
|
|
||||||
|
|
||||||
Bundle args = getArguments();
|
|
||||||
mShowNotice = (args != null) && args.getBoolean(HOME_SHOW_NOTICE, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
|
|
||||||
final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
|
|
||||||
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
|
|
||||||
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
|
|
||||||
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
|
|
||||||
filter.addDataScheme("package");
|
|
||||||
getActivity().registerReceiver(mHomePackageReceiver, filter);
|
|
||||||
|
|
||||||
buildHomeActivitiesList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
getActivity().unregisterReceiver(mHomePackageReceiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class HomeAppPreference extends Preference {
|
|
||||||
ComponentName activityName;
|
|
||||||
int index;
|
|
||||||
HomeSettings fragment;
|
|
||||||
final ColorFilter grayscaleFilter;
|
|
||||||
boolean isChecked;
|
|
||||||
|
|
||||||
boolean isSystem;
|
|
||||||
String uninstallTarget;
|
|
||||||
|
|
||||||
public HomeAppPreference(Context context, ComponentName activity,
|
|
||||||
int i, Drawable icon, CharSequence title, HomeSettings parent, ActivityInfo info,
|
|
||||||
boolean enabled, CharSequence summary) {
|
|
||||||
super(context);
|
|
||||||
setLayoutResource(R.layout.preference_home_app);
|
|
||||||
setIcon(icon);
|
|
||||||
setTitle(title);
|
|
||||||
setEnabled(enabled);
|
|
||||||
setSummary(summary);
|
|
||||||
activityName = activity;
|
|
||||||
fragment = parent;
|
|
||||||
index = i;
|
|
||||||
|
|
||||||
ColorMatrix colorMatrix = new ColorMatrix();
|
|
||||||
colorMatrix.setSaturation(0f);
|
|
||||||
float[] matrix = colorMatrix.getArray();
|
|
||||||
matrix[18] = 0.5f;
|
|
||||||
grayscaleFilter = new ColorMatrixColorFilter(colorMatrix);
|
|
||||||
|
|
||||||
determineTargets(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whether this activity is bundled on the system, with awareness
|
|
||||||
// of the META_HOME_ALTERNATE mechanism.
|
|
||||||
private void determineTargets(ActivityInfo info) {
|
|
||||||
final Bundle meta = info.metaData;
|
|
||||||
if (meta != null) {
|
|
||||||
final String altHomePackage = meta.getString(ActivityManager.META_HOME_ALTERNATE);
|
|
||||||
if (altHomePackage != null) {
|
|
||||||
try {
|
|
||||||
final int match = mPm.checkSignatures(info.packageName, altHomePackage);
|
|
||||||
if (match >= PackageManager.SIGNATURE_MATCH) {
|
|
||||||
PackageInfo altInfo = mPm.getPackageInfo(altHomePackage, 0);
|
|
||||||
final int altFlags = altInfo.applicationInfo.flags;
|
|
||||||
isSystem = (altFlags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
|
||||||
uninstallTarget = altInfo.packageName;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// e.g. named alternate package not found during lookup
|
|
||||||
Log.w(TAG, "Unable to compare/resolve alternate", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// No suitable metadata redirect, so use the package's own info
|
|
||||||
isSystem = (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
|
||||||
uninstallTarget = info.packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
|
||||||
super.onBindViewHolder(view);
|
|
||||||
|
|
||||||
RadioButton radio = (RadioButton) view.findViewById(R.id.home_radio);
|
|
||||||
radio.setChecked(isChecked);
|
|
||||||
|
|
||||||
Integer indexObj = new Integer(index);
|
|
||||||
|
|
||||||
ImageView icon = (ImageView) view.findViewById(R.id.home_app_uninstall);
|
|
||||||
if (isSystem) {
|
|
||||||
icon.setEnabled(false);
|
|
||||||
icon.setColorFilter(grayscaleFilter);
|
|
||||||
} else {
|
|
||||||
icon.setEnabled(true);
|
|
||||||
icon.setOnClickListener(mDeleteClickListener);
|
|
||||||
icon.setTag(indexObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
View v = view.findViewById(R.id.home_app_pref);
|
|
||||||
v.setTag(indexObj);
|
|
||||||
|
|
||||||
v.setOnClickListener(mHomeClickListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setChecked(boolean state) {
|
|
||||||
if (state != isChecked) {
|
|
||||||
isChecked = state;
|
|
||||||
notifyChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For search
|
|
||||||
*/
|
|
||||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
||||||
new BaseSearchIndexProvider() {
|
|
||||||
@Override
|
|
||||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
|
||||||
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
|
|
||||||
|
|
||||||
final PackageManager pm = context.getPackageManager();
|
|
||||||
final ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
|
|
||||||
pm.getHomeActivities(homeActivities);
|
|
||||||
|
|
||||||
final SharedPreferences sp = context.getSharedPreferences(
|
|
||||||
HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
|
|
||||||
final boolean doShowHome = sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false);
|
|
||||||
|
|
||||||
// We index Home Launchers only if there are more than one or if we are showing the
|
|
||||||
// Home tile into the Dashboard
|
|
||||||
if (homeActivities.size() > 1 || doShowHome) {
|
|
||||||
final Resources res = context.getResources();
|
|
||||||
|
|
||||||
// Add fragment title
|
|
||||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
|
||||||
data.title = res.getString(R.string.home_settings);
|
|
||||||
data.screenTitle = res.getString(R.string.home_settings);
|
|
||||||
data.keywords = res.getString(R.string.keywords_home);
|
|
||||||
result.add(data);
|
|
||||||
|
|
||||||
for (int i = 0; i < homeActivities.size(); i++) {
|
|
||||||
final ResolveInfo resolveInfo = homeActivities.get(i);
|
|
||||||
final ActivityInfo activityInfo = resolveInfo.activityInfo;
|
|
||||||
|
|
||||||
CharSequence name;
|
|
||||||
try {
|
|
||||||
name = activityInfo.loadLabel(pm);
|
|
||||||
if (TextUtils.isEmpty(name)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.v(TAG, "Problem dealing with Home " + activityInfo.name, e);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = new SearchIndexableRaw(context);
|
|
||||||
data.title = name.toString();
|
|
||||||
data.screenTitle = res.getString(R.string.home_settings);
|
|
||||||
result.add(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@@ -64,9 +64,9 @@ import com.android.settings.fingerprint.FingerprintSettings;
|
|||||||
import com.android.settings.location.LocationPreferenceController;
|
import com.android.settings.location.LocationPreferenceController;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Index;
|
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
|
import com.android.settings.search2.SearchFeatureProvider;
|
||||||
import com.android.settings.security.SecurityFeatureProvider;
|
import com.android.settings.security.SecurityFeatureProvider;
|
||||||
import com.android.settings.trustagent.TrustAgentManager;
|
import com.android.settings.trustagent.TrustAgentManager;
|
||||||
import com.android.settings.widget.GearPreference;
|
import com.android.settings.widget.GearPreference;
|
||||||
@@ -79,7 +79,6 @@ import com.android.settingslib.drawer.TileUtils;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||||
@@ -366,7 +365,8 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
|||||||
// The above preferences come and go based on security state, so we need to update
|
// The above preferences come and go based on security state, so we need to update
|
||||||
// the index. This call is expected to be fairly cheap, but we may want to do something
|
// the index. This call is expected to be fairly cheap, but we may want to do something
|
||||||
// smarter in the future.
|
// smarter in the future.
|
||||||
Index.getInstance(getActivity())
|
final Activity activity = getActivity();
|
||||||
|
FeatureFactory.getFactory(activity).getSearchFeatureProvider().getIndexingManager(activity)
|
||||||
.updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
|
.updateFromClassNameResource(SecuritySettings.class.getName(), true, true);
|
||||||
|
|
||||||
PreferenceGroup securityStatusPreferenceGroup =
|
PreferenceGroup securityStatusPreferenceGroup =
|
||||||
|
@@ -38,8 +38,6 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.Index;
|
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.HidProfile;
|
import com.android.settingslib.bluetooth.HidProfile;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
|
import com.android.settingslib.bluetooth.LocalBluetoothProfile;
|
||||||
@@ -250,17 +248,6 @@ public final class BluetoothDevicePreference extends Preference implements
|
|||||||
if (!mCachedDevice.startPairing()) {
|
if (!mCachedDevice.startPairing()) {
|
||||||
Utils.showError(getContext(), mCachedDevice.getName(),
|
Utils.showError(getContext(), mCachedDevice.getName(),
|
||||||
R.string.bluetooth_pairing_error_message);
|
R.string.bluetooth_pairing_error_message);
|
||||||
} else {
|
|
||||||
final Context context = getContext();
|
|
||||||
|
|
||||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
|
||||||
data.className = BluetoothSettings.class.getName();
|
|
||||||
data.title = mCachedDevice.getName();
|
|
||||||
data.screenTitle = context.getResources().getString(R.string.bluetooth_settings);
|
|
||||||
data.iconResId = R.drawable.ic_settings_bluetooth;
|
|
||||||
data.enabled = true;
|
|
||||||
|
|
||||||
Index.getInstance(context).updateFromSearchIndexableData(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,15 +21,12 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.search.Index;
|
|
||||||
import com.android.settings.widget.SwitchWidgetController;
|
import com.android.settings.widget.SwitchWidgetController;
|
||||||
import com.android.settingslib.WirelessUtils;
|
import com.android.settingslib.WirelessUtils;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||||
@@ -53,19 +50,6 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
|||||||
private static final int EVENT_UPDATE_INDEX = 0;
|
private static final int EVENT_UPDATE_INDEX = 0;
|
||||||
private final int mMetricsEvent;
|
private final int mMetricsEvent;
|
||||||
|
|
||||||
private Handler mHandler = new Handler() {
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
switch (msg.what) {
|
|
||||||
case EVENT_UPDATE_INDEX:
|
|
||||||
final boolean isBluetoothOn = msg.getData().getBoolean(EVENT_DATA_IS_BT_ON);
|
|
||||||
Index.getInstance(mContext).updateFromClassNameResource(
|
|
||||||
BluetoothSettings.class.getName(), true, isBluetoothOn);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@@ -142,7 +126,6 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
|||||||
case BluetoothAdapter.STATE_ON:
|
case BluetoothAdapter.STATE_ON:
|
||||||
setChecked(true);
|
setChecked(true);
|
||||||
mSwitchWidget.setEnabled(true);
|
mSwitchWidget.setEnabled(true);
|
||||||
updateSearchIndex(true);
|
|
||||||
break;
|
break;
|
||||||
case BluetoothAdapter.STATE_TURNING_OFF:
|
case BluetoothAdapter.STATE_TURNING_OFF:
|
||||||
mSwitchWidget.setEnabled(false);
|
mSwitchWidget.setEnabled(false);
|
||||||
@@ -150,12 +133,10 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
|||||||
case BluetoothAdapter.STATE_OFF:
|
case BluetoothAdapter.STATE_OFF:
|
||||||
setChecked(false);
|
setChecked(false);
|
||||||
mSwitchWidget.setEnabled(true);
|
mSwitchWidget.setEnabled(true);
|
||||||
updateSearchIndex(false);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
setChecked(false);
|
setChecked(false);
|
||||||
mSwitchWidget.setEnabled(true);
|
mSwitchWidget.setEnabled(true);
|
||||||
updateSearchIndex(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,15 +154,6 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSearchIndex(boolean isBluetoothOn) {
|
|
||||||
mHandler.removeMessages(EVENT_UPDATE_INDEX);
|
|
||||||
|
|
||||||
Message msg = new Message();
|
|
||||||
msg.what = EVENT_UPDATE_INDEX;
|
|
||||||
msg.getData().putBoolean(EVENT_DATA_IS_BT_ON, isBluetoothOn);
|
|
||||||
mHandler.sendMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSwitchToggled(boolean isChecked) {
|
public boolean onSwitchToggled(boolean isChecked) {
|
||||||
// Show toast message if Bluetooth is not allowed in airplane mode
|
// Show toast message if Bluetooth is not allowed in airplane mode
|
||||||
|
@@ -18,7 +18,6 @@ package com.android.settings.bluetooth;
|
|||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.DialogFragment;
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -117,10 +116,6 @@ public final class DeviceProfilesSettings extends InstrumentedDialogFragment imp
|
|||||||
break;
|
break;
|
||||||
case DialogInterface.BUTTON_NEUTRAL:
|
case DialogInterface.BUTTON_NEUTRAL:
|
||||||
mCachedDevice.unpair();
|
mCachedDevice.unpair();
|
||||||
com.android.settings.bluetooth.Utils.updateSearchIndex(getContext(),
|
|
||||||
BluetoothSettings.class.getName(), mCachedDevice.getName(),
|
|
||||||
getString(R.string.bluetooth_settings),
|
|
||||||
R.drawable.ic_settings_bluetooth, false);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,8 +27,6 @@ import android.widget.Toast;
|
|||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.Index;
|
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager.BluetoothManagerCallback;
|
||||||
import com.android.settingslib.bluetooth.Utils.ErrorListener;
|
import com.android.settingslib.bluetooth.Utils.ErrorListener;
|
||||||
@@ -116,21 +114,6 @@ public final class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the search Index for a specific class name and resources.
|
|
||||||
*/
|
|
||||||
public static void updateSearchIndex(Context context, String className, String title,
|
|
||||||
String screenTitle, int iconResId, boolean enabled) {
|
|
||||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
|
||||||
data.className = className;
|
|
||||||
data.title = title;
|
|
||||||
data.screenTitle = screenTitle;
|
|
||||||
data.iconResId = iconResId;
|
|
||||||
data.enabled = enabled;
|
|
||||||
|
|
||||||
Index.getInstance(context).updateFromSearchIndexableData(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LocalBluetoothManager getLocalBtManager(Context context) {
|
public static LocalBluetoothManager getLocalBtManager(Context context) {
|
||||||
return LocalBluetoothManager.getInstance(context, mOnInitCallback);
|
return LocalBluetoothManager.getInstance(context, mOnInitCallback);
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,6 @@ import com.android.settings.DeviceAdminSettings;
|
|||||||
import com.android.settings.DeviceInfoSettings;
|
import com.android.settings.DeviceInfoSettings;
|
||||||
import com.android.settings.DisplaySettings;
|
import com.android.settings.DisplaySettings;
|
||||||
import com.android.settings.DreamSettings;
|
import com.android.settings.DreamSettings;
|
||||||
import com.android.settings.HomeSettings;
|
|
||||||
import com.android.settings.IccLockSettings;
|
import com.android.settings.IccLockSettings;
|
||||||
import com.android.settings.MasterClear;
|
import com.android.settings.MasterClear;
|
||||||
import com.android.settings.PrivacySettings;
|
import com.android.settings.PrivacySettings;
|
||||||
@@ -148,7 +147,6 @@ public class SettingsGateway {
|
|||||||
SpellCheckersSettings.class.getName(),
|
SpellCheckersSettings.class.getName(),
|
||||||
UserDictionaryList.class.getName(),
|
UserDictionaryList.class.getName(),
|
||||||
UserDictionarySettings.class.getName(),
|
UserDictionarySettings.class.getName(),
|
||||||
HomeSettings.class.getName(),
|
|
||||||
DisplaySettings.class.getName(),
|
DisplaySettings.class.getName(),
|
||||||
DeviceInfoSettings.class.getName(),
|
DeviceInfoSettings.class.getName(),
|
||||||
ManageApplications.class.getName(),
|
ManageApplications.class.getName(),
|
||||||
|
@@ -40,7 +40,7 @@ import com.android.settings.core.lifecycle.Lifecycle;
|
|||||||
import com.android.settings.core.lifecycle.LifecycleObserver;
|
import com.android.settings.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settings.core.lifecycle.events.OnResume;
|
import com.android.settings.core.lifecycle.events.OnResume;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.search.Index;
|
import com.android.settings.search2.SearchFeatureProvider;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
public class BuildNumberPreferenceController extends PreferenceController
|
public class BuildNumberPreferenceController extends PreferenceController
|
||||||
@@ -221,8 +221,7 @@ public class BuildNumberPreferenceController extends PreferenceController
|
|||||||
Toast.LENGTH_LONG);
|
Toast.LENGTH_LONG);
|
||||||
mDevHitToast.show();
|
mDevHitToast.show();
|
||||||
// This is good time to index the Developer Options
|
// This is good time to index the Developer Options
|
||||||
Index.getInstance(
|
FeatureFactory.getFactory(mContext).getSearchFeatureProvider().getIndexingManager(mContext)
|
||||||
mContext.getApplicationContext()).updateFromClassNameResource(
|
.updateFromClassNameResource(DevelopmentSettings.class.getName(), true, true);
|
||||||
DevelopmentSettings.class.getName(), true, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,7 +52,9 @@ import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
|
|||||||
import com.android.settings.inputmethod.PhysicalKeyboardFragment;
|
import com.android.settings.inputmethod.PhysicalKeyboardFragment;
|
||||||
import com.android.settings.inputmethod.VirtualKeyboardFragment;
|
import com.android.settings.inputmethod.VirtualKeyboardFragment;
|
||||||
import com.android.settings.language.LanguageAndInputSettings;
|
import com.android.settings.language.LanguageAndInputSettings;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.print.PrintSettingsFragment;
|
import com.android.settings.print.PrintSettingsFragment;
|
||||||
|
import com.android.settings.search2.DatabaseIndexingManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -67,7 +69,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
private static final PackageChangeMonitor PACKAGE_CHANGE_MONITOR = new PackageChangeMonitor();
|
private static final PackageChangeMonitor PACKAGE_CHANGE_MONITOR = new PackageChangeMonitor();
|
||||||
|
|
||||||
// Null if not initialized.
|
// Null if not initialized.
|
||||||
@Nullable private Index mIndex;
|
@Nullable private DatabaseIndexingManager mIndexManager;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private boolean mHasFeaturePrinting;
|
private boolean mHasFeaturePrinting;
|
||||||
|
|
||||||
@@ -112,22 +114,25 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
final boolean isUserUnlocked = activity
|
final boolean isUserUnlocked = activity
|
||||||
.getSystemService(UserManager.class)
|
.getSystemService(UserManager.class)
|
||||||
.isUserUnlocked();
|
.isUserUnlocked();
|
||||||
register(activity, loaderId, Index.getInstance(activity), isUserUnlocked);
|
register(activity, loaderId, FeatureFactory.getFactory(activity)
|
||||||
|
.getSearchFeatureProvider().getIndexingManager(activity), isUserUnlocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For testing to inject {@link Index} object. Also because currently Robolectric doesn't
|
* For testing to inject {@link DatabaseIndexingManager} object.
|
||||||
* support API 24, we can not test code that calls {@link UserManager#isUserUnlocked()}.
|
* Also because currently Robolectric doesn't support API 24, we can not test code that calls
|
||||||
|
* {@link UserManager#isUserUnlocked()}.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void register(Activity activity, int loaderId, Index index, boolean isUserUnlocked) {
|
void register(Activity activity, int loaderId, DatabaseIndexingManager indexManager,
|
||||||
|
boolean isUserUnlocked) {
|
||||||
if (!isUserUnlocked) {
|
if (!isUserUnlocked) {
|
||||||
Log.w(TAG, "Skipping content monitoring because user is locked");
|
Log.w(TAG, "Skipping content monitoring because user is locked");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final Context context = activity.getApplicationContext();
|
final Context context = activity.getApplicationContext();
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mIndex = index;
|
mIndexManager = indexManager;
|
||||||
|
|
||||||
PACKAGE_CHANGE_MONITOR.registerMonitor(context);
|
PACKAGE_CHANGE_MONITOR.registerMonitor(context);
|
||||||
mHasFeaturePrinting = context.getPackageManager()
|
mHasFeaturePrinting = context.getPackageManager()
|
||||||
@@ -137,11 +142,11 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Watch for input device changes.
|
// Watch for input device changes.
|
||||||
InputDevicesMonitor.getInstance().initialize(context, index);
|
InputDevicesMonitor.getInstance().initialize(context, mIndexManager);
|
||||||
|
|
||||||
// Start tracking packages.
|
// Start tracking packages.
|
||||||
AccessibilityServicesMonitor.getInstance().initialize(context, index);
|
AccessibilityServicesMonitor.getInstance().initialize(context, mIndexManager);
|
||||||
InputMethodServicesMonitor.getInstance().initialize(context, index);
|
InputMethodServicesMonitor.getInstance().initialize(context, mIndexManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,7 +157,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
* @param loaderId id for loading print services.
|
* @param loaderId id for loading print services.
|
||||||
*/
|
*/
|
||||||
public void unregister(Activity activity, int loaderId) {
|
public void unregister(Activity activity, int loaderId) {
|
||||||
if (mIndex == null) return;
|
if (mIndexManager == null) return;
|
||||||
|
|
||||||
PACKAGE_CHANGE_MONITOR.unregisterMonitor();
|
PACKAGE_CHANGE_MONITOR.unregisterMonitor();
|
||||||
if (mHasFeaturePrinting) {
|
if (mHasFeaturePrinting) {
|
||||||
@@ -170,7 +175,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<List<PrintServiceInfo>> loader,
|
public void onLoadFinished(Loader<List<PrintServiceInfo>> loader,
|
||||||
List<PrintServiceInfo> services) {
|
List<PrintServiceInfo> services) {
|
||||||
mIndex.updateFromClassNameResource(PrintSettingsFragment.class.getName(),
|
mIndexManager.updateFromClassNameResource(PrintSettingsFragment.class.getName(),
|
||||||
false /* rebuild */, true /* includeInSearchResult */);
|
false /* rebuild */, true /* includeInSearchResult */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +188,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
private static class InputDevicesMonitor implements InputManager.InputDeviceListener {
|
private static class InputDevicesMonitor implements InputManager.InputDeviceListener {
|
||||||
|
|
||||||
// Null if not initialized.
|
// Null if not initialized.
|
||||||
@Nullable private Index mIndex;
|
@Nullable private DatabaseIndexingManager mIndexManager;
|
||||||
private InputManager mInputManager;
|
private InputManager mInputManager;
|
||||||
|
|
||||||
private InputDevicesMonitor() {}
|
private InputDevicesMonitor() {}
|
||||||
@@ -198,15 +203,15 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
synchronized void resetForTesting() {
|
synchronized void resetForTesting() {
|
||||||
if (mIndex != null) {
|
if (mIndexManager != null) {
|
||||||
mInputManager.unregisterInputDeviceListener(this /* listener */);
|
mInputManager.unregisterInputDeviceListener(this /* listener */);
|
||||||
}
|
}
|
||||||
mIndex = null;
|
mIndexManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void initialize(Context context, Index index) {
|
synchronized void initialize(Context context, DatabaseIndexingManager indexManager) {
|
||||||
if (mIndex != null) return;
|
if (mIndexManager != null) return;
|
||||||
mIndex = index;
|
mIndexManager = indexManager;
|
||||||
mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
|
mInputManager = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
|
||||||
buildIndex(true /* rebuild */);
|
buildIndex(true /* rebuild */);
|
||||||
|
|
||||||
@@ -215,7 +220,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildIndex(boolean rebuild) {
|
private void buildIndex(boolean rebuild) {
|
||||||
mIndex.updateFromClassNameResource(PhysicalKeyboardFragment.class.getName(),
|
mIndexManager.updateFromClassNameResource(PhysicalKeyboardFragment.class.getName(),
|
||||||
rebuild, true /* includeInSearchResult */);
|
rebuild, true /* includeInSearchResult */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,7 +319,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
private static class AccessibilityServicesMonitor {
|
private static class AccessibilityServicesMonitor {
|
||||||
|
|
||||||
// Null if not initialized.
|
// Null if not initialized.
|
||||||
@Nullable private Index mIndex;
|
@Nullable private DatabaseIndexingManager mIndexManager;
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
private final List<String> mAccessibilityServices = new ArrayList<>();
|
private final List<String> mAccessibilityServices = new ArrayList<>();
|
||||||
|
|
||||||
@@ -331,12 +336,12 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
synchronized void resetForTesting() {
|
synchronized void resetForTesting() {
|
||||||
mIndex = null;
|
mIndexManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void initialize(Context context, Index index) {
|
synchronized void initialize(Context context, DatabaseIndexingManager index) {
|
||||||
if (mIndex != null) return;
|
if (mIndexManager != null) return;
|
||||||
mIndex = index;
|
mIndexManager = index;
|
||||||
mPackageManager = context.getPackageManager();
|
mPackageManager = context.getPackageManager();
|
||||||
mAccessibilityServices.clear();
|
mAccessibilityServices.clear();
|
||||||
buildIndex(true /* rebuild */);
|
buildIndex(true /* rebuild */);
|
||||||
@@ -354,12 +359,12 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildIndex(boolean rebuild) {
|
private void buildIndex(boolean rebuild) {
|
||||||
mIndex.updateFromClassNameResource(AccessibilitySettings.class.getName(),
|
mIndexManager.updateFromClassNameResource(AccessibilitySettings.class.getName(),
|
||||||
rebuild, true /* includeInSearchResult */);
|
rebuild, true /* includeInSearchResult */);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void onPackageAvailable(String packageName) {
|
synchronized void onPackageAvailable(String packageName) {
|
||||||
if (mIndex == null) return;
|
if (mIndexManager == null) return;
|
||||||
if (mAccessibilityServices.contains(packageName)) return;
|
if (mAccessibilityServices.contains(packageName)) return;
|
||||||
|
|
||||||
final Intent intent = getAccessibilityServiceIntent(packageName);
|
final Intent intent = getAccessibilityServiceIntent(packageName);
|
||||||
@@ -371,7 +376,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized void onPackageUnavailable(String packageName) {
|
synchronized void onPackageUnavailable(String packageName) {
|
||||||
if (mIndex == null) return;
|
if (mIndexManager == null) return;
|
||||||
if (!mAccessibilityServices.remove(packageName)) return;
|
if (!mAccessibilityServices.remove(packageName)) return;
|
||||||
buildIndex(true /* rebuild */);
|
buildIndex(true /* rebuild */);
|
||||||
}
|
}
|
||||||
@@ -385,7 +390,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
Settings.Secure.getUriFor(Settings.Secure.ENABLED_INPUT_METHODS);
|
Settings.Secure.getUriFor(Settings.Secure.ENABLED_INPUT_METHODS);
|
||||||
|
|
||||||
// Null if not initialized.
|
// Null if not initialized.
|
||||||
@Nullable private Index mIndex;
|
@Nullable private DatabaseIndexingManager mIndexManager;
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
private ContentResolver mContentResolver;
|
private ContentResolver mContentResolver;
|
||||||
private final List<String> mInputMethodServices = new ArrayList<>();
|
private final List<String> mInputMethodServices = new ArrayList<>();
|
||||||
@@ -406,19 +411,19 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
synchronized void resetForTesting() {
|
synchronized void resetForTesting() {
|
||||||
if (mIndex != null) {
|
if (mIndexManager != null) {
|
||||||
mContentResolver.unregisterContentObserver(this /* observer */);
|
mContentResolver.unregisterContentObserver(this /* observer */);
|
||||||
}
|
}
|
||||||
mIndex = null;
|
mIndexManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void initialize(Context context, Index index) {
|
synchronized void initialize(Context context, DatabaseIndexingManager indexManager) {
|
||||||
final boolean hasFeatureIme = context.getPackageManager()
|
final boolean hasFeatureIme = context.getPackageManager()
|
||||||
.hasSystemFeature(PackageManager.FEATURE_INPUT_METHODS);
|
.hasSystemFeature(PackageManager.FEATURE_INPUT_METHODS);
|
||||||
if (!hasFeatureIme) return;
|
if (!hasFeatureIme) return;
|
||||||
|
|
||||||
if (mIndex != null) return;
|
if (mIndexManager != null) return;
|
||||||
mIndex = index;
|
mIndexManager = indexManager;
|
||||||
mPackageManager = context.getPackageManager();
|
mPackageManager = context.getPackageManager();
|
||||||
mContentResolver = context.getContentResolver();
|
mContentResolver = context.getContentResolver();
|
||||||
mInputMethodServices.clear();
|
mInputMethodServices.clear();
|
||||||
@@ -448,12 +453,12 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildIndex(Class<?> indexClass, boolean rebuild) {
|
private void buildIndex(Class<?> indexClass, boolean rebuild) {
|
||||||
mIndex.updateFromClassNameResource(indexClass.getName(), rebuild,
|
mIndexManager.updateFromClassNameResource(indexClass.getName(), rebuild,
|
||||||
true /* includeInSearchResult */);
|
true /* includeInSearchResult */);
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void onPackageAvailable(String packageName) {
|
synchronized void onPackageAvailable(String packageName) {
|
||||||
if (mIndex == null) return;
|
if (mIndexManager == null) return;
|
||||||
if (mInputMethodServices.contains(packageName)) return;
|
if (mInputMethodServices.contains(packageName)) return;
|
||||||
|
|
||||||
final Intent intent = getIMEServiceIntent(packageName);
|
final Intent intent = getIMEServiceIntent(packageName);
|
||||||
@@ -466,7 +471,7 @@ public final class DynamicIndexableContentMonitor implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
synchronized void onPackageUnavailable(String packageName) {
|
synchronized void onPackageUnavailable(String packageName) {
|
||||||
if (mIndex == null) return;
|
if (mIndexManager == null) return;
|
||||||
if (!mInputMethodServices.remove(packageName)) return;
|
if (!mInputMethodServices.remove(packageName)) return;
|
||||||
buildIndex(VirtualKeyboardFragment.class, true /* rebuild */);
|
buildIndex(VirtualKeyboardFragment.class, true /* rebuild */);
|
||||||
buildIndex(AvailableVirtualKeyboardFragment.class, true /* rebuild */);
|
buildIndex(AvailableVirtualKeyboardFragment.class, true /* rebuild */);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -120,6 +120,9 @@ import static com.android.settings.search2.DatabaseResultLoader.SELECT_COLUMNS;
|
|||||||
public class DatabaseIndexingManager {
|
public class DatabaseIndexingManager {
|
||||||
private static final String LOG_TAG = "DatabaseIndexingManager";
|
private static final String LOG_TAG = "DatabaseIndexingManager";
|
||||||
|
|
||||||
|
public static final String FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER =
|
||||||
|
"SEARCH_INDEX_DATA_PROVIDER";
|
||||||
|
|
||||||
private static final String NODE_NAME_PREFERENCE_SCREEN = "PreferenceScreen";
|
private static final String NODE_NAME_PREFERENCE_SCREEN = "PreferenceScreen";
|
||||||
private static final String NODE_NAME_CHECK_BOX_PREFERENCE = "CheckBoxPreference";
|
private static final String NODE_NAME_CHECK_BOX_PREFERENCE = "CheckBoxPreference";
|
||||||
private static final String NODE_NAME_LIST_PREFERENCE = "ListPreference";
|
private static final String NODE_NAME_LIST_PREFERENCE = "ListPreference";
|
||||||
|
@@ -26,7 +26,6 @@ import android.view.MenuItem;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.applications.PackageManagerWrapperImpl;
|
import com.android.settings.applications.PackageManagerWrapperImpl;
|
||||||
import com.android.settings.dashboard.SiteMapManager;
|
import com.android.settings.dashboard.SiteMapManager;
|
||||||
import com.android.settings.search.Index;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FeatureProvider for the refactored search code.
|
* FeatureProvider for the refactored search code.
|
||||||
@@ -99,11 +98,7 @@ public class SearchFeatureProviderImpl implements SearchFeatureProvider {
|
|||||||
@Override
|
@Override
|
||||||
public void updateIndex(Context context) {
|
public void updateIndex(Context context) {
|
||||||
long indexStartTime = System.currentTimeMillis();
|
long indexStartTime = System.currentTimeMillis();
|
||||||
if (isEnabled(context)) {
|
getIndexingManager(context).indexDatabase();
|
||||||
getIndexingManager(context).indexDatabase();
|
|
||||||
} else {
|
|
||||||
Index.getInstance(context).update();
|
|
||||||
}
|
|
||||||
Log.d(TAG, "IndexDatabase() took " +
|
Log.d(TAG, "IndexDatabase() took " +
|
||||||
(System.currentTimeMillis() - indexStartTime) + " ms");
|
(System.currentTimeMillis() - indexStartTime) + " ms");
|
||||||
}
|
}
|
||||||
|
@@ -24,8 +24,6 @@ import android.net.NetworkInfo;
|
|||||||
import android.net.wifi.SupplicantState;
|
import android.net.wifi.SupplicantState;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -34,7 +32,6 @@ import android.widget.Toast;
|
|||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.search.Index;
|
|
||||||
import com.android.settings.widget.SwitchWidgetController;
|
import com.android.settings.widget.SwitchWidgetController;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
@@ -79,19 +76,6 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
|||||||
private static final String EVENT_DATA_IS_WIFI_ON = "is_wifi_on";
|
private static final String EVENT_DATA_IS_WIFI_ON = "is_wifi_on";
|
||||||
private static final int EVENT_UPDATE_INDEX = 0;
|
private static final int EVENT_UPDATE_INDEX = 0;
|
||||||
|
|
||||||
private Handler mHandler = new Handler() {
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
switch (msg.what) {
|
|
||||||
case EVENT_UPDATE_INDEX:
|
|
||||||
final boolean isWiFiOn = msg.getData().getBoolean(EVENT_DATA_IS_WIFI_ON);
|
|
||||||
Index.getInstance(mContext).updateFromClassNameResource(
|
|
||||||
WifiSettings.class.getName(), true, isWiFiOn);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public WifiEnabler(Context context, SwitchWidgetController switchWidget,
|
public WifiEnabler(Context context, SwitchWidgetController switchWidget,
|
||||||
MetricsFeatureProvider metricsFeatureProvider) {
|
MetricsFeatureProvider metricsFeatureProvider) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -155,7 +139,6 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
|||||||
case WifiManager.WIFI_STATE_ENABLED:
|
case WifiManager.WIFI_STATE_ENABLED:
|
||||||
setSwitchBarChecked(true);
|
setSwitchBarChecked(true);
|
||||||
mSwitchWidget.setEnabled(true);
|
mSwitchWidget.setEnabled(true);
|
||||||
updateSearchIndex(true);
|
|
||||||
break;
|
break;
|
||||||
case WifiManager.WIFI_STATE_DISABLING:
|
case WifiManager.WIFI_STATE_DISABLING:
|
||||||
mSwitchWidget.setEnabled(false);
|
mSwitchWidget.setEnabled(false);
|
||||||
@@ -163,12 +146,10 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
|||||||
case WifiManager.WIFI_STATE_DISABLED:
|
case WifiManager.WIFI_STATE_DISABLED:
|
||||||
setSwitchBarChecked(false);
|
setSwitchBarChecked(false);
|
||||||
mSwitchWidget.setEnabled(true);
|
mSwitchWidget.setEnabled(true);
|
||||||
updateSearchIndex(false);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
setSwitchBarChecked(false);
|
setSwitchBarChecked(false);
|
||||||
mSwitchWidget.setEnabled(true);
|
mSwitchWidget.setEnabled(true);
|
||||||
updateSearchIndex(false);
|
|
||||||
}
|
}
|
||||||
if (mayDisableTethering(!mSwitchWidget.isChecked())) {
|
if (mayDisableTethering(!mSwitchWidget.isChecked())) {
|
||||||
if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
if (RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||||
@@ -182,15 +163,6 @@ public class WifiEnabler implements SwitchWidgetController.OnSwitchChangeListene
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSearchIndex(boolean isWiFiOn) {
|
|
||||||
mHandler.removeMessages(EVENT_UPDATE_INDEX);
|
|
||||||
|
|
||||||
Message msg = new Message();
|
|
||||||
msg.what = EVENT_UPDATE_INDEX;
|
|
||||||
msg.getData().putBoolean(EVENT_DATA_IS_WIFI_ON, isWiFiOn);
|
|
||||||
mHandler.sendMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setSwitchBarChecked(boolean checked) {
|
private void setSwitchBarChecked(boolean checked) {
|
||||||
mStateMachineEvent = true;
|
mStateMachineEvent = true;
|
||||||
mSwitchWidget.setChecked(checked);
|
mSwitchWidget.setChecked(checked);
|
||||||
|
@@ -30,6 +30,7 @@ import com.android.settings.DevelopmentSettings;
|
|||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.core.lifecycle.Lifecycle;
|
import com.android.settings.core.lifecycle.Lifecycle;
|
||||||
|
import com.android.settings.search2.DatabaseIndexingManager;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -172,7 +173,10 @@ public class BuildNumberPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onActivityResult_confirmPasswordRequestCompleted_enableDevPref() {
|
public void onActivityResult_confirmPasswordRequestCompleted_enableDevPref() {
|
||||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
final Context context = RuntimeEnvironment.application;
|
||||||
|
|
||||||
|
when(mFactory.searchFeatureProvider.getIndexingManager(any(Context.class)))
|
||||||
|
.thenReturn(mock(DatabaseIndexingManager.class));
|
||||||
|
|
||||||
mController = new BuildNumberPreferenceController(
|
mController = new BuildNumberPreferenceController(
|
||||||
context, mActivity, mFragment, mLifecycle);
|
context, mActivity, mFragment, mLifecycle);
|
||||||
|
@@ -62,6 +62,7 @@ import com.android.settings.inputmethod.PhysicalKeyboardFragment;
|
|||||||
import com.android.settings.inputmethod.VirtualKeyboardFragment;
|
import com.android.settings.inputmethod.VirtualKeyboardFragment;
|
||||||
import com.android.settings.language.LanguageAndInputSettings;
|
import com.android.settings.language.LanguageAndInputSettings;
|
||||||
import com.android.settings.print.PrintSettingsFragment;
|
import com.android.settings.print.PrintSettingsFragment;
|
||||||
|
import com.android.settings.search2.DatabaseIndexingManager;
|
||||||
import com.android.settings.testutils.shadow.ShadowActivityWithLoadManager;
|
import com.android.settings.testutils.shadow.ShadowActivityWithLoadManager;
|
||||||
import com.android.settings.testutils.shadow.ShadowContextImplWithRegisterReceiver;
|
import com.android.settings.testutils.shadow.ShadowContextImplWithRegisterReceiver;
|
||||||
import com.android.settings.testutils.shadow.ShadowInputManager;
|
import com.android.settings.testutils.shadow.ShadowInputManager;
|
||||||
@@ -72,6 +73,8 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
@@ -108,8 +111,10 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
private static final String IME_PACKAGE_1 = "ime-1";
|
private static final String IME_PACKAGE_1 = "ime-1";
|
||||||
private static final String IME_PACKAGE_2 = "ime-2";
|
private static final String IME_PACKAGE_2 = "ime-2";
|
||||||
|
|
||||||
private LoaderManager mLoaderManager = mock(LoaderManager.class);
|
@Mock
|
||||||
private Index mIndex = mock(Index.class);
|
private LoaderManager mLoaderManager;
|
||||||
|
@Mock
|
||||||
|
private DatabaseIndexingManager mIndexManager;
|
||||||
|
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private InputManager mInputManager;
|
private InputManager mInputManager;
|
||||||
@@ -124,6 +129,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
mActivity = Robolectric.buildActivity(Activity.class).get();
|
mActivity = Robolectric.buildActivity(Activity.class).get();
|
||||||
mInputManager = InputManager.getInstance();
|
mInputManager = InputManager.getInstance();
|
||||||
|
|
||||||
@@ -160,13 +166,13 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLockedUser() {
|
public void testLockedUser() {
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, false /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, false /* isUserUnlocked */);
|
||||||
|
|
||||||
// No loader procedure happens.
|
// No loader procedure happens.
|
||||||
verify(mLoaderManager, never()).initLoader(
|
verify(mLoaderManager, never()).initLoader(
|
||||||
anyInt(), any(Bundle.class), any(LoaderManager.LoaderCallbacks.class));
|
anyInt(), any(Bundle.class), any(LoaderManager.LoaderCallbacks.class));
|
||||||
// No indexing happens.
|
// No indexing happens.
|
||||||
verify(mIndex, never()).updateFromClassNameResource(
|
verify(mIndexManager, never()).updateFromClassNameResource(
|
||||||
anyString(), anyBoolean(), anyBoolean());
|
anyString(), anyBoolean(), anyBoolean());
|
||||||
|
|
||||||
mMonitor.unregister(mActivity, LOADER_ID);
|
mMonitor.unregister(mActivity, LOADER_ID);
|
||||||
@@ -179,7 +185,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
public void testWithNoPrintingFeature() {
|
public void testWithNoPrintingFeature() {
|
||||||
mRobolectricPackageManager.setSystemFeature(PackageManager.FEATURE_PRINTING, false);
|
mRobolectricPackageManager.setSystemFeature(PackageManager.FEATURE_PRINTING, false);
|
||||||
|
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, true /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, true /* isUserUnlocked */);
|
||||||
|
|
||||||
// No loader procedure happens.
|
// No loader procedure happens.
|
||||||
verify(mLoaderManager, never()).initLoader(
|
verify(mLoaderManager, never()).initLoader(
|
||||||
@@ -194,12 +200,12 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
assertThat(extractPackageMonitor()).isNull();
|
assertThat(extractPackageMonitor()).isNull();
|
||||||
|
|
||||||
// To suppress spurious test fail in {@link #shutDown()}.
|
// To suppress spurious test fail in {@link #shutDown()}.
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, true /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, true /* isUserUnlocked */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPrinterServiceIndex() {
|
public void testPrinterServiceIndex() {
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, true /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, true /* isUserUnlocked */);
|
||||||
|
|
||||||
// Loader procedure happens.
|
// Loader procedure happens.
|
||||||
verify(mLoaderManager, only()).initLoader(LOADER_ID, null, mMonitor);
|
verify(mLoaderManager, only()).initLoader(LOADER_ID, null, mMonitor);
|
||||||
@@ -217,7 +223,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInputDevicesMonitor() {
|
public void testInputDevicesMonitor() {
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, true /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, true /* isUserUnlocked */);
|
||||||
|
|
||||||
// Rebuild indexing should happen.
|
// Rebuild indexing should happen.
|
||||||
verifyRebuildIndexing(PhysicalKeyboardFragment.class);
|
verifyRebuildIndexing(PhysicalKeyboardFragment.class);
|
||||||
@@ -229,9 +235,9 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
* Nothing happens on successive register calls.
|
* Nothing happens on successive register calls.
|
||||||
*/
|
*/
|
||||||
mMonitor.unregister(mActivity, LOADER_ID);
|
mMonitor.unregister(mActivity, LOADER_ID);
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, true /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, true /* isUserUnlocked */);
|
||||||
|
|
||||||
verifyNoIndexing(PhysicalKeyboardFragment.class);
|
verifyNoIndexing(PhysicalKeyboardFragment.class);
|
||||||
assertThat(extactInputDeviceListener()).isEqualTo(listener);
|
assertThat(extactInputDeviceListener()).isEqualTo(listener);
|
||||||
@@ -239,7 +245,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* A device is added.
|
* A device is added.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
listener.onInputDeviceAdded(1 /* deviceId */);
|
listener.onInputDeviceAdded(1 /* deviceId */);
|
||||||
|
|
||||||
@@ -248,7 +254,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* A device is removed.
|
* A device is removed.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
listener.onInputDeviceRemoved(2 /* deviceId */);
|
listener.onInputDeviceRemoved(2 /* deviceId */);
|
||||||
|
|
||||||
@@ -257,7 +263,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* A device is changed.
|
* A device is changed.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
listener.onInputDeviceChanged(3 /* deviceId */);
|
listener.onInputDeviceChanged(3 /* deviceId */);
|
||||||
|
|
||||||
@@ -266,14 +272,14 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAccessibilityServicesMonitor() throws Exception {
|
public void testAccessibilityServicesMonitor() throws Exception {
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, true /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, true /* isUserUnlocked */);
|
||||||
|
|
||||||
verifyRebuildIndexing(AccessibilitySettings.class);
|
verifyRebuildIndexing(AccessibilitySettings.class);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When an accessibility service package is installed, incremental indexing happen.
|
* When an accessibility service package is installed, incremental indexing happen.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
installAccessibilityService(A11Y_PACKAGE_1);
|
installAccessibilityService(A11Y_PACKAGE_1);
|
||||||
|
|
||||||
@@ -282,7 +288,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When another accessibility service package is installed, incremental indexing happens.
|
* When another accessibility service package is installed, incremental indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
installAccessibilityService(A11Y_PACKAGE_2);
|
installAccessibilityService(A11Y_PACKAGE_2);
|
||||||
|
|
||||||
@@ -291,7 +297,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an accessibility service is disabled, rebuild indexing happens.
|
* When an accessibility service is disabled, rebuild indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
disableInstalledPackage(A11Y_PACKAGE_1);
|
disableInstalledPackage(A11Y_PACKAGE_1);
|
||||||
|
|
||||||
@@ -300,7 +306,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an accessibility service is enabled, incremental indexing happens.
|
* When an accessibility service is enabled, incremental indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
enableInstalledPackage(A11Y_PACKAGE_1);
|
enableInstalledPackage(A11Y_PACKAGE_1);
|
||||||
|
|
||||||
@@ -309,7 +315,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an accessibility service package is uninstalled, rebuild indexing happens.
|
* When an accessibility service package is uninstalled, rebuild indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
uninstallAccessibilityService(A11Y_PACKAGE_1);
|
uninstallAccessibilityService(A11Y_PACKAGE_1);
|
||||||
|
|
||||||
@@ -318,7 +324,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an input method service package is installed, nothing happens.
|
* When an input method service package is installed, nothing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
installInputMethodService(IME_PACKAGE_1);
|
installInputMethodService(IME_PACKAGE_1);
|
||||||
|
|
||||||
@@ -327,7 +333,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInputMethodServicesMonitor() throws Exception {
|
public void testInputMethodServicesMonitor() throws Exception {
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, true /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, true /* isUserUnlocked */);
|
||||||
|
|
||||||
verifyRebuildIndexing(VirtualKeyboardFragment.class);
|
verifyRebuildIndexing(VirtualKeyboardFragment.class);
|
||||||
verifyRebuildIndexing(AvailableVirtualKeyboardFragment.class);
|
verifyRebuildIndexing(AvailableVirtualKeyboardFragment.class);
|
||||||
@@ -341,7 +347,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an input method service package is installed, incremental indexing happen.
|
* When an input method service package is installed, incremental indexing happen.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
installInputMethodService(IME_PACKAGE_1);
|
installInputMethodService(IME_PACKAGE_1);
|
||||||
|
|
||||||
@@ -351,7 +357,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When another input method service package is installed, incremental indexing happens.
|
* When another input method service package is installed, incremental indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
installInputMethodService(IME_PACKAGE_2);
|
installInputMethodService(IME_PACKAGE_2);
|
||||||
|
|
||||||
@@ -361,7 +367,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an input method service is disabled, rebuild indexing happens.
|
* When an input method service is disabled, rebuild indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
disableInstalledPackage(IME_PACKAGE_1);
|
disableInstalledPackage(IME_PACKAGE_1);
|
||||||
|
|
||||||
@@ -371,7 +377,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an input method service is enabled, incremental indexing happens.
|
* When an input method service is enabled, incremental indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
enableInstalledPackage(IME_PACKAGE_1);
|
enableInstalledPackage(IME_PACKAGE_1);
|
||||||
|
|
||||||
@@ -381,7 +387,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an input method service package is uninstalled, rebuild indexing happens.
|
* When an input method service package is uninstalled, rebuild indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
uninstallInputMethodService(IME_PACKAGE_1);
|
uninstallInputMethodService(IME_PACKAGE_1);
|
||||||
|
|
||||||
@@ -391,7 +397,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When an accessibility service package is installed, nothing happens.
|
* When an accessibility service package is installed, nothing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
installAccessibilityService(A11Y_PACKAGE_1);
|
installAccessibilityService(A11Y_PACKAGE_1);
|
||||||
|
|
||||||
@@ -401,7 +407,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When enabled IMEs list is changed, rebuild indexing happens.
|
* When enabled IMEs list is changed, rebuild indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
observer.onChange(false /* selfChange */, enabledInputMethodsContentUri);
|
observer.onChange(false /* selfChange */, enabledInputMethodsContentUri);
|
||||||
|
|
||||||
@@ -411,7 +417,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUserDictionaryChangeMonitor() throws Exception {
|
public void testUserDictionaryChangeMonitor() throws Exception {
|
||||||
mMonitor.register(mActivity, LOADER_ID, mIndex, true /* isUserUnlocked */);
|
mMonitor.register(mActivity, LOADER_ID, mIndexManager, true /* isUserUnlocked */);
|
||||||
|
|
||||||
// Content observer should be registered.
|
// Content observer should be registered.
|
||||||
final ContentObserver observer = extractContentObserver(UserDictionary.Words.CONTENT_URI);
|
final ContentObserver observer = extractContentObserver(UserDictionary.Words.CONTENT_URI);
|
||||||
@@ -422,7 +428,7 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
/*
|
/*
|
||||||
* When user dictionary content is changed, rebuild indexing happens.
|
* When user dictionary content is changed, rebuild indexing happens.
|
||||||
*/
|
*/
|
||||||
reset(mIndex);
|
reset(mIndexManager);
|
||||||
|
|
||||||
observer.onChange(false /* selfChange */, UserDictionary.Words.CONTENT_URI);
|
observer.onChange(false /* selfChange */, UserDictionary.Words.CONTENT_URI);
|
||||||
|
|
||||||
@@ -434,21 +440,21 @@ public class DynamicIndexableContentMonitorTest {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
private void verifyNoIndexing(Class<?> indexingClass) {
|
private void verifyNoIndexing(Class<?> indexingClass) {
|
||||||
verify(mIndex, never()).updateFromClassNameResource(eq(indexingClass.getName()),
|
verify(mIndexManager, never()).updateFromClassNameResource(eq(indexingClass.getName()),
|
||||||
anyBoolean(), anyBoolean());
|
anyBoolean(), anyBoolean());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyRebuildIndexing(Class<?> indexingClass) {
|
private void verifyRebuildIndexing(Class<?> indexingClass) {
|
||||||
verify(mIndex, times(1)).updateFromClassNameResource(indexingClass.getName(),
|
verify(mIndexManager, times(1)).updateFromClassNameResource(indexingClass.getName(),
|
||||||
true /* rebuild */, true /* includeInSearchResults */);
|
true /* rebuild */, true /* includeInSearchResults */);
|
||||||
verify(mIndex, never()).updateFromClassNameResource(indexingClass.getName(),
|
verify(mIndexManager, never()).updateFromClassNameResource(indexingClass.getName(),
|
||||||
false /* rebuild */, true /* includeInSearchResults */);
|
false /* rebuild */, true /* includeInSearchResults */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyIncrementalIndexing(Class<?> indexingClass) {
|
private void verifyIncrementalIndexing(Class<?> indexingClass) {
|
||||||
verify(mIndex, times(1)).updateFromClassNameResource(indexingClass.getName(),
|
verify(mIndexManager, times(1)).updateFromClassNameResource(indexingClass.getName(),
|
||||||
false /* rebuild */, true /* includeInSearchResults */);
|
false /* rebuild */, true /* includeInSearchResults */);
|
||||||
verify(mIndex, never()).updateFromClassNameResource(indexingClass.getName(),
|
verify(mIndexManager, never()).updateFromClassNameResource(indexingClass.getName(),
|
||||||
true /* rebuild */, true /* includeInSearchResults */);
|
true /* rebuild */, true /* includeInSearchResults */);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -88,13 +88,4 @@ public class SearchFeatureProviderImplTest {
|
|||||||
mProvider.updateIndex(mActivity);
|
mProvider.updateIndex(mActivity);
|
||||||
verify(mProvider).getIndexingManager(any(Context.class));
|
verify(mProvider).getIndexingManager(any(Context.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdateIndexNewSearch_UsesIndex() {
|
|
||||||
mProvider = spy(new SearchFeatureProviderImpl());
|
|
||||||
when(mProvider.isEnabled(mActivity)).thenReturn(false);
|
|
||||||
|
|
||||||
mProvider.updateIndex(mActivity);
|
|
||||||
verify(mProvider, never()).getIndexingManager(any(Context.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import android.util.Log;
|
|||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.core.codeinspection.CodeInspector;
|
import com.android.settings.core.codeinspection.CodeInspector;
|
||||||
import com.android.settings.dashboard.DashboardFragmentSearchIndexProviderInspector;
|
import com.android.settings.dashboard.DashboardFragmentSearchIndexProviderInspector;
|
||||||
|
import com.android.settings.search2.DatabaseIndexingManager;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -39,14 +40,16 @@ public class SearchIndexProviderCodeInspector extends CodeInspector {
|
|||||||
private static final String NOT_IMPLEMENTING_INDEXABLE_ERROR =
|
private static final String NOT_IMPLEMENTING_INDEXABLE_ERROR =
|
||||||
"SettingsPreferenceFragment should implement Indexable, but these do not:\n";
|
"SettingsPreferenceFragment should implement Indexable, but these do not:\n";
|
||||||
private static final String NOT_CONTAINING_PROVIDER_OBJECT_ERROR =
|
private static final String NOT_CONTAINING_PROVIDER_OBJECT_ERROR =
|
||||||
"Indexable should have public field " + Index.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER
|
"Indexable should have public field "
|
||||||
|
+ DatabaseIndexingManager.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER
|
||||||
+ " but these are not:\n";
|
+ " but these are not:\n";
|
||||||
private static final String NOT_SHARING_PREF_CONTROLLERS_BETWEEN_FRAG_AND_PROVIDER =
|
private static final String NOT_SHARING_PREF_CONTROLLERS_BETWEEN_FRAG_AND_PROVIDER =
|
||||||
"DashboardFragment should share pref controllers with its SearchIndexProvider, but "
|
"DashboardFragment should share pref controllers with its SearchIndexProvider, but "
|
||||||
+ " these are not: \n";
|
+ " these are not: \n";
|
||||||
private static final String NOT_IN_INDEXABLE_PROVIDER_REGISTRY =
|
private static final String NOT_IN_INDEXABLE_PROVIDER_REGISTRY =
|
||||||
"Class containing " + Index.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER + " must be added to "
|
"Class containing " + DatabaseIndexingManager.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER
|
||||||
+ SearchIndexableResources.class.getName() + " but these are not: \n";
|
+ " must be added to " + SearchIndexableResources.class.getName()
|
||||||
|
+ " but these are not: \n";
|
||||||
|
|
||||||
private final List<String> notImplementingIndexableGrandfatherList;
|
private final List<String> notImplementingIndexableGrandfatherList;
|
||||||
private final List<String> notImplementingIndexProviderGrandfatherList;
|
private final List<String> notImplementingIndexProviderGrandfatherList;
|
||||||
@@ -146,7 +149,8 @@ public class SearchIndexProviderCodeInspector extends CodeInspector {
|
|||||||
|
|
||||||
private boolean hasSearchIndexProvider(Class clazz) {
|
private boolean hasSearchIndexProvider(Class clazz) {
|
||||||
try {
|
try {
|
||||||
final Field f = clazz.getField(Index.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER);
|
final Field f = clazz.getField(
|
||||||
|
DatabaseIndexingManager.FIELD_NAME_SEARCH_INDEX_DATA_PROVIDER);
|
||||||
return f != null;
|
return f != null;
|
||||||
} catch (NoClassDefFoundError e) {
|
} catch (NoClassDefFoundError e) {
|
||||||
// Cannot find class def, ignore
|
// Cannot find class def, ignore
|
||||||
|
Reference in New Issue
Block a user