1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.commands.svc; 18 19 import android.app.ActivityManager; 20 import android.os.ParcelFileDescriptor; 21 22 import java.io.FileInputStream; 23 24 public class SystemServerCommand extends Svc.Command { SystemServerCommand()25 public SystemServerCommand() { 26 super("system-server"); 27 } 28 29 @Override shortHelp()30 public String shortHelp() { 31 return "System server process related command"; 32 } 33 34 @Override longHelp()35 public String longHelp() { 36 return shortHelp() + "\n" 37 + "\n" 38 + "usage: system-server wait-for-crash\n" 39 + " Wait until the system server process crashes.\n\n"; 40 } 41 waitForCrash()42 private void waitForCrash() throws Exception { 43 ParcelFileDescriptor fd = ActivityManager.getService().getLifeMonitor(); 44 if (fd == null) { 45 System.err.println("Unable to get life monitor."); 46 return; 47 } 48 System.out.println("Waiting for the system server process to die..."); 49 new FileInputStream(fd.getFileDescriptor()).read(); 50 } 51 52 @Override run(String[] args)53 public void run(String[] args) { 54 try { 55 if (args.length > 1) { 56 switch (args[1]) { 57 case "wait-for-crash": 58 waitForCrash(); 59 return; 60 } 61 } 62 } catch (Exception e) { 63 e.printStackTrace(); 64 } 65 System.err.println(longHelp()); 66 } 67 } 68