meta模式是mtk提供的一種測試的模式募谎。常常在工廠測試中使用,他不用載入整個android系統(tǒng)阴汇,就跟recovery模式一樣数冬,是一種啟動模式。常用的啟動模式有
1.normal(就是正常用手機的模式啦)
2.recovery(刷機的時候用)
3.meta模式(工廠測試的時候常常用鲫寄,不用加載龐大的android系統(tǒng)吉执,減少檢測硬件好壞的干擾)
使用adb指令可以進入不同的模式
adb reboot meta
adb reboot recovery
應用層面可以用PowerManager.reboot方法實現(xiàn)
PowerManager powerManager = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
powerManager.reboot(PowerManager.REBOOT_META_WIFI ); //進入meta的wifi測試
下面深入系統(tǒng)看看是怎么進入meta模式的
在PowerManager 中調(diào)用reboot方法
public static final String REBOOT_META_WIFI = "meta_wifi";
public void reboot(String reason) {
try {
mService.reboot(false, reason, true);//mService會通過binder調(diào)用到PowerManagerService
} catch (RemoteException e) {
}
}
進入PowerManagerService的reboot方法
public void reboot(boolean confirm, String reason, boolean wait) {
....
shutdownOrRebootInternal(false, confirm, reason, wait);
.....
進入shutdownOrRebootInternal
private void shutdownOrRebootInternal(final boolean shutdown, final boolean confirm,
final String reason, boolean wait) {
......
ShutdownThread.reboot(mContext, reason, confirm);
......
}
開啟一個關機線程ShutdownThread,然后手機開始重啟地来。重啟后會進入 PowerManagerService的 lowLevelReboot方法戳玫。然后設置兩個屬性
SystemProperties.set("persist.meta.connecttype", "wifi");
SystemProperties.set("ctl.start", "pre_meta");
ctl.start用于啟動一個服務,所以這里會啟動服務pre_meta未斑。
public static void lowLevelReboot(String reason) {
if (reason == null) {
reason = "";
}
if (reason.equals(PowerManager.REBOOT_RECOVERY)) {
// If we are rebooting to go into recovery, instead of
// setting sys.powerctl directly we'll start the
// pre-recovery service which will do some preparation for
// recovery and then reboot for us.
SystemProperties.set("ctl.start", "pre-recovery");
} else if(reason.equals(PowerManager.REBOOT_META_WIFI)) {
// If we are rebooting to go into meta, instead of
// setting sys.powerctl directly we'll start the
// pre-meta service which will do some preparation for
// wifi meta mode and then reboot for us.
SystemProperties.set("persist.meta.connecttype", "wifi");
SystemProperties.set("ctl.start", "pre_meta");
} else if(reason.equals(PowerManager.REBOOT_META_USB)) {
// If we are rebooting to go into meta, instead of
// setting sys.powerctl directly we'll start the
// pre-meta service which will do some preparation for
// usb meta mode and then reboot for us.
SystemProperties.set("persist.meta.connecttype", "usb");
SystemProperties.set("ctl.start", "pre_meta");
}
try {
Thread.sleep(20 * 1000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
Slog.wtf(TAG, "Unexpected return from lowLevelReboot!");
}
在pre_meta中設置lk的環(huán)境變量咕宿,重新啟動
int main(int argc, char** argv)
{
if(set_env_value(REBOOT_META_FLAG,REBOOT_META_FLAG_VALUE,REBOOT_META_FLAG_LENGTH))
{
ALOGE("META[pre_meta] set %s to lk_env fail",REBOOT_META_FLAG);
}
sync();
property_set("sys.powerctl","reboot");
ALOGD("META[pre_meta] reboot target");
return 0;
}
在平臺的lk過程中判斷是否有這個flag
文件platform/mt6755/boot_mode.c
void boot_mode_select(void)
{
if (strcmp(meta_value, REBOOT_META_FLAG_VALUE) == 0){
g_boot_mode = META_BOOT;//設置全局的bootmode,這個在init進程會用到
set_env(REBOOT_META_FLAG, "0");
return;
}
mtk的init進程判斷啟動模式是meta wifi模式,則加載meta_init.rc文件
mediatek/proprietary/system/core/multi_init/init.cpp
if (mt_boot_mode == MT_META_BOOT) {
NOTICE("META Mode Booting.....\n");
init_parse_config_file("/meta_init.rc");
}
在meta_init.rc文件里面啟動測試服務府阀,就Ok了@铝汀!J哉恪6啊!L锇汀D坪!R疾浮3椤!管宵!
service meta_tst /system/bin/meta_tst