lin
2025-08-14 dae8bad597b6607a449b32bf76c523423f7720ed
feat(autoboot): Add detection SD card kickpi file to start aging testing function

Signed-off-by: lin <lin@kickpi.com>
2 files modified
117 ■■■■■ changed files
android/frameworks/base/packages/SystemUI/AndroidManifest.xml 9 ●●●● patch | view | raw | blame | history
android/frameworks/base/packages/SystemUI/src/com/android/systemui/BootonAppReceiver.java 108 ●●●●● patch | view | raw | blame | history
android/frameworks/base/packages/SystemUI/AndroidManifest.xml
....@@ -662,8 +662,15 @@
662662 android:name=".BootonAppReceiver"
663663 android:enabled="true"
664664 android:exported="true">
665
+ <!-- 单独处理 BOOT_COMPLETED -->
665666 <intent-filter>
666
- <action android:name="android.intent.action.BOOT_COMPLETED"></action>
667
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
668
+ </intent-filter>
669
+
670
+ <!-- 单独处理 MEDIA_MOUNTED -->
671
+ <intent-filter>
672
+ <action android:name="android.intent.action.MEDIA_MOUNTED" />
673
+ <data android:scheme="file" />
667674 </intent-filter>
668675 </receiver>
669676
android/frameworks/base/packages/SystemUI/src/com/android/systemui/BootonAppReceiver.java
....@@ -5,14 +5,88 @@
55 import android.content.BroadcastReceiver;
66 import android.content.Context;
77 import android.content.Intent;
8
-import android.os.Process;
8
+import java.lang.Process;
99 import android.os.SystemProperties;
1010 import android.util.Log;
1111 import android.content.ComponentName;
12
+import android.os.Environment;
13
+import android.os.storage.StorageManager;
14
+import java.util.List;
15
+import android.os.storage.StorageVolume;
16
+
17
+import java.io.File;
18
+import android.net.Uri;
19
+
20
+import java.io.DataOutputStream;
21
+import java.io.IOException;
1222
1323 import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
1424
1525 public class BootonAppReceiver extends BroadcastReceiver {
26
+ private static final String TAG = "kickpi";
27
+
28
+ public static void controlLED() {
29
+ new Thread(() -> {
30
+ Process process = null;
31
+ DataOutputStream outputStream = null;
32
+
33
+ try {
34
+ // 获取 Root 权限
35
+ process = Runtime.getRuntime().exec("su");
36
+ outputStream = new DataOutputStream(process.getOutputStream());
37
+
38
+ String baseDir = "/sys/class/leds/work-led/";
39
+
40
+ // 设置触发模式为 timer
41
+ outputStream.writeBytes("echo timer > " + baseDir + "trigger\n");
42
+
43
+ // 设置亮灯时间(单位:ms)
44
+ outputStream.writeBytes("echo 2000 > " + baseDir + "delay_on\n");
45
+
46
+ // 设置灭灯时间(单位:ms)
47
+ outputStream.writeBytes("echo 2000 > " + baseDir + "delay_off\n");
48
+
49
+ outputStream.flush();
50
+ // 等待命令执行完成
51
+ Thread.sleep(100);
52
+
53
+ int exitCode = process.waitFor();
54
+ if (exitCode == 0) {
55
+ Log.d(TAG, "LED control successful!");
56
+ } else {
57
+ Log.e(TAG, "LED control failed with exit code: " + exitCode);
58
+ }
59
+
60
+ } catch (IOException | InterruptedException e) {
61
+ Log.e(TAG, "Error in LED control: " + e.getMessage());
62
+ } finally {
63
+ try {
64
+ if (outputStream != null) outputStream.close();
65
+ if (process != null) process.destroy();
66
+ } catch (IOException e) {
67
+ Log.e(TAG, "Error cleaning up: " + e.getMessage());
68
+ }
69
+ }
70
+ }).start();
71
+ }
72
+
73
+ static void AgingTestbootApp(Context context) {
74
+ try {
75
+ Intent myintent = new Intent(Intent.ACTION_MAIN);
76
+ String bootAppPack = "null";
77
+ String bootAppClass = "null";
78
+ bootAppPack = "com.oranth.factory";
79
+ bootAppClass = "com.oranth.factory.MainActivity";
80
+ Log.i(TAG,"will boot up APP - " + bootAppPack + "/" + bootAppClass);
81
+
82
+ ComponentName cn = new ComponentName(bootAppPack, bootAppClass);
83
+ myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
84
+ myintent.setComponent(cn);
85
+ context.startActivity(myintent);
86
+ } catch (Exception e) {
87
+ e.printStackTrace();
88
+ }
89
+ }
1690
1791 static void LauncherbootApp(Context context) {
1892 try {
....@@ -39,10 +113,40 @@
39113 }
40114 }
41115
116
+ // 静态标志位,记录是否已找到文件
117
+ private static boolean kickPiFound = false;
118
+
42119 @Override
43120 public void onReceive(Context context, Intent intent) {
121
+
122
+ if (kickPiFound) {
123
+ return;
124
+ }
125
+
126
+ Log.i("kickpi","intent.getAction() = " + intent.getAction());
127
+ Log.i("kickpi","Intent.ACTION_MEDIA_MOUNTED = " + Intent.ACTION_MEDIA_MOUNTED);
128
+
129
+ if (Intent.ACTION_MEDIA_MOUNTED.equals(intent.getAction())) {
130
+ Uri uri = intent.getData();
131
+ String path = uri.getPath();
132
+ Log.d(TAG, "path: " + path);
133
+ // 构造目标文件路径
134
+ File kickPiFile = new File(path, "kickpi");
135
+
136
+ // 检查文件是否存在
137
+ if (kickPiFile.exists()) {
138
+ // 设置标志位,后续广播将被忽略
139
+ kickPiFound = true;
140
+ AgingTestbootApp(context);
141
+ controlLED();
142
+ }
143
+ }
144
+
145
+ Log.i("kickpi","intent.getAction() = " + intent.getAction());
44146 if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
45
- LauncherbootApp(context);
147
+ if (!kickPiFound) {
148
+ Log.i("kickpi","LauncherbootApp");
149
+ LauncherbootApp(context);}
46150 }
47151 }
48152 }