Move default app preferences to one screen
- Move emergency and SMS app preferences to default apps - Fix search on default apps - Make all default app prefs use AppListPreference - Some approximate UI work on AppListPreference Bug: 20210110 Change-Id: Id04086163c7e87c92a03af421a27018fb380b45d
This commit is contained in:
@@ -16,35 +16,27 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settings.applications.ApplicationsState.Callbacks;
|
||||
import com.android.settings.applications.ApplicationsState.Session;
|
||||
import com.android.settings.applications.PermissionsInfo.Callback;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AdvancedAppSettings extends SettingsPreferenceFragment implements Callbacks, Callback,
|
||||
Indexable {
|
||||
public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
||||
ApplicationsState.Callbacks, PermissionsInfo.Callback {
|
||||
|
||||
static final String TAG = "AdvancedAppSettings";
|
||||
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private static final String KEY_APP_PERM = "manage_perms";
|
||||
private static final String KEY_APP_DOMAIN_URLS = "domain_urls";
|
||||
private static final String KEY_DEFAULT_EMERGENCY_APP = "default_emergency_app";
|
||||
|
||||
private ApplicationsState mApplicationsState;
|
||||
private Session mSession;
|
||||
@@ -63,10 +55,6 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements C
|
||||
mAppPermsPreference = findPreference(KEY_APP_PERM);
|
||||
mAppDomainURLsPreference = findPreference(KEY_APP_DOMAIN_URLS);
|
||||
updateUI();
|
||||
|
||||
if (!DefaultEmergencyPreference.isAvailable(getActivity())) {
|
||||
removePreference(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
@@ -142,26 +130,4 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements C
|
||||
mPermissionsInfo.getRuntimePermAppsGrantedCount(),
|
||||
mPermissionsInfo.getRuntimePermAppsCount()));
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
ArrayList<SearchIndexableResource> result = new ArrayList<>(1);
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.advanced_apps;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
ArrayList<String> result = new ArrayList<>(1);
|
||||
if (!DefaultEmergencyPreference.isAvailable(context)) {
|
||||
result.add(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -22,15 +22,14 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.UserHandle;
|
||||
import android.preference.ListPreference;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.AppListPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultBrowserPreference extends ListPreference {
|
||||
public class DefaultBrowserPreference extends AppListPreference {
|
||||
|
||||
final private PackageManager mPm;
|
||||
|
||||
@@ -42,14 +41,13 @@ public class DefaultBrowserPreference extends ListPreference {
|
||||
}
|
||||
|
||||
private void loadBrowserApps() {
|
||||
ArrayMap<String, CharSequence> browsers = resolveBrowserApps();
|
||||
List<String> browsers = resolveBrowserApps();
|
||||
|
||||
setEntries(browsers.values().toArray(new CharSequence[browsers.size()]));
|
||||
setEntryValues(browsers.keySet().toArray(new String[browsers.size()]));
|
||||
setPackageNames(browsers.toArray(new String[browsers.size()]), null);
|
||||
}
|
||||
|
||||
private ArrayMap<String, CharSequence> resolveBrowserApps() {
|
||||
ArrayMap<String, CharSequence> result = new ArrayMap<>();
|
||||
private List<String> resolveBrowserApps() {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
// Create an Intent that will match ALL Browser Apps
|
||||
Intent intent = new Intent();
|
||||
@@ -58,22 +56,17 @@ public class DefaultBrowserPreference extends ListPreference {
|
||||
intent.setData(Uri.parse("http:"));
|
||||
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
PackageManager packageManager = getContext().getPackageManager();
|
||||
List<ResolveInfo> list = packageManager.queryIntentActivitiesAsUser(intent, 0,
|
||||
UserHandle.myUserId());
|
||||
List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(intent, 0, UserHandle.myUserId());
|
||||
|
||||
final int count = list.size();
|
||||
for (int i=0; i<count; i++) {
|
||||
ResolveInfo info = list.get(i);
|
||||
if (info.activityInfo == null || result.containsKey(info.activityInfo.packageName)
|
||||
if (info.activityInfo == null || result.contains(info.activityInfo.packageName)
|
||||
|| !info.handleAllWebDataURI) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String packageName = info.activityInfo.packageName;
|
||||
CharSequence label = info.activityInfo.applicationInfo.loadLabel(packageManager);
|
||||
|
||||
result.put(packageName, label);
|
||||
result.add(info.activityInfo.packageName);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -24,22 +24,22 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.preference.ListPreference;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.AppListPreference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A preference for choosing the default emergency app
|
||||
*/
|
||||
public class DefaultEmergencyPreference extends ListPreference {
|
||||
public class DefaultEmergencyPreference extends AppListPreference {
|
||||
|
||||
private final ContentResolver mContentResolver;
|
||||
|
||||
@@ -52,25 +52,6 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
return new SavedState(getEntries(), getEntryValues(), getSummary(), superState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
if (state instanceof SavedState) {
|
||||
SavedState savedState = (SavedState) state;
|
||||
setEntries(savedState.entries);
|
||||
setEntryValues(savedState.entryValues);
|
||||
setSummary(savedState.summary);
|
||||
super.onRestoreInstanceState(savedState.superState);
|
||||
} else {
|
||||
super.onRestoreInstanceState(state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
String previousValue = Settings.Secure.getString(mContentResolver,
|
||||
@@ -86,25 +67,23 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
}
|
||||
|
||||
private void load() {
|
||||
new AsyncTask<Void, Void, ArrayMap<String, CharSequence>>() {
|
||||
new AsyncTask<Void, Void, Set<String>>() {
|
||||
@Override
|
||||
protected ArrayMap<String, CharSequence> doInBackground(Void[] params) {
|
||||
protected Set<String> doInBackground(Void[] params) {
|
||||
return resolveAssistPackageAndQueryApps();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayMap<String, CharSequence> entries) {
|
||||
setEntries(entries.values().toArray(new CharSequence[entries.size()]));
|
||||
setEntryValues(entries.keySet().toArray(new String[entries.size()]));
|
||||
|
||||
setValue(Settings.Secure.getString(mContentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION));
|
||||
protected void onPostExecute(Set<String> entries) {
|
||||
String currentPkg = Settings.Secure.getString(mContentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
|
||||
setPackageNames(entries.toArray(new String[entries.size()]), currentPkg);
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private ArrayMap<String, CharSequence> resolveAssistPackageAndQueryApps() {
|
||||
ArrayMap<String, CharSequence> packages = new ArrayMap<>();
|
||||
private Set<String> resolveAssistPackageAndQueryApps() {
|
||||
Set<String> packages = new ArraySet<>();
|
||||
|
||||
Intent queryIntent = new Intent(TelephonyManager.ACTION_EMERGENCY_ASSISTANCE);
|
||||
PackageManager packageManager = getContext().getPackageManager();
|
||||
@@ -113,15 +92,13 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
PackageInfo bestMatch = null;
|
||||
for (int i = 0; i < infos.size(); i++) {
|
||||
if (infos.get(i) == null || infos.get(i).activityInfo == null
|
||||
|| packages.containsKey(infos.get(i).activityInfo.packageName)) {
|
||||
|| packages.contains(infos.get(i).activityInfo.packageName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String packageName = infos.get(i).activityInfo.packageName;
|
||||
CharSequence label = infos.get(i).activityInfo.applicationInfo
|
||||
.loadLabel(packageManager);
|
||||
|
||||
packages.put(packageName, label);
|
||||
packages.add(packageName);
|
||||
|
||||
PackageInfo packageInfo;
|
||||
try {
|
||||
@@ -142,7 +119,7 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
String defaultPackage = Settings.Secure.getString(mContentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
|
||||
boolean defaultMissing = TextUtils.isEmpty(defaultPackage)
|
||||
|| !packages.containsKey(defaultPackage);
|
||||
|| !packages.contains(defaultPackage);
|
||||
if (bestMatch != null && defaultMissing) {
|
||||
Settings.Secure.putString(mContentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION,
|
||||
@@ -161,49 +138,4 @@ public class DefaultEmergencyPreference extends ListPreference {
|
||||
return info.applicationInfo != null
|
||||
&& (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
}
|
||||
|
||||
private static class SavedState implements Parcelable {
|
||||
|
||||
public final CharSequence[] entries;
|
||||
public final CharSequence[] entryValues;
|
||||
public final CharSequence summary;
|
||||
public final Parcelable superState;
|
||||
|
||||
public SavedState(CharSequence[] entries, CharSequence[] entryValues,
|
||||
CharSequence summary, Parcelable superState) {
|
||||
this.entries = entries;
|
||||
this.entryValues = entryValues;
|
||||
this.summary = summary;
|
||||
this.superState = superState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeCharSequenceArray(entries);
|
||||
dest.writeCharSequenceArray(entryValues);
|
||||
dest.writeCharSequence(summary);
|
||||
dest.writeParcelable(superState, flags);
|
||||
}
|
||||
|
||||
public Creator<SavedState> CREATOR = new Creator<SavedState>() {
|
||||
@Override
|
||||
public SavedState createFromParcel(Parcel source) {
|
||||
CharSequence[] entries = source.readCharSequenceArray();
|
||||
CharSequence[] entryValues = source.readCharSequenceArray();
|
||||
CharSequence summary = source.readCharSequence();
|
||||
Parcelable superState = source.readParcelable(getClass().getClassLoader());
|
||||
return new SavedState(entries, entryValues, summary, superState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.applications;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.internal.telephony.SmsApplication;
|
||||
import com.android.internal.telephony.SmsApplication.SmsApplicationData;
|
||||
import com.android.settings.AppListPreference;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DefaultSmsPreference extends AppListPreference {
|
||||
|
||||
public DefaultSmsPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
loadSmsApps();
|
||||
}
|
||||
|
||||
private void loadSmsApps() {
|
||||
Collection<SmsApplicationData> smsApplications =
|
||||
SmsApplication.getApplicationCollection(getContext());
|
||||
|
||||
int count = smsApplications.size();
|
||||
String[] packageNames = new String[count];
|
||||
int i = 0;
|
||||
for (SmsApplicationData smsApplicationData : smsApplications) {
|
||||
packageNames[i++] = smsApplicationData.mPackageName;
|
||||
}
|
||||
setPackageNames(packageNames, getDefaultPackage());
|
||||
}
|
||||
|
||||
private String getDefaultPackage() {
|
||||
ComponentName appName = SmsApplication.getDefaultSmsApplication(getContext(), true);
|
||||
if (appName != null) {
|
||||
return appName.getPackageName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
if (!TextUtils.isEmpty(value) && !Objects.equals(value, getDefaultPackage())) {
|
||||
SmsApplication.setDefaultApplication(value, getContext());
|
||||
}
|
||||
setSummary(getEntry());
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isAvailable(Context context) {
|
||||
TelephonyManager tm =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return tm.isSmsCapable();
|
||||
}
|
||||
|
||||
}
|
@@ -17,26 +17,37 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.preference.Preference;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import com.android.settings.InstrumentedFragment;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
import com.android.settings.InstrumentedFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceClickListener {
|
||||
implements Preference.OnPreferenceClickListener, Indexable {
|
||||
|
||||
private static final String TAG = ManageDefaultApps.class.getSimpleName();
|
||||
|
||||
private static final String KEY_DEFAULT_BROWSER = "default_browser";
|
||||
private static final String KEY_SMS_APPLICATION = "default_sms_app";
|
||||
private static final String KEY_DEFAULT_EMERGENCY_APP = "default_emergency_app";
|
||||
|
||||
private DefaultBrowserPreference mDefaultBrowserPreference;
|
||||
private PackageManager mPm;
|
||||
@@ -63,6 +74,18 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
return mPm.setDefaultBrowserPackageName(packageName.toString(), myUserId);
|
||||
}
|
||||
});
|
||||
final boolean isRestrictedUser = UserManager.get(getActivity())
|
||||
.getUserInfo(myUserId).isRestricted();
|
||||
|
||||
// Restricted users cannot currently read/write SMS.
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
if (isRestrictedUser || !DefaultSmsPreference.isAvailable(getActivity())) {
|
||||
removePreference(KEY_SMS_APPLICATION);
|
||||
}
|
||||
|
||||
if (!DefaultEmergencyPreference.isAvailable(getActivity())) {
|
||||
removePreference(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,4 +119,33 @@ public class ManageDefaultApps extends SettingsPreferenceFragment
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
||||
Context context, boolean enabled) {
|
||||
SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.default_apps;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
// Remove SMS Application if the device does not support SMS
|
||||
final boolean isRestrictedUser = UserManager.get(context)
|
||||
.getUserInfo(UserHandle.myUserId()).isRestricted();
|
||||
if (!DefaultSmsPreference.isAvailable(context) || isRestrictedUser) {
|
||||
result.add(KEY_SMS_APPLICATION);
|
||||
}
|
||||
|
||||
if (!DefaultEmergencyPreference.isAvailable(context)) {
|
||||
result.add(KEY_DEFAULT_EMERGENCY_APP);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user