From dae8bad597b6607a449b32bf76c523423f7720ed Mon Sep 17 00:00:00 2001 From: lin <lin@kickpi.com> Date: Thu, 14 Aug 2025 09:38:29 +0000 Subject: [PATCH] feat(autoboot): Add detection SD card kickpi file to start aging testing function --- android/frameworks/base/packages/SystemUI/AndroidManifest.xml | 9 ++++ android/frameworks/base/packages/SystemUI/src/com/android/systemui/BootonAppReceiver.java | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 3 deletions(-) diff --git a/android/frameworks/base/packages/SystemUI/AndroidManifest.xml b/android/frameworks/base/packages/SystemUI/AndroidManifest.xml index 01cbcf5..49d15ef 100644 --- a/android/frameworks/base/packages/SystemUI/AndroidManifest.xml +++ b/android/frameworks/base/packages/SystemUI/AndroidManifest.xml @@ -662,8 +662,15 @@ android:name=".BootonAppReceiver" android:enabled="true" android:exported="true"> + <!-- 单独处理 BOOT_COMPLETED --> <intent-filter> - <action android:name="android.intent.action.BOOT_COMPLETED"></action> + <action android:name="android.intent.action.BOOT_COMPLETED" /> + </intent-filter> + + <!-- 单独处理 MEDIA_MOUNTED --> + <intent-filter> + <action android:name="android.intent.action.MEDIA_MOUNTED" /> + <data android:scheme="file" /> </intent-filter> </receiver> diff --git a/android/frameworks/base/packages/SystemUI/src/com/android/systemui/BootonAppReceiver.java b/android/frameworks/base/packages/SystemUI/src/com/android/systemui/BootonAppReceiver.java index 3a75428..31826aa 100755 --- a/android/frameworks/base/packages/SystemUI/src/com/android/systemui/BootonAppReceiver.java +++ b/android/frameworks/base/packages/SystemUI/src/com/android/systemui/BootonAppReceiver.java @@ -5,14 +5,88 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.os.Process; +import java.lang.Process; import android.os.SystemProperties; import android.util.Log; import android.content.ComponentName; +import android.os.Environment; +import android.os.storage.StorageManager; +import java.util.List; +import android.os.storage.StorageVolume; + +import java.io.File; +import android.net.Uri; + +import java.io.DataOutputStream; +import java.io.IOException; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; public class BootonAppReceiver extends BroadcastReceiver { + private static final String TAG = "kickpi"; + + public static void controlLED() { + new Thread(() -> { + Process process = null; + DataOutputStream outputStream = null; + + try { + // 获取 Root 权限 + process = Runtime.getRuntime().exec("su"); + outputStream = new DataOutputStream(process.getOutputStream()); + + String baseDir = "/sys/class/leds/work-led/"; + + // 设置触发模式为 timer + outputStream.writeBytes("echo timer > " + baseDir + "trigger\n"); + + // 设置亮灯时间(单位:ms) + outputStream.writeBytes("echo 2000 > " + baseDir + "delay_on\n"); + + // 设置灭灯时间(单位:ms) + outputStream.writeBytes("echo 2000 > " + baseDir + "delay_off\n"); + + outputStream.flush(); + // 等待命令执行完成 + Thread.sleep(100); + + int exitCode = process.waitFor(); + if (exitCode == 0) { + Log.d(TAG, "LED control successful!"); + } else { + Log.e(TAG, "LED control failed with exit code: " + exitCode); + } + + } catch (IOException | InterruptedException e) { + Log.e(TAG, "Error in LED control: " + e.getMessage()); + } finally { + try { + if (outputStream != null) outputStream.close(); + if (process != null) process.destroy(); + } catch (IOException e) { + Log.e(TAG, "Error cleaning up: " + e.getMessage()); + } + } + }).start(); + } + + static void AgingTestbootApp(Context context) { + try { + Intent myintent = new Intent(Intent.ACTION_MAIN); + String bootAppPack = "null"; + String bootAppClass = "null"; + bootAppPack = "com.oranth.factory"; + bootAppClass = "com.oranth.factory.MainActivity"; + Log.i(TAG,"will boot up APP - " + bootAppPack + "/" + bootAppClass); + + ComponentName cn = new ComponentName(bootAppPack, bootAppClass); + myintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + myintent.setComponent(cn); + context.startActivity(myintent); + } catch (Exception e) { + e.printStackTrace(); + } + } static void LauncherbootApp(Context context) { try { @@ -39,10 +113,40 @@ } } + // 静态标志位,记录是否已找到文件 + private static boolean kickPiFound = false; + @Override public void onReceive(Context context, Intent intent) { + + if (kickPiFound) { + return; + } + + Log.i("kickpi","intent.getAction() = " + intent.getAction()); + Log.i("kickpi","Intent.ACTION_MEDIA_MOUNTED = " + Intent.ACTION_MEDIA_MOUNTED); + + if (Intent.ACTION_MEDIA_MOUNTED.equals(intent.getAction())) { + Uri uri = intent.getData(); + String path = uri.getPath(); + Log.d(TAG, "path: " + path); + // 构造目标文件路径 + File kickPiFile = new File(path, "kickpi"); + + // 检查文件是否存在 + if (kickPiFile.exists()) { + // 设置标志位,后续广播将被忽略 + kickPiFound = true; + AgingTestbootApp(context); + controlLED(); + } + } + + Log.i("kickpi","intent.getAction() = " + intent.getAction()); if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { - LauncherbootApp(context); + if (!kickPiFound) { + Log.i("kickpi","LauncherbootApp"); + LauncherbootApp(context);} } } } -- Gitblit v1.6.2