Rearrange configure/default apps
Bug: 27276982 Bug: 27279305 Change-Id: I443e9d2bc0c3fd9bcc13ee86716c14fbb55af0ba
This commit is contained in:
@@ -16,23 +16,29 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.PermissionsSummaryHelper.PermissionsResultCallback;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
import com.android.settingslib.applications.ApplicationsState.AppEntry;
|
||||
import com.android.settingslib.applications.ApplicationsState.Session;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
||||
ApplicationsState.Callbacks {
|
||||
ApplicationsState.Callbacks, Indexable {
|
||||
|
||||
static final String TAG = "AdvancedAppSettings";
|
||||
|
||||
@@ -176,4 +182,20 @@ public class AdvancedAppSettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.advanced_apps;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
return Utils.getNonIndexable(R.xml.advanced_apps, context);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -21,17 +21,25 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.UserHandle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import android.util.Log;
|
||||
import com.android.internal.content.PackageMonitor;
|
||||
import com.android.settings.AppListPreference;
|
||||
import com.android.settings.PreferenceAvailabilityProvider;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultBrowserPreference extends AppListPreference {
|
||||
|
||||
private static final String TAG = "DefaultBrowserPref";
|
||||
|
||||
private static final long DELAY_UPDATE_BROWSER_MILLIS = 500;
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
|
||||
final private PackageManager mPm;
|
||||
|
||||
public DefaultBrowserPreference(Context context, AttributeSet attrs) {
|
||||
@@ -41,12 +49,70 @@ public class DefaultBrowserPreference extends AppListPreference {
|
||||
refreshBrowserApps();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
updateDefaultBrowserPreference();
|
||||
mPackageMonitor.register(getContext(), getContext().getMainLooper(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetached() {
|
||||
mPackageMonitor.unregister();
|
||||
super.onDetached();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String newValue) {
|
||||
|
||||
if (newValue == null) {
|
||||
return false;
|
||||
}
|
||||
final CharSequence packageName = (CharSequence) newValue;
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return false;
|
||||
}
|
||||
boolean result = mPm.setDefaultBrowserPackageNameAsUser(
|
||||
packageName.toString(), mUserId);
|
||||
if (result) {
|
||||
setSummary("%s");
|
||||
}
|
||||
return result && super.persistString(newValue);
|
||||
}
|
||||
|
||||
public void refreshBrowserApps() {
|
||||
List<String> browsers = resolveBrowserApps();
|
||||
|
||||
setPackageNames(browsers.toArray(new String[browsers.size()]), null);
|
||||
}
|
||||
|
||||
private void updateDefaultBrowserPreference() {
|
||||
refreshBrowserApps();
|
||||
|
||||
final PackageManager pm = getContext().getPackageManager();
|
||||
|
||||
String packageName = pm.getDefaultBrowserPackageNameAsUser(mUserId);
|
||||
if (!TextUtils.isEmpty(packageName)) {
|
||||
// Check if the default Browser package is still there
|
||||
Intent intent = new Intent();
|
||||
intent.setPackage(packageName);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.addCategory(Intent.CATEGORY_BROWSABLE);
|
||||
intent.setData(Uri.parse("http:"));
|
||||
|
||||
ResolveInfo info = mPm.resolveActivityAsUser(intent, 0, mUserId);
|
||||
if (info != null) {
|
||||
setValue(packageName);
|
||||
setSummary("%s");
|
||||
} else {
|
||||
setSummary(R.string.default_browser_title_none);
|
||||
}
|
||||
} else {
|
||||
setSummary(R.string.default_browser_title_none);
|
||||
Log.d(TAG, "Cannot set empty default Browser value!");
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> resolveBrowserApps() {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
@@ -58,7 +124,7 @@ public class DefaultBrowserPreference extends AppListPreference {
|
||||
|
||||
// Resolve that intent and check that the handleAllWebDataURI boolean is set
|
||||
List<ResolveInfo> list = mPm.queryIntentActivitiesAsUser(intent, PackageManager.MATCH_ALL,
|
||||
UserHandle.myUserId());
|
||||
mUserId);
|
||||
|
||||
final int count = list.size();
|
||||
for (int i=0; i<count; i++) {
|
||||
@@ -74,10 +140,36 @@ public class DefaultBrowserPreference extends AppListPreference {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
|
||||
private final Runnable mUpdateRunnable = new Runnable() {
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
return true;
|
||||
public void run() {
|
||||
updateDefaultBrowserPreference();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final PackageMonitor mPackageMonitor = new PackageMonitor() {
|
||||
@Override
|
||||
public void onPackageAdded(String packageName, int uid) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageAppeared(String packageName, int reason) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageDisappeared(String packageName, int reason) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageRemoved(String packageName, int uid) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
private void sendUpdate() {
|
||||
mHandler.postDelayed(mUpdateRunnable, DELAY_UPDATE_BROWSER_MILLIS);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -24,16 +24,13 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.AppListPreference;
|
||||
import com.android.settings.PreferenceAvailabilityProvider;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.SelfAvailablePreference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -42,7 +39,8 @@ import java.util.Set;
|
||||
/**
|
||||
* A preference for choosing the default emergency app
|
||||
*/
|
||||
public class DefaultEmergencyPreference extends AppListPreference {
|
||||
public class DefaultEmergencyPreference extends AppListPreference
|
||||
implements SelfAvailablePreference {
|
||||
|
||||
private final ContentResolver mContentResolver;
|
||||
|
||||
@@ -144,12 +142,8 @@ public class DefaultEmergencyPreference extends AppListPreference {
|
||||
&& (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
}
|
||||
|
||||
public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
return isCapable(context)
|
||||
&& context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null
|
||||
&& !Utils.isManagedProfile(UserManager.get(context));
|
||||
}
|
||||
public boolean isAvailable(Context context) {
|
||||
return isCapable(context)
|
||||
&& context.getPackageManager().resolveActivity(QUERY_INTENT, 0) != null;
|
||||
}
|
||||
}
|
||||
|
@@ -26,11 +26,8 @@ import android.content.pm.UserInfo;
|
||||
import android.os.Build;
|
||||
import android.os.UserManager;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.AppListPreference;
|
||||
import com.android.settings.PreferenceAvailabilityProvider;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -117,11 +114,4 @@ public class DefaultHomePreference extends AppListPreference {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
return !Utils.isManagedProfile(UserManager.get(context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import com.android.settings.AppListPreference;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
@@ -25,20 +23,17 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationAssistantService;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Slog;
|
||||
import com.android.settings.AppListPreference;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.notification.ManagedServiceSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.android.settings.PreferenceAvailabilityProvider;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.notification.ManagedServiceSettings;
|
||||
|
||||
public class DefaultNotificationAssistantPreference extends AppListPreference {
|
||||
private static final String TAG = "DefaultNotiAssist";
|
||||
|
||||
@@ -111,11 +106,4 @@ public class DefaultNotificationAssistantPreference extends AppListPreference {
|
||||
c.emptyText = R.string.no_notification_listeners;
|
||||
return c;
|
||||
}
|
||||
|
||||
public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
return !Utils.isManagedProfile(UserManager.get(context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,19 +19,16 @@ package com.android.settings.applications;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.telecom.DefaultDialerManager;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.AppListPreference;
|
||||
import com.android.settings.PreferenceAvailabilityProvider;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.SelfAvailablePreference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DefaultPhonePreference extends AppListPreference {
|
||||
public class DefaultPhonePreference extends AppListPreference implements SelfAvailablePreference {
|
||||
private final Context mContext;
|
||||
|
||||
public DefaultPhonePreference(Context context, AttributeSet attrs) {
|
||||
@@ -44,7 +41,7 @@ public class DefaultPhonePreference extends AppListPreference {
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
if (!TextUtils.isEmpty(value) && !Objects.equals(value, getDefaultPackage())) {
|
||||
TelecomManager.from(mContext).setDefaultDialer(value);
|
||||
DefaultDialerManager.setDefaultDialerApplication(getContext(), value, mUserId);
|
||||
}
|
||||
setSummary(getEntry());
|
||||
return true;
|
||||
@@ -52,7 +49,7 @@ public class DefaultPhonePreference extends AppListPreference {
|
||||
|
||||
private void loadDialerApps() {
|
||||
List<String> dialerPackages =
|
||||
DefaultDialerManager.getInstalledDialerApplications(getContext());
|
||||
DefaultDialerManager.getInstalledDialerApplications(getContext(), mUserId);
|
||||
|
||||
final String[] dialers = new String[dialerPackages.size()];
|
||||
for (int i = 0; i < dialerPackages.size(); i++) {
|
||||
@@ -62,22 +59,19 @@ public class DefaultPhonePreference extends AppListPreference {
|
||||
}
|
||||
|
||||
private String getDefaultPackage() {
|
||||
return DefaultDialerManager.getDefaultDialerApplication(getContext());
|
||||
return DefaultDialerManager.getDefaultDialerApplication(getContext(), mUserId);
|
||||
}
|
||||
|
||||
public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
|
||||
final TelephonyManager tm =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (!tm.isVoiceCapable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final UserManager um =
|
||||
(UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
return !um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
final TelephonyManager tm =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
if (!tm.isVoiceCapable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final UserManager um =
|
||||
(UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
return !um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS);
|
||||
}
|
||||
}
|
||||
|
@@ -22,17 +22,15 @@ import android.os.UserManager;
|
||||
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 com.android.settings.PreferenceAvailabilityProvider;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.SelfAvailablePreference;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DefaultSmsPreference extends AppListPreference {
|
||||
public class DefaultSmsPreference extends AppListPreference implements SelfAvailablePreference {
|
||||
|
||||
public DefaultSmsPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
@@ -70,18 +68,13 @@ public class DefaultSmsPreference extends AppListPreference {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
boolean isRestrictedUser =
|
||||
UserManager.get(context)
|
||||
.getUserInfo(UserHandle.myUserId()).isRestricted();
|
||||
TelephonyManager tm =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return !isRestrictedUser
|
||||
&& tm.isSmsCapable()
|
||||
&& !Utils.isManagedProfile(UserManager.get(context));
|
||||
}
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
boolean isRestrictedUser =
|
||||
UserManager.get(context)
|
||||
.getUserInfo(UserHandle.myUserId()).isRestricted();
|
||||
TelephonyManager tm =
|
||||
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
return !isRestrictedUser && tm.isSmsCapable();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,20 +18,15 @@ package com.android.settings.applications;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.PreferenceAvailabilityProvider;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.voice.VoiceInputListPreference;
|
||||
|
||||
/**
|
||||
@@ -179,11 +174,4 @@ public class ManageAssist extends SettingsPreferenceFragment
|
||||
mDefaultAssitPref.setValue(assistPackage);
|
||||
updateUi();
|
||||
}
|
||||
|
||||
public static class AvailabilityProvider implements PreferenceAvailabilityProvider {
|
||||
@Override
|
||||
public boolean isAvailable(Context context) {
|
||||
return !Utils.isManagedProfile(UserManager.get(context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,281 +0,0 @@
|
||||
/*
|
||||
* 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.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.util.ArrayMap;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.content.PackageMonitor;
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.PreferenceAvailabilityProvider;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Index;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.utils.ProfileSettingsPreferenceFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ManageDefaultApps extends ProfileSettingsPreferenceFragment
|
||||
implements Preference.OnPreferenceClickListener, Indexable {
|
||||
|
||||
private static final String TAG = ManageDefaultApps.class.getSimpleName();
|
||||
|
||||
private static final String KEY_DEFAULT_HOME = "default_home";
|
||||
private static final String KEY_ASSIST_AND_VOICE_INPUT = "assist_and_voice_input";
|
||||
private static final String KEY_DEFAULT_BROWSER = "default_browser";
|
||||
private static final String KEY_DEFAULT_PHONE_APP = "default_phone_app";
|
||||
private static final String KEY_DEFAULT_EMERGENCY_APP = "default_emergency_app";
|
||||
private static final String KEY_SMS_APPLICATION = "default_sms_app";
|
||||
private static final String KEY_DEFAULT_NOTIFICATION_ASST = "default_notification_asst_app";
|
||||
private static final String[] PREFERENCE_KEYS = new String[] {
|
||||
KEY_DEFAULT_HOME, KEY_ASSIST_AND_VOICE_INPUT, KEY_DEFAULT_BROWSER,
|
||||
KEY_DEFAULT_PHONE_APP, KEY_DEFAULT_EMERGENCY_APP, KEY_SMS_APPLICATION,
|
||||
KEY_DEFAULT_NOTIFICATION_ASST
|
||||
};
|
||||
|
||||
private DefaultBrowserPreference mDefaultBrowserPreference;
|
||||
private PackageManager mPm;
|
||||
private int myUserId;
|
||||
|
||||
private static final long DELAY_UPDATE_BROWSER_MILLIS = 500;
|
||||
|
||||
private final Handler mHandler = new Handler();
|
||||
|
||||
private final Runnable mUpdateRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateDefaultBrowserPreference();
|
||||
}
|
||||
};
|
||||
|
||||
private final PackageMonitor mPackageMonitor = new PackageMonitor() {
|
||||
@Override
|
||||
public void onPackageAdded(String packageName, int uid) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageAppeared(String packageName, int reason) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageDisappeared(String packageName, int reason) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageRemoved(String packageName, int uid) {
|
||||
sendUpdate();
|
||||
}
|
||||
|
||||
private void sendUpdate() {
|
||||
mHandler.postDelayed(mUpdateRunnable, DELAY_UPDATE_BROWSER_MILLIS);
|
||||
}
|
||||
};
|
||||
|
||||
private void updateDefaultBrowserPreference() {
|
||||
mDefaultBrowserPreference.refreshBrowserApps();
|
||||
|
||||
final PackageManager pm = getPackageManager();
|
||||
|
||||
String packageName = pm.getDefaultBrowserPackageNameAsUser(UserHandle.myUserId());
|
||||
if (!TextUtils.isEmpty(packageName)) {
|
||||
// Check if the default Browser package is still there
|
||||
Intent intent = new Intent();
|
||||
intent.setPackage(packageName);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.addCategory(Intent.CATEGORY_BROWSABLE);
|
||||
intent.setData(Uri.parse("http:"));
|
||||
|
||||
ResolveInfo info = mPm.resolveActivityAsUser(intent, 0, myUserId);
|
||||
if (info != null) {
|
||||
mDefaultBrowserPreference.setValue(packageName);
|
||||
CharSequence label = info.loadLabel(pm);
|
||||
mDefaultBrowserPreference.setSummary(label);
|
||||
} else {
|
||||
mDefaultBrowserPreference.setSummary(R.string.default_browser_title_none);
|
||||
}
|
||||
} else {
|
||||
mDefaultBrowserPreference.setSummary(R.string.default_browser_title_none);
|
||||
Log.d(TAG, "Cannot set empty default Browser value!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.default_apps);
|
||||
|
||||
mPm = getPackageManager();
|
||||
myUserId = UserHandle.myUserId();
|
||||
|
||||
|
||||
mDefaultBrowserPreference = (DefaultBrowserPreference) findPreference(KEY_DEFAULT_BROWSER);
|
||||
mDefaultBrowserPreference.setOnPreferenceChangeListener(
|
||||
new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
|
||||
if (newValue == null) {
|
||||
return false;
|
||||
}
|
||||
final CharSequence packageName = (CharSequence) newValue;
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return false;
|
||||
}
|
||||
boolean result = mPm.setDefaultBrowserPackageNameAsUser(
|
||||
packageName.toString(), myUserId);
|
||||
if (result) {
|
||||
mDefaultBrowserPreference.setValue(packageName.toString());
|
||||
final CharSequence appName = mDefaultBrowserPreference.getEntry();
|
||||
mDefaultBrowserPreference.setSummary(appName);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
updatePreferenceVisibility();
|
||||
// Update the index.
|
||||
Index.getInstance(getActivity()).updateFromClassNameResource(
|
||||
ManageDefaultApps.class.getName(), true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterate all preferences and hide it if it is unavailable.
|
||||
*/
|
||||
private void updatePreferenceVisibility() {
|
||||
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||
int count = preferenceScreen.getPreferenceCount();
|
||||
List<String> preferenceKeys = new ArrayList<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
String preferenceKey = preferenceScreen.getPreference(i).getKey();
|
||||
if (!TextUtils.isEmpty(preferenceKey)) {
|
||||
preferenceKeys.add(preferenceKey);
|
||||
}
|
||||
}
|
||||
for (String preferenceKey : preferenceKeys) {
|
||||
boolean isAvailable = getPreferenceAvailability(getContext(), preferenceKey);
|
||||
if (!isAvailable) {
|
||||
Preference preference = preferenceScreen.findPreference(preferenceKey);
|
||||
preferenceScreen.removePreference(preference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get availability of preference from {@link PreferenceAvailabilityProvider}.
|
||||
*/
|
||||
private static boolean getPreferenceAvailability(Context context,
|
||||
String preferenceKey) {
|
||||
// Consider the preference is unavailable if no corresponding provider is found.
|
||||
PreferenceAvailabilityProvider provider = getPreferenceAvailabilityProvider(preferenceKey);
|
||||
return (provider == null) ? false : provider.isAvailable(context);
|
||||
}
|
||||
|
||||
private static PreferenceAvailabilityProvider getPreferenceAvailabilityProvider(
|
||||
String preferenceKey) {
|
||||
switch (preferenceKey) {
|
||||
case KEY_ASSIST_AND_VOICE_INPUT:
|
||||
return new ManageAssist.AvailabilityProvider();
|
||||
case KEY_DEFAULT_BROWSER:
|
||||
return new DefaultBrowserPreference.AvailabilityProvider();
|
||||
case KEY_DEFAULT_EMERGENCY_APP:
|
||||
return new DefaultEmergencyPreference.AvailabilityProvider();
|
||||
case KEY_DEFAULT_HOME:
|
||||
return new DefaultHomePreference.AvailabilityProvider();
|
||||
case KEY_DEFAULT_NOTIFICATION_ASST:
|
||||
return new DefaultNotificationAssistantPreference.AvailabilityProvider();
|
||||
case KEY_DEFAULT_PHONE_APP:
|
||||
return new DefaultPhonePreference.AvailabilityProvider();
|
||||
case KEY_SMS_APPLICATION:
|
||||
return new DefaultSmsPreference.AvailabilityProvider();
|
||||
}
|
||||
Log.w(TAG, "getPreferenceAvailabilityProvider: Cannot find provider for " + preferenceKey);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateDefaultBrowserPreference();
|
||||
mPackageMonitor.register(getActivity(), getActivity().getMainLooper(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
mPackageMonitor.unregister();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMetricsCategory() {
|
||||
return MetricsEvent.APPLICATIONS_DEFAULT_APPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
// Iterate all preferences to see which is not available.
|
||||
final ArrayList<String> result = new ArrayList<>();
|
||||
for (String key : PREFERENCE_KEYS) {
|
||||
boolean isAvailable = getPreferenceAvailability(context, key);
|
||||
if (!isAvailable) {
|
||||
result.add(key);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
protected String getIntentActionString() {
|
||||
return Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.os.Bundle;
|
||||
import com.android.settings.InstrumentedFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
|
||||
public class SpecialAccessSettings extends SettingsPreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.special_access);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMetricsCategory() {
|
||||
return InstrumentedFragment.SPECIAL_ACCESS;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user