Android 顯示刷新頻率的實現(xiàn)代碼
Android 顯示刷新頻率
android11-release

開發(fā)者選項->顯示刷新頻率
packages/apps/Settings/src/com/android/settings/development/ShowRefreshRatePreferenceController.java
調(diào)用 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顯示

到此這篇關(guān)于Android 顯示刷新頻率的實現(xiàn)代碼的文章就介紹到這了,更多相關(guān)android刷新頻率內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android Canvas drawText文字居中的一些事(圖解)
這篇文章主要給大家介紹了關(guān)于Android Canvas drawText文字居中的一些事,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-12-12
Android如何在root設備上開啟ViewServer詳解
這篇文章主要給大家介紹了關(guān)于Android中如何在root設備上開啟ViewServer的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-12-12
Android 定位系統(tǒng)(GPS)開發(fā)詳解
GPS定位是智能手機上一個比較有意思的功能,LBS等服務都有效的利用了GPS定位功能,本文就跟大家分享下Android開發(fā)中的GPS定位知識2016-07-07
Android中TextView實現(xiàn)超過固定行數(shù)顯示“...展開全部”
這篇文章主要給大家介紹了關(guān)于Android中TextView如何實現(xiàn)超過固定行數(shù)顯示"...展開全部"的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。2017-12-12
WorkManager解決應用退出后繼續(xù)運行后臺任務
這篇文章主要為大家介紹了WorkManager解決應用退出后繼續(xù)運行后臺任務示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07
關(guān)于Android添加fragment后版本不兼容問題
這篇文章主要介紹了Android添加fragment后版本不兼容問題的解決方法,需要的朋友可以參考下2017-12-12

