Convert auto-fill default selector to full screen pattern.
Bug: 34280137 Test: RunSettingsRoboTests Change-Id: Icde3bcaf11615010d481f39d8b32d28dfc120018
This commit is contained in:
@@ -26,19 +26,12 @@
|
|||||||
android:fragment="com.android.settings.applications.ManageAssist"
|
android:fragment="com.android.settings.applications.ManageAssist"
|
||||||
android:order="-20"/>
|
android:order="-20"/>
|
||||||
|
|
||||||
<com.android.settings.applications.DefaultAutoFillPreference
|
|
||||||
android:key="default_autofill"
|
|
||||||
android:title="@string/autofill_app"
|
|
||||||
android:summary="@string/app_list_preference_none"
|
|
||||||
settings:keywords="@string/autofill_keywords"
|
|
||||||
android:order="-19"/>
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="default_browser"
|
android:key="default_browser"
|
||||||
android:title="@string/default_browser_title"
|
android:title="@string/default_browser_title"
|
||||||
android:summary="@string/default_browser_title_none"
|
android:summary="@string/default_browser_title_none"
|
||||||
android:fragment="com.android.settings.applications.defaultapps.DefaultBrowserPicker"
|
android:fragment="com.android.settings.applications.defaultapps.DefaultBrowserPicker"
|
||||||
android:order="-18">
|
android:order="-19">
|
||||||
<extra android:name="for_work" android:value="false"/>
|
<extra android:name="for_work" android:value="false"/>
|
||||||
</Preference>
|
</Preference>
|
||||||
|
|
||||||
@@ -48,26 +41,34 @@
|
|||||||
android:summary="@string/no_default_home"
|
android:summary="@string/no_default_home"
|
||||||
android:fragment="com.android.settings.applications.defaultapps.DefaultHomePicker"
|
android:fragment="com.android.settings.applications.defaultapps.DefaultHomePicker"
|
||||||
settings:keywords="@string/keywords_home"
|
settings:keywords="@string/keywords_home"
|
||||||
android:order="-17"/>
|
android:order="-18"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="default_phone_app"
|
android:key="default_phone_app"
|
||||||
android:title="@string/default_phone_title"
|
android:title="@string/default_phone_title"
|
||||||
android:fragment="com.android.settings.applications.defaultapps.DefaultPhonePicker"
|
android:fragment="com.android.settings.applications.defaultapps.DefaultPhonePicker"
|
||||||
settings:keywords="@string/keywords_default_phone_app"
|
settings:keywords="@string/keywords_default_phone_app"
|
||||||
android:order="-16"/>
|
android:order="-17"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="default_sms_app"
|
android:key="default_sms_app"
|
||||||
android:title="@string/sms_application_title"
|
android:title="@string/sms_application_title"
|
||||||
android:fragment="com.android.settings.applications.defaultapps.DefaultSmsPicker"
|
android:fragment="com.android.settings.applications.defaultapps.DefaultSmsPicker"
|
||||||
settings:keywords="@string/keywords_more_default_sms_app"
|
settings:keywords="@string/keywords_more_default_sms_app"
|
||||||
android:order="-15"/>
|
android:order="-16"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="default_emergency_app"
|
android:key="default_emergency_app"
|
||||||
android:title="@string/default_emergency_app"
|
android:title="@string/default_emergency_app"
|
||||||
settings:keywords="@string/keywords_emergency_app"
|
settings:keywords="@string/keywords_emergency_app"
|
||||||
|
android:order="-15"/>
|
||||||
|
|
||||||
|
<com.android.settings.widget.GearPreference
|
||||||
|
android:key="default_autofill"
|
||||||
|
android:title="@string/autofill_app"
|
||||||
|
android:summary="@string/app_list_preference_none"
|
||||||
|
android:fragment="com.android.settings.applications.defaultapps.DefaultAutoFillPicker"
|
||||||
|
settings:keywords="@string/autofill_keywords"
|
||||||
android:order="-14"/>
|
android:order="-14"/>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
|
@@ -11,6 +11,7 @@ import android.view.ViewGroup;
|
|||||||
/**
|
/**
|
||||||
* An AppListPreference with optional settings button.
|
* An AppListPreference with optional settings button.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class AppListPreferenceWithSettings extends AppListPreference {
|
public class AppListPreferenceWithSettings extends AppListPreference {
|
||||||
|
|
||||||
private View mSettingsIcon;
|
private View mSettingsIcon;
|
||||||
|
@@ -20,6 +20,7 @@ import android.provider.SearchIndexableResource;
|
|||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
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.DefaultBrowserPreferenceController;
|
||||||
import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
|
import com.android.settings.applications.defaultapps.DefaultEmergencyPreferenceController;
|
||||||
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
|
import com.android.settings.applications.defaultapps.DefaultHomePreferenceController;
|
||||||
@@ -60,6 +61,7 @@ public class AdvancedAppSettings extends DashboardFragment {
|
|||||||
controllers.add(new DefaultSmsPreferenceController(context));
|
controllers.add(new DefaultSmsPreferenceController(context));
|
||||||
controllers.add(new DefaultEmergencyPreferenceController(context));
|
controllers.add(new DefaultEmergencyPreferenceController(context));
|
||||||
controllers.add(new DefaultHomePreferenceController(context));
|
controllers.add(new DefaultHomePreferenceController(context));
|
||||||
|
controllers.add(new DefaultAutoFillPreferenceController(context));
|
||||||
return controllers;
|
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()) {
|
for (Map.Entry<String, DefaultAppInfo> app : mCandidates.entrySet()) {
|
||||||
final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
|
final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
|
||||||
final String appKey = app.getKey();
|
final String appKey = app.getKey();
|
||||||
|
final DefaultAppInfo info = app.getValue();
|
||||||
pref.setTitle(app.getValue().loadLabel(mPm.getPackageManager()));
|
pref.setTitle(info.loadLabel(mPm.getPackageManager()));
|
||||||
pref.setIcon(app.getValue().loadIcon(mPm.getPackageManager()));
|
pref.setIcon(info.loadIcon(mPm.getPackageManager()));
|
||||||
pref.setKey(appKey);
|
pref.setKey(appKey);
|
||||||
if (TextUtils.equals(defaultAppKey, appKey)) {
|
if (TextUtils.equals(defaultAppKey, appKey)) {
|
||||||
pref.setChecked(true);
|
pref.setChecked(true);
|
||||||
}
|
}
|
||||||
if (TextUtils.equals(systemDefaultAppKey, appKey)) {
|
if (TextUtils.equals(systemDefaultAppKey, appKey)) {
|
||||||
pref.setSummary(R.string.system_app);
|
pref.setSummary(R.string.system_app);
|
||||||
|
} else if (!TextUtils.isEmpty(info.summary)) {
|
||||||
|
pref.setSummary(info.summary);
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(app.getValue().disabledDescription)) {
|
if (!TextUtils.isEmpty(app.getValue().disabledDescription)) {
|
||||||
pref.setEnabled(false);
|
pref.setEnabled(false);
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.applications.defaultapps;
|
package com.android.settings.applications.defaultapps;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v7.preference.Preference;
|
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.PackageManagerWrapper;
|
||||||
import com.android.settings.applications.PackageManagerWrapperImpl;
|
import com.android.settings.applications.PackageManagerWrapperImpl;
|
||||||
import com.android.settings.core.PreferenceController;
|
import com.android.settings.core.PreferenceController;
|
||||||
|
import com.android.settings.widget.GearPreference;
|
||||||
|
|
||||||
public abstract class DefaultAppPreferenceController extends PreferenceController {
|
public abstract class DefaultAppPreferenceController extends PreferenceController {
|
||||||
|
|
||||||
@@ -54,8 +56,31 @@ public abstract class DefaultAppPreferenceController extends PreferenceControlle
|
|||||||
preference.setSummary(defaultAppLabel);
|
preference.setSummary(defaultAppLabel);
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "No default app");
|
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();
|
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) {
|
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||||
super.onBindViewHolder(holder);
|
super.onBindViewHolder(holder);
|
||||||
final View gear = holder.findViewById(R.id.settings_button);
|
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.
|
gear.setEnabled(true); // Make gear available even if the preference itself is disabled.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,9 +32,7 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import static org.mockito.Matchers.any;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -77,7 +75,7 @@ public class DefaultAppPreferenceControllerTest {
|
|||||||
|
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
verify(mPreference, never()).setSummary(any(CharSequence.class));
|
verify(mPreference).setSummary(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestPreferenceController extends DefaultAppPreferenceController {
|
private static class TestPreferenceController extends DefaultAppPreferenceController {
|
||||||
|
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.applications.PackageManagerWrapper;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class DefaultAutoFillPickerTest {
|
||||||
|
|
||||||
|
private static final String TEST_APP_KEY = "123";
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Activity mActivity;
|
||||||
|
@Mock
|
||||||
|
private UserManager mUserManager;
|
||||||
|
@Mock
|
||||||
|
private PackageManagerWrapper mPackageManager;
|
||||||
|
private DefaultAutoFillPicker mPicker;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||||
|
mPicker = spy(new DefaultAutoFillPicker());
|
||||||
|
mPicker.onAttach((Context) mActivity);
|
||||||
|
|
||||||
|
ReflectionHelpers.setField(mPicker, "mPm", mPackageManager);
|
||||||
|
|
||||||
|
doReturn(RuntimeEnvironment.application).when(mPicker).getContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setAndGetDefaultAppKey_shouldUpdateDefaultAutoFill() {
|
||||||
|
assertThat(mPicker.setDefaultAppKey(TEST_APP_KEY)).isTrue();
|
||||||
|
assertThat(mPicker.getDefaultAppKey()).isEqualTo(TEST_APP_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getConfirmationMessage_shouldNotBeNull() {
|
||||||
|
final DefaultAppInfo info = mock(DefaultAppInfo.class);
|
||||||
|
when(info.loadLabel(any(PackageManager.class))).thenReturn("test_app_name");
|
||||||
|
assertThat(mPicker.getConfirmationMessage(info)).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* 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.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.applications.PackageManagerWrapper;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class DefaultAutoFillPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private UserManager mUserManager;
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private PackageManagerWrapper mPackageManager;
|
||||||
|
|
||||||
|
private DefaultAutoFillPreferenceController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||||
|
|
||||||
|
mController = spy(new DefaultAutoFillPreferenceController(mContext));
|
||||||
|
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAlwaysAvailable() {
|
||||||
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_hasNoApp_shouldNotReturnLabel() {
|
||||||
|
final Preference pref = mock(Preference.class);
|
||||||
|
|
||||||
|
mController.updateState(pref);
|
||||||
|
verify(pref).setSummary(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getDefaultAppInfo_shouldHaveSettingsProvider() {
|
||||||
|
ReflectionHelpers.setField(mController, "mContext", RuntimeEnvironment.application);
|
||||||
|
Settings.Secure.putString(RuntimeEnvironment.application.getContentResolver(),
|
||||||
|
DefaultAutoFillPicker.SETTING, "com.android.settings/SettingsActivity.class");
|
||||||
|
|
||||||
|
final DefaultAppInfo info = mController.getDefaultAppInfo();
|
||||||
|
|
||||||
|
assertThat(info).isNotNull();
|
||||||
|
|
||||||
|
mController.getSettingIntent(info);
|
||||||
|
|
||||||
|
verify(mPackageManager.getPackageManager()).queryIntentServices(
|
||||||
|
DefaultAutoFillPicker.AUTO_FILL_PROBE, PackageManager.GET_META_DATA);
|
||||||
|
}
|
||||||
|
}
|
@@ -20,7 +20,6 @@ package com.android.settings.applications.defaultapps;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
@@ -32,11 +31,9 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
@@ -39,7 +39,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -77,7 +76,7 @@ public class DefaultBrowserPreferenceControllerTest {
|
|||||||
final Preference pref = mock(Preference.class);
|
final Preference pref = mock(Preference.class);
|
||||||
|
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
verify(pref, never()).setSummary(any(String.class));
|
verify(pref).setSummary(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user