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
+ }
+ }
+@Overrideprotected void onResume() {super.onResume();
因为开机默认状态,不会加载开发者模式的页面,因此在开发者模式的控制类是无法修改默认的,只能在开机必走的阶段执行使能,这里我选择的是FallbackHome这个类,每次在launcher启动之前都会调用这里,故选择该类。
编译验证,刷机即可发现在开发者选项中,该项值已经默认打开了。