diff --git a/color-check-baseline.xml b/color-check-baseline.xml index 3ebe9b13117..768929b6b98 100644 --- a/color-check-baseline.xml +++ b/color-check-baseline.xml @@ -1025,6 +1025,22 @@ column="5"/> + + + + @@ -1053,7 +1069,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1069,7 +1085,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1085,7 +1101,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1101,7 +1117,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1117,7 +1133,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1133,7 +1149,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1149,7 +1165,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1165,7 +1181,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1181,7 +1197,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1197,7 +1213,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1213,7 +1229,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1229,7 +1245,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1245,7 +1261,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1261,7 +1277,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1277,7 +1293,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1293,7 +1309,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1309,7 +1325,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1325,7 +1341,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1341,7 +1357,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1357,7 +1373,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1373,7 +1389,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1389,7 +1405,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1405,7 +1421,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1421,7 +1437,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1437,7 +1453,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1453,7 +1469,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1469,7 +1485,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1485,7 +1501,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1501,7 +1517,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1517,7 +1533,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1533,7 +1549,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1549,7 +1565,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1565,7 +1581,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1581,7 +1597,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1597,7 +1613,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1613,7 +1629,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1629,7 +1645,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1645,7 +1661,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1661,7 +1677,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1677,7 +1693,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1693,7 +1709,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1709,7 +1725,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1725,7 +1741,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1741,7 +1757,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1757,7 +1773,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1773,7 +1789,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1789,7 +1805,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1805,7 +1821,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1821,7 +1837,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1837,7 +1853,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -1853,7 +1869,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2561,6 +2577,22 @@ column="13"/> + + + + diff --git a/res/drawable/ic_homepage_wallpaper.xml b/res/drawable/ic_homepage_wallpaper.xml new file mode 100644 index 00000000000..0f914652c9e --- /dev/null +++ b/res/drawable/ic_homepage_wallpaper.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + diff --git a/res/drawable/ic_settings_wallpaper_white.xml b/res/drawable/ic_settings_wallpaper_white.xml new file mode 100644 index 00000000000..8591fb5c06e --- /dev/null +++ b/res/drawable/ic_settings_wallpaper_white.xml @@ -0,0 +1,25 @@ + + + + diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 3528f9f17b2..183dd1e579d 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -222,6 +222,10 @@ + + @string/wifi_security_sae + + @string/wifi_security_psk_sae @string/wifi_security_wpa2 @@ -230,6 +234,10 @@ + + 3 + + 2 1 diff --git a/res/values/colors.xml b/res/values/colors.xml index 2ce3949d34c..c858cb324ff 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -99,6 +99,7 @@ #2EC7DC #6F86DA #5E97F6 + #E51AD1 #1f000000 @*android:color/material_grey_100 diff --git a/res/xml/emergency_settings.xml b/res/xml/emergency_settings.xml index 41b503ecf7f..31c209bf375 100644 --- a/res/xml/emergency_settings.xml +++ b/res/xml/emergency_settings.xml @@ -23,15 +23,18 @@ android:key="emergency_info" android:title="@string/emergency_info_title" android:summary="@string/summary_placeholder" + android:order="0" settings:controller="com.android.settings.accounts.EmergencyInfoPreferenceController"/> { + roleControllerManager.isRoleVisible(mRoleName, executor, visible -> { mRoleVisible = visible; refreshAvailability(); }); - mRoleManager.isApplicationVisibleForRole(mRoleName, mPackageName, executor, + roleControllerManager.isApplicationVisibleForRole(mRoleName, mPackageName, executor, visible -> { mAppVisible = visible; refreshAvailability(); diff --git a/src/com/android/settings/emergency/EmergencyDashboardFragment.java b/src/com/android/settings/emergency/EmergencyDashboardFragment.java index c786767a559..19834309300 100644 --- a/src/com/android/settings/emergency/EmergencyDashboardFragment.java +++ b/src/com/android/settings/emergency/EmergencyDashboardFragment.java @@ -44,7 +44,7 @@ public class EmergencyDashboardFragment extends DashboardFragment { @Override public int getMetricsCategory() { - return SettingsEnums.EMERGENCY_SOS_GESTURE_SETTINGS; + return SettingsEnums.EMERGENCY_SETTINGS; } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = diff --git a/src/com/android/settings/homepage/contextualcards/slices/FaceSetupSlice.java b/src/com/android/settings/homepage/contextualcards/slices/FaceSetupSlice.java index 2e348240172..0ad241e7431 100644 --- a/src/com/android/settings/homepage/contextualcards/slices/FaceSetupSlice.java +++ b/src/com/android/settings/homepage/contextualcards/slices/FaceSetupSlice.java @@ -143,7 +143,7 @@ public class FaceSetupSlice implements CustomSliceable { private static RowBuilder buildRowBuilder(CharSequence title, CharSequence subTitle, IconCompat icon, Context context, Intent intent) { final SliceAction primarySliceAction = SliceAction.createDeeplink( - PendingIntent.getActivity(context, 0, intent, 0), icon, ListBuilder.ICON_IMAGE, + PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED), icon, ListBuilder.ICON_IMAGE, title); return new RowBuilder() .setTitleItem(icon, ListBuilder.ICON_IMAGE) diff --git a/src/com/android/settings/media/BluetoothPairingReceiver.java b/src/com/android/settings/media/BluetoothPairingReceiver.java index 5b578003941..1ec99b00598 100644 --- a/src/com/android/settings/media/BluetoothPairingReceiver.java +++ b/src/com/android/settings/media/BluetoothPairingReceiver.java @@ -25,7 +25,7 @@ import android.text.TextUtils; import com.android.settings.R; import com.android.settings.bluetooth.BluetoothPairingDetail; import com.android.settings.core.SubSettingLauncher; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; /** * BroadcastReceiver for handling media output intent @@ -33,7 +33,7 @@ import com.android.settingslib.media.MediaOutputSliceConstants; public class BluetoothPairingReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (TextUtils.equals(MediaOutputSliceConstants.ACTION_LAUNCH_BLUETOOTH_PAIRING, + if (TextUtils.equals(MediaOutputConstants.ACTION_LAUNCH_BLUETOOTH_PAIRING, intent.getAction())) { context.startActivity(new SubSettingLauncher(context) .setDestination(BluetoothPairingDetail.class.getName()) diff --git a/src/com/android/settings/media/MediaOutputIndicatorSlice.java b/src/com/android/settings/media/MediaOutputIndicatorSlice.java index 69e5dde4dbe..10a8b792d56 100644 --- a/src/com/android/settings/media/MediaOutputIndicatorSlice.java +++ b/src/com/android/settings/media/MediaOutputIndicatorSlice.java @@ -36,7 +36,7 @@ import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.slices.CustomSliceable; import com.android.settings.slices.SliceBackgroundWorker; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; public class MediaOutputIndicatorSlice implements CustomSliceable { @@ -128,15 +128,15 @@ public class MediaOutputIndicatorSlice implements CustomSliceable { } // Launch media output dialog mContext.sendBroadcast(new Intent() - .setPackage(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME) - .setAction(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG) - .putExtra(MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN, + .setPackage(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME) + .setAction(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG) + .putExtra(MediaOutputConstants.KEY_MEDIA_SESSION_TOKEN, mediaController.getSessionToken()) - .putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME, + .putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, mediaController.getPackageName())); // Dismiss volume panel mContext.sendBroadcast(new Intent() - .setPackage(MediaOutputSliceConstants.SETTINGS_PACKAGE_NAME) - .setAction(MediaOutputSliceConstants.ACTION_CLOSE_PANEL)); + .setPackage(MediaOutputConstants.SETTINGS_PACKAGE_NAME) + .setAction(MediaOutputConstants.ACTION_CLOSE_PANEL)); } } diff --git a/src/com/android/settings/media/RemoteMediaSlice.java b/src/com/android/settings/media/RemoteMediaSlice.java index 839dc4f1bfd..e69c0050145 100644 --- a/src/com/android/settings/media/RemoteMediaSlice.java +++ b/src/com/android/settings/media/RemoteMediaSlice.java @@ -48,7 +48,7 @@ import com.android.settings.slices.CustomSliceable; import com.android.settings.slices.SliceBackgroundWorker; import com.android.settings.slices.SliceBroadcastReceiver; import com.android.settings.slices.SliceBuilderUtils; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; import java.util.List; @@ -86,14 +86,14 @@ public class RemoteMediaSlice implements CustomSliceable { // Launch Media Output Dialog final RoutingSessionInfo info = intent.getParcelableExtra(SESSION_INFO); mContext.sendBroadcast(new Intent() - .setPackage(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME) - .setAction(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG) - .putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME, + .setPackage(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME) + .setAction(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG) + .putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, info.getClientPackageName())); // Dismiss volume panel mContext.sendBroadcast(new Intent() - .setPackage(MediaOutputSliceConstants.SETTINGS_PACKAGE_NAME) - .setAction(MediaOutputSliceConstants.ACTION_CLOSE_PANEL)); + .setPackage(MediaOutputConstants.SETTINGS_PACKAGE_NAME) + .setAction(MediaOutputConstants.ACTION_CLOSE_PANEL)); } } diff --git a/src/com/android/settings/network/telephony/EuiccOperationSidecar.java b/src/com/android/settings/network/telephony/EuiccOperationSidecar.java index c82220edeca..a637cc2339f 100644 --- a/src/com/android/settings/network/telephony/EuiccOperationSidecar.java +++ b/src/com/android/settings/network/telephony/EuiccOperationSidecar.java @@ -99,7 +99,7 @@ public abstract class EuiccOperationSidecar extends SidecarFragment { Intent intent = new Intent(getReceiverAction()); intent.putExtra(EXTRA_OP_ID, mOpId); return PendingIntent.getBroadcast( - getContext(), REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT); + getContext(), REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); } @Override diff --git a/src/com/android/settings/network/telephony/MobileDataSlice.java b/src/com/android/settings/network/telephony/MobileDataSlice.java index c3b08d38bfa..7c9bac0cf06 100644 --- a/src/com/android/settings/network/telephony/MobileDataSlice.java +++ b/src/com/android/settings/network/telephony/MobileDataSlice.java @@ -173,7 +173,7 @@ public class MobileDataSlice implements CustomSliceable { private PendingIntent getPrimaryAction() { final Intent intent = getIntent(); return PendingIntent.getActivity(mContext, 0 /* requestCode */, - intent, 0 /* flags */); + intent, PendingIntent.FLAG_MUTABLE_UNAUDITED /* flags */); } /** diff --git a/src/com/android/settings/notification/RemoteVolumeGroupController.java b/src/com/android/settings/notification/RemoteVolumeGroupController.java index eaff9e1c250..dd6f5160122 100644 --- a/src/com/android/settings/notification/RemoteVolumeGroupController.java +++ b/src/com/android/settings/notification/RemoteVolumeGroupController.java @@ -34,7 +34,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnDestroy; import com.android.settingslib.media.LocalMediaManager; import com.android.settingslib.media.MediaDevice; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; import com.android.settingslib.utils.ThreadUtils; import java.util.ArrayList; @@ -196,9 +196,9 @@ public class RemoteVolumeGroupController extends BasePreferenceController implem if (TextUtils.equals(info.getId(), preference.getKey().substring(SWITCHER_PREFIX.length()))) { final Intent intent = new Intent() - .setAction(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG) - .setPackage(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME) - .putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME, + .setAction(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG) + .setPackage(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME) + .putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, info.getClientPackageName()); mContext.sendBroadcast(intent); return true; diff --git a/src/com/android/settings/panel/SettingsPanelActivity.java b/src/com/android/settings/panel/SettingsPanelActivity.java index b7b15192354..856dc35c6ec 100644 --- a/src/com/android/settings/panel/SettingsPanelActivity.java +++ b/src/com/android/settings/panel/SettingsPanelActivity.java @@ -16,7 +16,7 @@ package com.android.settings.panel; -import static com.android.settingslib.media.MediaOutputSliceConstants.EXTRA_PACKAGE_NAME; +import static com.android.settingslib.media.MediaOutputConstants.EXTRA_PACKAGE_NAME; import android.content.Intent; import android.content.res.Configuration; diff --git a/src/com/android/settings/panel/VolumePanel.java b/src/com/android/settings/panel/VolumePanel.java index b5e807d8fa7..3e6d1ce958d 100644 --- a/src/com/android/settings/panel/VolumePanel.java +++ b/src/com/android/settings/panel/VolumePanel.java @@ -38,7 +38,7 @@ import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import com.android.settings.R; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; import java.util.ArrayList; import java.util.List; @@ -55,7 +55,7 @@ public class VolumePanel implements PanelContent, LifecycleObserver { private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (MediaOutputSliceConstants.ACTION_CLOSE_PANEL.equals(intent.getAction())) { + if (MediaOutputConstants.ACTION_CLOSE_PANEL.equals(intent.getAction())) { mCallback.forceClose(); } } @@ -73,7 +73,7 @@ public class VolumePanel implements PanelContent, LifecycleObserver { @OnLifecycleEvent(ON_RESUME) public void onResume() { final IntentFilter filter = new IntentFilter(); - filter.addAction(MediaOutputSliceConstants.ACTION_CLOSE_PANEL); + filter.addAction(MediaOutputConstants.ACTION_CLOSE_PANEL); mContext.registerReceiver(mReceiver, filter); } diff --git a/src/com/android/settings/sim/SimSelectNotification.java b/src/com/android/settings/sim/SimSelectNotification.java index 8d5a3e05c44..b4bd4096da1 100644 --- a/src/com/android/settings/sim/SimSelectNotification.java +++ b/src/com/android/settings/sim/SimSelectNotification.java @@ -226,7 +226,7 @@ public class SimSelectNotification extends BroadcastReceiver { resultIntent.setPackage(SETTINGS_PACKAGE_NAME); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); @@ -264,7 +264,7 @@ public class SimSelectNotification extends BroadcastReceiver { resultIntent.putExtra(Settings.EXTRA_SUB_ID, subId); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); builder.setContentIntent(resultPendingIntent); // Notify the notification. @@ -312,7 +312,7 @@ public class SimSelectNotification extends BroadcastReceiver { resultIntent.putExtra(Intent.EXTRA_TEXT, "help_uri_sim_combination_warning"); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = diff --git a/src/com/android/settings/slices/CustomSliceRegistry.java b/src/com/android/settings/slices/CustomSliceRegistry.java index be71b308a44..e40b164e966 100644 --- a/src/com/android/settings/slices/CustomSliceRegistry.java +++ b/src/com/android/settings/slices/CustomSliceRegistry.java @@ -46,7 +46,7 @@ import com.android.settings.notification.zen.ZenModeButtonPreferenceController; import com.android.settings.wifi.calling.WifiCallingSliceHelper; import com.android.settings.wifi.slice.ContextualWifiSlice; import com.android.settings.wifi.slice.WifiSlice; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; import java.util.Map; @@ -293,7 +293,7 @@ public class CustomSliceRegistry { .scheme(ContentResolver.SCHEME_CONTENT) .authority(SettingsSliceProvider.SLICE_AUTHORITY) .appendPath(SettingsSlicesContract.PATH_SETTING_ACTION) - .appendPath(MediaOutputSliceConstants.KEY_REMOTE_MEDIA) + .appendPath(MediaOutputConstants.KEY_REMOTE_MEDIA) .build(); /** diff --git a/src/com/android/settings/sound/MediaOutputPreferenceController.java b/src/com/android/settings/sound/MediaOutputPreferenceController.java index b5562a3a5c8..4ec00e358a9 100644 --- a/src/com/android/settings/sound/MediaOutputPreferenceController.java +++ b/src/com/android/settings/sound/MediaOutputPreferenceController.java @@ -32,7 +32,7 @@ import com.android.settings.media.MediaOutputUtils; import com.android.settingslib.Utils; import com.android.settingslib.bluetooth.A2dpProfile; import com.android.settingslib.bluetooth.HearingAidProfile; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; import java.util.List; @@ -134,11 +134,11 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro public boolean handlePreferenceTreeClick(Preference preference) { if (TextUtils.equals(preference.getKey(), getPreferenceKey())) { mContext.sendBroadcast(new Intent() - .setAction(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG) - .setPackage(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME) - .putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME, + .setAction(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG) + .setPackage(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME) + .putExtra(MediaOutputConstants.EXTRA_PACKAGE_NAME, mMediaController.getPackageName()) - .putExtra(MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN, + .putExtra(MediaOutputConstants.KEY_MEDIA_SESSION_TOKEN, mMediaController.getSessionToken())); return true; } diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java index 06f74d54e55..d05260afe1f 100644 --- a/src/com/android/settings/wifi/WifiUtils.java +++ b/src/com/android/settings/wifi/WifiUtils.java @@ -56,12 +56,12 @@ public class WifiUtils { } /** - * Check if the WPA2-PSK hotspot password is valid. + * Check if the hotspot password is valid. */ - public static boolean isHotspotWpa2PasswordValid(String password) { + public static boolean isHotspotPasswordValid(String password, int securityType) { final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); try { - configBuilder.setPassphrase(password, SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); + configBuilder.setPassphrase(password, securityType); } catch (IllegalArgumentException e) { return false; } diff --git a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java index 26d742d530e..afab8c3cf77 100644 --- a/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java +++ b/src/com/android/settings/wifi/calling/WifiCallingSliceHelper.java @@ -539,7 +539,7 @@ public class WifiCallingSliceHelper { */ public static PendingIntent getSettingsIntent(Context context) { final Intent intent = new Intent(Settings.ACTION_SETTINGS); - return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */); + return PendingIntent.getActivity(context, 0 /* requestCode */, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED /* flags */); } private PendingIntent getBroadcastIntent(String action) { @@ -547,7 +547,7 @@ public class WifiCallingSliceHelper { intent.setClass(mContext, SliceBroadcastReceiver.class); intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); return PendingIntent.getBroadcast(mContext, 0 /* requestCode */, intent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); } /** @@ -557,7 +557,7 @@ public class WifiCallingSliceHelper { final Intent intent = new Intent(action); intent.setPackage(SETTINGS_PACKAGE_NAME); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */); + return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED /* flags */); } private Resources getResourcesForSubId(int subId) { diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java index 2957e1fb8bd..abf5becfbc3 100644 --- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java +++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java @@ -301,7 +301,11 @@ public class WifiDppUtils { final String ssid = removeFirstAndLastDoubleQuotes(softApConfiguration.getSsid()); String security; - if (softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) { + final int securityType = softApConfiguration.getSecurityType(); + if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE) { + security = WifiQrCode.SECURITY_SAE; + } else if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK + || securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION) { security = WifiQrCode.SECURITY_WPA_PSK; } else { security = WifiQrCode.SECURITY_NO_PASSWORD; @@ -431,11 +435,11 @@ public class WifiDppUtils { private static boolean isSupportHotspotConfiguratorQrCodeGenerator( SoftApConfiguration softApConfiguration) { - // QR code generator produces QR code with ZXing's Wi-Fi network config format, - // it supports PSK and WEP and non security - // KeyMgmt.NONE is for WEP or non security - return softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK - || softApConfiguration.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_OPEN; + final int securityType = softApConfiguration.getSecurityType(); + return securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE + || securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION + || securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK + || securityType == SoftApConfiguration.SECURITY_TYPE_OPEN; } private static boolean isSupportWifiDpp(Context context, int wifiEntrySecurity) { diff --git a/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java index be67d22d966..14766f9ee41 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherPasswordPreferenceController.java @@ -37,12 +37,16 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import java.util.UUID; +/** + * Controller for logic pertaining to the password of Wi-Fi tethering. + */ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePreferenceController implements ValidatedEditTextPreference.Validator { private static final String PREF_KEY = "wifi_tether_network_password"; private String mPassword; + private int mSecurityType; private final MetricsFeatureProvider mMetricsFeatureProvider; @@ -68,13 +72,13 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer @Override public void updateDisplay() { final SoftApConfiguration config = mWifiManager.getSoftApConfiguration(); - if (config == null - || (config.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK - && TextUtils.isEmpty(config.getPassphrase()))) { + if (config.getSecurityType() != SoftApConfiguration.SECURITY_TYPE_OPEN + && TextUtils.isEmpty(config.getPassphrase())) { mPassword = generateRandomPassword(); } else { mPassword = config.getPassphrase(); } + mSecurityType = config.getSecurityType(); ((ValidatedEditTextPreference) mPreference).setValidator(this); ((ValidatedEditTextPreference) mPreference).setIsPassword(true); ((ValidatedEditTextPreference) mPreference).setIsSummaryPassword(true); @@ -105,20 +109,27 @@ public class WifiTetherPasswordPreferenceController extends WifiTetherBasePrefer // don't actually overwrite unless we get a new config in case it was accidentally toggled. if (securityType == SoftApConfiguration.SECURITY_TYPE_OPEN) { return ""; - } else if (!isTextValid(mPassword)) { + } else if (!WifiUtils.isHotspotPasswordValid(mPassword, securityType)) { mPassword = generateRandomPassword(); updatePasswordDisplay((EditTextPreference) mPreference); } return mPassword; } - public void updateVisibility(int securityType) { + /** + * This method set the security type of user selection. Then the controller will based on the + * security type changed to update the password changed on the preference. + * + * @param securityType The security type of SoftApConfiguration. + */ + public void setSecurityType(int securityType) { + mSecurityType = securityType; mPreference.setVisible(securityType != SoftApConfiguration.SECURITY_TYPE_OPEN); } @Override public boolean isTextValid(String value) { - return WifiUtils.isHotspotWpa2PasswordValid(value); + return WifiUtils.isHotspotPasswordValid(value, mSecurityType); } private static String generateRandomPassword() { diff --git a/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java b/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java index 56b50314b6d..acb82062496 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java +++ b/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceController.java @@ -1,28 +1,65 @@ +/* + * Copyright (C) 2021 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.wifi.tether; import static com.android.settings.AllInOneTetherSettings.DEDUP_POSTFIX; +import android.annotation.NonNull; import android.content.Context; +import android.net.wifi.SoftApCapability; import android.net.wifi.SoftApConfiguration; +import android.net.wifi.WifiManager; import android.util.FeatureFlagUtils; +import android.util.Log; +import androidx.annotation.VisibleForTesting; import androidx.preference.ListPreference; import androidx.preference.Preference; import com.android.settings.R; import com.android.settings.core.FeatureFlags; -public class WifiTetherSecurityPreferenceController extends WifiTetherBasePreferenceController { +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Controller for logic pertaining to the security type of Wi-Fi tethering. + */ +public class WifiTetherSecurityPreferenceController extends WifiTetherBasePreferenceController + implements WifiManager.SoftApCallback { private static final String PREF_KEY = "wifi_tether_security"; - private final String[] mSecurityEntries; + private Map mSecurityMap = new LinkedHashMap(); private int mSecurityValue; + @VisibleForTesting + boolean mIsWpa3Supported = true; public WifiTetherSecurityPreferenceController(Context context, OnTetherConfigUpdateListener listener) { super(context, listener); - mSecurityEntries = mContext.getResources().getStringArray(R.array.wifi_tether_security); + final String[] securityNames = mContext.getResources().getStringArray( + R.array.wifi_tether_security); + final String[] securityValues = mContext.getResources().getStringArray( + R.array.wifi_tether_security_values); + for (int i = 0; i < securityNames.length; i++) { + mSecurityMap.put(Integer.parseInt(securityValues[i]), securityNames[i]); + } + mWifiManager.registerSoftApCallback(context.getMainExecutor(), this); } @Override @@ -33,35 +70,55 @@ public class WifiTetherSecurityPreferenceController extends WifiTetherBasePrefer @Override public void updateDisplay() { - final SoftApConfiguration config = mWifiManager.getSoftApConfiguration(); - if (config != null && config.getSecurityType() == SoftApConfiguration.SECURITY_TYPE_OPEN) { - mSecurityValue = SoftApConfiguration.SECURITY_TYPE_OPEN; - } else { - mSecurityValue = SoftApConfiguration.SECURITY_TYPE_WPA2_PSK; + // The mPreference will be ready when the fragment calls displayPreference(). Since the + // capability of WPA3 hotspot callback will update the preference list here, add null point + // checking to avoid the mPreference is not ready when the fragment is loading for settings + // keyword searching only. + if (mPreference == null) { + return; + } + final ListPreference preference = (ListPreference) mPreference; + // If the device is not support WPA3 then remove the WPA3 options. + if (!mIsWpa3Supported && mSecurityMap.keySet() + .removeIf(key -> key > SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)) { + preference.setEntries(mSecurityMap.values().stream().toArray(CharSequence[]::new)); + preference.setEntryValues(mSecurityMap.keySet().stream().map(Integer::toBinaryString) + .toArray(CharSequence[]::new)); } - final ListPreference preference = (ListPreference) mPreference; - preference.setSummary(getSummaryForSecurityType(mSecurityValue)); + final int securityType = mWifiManager.getSoftApConfiguration().getSecurityType(); + mSecurityValue = mSecurityMap.get(securityType) != null + ? securityType : SoftApConfiguration.SECURITY_TYPE_WPA2_PSK; + + preference.setSummary(mSecurityMap.get(mSecurityValue)); preference.setValue(String.valueOf(mSecurityValue)); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { mSecurityValue = Integer.parseInt((String) newValue); - preference.setSummary(getSummaryForSecurityType(mSecurityValue)); - mListener.onTetherConfigUpdated(this); + preference.setSummary(mSecurityMap.get(mSecurityValue)); + if (mListener != null) { + mListener.onTetherConfigUpdated(this); + } return true; } + @Override + public void onCapabilityChanged(@NonNull SoftApCapability softApCapability) { + final boolean isWpa3Supported = + softApCapability.areFeaturesSupported(SoftApCapability.SOFTAP_FEATURE_WPA3_SAE); + if (!isWpa3Supported) { + Log.i(PREF_KEY, "WPA3 SAE is not supported on this device"); + } + if (mIsWpa3Supported != isWpa3Supported) { + mIsWpa3Supported = isWpa3Supported; + updateDisplay(); + } + mWifiManager.unregisterSoftApCallback(this); + } + public int getSecurityType() { return mSecurityValue; } - - private String getSummaryForSecurityType(int securityType) { - if (securityType == SoftApConfiguration.SECURITY_TYPE_OPEN) { - return mSecurityEntries[1]; - } - // WPA2 PSK - return mSecurityEntries[0]; - } } diff --git a/src/com/android/settings/wifi/tether/WifiTetherSettings.java b/src/com/android/settings/wifi/tether/WifiTetherSettings.java index d6c49bcda2c..f260298029c 100644 --- a/src/com/android/settings/wifi/tether/WifiTetherSettings.java +++ b/src/com/android/settings/wifi/tether/WifiTetherSettings.java @@ -192,7 +192,7 @@ public class WifiTetherSettings extends RestrictedDashboardFragment @Override public void onTetherConfigUpdated(AbstractPreferenceController context) { final SoftApConfiguration config = buildNewConfig(); - mPasswordPreferenceController.updateVisibility(config.getSecurityType()); + mPasswordPreferenceController.setSecurityType(config.getSecurityType()); /** * if soft AP is stopped, bring up @@ -216,10 +216,10 @@ public class WifiTetherSettings extends RestrictedDashboardFragment final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); final int securityType = mSecurityPreferenceController.getSecurityType(); configBuilder.setSsid(mSSIDPreferenceController.getSSID()); - if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK) { + if (securityType != SoftApConfiguration.SECURITY_TYPE_OPEN) { configBuilder.setPassphrase( mPasswordPreferenceController.getPasswordValidated(securityType), - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); + securityType); } configBuilder.setBand(mApBandPreferenceController.getBandIndex()); return configBuilder.build(); diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarControllerTest.java new file mode 100644 index 00000000000..d6c66ad4254 --- /dev/null +++ b/tests/robotests/src/com/android/settings/accessibility/ToggleAutoclickCustomSeekbarControllerTest.java @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2021 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.accessibility; + +import static android.content.Context.MODE_PRIVATE; + +import static com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController.KEY_CUSTOM_DELAY_VALUE; +import static com.android.settings.accessibility.ToggleAutoclickPreferenceController.KEY_DELAY_MODE; +import static com.android.settings.core.BasePreferenceController.AVAILABLE; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.robolectric.Shadows.shadowOf; + +import android.content.Context; +import android.content.SharedPreferences; +import android.provider.Settings; +import android.widget.ImageView; +import android.widget.SeekBar; +import android.widget.TextView; + +import androidx.lifecycle.LifecycleObserver; +import androidx.preference.PreferenceScreen; +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settingslib.core.lifecycle.Lifecycle; +import com.android.settingslib.widget.LayoutPreference; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; + +/** Tests for {@link ToggleAutoclickCustomSeekbarController}. */ +@RunWith(RobolectricTestRunner.class) +public class ToggleAutoclickCustomSeekbarControllerTest { + + @Mock + private PreferenceScreen mScreen; + + @Mock + private LayoutPreference mLayoutPreference; + + @Mock + private Lifecycle mLifecycle; + + private SharedPreferences mSharedPreferences; + private TextView mDelayLabel; + private ImageView mShorter; + private ImageView mLonger; + private SeekBar mSeekBar; + private ToggleAutoclickCustomSeekbarController mController; + private Context mContext; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + + final String mPrefKey = "prefKey"; + mContext = ApplicationProvider.getApplicationContext(); + mSharedPreferences = mContext.getSharedPreferences(mContext.getPackageName(), MODE_PRIVATE); + mDelayLabel = new TextView(mContext); + mShorter = new ImageView(mContext); + mLonger = new ImageView(mContext); + mSeekBar = new SeekBar(mContext); + mController = + new ToggleAutoclickCustomSeekbarController(mContext, mLifecycle, mPrefKey); + + doReturn(mLayoutPreference).when(mScreen).findPreference(mPrefKey); + doReturn(mSeekBar).when(mLayoutPreference).findViewById(R.id.autoclick_delay); + doReturn(mDelayLabel).when(mLayoutPreference).findViewById(R.id.current_label); + doReturn(mShorter).when(mLayoutPreference).findViewById(R.id.shorter); + doReturn(mLonger).when(mLayoutPreference).findViewById(R.id.longer); + } + + @Test + public void getAvailabilityStatus_available() { + assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); + } + + @Test + public void constructor_hasLifecycle_addObserver() { + verify(mLifecycle).addObserver(any(LifecycleObserver.class)); + } + + @Test + public void displayPreference_initSeekBar() { + mSharedPreferences.edit().putInt(KEY_CUSTOM_DELAY_VALUE, 700).apply(); + + mController.onResume(); + mController.displayPreference(mScreen); + mController.onPause(); + final SeekBar.OnSeekBarChangeListener mListener = + shadowOf(mSeekBar).getOnSeekBarChangeListener(); + + assertThat(mSeekBar.getMax()).isEqualTo(8); + assertThat(mSeekBar.getProgress()).isEqualTo(5); + assertThat(mListener).isNotNull(); + } + + @Test + public void displayPreference_initDelayLabel() { + mSharedPreferences.edit().putInt(KEY_CUSTOM_DELAY_VALUE, 700).apply(); + + mController.onResume(); + mController.displayPreference(mScreen); + mController.onPause(); + + assertThat(mDelayLabel.getText()).isEqualTo("0.7 seconds"); + } + + @Test + public void onSharedPreferenceChanged_delayMode_updateCustomDelayValue() { + mSharedPreferences.edit().putInt(KEY_CUSTOM_DELAY_VALUE, 700).apply(); + + mController.displayPreference(mScreen); + mController.onSharedPreferenceChanged(mSharedPreferences, KEY_DELAY_MODE); + final int actualDelayValue = + Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY, /* def= */ 0); + final int actualCustomDelayValue = + mSharedPreferences.getInt(KEY_CUSTOM_DELAY_VALUE, /* defValue= */ 0); + + assertThat(mDelayLabel.getText()).isEqualTo("0.7 seconds"); + assertThat(mSeekBar.getProgress()).isEqualTo(5); + assertThat(actualDelayValue).isEqualTo(700); + assertThat(actualCustomDelayValue).isEqualTo(700); + } + + @Test + public void onSeekBarProgressChanged_updateCustomDelayValue() { + mSharedPreferences.edit().putInt(KEY_CUSTOM_DELAY_VALUE, 700).apply(); + + mController.displayPreference(mScreen); + mController.mSeekBarChangeListener.onProgressChanged(mock(SeekBar.class), + /* value= */ 8, + true); + final int actualDelayValue = + Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY, /* def= */ 0); + final int actualCustomDelayValue = + mSharedPreferences.getInt(KEY_CUSTOM_DELAY_VALUE, /* defValue= */ 0); + + assertThat(mDelayLabel.getText()).isEqualTo("1 second"); + assertThat(mSeekBar.getProgress()).isEqualTo(8); + assertThat(actualDelayValue).isEqualTo(1000); + assertThat(actualCustomDelayValue).isEqualTo(1000); + } + + @Test + public void onShorterClicked_updateCustomDelayValue() { + mSharedPreferences.edit().putInt(KEY_CUSTOM_DELAY_VALUE, 700).apply(); + + mController.displayPreference(mScreen); + mShorter.callOnClick(); + final int actualDelayValue = + Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY, /* def= */ 0); + final int actualCustomDelayValue = + mSharedPreferences.getInt(KEY_CUSTOM_DELAY_VALUE, /* defValue= */ 0); + + assertThat(mSeekBar.getProgress()).isEqualTo(4); + assertThat(mDelayLabel.getText()).isEqualTo("0.6 seconds"); + assertThat(actualDelayValue).isEqualTo(600); + assertThat(actualCustomDelayValue).isEqualTo(600); + } + + @Test + public void onLongerClicked_updateCustomDelayValue() { + mSharedPreferences.edit().putInt(KEY_CUSTOM_DELAY_VALUE, 700).apply(); + + mController.displayPreference(mScreen); + mLonger.callOnClick(); + final int actualDelayValue = + Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_AUTOCLICK_DELAY, /* def= */ 0); + final int actualCustomDelayValue = + mSharedPreferences.getInt(KEY_CUSTOM_DELAY_VALUE, /* defValue= */ 0); + + assertThat(mSeekBar.getProgress()).isEqualTo(6); + assertThat(mDelayLabel.getText()).isEqualTo("0.8 seconds"); + assertThat(actualDelayValue).isEqualTo(800); + assertThat(actualCustomDelayValue).isEqualTo(800); + } +} diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java index 74c0bb5e007..7a4c6108916 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import static org.robolectric.Shadows.shadowOf; import android.app.Activity; +import android.app.role.RoleControllerManager; import android.app.role.RoleManager; import android.content.Context; import android.content.Intent; @@ -62,6 +63,8 @@ public class DefaultAppShortcutPreferenceControllerBaseTest { @Mock private RoleManager mRoleManager; @Mock + private RoleControllerManager mRoleControllerManager; + @Mock private Preference mPreference; private Activity mActivity; @@ -74,6 +77,7 @@ public class DefaultAppShortcutPreferenceControllerBaseTest { MockitoAnnotations.initMocks(this); ShadowApplication shadowApplication = ShadowApplication.getInstance(); shadowApplication.setSystemService(Context.ROLE_SERVICE, mRoleManager); + shadowApplication.setSystemService(Context.ROLE_CONTROLLER_SERVICE, mRoleControllerManager); mActivity = Robolectric.setupActivity(Activity.class); mShadowUserManager = shadowOf(mActivity.getSystemService(UserManager.class)); mController = new TestRolePreferenceController(mActivity); @@ -82,7 +86,7 @@ public class DefaultAppShortcutPreferenceControllerBaseTest { @Test public void constructor_callsIsApplicationVisibleForRole() { - verify(mRoleManager).isApplicationVisibleForRole(eq(TEST_ROLE_NAME), eq( + verify(mRoleControllerManager).isApplicationVisibleForRole(eq(TEST_ROLE_NAME), eq( TEST_PACKAGE_NAME), any(Executor.class), any(Consumer.class)); } @@ -149,7 +153,7 @@ public class DefaultAppShortcutPreferenceControllerBaseTest { private void setRoleIsVisible(boolean visible) { final ArgumentCaptor> callbackCaptor = ArgumentCaptor.forClass( Consumer.class); - verify(mRoleManager).isRoleVisible(eq(TEST_ROLE_NAME), any(Executor.class), + verify(mRoleControllerManager).isRoleVisible(eq(TEST_ROLE_NAME), any(Executor.class), callbackCaptor.capture()); final Consumer callback = callbackCaptor.getValue(); callback.accept(visible); @@ -158,7 +162,7 @@ public class DefaultAppShortcutPreferenceControllerBaseTest { private void setApplicationIsVisibleForRole(boolean visible) { final ArgumentCaptor> callbackCaptor = ArgumentCaptor.forClass( Consumer.class); - verify(mRoleManager).isApplicationVisibleForRole(eq(TEST_ROLE_NAME), eq( + verify(mRoleControllerManager).isApplicationVisibleForRole(eq(TEST_ROLE_NAME), eq( TEST_PACKAGE_NAME), any(Executor.class), callbackCaptor.capture()); final Consumer callback = callbackCaptor.getValue(); callback.accept(visible); diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java index 6d4186c1761..5940d72cb59 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultBrowserShortcutPreferenceControllerTest.java @@ -18,7 +18,7 @@ package com.android.settings.applications.appinfo; import static com.google.common.truth.Truth.assertThat; -import android.app.role.RoleManager; +import android.app.role.RoleControllerManager; import android.content.Context; import org.junit.Before; @@ -34,14 +34,15 @@ import org.robolectric.shadows.ShadowApplication; public class DefaultBrowserShortcutPreferenceControllerTest { @Mock - private RoleManager mRoleManager; + private RoleControllerManager mRoleControllerManager; private DefaultBrowserShortcutPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); - ShadowApplication.getInstance().setSystemService(Context.ROLE_SERVICE, mRoleManager); + ShadowApplication.getInstance().setSystemService(Context.ROLE_CONTROLLER_SERVICE, + mRoleControllerManager); mController = new DefaultBrowserShortcutPreferenceController(RuntimeEnvironment.application, "Package1"); } diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java index 0acd7bdb1c6..8dcf530aa4a 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultEmergencyShortcutPreferenceControllerTest.java @@ -18,7 +18,7 @@ package com.android.settings.applications.appinfo; import static com.google.common.truth.Truth.assertThat; -import android.app.role.RoleManager; +import android.app.role.RoleControllerManager; import android.content.Context; import org.junit.Before; @@ -34,14 +34,15 @@ import org.robolectric.shadows.ShadowApplication; public class DefaultEmergencyShortcutPreferenceControllerTest { @Mock - private RoleManager mRoleManager; + private RoleControllerManager mRoleControllerManager; private DefaultEmergencyShortcutPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); - ShadowApplication.getInstance().setSystemService(Context.ROLE_SERVICE, mRoleManager); + ShadowApplication.getInstance().setSystemService(Context.ROLE_CONTROLLER_SERVICE, + mRoleControllerManager); mController = new DefaultEmergencyShortcutPreferenceController( RuntimeEnvironment.application, "Package1"); } diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java index 1f0023a14c6..7071fec1186 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultHomeShortcutPreferenceControllerTest.java @@ -18,7 +18,7 @@ package com.android.settings.applications.appinfo; import static com.google.common.truth.Truth.assertThat; -import android.app.role.RoleManager; +import android.app.role.RoleControllerManager; import android.content.Context; import org.junit.Before; @@ -34,14 +34,15 @@ import org.robolectric.shadows.ShadowApplication; public class DefaultHomeShortcutPreferenceControllerTest { @Mock - private RoleManager mRoleManager; + private RoleControllerManager mRoleControllerManager; private DefaultHomeShortcutPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); - ShadowApplication.getInstance().setSystemService(Context.ROLE_SERVICE, mRoleManager); + ShadowApplication.getInstance().setSystemService(Context.ROLE_CONTROLLER_SERVICE, + mRoleControllerManager); mController = new DefaultHomeShortcutPreferenceController(RuntimeEnvironment.application, "Package1"); } diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java index c13066513ef..d1b6aebf55e 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultPhoneShortcutPreferenceControllerTest.java @@ -18,7 +18,7 @@ package com.android.settings.applications.appinfo; import static com.google.common.truth.Truth.assertThat; -import android.app.role.RoleManager; +import android.app.role.RoleControllerManager; import android.content.Context; import org.junit.Before; @@ -37,14 +37,15 @@ public class DefaultPhoneShortcutPreferenceControllerTest { private static final String PREFERENCE_KEY = "default_phone_app"; @Mock - private RoleManager mRoleManager; + private RoleControllerManager mRoleControllerManager; private DefaultPhoneShortcutPreferenceController mController; @Before public void setUp() { MockitoAnnotations.initMocks(this); - ShadowApplication.getInstance().setSystemService(Context.ROLE_SERVICE, mRoleManager); + ShadowApplication.getInstance().setSystemService(Context.ROLE_CONTROLLER_SERVICE, + mRoleControllerManager); mController = new DefaultPhoneShortcutPreferenceController(RuntimeEnvironment.application, TEST_PACKAGE_NAME); } diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java index e9c238d0529..691ce5e8579 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultSmsShortcutPreferenceControllerTest.java @@ -18,6 +18,7 @@ package com.android.settings.applications.appinfo; import static com.google.common.truth.Truth.assertThat; +import android.app.role.RoleControllerManager; import android.app.role.RoleManager; import android.content.Context; @@ -38,6 +39,8 @@ public class DefaultSmsShortcutPreferenceControllerTest { @Mock private RoleManager mRoleManager; + @Mock + private RoleControllerManager mRoleControllerManager; private DefaultSmsShortcutPreferenceController mController; @@ -46,6 +49,7 @@ public class DefaultSmsShortcutPreferenceControllerTest { MockitoAnnotations.initMocks(this); final ShadowApplication shadowApplication = ShadowApplication.getInstance(); shadowApplication.setSystemService(Context.ROLE_SERVICE, mRoleManager); + shadowApplication.setSystemService(Context.ROLE_CONTROLLER_SERVICE, mRoleControllerManager); mController = new DefaultSmsShortcutPreferenceController(RuntimeEnvironment.application, TEST_PACKAGE_NAME); } diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java index 68848af3ab9..7248ff65199 100644 --- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java +++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java @@ -51,7 +51,7 @@ import com.android.settings.slices.SliceBackgroundWorker; import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.media.MediaDevice; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; import org.junit.Before; import org.junit.Test; @@ -219,13 +219,13 @@ public class MediaOutputIndicatorSliceTest { Intent intent = intentList.get(0); assertThat(TextUtils.equals(TEST_PACKAGE_NAME, intent.getStringExtra( - MediaOutputSliceConstants.EXTRA_PACKAGE_NAME))).isTrue(); - assertThat(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG).isEqualTo( + MediaOutputConstants.EXTRA_PACKAGE_NAME))).isTrue(); + assertThat(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG).isEqualTo( intent.getAction()); - assertThat(TextUtils.equals(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME, + assertThat(TextUtils.equals(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME, intent.getPackage())).isTrue(); assertThat(mToken == intent.getExtras().getParcelable( - MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN)).isTrue(); + MediaOutputConstants.KEY_MEDIA_SESSION_TOKEN)).isTrue(); } @Test @@ -240,13 +240,13 @@ public class MediaOutputIndicatorSliceTest { Intent intent = intentList.get(0); assertThat(TextUtils.isEmpty(intent.getStringExtra( - MediaOutputSliceConstants.EXTRA_PACKAGE_NAME))).isTrue(); - assertThat(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG).isEqualTo( + MediaOutputConstants.EXTRA_PACKAGE_NAME))).isTrue(); + assertThat(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG).isEqualTo( intent.getAction()); - assertThat(TextUtils.equals(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME, + assertThat(TextUtils.equals(MediaOutputConstants.SYSTEMUI_PACKAGE_NAME, intent.getPackage())).isTrue(); assertThat(intent.getExtras().getParcelable( - MediaOutputSliceConstants.KEY_MEDIA_SESSION_TOKEN) == null).isTrue(); + MediaOutputConstants.KEY_MEDIA_SESSION_TOKEN) == null).isTrue(); } @Test diff --git a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java index eb84a4fb3fb..f604193debc 100644 --- a/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/sound/MediaOutputPreferenceControllerTest.java @@ -58,7 +58,7 @@ import com.android.settingslib.bluetooth.BluetoothEventManager; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; -import com.android.settingslib.media.MediaOutputSliceConstants; +import com.android.settingslib.media.MediaOutputConstants; import org.junit.After; import org.junit.Before; @@ -302,7 +302,7 @@ public class MediaOutputPreferenceControllerTest { mController.handlePreferenceTreeClick(mPreference); verify(mContext).sendBroadcast(intentCaptor.capture()); assertThat(intentCaptor.getValue().getAction()) - .isEqualTo(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG); + .isEqualTo(MediaOutputConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG); } /** diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java index 03a63b0b8b2..0dcf6852fad 100644 --- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java +++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSliceHelperTest.java @@ -397,14 +397,14 @@ public class WifiCallingSliceHelperTest { final Intent intent = new Intent(action); intent.setClass(mContext, SliceBroadcastReceiver.class); return PendingIntent.getBroadcast(mContext, 0 /* requestCode */, intent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_MUTABLE_UNAUDITED); } private PendingIntent getActivityIntent(String action) { final Intent intent = new Intent(action); intent.setPackage(SETTINGS_PACKAGE_NAME); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */); + return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_MUTABLE_UNAUDITED /* flags */); } private void assertTitle(List sliceItems, String 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 deleted file mode 100644 index c7d0695d0f5..00000000000 --- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.android.settings.wifi.tether; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.net.ConnectivityManager; -import android.net.wifi.SoftApConfiguration; -import android.net.wifi.WifiManager; - -import androidx.preference.ListPreference; -import androidx.preference.PreferenceScreen; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -@RunWith(RobolectricTestRunner.class) -public class WifiTetherSecurityPreferenceControllerTest { - - private static final String WPA2_PSK = - String.valueOf(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); - private static final String NONE = String.valueOf(SoftApConfiguration.SECURITY_TYPE_OPEN); - @Mock - private WifiTetherBasePreferenceController.OnTetherConfigUpdateListener mListener; - private Context mContext; - @Mock - private ConnectivityManager mConnectivityManager; - @Mock - private WifiManager mWifiManager; - @Mock - private PreferenceScreen mScreen; - private WifiTetherSecurityPreferenceController mController; - private ListPreference mPreference; - private SoftApConfiguration mConfig; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mConfig = new SoftApConfiguration.Builder().setSsid("test_1234") - .setPassphrase("test_password", - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK).build(); - mContext = spy(RuntimeEnvironment.application); - - when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); - when(mWifiManager.getSoftApConfiguration()).thenReturn(mConfig); - when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)) - .thenReturn(mConnectivityManager); - when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"}); - when(mScreen.findPreference(anyString())).thenReturn(mPreference); - - mController = new WifiTetherSecurityPreferenceController(mContext, mListener); - mPreference = new ListPreference(RuntimeEnvironment.application); - mController.mPreference = mPreference; - } - - @Test - public void onPreferenceChange_securityValueUpdated() { - mController.onPreferenceChange(mPreference, WPA2_PSK); - assertThat(mController.getSecurityType()).isEqualTo( - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); - assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal"); - - mController.onPreferenceChange(mPreference, NONE); - assertThat(mController.getSecurityType()).isEqualTo( - SoftApConfiguration.SECURITY_TYPE_OPEN); - assertThat(mPreference.getSummary().toString()).isEqualTo("None"); - } - - @Test - public void updateDisplay_preferenceUpdated() { - // test defaulting to WPA2-Personal on new config - when(mWifiManager.getSoftApConfiguration()).thenReturn(null); - mController.updateDisplay(); - assertThat(mController.getSecurityType()).isEqualTo( - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); - assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal"); - - // test open tether network - SoftApConfiguration config = new SoftApConfiguration.Builder(mConfig) - .setPassphrase(null, SoftApConfiguration.SECURITY_TYPE_OPEN).build(); - when(mWifiManager.getSoftApConfiguration()).thenReturn(config); - mController.updateDisplay(); - assertThat(mController.getSecurityType()).isEqualTo( - SoftApConfiguration.SECURITY_TYPE_OPEN); - assertThat(mPreference.getSummary().toString()).isEqualTo("None"); - - // test WPA2-Personal tether network - SoftApConfiguration config2 = new SoftApConfiguration.Builder(mConfig) - .setPassphrase("test_password", - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK).build(); - when(mWifiManager.getSoftApConfiguration()).thenReturn(config2); - mController.updateDisplay(); - assertThat(mController.getSecurityType()).isEqualTo( - SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); - assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal"); - } -} diff --git a/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java b/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java index 7a75443f814..1a5e8526dc3 100644 --- a/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java +++ b/tests/unit/src/com/android/settings/wifi/WifiUtilsTest.java @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiConfiguration; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -46,12 +47,48 @@ public class WifiUtilsTest { public void testPassword() { final String longPassword = "123456789012345678901234567890" + "1234567890123456789012345678901234567890"; - assertThat(WifiUtils.isHotspotWpa2PasswordValid("123")).isFalse(); - assertThat(WifiUtils.isHotspotWpa2PasswordValid("12345678")).isTrue(); - assertThat(WifiUtils.isHotspotWpa2PasswordValid("1234567890")).isTrue(); - assertThat(WifiUtils.isHotspotWpa2PasswordValid(longPassword)).isFalse(); - assertThat(WifiUtils.isHotspotWpa2PasswordValid("")).isFalse(); - assertThat(WifiUtils.isHotspotWpa2PasswordValid("€¥£")).isFalse(); + assertThat(WifiUtils.isHotspotPasswordValid("123", + SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)).isFalse(); + assertThat(WifiUtils.isHotspotPasswordValid("12345678", + SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid("1234567890", + SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid(longPassword, + SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)).isFalse(); + assertThat(WifiUtils.isHotspotPasswordValid("", + SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)).isFalse(); + assertThat(WifiUtils.isHotspotPasswordValid("€¥£", + SoftApConfiguration.SECURITY_TYPE_WPA2_PSK)).isFalse(); + + // The WPA3_SAE_TRANSITION password limitation should be same as WPA2_PSK + assertThat(WifiUtils.isHotspotPasswordValid("123", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION)).isFalse(); + assertThat(WifiUtils.isHotspotPasswordValid("12345678", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid("1234567890", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid(longPassword, + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION)).isFalse(); + assertThat(WifiUtils.isHotspotPasswordValid("", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION)).isFalse(); + assertThat(WifiUtils.isHotspotPasswordValid("€¥£", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION)).isFalse(); + + // The WA3_SAE password is requested that length > 1 only. + assertThat(WifiUtils.isHotspotPasswordValid("", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE)).isFalse(); + assertThat(WifiUtils.isHotspotPasswordValid("1", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid("123", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid("12345678", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid("1234567890", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid(longPassword, + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE)).isTrue(); + assertThat(WifiUtils.isHotspotPasswordValid("€¥£", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE)).isTrue(); } @Test diff --git a/tests/unit/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java b/tests/unit/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java new file mode 100644 index 00000000000..c86e3e5b7a4 --- /dev/null +++ b/tests/unit/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java @@ -0,0 +1,206 @@ +/* + * Copyright (C) 2021 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.wifi.tether; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.net.wifi.SoftApConfiguration; +import android.net.wifi.WifiManager; +import android.os.Looper; + +import androidx.preference.ListPreference; +import androidx.preference.PreferenceManager; +import androidx.preference.PreferenceScreen; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +@RunWith(AndroidJUnit4.class) +public class WifiTetherSecurityPreferenceControllerTest { + + private static final String PREF_KEY = "wifi_tether_security"; + private static final String WPA3_SAE = + String.valueOf(SoftApConfiguration.SECURITY_TYPE_WPA3_SAE); + private static final String WPA3_SAE_TRANSITION = + String.valueOf(SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION); + private static final String WPA2_PSK = + String.valueOf(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); + private static final String NONE = String.valueOf(SoftApConfiguration.SECURITY_TYPE_OPEN); + + @Rule + public final MockitoRule mMockitoRule = MockitoJUnit.rule(); + @Mock + private WifiManager mWifiManager; + @Mock + private WifiTetherBasePreferenceController.OnTetherConfigUpdateListener mListener; + + private WifiTetherSecurityPreferenceController mController; + private ListPreference mPreference; + private SoftApConfiguration mConfig; + + @Before + public void setUp() { + final Context context = spy(ApplicationProvider.getApplicationContext()); + mConfig = new SoftApConfiguration.Builder().setSsid("test_1234") + .setPassphrase(null, SoftApConfiguration.SECURITY_TYPE_OPEN).build(); + when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager); + when(mWifiManager.getSoftApConfiguration()).thenReturn(mConfig); + + mController = new WifiTetherSecurityPreferenceController(context, mListener); + if (Looper.myLooper() == null) { + Looper.prepare(); + } + final PreferenceManager preferenceManager = new PreferenceManager(context); + final PreferenceScreen screen = preferenceManager.createPreferenceScreen(context); + mPreference = new ListPreference(context); + mPreference.setKey(PREF_KEY); + screen.addPreference(mPreference); + mController.displayPreference(screen); + } + + @Test + public void onPreferenceChange_toWpa3Sae_shouldUpdateSecurityValue() { + mController.onPreferenceChange(mPreference, WPA3_SAE); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA3_SAE); + assertThat(mPreference.getSummary().toString()).isEqualTo("WPA3-Personal"); + } + + @Test + public void onPreferenceChange_toWpa3SaeTransition_shouldUpdateSecurityValue() { + mController.onPreferenceChange(mPreference, WPA3_SAE_TRANSITION); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION); + assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2/WPA3-Personal"); + } + + @Test + public void onPreferenceChange_toWpa2Psk_shouldUpdateSecurityValue() { + mController.onPreferenceChange(mPreference, WPA2_PSK); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); + assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal"); + } + + @Test + public void onPreferenceChange_toNone_shouldUpdateSecurityValue() { + mController.onPreferenceChange(mPreference, NONE); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_OPEN); + assertThat(mPreference.getSummary().toString()).isEqualTo("None"); + } + + @Test + public void updateDisplay_toWpa3Sae_shouldUpdateSecurityValue() { + SoftApConfiguration config = new SoftApConfiguration.Builder(mConfig) + .setPassphrase("test_password", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE).build(); + when(mWifiManager.getSoftApConfiguration()).thenReturn(config); + + mController.updateDisplay(); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA3_SAE); + assertThat(mPreference.getSummary().toString()).isEqualTo("WPA3-Personal"); + } + + @Test + public void updateDisplay_toWpa3SaeTransition_shouldUpdateSecurityValue() { + SoftApConfiguration config = new SoftApConfiguration.Builder(mConfig) + .setPassphrase("test_password", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION).build(); + when(mWifiManager.getSoftApConfiguration()).thenReturn(config); + + mController.updateDisplay(); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION); + assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2/WPA3-Personal"); + } + + @Test + public void updateDisplay_toWpa2Psk_shouldUpdateSecurityValue() { + SoftApConfiguration config = new SoftApConfiguration.Builder(mConfig) + .setPassphrase("test_password", + SoftApConfiguration.SECURITY_TYPE_WPA2_PSK).build(); + when(mWifiManager.getSoftApConfiguration()).thenReturn(config); + + mController.updateDisplay(); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); + assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal"); + } + + @Test + public void updateDisplay_toNone_shouldUpdateSecurityValue() { + SoftApConfiguration config = new SoftApConfiguration.Builder(mConfig) + .setPassphrase(null, SoftApConfiguration.SECURITY_TYPE_OPEN).build(); + when(mWifiManager.getSoftApConfiguration()).thenReturn(config); + + mController.updateDisplay(); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_OPEN); + assertThat(mPreference.getSummary().toString()).isEqualTo("None"); + } + + @Test + public void updateDisplay_toWpa3SaeButNotSupportWpa3_shouldBeDefaultToWpa2() { + mController.mIsWpa3Supported = false; + SoftApConfiguration config = new SoftApConfiguration.Builder(mConfig) + .setPassphrase("test_password", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE).build(); + when(mWifiManager.getSoftApConfiguration()).thenReturn(config); + + mController.updateDisplay(); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); + assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal"); + } + + @Test + public void updateDisplay_toWpa3SaeTransitionButNotSupportWpa3_shouldBeDefaultToWpa2() { + mController.mIsWpa3Supported = false; + SoftApConfiguration config = new SoftApConfiguration.Builder(mConfig) + .setPassphrase("test_password", + SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION).build(); + when(mWifiManager.getSoftApConfiguration()).thenReturn(config); + + mController.updateDisplay(); + + assertThat(mController.getSecurityType()) + .isEqualTo(SoftApConfiguration.SECURITY_TYPE_WPA2_PSK); + assertThat(mPreference.getSummary().toString()).isEqualTo("WPA2-Personal"); + } +}