[Android]添加全局水印 Posted on 2020-08-17 | In Android Words count in article: 字 | Reading time ≈ 分钟 需求 在测试版本添加水印,以明确该版本非正式版,仅供测试使用。 效果 正式版本编译时去掉ro.show.testversion=true即可 patch 准备透明背景图片,添加需要显示的文字,如下图: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108diff --git a/device/rockchip/rk3288/system.prop b/device/rockchip/rk3288/system.propindex daed487570..d519c47ab4 100644--- a/device/rockchip/rk3288/system.prop+++ b/device/rockchip/rk3288/system.prop@@ -47,3 +47,4 @@ ro.adb.secure=0 ro.rk.displayd.enable=false qemu.hw.mainkeys=0 service.adb.tcp.port=5555+ro.show.testversion=truediff --git a/frameworks/base/core/res/res/drawable-hdpi/test_version.png b/frameworks/base/core/res/res/drawable-hdpi/test_version.pngnew file mode 100644index 0000000000..70d118084dBinary files /dev/null and b/frameworks/base/core/res/res/drawable-hdpi/test_version.png differdiff --git a/frameworks/base/core/res/res/layout/test_version.xml b/frameworks/base/core/res/res/layout/test_version.xmlnew file mode 100644index 0000000000..e169f1852f--- /dev/null+++ b/frameworks/base/core/res/res/layout/test_version.xml@@ -0,0 +1,24 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- Copyright (C) 2006 The Android Open Source Project++ Licensed under the Apache License, Version 2.0 (the "License");+ you may not use this file except in compliance with the License.+ You may obtain a copy of the License at+ + http://www.apache.org/licenses/LICENSE-2.0+ + Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.+-->++<ImageView xmlns:android="http://schemas.android.com/apk/res/android"+ android:layout_width="wrap_content" android:layout_height="wrap_content"+ android:gravity="center"+ android:padding="3dp"+ android:background="@android:color/transparent"+ android:src="@drawable/test_version"+ android:alpha="0.3"+/>diff --git a/frameworks/base/core/res/res/values/symbols.xml b/frameworks/base/core/res/res/values/symbols.xmlindex 81d06afa8d..dcc18ebe0d 100644--- a/frameworks/base/core/res/res/values/symbols.xml+++ b/frameworks/base/core/res/res/values/symbols.xml@@ -1793,6 +1793,7 @@ <java-symbol type="layout" name="am_compat_mode_dialog" /> <java-symbol type="layout" name="launch_warning" /> <java-symbol type="layout" name="safe_mode" />+ <java-symbol type="layout" name="test_version" /> <java-symbol type="layout" name="simple_list_item_2_single_choice" /> <java-symbol type="layout" name="app_error_dialog" /> <java-symbol type="plurals" name="wifi_available" />diff --git a/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java b/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.javaindex 9fbd87de44..1edc98b446 100755--- a/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java+++ b/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java@@ -13075,6 +13075,28 @@ public final class ActivityManagerService extends ActivityManagerNative } } + private View TestVersionView = null;+ public final void showTestVersionOverlay() {+ if (null != TestVersionView) {+ ((WindowManager)mContext.getSystemService(+ Context.WINDOW_SERVICE)).removeView(TestVersionView);+ }+ int resorce = com.android.internal.R.layout.test_version;++ TestVersionView = LayoutInflater.from(mContext).inflate(resorce, 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;+ lp.format = TestVersionView.getBackground().getOpacity();+ lp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE+ | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;+ lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;+ ((WindowManager)mContext.getSystemService(+ Context.WINDOW_SERVICE)).addView(TestVersionView, lp);+ }+ public final void showSafeModeOverlay() { View v = LayoutInflater.from(mContext).inflate( com.android.internal.R.layout.safe_mode, null);diff --git a/frameworks/base/services/java/com/android/server/SystemServer.java b/frameworks/base/services/java/com/android/server/SystemServer.javaindex 393f062717..c0033ba04b 100644--- a/frameworks/base/services/java/com/android/server/SystemServer.java+++ b/frameworks/base/services/java/com/android/server/SystemServer.java@@ -1255,10 +1255,14 @@ public final class SystemServer { // we are in safe mode. //final boolean safeMode = wm.detectSafeMode(); final boolean safeMode = false;+ final boolean TestVersion = (SystemProperties.get("ro.show.testversion").equals("true") ? true : false); if (safeMode) { mActivityManagerService.enterSafeMode(); // Disable the JIT for the system_server process VMRuntime.getRuntime().disableJitCompilation();+ } else if (TestVersion) {+ mActivityManagerService.showTestVersionOverlay();+ VMRuntime.getRuntime().startJitCompilation(); } else { // Enable the JIT for the system_server process VMRuntime.getRuntime().startJitCompilation(); 您的支持将鼓励我继续创作! Donate WeChat Pay Alipay