Android开发者模式的选项中有一项叫“停用HW叠加层”,这个选项使能之后,系统所有的UI合成都会全部强制GPU去完成,HWC不再参与合成,需求来源就是默认要使能该功能,即禁用HW叠加,具体实现如下:
diff --git a/src/com/android/settings/FallbackHome.java b/src/com/android/settings/FallbackHome.java
index e3944a65c6..5e7e0cae59 100644
--- a/src/com/android/settings/FallbackHome.java
+++ b/src/com/android/settings/FallbackHome.java
@@ -17,6 +17,7 @@
package com.android.settings;
import android.app.Activity;
+import android.app.AppGlobals;
import android.app.WallpaperColors;
import android.app.WallpaperManager;
import android.app.WallpaperManager.OnColorsChangedListener;
@@ -25,7 +26,12 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
+import android.content.pm.IPackageManager;
import android.os.AsyncTask;
+import android.os.IBinder;
+import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.ServiceManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -48,6 +54,13 @@ public class FallbackHome extends Activity {
private boolean mProvisioned;
private WallpaperManager mWallManager;
+ private static final int SETTING_VALUE_ON = 1;
+ 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_DISABLE_OVERLAYS_CODE = 1008;
+
+ private static IBinder mSurfaceFlinger;
+
private final Runnable mProgressTimeoutRunnable = () -> {
View v = getLayoutInflater().inflate(
R.layout.fallback_home_finishing_boot, null /* root */);
@@ -100,10 +113,36 @@ public class FallbackHome extends Activity {
}
getWindow().getDecorView().setSystemUiVisibility(flags);
+ if (mSurfaceFlinger == null) {
+ mSurfaceFlinger = ServiceManager.getService(SURFACE_FLINGER_SERVICE_KEY);
+ }
+
+ initHardwareOverlaysSetting(SETTING_VALUE_ON);
+
registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));
maybeFinish();
}
+ public void initHardwareOverlaysSetting(int val) {
+ if (mSurfaceFlinger == null) {
+ return;
+ }
+
+ IPackageManager pm = AppGlobals.getPackageManager();
+ // magic communication with surface flinger.
+ try {
+ if (pm.isFirstBoot()) {
+ final Parcel data = Parcel.obtain();
+ data.writeInterfaceToken(SURFACE_COMPOSER_INTERFACE_KEY);
+ data.writeInt(val);
+ mSurfaceFlinger.transact(SURFACE_FLINGER_DISABLE_OVERLAYS_CODE, data, null, 0 /* flags */);
+ data.recycle();
+ }
+ } catch (RemoteException ex) {
+ // intentional no-op
+ }
+ }
+
@Override
protected void onResume() {
super.onResume();
因为开机默认状态,不会加载开发者模式的页面,因此在开发者模式的控制类是无法修改默认的,只能在开机必走的阶段执行使能,这里我选择的是FallbackHome这个类,每次在launcher启动之前都会调用这里,故选择该类。文章来源:https://www.toymoban.com/news/detail-506564.html
编译验证,刷机即可发现在开发者选项中,该项值已经默认打开了。文章来源地址https://www.toymoban.com/news/detail-506564.html
到了这里,关于默认开启“停用HW叠加层”开关,强制GPU渲染的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!