summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmds/svc/src/com/android/commands/svc/Svc.java1
-rw-r--r--cmds/svc/src/com/android/commands/svc/SystemServerCommand.java67
-rw-r--r--core/java/android/app/IActivityManager.aidl3
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java22
4 files changed, 93 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());
+ }
+}
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index 3aa9fa7fedee..dcef9d24d3ae 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -486,4 +486,7 @@ interface IActivityManager {
* started from the shell.
*/
void stopDelegateShellPermissionIdentity();
+
+ /** Returns a file descriptor that'll be closed when the system server process dies. */
+ ParcelFileDescriptor getLifeMonitor();
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 3c0430fe0adf..a3bcbdfc9d19 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1484,6 +1484,8 @@ public class ActivityManagerService extends IActivityManager.Stub
private static String sTheRealBuildSerial = Build.UNKNOWN;
+ private ParcelFileDescriptor[] mLifeMonitorFds;
+
final class UiHandler extends Handler {
public UiHandler() {
super(com.android.server.UiThread.get().getLooper(), null, true);
@@ -18462,4 +18464,24 @@ public class ActivityManagerService extends IActivityManager.Stub
private boolean isOnOffloadQueue(int flags) {
return (mEnableOffloadQueue && ((flags & Intent.FLAG_RECEIVER_OFFLOAD) != 0));
}
+
+ @Override
+ public ParcelFileDescriptor getLifeMonitor() {
+ if (!isCallerShell()) {
+ throw new SecurityException("Only shell can call it");
+ }
+ synchronized (this) {
+ try {
+ if (mLifeMonitorFds == null) {
+ mLifeMonitorFds = ParcelFileDescriptor.createPipe();
+ }
+ // The returned FD will be closed, but we want to keep our reader open,
+ // so return a dup instead.
+ return mLifeMonitorFds[0].dup();
+ } catch (IOException e) {
+ Slog.w(TAG, "Unable to create pipe", e);
+ return null;
+ }
+ }
+ }
}