測試程序
在/system/etc/init/hw/init.rc中追加下面的測試程序:
然後重啓
日誌
使用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
然後會看到下面的日誌:
test.txt的文件內容:
vsoc_x86_64:/ # cat /data/test.txt
1
- 再次設置test1或者test2
vsoc_x86_64:/ # setprop pengdl.test1 1
看到如下日誌:
文件內容還是1.
- 設置test3
vsoc_x86_64:/ # setprop pengdl.test3 1
看到如下日誌:
文件內容變成3
- 再次設置test3
vsoc_x86_64:/ # setprop pengdl.test3 1
看到如下日誌:
文件內容還是3
- 再次設置test1或者test2
vsoc_x86_64:/ # setprop pengdl.test2 1
看到如下日誌:
文件內容還是3
總結
從上面的測試可以得到如下結論:
- 當設置某個屬性時,會檢查所有用到該屬性的section的觸發條件
- 如果多個section的觸發條件都滿足,按照在文件中出現(或者說是解析時)的先後順序依次處理
- 每當屬性值被設置時,不管值有沒有變化,都會檢查觸發條件