Snap for 12748980 from 4a84a244b2 to 25Q1-release

Change-Id: I7371f78beedc547234832ed232c659bce2e9d641
This commit is contained in:
Android Build Coastguard Worker
2024-12-05 00:17:41 +00:00
75 changed files with 4033 additions and 7293 deletions

View File

@@ -852,10 +852,15 @@
</activity>
<activity android:name=".network.SimOnboardingActivity"
android:exported="false"
android:exported="true"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|smallestScreenSize"
android:permission="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"
android:theme="@style/Theme.SpaLib.BottomSheetDialog"/>
android:theme="@style/Theme.SpaLib.BottomSheetDialog">
<intent-filter android:priority="1">
<action android:name="android.settings.SIM_PREFERENCE_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".network.telephony.ToggleSubscriptionDialogActivity"
android:exported="false"

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2024 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
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="412dp"
android:height="300dp"
android:viewportHeight="300"
android:viewportWidth="412">
<path
android:fillColor="#000000"
android:pathData="M384.2 300H27.8C12.5 300 0 287.2 0 271.5V28.5C0 12.8 12.5 0 27.8 0H384.3C399.5 0 412 12.8 412 28.5V271.7C412 287.2 399.5 300 384.2 300Z" />
<path
android:fillColor="#D2E3FC"
android:pathData="M272.5 77.2V82.9C277.9 82.9 282.3 87.3 282.3 92.7C282.3 98.1 277.9 102.5 272.5 102.5V108.2C281.1 108.2 288 101.2 288 92.7C288 84.2 281 77.2 272.5 77.2Z" />
<path
android:fillColor="#669DF6"
android:pathData="M282.3 92.7C282.3 87.3 277.9 82.9 272.5 82.9V102.6C277.9 102.6 282.3 98.2 282.3 92.7Z" />
<path
android:fillColor="#80868B"
android:pathData="M274.9 97.7V88.2C274.9 86.9 273.8 85.8 272.5 85.8V35.9C272.5 29.3 267.2 24 260.6 24H151.3C144.7 24 139.4 29.3 139.4 35.9V264.1C139.4 270.7 144.7 276 151.3 276H260.7C267.3 276 272.6 270.7 272.6 264.1V147.6C273.9 147.6 275 146.5 275 145.2V121.4C275 120.1 273.9 119 272.6 119V100C273.9 100.1 274.9 99 274.9 97.7ZM270.2 264.1C270.2 269.3 265.9 273.6 260.7 273.6H151.3C146.1 273.6 141.8 269.3 141.8 264.1V35.9C141.8 30.7 146.1 26.4 151.3 26.4H260.7C265.9 26.4 270.2 30.7 270.2 35.9V264.1Z" />
<path
android:fillColor="#E8EAED"
android:pathData="M270.2 264.1C270.2 269.3 265.9 273.6 260.7 273.6H151.3C146.1 273.6 141.8 269.3 141.8 264.1V35.9C141.8 30.7 146.1 26.4 151.3 26.4H260.7C265.9 26.4 270.2 30.7 270.2 35.9V264.1Z" />
<path
android:fillColor="#000000"
android:pathData="M194.64 151.3C192.292 151.3 190.281 150.464 188.609 148.791C186.936 147.119 186.1 145.109 186.1 142.76V125.68C186.1 123.332 186.936 121.321 188.609 119.649C190.281 117.976 192.292 117.14 194.64 117.14H220.26C222.608 117.14 224.619 117.976 226.291 119.649C227.964 121.321 228.8 123.332 228.8 125.68V142.76C228.8 145.109 227.964 147.119 226.291 148.791C224.619 150.464 222.608 151.3 220.26 151.3H194.64ZM194.64 126.214H220.26C221.292 126.214 222.253 126.374 223.142 126.694C224.067 127.014 224.886 127.477 225.597 128.082V125.68C225.597 124.186 225.082 122.922 224.05 121.89C223.018 120.858 221.754 120.343 220.26 120.343H194.64C193.145 120.343 191.882 120.858 190.85 121.89C189.818 122.922 189.303 124.186 189.303 125.68V128.082C190.014 127.477 190.815 127.014 191.704 126.694C192.63 126.374 193.608 126.214 194.64 126.214ZM189.463 133.473L214.922 139.611C215.172 139.682 215.421 139.7 215.67 139.664C215.954 139.593 216.186 139.469 216.364 139.291L224.904 132.138C224.441 131.32 223.801 130.662 222.982 130.164C222.164 129.665 221.256 129.416 220.26 129.416H194.64C193.395 129.416 192.292 129.808 191.331 130.591C190.37 131.338 189.747 132.298 189.463 133.473Z" />
</vector>

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright (C) 2024 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
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="412dp"
android:height="300dp"
android:viewportHeight="300"
android:viewportWidth="412">
<path
android:fillColor="#FFFFFF"
android:pathData="M384.2 300H27.8C12.5 300 0 287.2 0 271.5V28.5C0 12.8 12.5 0 27.8 0H384.3C399.5 0 412 12.8 412 28.5V271.7C412 287.2 399.5 300 384.2 300Z" />
<path
android:fillColor="#8AB4F8"
android:pathData="M272.5 77.2V82.9C277.9 82.9 282.3 87.3 282.3 92.7C282.3 98.1 277.9 102.5 272.5 102.5V108.2C281.1 108.2 288 101.2 288 92.7C288 84.2 281 77.2 272.5 77.2Z" />
<path
android:fillColor="#669DF6"
android:pathData="M282.3 92.7C282.3 87.3 277.9 82.9 272.5 82.9V102.6C277.9 102.6 282.3 98.2 282.3 92.7Z" />
<path
android:fillColor="#DADCE0"
android:pathData="M274.9 97.7V88.2C274.9 86.9 273.8 85.8 272.5 85.8V35.9C272.5 29.3 267.2 24 260.6 24H151.3C144.7 24 139.4 29.3 139.4 35.9V264.1C139.4 270.7 144.7 276 151.3 276H260.7C267.3 276 272.6 270.7 272.6 264.1V147.6C273.9 147.6 275 146.5 275 145.2V121.4C275 120.1 273.9 119 272.6 119V100C273.9 100.1 274.9 99 274.9 97.7ZM270.2 264.1C270.2 269.3 265.9 273.6 260.7 273.6H151.3C146.1 273.6 141.8 269.3 141.8 264.1V35.9C141.8 30.7 146.1 26.4 151.3 26.4H260.7C265.9 26.4 270.2 30.7 270.2 35.9V264.1Z" />
<path
android:fillColor="#3C4043"
android:pathData="M270.2 264.1C270.2 269.3 265.9 273.6 260.7 273.6H151.3C146.1 273.6 141.8 269.3 141.8 264.1V35.9C141.8 30.7 146.1 26.4 151.3 26.4H260.7C265.9 26.4 270.2 30.7 270.2 35.9V264.1Z" />
<path
android:fillColor="#FFFFFF"
android:pathData="M194.64 151.3C192.292 151.3 190.281 150.464 188.609 148.791C186.936 147.119 186.1 145.109 186.1 142.76V125.68C186.1 123.332 186.936 121.321 188.609 119.649C190.281 117.976 192.292 117.14 194.64 117.14H220.26C222.608 117.14 224.619 117.976 226.291 119.649C227.964 121.321 228.8 123.332 228.8 125.68V142.76C228.8 145.109 227.964 147.119 226.291 148.791C224.619 150.464 222.608 151.3 220.26 151.3H194.64ZM194.64 126.214H220.26C221.292 126.214 222.253 126.374 223.142 126.694C224.067 127.014 224.886 127.477 225.597 128.082V125.68C225.597 124.186 225.082 122.922 224.05 121.89C223.018 120.858 221.754 120.343 220.26 120.343H194.64C193.145 120.343 191.882 120.858 190.85 121.89C189.818 122.922 189.303 124.186 189.303 125.68V128.082C190.014 127.477 190.815 127.014 191.704 126.694C192.63 126.374 193.608 126.214 194.64 126.214ZM189.463 133.473L214.922 139.611C215.172 139.682 215.421 139.7 215.67 139.664C215.954 139.593 216.186 139.469 216.364 139.291L224.904 132.138C224.441 131.32 223.801 130.662 222.982 130.164C222.164 129.665 221.256 129.416 220.26 129.416H194.64C193.395 129.416 192.292 129.808 191.331 130.591C190.37 131.338 189.747 132.298 189.463 133.473Z" />
</vector>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -842,4 +842,7 @@
<!-- Package name for Linux terminal app -->
<string name="config_linux_terminal_app_package_name" translatable="false">com.android.virtualization.terminal</string>
<!-- Disable the Testing Setting Menu for user builds, i.e only display the menu on userdebug/eng builds -->
<bool name="config_hide_testing_settings_menu_for_user_builds">false</bool>
</resources>

View File

@@ -11158,6 +11158,23 @@
<!-- Summary text for double tap power for camera [CHAR LIMIT=160]-->
<string name="double_tap_power_for_camera_summary">To quickly open camera, press the power button twice. Works from any screen.</string>
<!-- Title text for double tap power gesture [CHAR LIMIT=80]-->
<string name="double_tap_power_title">Double tap power button</string>
<!-- Summary for double tap power settings [DO NOT TRANSLATE] -->
<string name="double_tap_power_summary" translatable="false"><xliff:g id="double_tap_power_on_off" example="On">%1$s</xliff:g> / <xliff:g id="double_tap_power_actions" example="Access Wallet">%2$s</xliff:g></string>
<!-- Switch label to enable/disable double tap power button gesture [CHAR LIMIT=60] -->
<string name="double_tap_power_enabled">Use double tap</string>
<!-- Category title for double tap power gesture [CHAR_LIMIT=80] -->
<string name="double_tap_power_target_action_category">Double Tap Power Button</string>
<!-- Double Tap Power Gesture camera launch action title [CHAR_LIMIT=60] -->
<string name="double_tap_power_camera_action_title">Open Camera</string>
<!-- Setting summary to describe double tap power button will open camera. [CHAR LIMIT=NONE] -->
<string name="double_tap_power_camera_action_summary">Access Camera</string>
<!-- Double Tap Power Gesture wallet launch action title [CHAR_LIMIT=60] -->
<string name="double_tap_power_wallet_action_title">Open Wallet</string>
<!-- Setting summary to describe double tap power button will open wallet. [CHAR LIMIT=NONE] -->
<string name="double_tap_power_wallet_action_summary">Access Wallet</string>
<!-- Title text for double twist for camera mode [CHAR LIMIT=60]-->
<string name="double_twist_for_camera_mode_title">Flip camera for selfie</string>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project
Copyright (C) 2024 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.
@@ -18,19 +18,28 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/double_tap_power_for_camera_title">
android:title="@string/double_tap_power_title">
<com.android.settingslib.widget.IllustrationPreference
android:key="gesture_double_tap_power_video"
settings:searchable="false"
app:lottie_rawRes="@drawable/quickly_open_camera"/>
<SwitchPreferenceCompat
android:key="gesture_double_tap_power"
android:title="@string/double_tap_power_for_camera_title"
android:summary="@string/double_tap_power_for_camera_summary"
app:keywords="@string/keywords_gesture"
app:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController"/>
settings:lottie_rawRes="@drawable/quickly_open_camera"
settings:controller="com.android.settings.gestures.DoubleTapPowerIllustrationPreferenceController"/>
<com.android.settingslib.widget.MainSwitchPreference
android:key="gesture_double_tap_power_enabled_main_switch"
android:title="@string/double_tap_power_enabled"
settings:keywords="@string/keywords_gesture"
settings:controller="com.android.settings.gestures.DoubleTapPowerMainSwitchPreferenceController"/>
<PreferenceCategory
android:key="gesture_double_tap_power_actions"
android:title="@string/double_tap_power_target_action_category">
<com.android.settingslib.widget.SelectorWithWidgetPreference
android:key="gesture_double_power_tap_camera"
android:title="@string/double_tap_power_camera_action_title"
settings:controller="com.android.settings.gestures.DoubleTapPowerForCameraPreferenceController"/>
<com.android.settingslib.widget.SelectorWithWidgetPreference
android:key="gesture_double_power_tap_wallet"
android:title="@string/double_tap_power_wallet_action_title"
settings:controller="com.android.settings.gestures.DoubleTapPowerForWalletPreferenceController"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.
-->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/double_tap_power_for_camera_title">
<com.android.settingslib.widget.IllustrationPreference
android:key="gesture_double_tap_power_video"
settings:searchable="false"
settings:lottie_rawRes="@drawable/quickly_open_camera"/>
<SwitchPreferenceCompat
android:key="gesture_double_tap_power"
android:title="@string/double_tap_power_for_camera_title"
android:summary="@string/double_tap_power_for_camera_summary"
settings:keywords="@string/keywords_gesture"
settings:controller="com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController"/>
</PreferenceScreen>

View File

@@ -29,7 +29,7 @@
<Preference
android:key="gesture_double_tap_power_input_summary"
android:title="@string/double_tap_power_for_camera_title"
android:title="@string/double_tap_power_title"
android:fragment="com.android.settings.gestures.DoubleTapPowerSettings"
settings:searchable="false"
settings:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" />

View File

@@ -19,6 +19,7 @@ package com.android.settings;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.telephony.TelephonyManager;
import com.android.settings.Settings.TestingSettingsActivity;
@@ -32,11 +33,17 @@ public class TestingSettingsBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null
&& intent.getAction().equals(TelephonyManager.ACTION_SECRET_CODE)) {
&& intent.getAction().equals(TelephonyManager.ACTION_SECRET_CODE)
&& !isDisabled(context)) {
Intent i = new Intent(Intent.ACTION_MAIN);
i.setClass(context, TestingSettingsActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
private boolean isDisabled(Context context) {
return "user".equals(Build.TYPE) && context.getResources().getBoolean(
R.bool.config_hide_testing_settings_menu_for_user_builds);
}
}

View File

@@ -1,149 +0,0 @@
/*
* Copyright (C) 2022 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 android.content.ComponentName;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreate;
import com.android.settingslib.core.lifecycle.events.OnDestroy;
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
/** PrimarySwitchPreferenceController that shows quick settings tooltip on first use. */
public abstract class AccessibilityQuickSettingsPrimarySwitchPreferenceController
extends TogglePreferenceController
implements LifecycleObserver, OnCreate, OnDestroy, OnSaveInstanceState {
private static final String KEY_SAVED_QS_TOOLTIP_RESHOW = "qs_tooltip_reshow";
private final Handler mHandler;
private PrimarySwitchPreference mPreference;
private AccessibilityQuickSettingsTooltipWindow mTooltipWindow;
private boolean mNeedsQSTooltipReshow = false;
/** Returns the accessibility tile component name. */
@Nullable
abstract ComponentName getTileComponentName();
/** Returns the accessibility tile tooltip content. */
abstract CharSequence getTileTooltipContent();
public AccessibilityQuickSettingsPrimarySwitchPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
mHandler = new Handler(context.getMainLooper());
}
@Override
public void onCreate(Bundle savedInstanceState) {
// Restore the tooltip.
if (savedInstanceState != null) {
if (savedInstanceState.containsKey(KEY_SAVED_QS_TOOLTIP_RESHOW)) {
mNeedsQSTooltipReshow = savedInstanceState.getBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW);
}
}
}
@Override
public void onDestroy() {
mHandler.removeCallbacksAndMessages(null);
final boolean isTooltipWindowShowing = mTooltipWindow != null && mTooltipWindow.isShowing();
if (isTooltipWindowShowing) {
mTooltipWindow.dismiss();
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
final boolean isTooltipWindowShowing = mTooltipWindow != null && mTooltipWindow.isShowing();
if (mNeedsQSTooltipReshow || isTooltipWindowShowing) {
outState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, /* value= */ true);
}
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
if (mNeedsQSTooltipReshow) {
mHandler.post(this::showQuickSettingsTooltipIfNeeded);
}
}
@Override
public boolean setChecked(boolean isChecked) {
if (isChecked) {
showQuickSettingsTooltipIfNeeded();
}
return isChecked;
}
@Override
public boolean isChecked() {
return false;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_accessibility;
}
private void showQuickSettingsTooltipIfNeeded() {
if (mPreference == null) {
// Returns if no preference found by slice highlight menu.
return;
}
final ComponentName tileComponentName = getTileComponentName();
if (tileComponentName == null) {
// Returns if no tile service assigned.
return;
}
if (!mNeedsQSTooltipReshow && AccessibilityQuickSettingUtils.hasValueInSharedPreferences(
mContext, tileComponentName)) {
// Returns if quick settings tooltip only show once.
return;
}
// TODO (287728819): Move tooltip showing to SystemUI
// Since the lifecycle of controller is independent of that of the preference, doing
// null check on switch is a temporary solution for the case that switch view
// is not ready when we would like to show the tooltip. If the switch is not ready,
// we give up showing the tooltip and also do not reshow it in the future.
if (mPreference.getSwitch() != null) {
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(mContext);
mTooltipWindow.setup(getTileTooltipContent(),
R.drawable.accessibility_auto_added_qs_tooltip_illustration);
mTooltipWindow.showAtTopCenter(mPreference.getSwitch());
}
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(mContext, tileComponentName);
mNeedsQSTooltipReshow = false;
}
}

View File

@@ -177,9 +177,7 @@ public class AccessibilitySettings extends DashboardFragment implements
// Observe changes from accessibility selection menu
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
}
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_STICKY_KEYS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SLOW_KEYS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS);

View File

@@ -31,7 +31,6 @@ import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -114,9 +113,7 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
final List<String> shortcutFeatureKeys = new ArrayList<>();
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
}
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler());
mSettingsContentObserver.registerKeysToObserverCallback(shortcutFeatureKeys, key -> {
updateShortcutPreferenceData();
@@ -374,38 +371,13 @@ public abstract class AccessibilityShortcutPreferenceFragment extends Restricted
showQuickSettingsTooltipIfNeeded();
}
/**
* @deprecated made obsolete by quick settings rollout.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
private void showQuickSettingsTooltipIfNeeded() {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
// Don't show Quick Settings tooltip
return;
}
final ComponentName tileComponentName = getTileComponentName();
if (tileComponentName == null) {
// Returns if no tile service assigned.
return;
}
if (!mNeedsQSTooltipReshow && AccessibilityQuickSettingUtils.hasValueInSharedPreferences(
getContext(), tileComponentName)) {
// Returns if quick settings tooltip only show once.
return;
}
final CharSequence content = getTileTooltipContent(mNeedsQSTooltipType);
if (TextUtils.isEmpty(content)) {
// Returns if no content of tile tooltip assigned.
return;
}
final int imageResId = mNeedsQSTooltipType == QuickSettingsTooltipType.GUIDE_TO_EDIT
? R.drawable.accessibility_qs_tooltip_illustration
: R.drawable.accessibility_auto_added_qs_tooltip_illustration;
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(getContext());
mTooltipWindow.setup(content, imageResId);
mTooltipWindow.showAtTopCenter(getView());
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(getContext(),
tileComponentName);
mNeedsQSTooltipReshow = false;
}
/**

View File

@@ -72,7 +72,6 @@ import com.android.settingslib.utils.StringUtil;
import com.android.settingslib.widget.LottieColorUtils;
import com.airbnb.lottie.LottieAnimationView;
import com.airbnb.lottie.LottieDrawable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -335,7 +334,8 @@ public final class AccessibilityShortcutsTutorial {
result -> Log.w(TAG, "Invalid image raw resource id: " + imageRawRes,
result));
lottieView.setAnimation(imageRawRes);
lottieView.setRepeatCount(LottieDrawable.INFINITE);
// Follow the Motion Stoppable requirement by using a finite animation.
lottieView.setRepeatCount(0);
LottieColorUtils.applyDynamicColors(context, lottieView);
lottieView.playAnimation();
@@ -496,10 +496,6 @@ public final class AccessibilityShortcutsTutorial {
if ((shortcutTypes & shortcutType) == 0) {
continue;
}
if ((shortcutTypes & QUICK_SETTINGS) == QUICK_SETTINGS
&& !android.view.accessibility.Flags.a11yQsShortcut()) {
continue;
}
tutorialPages.add(
createShortcutTutorialPage(
context, shortcutType, buttonMode, featureName, inSetupWizard));

View File

@@ -61,7 +61,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringJoiner;
/** Provides utility methods to accessibility settings only. */
public final class AccessibilityUtil {
@@ -203,28 +202,23 @@ public final class AccessibilityUtil {
* @param context The current context.
* @param shortcutTypes A combination of {@link UserShortcutType}.
* @param componentName The component name that need to be opted in Settings.
*
* @deprecated use
* {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
static void optInAllValuesToSettings(Context context, int shortcutTypes,
@NonNull ComponentName componentName) {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ true,
shortcutTypes,
Set.of(componentName.flattenToString()),
UserHandle.myUserId()
);
}
return;
}
if ((shortcutTypes & SOFTWARE) == SOFTWARE) {
optInValueToSettings(context, SOFTWARE, componentName);
}
if (((shortcutTypes & HARDWARE) == HARDWARE)) {
optInValueToSettings(context, HARDWARE, componentName);
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ true,
shortcutTypes,
Set.of(componentName.flattenToString()),
UserHandle.myUserId()
);
}
}
@@ -234,38 +228,25 @@ public final class AccessibilityUtil {
* @param context The current context.
* @param shortcutType The preferred shortcut type user selected.
* @param componentName The component name that need to be opted in Settings.
*
* @deprecated use
* {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
@VisibleForTesting
static void optInValueToSettings(Context context, @UserShortcutType int shortcutType,
@NonNull ComponentName componentName) {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ true,
shortcutType,
Set.of(componentName.flattenToString()),
UserHandle.myUserId()
);
}
return;
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ true,
shortcutType,
Set.of(componentName.flattenToString()),
UserHandle.myUserId()
);
}
final String targetKey = convertKeyFromSettings(shortcutType);
final String targetString = Settings.Secure.getString(context.getContentResolver(),
targetKey);
if (hasValueInSettings(context, shortcutType, componentName)) {
return;
}
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
if (!TextUtils.isEmpty(targetString)) {
joiner.add(targetString);
}
joiner.add(componentName.flattenToString());
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
}
/**
@@ -275,27 +256,23 @@ public final class AccessibilityUtil {
* @param context The current context.
* @param shortcutTypes A combination of {@link UserShortcutType}.
* @param componentName The component name that need to be opted out from Settings.
*
* @deprecated use
* {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
static void optOutAllValuesFromSettings(Context context, int shortcutTypes,
@NonNull ComponentName componentName) {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ false,
shortcutTypes,
Set.of(componentName.flattenToString()),
UserHandle.myUserId()
);
}
return;
}
if ((shortcutTypes & SOFTWARE) == SOFTWARE) {
optOutValueFromSettings(context, SOFTWARE, componentName);
}
if (((shortcutTypes & HARDWARE) == HARDWARE)) {
optOutValueFromSettings(context, HARDWARE, componentName);
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ false,
shortcutTypes,
Set.of(componentName.flattenToString()),
UserHandle.myUserId()
);
}
}
@@ -305,42 +282,25 @@ public final class AccessibilityUtil {
* @param context The current context.
* @param shortcutType The preferred shortcut type user selected.
* @param componentName The component name that need to be opted out from Settings.
*
* @deprecated use
* {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
@VisibleForTesting
static void optOutValueFromSettings(Context context, @UserShortcutType int shortcutType,
@NonNull ComponentName componentName) {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ false,
shortcutType,
Set.of(componentName.flattenToString()),
UserHandle.myUserId()
);
}
return;
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ false,
shortcutType,
Set.of(componentName.flattenToString()),
UserHandle.myUserId()
);
}
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
final String targetKey = convertKeyFromSettings(shortcutType);
final String targetString = Settings.Secure.getString(context.getContentResolver(),
targetKey);
if (TextUtils.isEmpty(targetString)) {
return;
}
sStringColonSplitter.setString(targetString);
while (sStringColonSplitter.hasNext()) {
final String name = sStringColonSplitter.next();
if (TextUtils.isEmpty(name) || (componentName.flattenToString()).equals(name)) {
continue;
}
joiner.add(name);
}
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
}
/**
@@ -354,11 +314,6 @@ public final class AccessibilityUtil {
static boolean hasValuesInSettings(Context context, int shortcutTypes,
@NonNull ComponentName componentName) {
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if (!android.view.accessibility.Flags.a11yQsShortcut()) {
if ((shortcutType & QUICK_SETTINGS) == QUICK_SETTINGS) {
continue;
}
}
if (!android.provider.Flags.a11yStandaloneGestureEnabled()) {
if ((shortcutType & GESTURE) == GESTURE) {
continue;
@@ -379,15 +334,16 @@ public final class AccessibilityUtil {
* @param shortcutType The preferred shortcut type user selected.
* @param componentName The component name that need to be checked existed in Settings.
* @return {@code true} if componentName existed in Settings.
*
* @deprecated use
* {@link ShortcutUtils#isShortcutContained(Context, int, String)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
@VisibleForTesting
static boolean hasValueInSettings(Context context, @UserShortcutType int shortcutType,
@NonNull ComponentName componentName) {
if (!android.view.accessibility.Flags.a11yQsShortcut()
&& (shortcutType & QUICK_SETTINGS) == QUICK_SETTINGS) {
return false;
}
return ShortcutUtils.getShortcutTargetsFromSettings(
context, shortcutType, UserHandle.myUserId()
).contains(componentName.flattenToString());
@@ -405,11 +361,6 @@ public final class AccessibilityUtil {
@NonNull ComponentName componentName) {
int shortcutTypes = DEFAULT;
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if (!android.view.accessibility.Flags.a11yQsShortcut()) {
if ((shortcutType & QUICK_SETTINGS) == QUICK_SETTINGS) {
continue;
}
}
if (!android.provider.Flags.a11yStandaloneGestureEnabled()) {
if ((shortcutType & GESTURE) == GESTURE) {
continue;
@@ -428,23 +379,15 @@ public final class AccessibilityUtil {
*
* @param shortcutType The shortcut type.
* @return Mapping key in Settings.
*
* @deprecated use
* {@link ShortcutUtils#convertToKey(int)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
static String convertKeyFromSettings(@UserShortcutType int shortcutType) {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
return ShortcutUtils.convertToKey(shortcutType);
}
switch (shortcutType) {
case SOFTWARE:
return Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
case HARDWARE:
return Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
case TRIPLETAP:
return Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED;
default:
throw new IllegalArgumentException(
"Unsupported userShortcutType " + shortcutType);
}
return ShortcutUtils.convertToKey(shortcutType);
}
/**
@@ -521,10 +464,6 @@ public final class AccessibilityUtil {
final List<CharSequence> list = new ArrayList<>();
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if (!android.view.accessibility.Flags.a11yQsShortcut()
&& (shortcutType & QUICK_SETTINGS) == QUICK_SETTINGS) {
continue;
}
if (!android.provider.Flags.a11yStandaloneGestureEnabled()
&& (shortcutType & GESTURE) == GESTURE) {
continue;

View File

@@ -76,9 +76,7 @@ public class ColorAndMotionFragment extends DashboardFragment {
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED);
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
}
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
if (Flags.forceInvertColor()) {
mShortcutFeatureKeys.add(ToggleForceInvertPreferenceController.SETTINGS_KEY);
}

View File

@@ -17,7 +17,6 @@
package com.android.settings.accessibility;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.DEFAULT;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.QUICK_SETTINGS;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE;
import android.content.ComponentName;
@@ -25,7 +24,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.view.accessibility.Flags;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
@@ -123,11 +121,6 @@ public final class PreferredShortcuts {
@NonNull Context context, @NonNull Set<String> components) {
final Map<Integer, Set<String>> shortcutTypeToTargets = new ArrayMap<>();
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if (!Flags.a11yQsShortcut()
&& shortcutType == QUICK_SETTINGS) {
// Skip saving quick setting as preferred shortcut option when flag is not enabled
continue;
}
shortcutTypeToTargets.put(
shortcutType,
ShortcutUtils.getShortcutTargetsFromSettings(

View File

@@ -16,9 +16,6 @@
package com.android.settings.accessibility;
import static com.android.internal.accessibility.AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME;
import android.content.ComponentName;
import android.content.Context;
import android.database.ContentObserver;
import android.hardware.display.ColorDisplayManager;
@@ -29,12 +26,12 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.server.display.feature.flags.Flags;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.PrimarySwitchPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
@@ -42,7 +39,7 @@ import com.android.settingslib.core.lifecycle.events.OnStop;
/** PreferenceController that shows the Reduce Bright Colors summary */
public class ReduceBrightColorsPreferenceController
extends AccessibilityQuickSettingsPrimarySwitchPreferenceController
extends TogglePreferenceController
implements LifecycleObserver, OnStart, OnStop {
private ContentObserver mSettingsContentObserver;
private PrimarySwitchPreference mPreference;
@@ -72,7 +69,6 @@ public class ReduceBrightColorsPreferenceController
@Override
public boolean setChecked(boolean isChecked) {
super.setChecked(isChecked);
return mColorDisplayManager.setReduceBrightColorsActivated(isChecked);
}
@@ -125,20 +121,4 @@ public class ReduceBrightColorsPreferenceController
public void onStop() {
mContext.getContentResolver().unregisterContentObserver(mSettingsContentObserver);
}
@Nullable
@Override
protected ComponentName getTileComponentName() {
// TODO: When clean up the feature flag, change the parent class from
// AccessibilityQuickSettingsPrimarySwitchPreferenceController to
// TogglePreferenceController
return android.view.accessibility.Flags.a11yQsShortcut()
? null : REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME;
}
@Override
CharSequence getTileTooltipContent() {
return mContext.getText(
R.string.accessibility_reduce_bright_colors_auto_added_qs_tooltip_content);
}
}

View File

@@ -452,15 +452,11 @@ public class ToggleAccessibilityServicePreferenceFragment extends
@Override
protected int getDefaultShortcutTypes() {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
AccessibilityServiceInfo info = getAccessibilityServiceInfo();
boolean isAccessibilityTool = info != null && info.isAccessibilityTool();
return !isAccessibilityTool || getTileComponentName() == null
? super.getDefaultShortcutTypes()
: ShortcutConstants.UserShortcutType.QUICK_SETTINGS;
}
return super.getDefaultShortcutTypes();
AccessibilityServiceInfo info = getAccessibilityServiceInfo();
boolean isAccessibilityTool = info != null && info.isAccessibilityTool();
return !isAccessibilityTool || getTileComponentName() == null
? super.getDefaultShortcutTypes()
: ShortcutConstants.UserShortcutType.QUICK_SETTINGS;
}
private void onAllowButtonFromEnableToggleClicked() {

View File

@@ -167,9 +167,7 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
final List<String> shortcutFeatureKeys = new ArrayList<>();
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
if (android.view.accessibility.Flags.a11yQsShortcut()) {
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
}
shortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
return shortcutFeatureKeys;
}
@@ -750,44 +748,13 @@ public abstract class ToggleFeaturePreferenceFragment extends DashboardFragment
showQuickSettingsTooltipIfNeeded();
}
/**
* @deprecated made obsolete by quick settings rollout.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
private void showQuickSettingsTooltipIfNeeded() {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
// Don't show Quick Settings tooltip
return;
}
final ComponentName tileComponentName = getTileComponentName();
if (tileComponentName == null) {
// Returns if no tile service assigned.
return;
}
Activity activity = getActivity();
if (activity != null && WizardManagerHelper.isAnySetupWizard(activity.getIntent())) {
// Don't show QuickSettingsTooltip in Setup Wizard
return;
}
if (!mNeedsQSTooltipReshow && AccessibilityQuickSettingUtils.hasValueInSharedPreferences(
getContext(), tileComponentName)) {
// Returns if quick settings tooltip only show once.
return;
}
final CharSequence content = getTileTooltipContent(mNeedsQSTooltipType);
if (TextUtils.isEmpty(content)) {
// Returns if no content of tile tooltip assigned.
return;
}
final int imageResId = mNeedsQSTooltipType == QuickSettingsTooltipType.GUIDE_TO_EDIT
? R.drawable.accessibility_qs_tooltip_illustration
: R.drawable.accessibility_auto_added_qs_tooltip_illustration;
mTooltipWindow = new AccessibilityQuickSettingsTooltipWindow(getContext());
mTooltipWindow.setup(content, imageResId);
mTooltipWindow.showAtTopCenter(getView());
AccessibilityQuickSettingUtils.optInValueToSharedPreferences(getContext(),
tileComponentName);
mNeedsQSTooltipReshow = false;
}
/** Returns user visible name of the tile by given {@link ComponentName}. */

View File

@@ -56,6 +56,7 @@ import androidx.preference.PreferenceCategory;
import androidx.preference.SwitchPreferenceCompat;
import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType;
import com.android.internal.accessibility.util.ShortcutUtils;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.accessibility.Flags;
import com.android.settings.DialogCreatable;
@@ -74,7 +75,6 @@ import com.google.android.setupcompat.util.WizardManagerHelper;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.StringJoiner;
import java.util.stream.Stream;
/**
@@ -203,13 +203,13 @@ public class ToggleScreenMagnificationPreferenceFragment extends
}
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
// LINT.IfChange(:preference_list)
// LINT.IfChange(preference_list)
addMagnificationModeSetting(generalCategory);
addFollowTypingSetting(generalCategory);
addOneFingerPanningSetting(generalCategory);
addAlwaysOnSetting(generalCategory);
addJoystickSetting(generalCategory);
// LINT.ThenChange(:search_data)
// LINT.ThenChange(search_data)
}
@Override
@@ -588,70 +588,29 @@ public class ToggleScreenMagnificationPreferenceFragment extends
optInMagnificationValueToSettings(context, TWOFINGER_DOUBLETAP);
}
}
if (android.view.accessibility.Flags.a11yQsShortcut()) {
if (((shortcutTypes & QUICK_SETTINGS)
== QUICK_SETTINGS)) {
optInMagnificationValueToSettings(context, QUICK_SETTINGS);
}
if (((shortcutTypes & QUICK_SETTINGS)
== QUICK_SETTINGS)) {
optInMagnificationValueToSettings(context, QUICK_SETTINGS);
}
}
/**
* @deprecated use
* {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
private static void optInMagnificationValueToSettings(
Context context, @UserShortcutType int shortcutType) {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ true,
shortcutType,
Set.of(MAGNIFICATION_CONTROLLER_NAME),
UserHandle.myUserId()
);
}
return;
}
if (shortcutType == TRIPLETAP) {
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
return;
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (shortcutType == TWOFINGER_DOUBLETAP) {
Settings.Secure.putInt(
context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
ON);
return;
}
}
if (hasMagnificationValueInSettings(context, shortcutType)) {
return;
}
final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
final String targetString = Settings.Secure.getString(context.getContentResolver(),
targetKey);
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
if (!TextUtils.isEmpty(targetString)) {
joiner.add(targetString);
}
joiner.add(MAGNIFICATION_CONTROLLER_NAME);
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
// The size setting defaults to unknown. If the user has ever manually changed the size
// before, we do not automatically change it.
if (shortcutType == SOFTWARE
&& Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.UNKNOWN)
== FloatingMenuSizePreferenceController.Size.UNKNOWN) {
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.LARGE);
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ true,
shortcutType,
Set.of(MAGNIFICATION_CONTROLLER_NAME),
UserHandle.myUserId()
);
}
}
@@ -676,65 +635,30 @@ public class ToggleScreenMagnificationPreferenceFragment extends
optOutMagnificationValueFromSettings(context, TWOFINGER_DOUBLETAP);
}
}
if (android.view.accessibility.Flags.a11yQsShortcut()) {
if (((shortcutTypes & QUICK_SETTINGS)
if (((shortcutTypes & QUICK_SETTINGS)
== QUICK_SETTINGS)) {
optOutMagnificationValueFromSettings(context, QUICK_SETTINGS);
}
optOutMagnificationValueFromSettings(context, QUICK_SETTINGS);
}
}
/**
* @deprecated use
* {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
private static void optOutMagnificationValueFromSettings(Context context,
@UserShortcutType int shortcutType) {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ false,
shortcutType,
Set.of(MAGNIFICATION_CONTROLLER_NAME),
UserHandle.myUserId()
);
}
return;
AccessibilityManager a11yManager = context.getSystemService(AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(
/* enable= */ false,
shortcutType,
Set.of(MAGNIFICATION_CONTROLLER_NAME),
UserHandle.myUserId()
);
}
if (shortcutType == TRIPLETAP) {
Settings.Secure.putInt(context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
return;
}
if (Flags.enableMagnificationMultipleFingerMultipleTapGesture()) {
if (shortcutType == TWOFINGER_DOUBLETAP) {
Settings.Secure.putInt(
context.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
OFF);
return;
}
}
final String targetKey = AccessibilityUtil.convertKeyFromSettings(shortcutType);
final String targetString = Settings.Secure.getString(context.getContentResolver(),
targetKey);
if (TextUtils.isEmpty(targetString)) {
return;
}
final StringJoiner joiner = new StringJoiner(String.valueOf(COMPONENT_NAME_SEPARATOR));
sStringColonSplitter.setString(targetString);
while (sStringColonSplitter.hasNext()) {
final String name = sStringColonSplitter.next();
if (TextUtils.isEmpty(name) || MAGNIFICATION_CONTROLLER_NAME.equals(name)) {
continue;
}
joiner.add(name);
}
Settings.Secure.putString(context.getContentResolver(), targetKey, joiner.toString());
}
@VisibleForTesting
@@ -788,15 +712,16 @@ public class ToggleScreenMagnificationPreferenceFragment extends
return false;
}
/**
* @deprecated use
* {@link ShortcutUtils#getEnabledShortcutTypes(Context, String)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
private static int getUserShortcutTypeFromSettings(Context context) {
int shortcutTypes = DEFAULT;
for (int shortcutType : AccessibilityUtil.SHORTCUTS_ORDER_IN_UI) {
if ((shortcutType & (TWOFINGER_DOUBLETAP | QUICK_SETTINGS | GESTURE | TRIPLETAP))
== shortcutType
&& !android.view.accessibility.Flags.a11yQsShortcut()) {
// These shortcuts will throw if we try to look up their settings without the flag.
continue;
}
if (hasMagnificationValueInSettings(context, shortcutType)) {
shortcutTypes |= shortcutType;
}
@@ -831,7 +756,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
// LINT.IfChange(:search_data)
// LINT.IfChange(search_data)
@Override
public List<SearchIndexableRaw> getRawDataToIndex(Context context,
boolean enabled) {
@@ -887,7 +812,7 @@ public class ToggleScreenMagnificationPreferenceFragment extends
}
return niks;
}
// LINT.ThenChange(:preference_list)
// LINT.ThenChange(preference_list)
private SearchIndexableRaw createPreferenceSearchData(
Context context, Preference pref) {

View File

@@ -25,7 +25,6 @@ import android.os.UserHandle;
import android.service.quicksettings.TileService;
import android.util.ArraySet;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
@@ -82,8 +81,7 @@ public class QuickSettingsShortcutOptionController extends ShortcutOptionPrefere
@Override
protected boolean isShortcutAvailable() {
return Flags.a11yQsShortcut()
&& TileService.isQuickSettingsSupported()
return TileService.isQuickSettingsSupported()
&& allTargetsHasQsTile()
&& allTargetsHasValidQsTileUseCase();
}

View File

@@ -35,7 +35,6 @@ import com.android.settings.R;
import com.android.settingslib.widget.LottieColorUtils;
import com.airbnb.lottie.LottieAnimationView;
import com.airbnb.lottie.LottieDrawable;
/**
* A preference represents an accessibility shortcut option with a checkbox and a tutorial image
@@ -96,7 +95,8 @@ public class ShortcutOptionPreference extends CheckBoxPreference {
.getResourceEntryName(mIntroImageRawResId),
result));
imageView.setAnimation(mIntroImageRawResId);
imageView.setRepeatCount(LottieDrawable.INFINITE);
// Follow the Motion Stoppable requirement by using a finite animation.
imageView.setRepeatCount(0);
LottieColorUtils.applyDynamicColors(imageView.getContext(), imageView);
imageView.playAnimation();
} else {

View File

@@ -19,7 +19,6 @@ package com.android.settings.accessibility.shortcuts;
import android.content.Context;
import android.os.UserHandle;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
@@ -111,36 +110,27 @@ public abstract class ShortcutOptionPreferenceController extends BasePreferenceC
return !targets.isEmpty() && targets.containsAll(getShortcutTargets());
}
/**
* Enable or disable the shortcut for the given accessibility features.
*
* @deprecated use
* {@link AccessibilityManager#enableShortcutsForTargets(boolean, int, Set, int)} instead.
*
* (TODO 367414968: finish removal.)
*/
@Deprecated
protected void enableShortcutForTargets(boolean enable) {
Set<String> shortcutTargets = getShortcutTargets();
@ShortcutConstants.UserShortcutType int shortcutType = getShortcutType();
if (Flags.a11yQsShortcut()) {
AccessibilityManager a11yManager = mContext.getSystemService(
AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(enable, shortcutType, shortcutTargets,
UserHandle.myUserId());
}
return;
AccessibilityManager a11yManager = mContext.getSystemService(
AccessibilityManager.class);
if (a11yManager != null) {
a11yManager.enableShortcutsForTargets(enable, shortcutType, shortcutTargets,
UserHandle.myUserId());
}
if (enable) {
for (String target : shortcutTargets) {
ShortcutUtils.optInValueToSettings(mContext, shortcutType, target);
}
} else {
for (String target : shortcutTargets) {
ShortcutUtils.optOutValueFromSettings(mContext, shortcutType, target);
}
}
ShortcutUtils.updateInvisibleToggleAccessibilityServiceEnableState(
mContext, shortcutTargets, UserHandle.myUserId());
}
/**
* Returns true when the user can associate a shortcut to the targets
*/

View File

@@ -19,14 +19,11 @@ package com.android.settings.accessibility.shortcuts;
import static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
import android.content.Context;
import android.provider.Settings;
import android.view.View;
import android.view.accessibility.Flags;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityButtonFragment;
import com.android.settings.accessibility.FloatingMenuSizePreferenceController;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.utils.AnnotationSpan;
@@ -62,26 +59,4 @@ public abstract class SoftwareShortcutOptionPreferenceController
R.string.accessibility_shortcut_edit_dialog_summary_software_floating),
linkInfo);
}
@Override
protected void enableShortcutForTargets(boolean enable) {
super.enableShortcutForTargets(enable);
if (Flags.a11yQsShortcut()) {
return;
}
if (enable) {
// Update the A11y FAB size to large when the Magnification shortcut is enabled
// and the user hasn't changed the floating button size
if (isMagnificationInTargets()
&& Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.UNKNOWN)
== FloatingMenuSizePreferenceController.Size.UNKNOWN) {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.LARGE);
}
}
}
}

View File

@@ -20,7 +20,6 @@ import static com.android.internal.accessibility.AccessibilityShortcutController
import android.content.Context;
import android.provider.Settings;
import android.view.accessibility.Flags;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -99,17 +98,4 @@ public class TripleTapShortcutOptionController extends ShortcutOptionPreferenceC
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
AccessibilityUtil.State.OFF) == AccessibilityUtil.State.ON;
}
@Override
protected void enableShortcutForTargets(boolean enable) {
if (Flags.a11yQsShortcut()) {
super.enableShortcutForTargets(enable);
return;
}
Settings.Secure.putInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
enable ? AccessibilityUtil.State.ON : AccessibilityUtil.State.OFF);
}
}

View File

@@ -86,16 +86,4 @@ public class TwoFingerDoubleTapShortcutOptionController
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
AccessibilityUtil.State.OFF) == AccessibilityUtil.State.ON;
}
@Override
protected void enableShortcutForTargets(boolean enable) {
if (android.view.accessibility.Flags.a11yQsShortcut()) {
super.enableShortcutForTargets(enable);
return;
}
Settings.Secure.putInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
enable ? AccessibilityUtil.State.ON : AccessibilityUtil.State.OFF);
}
}

View File

@@ -17,14 +17,12 @@
package com.android.settings.accessibility.shortcuts;
import android.content.Context;
import android.view.accessibility.Flags;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityUtil;
/**
* A controller handles displaying the volume keys shortcut option preference and
@@ -61,16 +59,4 @@ public class VolumeKeysShortcutOptionController extends ShortcutOptionPreference
protected boolean isShortcutAvailable() {
return true;
}
@Override
protected void enableShortcutForTargets(boolean enable) {
super.enableShortcutForTargets(enable);
if (Flags.a11yQsShortcut()) {
return;
}
if (enable) {
AccessibilityUtil.skipVolumeShortcutDialogTimeoutRestriction(mContext);
}
}
}

View File

@@ -19,9 +19,118 @@ package com.android.settings.connecteddevice.display
import com.android.settings.R
import android.content.Context
import android.graphics.Point
import android.graphics.PointF
import android.graphics.RectF
import androidx.preference.Preference
import java.util.Locale
import kotlin.math.max
import kotlin.math.min
/**
* Contains the parameters needed for transforming global display coordinates to and from topology
* pane coordinates. This is necessary for implementing an interactive display topology pane. The
* pane allows dragging and dropping display blocks into place to define the topology. Conversion to
* pane coordinates is necessary when rendering the original topology. Conversion in the other
* direction, to display coordinates, is necessary for resolve a drag position to display space.
*
* The topology pane coordinates are integral and represent the relative position from the upper-
* left corner of the pane. It uses a scale optimized for showing all displays with minimal or no
* scrolling. The display coordinates are floating point and the origin can be in any position. In
* practice the origin will be the upper-left coordinate of the primary display.
*/
class TopologyScale(paneWidth : Int, displaysPos : Collection<RectF>) {
/** Scale of block sizes to real-world display sizes. Should be less than 1. */
val blockRatio : Float
/** Height of topology pane needed to allow all display blocks to appear with some padding. */
val paneHeight : Int
/** Pane's X view coordinate that corresponds with topology's X=0 coordinate. */
val originPaneX : Int
/** Pane's Y view coordinate that corresponds with topology's Y=0 coordinate. */
val originPaneY : Int
init {
val displayBounds = RectF(
Float.MAX_VALUE, Float.MAX_VALUE, Float.MIN_VALUE, Float.MIN_VALUE)
var smallestDisplayDim = Float.MAX_VALUE
var biggestDisplayHeight = Float.MIN_VALUE
// displayBounds is the smallest rect encompassing all displays, in display space.
// smallestDisplayDim is the size of the smallest display edge, in display space.
for (pos in displaysPos) {
displayBounds.union(pos)
smallestDisplayDim = minOf(smallestDisplayDim, pos.height(), pos.width())
biggestDisplayHeight = max(biggestDisplayHeight, pos.height())
}
// Set height according to the width and the aspect ratio of the display bounds.
// 0.05 is a reasonable limit to the size of display blocks. It appears to match the
// ratio used in the ChromeOS topology editor. It prevents blocks from being too large,
// which would make dragging and dropping awkward.
val rawBlockRatio = min(0.05, paneWidth.toDouble() * 0.6 / displayBounds.width())
// If the `ratio` is set too low because one of the displays will have an edge less than
// 48dp long, increase it such that the smallest edge is that long. This may override the
// 0.05 limit since it is more important than it.
blockRatio = max(48.0 / smallestDisplayDim, rawBlockRatio).toFloat()
// Essentially, we just set the pane height based on the pre-determined pane width and the
// aspect ratio of the display bounds. But we may need to increase it slightly to achieve
// 20% padding above and below the display bounds - this is where the 0.6 comes from.
val rawPaneHeight = max(
paneWidth.toDouble() / displayBounds.width() * displayBounds.height(),
displayBounds.height() * blockRatio / 0.6)
// It is easy for the aspect ratio to result in an excessively tall pane, since the width is
// pre-determined and may be considerably wider than necessary. So we prevent the height
// from growing too large here, by limiting vertical padding to the size of the tallest
// display. This improves results for very tall display bounds.
paneHeight = min(
rawPaneHeight.toInt(),
(blockRatio * (displayBounds.height() + biggestDisplayHeight * 2f)).toInt())
// Set originPaneXY (the location of 0,0 in display space in the pane's coordinate system)
// such that the display bounds rect is centered in the pane.
// It is unlikely that either of these coordinates will be negative since blockRatio has
// been chosen to allow 20% padding around each side of the display blocks. However, the
// a11y requirement applied above (48.0 / smallestDisplayDim) may cause the blocks to not
// fit. This should be rare in practice, and can be worked around by moving the settings UI
// to a larger display.
val blockMostLeft = (paneWidth - displayBounds.width() * blockRatio) / 2
val blockMostTop = (paneHeight - displayBounds.height() * blockRatio) / 2
originPaneX = (blockMostLeft - displayBounds.left * blockRatio).toInt()
originPaneY = (blockMostTop - displayBounds.top * blockRatio).toInt()
}
/** Transforms coordinates in view pane space to display space. */
fun paneToDisplayCoor(panePos : Point) : PointF {
return PointF(
(panePos.x - originPaneX).toFloat() / blockRatio,
(panePos.y - originPaneY).toFloat() / blockRatio)
}
/** Transforms coordinates in display space to view pane space. */
fun displayToPaneCoor(displayPos : PointF) : Point {
return Point(
(displayPos.x * blockRatio).toInt() + originPaneX,
(displayPos.y * blockRatio).toInt() + originPaneY)
}
override fun toString() : String {
return String.format(
Locale.ROOT,
"{TopoScale blockRatio=%f originPaneXY=%d,%d paneHeight=%d}",
blockRatio, originPaneX, originPaneY, paneHeight)
}
}
const val PREFERENCE_KEY = "display_topology_preference"
/**

View File

@@ -0,0 +1,114 @@
/*
* Copyright (C) 2024 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.gestures;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
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;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
public class DoubleTapPowerForCameraPreferenceController extends BasePreferenceController
implements LifecycleObserver, OnStart, OnStop {
@Nullable private Preference mPreference;
private final ContentObserver mSettingsObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
if (mPreference == null || uri == null) {
return;
}
if (uri.equals(
DoubleTapPowerSettingsUtils
.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI)) {
mPreference.setEnabled(
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(
mContext));
} else if (uri.equals(
DoubleTapPowerSettingsUtils
.DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI)) {
updateState(mPreference);
}
}
};
public DoubleTapPowerForCameraPreferenceController(
@NonNull Context context, @NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
if (!DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)
? AVAILABLE
: DISABLED_DEPENDENT_SETTING;
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public void updateState(@NonNull Preference preference) {
super.updateState(preference);
if (preference instanceof SelectorWithWidgetPreference) {
((SelectorWithWidgetPreference) preference)
.setChecked(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext));
}
}
@Override
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
if (!getPreferenceKey().equals(preference.getKey())) {
return false;
}
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
if (preference instanceof SelectorWithWidgetPreference) {
((SelectorWithWidgetPreference) preference).setChecked(true);
}
return true;
}
@Override
public void onStart() {
DoubleTapPowerSettingsUtils.registerObserver(mContext, mSettingsObserver);
}
@Override
public void onStop() {
DoubleTapPowerSettingsUtils.unregisterObserver(mContext, mSettingsObserver);
}
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright (C) 2024 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.gestures;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
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;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
public class DoubleTapPowerForWalletPreferenceController extends BasePreferenceController
implements LifecycleObserver, OnStart, OnStop {
@Nullable private Preference mPreference;
private final ContentObserver mSettingsObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
if (mPreference == null || uri == null) {
return;
}
if (uri.equals(
DoubleTapPowerSettingsUtils
.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI)) {
mPreference.setEnabled(
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(
mContext));
} else if (uri.equals(
DoubleTapPowerSettingsUtils
.DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI)) {
updateState(mPreference);
}
}
};
public DoubleTapPowerForWalletPreferenceController(
@NonNull Context context, @NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
if (!DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)
? AVAILABLE
: DISABLED_DEPENDENT_SETTING;
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public void updateState(@NonNull Preference preference) {
super.updateState(preference);
if (preference instanceof SelectorWithWidgetPreference) {
((SelectorWithWidgetPreference) preference)
.setChecked(
!DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext));
}
}
@Override
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
if (!getPreferenceKey().equals(preference.getKey())) {
return false;
}
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
if (preference instanceof SelectorWithWidgetPreference) {
((SelectorWithWidgetPreference) preference).setChecked(true);
}
return true;
}
@Override
public void onStart() {
DoubleTapPowerSettingsUtils.registerObserver(mContext, mSettingsObserver);
}
@Override
public void onStop() {
DoubleTapPowerSettingsUtils.unregisterObserver(mContext, mSettingsObserver);
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2024 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.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
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;
import com.android.settingslib.widget.IllustrationPreference;
/** Configures the behaviour of the double tap power illustration. */
public class DoubleTapPowerIllustrationPreferenceController extends BasePreferenceController
implements LifecycleObserver, OnStart, OnStop {
@Nullable
private IllustrationPreference mIllustrationPreference;
private final ContentObserver mSettingsObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
if (mIllustrationPreference != null && uri != null) {
updateState(mIllustrationPreference);
}
}
};
public DoubleTapPowerIllustrationPreferenceController(
@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
mIllustrationPreference = screen.findPreference(getPreferenceKey());
}
@Override
public void updateState(@NonNull Preference preference) {
super.updateState(preference);
((IllustrationPreference) preference)
.setLottieAnimationResId(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
mContext)
? R.drawable.quickly_open_camera
: R.drawable.double_tap_power_for_wallet);
}
@Override
public void onStart() {
final ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI, true, mSettingsObserver);
}
@Override
public void onStop() {
DoubleTapPowerSettingsUtils.unregisterObserver(mContext, mSettingsObserver);
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (C) 2024 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.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.settings.R;
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
/** The controller to handle double tap power button main switch enable or disable state. */
public class DoubleTapPowerMainSwitchPreferenceController
extends SettingsMainSwitchPreferenceController
implements LifecycleObserver, OnStart, OnStop {
private final ContentObserver mSettingsObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
if (mSwitchPreference == null || uri == null) {
return;
}
updateState(mSwitchPreference);
}
};
public DoubleTapPowerMainSwitchPreferenceController(
@NonNull Context context, @NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isChecked() {
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
return DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(
mContext, isChecked);
}
@Override
public void onStart() {
final ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(
DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI, true, mSettingsObserver);
}
@Override
public void onStop() {
DoubleTapPowerSettingsUtils.unregisterObserver(mContext, mSettingsObserver);
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -21,22 +21,17 @@ import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_D
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@VisibleForTesting
static final int ON = 0;
@VisibleForTesting
static final int OFF = 1;
public class DoubleTapPowerPreferenceController extends BasePreferenceController {
private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
private final String SECURE_KEY = CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
public DoubleTapPowerPreferenceController(Context context, String key) {
public DoubleTapPowerPreferenceController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
@@ -45,9 +40,13 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
|| prefs.getBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, false);
}
private static boolean isGestureAvailable(Context context) {
return context.getResources()
.getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
private static boolean isGestureAvailable(@NonNull Context context) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
return context.getResources()
.getBoolean(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(context);
}
@Override
@@ -56,30 +55,41 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(), "gesture_double_tap_power");
public void displayPreference(@NonNull PreferenceScreen screen) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
final Preference preference = screen.findPreference(getPreferenceKey());
if (preference != null) {
preference.setTitle(R.string.double_tap_power_for_camera_title);
}
}
super.displayPreference(screen);
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
protected String getVideoPrefKey() {
return PREF_KEY_VIDEO;
}
@Override
public boolean isChecked() {
final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
SECURE_KEY, ON);
return cameraDisabled == ON;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
isChecked ? ON : OFF);
@NonNull
public CharSequence getSummary() {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
final boolean isCameraDoubleTapPowerGestureEnabled =
Settings.Secure.getInt(
mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
DoubleTapPowerToOpenCameraPreferenceController.ON)
== DoubleTapPowerToOpenCameraPreferenceController.ON;
return mContext.getText(
isCameraDoubleTapPowerGestureEnabled
? R.string.gesture_setting_on
: R.string.gesture_setting_off);
}
if (DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)) {
final CharSequence onString =
mContext.getText(com.android.settings.R.string.gesture_setting_on);
final CharSequence actionString =
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
mContext)
? mContext.getText(R.string.double_tap_power_camera_action_summary)
: mContext.getText(R.string.double_tap_power_wallet_action_summary);
return mContext.getString(R.string.double_tap_power_summary, onString, actionString);
}
return mContext.getText(com.android.settings.R.string.gesture_setting_off);
}
}

View File

@@ -19,6 +19,9 @@ package com.android.settings.gestures;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.SearchIndexableResource;
import androidx.annotation.NonNull;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -27,6 +30,8 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import java.util.List;
@SearchIndexable
public class DoubleTapPowerSettings extends DashboardFragment {
@@ -56,9 +61,24 @@ public class DoubleTapPowerSettings extends DashboardFragment {
@Override
protected int getPreferenceScreenResId() {
return R.xml.double_tap_power_settings;
return android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()
? R.xml.double_tap_power_settings
: R.xml.double_tap_power_to_open_camera_settings;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.double_tap_power_settings);
new BaseSearchIndexProvider() {
@Override
@NonNull
public List<SearchIndexableResource> getXmlResourcesToIndex(
@NonNull Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId =
android.service.quickaccesswallet.Flags
.launchWalletOptionOnPowerDoubleTap()
? R.xml.double_tap_power_settings
: R.xml.double_tap_power_to_open_camera_settings;
return List.of(sir);
}
};
}

View File

@@ -0,0 +1,149 @@
/*
* Copyright (C) 2016 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.gestures;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.provider.Settings;
import androidx.annotation.NonNull;
import com.android.internal.R;
/** Common code for double tap power settings shared between controllers. */
final class DoubleTapPowerSettingsUtils {
/** Setting storing whether the double tap power button gesture is enabled. */
private static final String DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED =
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED;
static final Uri DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI =
Settings.Secure.getUriFor(DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED);
/** Setting storing the target action of the double tap power button gesture. */
private static final String DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION =
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE;
static final Uri DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI =
Settings.Secure.getUriFor(DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION);
private static final int DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE = 0;
private static final int DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE = 1;
static final int ON = 1;
static final int OFF = 0;
/**
* @return true if double tap power button gesture is available.
*/
public static boolean isDoubleTapPowerButtonGestureAvailable(@NonNull Context context) {
return context.getResources().getBoolean(R.bool.config_doubleTapPowerGestureEnabled);
}
/**
* Gets double tap power button gesture enable or disable flag from Settings provider.
*
* @return true if double tap on the power button gesture is currently enabled.
* @param context App context
*/
public static boolean isDoubleTapPowerButtonGestureEnabled(@NonNull Context context) {
return Settings.Secure.getInt(
context.getContentResolver(), DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, ON)
== ON;
}
/**
* Sets double tap power button gesture enable or disable flag to Settings provider.
*
* @param context App context
* @param enable enable or disable double tap power button gesture.
* @return {@code true} if the setting is updated.
*/
public static boolean setDoubleTapPowerButtonGestureEnabled(
@NonNull Context context, boolean enable) {
return Settings.Secure.putInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
enable ? ON : OFF);
}
/**
* @return true if double tap on the power button gesture for camera launch is currently
* enabled.
* @param context App context
*/
public static boolean isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
@NonNull Context context) {
return Settings.Secure.getInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
context.getResources()
.getInteger(
com.android.internal.R.integer
.config_defaultDoubleTapPowerGestureAction))
== DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE;
}
/**
* Sets double tap power button gesture behavior to launch the camera.
*
* @param context App context
* @return {@code true} if the setting is updated.
*/
public static boolean setDoubleTapPowerButtonForCameraLaunch(@NonNull Context context) {
return Settings.Secure.putInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
}
/**
* Sets double tap power button gesture behavior to launch the wallet.
*
* @param context App context
* @return {@code true} if the setting is updated.
*/
public static boolean setDoubleTapPowerButtonForWalletLaunch(@NonNull Context context) {
return Settings.Secure.putInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
}
/**
* Registers observer for settings state.
*
* @param observer Settings Content Observer
*/
public static void registerObserver(
@NonNull Context context, @NonNull ContentObserver observer) {
final ContentResolver resolver = context.getContentResolver();
resolver.registerContentObserver(
DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI, true, observer);
resolver.registerContentObserver(
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI, true, observer);
}
/** Unregisters observer. */
public static void unregisterObserver(
@NonNull Context context, @NonNull ContentObserver observer) {
final ContentResolver resolver = context.getContentResolver();
resolver.unregisterContentObserver(observer);
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2024 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.gestures;
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class DoubleTapPowerToOpenCameraPreferenceController extends TogglePreferenceController {
static final int ON = 0;
static final int OFF = 1;
public DoubleTapPowerToOpenCameraPreferenceController(
@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return mContext.getResources()
.getBoolean(
com.android.internal.R.bool
.config_cameraDoubleTapPowerGestureEnabled)
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(
mContext.getContentResolver(), CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON)
== ON;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(
mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
isChecked ? ON : OFF);
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(), "gesture_double_tap_power");
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -109,6 +109,12 @@ class SimOnboardingActivity : SpaBaseDialogActivity() {
}
var targetSubId = intent.getIntExtra(SUB_ID,SubscriptionManager.INVALID_SUBSCRIPTION_ID)
if (targetSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
targetSubId = intent.getIntExtra(
Settings.EXTRA_SUB_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID
)
}
initServiceData(this, targetSubId, callbackListener)
if (!onboardingService.isUsableTargetSubscriptionId) {
Log.e(TAG, "The subscription id is not usable.")
@@ -608,4 +614,4 @@ class SimOnboardingActivity : SpaBaseDialogActivity() {
CALLBACK_FINISH(5)
}
}
}
}

View File

@@ -42,6 +42,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.UserManager;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
@@ -91,6 +92,11 @@ public class SimSelectNotification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
UserManager userManager = context.getSystemService(UserManager.class);
if (userManager != null && !userManager.isMainUser()) {
Log.d(TAG, "The userId is not the main user");
return;
}
if (!SubscriptionUtil.isSimHardwareVisible(context)) {
Log.w(TAG, "Received unexpected intent with null action.");
return;

View File

@@ -16,22 +16,31 @@
package com.android.settings.wifi
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.net.wifi.WifiManager
import android.os.UserManager
import android.provider.Settings
import android.util.Log
import android.widget.Toast
import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceChangeListener
import com.android.settings.PreferenceRestrictionMixin
import com.android.settings.R
import com.android.settings.network.SatelliteRepository
import com.android.settings.overlay.FeatureFactory.Companion.featureFactory
import com.android.settings.widget.GenericSwitchController
import com.android.settings.network.SatelliteWarningDialogActivity
import com.android.settingslib.RestrictedSwitchPreference
import com.android.settingslib.WirelessUtils
import com.android.settingslib.datastore.AbstractKeyedDataObservable
import com.android.settingslib.datastore.DataChangeReason
import com.android.settingslib.datastore.KeyValueStore
import com.android.settingslib.datastore.NoOpKeyedObservable
import com.android.settingslib.metadata.*
import com.android.settingslib.metadata.PreferenceLifecycleProvider
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.ReadWritePermit
import com.android.settingslib.metadata.SensitivityLevel
import com.android.settingslib.metadata.SwitchPreference
import com.android.settingslib.preference.SwitchPreferenceBinding
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
@@ -40,12 +49,10 @@ import java.util.concurrent.TimeUnit
class WifiSwitchPreference :
SwitchPreference(KEY, R.string.wifi),
SwitchPreferenceBinding,
OnPreferenceChangeListener,
PreferenceLifecycleProvider,
PreferenceRestrictionMixin {
// TODO(b/372733639) Remove WifiEnabler and migrate to catalyst
private var wifiEnabler: WifiEnabler? = null
override val keywords: Int
get() = R.string.keywords_wifi
@@ -57,21 +64,57 @@ class WifiSwitchPreference :
override val useAdminDisabledSummary: Boolean
get() = true
override fun createWidget(context: Context) = RestrictedSwitchPreference(context)
override fun bind(preference: Preference, metadata: PreferenceMetadata) {
super.bind(preference, metadata)
preference.onPreferenceChangeListener = this
}
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
val context = preference.context
// Show dialog and do nothing under satellite mode.
if (context.isSatelliteOn()) {
context.startActivity(
Intent(context, SatelliteWarningDialogActivity::class.java)
.putExtra(
SatelliteWarningDialogActivity.EXTRA_TYPE_OF_SATELLITE_WARNING_DIALOG,
SatelliteWarningDialogActivity.TYPE_IS_WIFI,
)
)
return false
}
// Show toast message if Wi-Fi is not allowed in airplane mode
if (newValue == true && !context.isRadioAllowed()) {
Toast.makeText(context, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show()
return false
}
return true
}
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) =
ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) =
when {
isRadioAllowed(context, value) && !isSatelliteOn(context) -> ReadWritePermit.ALLOW
else -> ReadWritePermit.DISALLOW
(value == true && !context.isRadioAllowed()) || context.isSatelliteOn() ->
ReadWritePermit.DISALLOW
else -> ReadWritePermit.ALLOW
}
override val sensitivityLevel
get() = SensitivityLevel.LOW_SENSITIVITY
override fun storage(context: Context): KeyValueStore = WifiSwitchStore(context)
@Suppress("UNCHECKED_CAST")
private class WifiSwitchStore(private val context: Context) :
NoOpKeyedObservable<String>(),
KeyValueStore {
AbstractKeyedDataObservable<String>(), KeyValueStore {
private var broadcastReceiver: BroadcastReceiver? = null
override fun contains(key: String) =
key == KEY && context.getSystemService(WifiManager::class.java) != null
@@ -85,60 +128,51 @@ class WifiSwitchPreference :
context.getSystemService(WifiManager::class.java)?.isWifiEnabled = value
}
}
}
override fun onCreate(context: PreferenceLifecycleContext) {
context.requirePreference<RestrictedSwitchPreference>(KEY).let {
it.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference, newValue: Any ->
if (!isRadioAllowed(context, newValue as Boolean?)) {
Log.w(TAG, "Don't set APM, AIRPLANE_MODE_RADIOS is not allowed")
return@OnPreferenceChangeListener false
override fun onFirstObserverAdded() {
broadcastReceiver =
object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val wifiState = intent.wifiState
// do not notify for enabling/disabling state
if (
wifiState == WifiManager.WIFI_STATE_ENABLED ||
wifiState == WifiManager.WIFI_STATE_DISABLED
) {
notifyChange(KEY, DataChangeReason.UPDATE)
}
}
if (isSatelliteOn(context)) {
Log.w(TAG, "Don't set APM, the satellite is on")
return@OnPreferenceChangeListener false
}
return@OnPreferenceChangeListener true
}
val widget = GenericSwitchController(it)
wifiEnabler = WifiEnabler(context, widget, featureFactory.metricsFeatureProvider)
Log.i(TAG, "Create WifiEnabler:$wifiEnabler")
context.registerReceiver(
broadcastReceiver,
IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION),
)
}
}
override fun onResume(context: PreferenceLifecycleContext) {
wifiEnabler?.resume(context)
}
override fun onPause(context: PreferenceLifecycleContext) {
wifiEnabler?.pause()
}
override fun onDestroy(context: PreferenceLifecycleContext) {
wifiEnabler?.teardownSwitchController()
wifiEnabler = null
}
private fun isRadioAllowed(context: Context, newValue: Boolean?): Boolean {
newValue?.let { if (!it) return true } ?: return false
return WirelessUtils.isRadioAllowed(context, Settings.Global.RADIO_WIFI)
}
private fun isSatelliteOn(context: Context): Boolean {
try {
return SatelliteRepository(context)
.requestIsSessionStarted(Executors.newSingleThreadExecutor())
.get(2000, TimeUnit.MILLISECONDS)
} catch (e: Exception) {
Log.e(TAG, "Error to get satellite status : $e")
override fun onLastObserverRemoved() {
broadcastReceiver?.let { context.unregisterReceiver(it) }
}
return false
}
companion object {
const val TAG = "WifiSwitchPreference"
const val KEY = "main_toggle_wifi"
private fun Context.isRadioAllowed() =
WirelessUtils.isRadioAllowed(this, Settings.Global.RADIO_WIFI)
private fun Context.isSatelliteOn() =
try {
SatelliteRepository(this)
.requestIsSessionStarted(Executors.newSingleThreadExecutor())
.get(2000, TimeUnit.MILLISECONDS)
} catch (e: Exception) {
Log.e(TAG, "Error to get satellite status : $e")
false
}
private val Intent.wifiState
get() = getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN)
}
}
// LINT.ThenChange(WifiSwitchPreferenceController.java)

View File

@@ -18,9 +18,13 @@ package com.android.settings;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.telephony.TelephonyManager;
import org.junit.Before;
@@ -29,6 +33,7 @@ import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowBuild;
@RunWith(RobolectricTestRunner.class)
public class TestingSettingsBroadcastReceiverTest {
@@ -78,4 +83,68 @@ public class TestingSettingsBroadcastReceiverTest {
final String dest = next.getComponent().getClassName();
assertThat(dest).isEqualTo(Settings.TestingSettingsActivity.class.getName());
}
@Test
public void onReceive_disabledForUserBuild_BuildType_User_shouldNotStartActivity() {
// TestingSettingsMenu should be disabled if current Build.TYPE is "user" and
// 'config_hide_testing_settings_menu_for_user_builds' is true
ShadowBuild.setType("user");
mContext = spy(RuntimeEnvironment.application);
setUpConfig(mContext, true /*disable for user build*/);
final Intent intent = new Intent();
intent.setAction(TelephonyManager.ACTION_SECRET_CODE);
mReceiver.onReceive(mContext, intent);
final Intent next = Shadows.shadowOf(mApplication).getNextStartedActivity();
assertThat(next).isNull();
}
@Test
public void onReceive_disabledForUserBuild_BuildType_Userdebug_shouldStartActivity() {
// TestingSettingsMenu should not be disabled if current Build.TYPE is "userdebug" and
// 'config_hide_testing_settings_menu_for_user_builds' is true
ShadowBuild.setType("userdebug");
mContext = spy(RuntimeEnvironment.application);
setUpConfig(mContext, true /*disable for user build*/);
final Intent intent = new Intent();
intent.setAction(TelephonyManager.ACTION_SECRET_CODE);
mReceiver.onReceive(mContext, intent);
final Intent next = Shadows.shadowOf(mApplication).getNextStartedActivity();
assertThat(next).isNotNull();
final String dest = next.getComponent().getClassName();
assertThat(dest).isEqualTo(Settings.TestingSettingsActivity.class.getName());
}
@Test
public void onReceive_notDisabledForUserBuildType_shouldStartActivity() {
// TestingSettingsMenu should not be disabled if
// 'config_hide_testing_settings_menu_for_user_builds' is false, regardless of Build.TYPE
mContext = spy(RuntimeEnvironment.application);
setUpConfig(mContext, false /*disable for user build*/);
final Intent intent = new Intent();
intent.setAction(TelephonyManager.ACTION_SECRET_CODE);
mReceiver.onReceive(mContext, intent);
final Intent next = Shadows.shadowOf(mApplication).getNextStartedActivity();
assertThat(next).isNotNull();
final String dest = next.getComponent().getClassName();
assertThat(dest).isEqualTo(Settings.TestingSettingsActivity.class.getName());
}
private static void setUpConfig(Context context, boolean disabledForUserBuild) {
when(context.getApplicationContext()).thenReturn(context);
Resources spiedResources = spy(context.getResources());
when(context.getResources()).thenReturn(spiedResources);
when(spiedResources.getBoolean(R.bool.config_hide_testing_settings_menu_for_user_builds))
.thenReturn(disabledForUserBuild);
}
}

View File

@@ -1,198 +0,0 @@
/*
* Copyright (C) 2022 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 com.android.settings.accessibility.ToggleFeaturePreferenceFragment.KEY_SAVED_QS_TOOLTIP_RESHOW;
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.when;
import android.content.ComponentName;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settingslib.PrimarySwitchPreference;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowLooper;
/**
* Tests for {@link AccessibilityQuickSettingsPrimarySwitchPreferenceController}.
*/
@RunWith(RobolectricTestRunner.class)
public class AccessibilityQuickSettingsPrimarySwitchPreferenceControllerTest {
private static final String PLACEHOLDER_PACKAGE_NAME = "com.placeholder.example";
private static final String PLACEHOLDER_TILE_CLASS_NAME =
PLACEHOLDER_PACKAGE_NAME + "tile.placeholder";
private static final ComponentName PLACEHOLDER_TILE_COMPONENT_NAME = new ComponentName(
PLACEHOLDER_PACKAGE_NAME, PLACEHOLDER_TILE_CLASS_NAME);
private static final CharSequence PLACEHOLDER_TILE_CONTENT =
PLACEHOLDER_TILE_CLASS_NAME + ".tile.content";
private static final String TEST_KEY = "test_pref_key";
private static final String TEST_TITLE = "test_title";
@Rule
public final MockitoRule mockito = MockitoJUnit.rule();
@Spy
private final Context mContext = ApplicationProvider.getApplicationContext();
private TestAccessibilityQuickSettingsPrimarySwitchPreferenceController mController;
private PrimarySwitchPreference mPreference;
private TestFragment mFragment;
private PreferenceScreen mScreen;
private PreferenceViewHolder mHolder;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceManager mPreferenceManager;
private static PopupWindow getLatestPopupWindow() {
final ShadowApplication shadowApplication =
Shadow.extract(ApplicationProvider.getApplicationContext());
return shadowApplication.getLatestPopupWindow();
}
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext.setTheme(androidx.appcompat.R.style.Theme_AppCompat);
mFragment = spy(new TestFragment());
when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
when(mFragment.getContext()).thenReturn(mContext);
mScreen = spy(new PreferenceScreen(mContext, /* attrs= */ null));
when(mScreen.getPreferenceManager()).thenReturn(mPreferenceManager);
doReturn(mScreen).when(mFragment).getPreferenceScreen();
mPreference = new PrimarySwitchPreference(mContext);
mPreference.setKey(TEST_KEY);
mPreference.setTitle(TEST_TITLE);
LayoutInflater inflater = LayoutInflater.from(mContext);
mHolder = PreferenceViewHolder.createInstanceForTests(inflater.inflate(
com.android.settingslib.widget.preference.twotarget.R.layout.preference_two_target, null));
LinearLayout mWidgetView = mHolder.itemView.findViewById(android.R.id.widget_frame);
inflater.inflate(R.layout.preference_widget_primary_switch, mWidgetView, true);
mPreference.onBindViewHolder(mHolder);
mController = new TestAccessibilityQuickSettingsPrimarySwitchPreferenceController(mContext,
TEST_KEY);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
@Test
public void setChecked_showTooltipView() {
mController.displayPreference(mScreen);
mController.setChecked(true);
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
@Test
public void setChecked_notCallDisplayPreference_notShowTooltipView() {
// Simulates the slice highlight menu that does not call {@link #displayPreference} before
// {@link #setChecked} called.
mController.setChecked(true);
assertThat(getLatestPopupWindow()).isNull();
}
@Test
public void setChecked_tooltipViewShown_notShowTooltipView() {
mController.displayPreference(mScreen);
mController.setChecked(true);
getLatestPopupWindow().dismiss();
mController.setChecked(false);
mController.setChecked(true);
assertThat(getLatestPopupWindow().isShowing()).isFalse();
}
@Test
@Config(shadows = ShadowFragment.class)
public void restoreValueFromSavedInstanceState_showTooltipView() {
final Bundle savedInstanceState = new Bundle();
savedInstanceState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, /* value= */ true);
mController.onCreate(savedInstanceState);
mController.displayPreference(mScreen);
ShadowLooper.idleMainLooper();
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
public static class TestAccessibilityQuickSettingsPrimarySwitchPreferenceController
extends AccessibilityQuickSettingsPrimarySwitchPreferenceController {
public TestAccessibilityQuickSettingsPrimarySwitchPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
}
@Override
ComponentName getTileComponentName() {
return PLACEHOLDER_TILE_COMPONENT_NAME;
}
@Override
CharSequence getTileTooltipContent() {
return PLACEHOLDER_TILE_CONTENT;
}
}
private static class TestFragment extends SettingsPreferenceFragment {
@Override
protected boolean shouldSkipForInitialSUW() {
return false;
}
@Override
public int getMetricsCategory() {
return 0;
}
}
}

View File

@@ -376,21 +376,7 @@ public class AccessibilitySettingsTest {
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onCreate_flagDisabled_haveRegisterToSpecificUrisAndActions() {
setupFragment();
assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
AccessibilitySettingsContentObserver.class).isTrue();
assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE,
AccessibilitySettingsContentObserver.class).isTrue();
assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_QS_TARGETS,
AccessibilitySettingsContentObserver.class).isFalse();
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onCreate_flagEnabled_haveRegisterToSpecificUrisAndActions() {
public void onCreate_haveRegisterToSpecificUrisAndActions() {
setupFragment();
assertUriObserversContainsClazz(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,

View File

@@ -19,7 +19,6 @@ package com.android.settings.accessibility;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.QUICK_SETTINGS;
import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE;
import static com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment.KEY_SAVED_QS_TOOLTIP_RESHOW;
import static com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import static com.google.common.truth.Truth.assertThat;
@@ -38,14 +37,11 @@ import android.content.Context;
import android.content.Intent;
import android.icu.text.CaseMap;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.Flags;
import android.widget.PopupWindow;
import androidx.annotation.Nullable;
@@ -156,25 +152,6 @@ public class AccessibilityShortcutPreferenceFragmentTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = ShadowFragment.class)
public void restoreValueFromSavedInstanceState_showTooltipView() {
mContext.setTheme(androidx.appcompat.R.style.Theme_AppCompat);
mFragment.showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_EDIT);
assertThat(getLatestPopupWindow().isShowing()).isTrue();
final Bundle savedInstanceState = new Bundle();
savedInstanceState.putBoolean(KEY_SAVED_QS_TOOLTIP_RESHOW, /* value= */ true);
mFragment.onAttach(mContext);
mFragment.onCreate(savedInstanceState);
mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
mFragment.onViewCreated(mFragment.getView(), savedInstanceState);
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = ShadowFragment.class)
public void showQuickSettingsTooltipIfNeeded_qsFlagOn_dontShowTooltipView() {
mFragment.showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_EDIT);
@@ -219,7 +196,6 @@ public class AccessibilityShortcutPreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getShortcutTypeSummary_shortcutSummaryIsCorrectlySet() {
final PreferredShortcut userPreferredShortcut = new PreferredShortcut(
PLACEHOLDER_COMPONENT_NAME.flattenToString(),

View File

@@ -133,7 +133,6 @@ public final class AccessibilityShortcutsTutorialTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void createTutorialPages_turnOnQuickSettingShortcut_hasOnePage() {
mShortcutTypes |= QUICK_SETTINGS;
@@ -260,7 +259,6 @@ public final class AccessibilityShortcutsTutorialTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void createAccessibilityTutorialDialog_qsShortcut_inSuwTalkbackOn_verifyText() {
mShortcutTypes |= QUICK_SETTINGS;
setTouchExplorationEnabled(true);
@@ -292,7 +290,6 @@ public final class AccessibilityShortcutsTutorialTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void createAccessibilityTutorialDialog_qsShortcut_notInSuwTalkbackOn_verifyText() {
mShortcutTypes |= QUICK_SETTINGS;
setTouchExplorationEnabled(true);
@@ -318,7 +315,6 @@ public final class AccessibilityShortcutsTutorialTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void createAccessibilityTutorialDialog_qsShortcut_inSuwTalkbackOff_verifyText() {
mShortcutTypes |= QUICK_SETTINGS;
setTouchExplorationEnabled(false);
@@ -349,7 +345,6 @@ public final class AccessibilityShortcutsTutorialTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void createAccessibilityTutorialDialog_qsShortcut_notInSuwTalkbackOff_verifyText() {
mShortcutTypes |= QUICK_SETTINGS;
setTouchExplorationEnabled(false);

View File

@@ -46,7 +46,6 @@ import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.test.core.app.ApplicationProvider;
@@ -203,7 +202,6 @@ public final class AccessibilityUtilTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getUserShortcutTypeFromSettings_threeShortcutTypesChosen() {
setShortcut(SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
setShortcut(HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
@@ -220,22 +218,6 @@ public final class AccessibilityUtilTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInAllValuesToSettings_optInValue_haveMatchString() {
clearShortcuts();
int shortcutTypes = SOFTWARE | HARDWARE;
AccessibilityUtil.optInAllValuesToSettings(mContext, shortcutTypes, MOCK_COMPONENT_NAME);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
MOCK_COMPONENT_NAME.flattenToString());
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEqualTo(
MOCK_COMPONENT_NAME.flattenToString());
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInAllValuesToSettings_optInValue_callsA11yManager() {
AccessibilityManager a11yManager =
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
@@ -252,20 +234,6 @@ public final class AccessibilityUtilTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInValueToSettings_optInValue_haveMatchString() {
setShortcut(SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
AccessibilityUtil.optInValueToSettings(mContext, SOFTWARE,
MOCK_COMPONENT_NAME2);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
MOCK_COMPONENT_NAME.flattenToString() + ":"
+ MOCK_COMPONENT_NAME2.flattenToString());
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInValueToSettings_optInValue_callsA11yManager() {
AccessibilityManager a11yManager =
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
@@ -281,37 +249,6 @@ public final class AccessibilityUtilTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInValueToSettings_optInTwoValues_haveMatchString() {
setShortcut(SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
AccessibilityUtil.optInValueToSettings(mContext, SOFTWARE,
MOCK_COMPONENT_NAME2);
AccessibilityUtil.optInValueToSettings(mContext, SOFTWARE,
MOCK_COMPONENT_NAME2);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
MOCK_COMPONENT_NAME.flattenToString() + ":"
+ MOCK_COMPONENT_NAME2.flattenToString());
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutAllValuesToSettings_optOutValue_emptyString() {
setShortcut(SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
setShortcut(HARDWARE, MOCK_COMPONENT_NAME.flattenToString());
int shortcutTypes =
SOFTWARE | HARDWARE | TRIPLETAP;
AccessibilityUtil.optOutAllValuesFromSettings(mContext, shortcutTypes,
MOCK_COMPONENT_NAME);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEmpty();
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEmpty();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutAllValuesToSettings_optOutValue_callsA1yManager() {
AccessibilityManager a11yManager =
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
@@ -331,31 +268,6 @@ public final class AccessibilityUtilTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutValueFromSettings_optOutValue_emptyString() {
setShortcut(SOFTWARE, MOCK_COMPONENT_NAME.flattenToString());
AccessibilityUtil.optOutValueFromSettings(mContext, SOFTWARE,
MOCK_COMPONENT_NAME);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEmpty();
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutValueFromSettings_optOutValue_haveMatchString() {
setShortcut(SOFTWARE, MOCK_COMPONENT_NAME.flattenToString(),
MOCK_COMPONENT_NAME2.flattenToString());
AccessibilityUtil.optOutValueFromSettings(mContext, SOFTWARE,
MOCK_COMPONENT_NAME2);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
MOCK_COMPONENT_NAME.flattenToString());
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutValueFromSettings_optOutValue_callsA11yManager() {
AccessibilityManager a11yManager =
AccessibilityTestUtils.setupMockAccessibilityManager(mContext);
@@ -389,7 +301,6 @@ public final class AccessibilityUtilTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void convertKeyFromSettings_shortcutTypeMultiFingersMultiTap() {
assertThat(AccessibilityUtil.convertKeyFromSettings(TWOFINGER_DOUBLETAP))
.isEqualTo(
@@ -397,7 +308,6 @@ public final class AccessibilityUtilTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void convertKeyFromSettings_shortcutTypeQuickSettings() {
assertThat(AccessibilityUtil.convertKeyFromSettings(QUICK_SETTINGS))
.isEqualTo(Settings.Secure.ACCESSIBILITY_QS_TARGETS);

View File

@@ -26,8 +26,8 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.settings.SettingsEnums;
import android.content.ContentResolver;

View File

@@ -30,10 +30,10 @@ import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.R;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;

View File

@@ -31,9 +31,9 @@ import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.After;
@@ -42,8 +42,8 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
/** Test for {@link MediaVibrationIntensityPreferenceController}. */
@RunWith(RobolectricTestRunner.class)

View File

@@ -34,13 +34,8 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.service.quicksettings.TileService;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
@@ -55,7 +50,6 @@ import com.android.settings.accessibility.shortcuts.EditShortcutsPreferenceFragm
import com.android.settings.widget.SettingsMainSwitchPreference;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
@@ -75,8 +69,6 @@ import java.util.Set;
@RunWith(RobolectricTestRunner.class)
public class ToggleAccessibilityServicePreferenceFragmentTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private static final String PLACEHOLDER_PACKAGE_NAME = "com.placeholder.example";
private static final String PLACEHOLDER_PACKAGE_NAME2 = "com.placeholder.example2";
private static final String PLACEHOLDER_SERVICE_CLASS_NAME = "a11yservice1";
@@ -314,30 +306,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getDefaultShortcutTypes_noAssociatedTile_softwareTypeIsDefault() throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
setupAccessibilityServiceInfoForFragment(
/* isAccessibilityTool= */ true,
/* tileService= */ null
/* warningRequired= */);
assertThat(mFragment.getDefaultShortcutTypes())
.isEqualTo(ShortcutConstants.UserShortcutType.SOFTWARE);
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getDefaultShortcutTypes_hasAssociatedTile_softwareTypeIsDefault() {
PreferredShortcuts.clearPreferredShortcuts(mContext);
when(mFragment.getTileComponentName()).thenReturn(PLACEHOLDER_TILE_COMPONENT_NAME);
assertThat(mFragment.getDefaultShortcutTypes())
.isEqualTo(ShortcutConstants.UserShortcutType.SOFTWARE);
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getDefaultShortcutTypes_isAccessibilityTool_hasAssociatedTile_qsTypeIsDefault()
throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
@@ -351,7 +319,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getDefaultShortcutTypes_isNotAccessibilityTool_hasAssociatedTile_softwareTypeIsDefault()
throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
@@ -365,7 +332,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getDefaultShortcutTypes_isAccessibilityTool_noAssociatedTile_softwareTypeIsDefault()
throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
@@ -379,7 +345,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getDefaultShortcutTypes_isNotAccessibilityTool_noAssociatedTile_softwareTypeIsDefault()
throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
@@ -393,7 +358,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void toggleShortcutPreference_noUserPreferredShortcut_hasQsTile_enableQsShortcut()
throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
@@ -413,7 +377,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void toggleShortcutPreference_noUserPreferredShortcut_noQsTile_enableSoftwareShortcut()
throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
@@ -433,47 +396,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void toggleShortcutPreference_noUserPreferredShortcut_hasQsTile_flagOff_enableSoftwareShortcut()
throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
setupAccessibilityServiceInfoForFragment(
/* isAccessibilityTool= */ true,
/* tileService= */ PLACEHOLDER_TILE_COMPONENT_NAME
/* warningRequired= */);
mFragment.mShortcutPreference = new ShortcutPreference(mContext, /* attrs= */ null);
mFragment.mShortcutPreference.setChecked(true);
mFragment.onToggleClicked(mFragment.mShortcutPreference);
assertThat(
Settings.Secure.getString(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS))
.contains(mFragment.mComponentName.flattenToString());
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void toggleShortcutPreference_noUserPreferredShortcut_noQsTile_flagOff_enableSoftwareShortcut()
throws Throwable {
PreferredShortcuts.clearPreferredShortcuts(mContext);
setupAccessibilityServiceInfoForFragment(
/* isAccessibilityTool= */ true,
/* tileService= */ null
/* warningRequired= */);
mFragment.mShortcutPreference = new ShortcutPreference(mContext, /* attrs= */ null);
mFragment.mShortcutPreference.setChecked(true);
mFragment.onToggleClicked(mFragment.mShortcutPreference);
assertThat(
Settings.Secure.getString(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS))
.contains(mFragment.mComponentName.flattenToString());
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void toggleShortcutPreference_userPreferVolumeKeysShortcut_noQsTile_enableVolumeKeysShortcut()
throws Throwable {
setupAccessibilityServiceInfoForFragment(
@@ -498,7 +420,6 @@ public class ToggleAccessibilityServicePreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void toggleShortcutPreference_userPreferVolumeKeysShortcut_hasQsTile_enableVolumeKeysShortcut()
throws Throwable {
setupAccessibilityServiceInfoForFragment(

View File

@@ -139,25 +139,6 @@ public class ToggleColorInversionPreferenceFragmentTest {
assertThat(getLatestPopupWindow()).isNull();
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onPreferenceToggled_colorCorrectDisabled_shouldReturnTrueAndShowTooltipView() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, OFF);
mSwitchPreference.setChecked(false);
mFragment.onAttach(mContext);
mFragment.onCreateView(LayoutInflater.from(mContext), mock(ViewGroup.class), Bundle.EMPTY);
mFragment.onViewCreated(mFragment.getView(), Bundle.EMPTY);
mFragment.onPreferenceToggled(mSwitchPreference.getKey(), true);
final boolean isEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED, OFF) == ON;
assertThat(isEnabled).isTrue();
assertThat(getLatestPopupWindow()).isNotNull();
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
@Test
public void onPreferenceToggled_colorCorrectEnabled_shouldReturnFalseAndNotShowTooltipView() {
Settings.Secure.putInt(mContext.getContentResolver(),

View File

@@ -106,23 +106,6 @@ public class ToggleDaltonizerPreferenceFragmentTest {
assertThat(getLatestPopupWindow()).isNull();
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onPreferenceToggled_colorCorrectDisabled_shouldReturnTrueAndShowTooltipView() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, OFF);
ToggleDaltonizerPreferenceFragment fragment = getFragmentInResumedState();
SettingsMainSwitchPreference switchPreference = getMainFeatureToggle(fragment);
fragment.onPreferenceToggled(switchPreference.getKey(), true);
final boolean isEnabled = Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, OFF) == ON;
assertThat(isEnabled).isTrue();
assertThat(getLatestPopupWindow()).isNotNull();
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
@Test
public void onPreferenceToggled_colorCorrectEnabled_shouldReturnFalseAndNotShowTooltipView() {
Settings.Secure.putInt(mContext.getContentResolver(),

View File

@@ -26,7 +26,6 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -38,7 +37,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.icu.text.CaseMap;
import android.os.Bundle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
@@ -142,7 +140,6 @@ public class ToggleFeaturePreferenceFragmentTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = {ShadowFragment.class})
public void onResume_flagEnabled_haveRegisterToSpecificUris() {
mFragment.onAttach(mContext);
@@ -166,31 +163,6 @@ public class ToggleFeaturePreferenceFragmentTest {
any(AccessibilitySettingsContentObserver.class));
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = {ShadowFragment.class})
public void onResume_flagDisabled_haveRegisterToSpecificUris() {
mFragment.onAttach(mContext);
mFragment.onCreate(Bundle.EMPTY);
mFragment.onResume();
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver).registerContentObserver(
eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
verify(mContentResolver, never()).registerContentObserver(
eq(Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_QS_TARGETS)),
eq(false),
any(AccessibilitySettingsContentObserver.class));
}
@Test
public void updateShortcutPreferenceData_assignDefaultValueToVariable() {
mFragment.mComponentName = PLACEHOLDER_COMPONENT_NAME;
@@ -240,15 +212,6 @@ public class ToggleFeaturePreferenceFragmentTest {
assertThat(getLatestPopupWindow()).isNull();
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = ShadowFragment.class)
public void onPreferenceToggledOnEnabledService_showTooltipView() {
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
assertThat(getLatestPopupWindow().isShowing()).isTrue();
}
@Test
@Config(shadows = ShadowFragment.class)
public void onPreferenceToggledOnEnabledService_inSuw_toolTipViewShouldNotShow() {
@@ -261,18 +224,6 @@ public class ToggleFeaturePreferenceFragmentTest {
assertThat(getLatestPopupWindow()).isNull();
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = ShadowFragment.class)
public void onPreferenceToggledOnEnabledService_tooltipViewShown_notShowTooltipView() {
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
getLatestPopupWindow().dismiss();
mFragment.onPreferenceToggled(mFragment.getUseServicePreferenceKey(), /* enabled= */ true);
assertThat(getLatestPopupWindow().isShowing()).isFalse();
}
@Test
public void initTopIntroPreference_hasTopIntroTitle_shouldSetAsExpectedValue() {
mFragment.mTopIntroTitle = DEFAULT_TOP_INTRO;
@@ -365,7 +316,6 @@ public class ToggleFeaturePreferenceFragmentTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
@Config(shadows = ShadowFragment.class)
public void showQuickSettingsTooltipIfNeeded_qsFlagOn_dontShowTooltipView() {
mFragment.showQuickSettingsTooltipIfNeeded(QuickSettingsTooltipType.GUIDE_TO_EDIT);
@@ -374,7 +324,6 @@ public class ToggleFeaturePreferenceFragmentTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void getShortcutTypeSummary_shortcutSummaryIsCorrectlySet() {
final PreferredShortcut userPreferredShortcut = new PreferredShortcut(
PLACEHOLDER_COMPONENT_NAME.flattenToString(),

View File

@@ -337,8 +337,7 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onResume_flagEnabled_haveRegisterToSpecificUris() {
public void onResume_haveRegisterToSpecificUris() {
ShadowContentResolver shadowContentResolver = Shadows.shadowOf(
mContext.getContentResolver());
Uri[] observedUri = new Uri[]{
@@ -367,38 +366,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
}
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void onResume_flagDisabled_haveRegisterToSpecificUris() {
ShadowContentResolver shadowContentResolver = Shadows.shadowOf(
mContext.getContentResolver());
Uri[] observedUri = new Uri[]{
Settings.Secure.getUriFor(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS),
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE),
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_FOLLOW_TYPING_ENABLED),
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_ALWAYS_ON_ENABLED)
};
for (Uri uri : observedUri) {
// verify no observer registered before launching the fragment
assertThat(shadowContentResolver.getContentObservers(uri)).isEmpty();
}
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
for (Uri uri : observedUri) {
Collection<ContentObserver> observers = shadowContentResolver.getContentObservers(uri);
assertThat(observers.size()).isEqualTo(1);
assertThat(observers.stream().findFirst().get()).isInstanceOf(
AccessibilitySettingsContentObserver.class);
}
assertThat(shadowContentResolver.getContentObservers(
Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_QS_TARGETS))).hasSize(0);
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_ONE_FINGER_PANNING_GESTURE)
public void onResume_oneFingerPanningFlagOn_registerToSpecificUri() {
@@ -462,20 +429,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInAllValuesToSettings_optInValue_haveMatchString() {
int shortcutTypes = SOFTWARE | TRIPLETAP;
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
shortcutTypes);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
MAGNIFICATION_CONTROLLER_NAME);
assertThat(getMagnificationTripleTapStatus()).isTrue();
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInAllValuesToSettings_optInValue_callA11yManager() {
int shortcutTypes =
SOFTWARE | TRIPLETAP | HARDWARE
@@ -500,45 +453,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
verifyNoMoreInteractions(mAccessibilityManager);
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInAllValuesToSettings_twoFingerTripleTap_haveMatchString() {
int shortcutTypes = TWOFINGER_DOUBLETAP;
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
shortcutTypes);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, OFF)).isEqualTo(ON);
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInAllValuesToSettings_existOtherValue_optInValue_haveMatchString() {
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, PLACEHOLDER_COMPONENT_NAME.flattenToString());
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
SOFTWARE);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
PLACEHOLDER_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME);
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optInAllValuesToSettings_software_sizeValueIsNull_putLargeSizeValue() {
ShadowSettings.ShadowSecure.reset();
ToggleScreenMagnificationPreferenceFragment.optInAllMagnificationValuesToSettings(mContext,
SOFTWARE);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.UNKNOWN)).isEqualTo(
FloatingMenuSizePreferenceController.Size.LARGE);
}
@Test
public void optInAllValuesToSettings_software_sizeValueIsNotNull_sizeValueIsNotChanged() {
for (int size : new int[]{FloatingMenuSizePreferenceController.Size.LARGE,
@@ -594,24 +508,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutAllValuesToSettings_optOutValue_emptyString() {
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
putStringIntoSettings(HARDWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
setMagnificationTripleTapEnabled(/* enabled= */ true);
int shortcutTypes =
SOFTWARE | HARDWARE | TRIPLETAP;
ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings(
mContext, shortcutTypes);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEmpty();
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEmpty();
assertThat(getMagnificationTripleTapStatus()).isFalse();
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutAllValuesToSettings_optOutValue_callA11yManager() {
Set<String> shortcutTargets = Set.of(MAGNIFICATION_CONTROLLER_NAME);
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY, MAGNIFICATION_CONTROLLER_NAME);
@@ -635,38 +531,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
verifyNoMoreInteractions(mAccessibilityManager);
}
@Test
@EnableFlags(Flags.FLAG_ENABLE_MAGNIFICATION_MULTIPLE_FINGER_MULTIPLE_TAP_GESTURE)
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutAllValuesToSettings_twoFingerTripleTap_settingsValueIsOff() {
Settings.Secure.putInt(mContext.getContentResolver(),
TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON);
ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings(
mContext, TWOFINGER_DOUBLETAP);
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
TWO_FINGER_TRIPLE_TAP_SHORTCUT_KEY, ON)).isEqualTo(OFF);
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void optOutValueFromSettings_existOtherValue_optOutValue_haveMatchString() {
putStringIntoSettings(SOFTWARE_SHORTCUT_KEY,
PLACEHOLDER_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME);
putStringIntoSettings(HARDWARE_SHORTCUT_KEY,
PLACEHOLDER_COMPONENT_NAME.flattenToString() + ":" + MAGNIFICATION_CONTROLLER_NAME);
int shortcutTypes = SOFTWARE | HARDWARE;
ToggleScreenMagnificationPreferenceFragment.optOutAllMagnificationValuesFromSettings(
mContext, shortcutTypes);
assertThat(getStringFromSettings(SOFTWARE_SHORTCUT_KEY)).isEqualTo(
PLACEHOLDER_COMPONENT_NAME.flattenToString());
assertThat(getStringFromSettings(HARDWARE_SHORTCUT_KEY)).isEqualTo(
PLACEHOLDER_COMPONENT_NAME.flattenToString());
}
@Test
public void updateShortcutPreferenceData_assignDefaultValueToVariable() {
mFragController.create(R.id.main_content, /* bundle= */ null).start().resume();
@@ -979,7 +843,6 @@ public class ToggleScreenMagnificationPreferenceFragmentTest {
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void getShortcutTypeSummary_shortcutSummaryIsCorrectlySet() {
final PreferredShortcut userPreferredShortcut = new PreferredShortcut(
MAGNIFICATION_CONTROLLER_NAME,

View File

@@ -46,7 +46,6 @@ import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.util.Pair;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
@@ -466,7 +465,6 @@ public class EditShortcutsPreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void fragmentResumed_enableTouchExploration_qsShortcutOptionSummaryUpdated() {
String expectedSummary = StringUtil.getIcuPluralsString(mContext, 2,
R.string.accessibility_shortcut_edit_dialog_summary_quick_settings);
@@ -486,7 +484,6 @@ public class EditShortcutsPreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void fragmentPaused_enableTouchExploration_qsShortcutOptionSummaryNotUpdated() {
String expectedSummary = StringUtil.getIcuPluralsString(mContext, 1,
R.string.accessibility_shortcut_edit_dialog_summary_quick_settings);
@@ -644,7 +641,6 @@ public class EditShortcutsPreferenceFragmentTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void onQuickSettingsShortcutSettingChanged_preferredShortcutsUpdated() {
final String target = TARGET_FAKE_COMPONENT.flattenToString();
mFragmentScenario = createFragScenario(

View File

@@ -27,11 +27,7 @@ import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.ComponentName;
import android.content.Context;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
@@ -45,7 +41,6 @@ import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settingslib.utils.StringUtil;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -67,8 +62,6 @@ public class QuickSettingsShortcutOptionControllerTest {
private static final String TARGET_FLATTEN = TARGET.flattenToString();
private static final ComponentName TARGET_TILE =
new ComponentName("FakePackage", "FakeTileClass");
@Rule
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private final Context mContext = spy(ApplicationProvider.getApplicationContext());
private QuickSettingsShortcutOptionController mController;
@@ -149,13 +142,6 @@ public class QuickSettingsShortcutOptionControllerTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void isShortcutAvailable_a11yQsShortcutFlagDisabled_returnsFalse() {
assertThat(mController.isShortcutAvailable()).isFalse();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void isShortcutAvailable_qsNotSupported_returnsFalse() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_quickSettingsSupported, false);
@@ -164,7 +150,6 @@ public class QuickSettingsShortcutOptionControllerTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void isShortcutAvailable_qsTileProvided_returnsTrue() {
when(mAccessibilityManager.getA11yFeatureToTileMap(UserHandle.myUserId()))
.thenReturn(Map.of(TARGET, TARGET_TILE));
@@ -173,7 +158,6 @@ public class QuickSettingsShortcutOptionControllerTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void isShortcutAvailable_qsTileNotProvided_returnsFalse() {
when(mAccessibilityManager.getA11yFeatureToTileMap(UserHandle.myUserId()))
.thenReturn(Collections.emptyMap());
@@ -182,7 +166,6 @@ public class QuickSettingsShortcutOptionControllerTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void isShortcutAvailable_qsTileProvided_invalidUseCase_returnFalse() {
AccessibilityServiceInfo mockStandardA11yService =
AccessibilityTestUtils.createAccessibilityServiceInfo(
@@ -197,7 +180,6 @@ public class QuickSettingsShortcutOptionControllerTest {
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void isShortcutAvailable_qsTileProvided_validUseCase_returnTrue() {
AccessibilityServiceInfo mockAlwaysOnA11yService =
AccessibilityTestUtils.createAccessibilityServiceInfo(

View File

@@ -33,14 +33,11 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.fragment.app.FragmentActivity;
@@ -50,10 +47,8 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SubSettings;
import com.android.settings.accessibility.AccessibilityButtonFragment;
import com.android.settings.accessibility.FloatingMenuSizePreferenceController;
import com.android.settings.testutils.AccessibilityTestUtils;
import com.android.settings.utils.AnnotationSpan;
import com.android.settingslib.accessibility.AccessibilityUtils;
import org.junit.Before;
import org.junit.Rule;
@@ -178,23 +173,6 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableShortcut_shortcutTurnedOn() {
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
mController.setShortcutTargets(Set.of(target));
assertThat(ShortcutUtils.isComponentIdExistingInSettings(
mContext, ShortcutConstants.UserShortcutType.SOFTWARE, target
)).isFalse();
mController.enableShortcutForTargets(true);
assertThat(ShortcutUtils.isComponentIdExistingInSettings(
mContext, ShortcutConstants.UserShortcutType.SOFTWARE, target
)).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableShortcut_callA11yManager() {
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
mController.setShortcutTargets(Set.of(target));
@@ -214,25 +192,6 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableShortcut_shortcutTurnedOff() {
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
ShortcutUtils.optInValueToSettings(
mContext, ShortcutConstants.UserShortcutType.SOFTWARE, target);
assertThat(ShortcutUtils.isComponentIdExistingInSettings(
mContext, ShortcutConstants.UserShortcutType.SOFTWARE, target
)).isTrue();
mController.setShortcutTargets(Set.of(target));
mController.enableShortcutForTargets(false);
assertThat(ShortcutUtils.isComponentIdExistingInSettings(
mContext, ShortcutConstants.UserShortcutType.SOFTWARE, target
)).isFalse();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableShortcut_callA11yManager() {
String target = TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString();
ShortcutUtils.optInValueToSettings(
@@ -253,89 +212,6 @@ public class SoftwareShortcutOptionPreferenceControllerTest {
verifyNoMoreInteractions(mAccessibilityManager);
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableShortcutWithMagnification_menuSizeIncreased() {
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
mController.enableShortcutForTargets(true);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.UNKNOWN))
.isEqualTo(FloatingMenuSizePreferenceController.Size.LARGE);
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableShortcutWithMagnification_userConfigureSmallMenuSize_menuSizeNotChanged() {
Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.SMALL);
mController.setShortcutTargets(Set.of(TARGET_MAGNIFICATION));
mController.enableShortcutForTargets(true);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE,
FloatingMenuSizePreferenceController.Size.UNKNOWN))
.isEqualTo(FloatingMenuSizePreferenceController.Size.SMALL);
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableAlwaysOnServiceShortcut_turnsOnAlwaysOnService() {
mController.setShortcutTargets(
Set.of(TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString()));
mController.enableShortcutForTargets(true);
assertThat(AccessibilityUtils.getEnabledServicesFromSettings(mContext))
.contains(TARGET_ALWAYS_ON_A11Y_SERVICE);
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableAlwaysOnServiceShortcut_turnsOffAlwaysOnService() {
mController.setShortcutTargets(
Set.of(TARGET_ALWAYS_ON_A11Y_SERVICE.flattenToString()));
mController.enableShortcutForTargets(false);
assertThat(AccessibilityUtils.getEnabledServicesFromSettings(mContext))
.doesNotContain(TARGET_ALWAYS_ON_A11Y_SERVICE);
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableStandardServiceShortcut_wontTurnOnService() {
mController.setShortcutTargets(
Set.of(TARGET_STANDARD_A11Y_SERVICE.flattenToString()));
mController.enableShortcutForTargets(true);
assertThat(AccessibilityUtils.getEnabledServicesFromSettings(mContext))
.doesNotContain(TARGET_STANDARD_A11Y_SERVICE);
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableStandardServiceShortcutWithServiceOn_wontTurnOffService() {
mController.setShortcutTargets(
Set.of(TARGET_STANDARD_A11Y_SERVICE.flattenToString()));
AccessibilityUtils.setAccessibilityServiceState(
mContext, TARGET_STANDARD_A11Y_SERVICE, /* enabled= */ true);
mController.enableShortcutForTargets(false);
assertThat(AccessibilityUtils.getEnabledServicesFromSettings(mContext))
.contains(TARGET_STANDARD_A11Y_SERVICE);
}
private void assertLaunchSettingsPage(String page) {
ContextWrapper applicationContext = (Application) mContext.getApplicationContext();
final Intent intent = Shadows.shadowOf(applicationContext).getNextStartedActivity();

View File

@@ -28,12 +28,9 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import android.content.ComponentName;
import android.content.Context;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
@@ -182,20 +179,6 @@ public class TripleTapShortcutOptionControllerTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableShortcut_settingUpdated() {
mController.enableShortcutForTargets(true);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
AccessibilityUtil.State.OFF)
).isEqualTo(AccessibilityUtil.State.ON);
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableShortcut_callA11yManager() {
mController.enableShortcutForTargets(true);
@@ -209,20 +192,6 @@ public class TripleTapShortcutOptionControllerTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableShortcut_settingUpdated() {
mController.enableShortcutForTargets(false);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED,
AccessibilityUtil.State.OFF)
).isEqualTo(AccessibilityUtil.State.OFF);
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableShortcut_callA11yManager() {
mController.enableShortcutForTargets(false);

View File

@@ -143,20 +143,6 @@ public class TwoFingerDoubleTapShortcutOptionControllerTest {
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableShortcut_settingUpdated() {
mController.enableShortcutForTargets(true);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
AccessibilityUtil.State.OFF)
).isEqualTo(AccessibilityUtil.State.ON);
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableShortcut_callA11yManager() {
mController.enableShortcutForTargets(true);
@@ -170,20 +156,6 @@ public class TwoFingerDoubleTapShortcutOptionControllerTest {
}
@Test
@DisableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableShortcut_settingUpdated() {
mController.enableShortcutForTargets(false);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_MAGNIFICATION_TWO_FINGER_TRIPLE_TAP_ENABLED,
AccessibilityUtil.State.OFF)
).isEqualTo(AccessibilityUtil.State.OFF);
}
@Test
@EnableFlags(android.view.accessibility.Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableShortcut_callA11yManager() {
mController.enableShortcutForTargets(false);

View File

@@ -25,11 +25,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import android.content.ComponentName;
import android.content.Context;
import android.os.UserHandle;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.Flags;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
@@ -111,17 +108,6 @@ public class VolumeKeysShortcutOptionControllerTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableVolumeKeysShortcut_shortcutSet() {
mController.enableShortcutForTargets(true);
assertThat(
ShortcutUtils.isComponentIdExistingInSettings(
mContext, ShortcutConstants.UserShortcutType.HARDWARE, TARGET)).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_enableVolumeKeysShortcut_callA11yManager() {
mController.enableShortcutForTargets(true);
@@ -135,17 +121,6 @@ public class VolumeKeysShortcutOptionControllerTest {
}
@Test
@DisableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableVolumeKeysShortcut_shortcutNotSet() {
mController.enableShortcutForTargets(false);
assertThat(
ShortcutUtils.isComponentIdExistingInSettings(
mContext, ShortcutConstants.UserShortcutType.HARDWARE, TARGET)).isFalse();
}
@Test
@EnableFlags(Flags.FLAG_A11Y_QS_SHORTCUT)
public void enableShortcutForTargets_disableVolumeKeysShortcut_callA11yManager() {
mController.enableShortcutForTargets(false);

View File

@@ -0,0 +1,97 @@
/*
* Copyright (C) 2024 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.display
import android.graphics.Point
import android.graphics.PointF
import android.graphics.RectF
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
fun assertPointF(x: Float, y: Float, delta: Float, actual: PointF) {
assertEquals(x, actual.x, delta)
assertEquals(y, actual.y, delta)
}
@RunWith(RobolectricTestRunner::class)
class TopologyScaleTest {
@Test
fun oneDisplay4to3Aspect() {
val scale = TopologyScale(
/* paneWidth= */ 640,
listOf(RectF(0f, 0f, 640f, 480f)))
// blockRatio is higher than 0.05 in order to make the smallest display edge (480 dp) 48dp
// in the pane.
assertEquals(
"{TopoScale blockRatio=0.100000 originPaneXY=288,48 paneHeight=144}", "" + scale)
assertEquals(Point(352, 96), scale.displayToPaneCoor(PointF(640f, 480f)))
assertEquals(Point(320, 72), scale.displayToPaneCoor(PointF(320f, 240f)))
assertEquals(PointF(640f, 480f), scale.paneToDisplayCoor(Point(352, 96)))
}
@Test
fun twoUnalignedDisplays() {
val scale = TopologyScale(
/* paneWidth= */ 300,
listOf(RectF(0f, 0f, 1920f, 1200f), RectF(1920f, -300f, 3840f, 900f)))
assertEquals(
"{TopoScale blockRatio=0.046875 originPaneXY=60,37 paneHeight=117}", "" + scale)
assertEquals(Point(78, 55), scale.displayToPaneCoor(PointF(400f, 400f)))
assertEquals(Point(42, 37), scale.displayToPaneCoor(PointF(-400f, 0f)))
assertPointF(-384f, 106.6666f, 0.001f, scale.paneToDisplayCoor(Point(42, 42)))
}
@Test
fun twoDisplaysBlockRatioBumpedForGarSizeMinimumHorizontal() {
val scale = TopologyScale(
/* paneWidth= */ 192,
listOf(RectF(0f, 0f, 240f, 320f), RectF(-240f, -320f, 0f, 0f)))
// blockRatio is higher than 0.05 in order to make the smallest display edge (240 dp) 48dp
// in the pane.
assertEquals(
"{TopoScale blockRatio=0.200000 originPaneXY=96,128 paneHeight=256}", "" + scale)
assertEquals(Point(192, 256), scale.displayToPaneCoor(PointF(480f, 640f)))
assertEquals(Point(96, 64), scale.displayToPaneCoor(PointF(0f, -320f)))
assertPointF(220f, -430f, 0.001f, scale.paneToDisplayCoor(Point(140, 42)))
}
@Test
fun paneVerticalPaddingLimitedByTallestDisplay() {
val scale = TopologyScale(
/* paneWidth= */ 300,
listOf(
RectF(0f, 0f, 640f, 480f),
RectF(0f, 480f, 640f, 960f),
RectF(0f, 960f, 640f, 1440f),
RectF(0f, 1440f, 640f, 1920f),
RectF(0f, 1920f, 640f, 2400f),
RectF(0f, 2400f, 640f, 2880f)))
assertEquals(
"{TopoScale blockRatio=0.100000 originPaneXY=118,48 paneHeight=384}", "" + scale)
assertEquals(Point(150, 48), scale.displayToPaneCoor(PointF(320f, 0f)))
assertPointF(-180f, 2880f, 0.001f, scale.paneToDisplayCoor(Point(100, 336)))
}
}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2024 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.gestures;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DoubleTapPowerForCameraPreferenceControllerTest {
private static final String KEY = "gesture_double_power_tap_launch_camera";
private Context mContext;
private Resources mResources;
private DoubleTapPowerForCameraPreferenceController mController;
private SelectorWithWidgetPreference mPreference;
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
mController = new DoubleTapPowerForCameraPreferenceController(mContext, KEY);
mPreference = new SelectorWithWidgetPreference(mContext);
}
@Test
public void updateState_launchCameraEnabled_preferenceChecked() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void updateState_launchCameraDisabled_preferenceNotChecked() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureNotAvailable_preferenceUnsupported() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerButtonDisabled_preferenceDisabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerCameraLaunchEnabled_preferenceEnabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (C) 2024 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.gestures;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DoubleTapPowerForWalletPreferenceControllerTest {
private static final String KEY = "gesture_double_power_tap_launch_wallet";
private Context mContext;
private Resources mResources;
private DoubleTapPowerForWalletPreferenceController mController;
private SelectorWithWidgetPreference mPreference;
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
mController = new DoubleTapPowerForWalletPreferenceController(mContext, KEY);
mPreference = new SelectorWithWidgetPreference(mContext);
}
@Test
public void updateState_launchWalletEnabled_preferenceChecked() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isTrue();
}
@Test
public void updateState_launchWalletDisabled_preferenceNotChecked() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
mController.updateState(mPreference);
assertThat(mPreference.isChecked()).isFalse();
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureNotAvailable_preferenceUnsupported() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerButtonDisabled_preferenceDisabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerWalletLaunchEnabled_preferenceEnabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (C) 2024 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.gestures;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.app.Application;
import androidx.preference.PreferenceScreen;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.settings.R;
import com.android.settingslib.widget.IllustrationPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DoubleTapPowerIllustrationPreferenceControllerTest {
private static final String KEY = "gesture_double_tap_power_video";
private Application mContext;
private IllustrationPreference mPreference;
private DoubleTapPowerIllustrationPreferenceController mController;
@Before
public void setUp() {
mContext = ApplicationProvider.getApplicationContext();
mPreference = new IllustrationPreference(mContext);
mController = new DoubleTapPowerIllustrationPreferenceController(mContext, KEY);
PreferenceScreen mScreen = mock(PreferenceScreen.class);
when(mScreen.findPreference(KEY)).thenReturn(mPreference);
mController.displayPreference(mScreen);
}
@Test
public void updateState_setDoubleTapPowerForCamera_showsCameraIllustration() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
mController.updateState(mPreference);
assertThat(mPreference.getLottieAnimationResId()).isEqualTo(R.drawable.quickly_open_camera);
}
@Test
public void updateState_setDoubleTapPowerForWallet_showsWalletIllustration() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
mController.updateState(mPreference);
assertThat(mPreference.getLottieAnimationResId())
.isEqualTo(R.drawable.double_tap_power_for_wallet);
}
}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2024 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.gestures;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.R;
import com.android.settings.core.BasePreferenceController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DoubleTapPowerMainSwitchPreferenceControllerTest {
private static final String KEY = "gesture_double_tap_power_enabled_main_switch";
private Context mContext;
private Resources mResources;
private DoubleTapPowerMainSwitchPreferenceController mController;
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
mController = new DoubleTapPowerMainSwitchPreferenceController(mContext, KEY);
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureAvailable_preferenceEnabled() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureUnavailable_preferenceUnsupported() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void isChecked_setDoubleTapPowerGestureEnabled_mainSwitchChecked() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_setDoubleTapPowerGestureDisabled_mainSwitchUnchecked() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void setChecked_checkMainSwitch_doubleTapPowerGestureEnabled() {
mController.setChecked(true);
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
.isTrue();
}
@Test
public void setChecked_uncheckMainSwitch_doubleTapPowerGestureDisabled() {
mController.setChecked(false);
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
.isFalse();
}
}

View File

@@ -17,23 +17,37 @@
package com.android.settings.gestures;
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
import static android.provider.Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED;
import static com.android.settings.gestures.DoubleTapPowerPreferenceController.OFF;
import static com.android.settings.gestures.DoubleTapPowerPreferenceController.ON;
import static com.android.settings.gestures.DoubleTapPowerPreferenceController.isSuggestionComplete;
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.OFF;
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.service.quickaccesswallet.Flags;
import android.text.TextUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -44,16 +58,22 @@ import org.robolectric.annotation.Config;
@Config(shadows = SettingsShadowResources.class)
public class DoubleTapPowerPreferenceControllerTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private Context mContext;
private ContentResolver mContentResolver;
private DoubleTapPowerPreferenceController mController;
private Preference mPreference;
private PreferenceScreen mScreen;
private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mContext = RuntimeEnvironment.getApplication();
mContentResolver = mContext.getContentResolver();
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
mPreference = new Preference(mContext);
mScreen = mock(PreferenceScreen.class);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
@After
@@ -62,7 +82,26 @@ public class DoubleTapPowerPreferenceControllerTest {
}
@Test
public void isAvailable_configIsTrue_shouldReturnTrue() {
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsTrue_returnsTrue() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, Boolean.TRUE);
assertThat(mController.isAvailable()).isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagEnabled_configIsFalse_returnsFalse() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, Boolean.FALSE);
assertThat(mController.isAvailable()).isFalse();
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagDisabled_configIsTrue_returnsTrue() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled,
Boolean.TRUE);
@@ -71,7 +110,8 @@ public class DoubleTapPowerPreferenceControllerTest {
}
@Test
public void isAvailable_configIsTrue_shouldReturnFalse() {
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isAvailable_flagDisabled_configIsFalse_returnsFalse() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled,
Boolean.FALSE);
@@ -80,43 +120,63 @@ public class DoubleTapPowerPreferenceControllerTest {
}
@Test
public void testIsChecked_configIsNotSet_shouldReturnTrue() {
// Set the setting to be enabled.
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenNotAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, false);
assertThat(mController.isChecked()).isTrue();
assertThat(isSuggestionComplete(mContext, null /* prefs */)).isTrue();
}
@Test
public void testIsChecked_configIsSet_shouldReturnFalse() {
// Set the setting to be disabled.
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_falseWhenNotVisited() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet.
final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
assertThat(mController.isChecked()).isFalse();
assertThat(isSuggestionComplete(mContext, prefs)).isFalse();
}
@Test
public void isSuggestionCompleted_doubleTapPower_trueWhenNotAvailable() {
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenVisited() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet.
final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
prefs.edit().putBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
assertThat(isSuggestionComplete(mContext, prefs)).isTrue();
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_disableFlag_doubleTapPower_trueWhenNotAvailable() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, false);
assertThat(isSuggestionComplete(mContext, null/* prefs */)).isTrue();
assertThat(isSuggestionComplete(mContext, null /* prefs */)).isTrue();
}
@Test
public void isSuggestionCompleted_doubleTapPower_falseWhenNotVisited() {
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_disableFlag_doubleTapPower_falseWhenNotVisited() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet.
final SharedPreferences prefs =
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
assertThat(isSuggestionComplete(mContext, prefs)).isFalse();
}
@Test
public void isSuggestionCompleted_doubleTapPower_trueWhenVisited() {
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void isSuggestionCompleted_disableFlag_doubleTapPower_trueWhenVisited() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
// No stored value in shared preferences if not visited yet.
@@ -128,21 +188,92 @@ public class DoubleTapPowerPreferenceControllerTest {
}
@Test
public void isSliceableCorrectKey_returnsTrue() {
final DoubleTapPowerPreferenceController controller =
new DoubleTapPowerPreferenceController(mContext, "gesture_double_tap_power");
assertThat(controller.isSliceable()).isTrue();
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void displayPreference_flagDisabled_doubleTapPowerLegacyTitleIsDisplayed() {
mController.displayPreference(mScreen);
assertThat(
TextUtils.equals(
mPreference.getTitle(),
mContext.getText(R.string.double_tap_power_for_camera_title)))
.isTrue();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final DoubleTapPowerPreferenceController controller =
new DoubleTapPowerPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagDisabled_doubleTapPowerEnabled_returnsOn() {
// Set the setting to be enabled.
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_on)))
.isTrue();
}
@Test
public void isPublicSlice_returnTrue() {
assertThat(mController.isPublicSlice()).isTrue();
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagDisabled_doubleTapPowerDisabled_returnsOff() {
// Set the setting to be disabled.
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_off)))
.isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagEnabled_doubleTapPowerDisabled_returnsOff() {
// Set the setting to be disabled.
Settings.Secure.putInt(
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 0 /* OFF */);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getText(R.string.gesture_setting_off)))
.isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagEnabled_doubleTapPowerEnabled_cameraTargetAction_returnsSummary() {
// Set the setting to be enabled.
Settings.Secure.putInt(
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 1 /* ON */);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getString(
R.string.double_tap_power_summary,
mContext.getText(R.string.gesture_setting_on),
mContext.getText(
R.string.double_tap_power_camera_action_summary))))
.isTrue();
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getSummary_flagEnabled_doubleTapPowerEnabled_walletTargetAction_returnsSummary() {
// Set the setting to be enabled.
Settings.Secure.putInt(
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 1 /* ON */);
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
assertThat(
TextUtils.equals(
mController.getSummary(),
mContext.getString(
R.string.double_tap_power_summary,
mContext.getText(R.string.gesture_setting_on),
mContext.getText(
R.string.double_tap_power_wallet_action_summary))))
.isTrue();
}
}

View File

@@ -18,9 +18,16 @@ package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.SearchIndexableResource;
import android.service.quickaccesswallet.Flags;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -31,6 +38,7 @@ import java.util.List;
@RunWith(RobolectricTestRunner.class)
public class DoubleTapPowerSettingsTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private DoubleTapPowerSettings mSettings;
@Before
@@ -39,12 +47,38 @@ public class DoubleTapPowerSettingsTest {
}
@Test
public void testSearchIndexProvider_shouldIndexResource() {
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getPreferenceScreenResId_flagEnabled_returnsFlagEnabledResId() {
assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.double_tap_power_settings);
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void getPreferenceScreenResId_flagDisabled_returnsFlagDisabledResId() {
assertThat(mSettings.getPreferenceScreenResId())
.isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
}
@Test
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void testSearchIndexProvider_flagEnabled_shouldIndexFlagEnabledResource() {
final List<SearchIndexableResource> indexRes =
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.application, true /* enabled */);
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.getApplication(), true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.double_tap_power_settings);
}
@Test
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
public void testSearchIndexProvider_flagDisabled_shouldIndexFlagDisabledResource() {
final List<SearchIndexableResource> indexRes =
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
RuntimeEnvironment.getApplication(), true /* enabled */);
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId)
.isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
}
}

View File

@@ -0,0 +1,203 @@
/*
* 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.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.OFF;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DoubleTapPowerSettingsUtilsTest {
private static final int DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE = 0;
private static final int DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE = 1;
private Context mContext;
private Resources mResources;
@Before
public void setUp() {
mContext = spy(ApplicationProvider.getApplicationContext());
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
}
@Test
public void isDoubleTapPowerButtonGestureAvailable_setAvailable_returnsTrue() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext))
.isTrue();
}
@Test
public void isDoubleTapPowerButtonGestureAvailable_setUnavailable_returnsFalse() {
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext))
.isFalse();
}
@Test
public void isDoubleTapPowerButtonGestureEnabled_setEnabled_returnsTrue() {
Settings.Secure.putInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
ON);
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
.isTrue();
}
@Test
public void isDoubleTapPowerButtonGestureEnabled_setDisabled_returnsFalse() {
Settings.Secure.putInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
OFF);
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
.isFalse();
}
@Test
public void isDoubleTapPowerButtonGestureEnabled_valueNotSet_returnsTrue() {
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
.isTrue();
}
@Test
public void setDoubleTapPowerButtonGestureEnabled_setEnabled_returnsEnabled() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
OFF))
.isEqualTo(ON);
}
@Test
public void setDoubleTapPowerButtonGestureEnabled_setDisabled_returnsDisabled() {
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
ON))
.isEqualTo(OFF);
}
@Test
public void isDoubleTapPowerButtonGestureForCameraLaunchEnabled_valueSetToCamera_returnsTrue() {
Settings.Secure.putInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
assertThat(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
.isTrue();
}
@Test
public void
isDoubleTapPowerButtonGestureForCameraLaunchEnabled_valueNotSetToCamera_returnsFalse() {
Settings.Secure.putInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
assertThat(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
.isFalse();
}
@Test
public void
isDoubleTapPowerButtonGestureForCameraLaunchEnabled_defaultSetToCamera_returnsTrue() {
when(mResources.getInteger(R.integer.config_defaultDoubleTapPowerGestureAction))
.thenReturn(DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
assertThat(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
.isTrue();
}
@Test
public void
isDoubleTapPowerButtonGestureForCameraLaunchEnabled_defaultNotCamera_returnsFalse() {
when(mResources.getInteger(R.integer.config_defaultDoubleTapPowerGestureAction))
.thenReturn(DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
assertThat(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
.isFalse();
}
@Test
public void setDoubleTapPowerButtonForCameraLaunch_setGestureBehaviorToCameraLaunch() {
boolean result =
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
assertThat(result).isTrue();
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE))
.isEqualTo(DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
}
@Test
public void setDoubleTapPowerButtonForWalletLaunch_setGestureBehaviorToWalletLaunch() {
boolean result =
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
assertThat(result).isTrue();
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE))
.isEqualTo(DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
}
}

View File

@@ -0,0 +1,162 @@
/*
* Copyright (C) 2024 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.gestures;
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.OFF;
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.android.internal.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(AndroidJUnit4.class)
@Config(shadows = SettingsShadowResources.class)
public class DoubleTapPowerToOpenCameraPreferenceControllerTest {
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
private Context mContext;
private Resources mResources;
private DoubleTapPowerToOpenCameraPreferenceController mController;
private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.getApplication());
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
mController =
new DoubleTapPowerToOpenCameraPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
}
@After
public void tearDown() {
SettingsShadowResources.reset();
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureDisabled_preferenceUnsupported() {
when(mResources.getBoolean(R.bool.config_cameraDoubleTapPowerGestureEnabled))
.thenReturn(false);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
}
@Test
public void getAvailabilityStatus_setDoubleTapPowerGestureEnabled_preferenceSupported() {
when(mResources.getBoolean(R.bool.config_cameraDoubleTapPowerGestureEnabled))
.thenReturn(true);
assertThat(mController.getAvailabilityStatus())
.isEqualTo(BasePreferenceController.AVAILABLE);
}
@Test
public void isChecked_configIsNotSet_returnsTrue() {
// Set the setting to be enabled.
Settings.Secure.putInt(
mContext.getContentResolver(), CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void isChecked_setConfigFalse_returnsFalse() {
// Set the setting to be disabled.
Settings.Secure.putInt(
mContext.getContentResolver(), CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void isChecked_setConfigTrue_returnsFalse() {
// Set the setting to be disabled.
Settings.Secure.putInt(
mContext.getContentResolver(), CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void setChecked_checkToggle_cameraDoubleTapPowerGestureEnabled() {
mController.setChecked(true);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
OFF))
.isEqualTo(ON);
}
@Test
public void setChecked_uncheckToggle_cameraDoubleTapPowerGestureDisabled() {
mController.setChecked(false);
assertThat(
Settings.Secure.getInt(
mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
ON))
.isEqualTo(OFF);
}
@Test
public void isSliceableCorrectKey_returnsTrue() {
final DoubleTapPowerToOpenCameraPreferenceController controller =
new DoubleTapPowerToOpenCameraPreferenceController(
mContext, "gesture_double_tap_power");
assertThat(controller.isSliceable()).isTrue();
}
@Test
public void isSliceableIncorrectKey_returnsFalse() {
final DoubleTapPowerToOpenCameraPreferenceController controller =
new DoubleTapPowerToOpenCameraPreferenceController(mContext, "bad_key");
assertThat(controller.isSliceable()).isFalse();
}
@Test
public void isPublicSlice_returnTrue() {
assertThat(mController.isPublicSlice()).isTrue();
}
}

View File

@@ -54,6 +54,7 @@ import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.UserManager;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
@@ -103,6 +104,8 @@ public class SimSelectNotificationTest {
private DisplayMetrics mDisplayMetrics;
@Mock
private SimDialogActivity mActivity;
@Mock
private UserManager mUserManager;
private final String mFakeDisplayName = "fake_display_name";
private final CharSequence mFakeNotificationChannelTitle = "fake_notification_channel_title";
@@ -128,6 +131,8 @@ public class SimSelectNotificationTest {
.thenReturn(mNotificationManager);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE))
.thenReturn(mTelephonyManager);
when(mContext.getSystemService(UserManager.class))
.thenReturn(mUserManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE))
.thenReturn(mSubscriptionManager);
@@ -135,6 +140,7 @@ public class SimSelectNotificationTest {
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mPackageManager.checkPermission(any(), any()))
.thenReturn(PackageManager.PERMISSION_GRANTED);
when(mUserManager.isMainUser()).thenReturn(true);
when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mTelephonyManager);
when(mTelephonyManager.isDataEnabledForApn(TYPE_MMS)).thenReturn(false);
@@ -217,6 +223,18 @@ public class SimSelectNotificationTest {
verify(mNotificationManager, never()).createNotificationChannel(any());
}
@Test
public void onReceivePrimarySubListChange_userIdIsNotMain_notificationShouldNotSend() {
when(mUserManager.isMainUser()).thenReturn(false);
Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);
intent.putExtra(EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE,
EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_DATA);
// If MMS data is already enabled, there's no need to trigger the notification.
mSimSelectNotification.onReceive(mContext, intent);
verify(mNotificationManager, never()).createNotificationChannel(any());
}
@Test
public void onReceivePrimarySubListChange_NoExtra_notificationShouldNotSend() {
Intent intent = new Intent(TelephonyManager.ACTION_PRIMARY_SUBSCRIPTION_LIST_CHANGED);

View File

@@ -25,12 +25,7 @@ import static com.google.common.truth.Truth.assertThat;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.Settings;
import android.view.accessibility.Flags;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -41,7 +36,6 @@ import com.android.internal.accessibility.util.ShortcutUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -61,8 +55,6 @@ public class PreferredShortcutsTest {
CLASS_NAME_2);
private static final ContentResolver sContentResolver =
ApplicationProvider.getApplicationContext().getContentResolver();
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
private final Context mContext = ApplicationProvider.getApplicationContext();
@Before
@@ -175,7 +167,6 @@ public class PreferredShortcutsTest {
}
@Test
@RequiresFlagsEnabled(Flags.FLAG_A11Y_QS_SHORTCUT)
public void updatePreferredShortcutFromSettings_colorInversionWithQsAndSoftwareShortcut_preferredShortcutsMatches() {
String target = COLOR_INVERSION_COMPONENT_NAME.flattenToString();
Settings.Secure.putString(sContentResolver,
@@ -192,23 +183,6 @@ public class PreferredShortcutsTest {
}
@Test
@RequiresFlagsDisabled(Flags.FLAG_A11Y_QS_SHORTCUT)
public void updatePreferredShortcutFromSettings_colorInversionWithQsAndHardwareShortcut_qsShortcutNotSaved() {
String target = COLOR_INVERSION_COMPONENT_NAME.flattenToString();
Settings.Secure.putString(sContentResolver,
Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, target);
Settings.Secure.putString(sContentResolver,
Settings.Secure.ACCESSIBILITY_QS_TARGETS, target);
assertThat(!android.view.accessibility.Flags.a11yQsShortcut()).isTrue();
PreferredShortcuts.updatePreferredShortcutsFromSettings(mContext, Set.of(target));
int savedPreferredShortcut = PreferredShortcuts.retrieveUserShortcutType(
mContext, target);
assertThat(savedPreferredShortcut).isEqualTo(UserShortcutType.HARDWARE);
}
@Test
public void retrieveUserShortcutTypeWithoutDefault_noUserPreferredShortcuts_returnSoftwareShortcut() {
String target = COMPONENT_NAME_1.flattenToString();

View File

@@ -16,8 +16,6 @@
package com.android.settings.accessibility;
import static com.android.internal.accessibility.AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
@@ -26,12 +24,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.res.Resources;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.provider.Settings;
import android.view.accessibility.Flags;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -40,7 +33,6 @@ import com.android.internal.R;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -48,8 +40,6 @@ import org.junit.runner.RunWith;
public class ReduceBrightColorsPreferenceControllerTest {
private static final String PREF_KEY = "rbc_preference";
@Rule
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
private Context mContext;
private Resources mResources;;
private ReduceBrightColorsPreferenceController mController;
@@ -98,20 +88,6 @@ public class ReduceBrightColorsPreferenceControllerTest {
assertThat(mController.isAvailable()).isFalse();
}
@Test
@RequiresFlagsDisabled(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getTileComponentName_a11yQsFlagOff_returnComponentName() {
assertThat(mController.getTileComponentName())
.isEqualTo(REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME);
}
@Test
@RequiresFlagsEnabled(Flags.FLAG_A11Y_QS_SHORTCUT)
public void getTileComponentName_a11yQsFlagOff_returnNull() {
assertThat(mController.getTileComponentName()).isNull();
}
private int resourceId(String type, String name) {
return mContext.getResources().getIdentifier(name, type, mContext.getPackageName());
}

View File

@@ -19,6 +19,7 @@ package com.android.settings.network.telephony;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Looper;
@@ -32,6 +33,7 @@ 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;
@@ -42,8 +44,10 @@ public class SatelliteSettingsSosFooterPreferenceControllerTest {
@Rule
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
private Context mContext = null;
@Mock
private FooterPreference mFooterPreference;
private Context mContext = null;
private SatelliteSettingsSosFooterPreferenceController mController;
@Before
@@ -52,8 +56,7 @@ public class SatelliteSettingsSosFooterPreferenceControllerTest {
Looper.prepare();
}
mContext = spy(ApplicationProvider.getApplicationContext());
mFooterPreference = spy(new FooterPreference(mContext));
mFooterPreference.setKey(KEY);
when(mFooterPreference.getKey()).thenReturn(KEY);
mController = new SatelliteSettingsSosFooterPreferenceController(mContext, KEY);
}