Android學習 —— 測試init.rc中的條件觸發的處理順序

摩斯电码發表於2024-03-10

測試程式

在/system/etc/init/hw/init.rc中追加下面的測試程式:
image

然後重啟

日誌

使用logcat抓取init的日誌:

adb wait-for-device logcat -s init

測試

  • 依次設定test1和test2
vsoc_x86_64:/ # setprop pengdl.test1 1
vsoc_x86_64:/ # setprop pengdl.test2 1

然後會看到下面的日誌:
image

test.txt的檔案內容:

vsoc_x86_64:/ # cat /data/test.txt
1
  • 再次設定test1或者test2
vsoc_x86_64:/ # setprop pengdl.test1 1

看到如下日誌:
image

檔案內容還是1.

  • 設定test3
vsoc_x86_64:/ # setprop pengdl.test3 1

看到如下日誌:
image
檔案內容變成3

  • 再次設定test3
vsoc_x86_64:/ # setprop pengdl.test3 1

看到如下日誌:
image
檔案內容還是3

  • 再次設定test1或者test2
vsoc_x86_64:/ # setprop pengdl.test2 1

看到如下日誌:
image
檔案內容還是3

總結

從上面的測試可以得到如下結論:

  1. 當設定某個屬性時,會檢查所有用到該屬性的section的觸發條件
  2. 如果多個section的觸發條件都滿足,按照在檔案中出現(或者說是解析時)的先後順序依次處理
  3. 每當屬性值被設定時,不管值有沒有變化,都會檢查觸發條件

相關文章