refactor(brightness suw): decouple auto brightness initialization logic for setup flow

The AccessibilitySettingsForSetupWizard class should not be responsible for managing the initial
logic of controllers, such as determining which controllers need to be dynamically added or updated
using setInSetupWizard APIs. This logic should be handled directly by the controllers themselves.

Bug: 311093618
Flag: EXEMPT bugfix
Test: atest AccessibilitySettingsForSetupWizardTest
            AutoBrightnessPreferenceControllerForSetupWizardTest
            AutoBrightnessPreferenceControllerTest
            BrightnessLevelPreferenceControllerForSetupWizardTest
            BrightnessLevelPreferenceControllerTest

Change-Id: I6065a10e72d002981c0f514543e6933d79c2aa1b
This commit is contained in:
Menghan Li
2024-09-23 09:24:38 +00:00
parent aa7114cf3e
commit e0f734526d
11 changed files with 289 additions and 105 deletions

View File

@@ -22,28 +22,25 @@ import android.os.Process;
import android.os.UserManager;
import android.provider.Settings;
import androidx.annotation.NonNull;
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;
/**
* The top-level preference controller that updates the adaptive brightness.
*/
public class AutoBrightnessPreferenceController extends TogglePreferenceController {
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) {
public AutoBrightnessPreferenceController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
public void setInSetupWizard(boolean inSetupWizard) {
mInSetupWizard = inSetupWizard;
}
@Override
public boolean isChecked() {
return Settings.System.getInt(mContext.getContentResolver(),
@@ -60,14 +57,10 @@ public class AutoBrightnessPreferenceController extends TogglePreferenceControll
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
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;
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_automatic_brightness_available)
? AVAILABLE_UNSEARCHABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override

View File

@@ -0,0 +1,44 @@
/*
* 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.display;
import android.content.Context;
import androidx.annotation.NonNull;
import com.android.settings.accessibility.Flags;
/**
* The top-level preference controller that updates the adaptive brightness in the SetupWizard.
*/
public class AutoBrightnessPreferenceControllerForSetupWizard
extends AutoBrightnessPreferenceController {
public AutoBrightnessPreferenceControllerForSetupWizard(@NonNull Context context,
@NonNull String key) {
super(context, key);
}
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
if (!Flags.addBrightnessSettingsInSuw()) {
return CONDITIONALLY_UNAVAILABLE;
}
return super.getAvailabilityStatus();
}
}

View File

@@ -20,7 +20,6 @@ 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;
@@ -37,12 +36,13 @@ import android.os.UserManager;
import android.provider.Settings.System;
import android.text.TextUtils;
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.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;
@@ -54,18 +54,17 @@ import com.android.settingslib.transition.SettingsTransitionHelper;
import java.text.NumberFormat;
/**
* The top-level preference controller that updates the adaptive brightness level.
*/
public class BrightnessLevelPreferenceController extends BasePreferenceController implements
PreferenceControllerMixin, LifecycleObserver, OnStart, OnStop {
private static final String TAG = "BrightnessPrefCtrl";
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);
@@ -94,11 +93,13 @@ public class BrightnessLevelPreferenceController extends BasePreferenceControlle
}
};
public BrightnessLevelPreferenceController(Context context, Lifecycle lifecycle) {
public BrightnessLevelPreferenceController(@NonNull Context context,
@Nullable Lifecycle lifecycle) {
this(context, context.getString(R.string.preference_key_brightness_level), lifecycle);
}
private BrightnessLevelPreferenceController(Context context, String key, Lifecycle lifecycle) {
private BrightnessLevelPreferenceController(@NonNull Context context, @NonNull String key,
@Nullable Lifecycle lifecycle) {
super(context, key);
mDisplayManager = context.getSystemService(DisplayManager.class);
@@ -108,15 +109,8 @@ public class BrightnessLevelPreferenceController extends BasePreferenceControlle
mContentResolver = mContext.getContentResolver();
}
public void setInSetupWizard(boolean inSetupWizard) {
mInSetupWizard = inSetupWizard;
}
@Override
public int getAvailabilityStatus() {
if (mInSetupWizard && !Flags.addBrightnessSettingsInSuw()) {
return CONDITIONALLY_UNAVAILABLE;
}
return AVAILABLE;
}

View File

@@ -0,0 +1,47 @@
/*
* 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.display;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.settings.accessibility.Flags;
import com.android.settingslib.core.lifecycle.Lifecycle;
/**
* The top-level preference controller that updates the adaptive brightness level in the
* SetupWizard.
*/
public class BrightnessLevelPreferenceControllerForSetupWizard extends
BrightnessLevelPreferenceController {
public BrightnessLevelPreferenceControllerForSetupWizard(@NonNull Context context,
@Nullable Lifecycle lifecycle) {
super(context, lifecycle);
}
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
if (!Flags.addBrightnessSettingsInSuw()) {
return CONDITIONALLY_UNAVAILABLE;
}
return super.getAvailabilityStatus();
}
}