Android 显示刷新频率的实现代码
作者:xhBruce 时间:2023-09-18 07:01:34
Android 显示刷新频率
android11-release
开发者选项->显示刷新频率
packages/apps/Settings/src/com/android/settings/development/ShowRefreshRatePreferenceController.java
调用 SurfaceFlinger::onTransact 中 1034 方法
updateShowRefreshRateSetting() 通过 SurfaceFlinger 获取mRefreshRateOverlay != nullptr
判断显示是否打开
writeShowRefreshRateSetting(boolean isEnabled) 设置打开显示刷新频率
public class ShowRefreshRatePreferenceController extends DeveloperOptionsPreferenceController
implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
private static final String SHOW_REFRESH_RATE_KEY = "show_refresh_rate";
private static final int SETTING_VALUE_QUERY = 2;
private static final int SETTING_VALUE_ON = 1;
private static final int SETTING_VALUE_OFF = 0;
@VisibleForTesting
static final String SURFACE_FLINGER_SERVICE_KEY = "SurfaceFlinger";
@VisibleForTesting
static final int SURFACE_FLINGER_CODE = 1034;
private static final String SURFACE_COMPOSER_INTERFACE_KEY = "android.ui.ISurfaceComposer";
private final IBinder mSurfaceFlinger;
public ShowRefreshRatePreferenceController(Context context) {
super(context);
mSurfaceFlinger = ServiceManager.getService(SURFACE_FLINGER_SERVICE_KEY);
}
@Override
public String getPreferenceKey() {
return SHOW_REFRESH_RATE_KEY;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean isEnabled = (Boolean) newValue;
writeShowRefreshRateSetting(isEnabled);
return true;
}
@Override
public void updateState(Preference preference) {
updateShowRefreshRateSetting();
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled();
final SwitchPreference preference = (SwitchPreference) mPreference;
if (preference.isChecked()) {
// Writing false to the preference when the setting is already off will have a
// side effect of turning on the preference that we wish to avoid
writeShowRefreshRateSetting(false);
preference.setChecked(false);
}
}
@VisibleForTesting
void updateShowRefreshRateSetting() {
// magic communication with surface flinger.
try {
if (mSurfaceFlinger != null) {
final Parcel data = Parcel.obtain();
final Parcel reply = Parcel.obtain();
data.writeInterfaceToken(SURFACE_COMPOSER_INTERFACE_KEY);
data.writeInt(SETTING_VALUE_QUERY);
mSurfaceFlinger.transact(SURFACE_FLINGER_CODE, data, reply, 0 /* flags */);
final boolean enabled = reply.readBoolean();
((SwitchPreference) mPreference).setChecked(enabled);
reply.recycle();
data.recycle();
}
} catch (RemoteException ex) {
// intentional no-op
}
}
@VisibleForTesting
void writeShowRefreshRateSetting(boolean isEnabled) {
try {
if (mSurfaceFlinger != null) {
final Parcel data = Parcel.obtain();
data.writeInterfaceToken(SURFACE_COMPOSER_INTERFACE_KEY);
final int showRefreshRate = isEnabled ? SETTING_VALUE_ON : SETTING_VALUE_OFF;
data.writeInt(showRefreshRate);
mSurfaceFlinger.transact(SURFACE_FLINGER_CODE, data,
null /* reply */, 0 /* flags */);
data.recycle();
}
} catch (RemoteException ex) {
// intentional no-op
}
updateShowRefreshRateSetting();
}
}
RefreshRateOverlay 实际Layer显示刷新频率
frameworks\native\services\surfaceflinger\SurfaceFlinger.cpp
frameworks\native\services\surfaceflinger\RefreshRateOverlay.cpp
初始化 RefreshRateOverlay,通过 SurfaceFlinger createLayer显示
来源:https://blog.csdn.net/qq_23452385/article/details/119335668
标签:android,刷新,频率
0
投稿
猜你喜欢
Android ViewPager实现无限循环轮播广告位Banner效果
2023-06-26 22:02:29
简单了解Thymeleaf语法 数据延迟加载使用实例
2021-11-27 04:05:49
Java单例模式实现静态内部类方法示例
2021-08-03 00:36:51
利用java反射机制实现自动调用类的简单方法
2023-11-29 15:57:22
Unity实现颜色渐变滑动条
2023-11-28 10:54:51
APK程序获取system权限的方法
2023-09-05 06:41:49
vscode使用官方C/C++插件无法进行代码格式化问题
2022-07-13 06:24:47
C#实现Menu和ContextMenu自定义风格及contextMenu自定义
2022-01-03 04:09:30
浅谈关于Java的GC垃圾回收器的一些基本概念
2021-11-14 10:42:52
Java 数据结构与算法系列精讲之栈
2021-06-11 09:00:51
JAVA中的字符串常量池使用操作代码
2021-11-24 02:00:57
Eclipse IDE可支持Java 14編程
2022-09-06 10:14:43
Android实现探探图片滑动效果
2022-11-14 17:09:19
基于spring boot 的配置参考大全(推荐)
2021-11-28 23:32:41
springboot整合spring-retry的实现示例
2022-01-13 01:25:53
VsCode搭建Java开发环境的方法
2023-06-17 13:29:19
Java执行JS脚本工具
2022-04-07 08:00:16
Android仿微信列表滑动删除之可滑动控件(一)
2021-12-24 21:15:46
利用Java如何获取Mybatis动态生成的sql接口实现
2021-05-25 13:05:27
SpringBoot实现文件上传与下载功能的示例代码
2021-11-10 09:15:32