Loading cmds/svc/src/com/android/commands/svc/Svc.java +1 −0 Original line number Diff line number Diff line Loading @@ -98,5 +98,6 @@ public class Svc { new UsbCommand(), new NfcCommand(), new BluetoothCommand(), new SystemServerCommand(), }; } cmds/svc/src/com/android/commands/svc/SystemServerCommand.java 0 → 100644 +67 −0 Original line number Diff line number Diff line /* * 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()); } } core/java/android/app/IActivityManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -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(); } services/core/java/com/android/server/am/ActivityManagerService.java +22 −0 Original line number Diff line number Diff line Loading @@ -1486,6 +1486,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); Loading Loading @@ -18500,4 +18502,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; } } } } Loading
cmds/svc/src/com/android/commands/svc/Svc.java +1 −0 Original line number Diff line number Diff line Loading @@ -98,5 +98,6 @@ public class Svc { new UsbCommand(), new NfcCommand(), new BluetoothCommand(), new SystemServerCommand(), }; }
cmds/svc/src/com/android/commands/svc/SystemServerCommand.java 0 → 100644 +67 −0 Original line number Diff line number Diff line /* * 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()); } }
core/java/android/app/IActivityManager.aidl +3 −0 Original line number Diff line number Diff line Loading @@ -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(); }
services/core/java/com/android/server/am/ActivityManagerService.java +22 −0 Original line number Diff line number Diff line Loading @@ -1486,6 +1486,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); Loading Loading @@ -18500,4 +18502,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; } } } }