Merge "Fix a11y issues on the DO Disclosures page" into oc-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 59d2d79..4529891 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2933,8 +2933,6 @@
<intent-filter android:priority="60">
<action android:name="com.android.settings.action.SETTINGS" />
</intent-filter>
- <meta-data android:name="com.android.settings.category"
- android:value="com.android.settings.category.ia.system" />
<meta-data android:name="com.android.settings.summary"
android:resource="@string/summary_empty"/>
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 848d2eb..e7d17cb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3933,8 +3933,6 @@
<!-- Summary text for keyboards when no layout has been selected. [CHAR LIMIT=35] -->
<string name="default_keyboard_layout">Default</string>
- <!-- On Languages & input settings screen, heading. Inside the "Languages & input settings" screen, this is the header for settings that relate to mouse and trackpad devices. [CHAR LIMIT=40] -->
- <string name="pointer_settings_category">Mouse/trackpad</string>
<!-- On Languages & input settings screen, setting summary. Setting for mouse pointer speed. [CHAR LIMIT=35] -->
<string name="pointer_speed">Pointer speed</string>
@@ -4845,8 +4843,6 @@
<string name="voice_search_settings_title">Voice search</string>
<!-- Title of keyboard settings list item within voice input/output settings -->
<string name="keyboard_settings_title">Android keyboard</string>
- <!-- Title for the 'voice input' category of voice input/output settings -->
- <string name="voice_category">Speech</string>
<!-- Voice input settings --><skip />
<!-- [CHAR_LIMIT=NONE] Name of the settings item to open the voice input settings. -->
diff --git a/res/xml/development_prefs.xml b/res/xml/development_prefs.xml
index bec8863..0089ed7 100644
--- a/res/xml/development_prefs.xml
+++ b/res/xml/development_prefs.xml
@@ -138,7 +138,7 @@
android:title="@string/wait_for_debugger"
android:summary="@string/wait_for_debugger_summary"/>
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="verify_apps_over_usb"
android:title="@string/verify_apps_over_usb_title"
android:summary="@string/verify_apps_over_usb_summary"/>
diff --git a/res/xml/language_and_input.xml b/res/xml/language_and_input.xml
index 17bd576..ca5ce45 100644
--- a/res/xml/language_and_input.xml
+++ b/res/xml/language_and_input.xml
@@ -97,22 +97,13 @@
</PreferenceCategory>
- <PreferenceCategory
- android:key="pointer_settings_category"
- android:title="@string/pointer_settings_category">
+ <PreferenceCategory>
<com.android.settings.PointerSpeedPreference
android:key="pointer_speed"
android:title="@string/pointer_speed"
android:dialogTitle="@string/pointer_speed"/>
- </PreferenceCategory>
-
- <!-- TTS -->
- <PreferenceCategory
- android:key="voice_category"
- android:title="@string/voice_category">
-
<Preference
android:key="tts_settings"
android:title="@string/tts_settings_title"
diff --git a/res/xml/system_dashboard_fragment.xml b/res/xml/system_dashboard_fragment.xml
index 1186e78..b50d2fd 100644
--- a/res/xml/system_dashboard_fragment.xml
+++ b/res/xml/system_dashboard_fragment.xml
@@ -18,6 +18,16 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/header_category_system">
+ <!-- Backup -->
+ <Preference
+ android:key="backup_settings"
+ android:title="@string/privacy_settings_title"
+ android:summary="@string/summary_placeholder"
+ android:icon="@drawable/ic_settings_backup"
+ android:order="-60">
+ <intent android:action="android.settings.BACKUP_AND_RESET_SETTINGS" />
+ </Preference>
+
<!-- System updates -->
<Preference
android:key="system_update_settings"
diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index 9018d9b..51225aa 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -25,6 +25,7 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -55,7 +56,13 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
- return null;
+ return buildPreferenceControllers(context);
+ }
+
+ private static List<PreferenceController> buildPreferenceControllers(Context context) {
+ final List<PreferenceController> controllers = new ArrayList<>();
+ controllers.add(new SpecialAppAccessPreferenceController(context));
+ return controllers;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
@@ -67,5 +74,10 @@
sir.xmlResId = R.xml.app_and_notification;
return Arrays.asList(sir);
}
+
+ @Override
+ public List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
};
}
diff --git a/src/com/android/settings/applications/AutofillManagerWrapper.java b/src/com/android/settings/applications/AutofillManagerWrapper.java
new file mode 100644
index 0000000..04091b0
--- /dev/null
+++ b/src/com/android/settings/applications/AutofillManagerWrapper.java
@@ -0,0 +1,41 @@
+/*
+ * 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.view.autofill.AutofillManager;
+
+/**
+ * This interface replicates a subset of the android.view.autofill.AutofillManager (AFM). The
+ * interface exists so that we can use a thin wrapper around the AFM in production code and a mock
+ * in tests. We cannot directly mock or shadow the AFM, because some of the methods we rely on are
+ * newer than the API version supported by Robolectric.
+ */
+public interface AutofillManagerWrapper {
+ /**
+ * Calls {@code AutofillManager.hasAutofillFeature()}.
+ *
+ * @see AutofillManager#hasAutofillFeature
+ */
+ public boolean hasAutofillFeature();
+
+ /**
+ * Calls {@code AutofillManager.isAutofillSupported()}.
+ *
+ * @see AutofillManager#isAutofillSupported
+ */
+ public boolean isAutofillSupported();
+}
diff --git a/src/com/android/settings/applications/AutofillManagerWrapperImpl.java b/src/com/android/settings/applications/AutofillManagerWrapperImpl.java
new file mode 100644
index 0000000..9dd1b33
--- /dev/null
+++ b/src/com/android/settings/applications/AutofillManagerWrapperImpl.java
@@ -0,0 +1,45 @@
+/*
+ * 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.view.autofill.AutofillManager;
+
+public class AutofillManagerWrapperImpl implements AutofillManagerWrapper {
+ private final AutofillManager mAfm;
+
+ public AutofillManagerWrapperImpl(AutofillManager afm) {
+ mAfm = afm;
+ }
+
+ @Override
+ public boolean hasAutofillFeature() {
+ if (mAfm == null) {
+ return false;
+ }
+
+ return mAfm.hasAutofillFeature();
+ }
+
+ @Override
+ public boolean isAutofillSupported() {
+ if (mAfm == null) {
+ return false;
+ }
+
+ return mAfm.isAutofillSupported();
+ }
+}
diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java
index c0d2dd8..e9b7481 100755
--- a/src/com/android/settings/applications/InstalledAppDetails.java
+++ b/src/com/android/settings/applications/InstalledAppDetails.java
@@ -526,6 +526,9 @@
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_UNINSTALL:
+ // Refresh option menu
+ getActivity().invalidateOptionsMenu();
+
if (mDisableAfterUninstall) {
mDisableAfterUninstall = false;
new DisableChanger(this, mAppEntry.info,
diff --git a/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java b/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java
new file mode 100644
index 0000000..3735c01
--- /dev/null
+++ b/src/com/android/settings/applications/SpecialAppAccessPreferenceController.java
@@ -0,0 +1,51 @@
+/*
+ * 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.content.Context;
+import android.support.v7.preference.Preference;
+import com.android.settings.R;
+import com.android.settings.core.PreferenceController;
+import com.android.settings.datausage.DataSaverBackend;
+
+public class SpecialAppAccessPreferenceController extends PreferenceController {
+
+ private static final String KEY_SPECIAL_ACCESS = "special_access";
+
+ private DataSaverBackend mDataSaverBackend;
+
+ public SpecialAppAccessPreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_SPECIAL_ACCESS;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ if (mDataSaverBackend == null) {
+ mDataSaverBackend = new DataSaverBackend(mContext);
+ }
+ final int count = mDataSaverBackend.getWhitelistedCount();
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.special_access_summary, count, count));
+ }
+}
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
index 2e79660..5a437db 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPicker.java
@@ -16,6 +16,7 @@
package com.android.settings.applications.defaultapps;
+import android.Manifest;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
@@ -30,6 +31,7 @@
import android.service.autofill.AutofillServiceInfo;
import android.text.Html;
import android.text.TextUtils;
+import android.util.Log;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
@@ -40,6 +42,8 @@
public class DefaultAutofillPicker extends DefaultAppPickerFragment {
+ private static final String TAG = "DefaultAutofillPicker";
+
static final String SETTING = Settings.Secure.AUTOFILL_SERVICE;
static final Intent AUTOFILL_PROBE = new Intent(AutofillService.SERVICE_INTERFACE);
@@ -89,8 +93,13 @@
final List<ResolveInfo> resolveInfos = mPm.getPackageManager()
.queryIntentServices(AUTOFILL_PROBE, PackageManager.GET_META_DATA);
for (ResolveInfo info : resolveInfos) {
- candidates.add(new DefaultAppInfo(mPm, mUserId, new ComponentName(
- info.serviceInfo.packageName, info.serviceInfo.name)));
+ final String permission = info.serviceInfo.permission;
+ // TODO(b/37563972): remove BIND_AUTOFILL once clients use BIND_AUTOFILL_SERVICE
+ if (Manifest.permission.BIND_AUTOFILL_SERVICE.equals(permission)
+ || Manifest.permission.BIND_AUTOFILL.equals(permission)) {
+ candidates.add(new DefaultAppInfo(mPm, mUserId, new ComponentName(
+ info.serviceInfo.packageName, info.serviceInfo.name)));
+ }
}
return candidates;
}
@@ -157,9 +166,15 @@
final String flattenKey = new ComponentName(
serviceInfo.packageName, serviceInfo.name).flattenToString();
if (TextUtils.equals(mSelectedKey, flattenKey)) {
- final String settingsActivity = new AutofillServiceInfo(
- mPackageManager, serviceInfo)
- .getSettingsActivity();
+ final String settingsActivity;
+ try {
+ settingsActivity = new AutofillServiceInfo(mPackageManager, serviceInfo)
+ .getSettingsActivity();
+ } catch (SecurityException e) {
+ // Service does not declare the proper permission, ignore it.
+ Log.w(TAG, "Error getting info for " + serviceInfo + ": " + e);
+ return null;
+ }
if (TextUtils.isEmpty(settingsActivity)) {
return null;
}
diff --git a/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java b/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java
index 161f2df..1fd10ff 100644
--- a/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java
+++ b/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceController.java
@@ -21,16 +21,25 @@
import android.content.Intent;
import android.provider.Settings;
import android.text.TextUtils;
+import android.view.autofill.AutofillManager;
+
+import com.android.settings.applications.AutofillManagerWrapper;
+import com.android.settings.applications.AutofillManagerWrapperImpl;
public class DefaultAutofillPreferenceController extends DefaultAppPreferenceController {
+ private AutofillManagerWrapper mAutofillManager;
public DefaultAutofillPreferenceController(Context context) {
super(context);
+
+ mAutofillManager = new AutofillManagerWrapperImpl(
+ mContext.getSystemService(AutofillManager.class));
}
@Override
public boolean isAvailable() {
- return true;
+ return mAutofillManager.hasAutofillFeature()
+ && mAutofillManager.isAutofillSupported();
}
@Override
diff --git a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
new file mode 100644
index 0000000..8e0f922
--- /dev/null
+++ b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
@@ -0,0 +1,64 @@
+/*
+ * 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.backup;
+
+import android.app.backup.BackupManager;
+import android.content.Context;
+import android.os.Build;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.util.Log;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.core.PreferenceController;
+
+public class BackupSettingsActivityPreferenceController extends PreferenceController {
+ private static final String KEY_BACKUP_SETTINGS = "backup_settings";
+ private static final String TAG = "BackupSettingActivityPC" ;
+
+ private final UserManager mUm;
+ private final BackupManager mBackupManager;
+
+ public BackupSettingsActivityPreferenceController(Context context) {
+ super(context);
+ mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ mBackupManager = new BackupManager(context);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return mUm.isAdminUser();
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BACKUP_SETTINGS;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final boolean backupEnabled = mBackupManager.isBackupEnabled();
+
+ preference.setSummary(backupEnabled
+ ? R.string.accessibility_feature_state_on
+ : R.string.accessibility_feature_state_off);
+ }
+}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index aeb7efb..6a1c06c 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -96,9 +96,7 @@
keys.add(NfcPreferenceController.KEY_TOGGLE_NFC);
keys.add(NfcPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
}
- if (!pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
- keys.add(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
- }
+ keys.add(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
return keys;
}
};
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index 8eb1f61..16172bd 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -75,6 +75,7 @@
private static final String KEY_LIMIT_SUMMARY = "limit_summary";
private static final String KEY_RESTRICT_BACKGROUND = "restrict_background";
private static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
+ private static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
private DataUsageController mDataUsageController;
private DataUsageInfoController mDataInfoController;
@@ -491,6 +492,7 @@
if (hasMobileData) {
keys.add(KEY_RESTRICT_BACKGROUND);
}
+ keys.add(KEY_WIFI_USAGE_TITLE);
return keys;
}
diff --git a/src/com/android/settings/development/DevelopmentSettings.java b/src/com/android/settings/development/DevelopmentSettings.java
index 583a5eb..cf5d3a8 100644
--- a/src/com/android/settings/development/DevelopmentSettings.java
+++ b/src/com/android/settings/development/DevelopmentSettings.java
@@ -40,7 +40,6 @@
import android.content.pm.IShortcutService;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
-import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.hardware.usb.IUsbManager;
import android.hardware.usb.UsbManager;
@@ -140,7 +139,6 @@
private static final String DEBUG_APP_KEY = "debug_app";
private static final String WAIT_FOR_DEBUGGER_KEY = "wait_for_debugger";
private static final String MOCK_LOCATION_APP_KEY = "mock_location_app";
- private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
private static final String DEBUG_VIEW_ATTRIBUTES = "debug_view_attributes";
private static final String FORCE_ALLOW_ON_EXTERNAL_KEY = "force_allow_on_external";
private static final String STRICT_MODE_KEY = "strict_mode";
@@ -226,8 +224,6 @@
private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
- private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
-
private static final String TERMINAL_APP_PACKAGE = "com.android.terminal";
private static final String KEY_CONVERT_FBE = "convert_to_file_encryption";
@@ -275,7 +271,7 @@
private Preference mMockLocationAppPref;
private SwitchPreference mWaitForDebugger;
- private SwitchPreference mVerifyAppsOverUsb;
+ private VerifyAppsOverUsbPreferenceController mVerifyAppsOverUsbController;
private SwitchPreference mWifiDisplayCertification;
private SwitchPreference mWifiVerboseLogging;
private SwitchPreference mWifiAggressiveHandover;
@@ -393,6 +389,7 @@
mBugReportInPowerController = new BugReportInPowerPreferenceController(getActivity());
mTelephonyMonitorController = new TelephonyMonitorPreferenceController(getActivity());
mWebViewAppPrefController = new WebViewAppPreferenceController(getActivity());
+ mVerifyAppsOverUsbController = new VerifyAppsOverUsbPreferenceController(getActivity());
setIfOnlyAvailableForAdmins(true);
if (isUiRestricted() || !Utils.isDeviceProvisioned(getActivity())) {
@@ -453,14 +450,8 @@
mMockLocationAppPref = findPreference(MOCK_LOCATION_APP_KEY);
mAllPrefs.add(mMockLocationAppPref);
- mVerifyAppsOverUsb = findAndInitSwitchPref(VERIFY_APPS_OVER_USB_KEY);
- if (!showVerifierSetting()) {
- if (debugDebuggingCategory != null) {
- debugDebuggingCategory.removePreference(mVerifyAppsOverUsb);
- } else {
- mVerifyAppsOverUsb.setEnabled(false);
- }
- }
+ mVerifyAppsOverUsbController.displayPreference(getPreferenceScreen());
+
mStrictMode = findAndInitSwitchPref(STRICT_MODE_KEY);
mPointerLocation = findAndInitSwitchPref(POINTER_LOCATION_KEY);
mShowTouches = findAndInitSwitchPref(SHOW_TOUCHES_KEY);
@@ -795,7 +786,7 @@
updateImmediatelyDestroyActivitiesOptions();
updateAppProcessLimitOptions();
updateShowAllANRsOptions();
- updateVerifyAppsOverUsbOptions();
+ mVerifyAppsOverUsbController.updatePreference();
updateOtaDisableAutomaticUpdateOptions();
updateBugreportOptions();
updateForceRtlOptions();
@@ -995,19 +986,6 @@
}
}
- private void updateVerifyAppsOverUsbOptions() {
- updateSwitchPreference(mVerifyAppsOverUsb,
- Settings.Global.getInt(getActivity().getContentResolver(),
- Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0);
- mVerifyAppsOverUsb.setEnabled(enableVerifierSetting());
- }
-
- private void writeVerifyAppsOverUsbOptions() {
- Settings.Global.putInt(getActivity().getContentResolver(),
- Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB,
- mVerifyAppsOverUsb.isChecked() ? 1 : 0);
- }
-
private void updateOtaDisableAutomaticUpdateOptions() {
// We use the "disabled status" in code, but show the opposite text
// "Automatic system updates" on screen. So a value 0 indicates the
@@ -1026,31 +1004,6 @@
mOtaDisableAutomaticUpdate.isChecked() ? 0 : 1);
}
- private boolean enableVerifierSetting() {
- final ContentResolver cr = getActivity().getContentResolver();
- if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
- return false;
- }
- if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
- return false;
- } else {
- final PackageManager pm = getActivity().getPackageManager();
- final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
- verification.setType(PACKAGE_MIME_TYPE);
- verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
- if (receivers.size() == 0) {
- return false;
- }
- }
- return true;
- }
-
- private boolean showVerifierSetting() {
- return Settings.Global.getInt(getActivity().getContentResolver(),
- Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
- }
-
private static boolean showEnableOemUnlockPreference() {
return !SystemProperties.get(PERSISTENT_DATA_BLOCK_PROP).equals("");
}
@@ -2417,6 +2370,10 @@
return true;
}
+ if (mVerifyAppsOverUsbController.handlePreferenceTreeClick(preference)) {
+ return true;
+ }
+
if (preference == mEnableAdb) {
if (mEnableAdb.isChecked()) {
mDialogClicked = false;
@@ -2431,8 +2388,7 @@
} else {
Settings.Global.putInt(getActivity().getContentResolver(),
Settings.Global.ADB_ENABLED, 0);
- mVerifyAppsOverUsb.setEnabled(false);
- mVerifyAppsOverUsb.setChecked(false);
+ mVerifyAppsOverUsbController.updatePreference();
updateBugreportOptions();
}
} else if (preference == mClearAdbKeys) {
@@ -2482,8 +2438,6 @@
startActivityForResult(intent, RESULT_DEBUG_APP);
} else if (preference == mWaitForDebugger) {
writeDebuggerOptions();
- } else if (preference == mVerifyAppsOverUsb) {
- writeVerifyAppsOverUsbOptions();
} else if (preference == mOtaDisableAutomaticUpdate) {
writeOtaDisableAutomaticUpdateOptions();
} else if (preference == mStrictMode) {
@@ -2631,8 +2585,7 @@
mDialogClicked = true;
Settings.Global.putInt(getActivity().getContentResolver(),
Settings.Global.ADB_ENABLED, 1);
- mVerifyAppsOverUsb.setEnabled(true);
- updateVerifyAppsOverUsbOptions();
+ mVerifyAppsOverUsbController.updatePreference();
updateBugreportOptions();
} else {
// Reset the toggle
diff --git a/src/com/android/settings/development/VerifyAppsOverUsbPreferenceController.java b/src/com/android/settings/development/VerifyAppsOverUsbPreferenceController.java
new file mode 100644
index 0000000..c0bb0c7
--- /dev/null
+++ b/src/com/android/settings/development/VerifyAppsOverUsbPreferenceController.java
@@ -0,0 +1,149 @@
+/*
+ * 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.development;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.core.PreferenceController;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import java.util.List;
+
+/**
+ * Controller to manage the state of "Verify apps over USB" toggle.
+ */
+public class VerifyAppsOverUsbPreferenceController extends PreferenceController {
+ private static final String VERIFY_APPS_OVER_USB_KEY = "verify_apps_over_usb";
+ private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive";
+
+ private RestrictedSwitchPreference mPreference;
+
+ /**
+ * Class for indirection of RestrictedLockUtils for testing purposes. It would be nice to mock
+ * the appropriate methods in UserManager instead but they aren't accessible.
+ */
+ @VisibleForTesting
+ class RestrictedLockUtilsDelegate {
+ public EnforcedAdmin checkIfRestrictionEnforced(
+ Context context, String userRestriction, int userId) {
+ return RestrictedLockUtils.checkIfRestrictionEnforced(context, userRestriction, userId);
+ }
+ }
+ // NB: This field is accessed using reflection in the test, please keep name in sync.
+ private final RestrictedLockUtilsDelegate mRestrictedLockUtils =
+ new RestrictedLockUtilsDelegate();
+
+ VerifyAppsOverUsbPreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ if (isAvailable()) {
+ mPreference = (RestrictedSwitchPreference)
+ screen.findPreference(VERIFY_APPS_OVER_USB_KEY);
+ }
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return VERIFY_APPS_OVER_USB_KEY;
+ }
+
+ /** Saves the settings value when it is toggled. */
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (VERIFY_APPS_OVER_USB_KEY.equals(preference.getKey())) {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, mPreference.isChecked() ? 1 : 0);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks whether the toggle should be enabled depending on whether verify apps over USB is
+ * possible currently. If ADB is disabled or if package verifier does not exist, the toggle
+ * should be disabled.
+ */
+ private boolean shouldBeEnabled() {
+ final ContentResolver cr = mContext.getContentResolver();
+ if (Settings.Global.getInt(cr, Settings.Global.ADB_ENABLED, 0) == 0) {
+ return false;
+ }
+ if (Settings.Global.getInt(cr, Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) == 0) {
+ return false;
+ } else {
+ final PackageManager pm = mContext.getPackageManager();
+ final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
+ verification.setType(PACKAGE_MIME_TYPE);
+ verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0);
+ if (receivers.size() == 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Updates position, enabled status and maybe admin message.
+ */
+ public void updatePreference() {
+ if (!isAvailable()) {
+ return;
+ }
+
+ if (!shouldBeEnabled()) {
+ mPreference.setChecked(false);
+ mPreference.setDisabledByAdmin(null);
+ mPreference.setEnabled(false);
+ return;
+ }
+
+ final EnforcedAdmin enforcingAdmin = mRestrictedLockUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.ENSURE_VERIFY_APPS, UserHandle.myUserId());
+ if (enforcingAdmin != null) {
+ mPreference.setChecked(true);
+ mPreference.setDisabledByAdmin(enforcingAdmin);
+ return;
+ }
+
+ mPreference.setEnabled(true);
+ final boolean checked = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1) != 0;
+ mPreference.setChecked(checked);
+ }
+}
diff --git a/src/com/android/settings/language/LanguageAndInputSettings.java b/src/com/android/settings/language/LanguageAndInputSettings.java
index 86ce118..1999970 100644
--- a/src/com/android/settings/language/LanguageAndInputSettings.java
+++ b/src/com/android/settings/language/LanguageAndInputSettings.java
@@ -23,6 +23,8 @@
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.speech.tts.TtsEngines;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.text.TextUtils;
import android.view.inputmethod.InputMethodInfo;
@@ -81,7 +83,16 @@
@Override
protected List<PreferenceController> getPreferenceControllers(Context context) {
- final Lifecycle lifecycle = getLifecycle();
+ if (mAmbientDisplayConfig == null) {
+ mAmbientDisplayConfig = new AmbientDisplayConfiguration(context);
+ }
+
+ return buildPreferenceControllers(context, getLifecycle(), mAmbientDisplayConfig);
+ }
+
+ private static List<PreferenceController> buildPreferenceControllers(@NonNull Context context,
+ @Nullable Lifecycle lifecycle,
+ @NonNull AmbientDisplayConfiguration ambientDisplayConfiguration) {
final List<PreferenceController> controllers = new ArrayList<>();
// Language
controllers.add(new PhoneLanguagePreferenceController(context));
@@ -93,11 +104,10 @@
controllers.add(new PhysicalKeyboardPreferenceController(context, lifecycle));
final GameControllerPreferenceController gameControllerPreferenceController
= new GameControllerPreferenceController(context);
- lifecycle.addObserver(gameControllerPreferenceController);
-
- if (mAmbientDisplayConfig == null) {
- mAmbientDisplayConfig = new AmbientDisplayConfiguration(context);
+ if (lifecycle != null) {
+ lifecycle.addObserver(gameControllerPreferenceController);
}
+
controllers.add(gameControllerPreferenceController);
// Gestures
controllers.add(new AssistGesturePreferenceController(context, lifecycle));
@@ -105,9 +115,9 @@
controllers.add(new DoubleTwistPreferenceController(context, lifecycle));
controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle));
controllers.add(new PickupGesturePreferenceController(
- context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId()));
+ context, lifecycle, ambientDisplayConfiguration, UserHandle.myUserId()));
controllers.add(new DoubleTapScreenPreferenceController(
- context, lifecycle, mAmbientDisplayConfig, UserHandle.myUserId()));
+ context, lifecycle, ambientDisplayConfiguration, UserHandle.myUserId()));
controllers.add(new DefaultAutofillPreferenceController(context));
return controllers;
}
@@ -163,5 +173,11 @@
sir.xmlResId = R.xml.language_and_input;
return Arrays.asList(sir);
}
+
+ @Override
+ public List<PreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context, null,
+ new AmbientDisplayConfiguration(context));
+ }
};
}
diff --git a/src/com/android/settings/language/TtsPreferenceController.java b/src/com/android/settings/language/TtsPreferenceController.java
index 9b40b6d..0d1c753 100644
--- a/src/com/android/settings/language/TtsPreferenceController.java
+++ b/src/com/android/settings/language/TtsPreferenceController.java
@@ -18,14 +18,11 @@
import android.content.Context;
import android.speech.tts.TtsEngines;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.PreferenceController;
public class TtsPreferenceController extends PreferenceController {
- private static final String KEY_VOICE_CATEGORY = "voice_category";
private static final String KEY_TTS_SETTINGS = "tts_settings";
private final TtsEngines mTtsEngines;
@@ -41,14 +38,6 @@
}
@Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- if (!isAvailable()) {
- removePreference(screen, KEY_VOICE_CATEGORY);
- }
- }
-
- @Override
public String getPreferenceKey() {
return KEY_TTS_SETTINGS;
}
diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java
index a0ccf20..a28a726 100644
--- a/src/com/android/settings/network/NetworkDashboardFragment.java
+++ b/src/com/android/settings/network/NetworkDashboardFragment.java
@@ -142,5 +142,13 @@
sir.xmlResId = R.xml.network_and_internet;
return Arrays.asList(sir);
}
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ List<String> keys = new ArrayList<>();
+ // Remove master switch as a result
+ keys.add(WifiMasterSwitchPreferenceController.KEY_TOGGLE_WIFI);
+ return keys;
+ }
};
}
diff --git a/src/com/android/settings/system/SystemDashboardFragment.java b/src/com/android/settings/system/SystemDashboardFragment.java
index 76ac4a6..4c4ed21 100644
--- a/src/com/android/settings/system/SystemDashboardFragment.java
+++ b/src/com/android/settings/system/SystemDashboardFragment.java
@@ -21,6 +21,7 @@
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
+import com.android.settings.backup.BackupSettingsActivityPreferenceController;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.deviceinfo.AdditionalSystemUpdatePreferenceController;
@@ -60,6 +61,7 @@
final List<PreferenceController> controllers = new ArrayList<>();
controllers.add(new SystemUpdatePreferenceController(context, UserManager.get(context)));
controllers.add(new AdditionalSystemUpdatePreferenceController(context));
+ controllers.add(new BackupSettingsActivityPreferenceController(context));
return controllers;
}
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index fe2bbb3..5fb6500 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -403,12 +403,13 @@
&& ((mAccessPointSecurity == AccessPoint.SECURITY_WEP
&& mPasswordView.length() == 0)
|| (mAccessPointSecurity == AccessPoint.SECURITY_PSK
- && mPasswordView.length() < 8))) {
+ && (mPasswordView.length() < 8 || mPasswordView.length() > 63)))) {
passwordInvalid = true;
}
-
if ((mSsidView != null && mSsidView.length() == 0)
- || ((mAccessPoint == null || !mAccessPoint.isSaved()) && passwordInvalid)) {
+ || ((mAccessPoint == null || !mAccessPoint.isSaved()) && passwordInvalid
+ // If AccessPoint is saved (we're modifying it), allow zero length (unchanged) pw
+ || mAccessPoint.isSaved() && passwordInvalid && mPasswordView.length() > 0)) {
enabled = false;
} else {
enabled = ipAndProxyFieldsAreValid();
diff --git a/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java b/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java
index d72bb3e..09b3331 100644
--- a/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java
+++ b/src/com/android/settings/wifi/WifiMasterSwitchPreferenceController.java
@@ -33,7 +33,7 @@
implements SummaryUpdater.OnSummaryChangeListener,
LifecycleObserver, OnResume, OnPause, OnStart, OnStop {
- private static final String KEY_TOGGLE_WIFI = "toggle_wifi";
+ public static final String KEY_TOGGLE_WIFI = "toggle_wifi";
private MasterSwitchPreference mWifiPreference;
private WifiEnabler mWifiEnabler;
diff --git a/tests/app/src/com/android/settings/EncryptionInterstitialTest.java b/tests/app/src/com/android/settings/EncryptionInterstitialTest.java
index f30d511..eb61b00 100644
--- a/tests/app/src/com/android/settings/EncryptionInterstitialTest.java
+++ b/tests/app/src/com/android/settings/EncryptionInterstitialTest.java
@@ -93,7 +93,7 @@
Intent mMatchedIntent = null;
@Override
- public ActivityResult onMatchIntent(Intent intent) {
+ public ActivityResult onStartActivity(Intent intent) {
if ("test.unlock.intent".equals(intent.getAction())) {
mMatchedIntent = intent;
return new ActivityResult(Activity.RESULT_OK, null);
diff --git a/tests/robotests/src/com/android/settings/SettingsRobolectricTestRunner.java b/tests/robotests/src/com/android/settings/SettingsRobolectricTestRunner.java
index e063f88..a991e7a 100644
--- a/tests/robotests/src/com/android/settings/SettingsRobolectricTestRunner.java
+++ b/tests/robotests/src/com/android/settings/SettingsRobolectricTestRunner.java
@@ -83,11 +83,11 @@
null));
paths.add(new ResourcePath(
getPackageName(),
- Fs.fileFromPath("./frameworks/opt/setupwizard/library/gingerbread/res"),
+ Fs.fileFromPath("./frameworks/opt/setupwizard/library/eclair-mr1/res"),
null));
paths.add(new ResourcePath(
getPackageName(),
- Fs.fileFromPath("./frameworks/opt/setupwizard/library/recyclerview/res"),
+ Fs.fileFromPath("./frameworks/opt/setupwizard/library/full-support/res"),
null));
paths.add(new ResourcePath(
getPackageName(),
diff --git a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
index 6cf4a59..17910bf 100644
--- a/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/InstalledAppDetailsTest.java
@@ -31,6 +31,7 @@
import android.app.AlertDialog;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
@@ -378,4 +379,13 @@
verify(mockPreferenceScreen, times(1))
.removePreference(mockAppDomainsPref);
}
+
+ @Test
+ public void onActivityResult_uninstalledUpdates_shouldInvalidateOptionsMenu() {
+ doReturn(true).when(mAppDetail).refreshUi();
+
+ mAppDetail.onActivityResult(InstalledAppDetails.REQUEST_UNINSTALL, 0, mock(Intent.class));
+
+ verify(mActivity).invalidateOptionsMenu();
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java
new file mode 100644
index 0000000..44ca9f7
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/SpecialAppAccessPreferenceControllerTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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 static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settings.datausage.DataSaverBackend;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SpecialAppAccessPreferenceControllerTest {
+ private Context mContext;
+ @Mock
+ private DataSaverBackend mBackend;
+ @Mock
+ private Preference mPreference;
+
+ private SpecialAppAccessPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new SpecialAppAccessPreferenceController(mContext);
+ ReflectionHelpers.setField(mController, "mDataSaverBackend", mBackend);
+ }
+
+ @Test
+ public void isAvailable_shouldAlwaysReturnTrue() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void updateState_shouldSetSummary() {
+ when(mBackend.getWhitelistedCount()).thenReturn(0);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(mContext.getResources().getQuantityString(
+ R.plurals.special_access_summary, 0, 0));
+
+ when(mBackend.getWhitelistedCount()).thenReturn(1);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setSummary(mContext.getResources().getQuantityString(
+ R.plurals.special_access_summary, 1, 1));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
index 74612e3..a7912c4 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAutofillPreferenceControllerTest.java
@@ -22,10 +22,12 @@
import android.os.UserManager;
import android.provider.Settings;
import android.support.v7.preference.Preference;
+import android.view.autofill.AutofillManager;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.applications.AutofillManagerWrapper;
import com.android.settings.applications.PackageManagerWrapper;
import org.junit.Before;
@@ -54,6 +56,8 @@
private UserManager mUserManager;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PackageManagerWrapper mPackageManager;
+ @Mock
+ private AutofillManagerWrapper mAutofillManager;
private DefaultAutofillPreferenceController mController;
@@ -64,10 +68,23 @@
mController = spy(new DefaultAutofillPreferenceController(mContext));
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
+ ReflectionHelpers.setField(mController, "mAutofillManager", mAutofillManager);
}
@Test
- public void isAlwaysAvailable() {
+ public void isAvailableIfHasFeatureAndSupported() {
+ when(mContext.getSystemService(AutofillManager.class)).thenReturn(null);
+ assertThat(mController.isAvailable()).isFalse();
+
+ when(mAutofillManager.hasAutofillFeature()).thenReturn(false);
+ assertThat(mController.isAvailable()).isFalse();
+
+ when(mAutofillManager.hasAutofillFeature()).thenReturn(true);
+ when(mAutofillManager.isAutofillSupported()).thenReturn(false);
+ assertThat(mController.isAvailable()).isFalse();
+
+ when(mAutofillManager.hasAutofillFeature()).thenReturn(true);
+ when(mAutofillManager.isAutofillSupported()).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityPreferenceControllerTest.java
new file mode 100644
index 0000000..a58b67d
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityPreferenceControllerTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.backup;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.accounts.AccountManager;
+import android.app.backup.BackupManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.RemoteException;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
+ shadows = {BackupSettingsActivityPreferenceControllerTest.ShadowBackupManager.class})
+public class BackupSettingsActivityPreferenceControllerTest {
+ private static final String KEY_BACKUP_SETTINGS = "backup_settings";
+
+ private Context mContext;
+ @Mock
+ private UserManager mUserManager;
+
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private Preference mBackupPreference;
+
+ private BackupSettingsActivityPreferenceController mController;
+
+ private static boolean mBackupEnabled;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application.getApplicationContext());
+ when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
+
+ mController = new BackupSettingsActivityPreferenceController(mContext);
+ }
+
+ @Test
+ public void updateState_backupOn() throws RemoteException {
+ mBackupEnabled = true;
+
+ mController.updateState(mBackupPreference);
+
+ verify(mBackupPreference).setSummary(R.string.accessibility_feature_state_on);
+ }
+
+ @Test
+ public void updateState_backupOff() throws RemoteException {
+ mBackupEnabled = false;
+
+ mController.updateState(mBackupPreference);
+
+ verify(mBackupPreference).setSummary(R.string.accessibility_feature_state_off);
+ }
+
+ @Test
+ public void isAvailable_systemUser() {
+ when(mUserManager.isAdminUser()).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_nonSystemUser() {
+ when(mUserManager.isAdminUser()).thenReturn(false);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void getPreferenceKey() {
+ assertThat(mController.getPreferenceKey()).isEqualTo(KEY_BACKUP_SETTINGS);
+ }
+
+ @Implements(BackupManager.class)
+ public static class ShadowBackupManager {
+
+ @Implementation
+ public boolean isBackupEnabled() {
+ return mBackupEnabled;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
index a4b5c97..e792845 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
@@ -23,6 +23,7 @@
import com.android.settings.nfc.NfcPreferenceController;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.testutils.XmlTestUtils;
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;
@@ -30,13 +31,12 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -92,20 +92,15 @@
}
@Test
- public void testSearchIndexProvider_NoBluetooth_KeyAdded() {
- when(mManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)).thenReturn(false);
- final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
+ public void testNonIndexableKeys_existInXmlLayout() {
+ final Context context = RuntimeEnvironment.application;
+ when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
+ final List<String> niks = ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
+ .getNonIndexableKeys(context);
+ final int xmlId = (new ConnectedDeviceDashboardFragment()).getPreferenceScreenResId();
- assertThat(keys).isNotNull();
- assertThat(keys).contains(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
- }
+ final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
- @Test
- public void testSearchIndexProvider_Bluetooth_KeyNotAdded() {
- when(mManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)).thenReturn(true);
- final List<String> keys = mFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
-
- assertThat(keys).isNotNull();
- assertThat(keys).doesNotContain(BluetoothMasterSwitchPreferenceController.KEY_TOGGLE_BLUETOOTH);
+ assertThat(keys).containsAllIn(niks);
}
}
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index 71d9ea1..e1572ab 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -25,6 +25,8 @@
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
+import com.android.settings.testutils.XmlTestUtils;
import com.android.settingslib.NetworkPolicyEditor;
import org.junit.Before;
@@ -32,11 +34,13 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
+import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
@@ -143,4 +147,17 @@
policy.metered = false;
assertThat(dataUsageSummary.isMetered(config)).isFalse();
}
+
+ @Test
+ public void testNonIndexableKeys_existInXmlLayout() {
+ final Context context = RuntimeEnvironment.application;
+ final List<String> niks = DataUsageSummary.SEARCH_INDEX_DATA_PROVIDER
+ .getNonIndexableKeys(context);
+ final List<String> keys = new ArrayList<>();
+
+ keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage_wifi));
+ keys.addAll(XmlTestUtils.getKeysFromPreferenceXml(context, R.xml.data_usage));
+
+ assertThat(keys).containsAllIn(niks);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerTest.java
new file mode 100644
index 0000000..d9c17bc
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/VerifyAppsOverUsbPreferenceControllerTest.java
@@ -0,0 +1,179 @@
+/*
+ * 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.development;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.UserManager;
+import android.provider.Settings.Global;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import com.android.settingslib.RestrictedSwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+import java.util.Collections;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class VerifyAppsOverUsbPreferenceControllerTest {
+
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private RestrictedSwitchPreference mPreference;
+
+ @Mock
+ private VerifyAppsOverUsbPreferenceController.RestrictedLockUtilsDelegate
+ mRestrictedLockUtilsDelegate;
+
+ private Context mContext;
+ private VerifyAppsOverUsbPreferenceController mController;
+
+ /** Convenience class for setting global int settings. */
+ class GlobalSetter {
+ public GlobalSetter set(String setting, int value) {
+ Global.putInt(mContext.getContentResolver(), setting, value);
+ return this;
+ }
+ }
+ private final GlobalSetter mGlobals = new GlobalSetter();
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ final ShadowApplication shadowContext = ShadowApplication.getInstance();
+ mContext = spy(shadowContext.getApplicationContext());
+ when(mScreen.findPreference(anyString())).thenReturn(mPreference);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ mController = new VerifyAppsOverUsbPreferenceController(mContext);
+ ReflectionHelpers.setField(
+ mController, "mRestrictedLockUtils", mRestrictedLockUtilsDelegate);
+ }
+
+ private void setupVerifyBroadcastReceivers(boolean nonEmpty) {
+ final List<ResolveInfo> resolveInfos = nonEmpty
+ ? Collections.singletonList(mock(ResolveInfo.class))
+ : Collections.<ResolveInfo>emptyList();
+ when(mPackageManager.queryBroadcastReceivers((Intent) any(), anyInt()))
+ .thenReturn(resolveInfos);
+ }
+
+ private void setupEnforcedAdmin(EnforcedAdmin result) {
+ when(mRestrictedLockUtilsDelegate.checkIfRestrictionEnforced(
+ (Context) any(), anyString(), anyInt())).thenReturn(result);
+ }
+
+ @Test
+ public void updateState_preferenceCheckedWhenSettingIsOn() {
+ setupVerifyBroadcastReceivers(true);
+ setupEnforcedAdmin(null);
+ mGlobals.set(Global.ADB_ENABLED, 1).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
+ mController.displayPreference(mScreen);
+ mController.updatePreference();
+ verify(mPreference).setChecked(true);
+ }
+
+ @Test
+ public void updateState_preferenceUncheckedWhenSettingIsOff() {
+ setupVerifyBroadcastReceivers(true);
+ setupEnforcedAdmin(null);
+ mGlobals.set(Global.ADB_ENABLED, 1).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 0);
+ mController.displayPreference(mScreen);
+ mController.updatePreference();
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void updateState_preferenceUncheckedWhenNoAdb() {
+ setupVerifyBroadcastReceivers(true);
+ setupEnforcedAdmin(null);
+ mGlobals.set(Global.ADB_ENABLED, 0).set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
+ mController.displayPreference(mScreen);
+ mController.updatePreference();
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void updateState_preferenceUncheckedWhenVerifierIsOff() {
+ setupVerifyBroadcastReceivers(true);
+ setupEnforcedAdmin(null);
+ mGlobals.set(Global.ADB_ENABLED, 1)
+ .set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1)
+ .set(Global.PACKAGE_VERIFIER_ENABLE, 0);
+ mController.displayPreference(mScreen);
+ mController.updatePreference();
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void updateState_preferenceUncheckedWhenNoVerifyBroadcastReceivers() {
+ setupVerifyBroadcastReceivers(false);
+ setupEnforcedAdmin(null);
+ mGlobals.set(Global.ADB_ENABLED, 1)
+ .set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
+ mController.displayPreference(mScreen);
+ mController.updatePreference();
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void updateState_preferenceDisabledWhenRestrictedByAdmin() {
+ setupVerifyBroadcastReceivers(true);
+ final EnforcedAdmin admin = new EnforcedAdmin();
+ setupEnforcedAdmin(admin);
+ mGlobals.set(Global.ADB_ENABLED, 1)
+ .set(Global.PACKAGE_VERIFIER_INCLUDE_ADB, 1);
+ mController.displayPreference(mScreen);
+ mController.updatePreference();
+ verify(mPreference).setDisabledByAdmin(admin);
+ }
+
+ @Test
+ public void updateState_preferenceRemovedWhenVerifierSettingsVisibleIsOff() {
+ setupVerifyBroadcastReceivers(true);
+ mGlobals.set(Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 0);
+ when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
+ when(mScreen.getPreferenceCount()).thenReturn(1);
+ when(mScreen.getPreference(anyInt())).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ verify(mScreen).removePreference(mPreference);
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
index 643e305..8c23cbf 100644
--- a/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/language/LanguageAndInputSettingsTest.java
@@ -31,6 +31,7 @@
import android.hardware.input.InputManager;
import android.os.UserManager;
import android.provider.Settings;
+import android.view.autofill.AutofillManager;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.textservice.TextServicesManager;
@@ -72,6 +73,8 @@
private DevicePolicyManager mDpm;
@Mock
private InputMethodManager mInputMethodManager;
+ @Mock
+ private AutofillManager mAutofillManager;
private TestFragment mFragment;
@Before
@@ -84,6 +87,7 @@
.thenReturn(mock(TextServicesManager.class));
when(mContext.getSystemService(Context.DEVICE_POLICY_SERVICE)).thenReturn(mDpm);
when(mContext.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(mImm);
+ when(mContext.getSystemService(AutofillManager.class)).thenReturn(mAutofillManager);
mFragment = new TestFragment(mContext);
}
diff --git a/tests/robotests/src/com/android/settings/language/TtsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/language/TtsPreferenceControllerTest.java
index 31a3f07..4908b49 100644
--- a/tests/robotests/src/com/android/settings/language/TtsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/language/TtsPreferenceControllerTest.java
@@ -38,9 +38,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -94,7 +92,7 @@
mController.displayPreference(mScreen);
- // Remove both category and preference.
- verify(mScreen, times(2)).removePreference(any(Preference.class));
+ // Remove preference.
+ verify(mScreen).removePreference(any(Preference.class));
}
}
diff --git a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
index 2201c68..d1c3207 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java
@@ -15,16 +15,20 @@
*/
package com.android.settings.network;
+import android.content.Context;
import android.provider.SearchIndexableResource;
import android.view.Menu;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
+import com.android.settings.testutils.XmlTestUtils;
import com.android.settingslib.drawer.CategoryKey;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
@@ -74,4 +78,15 @@
verify(resetController).buildMenuItem(any(Menu.class));
}
+ @Test
+ public void testNonIndexableKeys_existInXmlLayout() {
+ final Context context = RuntimeEnvironment.application;
+ final List<String> niks = NetworkDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
+ .getNonIndexableKeys(context);
+ final int xmlId = (new NetworkDashboardFragment()).getPreferenceScreenResId();
+
+ final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
+
+ assertThat(keys).containsAllIn(niks);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
index 6a34472..6175093 100644
--- a/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
+++ b/tests/robotests/src/com/android/settings/search/BaseSearchIndexProviderTest.java
@@ -125,7 +125,7 @@
"key_user_dictionary_settings", "gesture_settings_category", "gesture_assist",
"gesture_swipe_down_fingerprint", "gesture_double_tap_power",
"gesture_double_twist", "gesture_double_tap_screen", "gesture_pick_up",
- "pointer_settings_category", "pointer_speed", "voice_category", "tts_settings",
+ "pointer_speed", "tts_settings",
"game_controller_settings_category", "vibrate_input_devices");
}
diff --git a/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java b/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java
index 20b3f89..f9d5439 100644
--- a/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/XmlTestUtils.java
@@ -53,5 +53,4 @@
return keys;
}
-
-}
+}
\ No newline at end of file