mPackages;
-
- @Override
- public void init() {
- throw new UnsupportedOperationException("Need to call constructor that takes context");
- }
-
- @Override
- public void init(Context context) {
- mPackages = null;
- final Uri providerUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT)
- .authority(AUTHORITY).appendPath(TABLE_PACKAGES).appendPath("*")
- .build();
- try (Cursor cursor = context.getContentResolver().query(providerUri,
- TABLE_PACKAGES_COLUMNS, null, null)) {
- if (cursor == null) {
- Log.w(TAG, "Didn't get cursor for " + providerUri);
- return;
- }
- final int count = cursor.getCount();
- if (count == 0) {
- if (DEBUG) {
- Log.d(TAG, "No packages anymore (was " + mPackages + ")");
- }
- return;
- }
- mPackages = new ArraySet<>(count);
- while (cursor.moveToNext()) {
- mPackages.add(cursor.getString(TABLE_PACKAGES_COL_PACKAGE));
- }
- if (DEBUG) {
- Log.d(TAG, "init(): " + mPackages);
- }
- }
- }
-
-
- @Override
- public boolean filterApp(AppEntry info) {
- return mPackages != null && mPackages.contains(info.info.packageName);
- }
- };
-}
diff --git a/src/com/android/settings/applications/AppStorageSettings.java b/src/com/android/settings/applications/AppStorageSettings.java
index e24a2109f60..c926da38a7b 100644
--- a/src/com/android/settings/applications/AppStorageSettings.java
+++ b/src/com/android/settings/applications/AppStorageSettings.java
@@ -18,13 +18,10 @@ package com.android.settings.applications;
import static android.content.pm.ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract.AUTHORITY;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract.TABLE_PERMISSIONS;
import android.app.ActivityManager;
import android.app.AppGlobals;
import android.app.GrantedUriPermission;
-import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -32,7 +29,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
-import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -461,17 +457,6 @@ public class AppStorageSettings extends AppInfoWithHeader
Context.ACTIVITY_SERVICE);
am.clearGrantedUriPermissions(packageName);
-
- // Also update the Scoped Directory Access UI permissions
- final Uri providerUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT)
- .authority(AUTHORITY).appendPath(TABLE_PERMISSIONS).appendPath("*")
- .build();
- Log.v(TAG, "Asking " + providerUri + " to delete permissions for " + packageName);
- final int deleted = context.getContentResolver().delete(providerUri, null, new String[] {
- packageName
- });
- Log.d(TAG, "Deleted " + deleted + " entries for package " + packageName);
-
// Update UI
refreshGrantedUriPermissions();
}
diff --git a/src/com/android/settings/applications/DirectoryAccessDetails.java b/src/com/android/settings/applications/DirectoryAccessDetails.java
deleted file mode 100644
index f158d81780a..00000000000
--- a/src/com/android/settings/applications/DirectoryAccessDetails.java
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * Copyright (C) 2018 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 android.os.storage.StorageVolume.ScopedAccessProviderContract.AUTHORITY;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract.COL_GRANTED;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract.TABLE_PERMISSIONS;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract
- .TABLE_PERMISSIONS_COLUMNS;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract
- .TABLE_PERMISSIONS_COL_DIRECTORY;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract
- .TABLE_PERMISSIONS_COL_GRANTED;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract
- .TABLE_PERMISSIONS_COL_PACKAGE;
-import static android.os.storage.StorageVolume.ScopedAccessProviderContract
- .TABLE_PERMISSIONS_COL_VOLUME_UUID;
-
-import static com.android.settings.applications.AppStateDirectoryAccessBridge.DEBUG;
-import static com.android.settings.applications.AppStateDirectoryAccessBridge.VERBOSE;
-
-import android.annotation.Nullable;
-import android.app.Activity;
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.storage.StorageManager;
-import android.os.storage.VolumeInfo;
-import android.util.IconDrawableFactory;
-import android.util.Log;
-import android.util.Pair;
-
-import androidx.appcompat.app.AlertDialog;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
-import androidx.preference.SwitchPreference;
-
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.R;
-import com.android.settings.widget.EntityHeaderController;
-import com.android.settings.widget.EntityHeaderController.ActionType;
-import com.android.settingslib.applications.AppUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Detailed settings for an app's directory access permissions (A.K.A Scoped Directory Access).
- *
- * Currently, it shows the entry for which the user denied access with the "Do not ask again"
- * flag checked on: the user than can use the settings toggle to reset that deniel.
- *
- *
This fragments dynamically lists all such permissions, starting with one preference per
- * directory in the primary storage, then adding additional entries for the external volumes (one
- * entry for the whole volume).
- */
-// TODO(b/72055774): add unit tests
-public class DirectoryAccessDetails extends AppInfoBase {
-
- @SuppressWarnings("hiding")
- private static final String TAG = "DirectoryAccessDetails";
-
- private boolean mCreated;
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
-
- if (mCreated) {
- Log.w(TAG, "onActivityCreated(): ignoring duplicate call");
- return;
- }
- mCreated = true;
- if (mPackageInfo == null) {
- Log.w(TAG, "onActivityCreated(): no package info");
- return;
- }
- final Activity activity = getActivity();
- final Preference pref = EntityHeaderController
- .newInstance(activity, this, /* header= */ null )
- .setRecyclerView(getListView(), getSettingsLifecycle())
- .setIcon(IconDrawableFactory.newInstance(getPrefContext())
- .getBadgedIcon(mPackageInfo.applicationInfo))
- .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
- .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
- .setPackageName(mPackageName)
- .setUid(mPackageInfo.applicationInfo.uid)
- .setHasAppInfoLink(false)
- .setButtonActions(ActionType.ACTION_NONE, ActionType.ACTION_NONE)
- .done(activity, getPrefContext());
- getPreferenceScreen().addPreference(pref);
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- addPreferencesFromResource(R.xml.directory_access_details);
-
- }
-
- @Override
- protected boolean refreshUi() {
- final Context context = getPrefContext();
- final PreferenceScreen prefsGroup = getPreferenceScreen();
- prefsGroup.removeAll();
-
- final Map externalVolumes = new HashMap<>();
-
- final Uri providerUri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT)
- .authority(AUTHORITY).appendPath(TABLE_PERMISSIONS).appendPath("*")
- .build();
- // Query provider for entries.
- try (Cursor cursor = context.getContentResolver().query(providerUri,
- TABLE_PERMISSIONS_COLUMNS, null, new String[] { mPackageName }, null)) {
- if (cursor == null) {
- Log.w(TAG, "Didn't get cursor for " + mPackageName);
- return true;
- }
- final int count = cursor.getCount();
- if (count == 0) {
- // This setting screen should not be reached if there was no permission, so just
- // ignore it
- Log.w(TAG, "No permissions for " + mPackageName);
- return true;
- }
-
- while (cursor.moveToNext()) {
- final String pkg = cursor.getString(TABLE_PERMISSIONS_COL_PACKAGE);
- final String uuid = cursor.getString(TABLE_PERMISSIONS_COL_VOLUME_UUID);
- final String dir = cursor.getString(TABLE_PERMISSIONS_COL_DIRECTORY);
- final boolean granted = cursor.getInt(TABLE_PERMISSIONS_COL_GRANTED) == 1;
- if (VERBOSE) {
- Log.v(TAG, "Pkg:" + pkg + " uuid: " + uuid + " dir: " + dir
- + " granted:" + granted);
- }
-
- if (!mPackageName.equals(pkg)) {
- // Sanity check, shouldn't happen
- Log.w(TAG, "Ignoring " + uuid + "/" + dir + " due to package mismatch: "
- + "expected " + mPackageName + ", got " + pkg);
- continue;
- }
-
- if (uuid == null) {
- if (dir == null) {
- // Sanity check, shouldn't happen
- Log.wtf(TAG, "Ignoring permission on primary storage root");
- } else {
- // Primary storage entry: add right away
- prefsGroup.addPreference(newPreference(context, dir, providerUri,
- /* uuid= */ null, dir, granted, /* children= */ null));
- }
- } else {
- // External volume entry: save it for later.
- ExternalVolume externalVolume = externalVolumes.get(uuid);
- if (externalVolume == null) {
- externalVolume = new ExternalVolume(uuid);
- externalVolumes.put(uuid, externalVolume);
- }
- if (dir == null) {
- // Whole volume
- externalVolume.granted = granted;
- } else {
- // Directory only
- externalVolume.children.add(new Pair<>(dir, granted));
- }
- }
- }
- }
-
- if (VERBOSE) {
- Log.v(TAG, "external volumes: " + externalVolumes);
- }
-
- if (externalVolumes.isEmpty()) {
- // We're done!
- return true;
- }
-
- // Add entries from external volumes
-
- // Query StorageManager to get the user-friendly volume names.
- final StorageManager sm = context.getSystemService(StorageManager.class);
- final List volumes = sm.getVolumes();
- if (volumes.isEmpty()) {
- Log.w(TAG, "StorageManager returned no secondary volumes");
- return true;
- }
- final Map volumeNames = new HashMap<>(volumes.size());
- for (VolumeInfo volume : volumes) {
- final String uuid = volume.getFsUuid();
- if (uuid == null) continue; // Primary storage; not used.
-
- String name = sm.getBestVolumeDescription(volume);
- if (name == null) {
- Log.w(TAG, "No description for " + volume + "; using uuid instead: " + uuid);
- name = uuid;
- }
- volumeNames.put(uuid, name);
- }
- if (VERBOSE) {
- Log.v(TAG, "UUID -> name mapping: " + volumeNames);
- }
-
- for (ExternalVolume volume : externalVolumes.values()) {
- final String volumeName = volumeNames.get(volume.uuid);
- if (volumeName == null) {
- Log.w(TAG, "Ignoring entry for invalid UUID: " + volume.uuid);
- continue;
- }
- // First add the pref for the whole volume...
- final PreferenceCategory category = new PreferenceCategory(context);
- prefsGroup.addPreference(category);
- final Set children = new HashSet<>(volume.children.size());
- category.addPreference(newPreference(context, volumeName, providerUri, volume.uuid,
- /* dir= */ null, volume.granted, children));
-
- // ... then the children prefs
- volume.children.forEach((pair) -> {
- final String dir = pair.first;
- final String name = context.getResources()
- .getString(R.string.directory_on_volume, volumeName, dir);
- final SwitchPreference childPref =
- newPreference(context, name, providerUri, volume.uuid, dir, pair.second,
- /* children= */ null);
- category.addPreference(childPref);
- children.add(childPref);
- });
- }
- return true;
- }
-
- private SwitchPreference newPreference(Context context, String title, Uri providerUri,
- String uuid, String dir, boolean granted, @Nullable Set children) {
- final SwitchPreference pref = new SwitchPreference(context);
- pref.setKey(String.format("%s:%s", uuid, dir));
- pref.setTitle(title);
- pref.setChecked(granted);
- pref.setOnPreferenceChangeListener((unused, value) -> {
- if (!Boolean.class.isInstance(value)) {
- // Sanity check
- Log.wtf(TAG, "Invalid value from switch: " + value);
- return true;
- }
- final boolean newValue = ((Boolean) value).booleanValue();
-
- resetDoNotAskAgain(context, newValue, providerUri, uuid, dir);
- if (children != null) {
- // When parent is granted, children should be hidden; and vice versa
- final boolean newChildValue = !newValue;
- for (SwitchPreference child : children) {
- child.setVisible(newChildValue);
- }
- }
- return true;
- });
- return pref;
- }
-
- private void resetDoNotAskAgain(Context context, boolean newValue, Uri providerUri,
- @Nullable String uuid, @Nullable String directory) {
- if (DEBUG) {
- Log.d(TAG, "Asking " + providerUri + " to update " + uuid + "/" + directory + " to "
- + newValue);
- }
- final ContentValues values = new ContentValues(1);
- values.put(COL_GRANTED, newValue);
- final int updated = context.getContentResolver().update(providerUri, values,
- null, new String[] { mPackageName, uuid, directory });
- if (DEBUG) {
- Log.d(TAG, "Updated " + updated + " entries for " + uuid + "/" + directory);
- }
- }
-
- @Override
- protected AlertDialog createDialog(int id, int errorCode) {
- return null;
- }
-
- @Override
- public int getMetricsCategory() {
- return MetricsEvent.APPLICATIONS_DIRECTORY_ACCESS_DETAIL;
- }
-
- private static class ExternalVolume {
- final String uuid;
- final List> children = new ArrayList<>();
- boolean granted;
-
- ExternalVolume(String uuid) {
- this.uuid = uuid;
- }
-
- @Override
- public String toString() {
- return "ExternalVolume: [uuid=" + uuid + ", granted=" + granted +
- ", children=" + children + "]";
- }
- }
-}
diff --git a/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceController.java b/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceController.java
index c86117503fd..5f41ae0afeb 100644
--- a/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceController.java
@@ -90,12 +90,9 @@ public class AppHeaderViewPreferenceController extends BasePreferenceController
private void setAppLabelAndIcon(PackageInfo pkgInfo, AppEntry appEntry) {
final Activity activity = mParent.getActivity();
final boolean isInstantApp = AppUtils.isInstant(pkgInfo.applicationInfo);
- final CharSequence summary = isInstantApp
- ? null : mContext.getString(Utils.getInstallationStatus(appEntry.info));
mEntityHeaderController
.setLabel(appEntry)
.setIcon(appEntry)
- .setSummary(summary)
.setIsInstantApp(isInstantApp)
.done(activity, false /* rebindActions */);
}
diff --git a/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java b/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
index 7d1e159ffe0..0d2bcab3129 100644
--- a/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
+++ b/src/com/android/settings/applications/manageapplications/AppFilterRegistry.java
@@ -19,7 +19,6 @@ package com.android.settings.applications.manageapplications;
import androidx.annotation.IntDef;
import com.android.settings.R;
-import com.android.settings.applications.AppStateDirectoryAccessBridge;
import com.android.settings.applications.AppStateInstallAppsBridge;
import com.android.settings.applications.AppStateNotificationBridge;
import com.android.settings.applications.AppStateOverlayBridge;
@@ -70,7 +69,6 @@ public class AppFilterRegistry {
public static final int FILTER_APPS_WITH_OVERLAY = 11;
public static final int FILTER_APPS_WRITE_SETTINGS = 12;
public static final int FILTER_APPS_INSTALL_SOURCES = 13;
- public static final int FILTER_APP_HAS_DIRECTORY_ACCESS = 14;
public static final int FILTER_APP_CAN_CHANGE_WIFI_STATE = 15;
public static final int FILTER_APPS_BLOCKED = 16;
// Next id: 17
@@ -170,12 +168,6 @@ public class AppFilterRegistry {
FILTER_APPS_INSTALL_SOURCES,
R.string.filter_install_sources_apps);
- // Apps that interacted with directory access permissions (A.K.A. Scoped Directory Access)
- mFilters[FILTER_APP_HAS_DIRECTORY_ACCESS] = new AppFilterItem(
- AppStateDirectoryAccessBridge.FILTER_APP_HAS_DIRECTORY_ACCESS,
- FILTER_APP_HAS_DIRECTORY_ACCESS,
- R.string.filter_install_sources_apps);
-
mFilters[FILTER_APP_CAN_CHANGE_WIFI_STATE] = new AppFilterItem(
AppStateChangeWifiStateBridge.FILTER_CHANGE_WIFI_STATE,
FILTER_APP_CAN_CHANGE_WIFI_STATE,
@@ -208,8 +200,6 @@ public class AppFilterRegistry {
return FILTER_APPS_WRITE_SETTINGS;
case ManageApplications.LIST_TYPE_MANAGE_SOURCES:
return FILTER_APPS_INSTALL_SOURCES;
- case ManageApplications.LIST_TYPE_DIRECTORY_ACCESS:
- return FILTER_APP_HAS_DIRECTORY_ACCESS;
case ManageApplications.LIST_TYPE_WIFI_ACCESS:
return FILTER_APP_CAN_CHANGE_WIFI_STATE;
case ManageApplications.LIST_TYPE_NOTIFICATION:
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index 44ea575a825..6b2fb916b1b 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -90,7 +90,6 @@ import com.android.settings.SettingsActivity;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
import com.android.settings.applications.AppStateBaseBridge;
-import com.android.settings.applications.AppStateDirectoryAccessBridge;
import com.android.settings.applications.AppStateInstallAppsBridge;
import com.android.settings.applications.AppStateNotificationBridge;
import com.android.settings.applications.AppStateNotificationBridge.NotificationsSentState;
@@ -101,7 +100,6 @@ import com.android.settings.applications.AppStateUsageBridge.UsageState;
import com.android.settings.applications.AppStateWriteSettingsBridge;
import com.android.settings.applications.AppStorageSettings;
import com.android.settings.applications.DefaultAppSettings;
-import com.android.settings.applications.DirectoryAccessDetails;
import com.android.settings.applications.InstalledAppCounter;
import com.android.settings.applications.UsageAccessDetails;
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
@@ -218,7 +216,6 @@ public class ManageApplications extends InstrumentedFragment
public static final int LIST_TYPE_GAMES = 9;
public static final int LIST_TYPE_MOVIES = 10;
public static final int LIST_TYPE_PHOTOGRAPHY = 11;
- public static final int LIST_TYPE_DIRECTORY_ACCESS = 12;
public static final int LIST_TYPE_WIFI_ACCESS = 13;
// List types that should show instant apps.
@@ -293,9 +290,6 @@ public class ManageApplications extends InstrumentedFragment
mListType = LIST_TYPE_PHOTOGRAPHY;
mSortOrder = R.id.sort_order_size;
mStorageType = args.getInt(EXTRA_STORAGE_TYPE, STORAGE_TYPE_DEFAULT);
- } else if (className.equals(Settings.DirectoryAccessSettingsActivity.class.getName())) {
- mListType = LIST_TYPE_DIRECTORY_ACCESS;
- screenTitle = R.string.directory_access;
} else if (className.equals(Settings.ChangeWifiStateActivity.class.getName())) {
mListType = LIST_TYPE_WIFI_ACCESS;
screenTitle = R.string.change_wifi_state_title;
@@ -479,8 +473,6 @@ public class ManageApplications extends InstrumentedFragment
return MetricsEvent.SYSTEM_ALERT_WINDOW_APPS;
case LIST_TYPE_MANAGE_SOURCES:
return MetricsEvent.MANAGE_EXTERNAL_SOURCES;
- case LIST_TYPE_DIRECTORY_ACCESS:
- return MetricsEvent.DIRECTORY_ACCESS;
case LIST_TYPE_WIFI_ACCESS:
return MetricsEvent.CONFIGURE_WIFI;
default:
@@ -578,9 +570,6 @@ public class ManageApplications extends InstrumentedFragment
case LIST_TYPE_PHOTOGRAPHY:
startAppInfoFragment(AppStorageSettings.class, R.string.storage_photos_videos);
break;
- case LIST_TYPE_DIRECTORY_ACCESS:
- startAppInfoFragment(DirectoryAccessDetails.class, R.string.directory_access);
- break;
case LIST_TYPE_WIFI_ACCESS:
startAppInfoFragment(ChangeWifiStateDetails.class,
R.string.change_wifi_state_title);
@@ -916,8 +905,6 @@ public class ManageApplications extends InstrumentedFragment
mExtraInfoBridge = new AppStateWriteSettingsBridge(mContext, mState, this);
} else if (mManageApplications.mListType == LIST_TYPE_MANAGE_SOURCES) {
mExtraInfoBridge = new AppStateInstallAppsBridge(mContext, mState, this);
- } else if (mManageApplications.mListType == LIST_TYPE_DIRECTORY_ACCESS) {
- mExtraInfoBridge = new AppStateDirectoryAccessBridge(mState, this);
} else if (mManageApplications.mListType == LIST_TYPE_WIFI_ACCESS) {
mExtraInfoBridge = new AppStateChangeWifiStateBridge(mContext, mState, this);
} else {
@@ -1360,9 +1347,6 @@ public class ManageApplications extends InstrumentedFragment
case LIST_TYPE_MANAGE_SOURCES:
holder.setSummary(ExternalSourcesDetails.getPreferenceSummary(mContext, entry));
break;
- case LIST_TYPE_DIRECTORY_ACCESS:
- holder.setSummary(null);
- break;
case LIST_TYPE_WIFI_ACCESS:
holder.setSummary(ChangeWifiStateDetails.getSummary(mContext, entry));
break;
diff --git a/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
index 5c678a95c34..54842f71f81 100644
--- a/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
@@ -74,7 +74,6 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
final List controllers = new ArrayList<>();
controllers.add(new BluetoothFilesPreferenceController(context));
- controllers.add(new BluetoothOnWhileDrivingPreferenceController(context));
final PrintSettingPreferenceController printerController =
new PrintSettingPreferenceController(context);
diff --git a/src/com/android/settings/connecteddevice/BluetoothOnWhileDrivingPreferenceController.java b/src/com/android/settings/connecteddevice/BluetoothOnWhileDrivingPreferenceController.java
deleted file mode 100644
index 6d4e8b848b1..00000000000
--- a/src/com/android/settings/connecteddevice/BluetoothOnWhileDrivingPreferenceController.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2018 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.connecteddevice;
-
-import android.content.Context;
-import android.provider.Settings;
-import android.util.FeatureFlagUtils;
-
-import com.android.settings.core.FeatureFlags;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settings.core.TogglePreferenceController;
-
-/** Handles a toggle for a setting to turn on Bluetooth while driving. * */
-public class BluetoothOnWhileDrivingPreferenceController extends TogglePreferenceController
- implements PreferenceControllerMixin {
- static final String KEY_BLUETOOTH_ON_DRIVING = "bluetooth_on_while_driving";
-
- public BluetoothOnWhileDrivingPreferenceController(Context context) {
- super(context, KEY_BLUETOOTH_ON_DRIVING);
- }
-
- @Override
- public int getAvailabilityStatus() {
- if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.BLUETOOTH_WHILE_DRIVING)) {
- return AVAILABLE;
- }
- return CONDITIONALLY_UNAVAILABLE;
- }
-
- @Override
- public boolean isChecked() {
- return Settings.Secure.getInt(
- mContext.getContentResolver(),
- Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING,
- 0)
- != 0;
- }
-
- @Override
- public boolean setChecked(boolean isChecked) {
- final int value = isChecked ? 1 : 0;
- return Settings.Secure.putInt(
- mContext.getContentResolver(), Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING, value);
- }
-}
diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java
index 811f7ade83f..0a26b79c93d 100644
--- a/src/com/android/settings/core/FeatureFlags.java
+++ b/src/com/android/settings/core/FeatureFlags.java
@@ -20,7 +20,6 @@ package com.android.settings.core;
* This class keeps track of all feature flags in Settings.
*/
public class FeatureFlags {
- public static final String BLUETOOTH_WHILE_DRIVING = "settings_bluetooth_while_driving";
public static final String AUDIO_SWITCHER_SETTINGS = "settings_audio_switcher";
public static final String DYNAMIC_HOMEPAGE = "settings_dynamic_homepage";
public static final String HEARING_AID_SETTINGS = "settings_bluetooth_hearing_aid";
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 434697359bb..f61cb0c464d 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -34,7 +34,6 @@ import com.android.settings.accounts.ChooseAccountFragment;
import com.android.settings.accounts.ManagedProfileSettings;
import com.android.settings.applications.AppAndNotificationDashboardFragment;
import com.android.settings.applications.DefaultAppSettings;
-import com.android.settings.applications.DirectoryAccessDetails;
import com.android.settings.applications.ProcessStatsSummary;
import com.android.settings.applications.ProcessStatsUi;
import com.android.settings.applications.UsageAccessDetails;
@@ -258,7 +257,6 @@ public class SettingsGateway {
LockscreenDashboardFragment.class.getName(),
BluetoothDeviceDetailsFragment.class.getName(),
DataUsageList.class.getName(),
- DirectoryAccessDetails.class.getName(),
ToggleBackupSettingFragment.class.getName(),
PreviouslyConnectedDeviceDashboardFragment.class.getName(),
};
diff --git a/src/com/android/settings/development/DesktopModePreferenceController.java b/src/com/android/settings/development/DesktopModePreferenceController.java
new file mode 100644
index 00000000000..528af8aee80
--- /dev/null
+++ b/src/com/android/settings/development/DesktopModePreferenceController.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2018 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 android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS;
+
+import android.content.Context;
+import android.os.Build;
+import android.provider.Settings;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+public class DesktopModePreferenceController extends DeveloperOptionsPreferenceController
+ implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
+
+ private static final String FORCE_DESKTOP_MODE_KEY = "force_desktop_mode_on_external_displays";
+
+ @VisibleForTesting
+ static final int SETTING_VALUE_OFF = 0;
+ @VisibleForTesting
+ static final int SETTING_VALUE_ON = 1;
+
+ public DesktopModePreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return FORCE_DESKTOP_MODE_KEY;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean isEnabled = (Boolean) newValue;
+ Settings.Global.putInt(mContext.getContentResolver(),
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS,
+ isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF);
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, SETTING_VALUE_OFF);
+ ((SwitchPreference) mPreference).setChecked(mode != SETTING_VALUE_OFF);
+ }
+
+ @Override
+ protected void onDeveloperOptionsSwitchDisabled() {
+ super.onDeveloperOptionsSwitchDisabled();
+ Settings.Global.putInt(mContext.getContentResolver(),
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, SETTING_VALUE_OFF);
+ ((SwitchPreference) mPreference).setChecked(false);
+ }
+
+ @VisibleForTesting
+ String getBuildType() {
+ return Build.TYPE;
+ }
+}
diff --git a/src/com/android/settings/development/DevelopmentOptionsActivityRequestCodes.java b/src/com/android/settings/development/DevelopmentOptionsActivityRequestCodes.java
index 6e3ec9323c5..3532a155c5f 100644
--- a/src/com/android/settings/development/DevelopmentOptionsActivityRequestCodes.java
+++ b/src/com/android/settings/development/DevelopmentOptionsActivityRequestCodes.java
@@ -27,4 +27,6 @@ public interface DevelopmentOptionsActivityRequestCodes {
int REQUEST_MOCK_LOCATION_APP = 2;
int REQUEST_CODE_ANGLE_ENABLED_APP = 3;
+
+ int REQUEST_CODE_UPDATED_GFX_DRIVER_DEV_OPT_IN_APP = 4;
}
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index 82c98288973..0fcf6aa6e9e 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -406,6 +406,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new WaitForDebuggerPreferenceController(context));
controllers.add(new EnableGpuDebugLayersPreferenceController(context));
controllers.add(new AngleEnabledAppPreferenceController(context, fragment));
+ controllers.add(new UpdatedGfxDriverDevOptInPreferenceController(context, fragment));
controllers.add(new VerifyAppsOverUsbPreferenceController(context));
controllers.add(new LogdSizePreferenceController(context));
controllers.add(new LogPersistPreferenceController(context, fragment, lifecycle));
@@ -458,6 +459,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new AllowAppsOnExternalPreferenceController(context));
controllers.add(new ResizableActivityPreferenceController(context));
controllers.add(new FreeformWindowsPreferenceController(context));
+ controllers.add(new DesktopModePreferenceController(context));
controllers.add(new SmsAccessRestrictionPreferenceController(context));
controllers.add(new ShortcutManagerThrottlingPreferenceController(context));
controllers.add(new EnableGnssRawMeasFullTrackingPreferenceController(context));
diff --git a/src/com/android/settings/development/FreeformWindowsPreferenceController.java b/src/com/android/settings/development/FreeformWindowsPreferenceController.java
index 5b19f36c152..4d384809464 100644
--- a/src/com/android/settings/development/FreeformWindowsPreferenceController.java
+++ b/src/com/android/settings/development/FreeformWindowsPreferenceController.java
@@ -19,7 +19,6 @@ package com.android.settings.development;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
-import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -37,18 +36,11 @@ public class FreeformWindowsPreferenceController extends DeveloperOptionsPrefere
static final int SETTING_VALUE_OFF = 0;
@VisibleForTesting
static final int SETTING_VALUE_ON = 1;
- @VisibleForTesting
- static final String USER_BUILD_TYPE = "user";
public FreeformWindowsPreferenceController(Context context) {
super(context);
}
- @Override
- public boolean isAvailable() {
- return !TextUtils.equals(USER_BUILD_TYPE, getBuildType());
- }
-
@Override
public String getPreferenceKey() {
return ENABLE_FREEFORM_SUPPORT_KEY;
diff --git a/src/com/android/settings/development/UpdatedGfxDriverDevOptInPreferenceController.java b/src/com/android/settings/development/UpdatedGfxDriverDevOptInPreferenceController.java
new file mode 100644
index 00000000000..ad2131efaac
--- /dev/null
+++ b/src/com/android/settings/development/UpdatedGfxDriverDevOptInPreferenceController.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2018 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 com.android.settings.development.DevelopmentOptionsActivityRequestCodes
+ .REQUEST_CODE_UPDATED_GFX_DRIVER_DEV_OPT_IN_APP;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.provider.Settings;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+// TODO(b/119221883): Need to override isAvailable() to return false when updatable graphics driver is not supported.
+public class UpdatedGfxDriverDevOptInPreferenceController
+ extends DeveloperOptionsPreferenceController
+ implements PreferenceControllerMixin, OnActivityResultListener {
+
+ private static final String UPDATED_GFX_DRIVER_DEV_OPT_IN_APP_KEY =
+ "updated_gfx_driver_dev_opt_in_app";
+
+ private final DevelopmentSettingsDashboardFragment mFragment;
+ private final PackageManager mPackageManager;
+
+ public UpdatedGfxDriverDevOptInPreferenceController(Context context,
+ DevelopmentSettingsDashboardFragment fragment) {
+ super(context);
+ mFragment = fragment;
+ mPackageManager = mContext.getPackageManager();
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return UPDATED_GFX_DRIVER_DEV_OPT_IN_APP_KEY;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (UPDATED_GFX_DRIVER_DEV_OPT_IN_APP_KEY.equals(preference.getKey())) {
+ // pass it on to settings
+ final Intent intent = getActivityStartIntent();
+ mFragment.startActivityForResult(intent,
+ REQUEST_CODE_UPDATED_GFX_DRIVER_DEV_OPT_IN_APP);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ updatePreferenceSummary();
+ }
+
+ @Override
+ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode != REQUEST_CODE_UPDATED_GFX_DRIVER_DEV_OPT_IN_APP
+ || resultCode != Activity.RESULT_OK) {
+ return false;
+ }
+ Settings.Global.putString(mContext.getContentResolver(),
+ Settings.Global.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP, data.getAction());
+ updatePreferenceSummary();
+ return true;
+ }
+
+ @Override
+ protected void onDeveloperOptionsSwitchDisabled() {
+ super.onDeveloperOptionsSwitchDisabled();
+ mPreference.setSummary(mContext.getResources().getString(
+ R.string.updated_gfx_driver_dev_opt_in_app_not_set));
+ }
+
+ @VisibleForTesting
+ Intent getActivityStartIntent() {
+ Intent intent = new Intent(mContext, AppPicker.class);
+ intent.putExtra(AppPicker.EXTRA_NON_SYSTEM, true /* value */);
+ return intent;
+ }
+
+ private void updatePreferenceSummary() {
+ final String updatedGfxDriverDevOptInApp = Settings.Global.getString(
+ mContext.getContentResolver(), Settings.Global.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP);
+ if (updatedGfxDriverDevOptInApp != null && !updatedGfxDriverDevOptInApp.isEmpty()) {
+ mPreference.setSummary(mContext.getResources().getString(
+ R.string.updated_gfx_driver_dev_opt_in_app_set,
+ getAppLabel(updatedGfxDriverDevOptInApp)));
+ } else {
+ mPreference.setSummary(mContext.getResources().getString(
+ R.string.updated_gfx_driver_dev_opt_in_app_not_set));
+ }
+ }
+
+ private String getAppLabel(String applicationPackageName) {
+ try {
+ final ApplicationInfo ai = mPackageManager.getApplicationInfo(applicationPackageName,
+ PackageManager.GET_DISABLED_COMPONENTS);
+ final CharSequence lab = mPackageManager.getApplicationLabel(ai);
+ return lab != null ? lab.toString() : applicationPackageName;
+ } catch (PackageManager.NameNotFoundException e) {
+ return applicationPackageName;
+ }
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java b/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java
index 25090dce0eb..a9d0e3fe352 100644
--- a/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java
@@ -79,12 +79,7 @@ public class DeviceModelPreferenceController extends BasePreferenceController {
}
public static String getDeviceModel() {
- FutureTask msvSuffixTask = new FutureTask(new Callable() {
- @Override
- public String call() {
- return DeviceInfoUtils.getMsvSuffix();
- }
- });
+ FutureTask msvSuffixTask = new FutureTask<>(() -> DeviceInfoUtils.getMsvSuffix());
msvSuffixTask.run();
try {
diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
index 37f80b736ea..8c6c5aea0c9 100644
--- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
+++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
@@ -181,25 +181,6 @@ public class MyDeviceInfoFragment extends DashboardFragment
controller.updateDeviceName(confirm);
}
- private static class SummaryProvider implements SummaryLoader.SummaryProvider {
-
- private final SummaryLoader mSummaryLoader;
-
- public SummaryProvider(SummaryLoader summaryLoader) {
- mSummaryLoader = summaryLoader;
- }
-
- @Override
- public void setListening(boolean listening) {
- if (listening) {
- mSummaryLoader.setSummary(this, DeviceModelPreferenceController.getDeviceModel());
- }
- }
- }
-
- public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
- = (activity, summaryLoader) -> new SummaryProvider(summaryLoader);
-
/**
* For Search.
*/
diff --git a/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceController.java b/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceController.java
new file mode 100644
index 00000000000..ba28f3a1b48
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceController.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2018 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.deviceinfo.aboutphone;
+
+import android.content.Context;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.deviceinfo.DeviceModelPreferenceController;
+
+public class TopLevelAboutDevicePreferenceController extends BasePreferenceController {
+
+ public TopLevelAboutDevicePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return DeviceModelPreferenceController.getDeviceModel();
+ }
+}
diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
index 5ca8fea802a..5bdf5873cf5 100644
--- a/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
+++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialogHelper.java
@@ -23,6 +23,8 @@ import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.res.ColorStateList;
+import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Process;
import android.os.UserHandle;
@@ -109,16 +111,24 @@ public class ActionDisabledByAdminDialogHelper {
if (admin == null) {
return;
}
+ ImageView supportIconView = root.requireViewById(R.id.admin_support_icon);
if (!RestrictedLockUtilsInternal.isAdminInCurrentUserOrProfile(mActivity, admin)
|| !RestrictedLockUtils.isCurrentUserOrProfile(mActivity, userId)) {
admin = null;
+
+ supportIconView.setImageDrawable(
+ mActivity.getDrawable(com.android.internal.R.drawable.ic_info));
+
+ TypedArray ta = mActivity.obtainStyledAttributes(new int[]{android.R.attr.colorAccent});
+ supportIconView.setImageTintList(ColorStateList.valueOf(ta.getColor(0, 0)));
+ ta.recycle();
} else {
final Drawable badgedIcon = Utils.getBadgedIcon(
IconDrawableFactory.newInstance(mActivity),
mActivity.getPackageManager(),
admin.getPackageName(),
userId);
- ((ImageView) root.findViewById(R.id.admin_support_icon)).setImageDrawable(badgedIcon);
+ supportIconView.setImageDrawable(badgedIcon);
}
setAdminSupportTitle(root, restriction);
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index e34e6224406..ce9cabcf428 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -235,10 +235,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
controller.setLabel(mAppEntry);
controller.setIcon(mAppEntry);
boolean isInstantApp = AppUtils.isInstant(mAppEntry.info);
- CharSequence summary = isInstantApp
- ? null : getString(Utils.getInstallationStatus(mAppEntry.info));
controller.setIsInstantApp(AppUtils.isInstant(mAppEntry.info));
- controller.setSummary(summary);
}
controller.done(context, true /* rebindActions */);
diff --git a/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java b/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
index 0065f5c2525..b5cdf87cf53 100644
--- a/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
+++ b/src/com/android/settings/homepage/contextualcards/CardDatabaseHelper.java
@@ -201,7 +201,7 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
final String selection = CardColumns.CARD_DISMISSED + "=0";
Cursor cursor = db.query(CARD_TABLE, null /* columns */, selection,
null /* selectionArgs */, null /* groupBy */, null /* having */,
- null /* orderBy */);
+ CardColumns.SCORE + " DESC" /* orderBy */);
return cursor;
}
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCard.java b/src/com/android/settings/homepage/contextualcards/ContextualCard.java
index b0dfad80e7f..8d439147af8 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCard.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCard.java
@@ -33,12 +33,12 @@ public class ContextualCard {
/**
* Flags indicating the type of the ContextualCard.
*/
- @IntDef({CardType.DEFAULT, CardType.SLICE, CardType.SUGGESTION, CardType.CONDITIONAL})
+ @IntDef({CardType.DEFAULT, CardType.SLICE, CardType.LEGACY_SUGGESTION, CardType.CONDITIONAL})
@Retention(RetentionPolicy.SOURCE)
public @interface CardType {
int DEFAULT = 0;
int SLICE = 1;
- int SUGGESTION = 2;
+ int LEGACY_SUGGESTION = 2;
int CONDITIONAL = 3;
}
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
index 2253a2f839a..dabc88c67f6 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLookupTable.java
@@ -18,11 +18,16 @@ package com.android.settings.homepage.contextualcards;
import android.util.Log;
+import androidx.annotation.LayoutRes;
import androidx.annotation.VisibleForTesting;
import com.android.settings.homepage.contextualcards.ContextualCard.CardType;
import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardController;
import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardRenderer;
+import com.android.settings.homepage.contextualcards.legacysuggestion
+ .LegacySuggestionContextualCardController;
+import com.android.settings.homepage.contextualcards.legacysuggestion
+ .LegacySuggestionContextualCardRenderer;
import com.android.settings.homepage.contextualcards.slices.SliceContextualCardController;
import com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer;
@@ -34,6 +39,7 @@ import java.util.stream.Collectors;
public class ContextualCardLookupTable {
private static final String TAG = "ContextualCardLookup";
+
static class ControllerRendererMapping implements Comparable {
@CardType
final int mCardType;
@@ -41,7 +47,7 @@ public class ContextualCardLookupTable {
final Class extends ContextualCardController> mControllerClass;
final Class extends ContextualCardRenderer> mRendererClass;
- ControllerRendererMapping(@CardType int cardType, int viewType,
+ ControllerRendererMapping(@CardType int cardType, @LayoutRes int viewType,
Class extends ContextualCardController> controllerClass,
Class extends ContextualCardRenderer> rendererClass) {
mCardType = cardType;
@@ -69,6 +75,10 @@ public class ContextualCardLookupTable {
ConditionContextualCardRenderer.FULL_WIDTH_VIEW_TYPE,
ConditionContextualCardController.class,
ConditionContextualCardRenderer.class));
+ add(new ControllerRendererMapping(CardType.LEGACY_SUGGESTION,
+ LegacySuggestionContextualCardRenderer.VIEW_TYPE,
+ LegacySuggestionContextualCardController.class,
+ LegacySuggestionContextualCardRenderer.class));
add(new ControllerRendererMapping(CardType.SLICE,
SliceContextualCardRenderer.VIEW_TYPE,
SliceContextualCardController.class,
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
index 9bd08c8a3fe..39ceff317b6 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardManager.java
@@ -16,7 +16,8 @@
package com.android.settings.homepage.contextualcards;
-import static com.android.settings.homepage.contextualcards.ContextualCardLoader.CARD_CONTENT_LOADER_ID;
+import static com.android.settings.homepage.contextualcards.ContextualCardLoader
+ .CARD_CONTENT_LOADER_ID;
import static java.util.stream.Collectors.groupingBy;
@@ -57,8 +58,8 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
private static final String TAG = "ContextualCardManager";
//The list for Settings Custom Card
- @ContextualCard.CardType
- private static final int[] SETTINGS_CARDS = {ContextualCard.CardType.CONDITIONAL};
+ private static final int[] SETTINGS_CARDS =
+ {ContextualCard.CardType.CONDITIONAL, ContextualCard.CardType.LEGACY_SUGGESTION};
private final Context mContext;
private final ControllerRendererPool mControllerRendererPool;
@@ -68,14 +69,14 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
private ContextualCardUpdateListener mListener;
- public ContextualCardManager(Context context, @NonNull Lifecycle lifecycle) {
+ public ContextualCardManager(Context context, Lifecycle lifecycle) {
mContext = context;
mLifecycle = lifecycle;
mContextualCards = new ArrayList<>();
mLifecycleObservers = new ArrayList<>();
mControllerRendererPool = new ControllerRendererPool();
//for data provided by Settings
- for (int cardType : SETTINGS_CARDS) {
+ for (@ContextualCard.CardType int cardType : SETTINGS_CARDS) {
setupController(cardType);
}
}
@@ -94,7 +95,7 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo
}
}
- private void setupController(int cardType) {
+ private void setupController(@ContextualCard.CardType int cardType) {
final ContextualCardController controller = mControllerRendererPool.getController(mContext,
cardType);
if (controller == null) {
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/ContextualCardRenderer.java
index bb85bd23916..283a079c94a 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardRenderer.java
@@ -18,6 +18,7 @@ package com.android.settings.homepage.contextualcards;
import android.view.View;
+import androidx.annotation.LayoutRes;
import androidx.recyclerview.widget.RecyclerView;
/**
@@ -28,6 +29,7 @@ public interface ContextualCardRenderer {
/**
* The layout type of the renderer.
*/
+ @LayoutRes
int getViewType(boolean isHalfWidth);
/**
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardUpdateListener.java b/src/com/android/settings/homepage/contextualcards/ContextualCardUpdateListener.java
index 725f6dae4ed..9b90d41d8d8 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardUpdateListener.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardUpdateListener.java
@@ -16,6 +16,8 @@
package com.android.settings.homepage.contextualcards;
+import androidx.annotation.MainThread;
+
import java.util.List;
import java.util.Map;
@@ -31,5 +33,6 @@ public interface ContextualCardUpdateListener {
* null, which means all cards from corresponding {@link
* ContextualCard.CardType} are removed.
*/
+ @MainThread
void onContextualCardUpdated(Map> cards);
}
\ No newline at end of file
diff --git a/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java b/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
index 8e59f466983..7d9d5a8a4a3 100644
--- a/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
+++ b/src/com/android/settings/homepage/contextualcards/ControllerRendererPool.java
@@ -26,6 +26,10 @@ import androidx.lifecycle.LifecycleOwner;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardController;
import com.android.settings.homepage.contextualcards.conditional.ConditionContextualCardRenderer;
+import com.android.settings.homepage.contextualcards.legacysuggestion
+ .LegacySuggestionContextualCardController;
+import com.android.settings.homepage.contextualcards.legacysuggestion
+ .LegacySuggestionContextualCardRenderer;
import com.android.settings.homepage.contextualcards.slices.SliceContextualCardController;
import com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer;
@@ -111,6 +115,8 @@ public class ControllerRendererPool {
return new ConditionContextualCardController(context);
} else if (SliceContextualCardController.class == clz) {
return new SliceContextualCardController();
+ } else if (LegacySuggestionContextualCardController.class == clz) {
+ return new LegacySuggestionContextualCardController(context);
}
return null;
}
@@ -118,9 +124,12 @@ public class ControllerRendererPool {
private ContextualCardRenderer createCardRenderer(Context context,
LifecycleOwner lifecycleOwner, Class> clz) {
if (ConditionContextualCardRenderer.class == clz) {
- return new ConditionContextualCardRenderer(context, this /*controllerRendererPool*/);
+ return new ConditionContextualCardRenderer(context, this /* controllerRendererPool */);
} else if (SliceContextualCardRenderer.class == clz) {
return new SliceContextualCardRenderer(context, lifecycleOwner);
+ } else if (LegacySuggestionContextualCardRenderer.class == clz) {
+ return new LegacySuggestionContextualCardRenderer(context,
+ this /* controllerRendererPool */);
}
return null;
}
diff --git a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
index 41c540c1eee..5e4e749c6b2 100644
--- a/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
+++ b/src/com/android/settings/homepage/contextualcards/conditional/ConditionContextualCardRenderer.java
@@ -23,6 +23,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
+import androidx.annotation.LayoutRes;
import androidx.recyclerview.widget.RecyclerView;
import com.android.internal.logging.nano.MetricsProto;
@@ -37,7 +38,9 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
* Card renderer for {@link ConditionalContextualCard}.
*/
public class ConditionContextualCardRenderer implements ContextualCardRenderer {
+ @LayoutRes
public static final int HALF_WIDTH_VIEW_TYPE = R.layout.homepage_condition_half_tile;
+ @LayoutRes
public static final int FULL_WIDTH_VIEW_TYPE = R.layout.homepage_condition_full_tile;
private final Context mContext;
diff --git a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCard.java b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCard.java
new file mode 100644
index 00000000000..d11f77120ea
--- /dev/null
+++ b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCard.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2018 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.homepage.contextualcards.legacysuggestion;
+
+import android.app.PendingIntent;
+
+import com.android.settings.homepage.contextualcards.ContextualCard;
+
+public class LegacySuggestionContextualCard extends ContextualCard {
+
+ private final PendingIntent mPendingIntent;
+
+ public LegacySuggestionContextualCard(Builder builder) {
+ super(builder);
+ mPendingIntent = builder.mPendingIntent;
+ }
+
+ @Override
+ public int getCardType() {
+ return CardType.LEGACY_SUGGESTION;
+ }
+
+ public PendingIntent getPendingIntent() {
+ return mPendingIntent;
+ }
+
+ public static class Builder extends ContextualCard.Builder {
+
+ private PendingIntent mPendingIntent;
+
+ public Builder setPendingIntent(PendingIntent pendingIntent) {
+ mPendingIntent = pendingIntent;
+ return this;
+ }
+
+ @Override
+ public Builder setCardType(int cardType) {
+ throw new IllegalArgumentException(
+ "Cannot change card type for " + getClass().getName());
+ }
+
+ public LegacySuggestionContextualCard build() {
+ return new LegacySuggestionContextualCard(this);
+ }
+ }
+
+}
diff --git a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java
new file mode 100644
index 00000000000..550f84566d3
--- /dev/null
+++ b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardController.java
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2018 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.homepage.contextualcards.legacysuggestion;
+
+import android.app.PendingIntent;
+import android.content.ComponentName;
+import android.content.Context;
+import android.service.settings.suggestions.Suggestion;
+import android.util.ArrayMap;
+import android.util.Log;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.R;
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.homepage.contextualcards.ContextualCardController;
+import com.android.settings.homepage.contextualcards.ContextualCardUpdateListener;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+import com.android.settingslib.suggestions.SuggestionController;
+import com.android.settingslib.suggestions.SuggestionController.ServiceConnectionListener;
+import com.android.settingslib.utils.ThreadUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class LegacySuggestionContextualCardController implements ContextualCardController,
+ LifecycleObserver, OnStart, OnStop, ServiceConnectionListener {
+
+ private static final String TAG = "LegacySuggestCardCtrl";
+
+ @VisibleForTesting
+ SuggestionController mSuggestionController;
+
+ private ContextualCardUpdateListener mCardUpdateListener;
+ private final Context mContext;
+
+
+ public LegacySuggestionContextualCardController(Context context) {
+ mContext = context;
+ if (!mContext.getResources().getBoolean(R.bool.config_use_legacy_suggestion)) {
+ Log.w(TAG, "Legacy suggestion contextual card disabled, skipping.");
+ return;
+ }
+ final ComponentName suggestionServiceComponent =
+ FeatureFactory.getFactory(mContext).getSuggestionFeatureProvider(mContext)
+ .getSuggestionServiceComponent();
+ mSuggestionController = new SuggestionController(
+ mContext, suggestionServiceComponent, this /* listener */);
+
+ }
+
+ @Override
+ public int getCardType() {
+ return ContextualCard.CardType.LEGACY_SUGGESTION;
+ }
+
+ @Override
+ public void onPrimaryClick(ContextualCard card) {
+ try {
+ ((LegacySuggestionContextualCard) card).getPendingIntent().send();
+ } catch (PendingIntent.CanceledException e) {
+ Log.w(TAG, "Failed to start suggestion " + card.getTitleText());
+ }
+ }
+
+ @Override
+ public void onActionClick(ContextualCard card) {
+
+ }
+
+ @Override
+ public void setCardUpdateListener(ContextualCardUpdateListener listener) {
+ mCardUpdateListener = listener;
+ }
+
+ @Override
+ public void onStart() {
+ if (mSuggestionController == null) {
+ return;
+ }
+ mSuggestionController.start();
+ }
+
+ @Override
+ public void onStop() {
+ if (mSuggestionController == null) {
+ return;
+ }
+ mSuggestionController.stop();
+ }
+
+ @Override
+ public void onServiceConnected() {
+ loadSuggestions();
+ }
+
+ @Override
+ public void onServiceDisconnected() {
+
+ }
+
+ private void loadSuggestions() {
+ ThreadUtils.postOnBackgroundThread(() -> {
+ if (mSuggestionController == null || mCardUpdateListener == null) {
+ return;
+ }
+ final List suggestions = mSuggestionController.getSuggestions();
+ Log.d(TAG, "Loaded suggests: "
+ + suggestions == null ? "null" : String.valueOf(suggestions.size()));
+
+ final List cards = new ArrayList<>();
+ if (suggestions != null) {
+ // Convert suggestion to ContextualCard
+ for (Suggestion suggestion : suggestions) {
+ final LegacySuggestionContextualCard.Builder cardBuilder =
+ new LegacySuggestionContextualCard.Builder();
+ if (suggestion.getIcon() != null) {
+ cardBuilder.setIconDrawable(suggestion.getIcon().loadDrawable(mContext));
+ }
+ cardBuilder
+ .setPendingIntent(suggestion.getPendingIntent())
+ .setName(suggestion.getId())
+ .setTitleText(suggestion.getTitle().toString())
+ .setSummaryText(suggestion.getSummary().toString());
+
+ cards.add(cardBuilder.build());
+ }
+ }
+
+ // Update adapter
+ final Map> suggestionCards = new ArrayMap<>();
+ suggestionCards.put(ContextualCard.CardType.LEGACY_SUGGESTION, cards);
+ ThreadUtils.postOnMainThread(
+ () -> mCardUpdateListener.onContextualCardUpdated(suggestionCards));
+
+ });
+ }
+}
diff --git a/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardRenderer.java b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardRenderer.java
new file mode 100644
index 00000000000..3ce1883f096
--- /dev/null
+++ b/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardRenderer.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2018 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.homepage.contextualcards.legacysuggestion;
+
+import android.content.Context;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import androidx.annotation.LayoutRes;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.settings.R;
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.homepage.contextualcards.ContextualCardRenderer;
+import com.android.settings.homepage.contextualcards.ControllerRendererPool;
+
+public class LegacySuggestionContextualCardRenderer implements ContextualCardRenderer {
+
+ @LayoutRes
+ public static final int VIEW_TYPE = R.layout.homepage_suggestion_tile;
+
+ private final Context mContext;
+ private final ControllerRendererPool mControllerRendererPool;
+
+ public LegacySuggestionContextualCardRenderer(Context context,
+ ControllerRendererPool controllerRendererPool) {
+ mContext = context;
+ mControllerRendererPool = controllerRendererPool;
+ }
+
+ @Override
+ public int getViewType(boolean isHalfWidth) {
+ return VIEW_TYPE;
+ }
+
+ @Override
+ public RecyclerView.ViewHolder createViewHolder(View view) {
+ return new LegacySuggestionViewHolder(view);
+ }
+
+ @Override
+ public void bindView(RecyclerView.ViewHolder holder, ContextualCard card) {
+ final LegacySuggestionViewHolder vh = (LegacySuggestionViewHolder) holder;
+ vh.icon.setImageDrawable(card.getIconDrawable());
+ vh.title.setText(card.getTitleText());
+ vh.summary.setText(card.getSummaryText());
+ vh.itemView.setOnClickListener(v ->
+ mControllerRendererPool.getController(mContext,
+ card.getCardType()).onPrimaryClick(card));
+ }
+
+ private static class LegacySuggestionViewHolder extends RecyclerView.ViewHolder {
+
+ public final ImageView icon;
+ public final TextView title;
+ public final TextView summary;
+
+ public LegacySuggestionViewHolder(View itemView) {
+ super(itemView);
+ icon = itemView.findViewById(android.R.id.icon);
+ title = itemView.findViewById(android.R.id.title);
+ summary = itemView.findViewById(android.R.id.summary);
+ }
+ }
+}
+
diff --git a/src/com/android/settings/network/ApnPreference.java b/src/com/android/settings/network/ApnPreference.java
index 412259bab72..a7fbb6eaa92 100755
--- a/src/com/android/settings/network/ApnPreference.java
+++ b/src/com/android/settings/network/ApnPreference.java
@@ -25,18 +25,15 @@ import android.telephony.SubscriptionManager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
-import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.RadioButton;
-import android.widget.RelativeLayout;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
-public class ApnPreference extends Preference implements
- CompoundButton.OnCheckedChangeListener, OnClickListener {
+public class ApnPreference extends Preference implements CompoundButton.OnCheckedChangeListener {
final static String TAG = "ApnPreference";
private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
@@ -82,11 +79,6 @@ public class ApnPreference extends Preference implements
rb.setVisibility(View.GONE);
}
}
-
- View textLayout = view.findViewById(R.id.text_layout);
- if ((textLayout != null) && textLayout instanceof RelativeLayout) {
- textLayout.setOnClickListener(this);
- }
}
public boolean isChecked() {
@@ -116,16 +108,16 @@ public class ApnPreference extends Preference implements
}
}
- public void onClick(android.view.View v) {
- if ((v != null) && (R.id.text_layout == v.getId())) {
- Context context = getContext();
- if (context != null) {
- int pos = Integer.parseInt(getKey());
- Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
- Intent editIntent = new Intent(Intent.ACTION_EDIT, url);
- editIntent.putExtra(ApnSettings.SUB_ID, mSubId);
- context.startActivity(editIntent);
- }
+ @Override
+ protected void onClick() {
+ super.onClick();
+ Context context = getContext();
+ if (context != null) {
+ int pos = Integer.parseInt(getKey());
+ Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
+ Intent editIntent = new Intent(Intent.ACTION_EDIT, url);
+ editIntent.putExtra(ApnSettings.SUB_ID, mSubId);
+ context.startActivity(editIntent);
}
}
diff --git a/src/com/android/settings/network/ApnSettings.java b/src/com/android/settings/network/ApnSettings.java
index beeaab35c7a..a71dfaa7e16 100755
--- a/src/com/android/settings/network/ApnSettings.java
+++ b/src/com/android/settings/network/ApnSettings.java
@@ -21,7 +21,6 @@ import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
-import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
@@ -65,8 +64,7 @@ import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import java.util.ArrayList;
-public class ApnSettings extends RestrictedSettingsFragment implements
- Preference.OnPreferenceChangeListener {
+public class ApnSettings extends RestrictedSettingsFragment {
static final String TAG = "ApnSettings";
public static final String EXTRA_POSITION = "position";
@@ -313,7 +311,6 @@ public class ApnSettings extends RestrictedSettingsFragment implements
pref.setTitle(name);
pref.setSummary(apn);
pref.setPersistent(false);
- pref.setOnPreferenceChangeListener(this);
pref.setSubId(subId);
boolean selectable = ((type == null) || !type.equals("mms"));
@@ -405,14 +402,6 @@ public class ApnSettings extends RestrictedSettingsFragment implements
startActivity(intent);
}
- @Override
- public boolean onPreferenceTreeClick(Preference preference) {
- int pos = Integer.parseInt(preference.getKey());
- Uri url = ContentUris.withAppendedId(Telephony.Carriers.CONTENT_URI, pos);
- startActivity(new Intent(Intent.ACTION_EDIT, url));
- return true;
- }
-
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.d(TAG, "onPreferenceChange(): Preference - " + preference
+ ", newValue - " + newValue + ", newValue type - "
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index b077dd526fc..b323f910af5 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -180,7 +180,7 @@ public class EnabledNetworkModePreferenceController extends BasePreferenceContro
preference.setEntryValues(
R.array.enabled_networks_tdscdma_values);
} else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)
- && !resources.getBoolean(R.bool.config_enabled_lte)) {
+ && !carrierConfig.getBoolean(CarrierConfigManager.KEY_LTE_ENABLED_BOOL)) {
preference.setEntries(R.array.enabled_networks_except_gsm_lte_choices);
preference.setEntryValues(R.array.enabled_networks_except_gsm_lte_values);
} else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)) {
@@ -190,7 +190,7 @@ public class EnabledNetworkModePreferenceController extends BasePreferenceContro
preference.setEntries(select);
preference.setEntryValues(
R.array.enabled_networks_except_gsm_values);
- } else if (!resources.getBoolean(R.bool.config_enabled_lte)) {
+ } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_LTE_ENABLED_BOOL)) {
preference.setEntries(
R.array.enabled_networks_except_lte_choices);
preference.setEntryValues(
diff --git a/src/com/android/settings/network/telephony/MobileNetworkUtils.java b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
index 689799eb96a..dc184d3df3f 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkUtils.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkUtils.java
@@ -27,6 +27,7 @@ import android.database.Cursor;
import android.os.PersistableBundle;
import android.os.SystemProperties;
import android.provider.Settings;
+import android.service.carrier.CarrierMessagingService;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.CarrierConfigManager;
@@ -329,28 +330,11 @@ public class MobileNetworkUtils {
* settings
*/
public static boolean isWorldMode(Context context, int subId) {
- final TelephonyManager telephonyManager = context.getSystemService(TelephonyManager.class)
- .createForSubscriptionId(subId);
- boolean worldModeOn = false;
- final String configString = context.getString(R.string.config_world_mode);
-
- if (!TextUtils.isEmpty(configString)) {
- String[] configArray = configString.split(";");
- // Check if we have World mode configuration set to True only or config is set to True
- // and SIM GID value is also set and matches to the current SIM GID.
- if (configArray != null &&
- ((configArray.length == 1 && configArray[0].equalsIgnoreCase("true"))
- || (configArray.length == 2 && !TextUtils.isEmpty(configArray[1])
- && telephonyManager != null
- && configArray[1].equalsIgnoreCase(
- telephonyManager.getGroupIdLevel1())))) {
- worldModeOn = true;
- }
- }
-
- Log.d(TAG, "isWorldMode=" + worldModeOn);
-
- return worldModeOn;
+ final PersistableBundle carrierConfig = context.getSystemService(
+ CarrierConfigManager.class).getConfigForSubId(subId);
+ return carrierConfig == null
+ ? false
+ : carrierConfig.getBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL);
}
/**
@@ -396,14 +380,21 @@ public class MobileNetworkUtils {
//TODO(b/117651939): move it to telephony
private static boolean isTdscdmaSupported(Context context, TelephonyManager telephonyManager) {
- if (context.getResources().getBoolean(R.bool.config_support_tdscdma)) {
+ final PersistableBundle carrierConfig = context.getSystemService(
+ CarrierConfigManager.class).getConfig();
+
+ if (carrierConfig == null) {
+ return false;
+ }
+
+ if (carrierConfig.getBoolean(CarrierConfigManager.KEY_SUPPORT_TDSCDMA_BOOL)) {
return true;
}
String operatorNumeric = telephonyManager.getServiceState().getOperatorNumeric();
- String[] numericArray = context.getResources().getStringArray(
- R.array.config_support_tdscdma_roaming_on_networks);
- if (numericArray.length == 0 || operatorNumeric == null) {
+ String[] numericArray = carrierConfig.getStringArray(
+ CarrierConfigManager.KEY_SUPPORT_TDSCDMA_ROAMING_NETWORKS_STRING_ARRAY);
+ if (numericArray == null || operatorNumeric == null) {
return false;
}
for (String numeric : numericArray) {
@@ -413,4 +404,4 @@ public class MobileNetworkUtils {
}
return false;
}
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index 7f04bde801f..14a918ed8f5 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -264,6 +264,10 @@ public class ChooseLockGeneric extends SettingsActivity {
return false;
}
+ protected Class extends ChooseLockGeneric.InternalActivity> getInternalActivityClass() {
+ return ChooseLockGeneric.InternalActivity.class;
+ }
+
protected void addHeaderView() {
if (mForFingerprint) {
setHeaderView(R.layout.choose_lock_generic_fingerprint_header);
@@ -291,7 +295,7 @@ public class ChooseLockGeneric extends SettingsActivity {
return true;
} else if (KEY_SKIP_FINGERPRINT.equals(key) || KEY_SKIP_FACE.equals(key)) {
Intent chooseLockGenericIntent = new Intent(getActivity(),
- ChooseLockGeneric.InternalActivity.class);
+ getInternalActivityClass());
chooseLockGenericIntent.setAction(getIntent().getAction());
// Forward the target user id to ChooseLockGeneric.
chooseLockGenericIntent.putExtra(Intent.EXTRA_USER_ID, mUserId);
diff --git a/src/com/android/settings/password/SetupChooseLockGeneric.java b/src/com/android/settings/password/SetupChooseLockGeneric.java
index 700cc2dde1e..76001048ace 100644
--- a/src/com/android/settings/password/SetupChooseLockGeneric.java
+++ b/src/com/android/settings/password/SetupChooseLockGeneric.java
@@ -27,6 +27,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
+import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.recyclerview.widget.RecyclerView;
@@ -135,6 +136,11 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
return true;
}
+ @Override
+ protected Class extends ChooseLockGeneric.InternalActivity> getInternalActivityClass() {
+ return SetupChooseLockGeneric.InternalActivity.class;
+ }
+
/***
* Disables preferences that are less secure than required quality and shows only secure
* screen lock options here.
@@ -207,4 +213,25 @@ public class SetupChooseLockGeneric extends ChooseLockGeneric {
return intent;
}
}
+
+ public static class InternalActivity extends ChooseLockGeneric.InternalActivity {
+ @Override
+ protected boolean isValidFragment(String fragmentName) {
+ return InternalSetupChooseLockGenericFragment.class.getName().equals(fragmentName);
+ }
+
+ @Override
+ /* package */ Class extends Fragment> getFragmentClass() {
+ return InternalSetupChooseLockGenericFragment.class;
+ }
+
+ public static class InternalSetupChooseLockGenericFragment
+ extends ChooseLockGenericFragment {
+ @Override
+ protected boolean canRunBeforeDeviceProvisioned() {
+ return true;
+ }
+ }
+ }
+
}
diff --git a/src/com/android/settings/print/PrintJobMessagePreferenceController.java b/src/com/android/settings/print/PrintJobMessagePreferenceController.java
new file mode 100644
index 00000000000..9573e5d6007
--- /dev/null
+++ b/src/com/android/settings/print/PrintJobMessagePreferenceController.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 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.print;
+
+import android.content.Context;
+import android.print.PrintJob;
+import android.print.PrintJobInfo;
+import android.text.TextUtils;
+
+public class PrintJobMessagePreferenceController extends PrintJobPreferenceControllerBase {
+
+ public PrintJobMessagePreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ protected void updateUi() {
+ final PrintJob printJob = getPrintJob();
+
+ if (printJob == null) {
+ mFragment.finish();
+ return;
+ }
+
+ if (printJob.isCancelled() || printJob.isCompleted()) {
+ mFragment.finish();
+ return;
+ }
+
+ final PrintJobInfo info = printJob.getInfo();
+ final CharSequence status = info.getStatus(mContext.getPackageManager());
+ mPreference.setVisible(!TextUtils.isEmpty(status));
+ mPreference.setSummary(status);
+ }
+}
diff --git a/src/com/android/settings/print/PrintJobPreferenceController.java b/src/com/android/settings/print/PrintJobPreferenceController.java
new file mode 100644
index 00000000000..0eff0d6d612
--- /dev/null
+++ b/src/com/android/settings/print/PrintJobPreferenceController.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2018 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.print;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
+import android.print.PrintJob;
+import android.print.PrintJobInfo;
+import android.text.format.DateUtils;
+
+import com.android.settings.R;
+
+import java.text.DateFormat;
+
+public class PrintJobPreferenceController extends PrintJobPreferenceControllerBase {
+
+ public PrintJobPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ protected void updateUi() {
+ final PrintJob printJob = getPrintJob();
+
+ if (printJob == null) {
+ mFragment.finish();
+ return;
+ }
+
+ if (printJob.isCancelled() || printJob.isCompleted()) {
+ mFragment.finish();
+ return;
+ }
+
+ PrintJobInfo info = printJob.getInfo();
+
+ switch (info.getState()) {
+ case PrintJobInfo.STATE_CREATED: {
+ mPreference.setTitle(mContext.getString(
+ R.string.print_configuring_state_title_template, info.getLabel()));
+ }
+ break;
+ case PrintJobInfo.STATE_QUEUED:
+ case PrintJobInfo.STATE_STARTED: {
+ if (!printJob.getInfo().isCancelling()) {
+ mPreference.setTitle(mContext.getString(
+ R.string.print_printing_state_title_template, info.getLabel()));
+ } else {
+ mPreference.setTitle(mContext.getString(
+ R.string.print_cancelling_state_title_template, info.getLabel()));
+ }
+ }
+ break;
+
+ case PrintJobInfo.STATE_FAILED: {
+ mPreference.setTitle(mContext.getString(
+ R.string.print_failed_state_title_template, info.getLabel()));
+ }
+ break;
+
+ case PrintJobInfo.STATE_BLOCKED: {
+ if (!printJob.getInfo().isCancelling()) {
+ mPreference.setTitle(mContext.getString(
+ R.string.print_blocked_state_title_template, info.getLabel()));
+ } else {
+ mPreference.setTitle(mContext.getString(
+ R.string.print_cancelling_state_title_template, info.getLabel()));
+ }
+ }
+ break;
+ }
+
+ mPreference.setSummary(mContext.getString(R.string.print_job_summary,
+ info.getPrinterName(), DateUtils.formatSameDayTime(
+ info.getCreationTime(), info.getCreationTime(), DateFormat.SHORT,
+ DateFormat.SHORT)));
+
+ TypedArray a = mContext.obtainStyledAttributes(new int[]{
+ android.R.attr.colorControlNormal});
+ int tintColor = a.getColor(0, 0);
+ a.recycle();
+
+ switch (info.getState()) {
+ case PrintJobInfo.STATE_QUEUED:
+ case PrintJobInfo.STATE_STARTED: {
+ Drawable icon = mContext.getDrawable(com.android.internal.R.drawable.ic_print);
+ icon.setTint(tintColor);
+ mPreference.setIcon(icon);
+ break;
+ }
+
+ case PrintJobInfo.STATE_FAILED:
+ case PrintJobInfo.STATE_BLOCKED: {
+ Drawable icon = mContext.getDrawable(
+ com.android.internal.R.drawable.ic_print_error);
+ icon.setTint(tintColor);
+ mPreference.setIcon(icon);
+ break;
+ }
+ }
+ }
+}
diff --git a/src/com/android/settings/print/PrintJobPreferenceControllerBase.java b/src/com/android/settings/print/PrintJobPreferenceControllerBase.java
new file mode 100644
index 00000000000..0726a19f4d1
--- /dev/null
+++ b/src/com/android/settings/print/PrintJobPreferenceControllerBase.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2018 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.print;
+
+import android.content.Context;
+import android.print.PrintJob;
+import android.print.PrintJobId;
+import android.print.PrintManager;
+import android.util.Log;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+public abstract class PrintJobPreferenceControllerBase extends BasePreferenceController implements
+ LifecycleObserver, OnStart, OnStop, PrintManager.PrintJobStateChangeListener {
+ private static final String TAG = "PrintJobPrefCtrlBase";
+
+ private static final String EXTRA_PRINT_JOB_ID = "EXTRA_PRINT_JOB_ID";
+
+ private final PrintManager mPrintManager;
+ protected Preference mPreference;
+ protected PrintJobSettingsFragment mFragment;
+ protected PrintJobId mPrintJobId;
+
+ public PrintJobPreferenceControllerBase(Context context, String key) {
+ super(context, key);
+ mPrintManager = ((PrintManager) mContext.getSystemService(
+ Context.PRINT_SERVICE)).getGlobalPrintManagerForUser(mContext.getUserId());
+ }
+
+ @Override
+ public void onStart() {
+ mPrintManager.addPrintJobStateChangeListener(this);
+ updateUi();
+ }
+
+ @Override
+ public void onStop() {
+ mPrintManager.removePrintJobStateChangeListener(this);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public void onPrintJobStateChanged(PrintJobId printJobId) {
+ updateUi();
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ public void init(PrintJobSettingsFragment fragment) {
+ mFragment = fragment;
+ processArguments();
+ }
+
+ protected PrintJob getPrintJob() {
+ return mPrintManager.getPrintJob(mPrintJobId);
+ }
+
+ protected abstract void updateUi();
+
+ private void processArguments() {
+ String printJobId = mFragment.getArguments().getString(EXTRA_PRINT_JOB_ID);
+ if (printJobId == null) {
+ printJobId = mFragment.getActivity().getIntent().getStringExtra(EXTRA_PRINT_JOB_ID);
+
+ if (printJobId == null) {
+ Log.w(TAG, EXTRA_PRINT_JOB_ID + " not set");
+ mFragment.finish();
+ return;
+ }
+ }
+ mPrintJobId = PrintJobId.unflattenFromString(printJobId);
+ }
+}
diff --git a/src/com/android/settings/print/PrintJobSettingsFragment.java b/src/com/android/settings/print/PrintJobSettingsFragment.java
index ba0172ba560..1d6ff5a1451 100644
--- a/src/com/android/settings/print/PrintJobSettingsFragment.java
+++ b/src/com/android/settings/print/PrintJobSettingsFragment.java
@@ -17,114 +17,59 @@
package com.android.settings.print;
import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.print.PrintJob;
-import android.print.PrintJobId;
-import android.print.PrintJobInfo;
-import android.print.PrintManager;
-import android.print.PrintManager.PrintJobStateChangeListener;
-import android.text.TextUtils;
-import android.text.format.DateUtils;
-import android.util.Log;
-import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-
-import java.text.DateFormat;
+import com.android.settings.dashboard.DashboardFragment;
/**
* Fragment for management of a print job.
*/
-public class PrintJobSettingsFragment extends SettingsPreferenceFragment {
- private static final String LOG_TAG = PrintJobSettingsFragment.class.getSimpleName();
+public class PrintJobSettingsFragment extends DashboardFragment {
+ private static final String TAG = "PrintJobSettingsFragment";
private static final int MENU_ITEM_ID_CANCEL = 1;
private static final int MENU_ITEM_ID_RESTART = 2;
- private static final String EXTRA_PRINT_JOB_ID = "EXTRA_PRINT_JOB_ID";
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.print_job_settings;
+ }
- private static final String PRINT_JOB_PREFERENCE = "print_job_preference";
- private static final String PRINT_JOB_MESSAGE_PREFERENCE = "print_job_message_preference";
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
- private final PrintJobStateChangeListener mPrintJobStateChangeListener =
- new PrintJobStateChangeListener() {
- @Override
- public void onPrintJobStateChanged(PrintJobId printJobId) {
- updateUi();
- }
- };
-
- private PrintManager mPrintManager;
-
- private Preference mPrintJobPreference;
- private Preference mMessagePreference;
-
- private PrintJobId mPrintJobId;
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ use(PrintJobPreferenceController.class).init(this);
+ use(PrintJobMessagePreferenceController.class).init(this);
+ }
@Override
public int getMetricsCategory() {
return MetricsEvent.PRINT_JOB_SETTINGS;
}
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = super.onCreateView(inflater, container, savedInstanceState);
-
- addPreferencesFromResource(R.xml.print_job_settings);
- mPrintJobPreference = findPreference(PRINT_JOB_PREFERENCE);
- mMessagePreference = findPreference(PRINT_JOB_MESSAGE_PREFERENCE);
-
- mPrintManager = ((PrintManager) getActivity().getSystemService(
- Context.PRINT_SERVICE)).getGlobalPrintManagerForUser(
- getActivity().getUserId());
-
- getActivity().getActionBar().setTitle(R.string.print_print_job);
-
- processArguments();
-
- setHasOptionsMenu(true);
-
- return view;
- }
-
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getListView().setEnabled(false);
}
- @Override
- public void onStart() {
- super.onStart();
- mPrintManager.addPrintJobStateChangeListener(
- mPrintJobStateChangeListener);
- updateUi();
- }
-
- @Override
- public void onStop() {
- super.onStop();
- mPrintManager.removePrintJobStateChangeListener(
- mPrintJobStateChangeListener);
- }
-
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
- PrintJob printJob = getPrintJob();
+ final PrintJob printJob = use(PrintJobPreferenceController.class).getPrintJob();
if (printJob == null) {
return;
}
@@ -144,7 +89,7 @@ public class PrintJobSettingsFragment extends SettingsPreferenceFragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- PrintJob printJob = getPrintJob();
+ final PrintJob printJob = use(PrintJobPreferenceController.class).getPrintJob();
if (printJob != null) {
switch (item.getItemId()) {
@@ -164,113 +109,4 @@ public class PrintJobSettingsFragment extends SettingsPreferenceFragment {
return super.onOptionsItemSelected(item);
}
-
- private void processArguments() {
- String printJobId = getArguments().getString(EXTRA_PRINT_JOB_ID);
- if (printJobId == null) {
- printJobId = getIntent().getStringExtra(EXTRA_PRINT_JOB_ID);
-
- if (printJobId == null) {
- Log.w(LOG_TAG, EXTRA_PRINT_JOB_ID + " not set");
- finish();
- return;
- }
- }
-
-
- mPrintJobId = PrintJobId.unflattenFromString(printJobId);
- }
-
- private PrintJob getPrintJob() {
- return mPrintManager.getPrintJob(mPrintJobId);
- }
-
- private void updateUi() {
- PrintJob printJob = getPrintJob();
-
- if (printJob == null) {
- finish();
- return;
- }
-
- if (printJob.isCancelled() || printJob.isCompleted()) {
- finish();
- return;
- }
-
- PrintJobInfo info = printJob.getInfo();
-
- switch (info.getState()) {
- case PrintJobInfo.STATE_CREATED: {
- mPrintJobPreference.setTitle(getString(
- R.string.print_configuring_state_title_template, info.getLabel()));
- } break;
- case PrintJobInfo.STATE_QUEUED:
- case PrintJobInfo.STATE_STARTED: {
- if (!printJob.getInfo().isCancelling()) {
- mPrintJobPreference.setTitle(getString(
- R.string.print_printing_state_title_template, info.getLabel()));
- } else {
- mPrintJobPreference.setTitle(getString(
- R.string.print_cancelling_state_title_template, info.getLabel()));
- }
- } break;
-
- case PrintJobInfo.STATE_FAILED: {
- mPrintJobPreference.setTitle(getString(
- R.string.print_failed_state_title_template, info.getLabel()));
- } break;
-
- case PrintJobInfo.STATE_BLOCKED: {
- if (!printJob.getInfo().isCancelling()) {
- mPrintJobPreference.setTitle(getString(
- R.string.print_blocked_state_title_template, info.getLabel()));
- } else {
- mPrintJobPreference.setTitle(getString(
- R.string.print_cancelling_state_title_template, info.getLabel()));
- }
- } break;
- }
-
- mPrintJobPreference.setSummary(getString(R.string.print_job_summary,
- info.getPrinterName(), DateUtils.formatSameDayTime(
- info.getCreationTime(), info.getCreationTime(), DateFormat.SHORT,
- DateFormat.SHORT)));
-
- TypedArray a = getActivity().obtainStyledAttributes(new int[]{
- android.R.attr.colorControlNormal});
- int tintColor = a.getColor(0, 0);
- a.recycle();
-
- switch (info.getState()) {
- case PrintJobInfo.STATE_QUEUED:
- case PrintJobInfo.STATE_STARTED: {
- Drawable icon = getActivity().getDrawable(com.android.internal.R.drawable.ic_print);
- icon.setTint(tintColor);
- mPrintJobPreference.setIcon(icon);
- break;
- }
-
- case PrintJobInfo.STATE_FAILED:
- case PrintJobInfo.STATE_BLOCKED: {
- Drawable icon = getActivity().getDrawable(
- com.android.internal.R.drawable.ic_print_error);
- icon.setTint(tintColor);
- mPrintJobPreference.setIcon(icon);
- break;
- }
- }
-
- CharSequence status = info.getStatus(getPackageManager());
- if (!TextUtils.isEmpty(status)) {
- if (getPreferenceScreen().findPreference(PRINT_JOB_MESSAGE_PREFERENCE) == null) {
- getPreferenceScreen().addPreference(mMessagePreference);
- }
- mMessagePreference.setSummary(status);
- } else {
- getPreferenceScreen().removePreference(mMessagePreference);
- }
-
- getActivity().invalidateOptionsMenu();
- }
}
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 4b93fc1796d..70837a6a810 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -454,6 +454,13 @@ public class WifiConfigController implements TextWatcher,
return false;
}
+ boolean isValidSaePassword(String password) {
+ if (password.length() >= 1 && password.length() <= 63) {
+ return true;
+ }
+ return false;
+ }
+
boolean isSubmittable() {
boolean enabled = false;
boolean passwordInvalid = false;
@@ -461,7 +468,9 @@ public class WifiConfigController implements TextWatcher,
&& ((mAccessPointSecurity == AccessPoint.SECURITY_WEP
&& mPasswordView.length() == 0)
|| (mAccessPointSecurity == AccessPoint.SECURITY_PSK
- && !isValidPsk(mPasswordView.getText().toString())))) {
+ && !isValidPsk(mPasswordView.getText().toString()))
+ || (mAccessPointSecurity == AccessPoint.SECURITY_SAE
+ && !isValidSaePassword(mPasswordView.getText().toString())))) {
passwordInvalid = true;
}
if ((mSsidView != null && mSsidView.length() == 0)
@@ -475,7 +484,9 @@ public class WifiConfigController implements TextWatcher,
} else {
enabled = ipAndProxyFieldsAreValid();
}
- if (mAccessPointSecurity == AccessPoint.SECURITY_EAP && mEapCaCertSpinner != null
+ if ((mAccessPointSecurity == AccessPoint.SECURITY_EAP ||
+ mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B)
+ && mEapCaCertSpinner != null
&& mView.findViewById(R.id.l_ca_cert).getVisibility() != View.GONE) {
String caCertSelection = (String) mEapCaCertSpinner.getSelectedItem();
if (caCertSelection.equals(mUnspecifiedCertString)) {
@@ -492,7 +503,9 @@ public class WifiConfigController implements TextWatcher,
enabled = false;
}
}
- if (mAccessPointSecurity == AccessPoint.SECURITY_EAP && mEapUserCertSpinner != null
+ if ((mAccessPointSecurity == AccessPoint.SECURITY_EAP ||
+ mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B)
+ && mEapUserCertSpinner != null
&& mView.findViewById(R.id.l_user_cert).getVisibility() != View.GONE
&& mEapUserCertSpinner.getSelectedItem().equals(mUnspecifiedCertString)) {
// Disallow submit if the user has not selected a user certificate for an EAP network
@@ -590,8 +603,18 @@ public class WifiConfigController implements TextWatcher,
break;
case AccessPoint.SECURITY_EAP:
+ case AccessPoint.SECURITY_EAP_SUITE_B:
config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
+ if (mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B) {
+ config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
+ config.requirePMF = true;
+ config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
+ config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
+ config.allowedGroupMgmtCiphers.set(WifiConfiguration.GroupMgmtCipher
+ .BIP_GMAC_256);
+ config.allowedSuiteBCiphers.set(WifiConfiguration.SuiteBCipher.ECDHE_RSA);
+ }
config.enterpriseConfig = new WifiEnterpriseConfig();
int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
int phase2Method = mPhase2Spinner.getSelectedItemPosition();
@@ -700,6 +723,20 @@ public class WifiConfigController implements TextWatcher,
config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
}
break;
+ case AccessPoint.SECURITY_SAE:
+ config.allowedKeyManagement.set(KeyMgmt.SAE);
+ config.requirePMF = true;
+ if (mPasswordView.length() != 0) {
+ String password = mPasswordView.getText().toString();
+ config.preSharedKey = '"' + password + '"';
+ }
+ break;
+
+ case AccessPoint.SECURITY_OWE:
+ config.allowedKeyManagement.set(KeyMgmt.OWE);
+ config.requirePMF = true;
+ break;
+
default:
return null;
}
@@ -851,7 +888,8 @@ public class WifiConfigController implements TextWatcher,
}
private void showSecurityFields() {
- if (mAccessPointSecurity == AccessPoint.SECURITY_NONE) {
+ if (mAccessPointSecurity == AccessPoint.SECURITY_NONE ||
+ mAccessPointSecurity == AccessPoint.SECURITY_OWE) {
mView.findViewById(R.id.security_fields).setVisibility(View.GONE);
return;
}
@@ -870,7 +908,8 @@ public class WifiConfigController implements TextWatcher,
}
}
- if (mAccessPointSecurity != AccessPoint.SECURITY_EAP) {
+ if (mAccessPointSecurity != AccessPoint.SECURITY_EAP &&
+ mAccessPointSecurity != AccessPoint.SECURITY_EAP_SUITE_B) {
mView.findViewById(R.id.eap).setVisibility(View.GONE);
return;
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index f097d5b810c..1c9a5e136c0 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -488,7 +488,8 @@ public class WifiSettings extends RestrictedSettingsFragment
menu.add(Menu.NONE, MENU_ID_MODIFY, 0, R.string.wifi_menu_modify);
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
if (nfcAdapter != null && nfcAdapter.isEnabled() &&
- mSelectedAccessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
+ (!(mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
+ (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE))) {
// Only allow writing of NFC tags for password-protected networks.
menu.add(Menu.NONE, MENU_ID_WRITE_NFC, 0, R.string.wifi_menu_write_to_nfc);
}
@@ -506,7 +507,8 @@ public class WifiSettings extends RestrictedSettingsFragment
boolean isSavedNetwork = mSelectedAccessPoint.isSaved();
if (isSavedNetwork) {
connect(mSelectedAccessPoint.getConfig(), isSavedNetwork);
- } else if (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) {
+ } else if ((mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
+ (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
/** Bypass dialog for unsecured networks */
mSelectedAccessPoint.generateOpenNetworkConfig();
connect(mSelectedAccessPoint.getConfig(), isSavedNetwork);
@@ -552,7 +554,8 @@ public class WifiSettings extends RestrictedSettingsFragment
* networks, or Passpoint provided networks.
*/
WifiConfiguration config = mSelectedAccessPoint.getConfig();
- if (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) {
+ if ((mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
+ (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
mSelectedAccessPoint.generateOpenNetworkConfig();
connect(mSelectedAccessPoint.getConfig(), mSelectedAccessPoint.isSaved());
} else if (mSelectedAccessPoint.isSaved() && config != null
@@ -772,7 +775,8 @@ public class WifiSettings extends RestrictedSettingsFragment
preference.setKey(key);
preference.setOrder(index);
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
- && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
+ && (accessPoint.getSecurity() != AccessPoint.SECURITY_NONE &&
+ accessPoint.getSecurity() != AccessPoint.SECURITY_OWE)) {
if (!accessPoint.isSaved() || isDisabledByWrongPassword(accessPoint)) {
onPreferenceTreeClick(preference);
mOpenSsid = null;
diff --git a/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java b/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java
index 2afe35bf2d4..9f81431829c 100644
--- a/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java
+++ b/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java
@@ -67,7 +67,7 @@ public class WifiPrivacyPreferenceController extends BasePreferenceController im
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (mWifiConfiguration != null) {
- //TODO(b/117957974): update MAC randomization level to WifiManager
+ mWifiConfiguration.macRandomizationSetting = Integer.parseInt((String) newValue);
mWifiManager.updateNetwork(mWifiConfiguration);
}
updateSummary((DropDownPreference) preference, Integer.parseInt((String) newValue));
@@ -77,10 +77,9 @@ public class WifiPrivacyPreferenceController extends BasePreferenceController im
@VisibleForTesting
int getRandomizationValue() {
if (mWifiConfiguration != null) {
- //TODO(b/117957974): get real MAC randomization level from WifiManager
- return 0;
+ return mWifiConfiguration.macRandomizationSetting;
}
- return 0;
+ return WifiConfiguration.RANDOMIZATION_PERSISTENT;
}
private void updateSummary(DropDownPreference preference, int macRandomized) {
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index 6f4deca9adc..479ffee26c8 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -15,7 +15,6 @@ com.android.settings.applications.appinfo.WriteSettingsDetails
com.android.settings.applications.AppLaunchSettings
com.android.settings.applications.AppStorageSettings
com.android.settings.applications.ConfirmConvertToFbe
-com.android.settings.applications.DirectoryAccessDetails
com.android.settings.applications.ProcessStatsDetail
com.android.settings.applications.ProcessStatsSummary
com.android.settings.applications.ProcessStatsUi
@@ -59,6 +58,7 @@ com.android.settings.notification.RedactionInterstitial$RedactionInterstitialFra
com.android.settings.notification.ZenModeEventRuleSettings
com.android.settings.notification.ZenModeScheduleRuleSettings
com.android.settings.password.ChooseLockGeneric$ChooseLockGenericFragment
+com.android.settings.password.SetupChooseLockGeneric$InternalActivity$InternalSetupChooseLockGenericFragment
com.android.settings.password.SetupChooseLockGeneric$SetupChooseLockGenericFragment
com.android.settings.print.PrintJobSettingsFragment
com.android.settings.print.PrintServiceSettingsFragment
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index 6347d7935c2..73d22647091 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -62,6 +62,8 @@
false
true
false
+ false
+ true
false
diff --git a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
index c72561ed59c..039d2e231d3 100644
--- a/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AvatarViewMixinTest.java
@@ -18,18 +18,22 @@ package com.android.settings.accounts;
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.accounts.Account;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.ProviderInfo;
+import android.content.pm.ResolveInfo;
import android.widget.ImageView;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
-import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
@@ -39,50 +43,92 @@ import org.robolectric.android.controller.ActivityController;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
+import org.robolectric.shadow.api.Shadow;
+import org.robolectric.shadows.ShadowPackageManager;
@RunWith(SettingsRobolectricTestRunner.class)
public class AvatarViewMixinTest {
private static final String DUMMY_ACCOUNT = "test@domain.com";
private static final String DUMMY_DOMAIN = "domain.com";
+ private static final String DUMMY_AUTHORITY = "authority.domain.com";
private Context mContext;
private ImageView mImageView;
+ private ActivityController mController;
+ private SettingsHomepageActivity mActivity;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mImageView = new ImageView(mContext);
+ mController = Robolectric.buildActivity(SettingsHomepageActivity.class).create();
+ mActivity = (SettingsHomepageActivity) mController.get();
}
@Test
public void hasAccount_useDefaultAccountData_returnFalse() {
- final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(mContext, mImageView);
+ final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(mActivity, mImageView);
assertThat(avatarViewMixin.hasAccount()).isFalse();
}
@Test
@Config(shadows = ShadowAccountFeatureProviderImpl.class)
public void hasAccount_useShadowAccountData_returnTrue() {
- final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(mContext, mImageView);
+ final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(mActivity, mImageView);
assertThat(avatarViewMixin.hasAccount()).isTrue();
}
@Test
- public void onStart_useMockAvatarViewMixin_shouldBeExecuted() {
- final AvatarViewMixin mockAvatar = spy(new AvatarViewMixin(mContext, mImageView));
+ public void onStart_configDisabled_doNothing() {
+ final AvatarViewMixin mixin = spy(new AvatarViewMixin(mActivity, mImageView));
+ mixin.onStart();
- final ActivityController controller = Robolectric.buildActivity(
- SettingsHomepageActivity.class).create();
- final SettingsHomepageActivity settingsHomepageActivity =
- (SettingsHomepageActivity) controller.get();
- settingsHomepageActivity.getLifecycle().addObserver(mockAvatar);
- controller.start();
-
- verify(mockAvatar).onStart();
+ verify(mixin, never()).hasAccount();
}
- @Implements(AccountFeatureProviderImpl.class)
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void onStart_useMockAvatarViewMixin_shouldBeExecuted() {
+ final AvatarViewMixin mockAvatar = spy(new AvatarViewMixin(mActivity, mImageView));
+
+ mActivity.getLifecycle().addObserver(mockAvatar);
+ mController.start();
+
+ verify(mockAvatar).hasAccount();
+ }
+
+ @Test
+ public void queryProviderAuthority_useShadowPackagteManager_returnNull() {
+ final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(mActivity, mImageView);
+
+ assertThat(avatarViewMixin.queryProviderAuthority()).isNull();
+ }
+
+ @Test
+ public void queryProviderAuthority_useNewShadowPackagteManager_returnAuthority() {
+ final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(mActivity, mImageView);
+ ShadowPackageManager shadowPackageManager = Shadow.extract(mContext.getPackageManager());
+ final PackageInfo accountProvider = new PackageInfo();
+ accountProvider.packageName = "test.pkg";
+ accountProvider.applicationInfo = new ApplicationInfo();
+ accountProvider.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
+ accountProvider.applicationInfo.packageName = accountProvider.packageName;
+ accountProvider.providers = new ProviderInfo[1];
+ accountProvider.providers[0] = new ProviderInfo();
+ accountProvider.providers[0].authority = DUMMY_AUTHORITY;
+ accountProvider.providers[0].packageName = accountProvider.packageName;
+ accountProvider.providers[0].name = "test.class";
+ accountProvider.providers[0].applicationInfo = accountProvider.applicationInfo;
+
+ final ResolveInfo resolveInfo = new ResolveInfo();
+ resolveInfo.providerInfo = accountProvider.providers[0];
+ shadowPackageManager.addResolveInfoForIntent(AvatarViewMixin.INTENT_GET_ACCOUNT_DATA,
+ resolveInfo);
+ assertThat(avatarViewMixin.queryProviderAuthority()).isEqualTo(DUMMY_AUTHORITY);
+ }
+
+ @Implements(value = AccountFeatureProviderImpl.class)
public static class ShadowAccountFeatureProviderImpl {
@Implementation
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceControllerTest.java
index a342e10c8be..d3e00c37159 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppHeaderViewPreferenceControllerTest.java
@@ -106,15 +106,12 @@ public class AppHeaderViewPreferenceControllerTest {
final TextView title = mHeader.findViewById(R.id.entity_header_title);
- final TextView summary = mHeader.findViewById(R.id.entity_header_summary);
mController.displayPreference(mScreen);
mController.refreshUi();
assertThat(title).isNotNull();
assertThat(title.getText()).isEqualTo(appLabel);
- assertThat(summary).isNotNull();
- assertThat(summary.getText()).isEqualTo(mContext.getString(R.string.installed));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/BluetoothOnWhileDrivingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/BluetoothOnWhileDrivingPreferenceControllerTest.java
deleted file mode 100644
index 83763bb4142..00000000000
--- a/tests/robotests/src/com/android/settings/connecteddevice/BluetoothOnWhileDrivingPreferenceControllerTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2018 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.connecteddevice;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.provider.Settings;
-import android.provider.Settings.Secure;
-import android.util.FeatureFlagUtils;
-
-import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.FeatureFlags;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RuntimeEnvironment;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-public class BluetoothOnWhileDrivingPreferenceControllerTest {
-
- private BluetoothOnWhileDrivingPreferenceController mController;
- private Context mContext;
-
- @Before
- public void setUp() {
- mContext = RuntimeEnvironment.application;
- mController = new BluetoothOnWhileDrivingPreferenceController(mContext);
- }
-
- @Test
- public void getAvailabilityStatus_onWhenEnabled() {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.BLUETOOTH_WHILE_DRIVING, true);
-
- assertThat(mController.getAvailabilityStatus())
- .isEqualTo(BasePreferenceController.AVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_offWhenDisabled() {
- assertThat(mController.getAvailabilityStatus())
- .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
- }
-
- @Test
- public void setChecked_togglesSettingSecure() {
- mController.setChecked(true);
-
- final String name = Secure.BLUETOOTH_ON_WHILE_DRIVING;
- assertThat(Settings.Secure.getInt(mContext.getContentResolver(), name, 0)).isEqualTo(1);
- }
-}
diff --git a/tests/robotests/src/com/android/settings/development/DesktopModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/DesktopModePreferenceControllerTest.java
new file mode 100644
index 00000000000..e6e8cb9e850
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/DesktopModePreferenceControllerTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2018 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 android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS;
+
+import static com.android.settings.development.DesktopModePreferenceController.SETTING_VALUE_OFF;
+import static com.android.settings.development.DesktopModePreferenceController.SETTING_VALUE_ON;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class DesktopModePreferenceControllerTest {
+
+ private static final String ENG_BUILD_TYPE = "eng";
+ private static final String USER_BUILD_TYPE = "user";
+
+ @Mock
+ private SwitchPreference mPreference;
+ @Mock
+ private PreferenceScreen mScreen;
+
+ private Context mContext;
+ private DesktopModePreferenceController mController;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new DesktopModePreferenceController(mContext);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ }
+
+ @Test
+ public void isAvailable_engBuild_shouldBeTrue() {
+ mController = spy(mController);
+ doReturn(ENG_BUILD_TYPE).when(mController).getBuildType();
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvaiable_userBuild_shouldBeTrue() {
+ mController = spy(mController);
+ doReturn(USER_BUILD_TYPE).when(mController).getBuildType();
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void onPreferenceChange_switchEnabled_shouldEnableFreeformWindows() {
+ mController.onPreferenceChange(mPreference, true /* new value */);
+
+ final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, -1 /* default */);
+ assertThat(mode).isEqualTo(SETTING_VALUE_ON);
+ }
+
+ @Test
+ public void onPreferenceChange_switchDisabled_shouldDisableFreeformWindows() {
+ mController.onPreferenceChange(mPreference, false /* new value */);
+
+ final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, -1 /* default */);
+ assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
+ }
+
+ @Test
+ public void updateState_settingEnabled_preferenceShouldBeChecked() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, SETTING_VALUE_ON);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(true);
+ }
+
+ @Test
+ public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
+ Settings.Global.putInt(mContext.getContentResolver(),
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, SETTING_VALUE_OFF);
+
+ mController.updateState(mPreference);
+
+ verify(mPreference).setChecked(false);
+ }
+
+ @Test
+ public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
+ mController.onDeveloperOptionsSwitchDisabled();
+
+ final int mode = Settings.Global.getInt(mContext.getContentResolver(),
+ DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS, -1 /* default */);
+ assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
+ verify(mPreference).setEnabled(false);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/development/FreeformWindowsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/FreeformWindowsPreferenceControllerTest.java
index b58f756169a..08fb23e885f 100644
--- a/tests/robotests/src/com/android/settings/development/FreeformWindowsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/FreeformWindowsPreferenceControllerTest.java
@@ -19,7 +19,6 @@ package com.android.settings.development;
import static com.android.settings.development.FreeformWindowsPreferenceController
.SETTING_VALUE_OFF;
import static com.android.settings.development.FreeformWindowsPreferenceController.SETTING_VALUE_ON;
-import static com.android.settings.development.FreeformWindowsPreferenceController.USER_BUILD_TYPE;
import static com.google.common.truth.Truth.assertThat;
@@ -47,6 +46,7 @@ import org.robolectric.RuntimeEnvironment;
public class FreeformWindowsPreferenceControllerTest {
private static final String ENG_BUILD_TYPE = "eng";
+ private static final String USER_BUILD_TYPE = "user";
@Mock
private SwitchPreference mPreference;
@@ -74,11 +74,11 @@ public class FreeformWindowsPreferenceControllerTest {
}
@Test
- public void isAvaiable_userBuild_shouldBeFalse() {
+ public void isAvaiable_userBuild_shouldBeTrue() {
mController = spy(mController);
doReturn(USER_BUILD_TYPE).when(mController).getBuildType();
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.isAvailable()).isTrue();
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/UpdatedGfxDriverDevOptInPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/UpdatedGfxDriverDevOptInPreferenceControllerTest.java
new file mode 100644
index 00000000000..307191200cb
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/UpdatedGfxDriverDevOptInPreferenceControllerTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2018 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 com.android.settings.development.DevelopmentOptionsActivityRequestCodes.REQUEST_CODE_UPDATED_GFX_DRIVER_DEV_OPT_IN_APP;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Activity;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.provider.Settings;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class UpdatedGfxDriverDevOptInPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+ @Mock
+ private DevelopmentSettingsDashboardFragment mFragment;
+
+ private Context mContext;
+ private Preference mPreference;
+ private UpdatedGfxDriverDevOptInPreferenceController mController;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = spy(new UpdatedGfxDriverDevOptInPreferenceController(mContext, mFragment));
+ mPreference = new Preference(mContext);
+ mPreference.setKey(mController.getPreferenceKey());
+
+ when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
+ .thenReturn(mPreference);
+ mController.displayPreference(mPreferenceScreen);
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_preferenceClicked_launchActivity() {
+ final Intent activityStartIntent = new Intent(mContext, AppPicker.class);
+ final String preferenceKey = mController.getPreferenceKey();
+ doReturn(activityStartIntent).when(mController).getActivityStartIntent();
+ mController.handlePreferenceTreeClick(mPreference);
+
+ verify(mFragment).startActivityForResult(activityStartIntent,
+ REQUEST_CODE_UPDATED_GFX_DRIVER_DEV_OPT_IN_APP);
+ }
+
+ @Test
+ public void updateState_foobarAppSelected_shouldUpdateSummaryWithUpdatedDriverDevOptInAppLabel() {
+ final String selectedApp = "foobar";
+ final ContentResolver contentResolver = mContext.getContentResolver();
+ Settings.Global.putString(contentResolver,
+ Settings.Global.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP, selectedApp);
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.updated_gfx_driver_dev_opt_in_app_set, selectedApp));
+ }
+
+ @Test
+ public void updateState_noAppSelected_shouldUpdateSummaryWithNoAppSelected() {
+ final String selectedApp = null;
+ final ContentResolver contentResolver = mContext.getContentResolver();
+ Settings.Global.putString(contentResolver,
+ Settings.Global.UPDATED_GFX_DRIVER_DEV_OPT_IN_APP, selectedApp);
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.updated_gfx_driver_dev_opt_in_app_not_set));
+ }
+
+ @Test
+ public void onActivityResult_foobarAppSelected_shouldUpdateSummaryWithUpdatedDriverDevOptInLabel() {
+ Intent activityResultIntent = new Intent(mContext, AppPicker.class);
+ final String appLabel = "foobar";
+ activityResultIntent.setAction(appLabel);
+ final boolean result = mController
+ .onActivityResult(REQUEST_CODE_UPDATED_GFX_DRIVER_DEV_OPT_IN_APP, Activity.RESULT_OK,
+ activityResultIntent);
+
+ assertThat(result).isTrue();
+ assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.updated_gfx_driver_dev_opt_in_app_set, appLabel));
+ }
+
+ @Test
+ public void onActivityResult_badRequestCode_shouldReturnFalse() {
+ assertThat(mController.onActivityResult(
+ -1 /* requestCode */, -1 /* resultCode */, null /* intent */)).isFalse();
+ }
+
+ @Test
+ public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
+ mController.onDeveloperOptionsSwitchDisabled();
+
+ assertThat(mPreference.isEnabled()).isFalse();
+ assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.updated_gfx_driver_dev_opt_in_app_not_set));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/deviceinfo/DeviceNameWarningDialogTest.java b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/DeviceNameWarningDialogTest.java
similarity index 72%
rename from tests/robotests/src/com/android/settings/deviceinfo/deviceinfo/DeviceNameWarningDialogTest.java
rename to tests/robotests/src/com/android/settings/deviceinfo/aboutphone/DeviceNameWarningDialogTest.java
index 0be0ac23762..6ea36a06836 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/deviceinfo/DeviceNameWarningDialogTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/DeviceNameWarningDialogTest.java
@@ -1,4 +1,20 @@
-package com.android.settings.deviceinfo.deviceinfo;
+/*
+ * Copyright (C) 2018 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.deviceinfo.aboutphone;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -6,8 +22,6 @@ import static org.mockito.Mockito.verify;
import android.content.DialogInterface;
-import com.android.settings.deviceinfo.aboutphone.DeviceNameWarningDialog;
-import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Test;
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/MyDeviceInfoFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragmentTest.java
similarity index 97%
rename from tests/robotests/src/com/android/settings/deviceinfo/MyDeviceInfoFragmentTest.java
rename to tests/robotests/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragmentTest.java
index 4a741cffb6a..e304a1e710d 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/MyDeviceInfoFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragmentTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.deviceinfo;
+package com.android.settings.deviceinfo.aboutphone;
import static com.android.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
@@ -35,7 +35,7 @@ import android.util.ArrayMap;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.PreferenceScreen;
-import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
+import com.android.settings.deviceinfo.BuildNumberPreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceControllerTest.java
new file mode 100644
index 00000000000..ae3007c9d84
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/aboutphone/TopLevelAboutDevicePreferenceControllerTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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.deviceinfo.aboutphone;
+
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.os.Build;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class TopLevelAboutDevicePreferenceControllerTest {
+
+ private Context mContext;
+ private TopLevelAboutDevicePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mController = new TopLevelAboutDevicePreferenceController(mContext, "test_key");
+ }
+
+ @Test
+ public void getAvailabilityState_shouldBeAvailable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getSummary_shouldReturnDeviceModel() {
+ assertThat(mController.getSummary().toString()).isEqualTo(Build.MODEL);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index b356c49de67..1a8d58dff09 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -258,7 +258,6 @@ public class AdvancedPowerUsageDetailTest {
verify(mEntityHeaderController).setIcon(mAppEntry);
verify(mEntityHeaderController).setLabel(mAppEntry);
verify(mEntityHeaderController).setIsInstantApp(true);
- verify(mEntityHeaderController).setSummary((CharSequence) null);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/CardDatabaseHelperTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/CardDatabaseHelperTest.java
index b25508b13d5..ef60f85ff62 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/CardDatabaseHelperTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/CardDatabaseHelperTest.java
@@ -18,10 +18,12 @@ package com.android.settings.homepage.contextualcards;
import static com.google.common.truth.Truth.assertThat;
+import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import com.android.settings.intelligence.ContextualCardProto;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.After;
@@ -30,6 +32,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
+import java.util.ArrayList;
+import java.util.List;
+
@RunWith(SettingsRobolectricTestRunner.class)
public class CardDatabaseHelperTest {
@@ -80,4 +85,38 @@ public class CardDatabaseHelperTest {
assertThat(columnNames).isEqualTo(expectedNames);
cursor.close();
}
+
+ @Test
+ public void getContextualCards_shouldSortByScore() {
+ insertFakeCard(mDatabase, "card1", 1, "uri1");
+ insertFakeCard(mDatabase, "card2", 0, "uri2");
+ insertFakeCard(mDatabase, "card3", 10, "uri3");
+ // Should sort as 3,1,2
+ try (final Cursor cursor = CardDatabaseHelper.getInstance(mContext).getContextualCards()) {
+ assertThat(cursor.getCount()).isEqualTo(3);
+ final List cards = new ArrayList<>();
+ for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
+ cards.add(new ContextualCard(cursor));
+ }
+ assertThat(cards.get(0).getName()).isEqualTo("card3");
+ assertThat(cards.get(1).getName()).isEqualTo("card1");
+ assertThat(cards.get(2).getName()).isEqualTo("card2");
+ }
+ }
+
+ private static void insertFakeCard(SQLiteDatabase db, String name, double score, String uri) {
+ final ContentValues value = new ContentValues();
+ value.put(CardDatabaseHelper.CardColumns.NAME, name);
+ value.put(CardDatabaseHelper.CardColumns.SCORE, score);
+ value.put(CardDatabaseHelper.CardColumns.SLICE_URI, uri);
+
+ value.put(CardDatabaseHelper.CardColumns.TYPE, ContextualCard.CardType.SLICE);
+ value.put(CardDatabaseHelper.CardColumns.CATEGORY,
+ ContextualCardProto.ContextualCard.Category.DEFAULT.getNumber());
+ value.put(CardDatabaseHelper.CardColumns.PACKAGE_NAME,
+ RuntimeEnvironment.application.getPackageName());
+ value.put(CardDatabaseHelper.CardColumns.APP_VERSION, 1);
+
+ db.insert(CardDatabaseHelper.CARD_TABLE, null, value);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/ConditionalContextualCardTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/ConditionalContextualCardTest.java
index 2cff9f26bce..74e88d7eebf 100644
--- a/tests/robotests/src/com/android/settings/homepage/contextualcards/ConditionalContextualCardTest.java
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/ConditionalContextualCardTest.java
@@ -30,7 +30,7 @@ public class ConditionalContextualCardTest {
@Test(expected = IllegalArgumentException.class)
public void newInstance_changeCardType_shouldCrash() {
new ConditionalContextualCard.Builder()
- .setCardType(ContextualCard.CardType.SUGGESTION)
+ .setCardType(ContextualCard.CardType.LEGACY_SUGGESTION)
.build();
}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java
new file mode 100644
index 00000000000..9d9d84e34a0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardControllerTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2018 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.homepage.contextualcards.legacysuggestion;
+
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+
+import com.android.settings.homepage.contextualcards.ContextualCardUpdateListener;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowThreadUtils;
+import com.android.settingslib.suggestions.SuggestionController;
+
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = ShadowThreadUtils.class)
+public class LegacySuggestionContextualCardControllerTest {
+
+ @Mock
+ private SuggestionController mSuggestionController;
+ @Mock
+ private ContextualCardUpdateListener mCardUpdateListener;
+
+ private Context mContext;
+ private LegacySuggestionContextualCardController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest();
+ mContext = RuntimeEnvironment.application;
+ mController = new LegacySuggestionContextualCardController(mContext);
+ }
+
+ @Test
+ public void init_configOn_shouldCreateSuggestionController() {
+ final LegacySuggestionContextualCardController controller =
+ new LegacySuggestionContextualCardController(mContext);
+ assertThat(controller.mSuggestionController).isNotNull();
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void init_configOff_shouldNotCreateSuggestionController() {
+ final LegacySuggestionContextualCardController controller =
+ new LegacySuggestionContextualCardController(mContext);
+
+ assertThat(controller.mSuggestionController).isNull();
+ }
+
+ @Test
+ public void goThroughLifecycle_hasSuggestionController_shouldStartStopController() {
+ mController.mSuggestionController = mSuggestionController;
+ mController.onStart();
+ verify(mSuggestionController).start();
+
+ mController.onStop();
+ verify(mSuggestionController).stop();
+ }
+
+ @Test
+ public void onServiceConnected_shouldLoadSuggestion() {
+ mController.mSuggestionController = mSuggestionController;
+ mController.setCardUpdateListener(mCardUpdateListener);
+ mController.onServiceConnected();
+
+ verify(mSuggestionController).getSuggestions();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardRendererTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardRendererTest.java
new file mode 100644
index 00000000000..20f1b7bbfe0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardRendererTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2018 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.homepage.contextualcards.legacysuggestion;
+
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.settings.R;
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.homepage.contextualcards.ControllerRendererPool;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class LegacySuggestionContextualCardRendererTest {
+ @Mock
+ private ControllerRendererPool mControllerRendererPool;
+ @Mock
+ private LegacySuggestionContextualCardController mController;
+ private Context mContext;
+ private LegacySuggestionContextualCardRenderer mRenderer;
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mRenderer = new LegacySuggestionContextualCardRenderer(mContext, mControllerRendererPool);
+ }
+
+ @Test
+ public void bindView_shouldSetListener() {
+ final int viewType = mRenderer.getViewType(true /* isHalfWidth */);
+ final RecyclerView recyclerView = new RecyclerView(mContext);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
+ final View card = LayoutInflater.from(mContext).inflate(viewType, recyclerView, false);
+ final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(card);
+
+ when(mControllerRendererPool.getController(mContext,
+ ContextualCard.CardType.LEGACY_SUGGESTION)).thenReturn(mController);
+
+ mRenderer.bindView(viewHolder, buildContextualCard());
+
+ assertThat(card).isNotNull();
+ assertThat(card.hasOnClickListeners()).isTrue();
+ }
+
+ @Test
+ public void viewClick_shouldInvokeControllerPrimaryClick() {
+ final int viewType = mRenderer.getViewType(true /* isHalfWidth */);
+ final RecyclerView recyclerView = new RecyclerView(mContext);
+ recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
+ final View card = LayoutInflater.from(mContext).inflate(viewType, recyclerView, false);
+ final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(card);
+ when(mControllerRendererPool.getController(mContext,
+ ContextualCard.CardType.LEGACY_SUGGESTION)).thenReturn(mController);
+
+ mRenderer.bindView(viewHolder, buildContextualCard());
+
+ assertThat(card).isNotNull();
+ card.performClick();
+
+ verify(mController).onPrimaryClick(any(ContextualCard.class));
+ }
+
+ private ContextualCard buildContextualCard() {
+ return new LegacySuggestionContextualCard.Builder()
+ .setName("test_name")
+ .setTitleText("test_title")
+ .setSummaryText("test_summary")
+ .setIconDrawable(mContext.getDrawable(R.drawable.ic_do_not_disturb_on_24dp))
+ .build();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardTest.java
new file mode 100644
index 00000000000..8b9a7a9aaca
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/legacysuggestion/LegacySuggestionContextualCardTest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 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.homepage.contextualcards.legacysuggestion;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+
+import android.app.PendingIntent;
+
+import com.android.settings.homepage.contextualcards.ContextualCard;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class LegacySuggestionContextualCardTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void newInstance_changeCardType_shouldCrash() {
+ new LegacySuggestionContextualCard.Builder()
+ .setCardType(ContextualCard.CardType.CONDITIONAL)
+ .build();
+ }
+
+ @Test
+ public void getCardType_shouldAlwaysBeSuggestionType() {
+ assertThat(new LegacySuggestionContextualCard.Builder().build().getCardType())
+ .isEqualTo(ContextualCard.CardType.LEGACY_SUGGESTION);
+ }
+
+ @Test
+ public void build_shouldSetPendingIntent() {
+ assertThat(new LegacySuggestionContextualCard.Builder()
+ .setPendingIntent(mock(PendingIntent.class))
+ .build()
+ .getPendingIntent()).isNotNull();
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
index 676c9f4f23d..8a57a0cc751 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/MobileNetworkUtilsTest.java
@@ -165,7 +165,8 @@ public class MobileNetworkUtilsTest {
@Test
public void isCdmaOptions_worldModeWithGsmWcdma_returnTrue() {
when(mTelephonyManager.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_GSM);
- when(mContext.getString(R.string.config_world_mode)).thenReturn("true");
+ mCarrierConfig.putBoolean(CarrierConfigManager.KEY_WORLD_MODE_ENABLED_BOOL, true);
+
Settings.Global.putInt(mContext.getContentResolver(),
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + SUB_ID_1,
TelephonyManager.NETWORK_MODE_LTE_GSM_WCDMA);
diff --git a/tests/robotests/src/com/android/settings/print/PrintJobMessagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/print/PrintJobMessagePreferenceControllerTest.java
new file mode 100644
index 00000000000..50dd38b183b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/print/PrintJobMessagePreferenceControllerTest.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2018 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.print;
+
+import static androidx.lifecycle.Lifecycle.Event.ON_START;
+import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.print.PrintJob;
+import android.print.PrintJobInfo;
+import android.print.PrintManager;
+
+import androidx.lifecycle.LifecycleOwner;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class PrintJobMessagePreferenceControllerTest {
+ private static final String PREF_KEY = "print_job_message_preference";
+
+ @Mock
+ private PrintManager mPrintManager;
+ @Mock
+ private PrintJob mPrintJob;
+ @Mock
+ private PrintJobInfo mPrintJobInfo;
+ @Mock
+ private PreferenceScreen mScreen;
+
+ private Context mContext;
+ private PrintJobMessagePreferenceController mController;
+ private Preference mPreference;
+ private LifecycleOwner mLifecycleOwner;
+ private Lifecycle mLifecycle;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ mPreference = new Preference(mContext);
+ when(mContext.getSystemService(Context.PRINT_SERVICE)).thenReturn(mPrintManager);
+ when(mPrintManager.getGlobalPrintManagerForUser(anyInt())).thenReturn(mPrintManager);
+ when(mPrintManager.getPrintJob(anyObject())).thenReturn(mPrintJob);
+ when(mPrintJob.getInfo()).thenReturn(mPrintJobInfo);
+ mController = new PrintJobMessagePreferenceController(mContext, PREF_KEY);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ mController.displayPreference(mScreen);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
+ mLifecycle.addObserver(mController);
+ }
+
+ @Test
+ public void onStartStop_shouldRegisterPrintStateListener() {
+ mLifecycle.handleLifecycleEvent(ON_START);
+ mLifecycle.handleLifecycleEvent(ON_STOP);
+
+ verify(mPrintManager).addPrintJobStateChangeListener(mController);
+ verify(mPrintManager).removePrintJobStateChangeListener(mController);
+ }
+
+ @Test
+ public void updateUi_visiblePreference() {
+ when(mPrintJobInfo.getStatus(anyObject())).thenReturn("TestPrint");
+ mLifecycle.handleLifecycleEvent(ON_START);
+
+ assertThat(mPreference.isVisible()).isTrue();
+
+ mLifecycle.handleLifecycleEvent(ON_STOP);
+ }
+
+ @Test
+ public void updateUi_invisiblePreference() {
+ when(mPrintJobInfo.getStatus(anyObject())).thenReturn(null);
+ mLifecycle.handleLifecycleEvent(ON_START);
+
+ assertThat(mPreference.isVisible()).isFalse();
+
+ mLifecycle.handleLifecycleEvent(ON_STOP);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/print/PrintJobPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/print/PrintJobPreferenceControllerTest.java
new file mode 100644
index 00000000000..fc92eb3cc8f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/print/PrintJobPreferenceControllerTest.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2018 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.print;
+
+import static androidx.lifecycle.Lifecycle.Event.ON_START;
+import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.print.PrintJob;
+import android.print.PrintJobInfo;
+import android.print.PrintManager;
+
+import androidx.lifecycle.LifecycleOwner;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+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;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class PrintJobPreferenceControllerTest {
+ private static final String PREF_KEY = "print_job_preference";
+
+ @Mock
+ private PrintManager mPrintManager;
+ @Mock
+ private PrintJob mPrintJob;
+ @Mock
+ private PrintJobInfo mPrintJobInfo;
+ @Mock
+ private PreferenceScreen mScreen;
+
+ private Context mContext;
+ private LifecycleOwner mLifecycleOwner;
+ private Lifecycle mLifecycle;
+ private PrintJobPreferenceController mController;
+ private Preference mPreference;
+ private String mTestLabel;
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ mPreference = new Preference(mContext);
+ mTestLabel = "PrintTest";
+ when(mContext.getSystemService(Context.PRINT_SERVICE)).thenReturn(mPrintManager);
+ when(mPrintManager.getGlobalPrintManagerForUser(anyInt())).thenReturn(mPrintManager);
+ when(mPrintManager.getPrintJob(anyObject())).thenReturn(mPrintJob);
+ when(mPrintJob.getInfo()).thenReturn(mPrintJobInfo);
+ mController = new PrintJobPreferenceController(mContext, PREF_KEY);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ when(mPrintJobInfo.getLabel()).thenReturn(mTestLabel);
+ mController.displayPreference(mScreen);
+ mLifecycleOwner = () -> mLifecycle;
+ mLifecycle = new Lifecycle(mLifecycleOwner);
+ mLifecycle.addObserver(mController);
+ }
+
+ @Test
+ public void onStartStop_shouldRegisterPrintStateListener() {
+ mLifecycle.handleLifecycleEvent(ON_START);
+ mLifecycle.handleLifecycleEvent(ON_STOP);
+
+ verify(mPrintManager).addPrintJobStateChangeListener(mController);
+ verify(mPrintManager).removePrintJobStateChangeListener(mController);
+ }
+
+ @Test
+ public void updateUi_jobState_STATE_CREATED() {
+ when(mPrintJobInfo.getState()).thenReturn(PrintJobInfo.STATE_CREATED);
+
+ mController.onStart();
+ String title = mContext.getString(
+ R.string.print_configuring_state_title_template, mTestLabel);
+
+ assertThat(mPreference.getTitle()).isEqualTo(title);
+ }
+
+ @Test
+ public void updateUi_jobState_STATE_QUEUED() {
+ when(mPrintJobInfo.getState()).thenReturn(PrintJobInfo.STATE_QUEUED);
+
+ mController.onStart();
+ String title = mContext.getString(
+ R.string.print_printing_state_title_template, mTestLabel);
+
+ assertThat(mPreference.getTitle()).isEqualTo(title);
+ }
+
+ @Test
+ public void updateUi_jobState_STATE_STARTED() {
+ when(mPrintJobInfo.getState()).thenReturn(PrintJobInfo.STATE_STARTED);
+
+ mController.onStart();
+ String title = mContext.getString(
+ R.string.print_printing_state_title_template, mTestLabel);
+
+ assertThat(mPreference.getTitle()).isEqualTo(title);
+ }
+
+ @Test
+ public void updateUi_jobState_STATE_QUEUED_and_jobInfo_CANCELLING() {
+ when(mPrintJobInfo.getState()).thenReturn(PrintJobInfo.STATE_QUEUED);
+ when(mPrintJobInfo.isCancelling()).thenReturn(true);
+
+ mController.onStart();
+ String title = mContext.getString(
+ R.string.print_cancelling_state_title_template, mTestLabel);
+
+ assertThat(mPreference.getTitle()).isEqualTo(title);
+ }
+
+ @Test
+ public void updateUi_jobState_STATE_STARTED_and_jobInfo_CANCELLING() {
+ when(mPrintJobInfo.getState()).thenReturn(PrintJobInfo.STATE_STARTED);
+ when(mPrintJobInfo.isCancelling()).thenReturn(true);
+
+ mController.onStart();
+ String title = mContext.getString(
+ R.string.print_cancelling_state_title_template, mTestLabel);
+
+ assertThat(mPreference.getTitle()).isEqualTo(title);
+ }
+
+ @Test
+ public void updateUi_jobState_STATE_FAILED() {
+ when(mPrintJobInfo.getState()).thenReturn(PrintJobInfo.STATE_FAILED);
+
+ mController.onStart();
+ String title = mContext.getString(
+ R.string.print_failed_state_title_template, mTestLabel);
+
+ assertThat(mPreference.getTitle()).isEqualTo(title);
+ }
+
+ @Test
+ public void updateUi_jobState_STATE_BLOCKED() {
+ when(mPrintJobInfo.getState()).thenReturn(PrintJobInfo.STATE_BLOCKED);
+
+ mController.onStart();
+ String title = mContext.getString(
+ R.string.print_blocked_state_title_template, mTestLabel);
+
+ assertThat(mPreference.getTitle()).isEqualTo(title);
+ }
+
+ @Test
+ public void updateUi_jobState_STATE_BLOCKED_and_jobInfo_CANCELLING() {
+ when(mPrintJobInfo.getState()).thenReturn(PrintJobInfo.STATE_BLOCKED);
+ when(mPrintJobInfo.isCancelling()).thenReturn(true);
+
+ mController.onStart();
+ String title = mContext.getString(
+ R.string.print_cancelling_state_title_template, mTestLabel);
+
+ assertThat(mPreference.getTitle()).isEqualTo(title);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java
index f8131850fe3..e8d13dfe218 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java
@@ -66,7 +66,7 @@ public class WifiTetherSecurityPreferenceControllerTest {
public void onPreferenceChange_securityValueUpdated() {
mController.onPreferenceChange(mPreference, WPA2_PSK);
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
- assertThat(mPreference.getSummary()).isEqualTo("WPA2 PSK");
+ assertThat(mPreference.getSummary()).isEqualTo("WPA2-Personal");
mController.onPreferenceChange(mPreference, NONE);
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.NONE);
@@ -75,11 +75,11 @@ public class WifiTetherSecurityPreferenceControllerTest {
@Test
public void updateDisplay_preferenceUpdated() {
- // test defaulting to WPA2 PSK on new config
+ // test defaulting to WPA2-Personal on new config
when(mWifiManager.getWifiApConfiguration()).thenReturn(null);
mController.updateDisplay();
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
- assertThat(mPreference.getSummary()).isEqualTo("WPA2 PSK");
+ assertThat(mPreference.getSummary()).isEqualTo("WPA2-Personal");
// test open tether network
when(mWifiManager.getWifiApConfiguration()).thenReturn(mConfig);
@@ -89,11 +89,11 @@ public class WifiTetherSecurityPreferenceControllerTest {
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.NONE);
assertThat(mPreference.getSummary()).isEqualTo("None");
- // test WPA2 PSK tether network
+ // test WPA2-Personal tether network
mConfig.allowedKeyManagement.clear();
mConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
mController.updateDisplay();
assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
- assertThat(mPreference.getSummary()).isEqualTo("WPA2 PSK");
+ assertThat(mPreference.getSummary()).isEqualTo("WPA2-Personal");
}
}
diff --git a/tests/uitests/assets/search_results_list b/tests/uitests/assets/search_results_list
index a0cc894f705..6f7c5136a4a 100644
--- a/tests/uitests/assets/search_results_list
+++ b/tests/uitests/assets/search_results_list
@@ -166,7 +166,6 @@ Device name;device_name
Device security;security_category
Device theme;theme
Dial pad tones;dial_pad_tones
-Directory access;special_app_directory_access
Disable Bluetooth A2DP hardware offload;bluetooth_disable_a2dp_hw_offload
Disable HW overlays;disable_overlays
Disable USB audio routing;usb_audio
@@ -236,6 +235,7 @@ Force 4x MSAA;force_msaa
Force RTL layout direction;force_rtl_layout_all_locales
Force activities to be resizable;force_resizable_activities
Force allow apps on external;force_allow_on_external
+Force desktop mode;force_desktop_mode_on_external_displays
Force full GNSS measurements;enable_gnss_raw_meas_full_tracking
Free up space;storage_settings_free_space
Games;pref_games
@@ -620,4 +620,4 @@ Your access to this device;device_access_category
;auto_brightness_video
;battery_header
;battery_tip
- ;feature_flag_category
\ No newline at end of file
+ ;feature_flag_category
diff --git a/tests/unit/src/com/android/settings/password/SetupChooseLockGenericTest.java b/tests/unit/src/com/android/settings/password/SetupChooseLockGenericTest.java
new file mode 100644
index 00000000000..ce3d08f0b1d
--- /dev/null
+++ b/tests/unit/src/com/android/settings/password/SetupChooseLockGenericTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 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.password;
+
+import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD;
+import static android.support.test.InstrumentationRegistry.getInstrumentation;
+import static android.support.test.InstrumentationRegistry.getTargetContext;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.provider.Settings;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
+import android.support.test.runner.lifecycle.Stage;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiSelector;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Collection;
+
+/**
+ * Tests for {@link SetupChooseLockGenericTest}
+ *
+ */
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class SetupChooseLockGenericTest {
+
+ private UiDevice mDevice;
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mDevice = UiDevice.getInstance(getInstrumentation());
+ mContext = getInstrumentation().getTargetContext();
+ Settings.Global.putInt(
+ mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0);
+ }
+
+ @After
+ public void tearDown() {
+ Settings.Global.putInt(
+ mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
+ }
+
+ @Test
+ public void clickSkipFigerprintPreference_deviceNotProvisioned_shouldBeAbleToProceed()
+ throws Throwable {
+ final Intent newPasswordIntent =
+ new Intent(getTargetContext(), SetupChooseLockGeneric.class)
+ .putExtra(ChooseLockSettingsHelper.EXTRA_KEY_FOR_FINGERPRINT, true)
+ .setAction(ACTION_SET_NEW_PASSWORD)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+
+ getInstrumentation().getContext().startActivity(newPasswordIntent);
+ mDevice.waitForIdle();
+ mDevice.findObject(new UiSelector().textContains("Continue without ")).click();
+
+ final Activity activity = getCurrentActivity();
+ assertThat(activity).isInstanceOf(SetupChooseLockGeneric.InternalActivity.class);
+ }
+
+ private Activity getCurrentActivity() throws Throwable {
+ getInstrumentation().waitForIdleSync();
+ final Activity[] activity = new Activity[1];
+ getInstrumentation().runOnMainSync(() -> {
+ Collection activities = ActivityLifecycleMonitorRegistry.getInstance()
+ .getActivitiesInStage(Stage.RESUMED);
+ activity[0] = activities.iterator().next();
+ });
+ return activity[0];
+ }
+
+}