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

測試程序

在/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. 每當屬性值被設置時,不管值有沒有變化,都會檢查觸發條件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章