定屏案例--monkey参数不对导致的定屏

monkey测试中如果不添加--kill-process-after-error 参数,在系统关键进程存在block的情况导致watchdog的时候会导致定屏而非重启,原因如下:
在watchdog.java里面的run函数里,会做检测,如果controller不为空,说明有monkey,所以要将该信息回报给monkey,所以会调用monkey的systemNotResponding函数
watchdog.java:
            synchronized (this) {
                controller = mController;
            }
            if (controller != null) {
                Slog.i(TAG, "Reporting stuck state to activity controller");
                try {
                    Binder.setDumpDisabled("Service dumps disabled due to hung system process.");
                    // 1 = keep waiting, -1 = kill system
                    int res = controller.systemNotResponding(subject);
                    if (res >= 0) {
                        Slog.i(TAG, "Activity controller requested to coninue to wait");
                        waitedHalf = false;
                        continue;
                    }
                } catch (RemoteException e) {
                }
            }
monkey.java里在systemNotResponding这个函数里,如果加了--kill-process-after-error函数后,就会将mKillProcessAfterError设置为true
              } else if (opt.equals("--kill-process-after-error")) {
                    mKillProcessAfterError = true;
                    
 如果mKillProcessAfterError = true monkey的  systemNotResponding 的函数就会返回-1, 后面watchdog就可以正常走了。反之,返回1的话走到wathdog的run里面,res就会大于0,然后就会打印"Activity controller requested to coninue to wait"到 system log里,然后将 waitedHalf = false continue了,就不会走watchdog kill的流程了,就会定屏了。
public int systemNotResponding(String message) {
            StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskWrites();
            System.err.println("// WATCHDOG: " + message);
            StrictMode.setThreadPolicy(savedPolicy);

            synchronized (Monkey.this) {
                if (!mIgnoreCrashes) {
                    mAbort = true;
                }
                if (mRequestBugreport) {
                    mRequestWatchdogBugreport = true;
                }
                mWatchdogWaiting = true;
            }
            synchronized (Monkey.this) {
                while (mWatchdogWaiting) {
                    try {
                        Monkey.this.wait();
                    } catch (InterruptedException e) {
                    }
                }
            }
            return (mKillProcessAfterError) ? -1 : 1;
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值