Convert auto-fill default selector to full screen pattern.
Bug: 34280137 Test: RunSettingsRoboTests Change-Id: Icde3bcaf11615010d481f39d8b32d28dfc120018
This commit is contained in:
@@ -118,15 +118,17 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
||||
for (Map.Entry<String, DefaultAppInfo> app : mCandidates.entrySet()) {
|
||||
final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
|
||||
final String appKey = app.getKey();
|
||||
|
||||
pref.setTitle(app.getValue().loadLabel(mPm.getPackageManager()));
|
||||
pref.setIcon(app.getValue().loadIcon(mPm.getPackageManager()));
|
||||
final DefaultAppInfo info = app.getValue();
|
||||
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);
|
||||
}
|
||||
if (!TextUtils.isEmpty(app.getValue().disabledDescription)) {
|
||||
pref.setEnabled(false);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.applications.defaultapps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
@@ -26,6 +27,7 @@ import android.util.Log;
|
||||
import com.android.settings.applications.PackageManagerWrapper;
|
||||
import com.android.settings.applications.PackageManagerWrapperImpl;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.widget.GearPreference;
|
||||
|
||||
public abstract class DefaultAppPreferenceController extends PreferenceController {
|
||||
|
||||
@@ -54,8 +56,31 @@ public abstract class DefaultAppPreferenceController extends PreferenceControlle
|
||||
preference.setSummary(defaultAppLabel);
|
||||
} else {
|
||||
Log.d(TAG, "No default app");
|
||||
preference.setSummary(null);
|
||||
}
|
||||
mayUpdateGearIcon(app, preference);
|
||||
}
|
||||
|
||||
private void mayUpdateGearIcon(DefaultAppInfo app, Preference preference) {
|
||||
if (!(preference instanceof GearPreference)) {
|
||||
return;
|
||||
}
|
||||
final Intent settingIntent = getSettingIntent(app);
|
||||
if (settingIntent != null) {
|
||||
((GearPreference) preference).setOnGearClickListener(
|
||||
p -> mContext.startActivity(settingIntent));
|
||||
} else {
|
||||
((GearPreference) preference).setOnGearClickListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract DefaultAppInfo getDefaultAppInfo();
|
||||
|
||||
/**
|
||||
* Returns an optional intent that will be launched when clicking "gear" icon.
|
||||
*/
|
||||
protected Intent getSettingIntent(DefaultAppInfo info) {
|
||||
//By default return null. It's up to subclasses to provide logic.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.defaultapps;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.provider.Settings;
|
||||
import android.service.autofill.AutoFillService;
|
||||
import android.service.autofill.AutoFillServiceInfo;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultAutoFillPicker extends DefaultAppPickerFragment {
|
||||
|
||||
static final String SETTING = Settings.Secure.AUTO_FILL_SERVICE;
|
||||
static final Intent AUTO_FILL_PROBE = new Intent(AutoFillService.SERVICE_INTERFACE);
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.DEFAULT_AUTOFILL_PICKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldShowItemNone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<DefaultAppInfo> getCandidates() {
|
||||
final List<DefaultAppInfo> candidates = new ArrayList<>();
|
||||
final List<ResolveInfo> resolveInfos = mPm.getPackageManager()
|
||||
.queryIntentServices(AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
|
||||
for (ResolveInfo info : resolveInfos) {
|
||||
candidates.add(new DefaultAppInfo(mUserId, new ComponentName(
|
||||
info.serviceInfo.packageName, info.serviceInfo.name), null /* summary */));
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultAppKey() {
|
||||
return Settings.Secure.getString(getContext().getContentResolver(), SETTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfirmationMessage(DefaultAppInfo appInfo) {
|
||||
if (appInfo == null) {
|
||||
return null;
|
||||
}
|
||||
final CharSequence appName = appInfo.loadLabel(mPm.getPackageManager());
|
||||
return getContext().getString(R.string.autofill_confirmation_message, appName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean setDefaultAppKey(String key) {
|
||||
Settings.Secure.putString(getContext().getContentResolver(), SETTING, key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides Intent to setting activity for the specified auto-fill service.
|
||||
*/
|
||||
static final class AutoFillSettingIntentProvider
|
||||
implements SettingIntentProvider {
|
||||
|
||||
private final String mSelectedKey;
|
||||
private final PackageManager mPackageManager;
|
||||
|
||||
public AutoFillSettingIntentProvider(PackageManager packageManager, String key) {
|
||||
mSelectedKey = key;
|
||||
mPackageManager = packageManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
final List<ResolveInfo> resolveInfos = mPackageManager.queryIntentServices(
|
||||
AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
|
||||
|
||||
for (ResolveInfo resolveInfo : resolveInfos) {
|
||||
final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
|
||||
final String flattenKey = new ComponentName(
|
||||
serviceInfo.packageName, serviceInfo.name).flattenToString();
|
||||
if (TextUtils.equals(mSelectedKey, flattenKey)) {
|
||||
final String settingsActivity = new AutoFillServiceInfo(
|
||||
mPackageManager, serviceInfo)
|
||||
.getSettingsActivity();
|
||||
if (TextUtils.isEmpty(settingsActivity)) {
|
||||
return null;
|
||||
}
|
||||
return new Intent(Intent.ACTION_MAIN).setComponent(
|
||||
new ComponentName(serviceInfo.packageName, settingsActivity));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.defaultapps;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class DefaultAutoFillPreferenceController extends DefaultAppPreferenceController {
|
||||
|
||||
public DefaultAutoFillPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "default_autofill";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Intent getSettingIntent(DefaultAppInfo info) {
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
final DefaultAutoFillPicker.AutoFillSettingIntentProvider intentProvider =
|
||||
new DefaultAutoFillPicker.AutoFillSettingIntentProvider(
|
||||
mPackageManager.getPackageManager(), info.getKey());
|
||||
return intentProvider.getIntent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultAppInfo getDefaultAppInfo() {
|
||||
final String flattenComponent = Settings.Secure.getString(mContext.getContentResolver(),
|
||||
DefaultAutoFillPicker.SETTING);
|
||||
if (!TextUtils.isEmpty(flattenComponent)) {
|
||||
DefaultAppInfo appInfo = new DefaultAppInfo(
|
||||
mUserId, ComponentName.unflattenFromString(flattenComponent), null /*summary*/);
|
||||
return appInfo;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.defaultapps;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Intent;
|
||||
|
||||
/**
|
||||
* Provides an "advanced setting" intent for this app info.
|
||||
*/
|
||||
interface SettingIntentProvider {
|
||||
@Nullable
|
||||
Intent getIntent();
|
||||
}
|
||||
Reference in New Issue
Block a user