[Android]添加全局水印

需求

在测试版本添加水印,以明确该版本非正式版,仅供测试使用。

效果

正式版本编译时去掉ro.show.testversion=true即可

patch

准备透明背景图片,添加需要显示的文字,如下图:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

diff --git a/device/rockchip/rk3288/system.prop b/device/rockchip/rk3288/system.prop
index 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=true
diff --git a/frameworks/base/core/res/res/drawable-hdpi/test_version.png b/frameworks/base/core/res/res/drawable-hdpi/test_version.png
new file mode 100644
index 0000000000..70d118084d
Binary files /dev/null and b/frameworks/base/core/res/res/drawable-hdpi/test_version.png differ
diff --git a/frameworks/base/core/res/res/layout/test_version.xml b/frameworks/base/core/res/res/layout/test_version.xml
new file mode 100644
index 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.xml
index 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.java
index 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.java
index 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();
您的支持将鼓励我继续创作!