display: add hdr display switch preference
Change-Id: Ibbafce724ae0386c054394cdd8089ec58593cb30 Signed-off-by: rmp22 <195054967+rmp22@users.noreply.github.com>
This commit is contained in:
@@ -327,4 +327,8 @@
|
||||
<string name="triluminos_engine_mode_title">Triluminos display</string>
|
||||
<string name="display_engine_default">Default</string>
|
||||
<string name="display_engine_mode_footer_text">Inspired by Sony\'s Bravia/X-Reality engine, the Display Engine features Vivid mode for enhanced brightness and color saturation, X-Reality mode for improved detail and color accuracy, and Triluminos mode for notorious display color accuracy.</string>
|
||||
|
||||
<!-- HDR Display -->
|
||||
<string name="hdr_display_title">HDR Display</string>
|
||||
<string name="hdr_display_summary">Enable peak brightness for HDR content. This will increase battery usage</string>
|
||||
</resources>
|
||||
|
||||
@@ -181,6 +181,12 @@
|
||||
android:summary="@string/display_white_balance_summary"
|
||||
settings:controller="com.android.settings.display.DisplayWhiteBalancePreferenceController"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="hdr_display"
|
||||
android:title="@string/hdr_display_title"
|
||||
android:summary="@string/hdr_display_summary"
|
||||
settings:controller="com.android.settings.display.HdrDisplayPreferenceController"/>
|
||||
|
||||
<ListPreference
|
||||
android:key="max_refresh_rate"
|
||||
android:title="@string/max_refresh_rate_title"
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2025 The AxionAOSP 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.app.ActivityManager;
|
||||
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 android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Secure;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
public class HdrDisplayPreferenceController extends TogglePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private static final String HDR_DISPLAY_SETTING = "hdr_display";
|
||||
|
||||
@VisibleForTesting
|
||||
ContentObserver mContentObserver;
|
||||
private Preference mPreference;
|
||||
|
||||
public HdrDisplayPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return SystemProperties.getBoolean("ro.surface_flinger.has_HDR_display", false)
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(), HDR_DISPLAY_SETTING, 1) != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
HDR_DISPLAY_SETTING,
|
||||
isChecked ? 1 : 0
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_display;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (!isAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
mContentObserver = new ContentObserver(new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
super.onChange(selfChange, uri);
|
||||
if (HDR_DISPLAY_SETTING.equals(uri.getLastPathSegment())) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cr.registerContentObserver(Settings.Secure.getUriFor(HDR_DISPLAY_SETTING),
|
||||
false, mContentObserver, ActivityManager.getCurrentUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mContentObserver != null) {
|
||||
mContext.getContentResolver().unregisterContentObserver(mContentObserver);
|
||||
mContentObserver = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user