-
效果
-
源码实现
frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
public final void showSafeModeOverlay() {View v = LayoutInflater.from(mContext).inflate(com.android.internal.R.layout.safe_mode, null);WindowManager.LayoutParams lp = new WindowManager.LayoutParams();lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;lp.width = WindowManager.LayoutParams.WRAP_CONTENT;lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//lp.gravity = Gravity.BOTTOM | Gravity.START;//修改为居中显示lp.gravity = Gravity.CENTER;lp.format = v.getBackground().getOpacity();lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;lp.privateFlags |= WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).addView(v, lp);
}
- 源码调用
frameworks/base/services/java/com/android/server/SystemServer.java
//if(safeMode){//默认设置为安全模式mActivityManagerService.showSafeModeOverlay();//}
- 布局
frameworks/base/core/res/res/layout/safe_mode.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="wrap_content" android:layout_height="wrap_content"android:textAppearance="?android:attr/textAppearanceLarge"android:gravity="center"android:padding="3dp"android:background="@drawable/safe_mode_background"android:textColor="@color/safe_mode_text"android:text="@string/safeModeTest"
/>
- 资源
frameworks/base/core/res/res/values/string.xml
<string name="safeModeTest">Debug version, cannot be used for external provision</string>
frameworks/base/core/res/res/values-zh-rCN/string.xml
<string name="safeModeTest">当前是调试版本,不可用于对外提供</string>