diff options
author | Makoto Onuki <omakoto@google.com> | 2019-02-19 15:55:44 -0800 |
---|---|---|
committer | Makoto Onuki <omakoto@google.com> | 2019-02-20 10:20:31 -0800 |
commit | b4469f9e589949beeed37ae9a7b11023a1fb64a8 (patch) | |
tree | 76fb6b804a5662596bfd32d562eeab12b001cad1 /cmds/svc | |
parent | 32981ff4d406cd44c5e57814088028fecb9bf72f (diff) |
Add ADB command to wait for system server crash
"adb shell svc system-server wait-for-crash" will block until the process dies.
Bug: 124022170
Test: Manual
- Run "adb shell svc system-server wait-for-crash" on multiple terminals
- Make sure open FDs aren't increasing by checking /proc/`pid system_server`/fd
- adb shell killall system_server
- All the "adb shell svc system-server wait-for-crash" should finish.
Change-Id: I203d001cd296d506ebf9f5a70b97e05e5769961a
Diffstat (limited to 'cmds/svc')
-rw-r--r-- | cmds/svc/src/com/android/commands/svc/Svc.java | 1 | ||||
-rw-r--r-- | cmds/svc/src/com/android/commands/svc/SystemServerCommand.java | 67 |
2 files changed, 68 insertions, 0 deletions
diff --git a/cmds/svc/src/com/android/commands/svc/Svc.java b/cmds/svc/src/com/android/commands/svc/Svc.java index 62225df0d6ae..68fb8e694e6f 100644 --- a/cmds/svc/src/com/android/commands/svc/Svc.java +++ b/cmds/svc/src/com/android/commands/svc/Svc.java @@ -98,5 +98,6 @@ public class Svc { new UsbCommand(), new NfcCommand(), new BluetoothCommand(), + new SystemServerCommand(), }; } diff --git a/cmds/svc/src/com/android/commands/svc/SystemServerCommand.java b/cmds/svc/src/com/android/commands/svc/SystemServerCommand.java new file mode 100644 index 000000000000..b9104d169fa6 --- /dev/null +++ b/cmds/svc/src/com/android/commands/svc/SystemServerCommand.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.commands.svc; + +import android.app.ActivityManager; +import android.os.ParcelFileDescriptor; + +import java.io.FileInputStream; + +public class SystemServerCommand extends Svc.Command { + public SystemServerCommand() { + super("system-server"); + } + + @Override + public String shortHelp() { + return "System server process related command"; + } + + @Override + public String longHelp() { + return shortHelp() + "\n" + + "\n" + + "usage: system-server wait-for-crash\n" + + " Wait until the system server process crashes.\n\n"; + } + + private void waitForCrash() throws Exception { + ParcelFileDescriptor fd = ActivityManager.getService().getLifeMonitor(); + if (fd == null) { + System.err.println("Unable to get life monitor."); + return; + } + System.out.println("Waiting for the system server process to die..."); + new FileInputStream(fd.getFileDescriptor()).read(); + } + + @Override + public void run(String[] args) { + try { + if (args.length > 1) { + switch (args[1]) { + case "wait-for-crash": + waitForCrash(); + return; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + System.err.println(longHelp()); + } +} |