Most services require the caller to hold android.permission.DUMP. + * + * @param name of the service to dump + * @param fd to write dump output to (usually an output log file) + * @param args to pass to the service's dump method, may be null + * @return true if the service was dumped successfully, false if + * the service could not be found or had an error while dumping + */ + public static boolean dumpService(String name, FileDescriptor fd, String[] args) { + IBinder service = ServiceManager.getService(name); + if (service == null) { + Log.e(TAG, "Can't find service to dump: " + name); + return false; + } + + try { + service.dump(fd, args); + return true; + } catch (RemoteException e) { + Log.e(TAG, "Can't dump service: " + name, e); + return false; + } + } }