Merge "Convert auto-fill default selector to full screen pattern."
This commit is contained in:
@@ -11,6 +11,7 @@ import android.view.ViewGroup;
|
||||
/**
|
||||
* An AppListPreference with optional settings button.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AppListPreferenceWithSettings extends AppListPreference {
|
||||
|
||||
private View mSettingsIcon;
|
||||
|
@@ -20,6 +20,7 @@ import android.provider.SearchIndexableResource;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.applications.defaultapps.DefaultAutoFillPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultBrowserPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
|
||||
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
|
||||
@@ -60,6 +61,7 @@ public class AdvancedAppSettings extends DashboardFragment {
|
||||
controllers.add(new DefaultSmsPreferenceController(context));
|
||||
controllers.add(new DefaultEmergencyPreferenceController(context));
|
||||
controllers.add(new DefaultHomePreferenceController(context));
|
||||
controllers.add(new DefaultAutoFillPreferenceController(context));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
|
@@ -1,135 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
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.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.AppListPreferenceWithSettings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultAutoFillPreference extends AppListPreferenceWithSettings {
|
||||
private static final String TAG = "DefaultAutoFill";
|
||||
|
||||
private static final String SETTING = Settings.Secure.AUTO_FILL_SERVICE;
|
||||
|
||||
public DefaultAutoFillPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
setSavesState(false);
|
||||
setShowItemNone(true);
|
||||
|
||||
refreshData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CharSequence getConfirmationMessage(String value) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int index = findIndexOfValue(value);
|
||||
CharSequence[] entries = getEntries();
|
||||
if (index < 0 || index >= entries.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CharSequence entry = entries[index];
|
||||
return getContext().getString(R.string.autofill_confirmation_message, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean persistString(String value) {
|
||||
Settings.Secure.putString(getContext().getContentResolver(), SETTING, value);
|
||||
refreshData();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void refreshData() {
|
||||
ComponentName selectedComponent = getSelectedComponentName();
|
||||
List<AutoFillServiceInfo> infos = getInfos();
|
||||
|
||||
AutoFillServiceInfo selectedInfo = null;
|
||||
int numberOfComponents = infos.size();
|
||||
ComponentName[] components = new ComponentName[numberOfComponents];
|
||||
for (int i = 0; i < numberOfComponents; ++i) {
|
||||
AutoFillServiceInfo info = infos.get(i);
|
||||
ServiceInfo serviceInfo = info.getServiceInfo();
|
||||
ComponentName component =
|
||||
new ComponentName(serviceInfo.packageName, serviceInfo.name);
|
||||
components[i] = component;
|
||||
|
||||
if (component.equals(selectedComponent)) {
|
||||
selectedInfo = info;
|
||||
}
|
||||
}
|
||||
|
||||
ComponentName selectedComponentSettings = null;
|
||||
if (selectedInfo != null) {
|
||||
String settingsActivity = selectedInfo.getSettingsActivity();
|
||||
selectedComponentSettings = settingsActivity != null
|
||||
? new ComponentName(selectedComponent.getPackageName(), settingsActivity)
|
||||
: null;
|
||||
} else { // selected component not found
|
||||
Log.w(TAG, "Selected AutoFillService not found " + selectedComponent);
|
||||
selectedComponent = null;
|
||||
selectedComponentSettings = null;
|
||||
}
|
||||
|
||||
setComponentNames(components, selectedComponent);
|
||||
setSettingsComponent(selectedComponentSettings);
|
||||
setSummary(getEntry());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ComponentName getSelectedComponentName() {
|
||||
String componentString =
|
||||
Settings.Secure.getString(getContext().getContentResolver(), SETTING);
|
||||
if (componentString == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ComponentName.unflattenFromString(componentString);
|
||||
}
|
||||
|
||||
private List<AutoFillServiceInfo> getInfos() {
|
||||
PackageManager pm = getContext().getPackageManager();
|
||||
List<ResolveInfo> resolveInfos = pm.queryIntentServices(
|
||||
new Intent(AutoFillService.SERVICE_INTERFACE),
|
||||
PackageManager.GET_META_DATA);
|
||||
List<AutoFillServiceInfo> infos = new ArrayList<>(resolveInfos.size());
|
||||
for (ResolveInfo resolveInfo : resolveInfos) {
|
||||
ServiceInfo serviceInfo = resolveInfo.serviceInfo;
|
||||
AutoFillServiceInfo info = new AutoFillServiceInfo(pm, serviceInfo);
|
||||
infos.add(info);
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
@@ -45,7 +45,13 @@ public class GearPreference extends RestrictedPreference implements View.OnClick
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
final View gear = holder.findViewById(R.id.settings_button);
|
||||
gear.setOnClickListener(this);
|
||||
if (mOnGearClickListener != null) {
|
||||
gear.setVisibility(View.VISIBLE);
|
||||
gear.setOnClickListener(this);
|
||||
} else {
|
||||
gear.setVisibility(View.GONE);
|
||||
gear.setOnClickListener(null);
|
||||
}
|
||||
gear.setEnabled(true); // Make gear available even if the preference itself is disabled.
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user