需求
继https://intgyl.com/post/a5cf29a9.html#more 添加logo和开机动画分区后,又有部分客户需要不同的显示方向,即现场安装时可能使用横屏也可能使用竖屏
分析
由于我们已经添加了logo分区和oem分区,因此只需要将对应方向的logo和动画替换即可,启动logo分区没有文件系统,oem分区为ext4文件系统,而且开机后已经挂载到/oem/下,因此总体流程如下
- 在settings中添加旋转屏幕的选项,提供用户选择具体方向
- 获取到对应的选择后调用提前写好的脚步进行相关操作
验证后发现脚步的操作需要root权限,而setting中没有该权限无法执行
改进方案:
- setting中添加选项保持不变
- 将脚本的执行操作放到recovery中执行,recovery中是有root权限的,因此可以对分区进行修改
实现
setting中添加选项
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17diff --git a/packages/apps/Settings/res/xml/display_settings.xml b/packages/apps/Settings/res/xml/display_settings.xml
index ad57326..c706d52 100755 (executable)
--- a/packages/apps/Settings/res/xml/display_settings.xml
+++ b/packages/apps/Settings/res/xml/display_settings.xml
@@ -121,5 +121,12 @@
android:key="vr_display_pref"
android:summary="%s"
android:title="@string/display_vr_pref_title" />
+ <Preference android:key="screen_rotation"
+ android:title="@string/screen_rotation" >
+ <intent
+ android:action="android.intent.action.MAIN"
+ android:targetPackage="com.example.tchippoweronoffalarm"
+ android:targetClass="com.example.tchippoweronoffalarm.ScreenRotationAndStatusbarActivity" />
+ </Preference>
</PreferenceScreen>1
2
3
4
5
6
7
8
9
10
11
12diff --git a/packages/apps/Settings/res/values/strings.xml b/packages/apps/Settings/res/values/strings.xml
index 8e2c52a..a2927fa 100755 (executable)
--- a/packages/apps/Settings/res/values/strings.xml
+++ b/packages/apps/Settings/res/values/strings.xml
@@ -7969,6 +7969,7 @@
<string name="screen_control_ok_title">Keep</string>
<string name="screen_control_cancel_title">Restore</string>
<string name="screenscale">Screen Scale</string>
+ <string name="screen_rotation">屏幕旋转</string>
<!-- $_rbox_$_modify_$_zhengyang: end for screen settings -->
<string name="confirm_dialog_title">Save Confirm</string>
<string name="confirm_dialog_message">Will cancel in</string>添加进入recovery旋转操作的api
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
66diff --git a/frameworks/base/api/current.txt b/frameworks/base/api/current.txt
index 81b526061b..3b0067d65c 100644
--- a/frameworks/base/api/current.txt
+++ b/frameworks/base/api/current.txt
@@ -29418,6 +29418,7 @@ package android.os {
public class RecoverySystem {
method public static void installPackage(android.content.Context, java.io.File) throws java.io.IOException;
+ method public static void rebootRotateScreen(android.content.Context) throws java.io.IOException;
method public static void rebootWipeCache(android.content.Context) throws java.io.IOException;
method public static void rebootWipeUserData(android.content.Context) throws java.io.IOException;
method public static void verifyPackage(java.io.File, android.os.RecoverySystem.ProgressListener, java.io.File) throws java.security.GeneralSecurityException, java.io.IOException;
diff --git a/frameworks/base/api/system-current.txt b/frameworks/base/api/system-current.txt
index 9f8f33621a..6c62a09961 100644
--- a/frameworks/base/api/system-current.txt
+++ b/frameworks/base/api/system-current.txt
@@ -31926,6 +31926,7 @@ package android.os {
method public static void installPackage(android.content.Context, java.io.File, boolean) throws java.io.IOException;
method public static void processPackage(android.content.Context, java.io.File, android.os.RecoverySystem.ProgressListener, android.os.Handler) throws java.io.IOException;
method public static void processPackage(android.content.Context, java.io.File, android.os.RecoverySystem.ProgressListener) throws java.io.IOException;
+ method public static void rebootRotateScreen(android.content.Context) throws java.io.IOException;
method public static void rebootWipeAb(android.content.Context, java.io.File, java.lang.String) throws java.io.IOException;
method public static void rebootWipeCache(android.content.Context) throws java.io.IOException;
method public static void rebootWipeUserData(android.content.Context) throws java.io.IOException;
diff --git a/frameworks/base/api/test-current.txt b/frameworks/base/api/test-current.txt
index 8f69c4bb3e..d9dc025e73 100644
--- a/frameworks/base/api/test-current.txt
+++ b/frameworks/base/api/test-current.txt
@@ -29493,6 +29493,7 @@ package android.os {
public class RecoverySystem {
method public static void installPackage(android.content.Context, java.io.File) throws java.io.IOException;
+ method public static void rebootRotateScreen(android.content.Context) throws java.io.IOException;
method public static void rebootWipeCache(android.content.Context) throws java.io.IOException;
method public static void rebootWipeUserData(android.content.Context) throws java.io.IOException;
method public static void verifyPackage(java.io.File, android.os.RecoverySystem.ProgressListener, java.io.File) throws java.security.GeneralSecurityException, java.io.IOException;
diff --git a/frameworks/base/core/java/android/os/RecoverySystem.java b/frameworks/base/core/java/android/os/RecoverySystem.java
index 4dc501ef25..969510db17 100644
--- a/frameworks/base/core/java/android/os/RecoverySystem.java
+++ b/frameworks/base/core/java/android/os/RecoverySystem.java
@@ -676,6 +676,25 @@ public class RecoverySystem {
bootCommand(context, "--wipe_cache", reasonArg, localeArg);
}
+ /**
+ * Reboot into the recovery system to rotate the screen.
+ * @throws IOException if something goes wrong.
+ */
+ public static void rebootRotateScreen(Context context) throws IOException {
+ rebootRotateScreen(context, context.getPackageName());
+ }
+
+ /** {@hide} */
+ public static void rebootRotateScreen(Context context, String reason) throws IOException {
+ String reasonArg = null;
+ if (!TextUtils.isEmpty(reason)) {
+ reasonArg = sanitizeArg(reason);
+ }
+
+ final String localeArg = "--locale=" + Locale.getDefault().toString();
+ bootCommand(context, "--rotate_screen", reasonArg, localeArg);
+ }
+
/**
* Reboot into recovery and wipe the A/B device.
*recovery 修改
接收到对应的参数后执行体检准备好的修改脚本即可
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
55diff --git a/bootable/recovery/recovery.cpp b/bootable/recovery/recovery.cpp
index 10743c95de..8cf2e26687 100644
--- a/bootable/recovery/recovery.cpp
+++ b/bootable/recovery/recovery.cpp
@@ -97,6 +97,7 @@ static const struct option OPTIONS[] = {
{ "resize_partition", required_argument, NULL, 'r'+'p' },
{ "factory_mode", required_argument, NULL, 'f' },
{ "pcba_test", required_argument, NULL, 'p'+'t' },
+ { "rotate_screen", required_argument, NULL, 'r'+'s' },
{ NULL, 0, NULL, 0 },
};
@@ -1716,11 +1717,13 @@ int main(int argc, char **argv) {
const char *update_package = NULL;
const char *update_rkimage = NULL;
const char *factory_mode = NULL;
+ const char *rotation = NULL;
char *sdboot_update_package = NULL;
bool should_wipe_data = false;
bool should_wipe_all = false;
bool should_wipe_cache = false;
bool should_wipe_ab = false;
+ bool should_rotate_screen = false;
size_t wipe_package_size = 0;
bool show_text = false;
bool sideload = false;
@@ -1781,6 +1784,7 @@ int main(int argc, char **argv) {
break;
case 'f': factory_mode = optarg; break;
case 'p'+'t': factory_mode = optarg; break;
+ case 'r'+'s': {should_rotate_screen = true; rotation = optarg;} break;
case '?':
LOGE("Invalid command argument\n");
continue;
@@ -1953,7 +1957,19 @@ int main(int argc, char **argv) {
printf("do_factory_mode status=%d factory_mode=%s \n", status, factory_mode);
exit_from_factory = 1;
- }else if (sdboot_update_package != NULL){
+ } else if (should_rotate_screen) {
+
+ char cmd[1024];
+ memset(cmd, 0, sizeof(cmd));
+ strcpy(cmd, "sh /oem/rotation/modify-rotation.sh ");
+ strcat(cmd, rotation);
+
+ ensure_path_mounted("/system");
+ ensure_path_mounted("/oem");
+ system(cmd);
+ system("sync");
+
+ } else if (sdboot_update_package != NULL){
printf("bSDBoot = %d, sdboot_update_package=%s\n", rksdboot.isSDboot(), sdboot_update_package);
startLed();
status = rksdboot.do_rk_mode_update(sdboot_update_package);修改脚本
脚本的主要操作如下:
使用dd命令将对应角度的logo图片写入logo分区
将对应的动画拷贝到/oem/media 目录想
修改system/build.prop中ro.sf.hwrotation的值,该属性用于确定屏幕方向
1 | if [ $# != 1 ]; then |
完整patch
1 | display: add screen rotation option in Settings |