Framework基础:手机如何进入meta测试模式

meta模式是mtk提供的一种测试的模式。常常在工厂测试中使用,他不用载入整个android系统,就跟recovery模式一样,是一种启动模式。常用的启动模式有
1.normal(就是正常用手机的模式啦)
2.recovery(刷机的时候用)
3.meta模式(工厂测试的时候常常用,不用加载庞大的android系统,减少检测硬件好坏的干扰)

使用adb指令可以进入不同的模式

adb reboot meta
adb reboot recovery

应用层面可以用PowerManager.reboot方法实现

PowerManager powerManager = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
powerManager.reboot(PowerManager.REBOOT_META_WIFI ); //进入meta的wifi测试

下面深入系统看看是怎么进入meta模式的
在PowerManager 中调用reboot方法

public static final String REBOOT_META_WIFI = "meta_wifi";
    public void reboot(String reason) {
        try {
            mService.reboot(false, reason, true);//mService会通过binder调用到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的环境变量,重新启动

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了!!!!!!!!!!!!

service meta_tst /system/bin/meta_tst
    原文作者:九九叔
    原文地址: https://www.jianshu.com/p/e19c0525b9f3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞