Refactor DefaultAppPicker to a general radio button picker
Bug: 36557316 Test: make RunSettingsRoboTests Change-Id: I52985e527e55697cf29f8d97d775d4bbed025beb
This commit is contained in:
@@ -26,91 +26,101 @@ import android.graphics.drawable.Drawable;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||
|
||||
/**
|
||||
* Data model representing an app in DefaultAppPicker UI.
|
||||
*/
|
||||
public class DefaultAppInfo {
|
||||
public class DefaultAppInfo extends RadioButtonPickerFragment.CandidateInfo {
|
||||
|
||||
public final int userId;
|
||||
public final ComponentName componentName;
|
||||
public final PackageItemInfo packageItemInfo;
|
||||
public final String summary;
|
||||
public final boolean enabled;
|
||||
protected final PackageManagerWrapper mPm;
|
||||
|
||||
public DefaultAppInfo(int uid, ComponentName cn) {
|
||||
this(uid, cn, null /* summary */);
|
||||
public DefaultAppInfo(PackageManagerWrapper pm, int uid, ComponentName cn) {
|
||||
this(pm, uid, cn, null /* summary */);
|
||||
}
|
||||
|
||||
public DefaultAppInfo(int uid, ComponentName cn, String summary) {
|
||||
this(uid, cn, summary, true /* enabled */);
|
||||
public DefaultAppInfo(PackageManagerWrapper pm, int uid, ComponentName cn, String summary) {
|
||||
this(pm, uid, cn, summary, true /* enabled */);
|
||||
}
|
||||
|
||||
public DefaultAppInfo(int uid, ComponentName cn, String summary, boolean enabled) {
|
||||
public DefaultAppInfo(PackageManagerWrapper pm, int uid, ComponentName cn, String summary,
|
||||
boolean enabled) {
|
||||
super(enabled);
|
||||
mPm = pm;
|
||||
packageItemInfo = null;
|
||||
userId = uid;
|
||||
componentName = cn;
|
||||
this.summary = summary;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public DefaultAppInfo(PackageItemInfo info, String summary, boolean enabled) {
|
||||
public DefaultAppInfo(PackageManagerWrapper pm, PackageItemInfo info, String summary,
|
||||
boolean enabled) {
|
||||
super(enabled);
|
||||
mPm = pm;
|
||||
userId = UserHandle.myUserId();
|
||||
packageItemInfo = info;
|
||||
componentName = null;
|
||||
this.summary = summary;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public DefaultAppInfo(PackageItemInfo info) {
|
||||
this(info, null /* summary */, true /* enabled */);
|
||||
public DefaultAppInfo(PackageManagerWrapper pm, PackageItemInfo info) {
|
||||
this(pm, info, null /* summary */, true /* enabled */);
|
||||
}
|
||||
|
||||
public CharSequence loadLabel(PackageManager pm) {
|
||||
@Override
|
||||
public CharSequence loadLabel() {
|
||||
if (componentName != null) {
|
||||
try {
|
||||
final ActivityInfo actInfo = AppGlobals.getPackageManager().getActivityInfo(
|
||||
componentName, 0, userId);
|
||||
if (actInfo != null) {
|
||||
return actInfo.loadLabel(pm);
|
||||
return actInfo.loadLabel(mPm.getPackageManager());
|
||||
} else {
|
||||
final ApplicationInfo appInfo = pm.getApplicationInfoAsUser(
|
||||
final ApplicationInfo appInfo = mPm.getApplicationInfoAsUser(
|
||||
componentName.getPackageName(), 0, userId);
|
||||
return appInfo.loadLabel(pm);
|
||||
return appInfo.loadLabel(mPm.getPackageManager());
|
||||
}
|
||||
} catch (RemoteException | PackageManager.NameNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
} else if (packageItemInfo != null) {
|
||||
return packageItemInfo.loadLabel(pm);
|
||||
return packageItemInfo.loadLabel(mPm.getPackageManager());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Drawable loadIcon(PackageManager pm) {
|
||||
@Override
|
||||
public Drawable loadIcon() {
|
||||
if (componentName != null) {
|
||||
try {
|
||||
final ActivityInfo actInfo = AppGlobals.getPackageManager().getActivityInfo(
|
||||
componentName, 0, userId);
|
||||
if (actInfo != null) {
|
||||
return actInfo.loadIcon(pm);
|
||||
return actInfo.loadIcon(mPm.getPackageManager());
|
||||
} else {
|
||||
final ApplicationInfo appInfo = pm.getApplicationInfoAsUser(
|
||||
final ApplicationInfo appInfo = mPm.getApplicationInfoAsUser(
|
||||
componentName.getPackageName(), 0, userId);
|
||||
return appInfo.loadIcon(pm);
|
||||
return appInfo.loadIcon(mPm.getPackageManager());
|
||||
}
|
||||
} catch (RemoteException | PackageManager.NameNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (packageItemInfo != null) {
|
||||
return packageItemInfo.loadIcon(pm);
|
||||
return packageItemInfo.loadIcon(mPm.getPackageManager());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
if (componentName != null) {
|
||||
return componentName.flattenToString();
|
||||
|
||||
@@ -24,113 +24,36 @@ import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.applications.PackageManagerWrapperImpl;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.widget.RadioButtonPickerFragment;
|
||||
import com.android.settings.widget.RadioButtonPreference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A generic app picker fragment that shows a list of app as radio button group.
|
||||
*/
|
||||
public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFragment implements
|
||||
RadioButtonPreference.OnClickListener {
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
static final String EXTRA_FOR_WORK = "for_work";
|
||||
|
||||
private final Map<String, DefaultAppInfo> mCandidates = new ArrayMap<>();
|
||||
public abstract class DefaultAppPickerFragment extends RadioButtonPickerFragment {
|
||||
|
||||
protected PackageManagerWrapper mPm;
|
||||
protected UserManager mUserManager;
|
||||
protected int mUserId;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mPm = new PackageManagerWrapperImpl(context.getPackageManager());
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
final Bundle arguments = getArguments();
|
||||
|
||||
boolean mForWork = false;
|
||||
if (arguments != null) {
|
||||
mForWork = arguments.getBoolean(EXTRA_FOR_WORK);
|
||||
}
|
||||
final UserHandle managedProfile = Utils.getManagedProfile(mUserManager);
|
||||
mUserId = mForWork && managedProfile != null
|
||||
? managedProfile.getIdentifier()
|
||||
: UserHandle.myUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
super.onCreatePreferences(savedInstanceState, rootKey);
|
||||
addPreferencesFromResource(R.xml.app_picker_prefs);
|
||||
updateCandidates();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void updateCandidates() {
|
||||
mCandidates.clear();
|
||||
final List<? extends DefaultAppInfo> candidateList = getCandidates();
|
||||
if (candidateList != null) {
|
||||
for (DefaultAppInfo info : candidateList) {
|
||||
mCandidates.put(info.getKey(), info);
|
||||
}
|
||||
}
|
||||
final String defaultAppKey = getDefaultAppKey();
|
||||
final String systemDefaultAppKey = getSystemDefaultAppKey();
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
screen.removeAll();
|
||||
if (shouldShowItemNone()) {
|
||||
final RadioButtonPreference nonePref = new RadioButtonPreference(getPrefContext());
|
||||
nonePref.setIcon(R.drawable.ic_remove_circle);
|
||||
nonePref.setTitle(R.string.app_list_preference_none);
|
||||
nonePref.setChecked(TextUtils.isEmpty(defaultAppKey));
|
||||
nonePref.setOnClickListener(this);
|
||||
screen.addPreference(nonePref);
|
||||
}
|
||||
for (Map.Entry<String, DefaultAppInfo> app : mCandidates.entrySet()) {
|
||||
RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
|
||||
configurePreferenceFromAppInfo(
|
||||
pref, app.getKey(), app.getValue(), defaultAppKey, systemDefaultAppKey);
|
||||
screen.addPreference(pref);
|
||||
}
|
||||
mayCheckOnlyRadioButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRadioButtonClicked(RadioButtonPreference selected) {
|
||||
final String selectedKey = selected.getKey();
|
||||
final String confirmationMessage = getConfirmationMessage(mCandidates.get(selectedKey));
|
||||
final String confirmationMessage = getConfirmationMessage(getCandidate(selectedKey));
|
||||
final Activity activity = getActivity();
|
||||
if (TextUtils.isEmpty(confirmationMessage)) {
|
||||
onRadioButtonConfirmed(selectedKey);
|
||||
super.onRadioButtonClicked(selected);
|
||||
} else if (activity != null) {
|
||||
final DialogFragment fragment = ConfirmationDialogFragment.newInstance(
|
||||
this, selectedKey, confirmationMessage);
|
||||
@@ -138,63 +61,21 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
}
|
||||
}
|
||||
|
||||
private void onRadioButtonConfirmed(String selectedKey) {
|
||||
final boolean success = setDefaultAppKey(selectedKey);
|
||||
if (success) {
|
||||
updateCheckedState(selectedKey);
|
||||
}
|
||||
onSelectionPerformed(success);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public void updateCheckedState(String selectedKey) {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
if (screen != null) {
|
||||
final int count = screen.getPreferenceCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
final Preference pref = screen.getPreference(i);
|
||||
if (pref instanceof RadioButtonPreference) {
|
||||
final RadioButtonPreference radioPref = (RadioButtonPreference) pref;
|
||||
final boolean newCheckedState = TextUtils.equals(pref.getKey(), selectedKey);
|
||||
if (radioPref.isChecked() != newCheckedState) {
|
||||
radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void bindPreferenceExtra(RadioButtonPreference pref,
|
||||
String key, CandidateInfo info, String defaultKey, String systemDefaultKey) {
|
||||
if (!(info instanceof DefaultAppInfo)) {
|
||||
return;
|
||||
}
|
||||
if (TextUtils.equals(systemDefaultKey, key)) {
|
||||
pref.setSummary(R.string.system_app);
|
||||
} else if (!TextUtils.isEmpty(((DefaultAppInfo) info).summary)) {
|
||||
pref.setSummary(((DefaultAppInfo) info).summary);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
void mayCheckOnlyRadioButton() {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
// If there is only 1 thing on screen, select it.
|
||||
if (screen != null && screen.getPreferenceCount() == 1) {
|
||||
final Preference onlyPref = screen.getPreference(0);
|
||||
if (onlyPref instanceof RadioButtonPreference) {
|
||||
((RadioButtonPreference) onlyPref).setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean shouldShowItemNone() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String getSystemDefaultAppKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract List<? extends DefaultAppInfo> getCandidates();
|
||||
|
||||
protected abstract String getDefaultAppKey();
|
||||
|
||||
protected abstract boolean setDefaultAppKey(String key);
|
||||
|
||||
// Called after the user tries to select an item.
|
||||
protected void onSelectionPerformed(boolean success) {
|
||||
}
|
||||
|
||||
protected String getConfirmationMessage(DefaultAppInfo appInfo) {
|
||||
protected String getConfirmationMessage(CandidateInfo info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -241,23 +122,4 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public RadioButtonPreference configurePreferenceFromAppInfo(RadioButtonPreference pref,
|
||||
String appKey, DefaultAppInfo info, String defaultAppKey, String systemDefaultAppKey) {
|
||||
pref.setTitle(info.loadLabel(mPm.getPackageManager()));
|
||||
pref.setIcon(info.loadIcon(mPm.getPackageManager()));
|
||||
pref.setKey(appKey);
|
||||
if (TextUtils.equals(defaultAppKey, appKey)) {
|
||||
pref.setChecked(true);
|
||||
}
|
||||
if (TextUtils.equals(systemDefaultAppKey, appKey)) {
|
||||
pref.setSummary(R.string.system_app);
|
||||
} else if (!TextUtils.isEmpty(info.summary)) {
|
||||
pref.setSummary(info.summary);
|
||||
}
|
||||
pref.setEnabled(info.enabled);
|
||||
pref.setOnClickListener(this);
|
||||
return pref;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class DefaultAppPreferenceController extends PreferenceControlle
|
||||
final DefaultAppInfo app = getDefaultAppInfo();
|
||||
CharSequence defaultAppLabel = null;
|
||||
if (app != null) {
|
||||
defaultAppLabel = app.loadLabel(mPackageManager.getPackageManager());
|
||||
defaultAppLabel = app.loadLabel();
|
||||
}
|
||||
if (!TextUtils.isEmpty(defaultAppLabel)) {
|
||||
preference.setSummary(defaultAppLabel);
|
||||
|
||||
@@ -56,34 +56,34 @@ public class DefaultAutofillPicker extends DefaultAppPickerFragment {
|
||||
final List<ResolveInfo> resolveInfos = mPm.getPackageManager()
|
||||
.queryIntentServices(AUTOFILL_PROBE, PackageManager.GET_META_DATA);
|
||||
for (ResolveInfo info : resolveInfos) {
|
||||
candidates.add(new DefaultAppInfo(mUserId, new ComponentName(
|
||||
candidates.add(new DefaultAppInfo(mPm, mUserId, new ComponentName(
|
||||
info.serviceInfo.packageName, info.serviceInfo.name)));
|
||||
}
|
||||
final List<ResolveInfo> oldResolveInfos = mPm.getPackageManager()
|
||||
.queryIntentServices(OLD_AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
|
||||
for (ResolveInfo info : oldResolveInfos) {
|
||||
candidates.add(new DefaultAppInfo(mUserId, new ComponentName(
|
||||
candidates.add(new DefaultAppInfo(mPm, mUserId, new ComponentName(
|
||||
info.serviceInfo.packageName, info.serviceInfo.name)));
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
protected String getDefaultKey() {
|
||||
return Settings.Secure.getString(getContext().getContentResolver(), SETTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfirmationMessage(DefaultAppInfo appInfo) {
|
||||
protected String getConfirmationMessage(CandidateInfo appInfo) {
|
||||
if (appInfo == null) {
|
||||
return null;
|
||||
}
|
||||
final CharSequence appName = appInfo.loadLabel(mPm.getPackageManager());
|
||||
final CharSequence appName = appInfo.loadLabel();
|
||||
return getContext().getString(R.string.autofill_confirmation_message, appName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String key) {
|
||||
protected boolean setDefaultKey(String key) {
|
||||
Settings.Secure.putString(getContext().getContentResolver(), SETTING, key);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class DefaultAutofillPreferenceController extends DefaultAppPreferenceCon
|
||||
final String flattenComponent = Settings.Secure.getString(mContext.getContentResolver(),
|
||||
DefaultAutofillPicker.SETTING);
|
||||
if (!TextUtils.isEmpty(flattenComponent)) {
|
||||
DefaultAppInfo appInfo = new DefaultAppInfo(
|
||||
DefaultAppInfo appInfo = new DefaultAppInfo(mPackageManager,
|
||||
mUserId, ComponentName.unflattenFromString(flattenComponent));
|
||||
return appInfo;
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ public class DefaultBrowserPicker extends DefaultAppPickerFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
protected String getDefaultKey() {
|
||||
return mPm.getDefaultBrowserPackageNameAsUser(mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String packageName) {
|
||||
protected boolean setDefaultKey(String packageName) {
|
||||
return mPm.setDefaultBrowserPackageNameAsUser(packageName, mUserId);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DefaultBrowserPicker extends DefaultAppPickerFragment {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
candidates.add(new DefaultAppInfo(
|
||||
candidates.add(new DefaultAppInfo(mPm,
|
||||
mPm.getApplicationInfoAsUser(info.activityInfo.packageName, 0, mUserId)));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Skip unknown packages.
|
||||
|
||||
@@ -52,8 +52,7 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final DefaultAppInfo defaultApp = getDefaultAppInfo();
|
||||
final CharSequence defaultAppLabel = defaultApp != null
|
||||
? defaultApp.loadLabel(mPackageManager.getPackageManager()) : null;
|
||||
final CharSequence defaultAppLabel = defaultApp != null ? defaultApp.loadLabel() : null;
|
||||
if (TextUtils.isEmpty(defaultAppLabel)) {
|
||||
final String onlyAppLabel = getOnlyAppLabel();
|
||||
if (!TextUtils.isEmpty(onlyAppLabel)) {
|
||||
@@ -65,8 +64,9 @@ public class DefaultBrowserPreferenceController extends DefaultAppPreferenceCont
|
||||
@Override
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
try {
|
||||
return new DefaultAppInfo(mPackageManager.getPackageManager().getApplicationInfo(
|
||||
mPackageManager.getDefaultBrowserPackageNameAsUser(mUserId), 0));
|
||||
return new DefaultAppInfo(mPackageManager,
|
||||
mPackageManager.getPackageManager().getApplicationInfo(
|
||||
mPackageManager.getDefaultBrowserPackageNameAsUser(mUserId), 0));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DefaultEmergencyPicker extends DefaultAppPickerFragment {
|
||||
final PackageInfo packageInfo =
|
||||
mPm.getPackageManager().getPackageInfo(info.activityInfo.packageName, 0);
|
||||
final ApplicationInfo appInfo = packageInfo.applicationInfo;
|
||||
candidates.add(new DefaultAppInfo(appInfo));
|
||||
candidates.add(new DefaultAppInfo(mPm, appInfo));
|
||||
// Get earliest installed system app.
|
||||
if (isSystemApp(appInfo) && (bestMatch == null ||
|
||||
bestMatch.firstInstallTime > packageInfo.firstInstallTime)) {
|
||||
@@ -59,9 +59,9 @@ public class DefaultEmergencyPicker extends DefaultAppPickerFragment {
|
||||
// Skip unknown packages.
|
||||
}
|
||||
if (bestMatch != null) {
|
||||
final String defaultKey = getDefaultAppKey();
|
||||
final String defaultKey = getDefaultKey();
|
||||
if (TextUtils.isEmpty(defaultKey)) {
|
||||
setDefaultAppKey(bestMatch.packageName);
|
||||
setDefaultKey(bestMatch.packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,19 +69,19 @@ public class DefaultEmergencyPicker extends DefaultAppPickerFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfirmationMessage(DefaultAppInfo info) {
|
||||
protected String getConfirmationMessage(CandidateInfo info) {
|
||||
return Utils.isPackageDirectBootAware(getContext(), info.getKey()) ? null
|
||||
: getContext().getString(R.string.direct_boot_unaware_dialog_message);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
protected String getDefaultKey() {
|
||||
return Settings.Secure.getString(getContext().getContentResolver(),
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String key) {
|
||||
protected boolean setDefaultKey(String key) {
|
||||
final ContentResolver contentResolver = getContext().getContentResolver();
|
||||
final String previousValue = Settings.Secure.getString(contentResolver,
|
||||
Settings.Secure.EMERGENCY_ASSISTANCE_APPLICATION);
|
||||
|
||||
@@ -68,14 +68,15 @@ public class DefaultHomePicker extends DefaultAppPickerFragment {
|
||||
} else {
|
||||
summary = null;
|
||||
}
|
||||
final DefaultAppInfo candidate = new DefaultAppInfo(mUserId, activityName, summary);
|
||||
final DefaultAppInfo candidate =
|
||||
new DefaultAppInfo(mPm, mUserId, activityName, summary);
|
||||
candidates.add(candidate);
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
protected String getDefaultKey() {
|
||||
final ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
final ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
|
||||
if (currentDefaultHome != null) {
|
||||
@@ -85,7 +86,7 @@ public class DefaultHomePicker extends DefaultAppPickerFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String key) {
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (!TextUtils.isEmpty(key)) {
|
||||
final ComponentName component = ComponentName.unflattenFromString(key);
|
||||
final List<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
|
||||
@@ -60,8 +60,7 @@ public class DefaultHomePreferenceController extends DefaultAppPreferenceControl
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final DefaultAppInfo defaultApp = getDefaultAppInfo();
|
||||
final CharSequence defaultAppLabel = defaultApp != null
|
||||
? defaultApp.loadLabel(mPackageManager.getPackageManager()) : null;
|
||||
final CharSequence defaultAppLabel = defaultApp != null ? defaultApp.loadLabel() : null;
|
||||
if (TextUtils.isEmpty(defaultAppLabel)) {
|
||||
final String onlyAppLabel = getOnlyAppLabel();
|
||||
if (!TextUtils.isEmpty(onlyAppLabel)) {
|
||||
@@ -75,7 +74,7 @@ public class DefaultHomePreferenceController extends DefaultAppPreferenceControl
|
||||
final ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
|
||||
final ComponentName currentDefaultHome = mPackageManager.getHomeActivities(homeActivities);
|
||||
|
||||
return new DefaultAppInfo(mUserId, currentDefaultHome);
|
||||
return new DefaultAppInfo(mPackageManager, mUserId, currentDefaultHome);
|
||||
}
|
||||
|
||||
private String getOnlyAppLabel() {
|
||||
|
||||
@@ -43,12 +43,12 @@ public class DefaultNotificationAssistantPicker extends DefaultAppPickerFragment
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
protected String getDefaultKey() {
|
||||
return Settings.Secure.getString(getContext().getContentResolver(), mConfig.setting);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String value) {
|
||||
protected boolean setDefaultKey(String value) {
|
||||
Settings.Secure.putString(getContext().getContentResolver(), mConfig.setting, value);
|
||||
return true;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class DefaultNotificationAssistantPicker extends DefaultAppPickerFragment
|
||||
continue;
|
||||
}
|
||||
|
||||
candidates.add(new DefaultAppInfo(
|
||||
candidates.add(new DefaultAppInfo(mPm,
|
||||
mUserId, new ComponentName(info.packageName, info.name)));
|
||||
}
|
||||
return candidates;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class DefaultPhonePicker extends DefaultAppPickerFragment {
|
||||
DefaultDialerManager.getInstalledDialerApplications(getContext(), mUserId);
|
||||
for (String packageName : dialerPackages) {
|
||||
try {
|
||||
candidates.add(new DefaultAppInfo(
|
||||
candidates.add(new DefaultAppInfo(mPm,
|
||||
mPm.getApplicationInfoAsUser(packageName, 0, mUserId)));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Skip unknown packages.
|
||||
@@ -60,18 +60,18 @@ public class DefaultPhonePicker extends DefaultAppPickerFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
protected String getDefaultKey() {
|
||||
return mDefaultKeyUpdater.getDefaultDialerApplication(getContext(), mUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSystemDefaultAppKey() {
|
||||
protected String getSystemDefaultKey() {
|
||||
return mDefaultKeyUpdater.getSystemDialerPackage();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String key) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, getDefaultAppKey())) {
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, getDefaultKey())) {
|
||||
return mDefaultKeyUpdater.setDefaultDialerApplication(getContext(), key, mUserId);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -57,8 +57,10 @@ public class DefaultPhonePreferenceController extends DefaultAppPreferenceContro
|
||||
@Override
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
try {
|
||||
return new DefaultAppInfo(mPackageManager.getPackageManager().getApplicationInfo(
|
||||
DefaultDialerManager.getDefaultDialerApplication(mContext, mUserId), 0));
|
||||
return new DefaultAppInfo(mPackageManager,
|
||||
mPackageManager.getPackageManager().getApplicationInfo(
|
||||
DefaultDialerManager.getDefaultDialerApplication(mContext, mUserId),
|
||||
0));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DefaultSmsPicker extends DefaultAppPickerFragment {
|
||||
|
||||
for (SmsApplication.SmsApplicationData smsApplicationData : smsApplications) {
|
||||
try {
|
||||
candidates.add(new DefaultAppInfo(
|
||||
candidates.add(new DefaultAppInfo(mPm,
|
||||
mPm.getApplicationInfoAsUser(smsApplicationData.mPackageName, 0, mUserId)));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
// Skip unknown packages.
|
||||
@@ -58,13 +58,13 @@ public class DefaultSmsPicker extends DefaultAppPickerFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
protected String getDefaultKey() {
|
||||
return mDefaultKeyUpdater.getDefaultApplication(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String key) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, getDefaultAppKey())) {
|
||||
protected boolean setDefaultKey(String key) {
|
||||
if (!TextUtils.isEmpty(key) && !TextUtils.equals(key, getDefaultKey())) {
|
||||
mDefaultKeyUpdater.setDefaultApplication(getContext(), key);
|
||||
return true;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class DefaultSmsPicker extends DefaultAppPickerFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfirmationMessage(DefaultAppInfo info) {
|
||||
protected String getConfirmationMessage(CandidateInfo info) {
|
||||
return Utils.isPackageDirectBootAware(getContext(), info.getKey()) ? null
|
||||
: getContext().getString(R.string.direct_boot_unaware_dialog_message);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DefaultSmsPreferenceController extends DefaultAppPreferenceControll
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
final ComponentName app = SmsApplication.getDefaultSmsApplication(mContext, true);
|
||||
if (app != null) {
|
||||
return new DefaultAppInfo(mUserId, app);
|
||||
return new DefaultAppInfo(mPackageManager, mUserId, app);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user