diff options
author | David Sodman <dsodman@google.com> | 2018-07-20 13:57:41 -0700 |
---|---|---|
committer | David Sodman <dsodman@google.com> | 2018-08-23 20:04:03 -0700 |
commit | 7915fda7eea56a8461be3025dc7a6f18cf26c15a (patch) | |
tree | 820333ea30d6926beedf0b235d66dbf0449a26cd /src/com | |
parent | 10995c9bfc71362c6ce8d1ccebd9497aa3aa828d (diff) | |
download | packages_apps_Settings-7915fda7eea56a8461be3025dc7a6f18cf26c15a.tar.gz packages_apps_Settings-7915fda7eea56a8461be3025dc7a6f18cf26c15a.tar.bz2 packages_apps_Settings-7915fda7eea56a8461be3025dc7a6f18cf26c15a.zip |
Add Support for Virtual High Refresh Rate mode
Add a developer options settings switch to enable a virtual
HiFrequency panel mode to be able to test the SW stack with
display running at 50% faster than the default refresh
rate.
Bug: 111549030
Test: Enable HiFrequency mode and use systrace/adb to verity
Change-Id: Ibfd30ca1a14a146419233eaefa9b5095bf459adc
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java | 1 | ||||
-rw-r--r-- | src/com/android/settings/development/HighFrequencyDisplayPreferenceController.java | 129 |
2 files changed, 130 insertions, 0 deletions
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index 5be381a04c..54ca6ef776 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -439,6 +439,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new TransitionAnimationScalePreferenceController(context)); controllers.add(new AnimatorDurationScalePreferenceController(context)); controllers.add(new SecondaryDisplayPreferenceController(context)); + controllers.add(new HighFrequencyDisplayPreferenceController(context)); controllers.add(new GpuViewUpdatesPreferenceController(context)); controllers.add(new HardwareLayersUpdatesPreferenceController(context)); controllers.add(new DebugGpuOverdrawPreferenceController(context)); diff --git a/src/com/android/settings/development/HighFrequencyDisplayPreferenceController.java b/src/com/android/settings/development/HighFrequencyDisplayPreferenceController.java new file mode 100644 index 0000000000..cbb8d4ce6d --- /dev/null +++ b/src/com/android/settings/development/HighFrequencyDisplayPreferenceController.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2018 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.development; + +import android.content.Context; +import android.os.IBinder; +import android.os.Parcel; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.text.TextUtils; + +import com.android.settings.R; +import com.android.settings.core.PreferenceControllerMixin; +import com.android.settingslib.development.DeveloperOptionsPreferenceController; + +import androidx.annotation.VisibleForTesting; +import androidx.preference.ListPreference; +import androidx.preference.Preference; +import androidx.preference.SwitchPreference; + +public class HighFrequencyDisplayPreferenceController extends DeveloperOptionsPreferenceController + implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { + + private static final String HIGH_FREQUENCY_DISPLAY_KEY = "high_frequency_display_device"; + + private static final String SURFACE_FLINGER_SERVICE_KEY = "SurfaceFlinger"; + private static final String SURFACE_COMPOSER_INTERFACE_KEY = "android.ui.ISurfaceComposer"; + private static final int SURFACE_FLINGER_HIGH_FREQUENCY_DISPLAY_CODE = 1029; + + private final IBinder mSurfaceFlingerBinder; + + public HighFrequencyDisplayPreferenceController(Context context) { + super(context); + mSurfaceFlingerBinder = ServiceManager.getService(SURFACE_FLINGER_SERVICE_KEY); + } + + @Override + public String getPreferenceKey() { + return HIGH_FREQUENCY_DISPLAY_KEY; + } + + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + Boolean isEnabled = (Boolean) newValue; + writeHighFrequencyDisplaySetting(isEnabled); + ((SwitchPreference) preference).setChecked(isEnabled); + return true; + } + + @Override + public void updateState(Preference preference) { + boolean enableHighFrequencyPanel = readHighFrequencyDisplaySetting(); + ((SwitchPreference) preference).setChecked(enableHighFrequencyPanel); + } + + @Override + protected void onDeveloperOptionsSwitchDisabled() { + super.onDeveloperOptionsSwitchDisabled(); + writeHighFrequencyDisplaySetting(false); + ((SwitchPreference) mPreference).setChecked(false); + } + + @VisibleForTesting + boolean readHighFrequencyDisplaySetting() { + boolean isEnabled = false; + try { + if (mSurfaceFlingerBinder != null) { + final Parcel data = Parcel.obtain(); + final Parcel result = Parcel.obtain(); + data.writeInterfaceToken(SURFACE_COMPOSER_INTERFACE_KEY); + data.writeInt(0); + data.writeInt(0); + mSurfaceFlingerBinder.transact( + SURFACE_FLINGER_HIGH_FREQUENCY_DISPLAY_CODE, + data, result, 0); + + if (result.readInt() != 1 || result.readInt() != 1) { + isEnabled = true; + } + } + } catch (RemoteException ex) { + // intentional no-op + } + return isEnabled; + } + + @VisibleForTesting + void writeHighFrequencyDisplaySetting(boolean isEnabled) { + int multiplier; + int divisor; + + if (isEnabled) { + // 60Hz * 3/2 = 90Hz + multiplier = 2; + divisor = 3; + } else { + multiplier = 1; + divisor = 1; + } + + try { + if (mSurfaceFlingerBinder != null) { + final Parcel data = Parcel.obtain(); + data.writeInterfaceToken(SURFACE_COMPOSER_INTERFACE_KEY); + data.writeInt(multiplier); + data.writeInt(divisor); + mSurfaceFlingerBinder.transact( + SURFACE_FLINGER_HIGH_FREQUENCY_DISPLAY_CODE, + data, null, 0); + } + } catch (RemoteException ex) { + // intentional no-op + } + } +} |