Merge "feat(brightness suw): add brightness preferences in suw" into main
This commit is contained in:
@@ -3,6 +3,13 @@ container: "system_ext"
|
||||
|
||||
# NOTE: Keep alphabetized to help limit merge conflicts from multiple simultaneous editors.
|
||||
|
||||
flag {
|
||||
name: "add_brightness_settings_in_suw"
|
||||
namespace: "accessibility"
|
||||
description: "Whether to add brightness preference in SUW Vision Settings"
|
||||
bug: "332974327"
|
||||
}
|
||||
|
||||
flag {
|
||||
name: "edit_shortcuts_in_full_screen"
|
||||
namespace: "accessibility"
|
||||
|
@@ -1,6 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<issues format="4">
|
||||
|
||||
<issue
|
||||
id="LintError"
|
||||
severity="Error"
|
||||
message="No `.class` files were found in project ".", so none of the classfile based checks could be run. Does the project need to be built first?"
|
||||
category="Lint"
|
||||
priority="10"
|
||||
summary="Lint Failure"
|
||||
explanation="This issue type represents a problem running lint itself. Examples include failure to find bytecode for source files (which means certain detectors could not be run), parsing errors in lint configuration files, etc.
These errors are not errors in your own code, but they are shown to make it clear that some checks were not completed.">
|
||||
<location
|
||||
file="."/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
@@ -4561,6 +4573,38 @@
|
||||
column="17"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" android:color="@color/accessibility_feature_background"/>"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/drawable/ic_suw_brightness_auto.xml"
|
||||
line="22"
|
||||
column="13"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
message="Avoid using hardcoded color"
|
||||
category="Correctness"
|
||||
priority="4"
|
||||
summary="Using hardcoded color"
|
||||
explanation="Hardcoded color values are bad because theme changes cannot be uniformly applied.Instead use the theme specific colors such as `?android:attr/textColorPrimary` in attributes.
This ensures that a theme change from a light to a dark theme can be uniformlyapplied across the app."
|
||||
errorLine1=" android:color="@color/accessibility_feature_background"/>"
|
||||
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
|
||||
<location
|
||||
file="res/drawable/ic_suw_brightness_level.xml"
|
||||
line="22"
|
||||
column="13"/>
|
||||
</issue>
|
||||
|
||||
<issue
|
||||
id="HardCodedColor"
|
||||
severity="Error"
|
||||
|
25
res/drawable/ic_brightness_auto.xml
Normal file
25
res/drawable/ic_brightness_auto.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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="@dimen/accessibility_icon_foreground_size"
|
||||
android:height="@dimen/accessibility_icon_foreground_size"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M312,640L376,640L408,548L554,548L586,640L648,640L512,280L448,280L312,640ZM426,496L478,346L482,346L534,496L426,496ZM480,932L346,800L160,800L160,614L28,480L160,346L160,160L346,160L480,28L614,160L800,160L800,346L932,480L800,614L800,800L614,800L480,932ZM480,820L580,720L720,720L720,580L820,480L720,380L720,240L580,240L480,140L380,240L240,240L240,380L140,480L240,580L240,720L380,720L480,820ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
|
||||
</vector>
|
25
res/drawable/ic_brightness_medium.xml
Normal file
25
res/drawable/ic_brightness_medium.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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="@dimen/accessibility_icon_foreground_size"
|
||||
android:height="@dimen/accessibility_icon_foreground_size"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M480,932L346,800L160,800L160,614L28,480L160,346L160,160L346,160L480,28L614,160L800,160L800,346L932,480L800,614L800,800L614,800L480,932ZM480,680Q563,680 621.5,621.5Q680,563 680,480Q680,397 621.5,338.5Q563,280 480,280L480,680ZM480,820L580,720L720,720L720,580L820,480L720,380L720,240L580,240L480,140L380,240L240,240L240,380L140,480L240,580L240,720L380,720L480,820ZM480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480L480,480Z"/>
|
||||
</vector>
|
26
res/drawable/ic_suw_brightness_auto.xml
Normal file
26
res/drawable/ic_suw_brightness_auto.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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.
|
||||
-->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/accessibility_icon_size"
|
||||
android:height="@dimen/accessibility_icon_size"
|
||||
android:color="@color/accessibility_feature_background"/>
|
||||
</item>
|
||||
<item android:gravity="center"
|
||||
android:drawable="@drawable/ic_brightness_auto"/>
|
||||
</layer-list>
|
26
res/drawable/ic_suw_brightness_level.xml
Normal file
26
res/drawable/ic_suw_brightness_level.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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.
|
||||
-->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<com.android.settingslib.widget.AdaptiveIconShapeDrawable
|
||||
android:width="@dimen/accessibility_icon_size"
|
||||
android:height="@dimen/accessibility_icon_size"
|
||||
android:color="@color/accessibility_feature_background"/>
|
||||
</item>
|
||||
<item android:gravity="center"
|
||||
android:drawable="@drawable/ic_brightness_medium"/>
|
||||
</layer-list>
|
@@ -2732,6 +2732,10 @@
|
||||
<!-- Display settings screen, Color mode option for "Adaptive color" [CHAR LIMIT=45] -->
|
||||
<string name="color_mode_option_automatic">Adaptive</string>
|
||||
|
||||
<!-- Key for the brightness level preference -->
|
||||
<string name="preference_key_brightness_level" translatable="false">brightness</string>
|
||||
<!-- Key for the auto brightness preference -->
|
||||
<string name="preference_key_auto_brightness" translatable="false">auto_brightness_entry</string>
|
||||
<!-- Sound & display settings screen, setting option name to change brightness level -->
|
||||
<string name="brightness">Brightness level</string>
|
||||
<!-- Sound & display settings screen, setting option name to enable adaptive brightness [CHAR LIMIT=30] -->
|
||||
|
@@ -29,6 +29,22 @@
|
||||
settings:keywords="text_reading_options"
|
||||
settings:controller="com.android.settings.accessibility.TextReadingFragmentForSuwController"/>
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="@string/preference_key_brightness_level"
|
||||
android:icon="@drawable/ic_suw_brightness_level"
|
||||
android:title="@string/brightness"
|
||||
settings:keywords="@string/keywords_display_brightness_level"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:userRestriction="no_config_brightness"/>
|
||||
|
||||
<com.android.settingslib.PrimarySwitchPreference
|
||||
android:key="@string/preference_key_auto_brightness"
|
||||
android:icon="@drawable/ic_suw_brightness_auto"
|
||||
android:title="@string/auto_brightness_title"
|
||||
android:fragment="com.android.settings.accessibility.AutoBrightnessPreferenceFragmentForSetupWizard"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:userRestriction="no_config_brightness"/>
|
||||
|
||||
<Preference
|
||||
android:fragment="com.android.settings.accessibility.ToggleScreenMagnificationPreferenceFragmentForSetupWizard"
|
||||
android:key="screen_magnification_preference"
|
||||
|
@@ -26,14 +26,14 @@
|
||||
android:order="-200">
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="brightness"
|
||||
android:key="@string/preference_key_brightness_level"
|
||||
android:title="@string/brightness"
|
||||
settings:keywords="@string/keywords_display_brightness_level"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:userRestriction="no_config_brightness"/>
|
||||
|
||||
<com.android.settingslib.PrimarySwitchPreference
|
||||
android:key="auto_brightness_entry"
|
||||
android:key="@string/preference_key_auto_brightness"
|
||||
android:title="@string/auto_brightness_title"
|
||||
android:fragment="com.android.settings.display.AutoBrightnessSettings"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
|
@@ -24,6 +24,7 @@ import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIU
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -40,11 +41,15 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.display.AutoBrightnessPreferenceController;
|
||||
import com.android.settings.display.BrightnessLevelPreferenceController;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupdesign.GlifPreferenceLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -161,6 +166,21 @@ public class AccessibilitySettingsForSetupWizard extends DashboardFragment
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
BrightnessLevelPreferenceController brightnessLevelPreferenceController =
|
||||
new BrightnessLevelPreferenceController(context, getSettingsLifecycle());
|
||||
brightnessLevelPreferenceController.setInSetupWizard(true);
|
||||
controllers.add(brightnessLevelPreferenceController);
|
||||
String autoBrightnessKey = context.getString(R.string.preference_key_auto_brightness);
|
||||
AutoBrightnessPreferenceController autoBrightnessPreferenceController =
|
||||
new AutoBrightnessPreferenceController(context, autoBrightnessKey);
|
||||
autoBrightnessPreferenceController.setInSetupWizard(true);
|
||||
controllers.add(autoBrightnessPreferenceController);
|
||||
return controllers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns accessibility service info by given package name and service name.
|
||||
*
|
||||
|
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.accessibility;
|
||||
|
||||
import static android.app.Activity.RESULT_CANCELED;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.display.AutoBrightnessSettings;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupdesign.GlifPreferenceLayout;
|
||||
|
||||
/**
|
||||
* Fragment for adaptive brightness settings in the SetupWizard.
|
||||
*/
|
||||
public class AutoBrightnessPreferenceFragmentForSetupWizard extends AutoBrightnessSettings {
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (view instanceof GlifPreferenceLayout) {
|
||||
final GlifPreferenceLayout layout = (GlifPreferenceLayout) view;
|
||||
final String title = getContext().getString(
|
||||
R.string.auto_brightness_title);
|
||||
final Drawable icon = getContext().getDrawable(R.drawable.ic_accessibility_visibility);
|
||||
icon.setTintList(Utils.getColorAttr(getContext(), android.R.attr.colorPrimary));
|
||||
AccessibilitySetupWizardUtils.updateGlifPreferenceLayout(getContext(), layout, title,
|
||||
/* description= */ null, icon);
|
||||
|
||||
final FooterBarMixin mixin = layout.getMixin(FooterBarMixin.class);
|
||||
AccessibilitySetupWizardUtils.setPrimaryButton(getContext(), mixin, R.string.done,
|
||||
() -> {
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView onCreateRecyclerView(@NonNull LayoutInflater inflater,
|
||||
@NonNull ViewGroup parent, @Nullable Bundle savedInstanceState) {
|
||||
if (parent instanceof GlifPreferenceLayout) {
|
||||
final GlifPreferenceLayout layout = (GlifPreferenceLayout) parent;
|
||||
return layout.onCreateRecyclerView(inflater, parent, savedInstanceState);
|
||||
}
|
||||
return super.onCreateRecyclerView(inflater, parent, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SUW_ACCESSIBILITY_AUTO_BRIGHTNESS;
|
||||
}
|
||||
}
|
@@ -28,6 +28,7 @@ import com.android.settings.accessibility.AccessibilityDetailsSettingsFragment;
|
||||
import com.android.settings.accessibility.AccessibilityHearingAidsFragment;
|
||||
import com.android.settings.accessibility.AccessibilitySettings;
|
||||
import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
|
||||
import com.android.settings.accessibility.AutoBrightnessPreferenceFragmentForSetupWizard;
|
||||
import com.android.settings.accessibility.CaptioningPropertiesFragment;
|
||||
import com.android.settings.accessibility.ColorAndMotionFragment;
|
||||
import com.android.settings.accessibility.HearingDevicePairingFragment;
|
||||
@@ -258,6 +259,7 @@ public class SettingsGateway {
|
||||
EditShortcutsPreferenceFragment.class.getName(),
|
||||
TextReadingPreferenceFragment.class.getName(),
|
||||
TextReadingPreferenceFragmentForSetupWizard.class.getName(),
|
||||
AutoBrightnessPreferenceFragmentForSetupWizard.class.getName(),
|
||||
CaptioningPropertiesFragment.class.getName(),
|
||||
ToggleDaltonizerPreferenceFragment.class.getName(),
|
||||
ToggleColorInversionPreferenceFragment.class.getName(),
|
||||
|
@@ -25,6 +25,7 @@ import android.provider.Settings;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.Flags;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.PrimarySwitchPreference;
|
||||
|
||||
@@ -33,10 +34,16 @@ public class AutoBrightnessPreferenceController extends TogglePreferenceControll
|
||||
private final String SYSTEM_KEY = SCREEN_BRIGHTNESS_MODE;
|
||||
private final int DEFAULT_VALUE = SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||
|
||||
private boolean mInSetupWizard;
|
||||
|
||||
public AutoBrightnessPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setInSetupWizard(boolean inSetupWizard) {
|
||||
mInSetupWizard = inSetupWizard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.System.getInt(mContext.getContentResolver(),
|
||||
@@ -53,10 +60,14 @@ public class AutoBrightnessPreferenceController extends TogglePreferenceControll
|
||||
@Override
|
||||
@AvailabilityStatus
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available)
|
||||
? AVAILABLE_UNSEARCHABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
if (!mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
if (mInSetupWizard && !Flags.addBrightnessSettingsInSuw()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -20,6 +20,7 @@ import static com.android.settingslib.display.BrightnessUtils.GAMMA_SPACE_MAX;
|
||||
import static com.android.settingslib.display.BrightnessUtils.GAMMA_SPACE_MIN;
|
||||
import static com.android.settingslib.display.BrightnessUtils.convertLinearToGammaFloat;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityOptions;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
@@ -39,10 +40,12 @@ import android.text.TextUtils;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.accessibility.Flags;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
@@ -51,17 +54,18 @@ import com.android.settingslib.transition.SettingsTransitionHelper;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public class BrightnessLevelPreferenceController extends AbstractPreferenceController implements
|
||||
public class BrightnessLevelPreferenceController extends BasePreferenceController implements
|
||||
PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private static final String TAG = "BrightnessPrefCtrl";
|
||||
private static final String KEY_BRIGHTNESS = "brightness";
|
||||
|
||||
private static final Uri BRIGHTNESS_ADJ_URI;
|
||||
private final ContentResolver mContentResolver;
|
||||
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||
private final DisplayManager mDisplayManager;
|
||||
|
||||
@Nullable
|
||||
private Preference mPreference;
|
||||
private boolean mInSetupWizard;
|
||||
|
||||
static {
|
||||
BRIGHTNESS_ADJ_URI = System.getUriFor(System.SCREEN_AUTO_BRIGHTNESS_ADJ);
|
||||
@@ -90,9 +94,12 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context);
|
||||
this(context, context.getString(R.string.preference_key_brightness_level), lifecycle);
|
||||
}
|
||||
|
||||
private BrightnessLevelPreferenceController(Context context, String key, Lifecycle lifecycle) {
|
||||
super(context, key);
|
||||
mDisplayManager = context.getSystemService(DisplayManager.class);
|
||||
|
||||
if (lifecycle != null) {
|
||||
@@ -101,20 +108,22 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
public void setInSetupWizard(boolean inSetupWizard) {
|
||||
mInSetupWizard = inSetupWizard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BRIGHTNESS;
|
||||
public int getAvailabilityStatus() {
|
||||
if (mInSetupWizard && !Flags.addBrightnessSettingsInSuw()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(KEY_BRIGHTNESS);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -23,6 +23,7 @@ import static com.android.settings.accessibility.AccessibilitySettingsForSetupWi
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -45,7 +46,10 @@ import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.display.AutoBrightnessPreferenceController;
|
||||
import com.android.settings.display.BrightnessLevelPreferenceController;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupdesign.GlifPreferenceLayout;
|
||||
@@ -88,7 +92,7 @@ public class AccessibilitySettingsForSetupWizardTest {
|
||||
private GlifPreferenceLayout mGlifLayoutView;
|
||||
@Mock
|
||||
private FooterBarMixin mFooterBarMixin;
|
||||
private AccessibilitySettingsForSetupWizard mFragment;
|
||||
private TestAccessibilitySettingsForSetupWizard mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -141,6 +145,19 @@ public class AccessibilitySettingsForSetupWizardTest {
|
||||
assertThat(mFragment.mSelectToSpeakPreference.getKey()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPreferenceControllers_brightnessPreferencesControllersAreCreated() {
|
||||
mFragment.onAttach(mContext);
|
||||
|
||||
List<AbstractPreferenceController> controllers =
|
||||
mFragment.createPreferenceControllers(mContext);
|
||||
|
||||
assertTrue(controllers.stream().anyMatch(
|
||||
controller -> controller instanceof BrightnessLevelPreferenceController));
|
||||
assertTrue(controllers.stream().anyMatch(
|
||||
controller -> controller instanceof AutoBrightnessPreferenceController));
|
||||
}
|
||||
|
||||
private void addEnabledServiceInfo(ComponentName componentName, boolean isAccessibilityTool) {
|
||||
final AccessibilityServiceInfo a11yServiceInfo = mock(AccessibilityServiceInfo.class);
|
||||
when(a11yServiceInfo.getComponentName()).thenReturn(componentName);
|
||||
@@ -170,12 +187,14 @@ public class AccessibilitySettingsForSetupWizardTest {
|
||||
|
||||
private final Context mContext;
|
||||
private final PreferenceManager mPreferenceManager;
|
||||
final PreferenceScreen mPreferenceScreen;
|
||||
|
||||
TestAccessibilitySettingsForSetupWizard(Context context) {
|
||||
super();
|
||||
mContext = context;
|
||||
mPreferenceManager = new PreferenceManager(context);
|
||||
mPreferenceManager.setPreferences(mPreferenceManager.createPreferenceScreen(context));
|
||||
mPreferenceScreen = spy(mPreferenceManager.createPreferenceScreen(context));
|
||||
mPreferenceManager.setPreferences(mPreferenceScreen);
|
||||
mDisplayMagnificationPreference = new Preference(context);
|
||||
mScreenReaderPreference = new RestrictedPreference(context);
|
||||
mSelectToSpeakPreference = new RestrictedPreference(context);
|
||||
|
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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.accessibility;
|
||||
|
||||
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.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.google.android.setupcompat.template.FooterBarMixin;
|
||||
import com.google.android.setupdesign.GlifPreferenceLayout;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
/** Tests for {@link AutoBrightnessPreferenceFragmentForSetupWizard}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class AutoBrightnessPreferenceFragmentForSetupWizardTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mMockito = MockitoJUnit.rule();
|
||||
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private GlifPreferenceLayout mGlifLayoutView;
|
||||
@Mock
|
||||
private FooterBarMixin mFooterBarMixin;
|
||||
private AutoBrightnessPreferenceFragmentForSetupWizard mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFragment = spy(new AutoBrightnessPreferenceFragmentForSetupWizard());
|
||||
doReturn(mock(LifecycleOwner.class)).when(mFragment).getViewLifecycleOwner();
|
||||
doReturn(mContext).when(mFragment).getContext();
|
||||
when(mGlifLayoutView.getMixin(eq(FooterBarMixin.class))).thenReturn(mFooterBarMixin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHeaderText_onViewCreated_verifyAction() {
|
||||
final String title = "title";
|
||||
doReturn(title).when(mContext).getString(R.string.auto_brightness_title);
|
||||
|
||||
mFragment.onViewCreated(mGlifLayoutView, null);
|
||||
|
||||
verify(mGlifLayoutView).setHeaderText(title);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_returnsCorrectCategory() {
|
||||
assertThat(mFragment.getMetricsCategory()).isEqualTo(
|
||||
SettingsEnums.SUW_ACCESSIBILITY_AUTO_BRIGHTNESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onViewCreated_verifyAction() {
|
||||
mFragment.onViewCreated(mGlifLayoutView, null);
|
||||
|
||||
verify(mFooterBarMixin).setPrimaryButton(any());
|
||||
}
|
||||
}
|
@@ -21,18 +21,24 @@ import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
|
||||
import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.Flags;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@@ -44,6 +50,9 @@ import org.robolectric.annotation.Config;
|
||||
@Config(shadows = {SettingsShadowResources.class})
|
||||
public class AutoBrightnessPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
private static final String PREFERENCE_KEY = "auto_brightness";
|
||||
|
||||
private Context mContext;
|
||||
@@ -121,13 +130,34 @@ public class AutoBrightnessPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_configTrueSet_shouldReturnAvailableUnsearchable() {
|
||||
public void getAvailabilityStatusNotInSUW_configTrueSet_shouldReturnAvailableUnsearchable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available, true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
|
||||
public void getAvailabilityStatusInSUW_configTrueAndFlagOn_shouldReturnAvailableUnsearchable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available, true);
|
||||
mController.setInSetupWizard(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
|
||||
public void
|
||||
getAvailabilityStatusInSUW_configTrueAndFlagOff_shouldReturnConditionallyUnavailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_automatic_brightness_available, true);
|
||||
mController.setInSetupWizard(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_configFalseSet_shouldReturnUnsupportedOnDevice() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
|
@@ -33,16 +33,22 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.display.BrightnessInfo;
|
||||
import android.os.PowerManager;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings.System;
|
||||
import android.view.Display;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.Flags;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
import com.android.settingslib.transition.SettingsTransitionHelper;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
@@ -58,6 +64,9 @@ import org.robolectric.shadows.ShadowContentResolver;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class BrightnessLevelPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
|
||||
@Mock
|
||||
private PowerManager mPowerManager;
|
||||
@Mock
|
||||
@@ -90,10 +99,24 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldAlwaysReturnTrue() {
|
||||
public void isAvailable_shouldAlwaysReturnTrueWhenNotInSetupWizard() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
|
||||
public void isAvailable_inSetupWizardAndFlagOn_shouldReturnTrue() {
|
||||
mController.setInSetupWizard(true);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_ADD_BRIGHTNESS_SETTINGS_IN_SUW)
|
||||
public void isAvailable_inSetupWizardAndFlagOff_shouldReturnFalse() {
|
||||
mController.setInSetupWizard(true);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRegisterObserver() {
|
||||
BrightnessLevelPreferenceController controller =
|
||||
@@ -169,13 +192,14 @@ public class BrightnessLevelPreferenceControllerTest {
|
||||
final BrightnessLevelPreferenceController controller =
|
||||
new BrightnessLevelPreferenceController(activity, null);
|
||||
final ShadowActivity shadowActivity = shadowOf(activity);
|
||||
when(mPreference.getKey()).thenReturn("brightness");
|
||||
|
||||
String preferenceKey = mContext.getString(R.string.preference_key_brightness_level);
|
||||
when(mPreference.getKey()).thenReturn(preferenceKey);
|
||||
|
||||
controller.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final Intent intent = shadowActivity.getNextStartedActivity();
|
||||
assertThat(intent.getIntExtra(SettingsBaseActivity.EXTRA_PAGE_TRANSITION_TYPE, 0))
|
||||
.isEqualTo(SettingsTransitionHelper.TransitionType.TRANSITION_NONE);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -228,6 +228,8 @@ public class BatteryTestUtils {
|
||||
|
||||
/** Create a power anomaly event proto of adaptive brightness. */
|
||||
public static PowerAnomalyEvent createAdaptiveBrightnessAnomalyEvent(boolean changeSettings) {
|
||||
// TODO: migrate "auto_brightness_entry" to use R.string.preference_key_auto_brightness
|
||||
// if we can access the Context here. (b/338314718)
|
||||
WarningBannerInfo.Builder warningBannerInfoBuilder =
|
||||
WarningBannerInfo.newBuilder()
|
||||
.setMainButtonDestination(DisplaySettings.class.getName())
|
||||
|
Reference in New Issue
Block a user