meta模式是mtk提供的一種測試的模式。常常在工廠測試中使用,他不用載入整個android系統(tǒng),就跟recovery模式一樣,是一種啟動模式。常用的啟動模式有
1.normal(就是正常用手機的模式啦)
2.recovery(刷機的時候用)
3.meta模式(工廠測試的時候常常用,不用加載龐大的android系統(tǒng),減少檢測硬件好壞的干擾)
使用adb指令可以進(jìn)入不同的模式
adb reboot meta
adb reboot recovery
應(yīng)用層面可以用PowerManager.reboot方法實現(xiàn)
PowerManager powerManager = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
powerManager.reboot(PowerManager.REBOOT_META_WIFI ); //進(jìn)入meta的wifi測試
下面深入系統(tǒng)看看是怎么進(jìn)入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) {
}
}
進(jìn)入PowerManagerService的reboot方法
public void reboot(boolean confirm, String reason, boolean wait) {
....
shutdownOrRebootInternal(false, confirm, reason, wait);
.....
進(jìn)入shutdownOrRebootInternal
private void shutdownOrRebootInternal(final boolean shutdown, final boolean confirm,
final String reason, boolean wait) {
......
ShutdownThread.reboot(mContext, reason, confirm);
......
}
開啟一個關(guān)機線程ShutdownThread,然后手機開始重啟。重啟后會進(jìn)入 PowerManagerService的 lowLevelReboot方法。然后設(shè)置兩個屬性
SystemProperties.set("persist.meta.connecttype", "wifi");
SystemProperties.set("ctl.start", "pre_meta");
ctl.start用于啟動一個服務(wù),所以這里會啟動服務(wù)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中設(shè)置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;//設(shè)置全局的bootmode,這個在init進(jìn)程會用到
set_env(REBOOT_META_FLAG, "0");
return;
}
mtk的init進(jìn)程判斷啟動模式是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文件里面啟動測試服務(wù),就Ok了!!!!!!!!!!!!
service meta_tst /system/bin/meta_tst