[Android] 讓系統開機時自動執行script
System service法
在init.rc裡,把要呼叫的script註冊成service,並在開機時執行。init.rc
service call_script /system/bin/sh /system/bin/test.sh class main user root group shell oneshot |
Framework法
由於上述方法在新版Android時還是會權限不足,所改改由framework端,有root權限的services下手。編譯時拷貝
device/nvidia/ventana/ventana.mk
PRODUCT_COPY_FILES += \ vendor/xxx/symlink-apk.sh:system/bin/symlink-apk.sh |
java的exec method
frameworks/base/services/java/com/android/server/SystemServer.java
@Override public void run() { //+++ File file = new File("/data/media/apk-link"); if(!file.exists()){ try{ Runtime rt = Runtime.getRuntime(); Process proc = rt.exec ("symlink-apk.sh"); }catch(Exception e){ e.printStackTrace(); throw new SecurityException(); } } EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_SYSTEM_RUN, SystemClock.uptimeMillis()); //--- |
留言
張貼留言