OSDN Git Service

[AM] Fix system server may killed when monkey crash.
authorMark Lu <Mark_Lu@htc.com>
Mon, 21 Nov 2016 07:38:13 +0000 (15:38 +0800)
committerMark Lu <Mark_Lu@htc.com>
Tue, 29 Nov 2016 06:21:24 +0000 (06:21 +0000)
commitb5e249963141b2ab00d1a9b5e4b76d5689d64f2e
tree7ba76cd64fd59b55b4c485274ef6ee1f0859b658
parentba63f32ed588d236da49a513b5fe7c54ae6fb11d
[AM] Fix system server may killed when monkey crash.

 Symptom: monkey crash caused system server killed.
 Root Cause: when monkey crash or app crash before process bound,
        calling AppErrors.crashApplication will first
        clear binder identities, that will caused calling pid / uid
        will become with current process (i.e. system server),
        so in handleAppCrashInActivityController, when monkey registered
        activityController would like to kill crash process,
        but not found in AMS (monkey created by app_process)
        then using calling pid / uid will become to kill system server.
 Solution: add calling pid / uid parameters for
         handleAppCrashInActivityController to prevent binder identities
         cleared case.

 Test: To simulate monkey or app crash before process bound may not easy
     by using simple command, but we can write a sample program to
     simulate RuntimeInit to call handleApplicationCrash when met
     uncauchtException,

    Below is test steps in Android 7.1.1 emulator.

1. start emulator
2. after emulater started, use "adb shell am monitor" to set
   activityController & monitor process by console.
3. write a .jar program as monkey by below sample code to simulate null
   application binder to call handleApplicationCrash() as RuntimeInit:

package com.android.test;

import com.android.internal.os.BaseCommand;
public class SimulateMonkeyCrash extends BaseCommand {

    public static void main(String[] args) {
        IActivityManager am = ActivityManagerNative.getDefault();
        try {
            am.handleApplicationCrash(null,
                 new ApplicationErrorReport.CrashInfo(new Throwable()));
        } catch (RemoteException e) {
            e.printStackTrace();
    }
}

4. write a .sh file named SimulateMonkeyCrash.sh as below:
  #
  base=/system
  export CLASSPATH=$base/framework/SimulateMonkeyCrash.jar
  exec app_process $base/bin com.android.test.SimulateMonkeyCrash "$@"

5. let .sh file is executable by "chomod 755".
6. push .jar file into /system/framework & .sh file into /system/bin
7 execute .sh file.
8. activityController will detected program crash in console as below,
press k:
Waiting after crash...  available commands:
(c)ontinue: show crash dialog
(k)ill: immediately kill app
(q)uit: finish monitoring

9 you can see system server is crash.

Change-Id: Ibac4d88872f24af109d8e8522ecf5ac72fac0ce0
services/core/java/com/android/server/am/AppErrors.java