Merge "Add Home / Launcher apps indexing" into lmp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3f3426e0d9
@@ -1824,5 +1824,19 @@
|
||||
</intent-filter>
|
||||
</provider>
|
||||
|
||||
<receiver android:name=".search.HomePackageReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_ADDED" />
|
||||
<action android:name="android.intent.action.PACKAGE_CHANGED" />
|
||||
<action android:name="android.intent.action.PACKAGE_REMOVED" />
|
||||
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
<data android:scheme="package"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
@@ -5463,6 +5463,7 @@
|
||||
<string name="keywords_wifi">wifi wi-fi network connection</string>
|
||||
<string name="keywords_more_default_sms_app">text message</string>
|
||||
<string name="keywords_more_mobile_networks">cellular cell carrier wireless</string>
|
||||
<string name="keywords_home">launcher</string>
|
||||
<string name="keywords_display">screen touchscreen</string>
|
||||
<string name="keywords_display_brightness_level">dim screen touchscreen</string>
|
||||
<string name="keywords_display_auto_brightness">dim screen touchscreen</string>
|
||||
|
@@ -17,17 +17,21 @@
|
||||
package com.android.settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.res.Resources;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.ColorMatrix;
|
||||
import android.graphics.ColorMatrixColorFilter;
|
||||
@@ -37,13 +41,17 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceGroup;
|
||||
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.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
|
||||
public class HomeSettings extends SettingsPreferenceFragment {
|
||||
public class HomeSettings extends SettingsPreferenceFragment implements Indexable {
|
||||
static final String TAG = "HomeSettings";
|
||||
|
||||
static final int REQUESTING_UNINSTALL = 10;
|
||||
@@ -289,4 +297,59 @@ public class HomeSettings extends SettingsPreferenceFragment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -295,7 +295,6 @@ public class SettingsActivity extends Activity
|
||||
|
||||
private boolean mBatteryPresent = true;
|
||||
private BroadcastReceiver mBatteryInfoReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
|
@@ -78,10 +78,8 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
new UserDictionaryContentObserver(mHandler);
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private boolean mHasFeturePrinting;
|
||||
|
||||
private boolean mHasFetureIme;
|
||||
private boolean mHasFeaturePrinting;
|
||||
private boolean mHasFeatureIme;
|
||||
|
||||
private static Intent getAccessibilityServiceIntent(String packageName) {
|
||||
final Intent intent = new Intent(AccessibilityService.SERVICE_INTERFACE);
|
||||
@@ -104,9 +102,9 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
public void register(Context context) {
|
||||
mContext = context;
|
||||
|
||||
mHasFeturePrinting = mContext.getPackageManager().hasSystemFeature(
|
||||
mHasFeaturePrinting = mContext.getPackageManager().hasSystemFeature(
|
||||
PackageManager.FEATURE_PRINTING);
|
||||
mHasFetureIme = mContext.getPackageManager().hasSystemFeature(
|
||||
mHasFeatureIme = mContext.getPackageManager().hasSystemFeature(
|
||||
PackageManager.FEATURE_INPUT_METHODS);
|
||||
|
||||
// Cache accessibility service packages to know when they go away.
|
||||
@@ -124,7 +122,7 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
mAccessibilityServices.add(resolveInfo.serviceInfo.packageName);
|
||||
}
|
||||
|
||||
if (mHasFeturePrinting) {
|
||||
if (mHasFeaturePrinting) {
|
||||
// Cache print service packages to know when they go away.
|
||||
PrintManager printManager = (PrintManager)
|
||||
mContext.getSystemService(Context.PRINT_SERVICE);
|
||||
@@ -141,7 +139,7 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
}
|
||||
|
||||
// Cache IME service packages to know when they go away.
|
||||
if (mHasFetureIme) {
|
||||
if (mHasFeatureIme) {
|
||||
InputMethodManager imeManager = (InputMethodManager)
|
||||
mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
List<InputMethodInfo> inputMethods = imeManager.getInputMethodList();
|
||||
@@ -174,7 +172,7 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
Context.INPUT_SERVICE);
|
||||
inputManager.unregisterInputDeviceListener(this);
|
||||
|
||||
if (mHasFetureIme) {
|
||||
if (mHasFeatureIme) {
|
||||
mContext.getContentResolver().unregisterContentObserver(
|
||||
mUserDictionaryContentObserver);
|
||||
}
|
||||
@@ -242,7 +240,7 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
}
|
||||
}
|
||||
|
||||
if (mHasFeturePrinting) {
|
||||
if (mHasFeaturePrinting) {
|
||||
if (!mPrintServices.contains(packageName)) {
|
||||
final Intent intent = getPrintServiceIntent(packageName);
|
||||
if (!mContext.getPackageManager().queryIntentServices(intent, 0).isEmpty()) {
|
||||
@@ -253,7 +251,7 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
}
|
||||
}
|
||||
|
||||
if (mHasFetureIme) {
|
||||
if (mHasFeatureIme) {
|
||||
if (!mImeServices.contains(packageName)) {
|
||||
Intent intent = getIMEServiceIntent(packageName);
|
||||
if (!mContext.getPackageManager().queryIntentServices(intent, 0).isEmpty()) {
|
||||
@@ -273,7 +271,7 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
AccessibilitySettings.class.getName(), true, true);
|
||||
}
|
||||
|
||||
if (mHasFeturePrinting) {
|
||||
if (mHasFeaturePrinting) {
|
||||
final int printIndex = mPrintServices.indexOf(packageName);
|
||||
if (printIndex >= 0) {
|
||||
mPrintServices.remove(printIndex);
|
||||
@@ -282,7 +280,7 @@ public final class DynamicIndexableContentMonitor extends PackageMonitor impleme
|
||||
}
|
||||
}
|
||||
|
||||
if (mHasFetureIme) {
|
||||
if (mHasFeatureIme) {
|
||||
final int imeIndex = mImeServices.indexOf(packageName);
|
||||
if (imeIndex >= 0) {
|
||||
mImeServices.remove(imeIndex);
|
||||
|
36
src/com/android/settings/search/HomePackageReceiver.java
Normal file
36
src/com/android/settings/search/HomePackageReceiver.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.search;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import com.android.settings.HomeSettings;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A BroadcastReceiver for detecting Home Launchers
|
||||
*/
|
||||
public class HomePackageReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Index.getInstance(context).updateFromClassNameResource(
|
||||
HomeSettings.class.getName(), true, true);
|
||||
}
|
||||
}
|
@@ -119,7 +119,7 @@ public final class SearchIndexableResources {
|
||||
sResMap.put(HomeSettings.class.getName(),
|
||||
new SearchIndexableResource(
|
||||
Ranking.getRankForClassName(HomeSettings.class.getName()),
|
||||
R.xml.home_selection,
|
||||
NO_DATA_RES_ID,
|
||||
HomeSettings.class.getName(),
|
||||
R.drawable.ic_settings_home));
|
||||
|
||||
|
Reference in New Issue
Block a user