下面列出了android.util.PrintWriterPrinter#com.android.internal.util.DumpUtils 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void dumpLocked(PrintWriter pw) {
super.dumpLocked(pw);
pw.println("mCurrentStatus=" + getWifiDisplayStatusLocked());
pw.println("mFeatureState=" + mFeatureState);
pw.println("mScanState=" + mScanState);
pw.println("mActiveDisplayState=" + mActiveDisplayState);
pw.println("mActiveDisplay=" + mActiveDisplay);
pw.println("mDisplays=" + Arrays.toString(mDisplays));
pw.println("mAvailableDisplays=" + Arrays.toString(mAvailableDisplays));
pw.println("mRememberedDisplays=" + Arrays.toString(mRememberedDisplays));
pw.println("mPendingStatusChangeBroadcast=" + mPendingStatusChangeBroadcast);
pw.println("mSupportsProtectedBuffers=" + mSupportsProtectedBuffers);
// Try to dump the controller state.
if (mDisplayController == null) {
pw.println("mDisplayController=null");
} else {
pw.println("mDisplayController:");
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
ipw.increaseIndent();
DumpUtils.dumpAsync(getHandler(), mDisplayController, ipw, "", 200);
}
}
@Override
protected void dump(FileDescriptor fd, final PrintWriter fout, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, fout)) return;
if (isSafeMode()) {
fout.println("disabled because the system is in safe mode.");
return;
}
if (!mTrustAgentsCanRun) {
fout.println("disabled because the third-party apps can't run yet.");
return;
}
final List<UserInfo> userInfos = mUserManager.getUsers(true /* excludeDying */);
mHandler.runWithScissors(new Runnable() {
@Override
public void run() {
fout.println("Trust manager state:");
for (UserInfo user : userInfos) {
dumpUser(fout, user, user.id == mCurrentUser);
}
}
}, 1500);
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
pw.println("Vibrator Service:");
synchronized (mLock) {
pw.print(" mCurrentVibration=");
if (mCurrentVibration != null) {
pw.println(mCurrentVibration.toInfo().toString());
} else {
pw.println("null");
}
pw.println(" mLowPowerMode=" + mLowPowerMode);
pw.println(" mHapticFeedbackIntensity=" + mHapticFeedbackIntensity);
pw.println(" mNotificationIntensity=" + mNotificationIntensity);
pw.println("");
pw.println(" Previous vibrations:");
for (VibrationInfo info : mPreviousVibrations) {
pw.print(" ");
pw.println(info.toString());
}
}
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
if (!mDetectedAtStartup) {
pw.println("Native Common Time service was not detected at startup. " +
"Service is unavailable");
return;
}
synchronized (mLock) {
pw.println("Current Common Time Management Service Config:");
pw.println(String.format(" Native service : %s",
(null == mCTConfig) ? "reconnecting"
: "alive"));
pw.println(String.format(" Bound interface : %s",
(null == mCurIface ? "unbound" : mCurIface)));
pw.println(String.format(" Allow WiFi : %s", ALLOW_WIFI ? "yes" : "no"));
pw.println(String.format(" Allow Auto Disable : %s", AUTO_DISABLE ? "yes" : "no"));
pw.println(String.format(" Server Priority : %d", mEffectivePrio));
pw.println(String.format(" No iface timeout : %d", NO_INTERFACE_TIMEOUT));
}
}
@Override // Binder call
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
final long ident = Binder.clearCallingIdentity();
boolean isDumpProto = false;
for (String arg : args) {
if (arg.equals("--proto")) {
isDumpProto = true;
}
}
try {
if (isDumpProto) {
dumpProto(fd);
} else {
dumpInternal(pw);
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args){
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
pw.println("Current lock settings service state:");
pw.println(String.format("SP Enabled = %b",
mLockPatternUtils.isSyntheticPasswordEnabled()));
List<UserInfo> users = mUserManager.getUsers();
for (int user = 0; user < users.size(); user++) {
final int userId = users.get(user).id;
pw.println(" User " + userId);
synchronized (mSpManager) {
pw.println(String.format(" SP Handle = %x",
getSyntheticPasswordHandleLocked(userId)));
}
try {
pw.println(String.format(" SID = %x",
getGateKeeperService().getSecureUserId(userId)));
} catch (RemoteException e) {
// ignore.
}
}
}
@SuppressWarnings("unused")
@Override
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, fout)) return;
if (!DEBUG) return;
try {
final Printer p = new PrintWriterPrinter(fout);
p.println("CountryDetectorService state:");
p.println(" Number of listeners=" + mReceivers.keySet().size());
if (mCountryDetector == null) {
p.println(" ComprehensiveCountryDetector not initialized");
} else {
p.println(" " + mCountryDetector.toString());
}
} catch (Exception e) {
Slog.e(TAG, "Failed to dump CountryDetectorService: ", e);
}
}
@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) return;
synchronized (sStatsdLock) {
writer.println("Number of configuration files deleted: " + mDeletedFiles.size());
if (mDeletedFiles.size() > 0) {
writer.println(" timestamp, deleted file name");
}
long lastBootMillis =
SystemClock.currentThreadTimeMillis() - SystemClock.elapsedRealtime();
for (Long elapsedMillis : mDeletedFiles.keySet()) {
long deletionMillis = lastBootMillis + elapsedMillis;
writer.println(" " + deletionMillis + ", " + mDeletedFiles.get(elapsedMillis));
}
}
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
pw.println("****** Dump of HardwarePropertiesManagerService ******");
final String PKG = getCallingPackageName();
dumpTempValues(PKG, pw, DEVICE_TEMPERATURE_CPU, "CPU ");
dumpTempValues(PKG, pw, DEVICE_TEMPERATURE_GPU, "GPU ");
dumpTempValues(PKG, pw, DEVICE_TEMPERATURE_BATTERY, "Battery ");
dumpTempValues(PKG, pw, DEVICE_TEMPERATURE_SKIN, "Skin ");
float[] fanSpeeds = getFanSpeeds(PKG);
pw.println("Fan speed: " + Arrays.toString(fanSpeeds) + "\n");
CpuUsageInfo[] cpuUsageInfos = getCpuUsages(PKG);
int core = 0;
for (int i = 0; i < cpuUsageInfos.length; i++) {
pw.println("Cpu usage of core: " + i +
", active = " + cpuUsageInfos[i].getActive() +
", total = " + cpuUsageInfos[i].getTotal());
}
pw.println("****** End of HardwarePropertiesManagerService dump ******");
}
@Override
public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) return;
pw.println("MEDIA SESSION SERVICE (dumpsys media_session)");
pw.println();
synchronized (mLock) {
pw.println(mSessionsListeners.size() + " sessions listeners.");
pw.println("Global priority session is " + mGlobalPrioritySession);
if (mGlobalPrioritySession != null) {
mGlobalPrioritySession.dump(pw, " ");
}
pw.println("User Records:");
int count = mUserRecords.size();
for (int i = 0; i < count; i++) {
mUserRecords.valueAt(i).dumpLocked(pw, "");
}
mAudioPlayerStateMonitor.dump(getContext(), pw, "");
}
}
@Override
public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
pw.println("MEDIA ROUTER SERVICE (dumpsys media_router)");
pw.println();
pw.println("Global state");
pw.println(" mCurrentUserId=" + mCurrentUserId);
synchronized (mLock) {
final int count = mUserRecords.size();
for (int i = 0; i < count; i++) {
UserRecord userRecord = mUserRecords.valueAt(i);
pw.println();
userRecord.dump(pw, "");
}
}
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
pw.println("Dumping ContextHub Service");
pw.println("");
// dump ContextHubInfo
pw.println("=================== CONTEXT HUBS ====================");
for (ContextHubInfo hubInfo : mContextHubIdToInfoMap.values()) {
pw.println(hubInfo);
}
pw.println("");
pw.println("=================== NANOAPPS ====================");
// Dump nanoAppHash
for (NanoAppInstanceInfo info : mNanoAppStateManager.getNanoAppInstanceInfoCollection()) {
pw.println(info);
}
// dump eventLog
}
private ArrayList<ContentProviderRecord> getProvidersForName(String name) {
ArrayList<ContentProviderRecord> allProviders = new ArrayList<ContentProviderRecord>();
final ArrayList<ContentProviderRecord> ret = new ArrayList<>();
final Predicate<ContentProviderRecord> filter = DumpUtils.filterRecord(name);
synchronized (mAm) {
allProviders.addAll(mSingletonByClass.values());
for (int i=0; i<mProvidersByClassPerUser.size(); i++) {
allProviders.addAll(mProvidersByClassPerUser.valueAt(i).values());
}
CollectionUtils.addIf(allProviders, ret, filter);
}
// Sort by component name.
ret.sort(Comparator.comparing(WithComponentName::getComponentName));
return ret;
}
public void dumpLocked(PrintWriter pw) {
pw.println(" " + mName + ":");
pw.println(" mModes=" + Arrays.toString(mModes.toArray()));
pw.println(" mActiveMode=" + mActiveMode);
pw.println(" mGravity=" + mGravity);
pw.println(" mSecure=" + mSecure);
pw.println(" mNumber=" + mNumber);
// Try to dump the window state.
if (mWindow != null) {
final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
ipw.increaseIndent();
DumpUtils.dumpAsync(mUiHandler, mWindow, ipw, "", 200);
}
}
@Override // Binder call
public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
final long token = Binder.clearCallingIdentity();
try {
dumpInternal(pw);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) return;
final long ident = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
if (args == null || args.length == 0 || "-a".equals(args[0])) {
pw.println("Current Dock Observer Service state:");
if (mUpdatesStopped) {
pw.println(" (UPDATES STOPPED -- use 'reset' to restart)");
}
pw.println(" reported state: " + mReportedDockState);
pw.println(" previous state: " + mPreviousDockState);
pw.println(" actual state: " + mActualDockState);
} else if (args.length == 3 && "set".equals(args[0])) {
String key = args[1];
String value = args[2];
try {
if ("state".equals(key)) {
mUpdatesStopped = true;
setDockStateLocked(Integer.parseInt(value));
} else {
pw.println("Unknown set option: " + key);
}
} catch (NumberFormatException ex) {
pw.println("Bad value: " + value);
}
} else if (args.length == 1 && "reset".equals(args[0])) {
mUpdatesStopped = false;
setDockStateLocked(mActualDockState);
} else {
pw.println("Dump current dock state, or:");
pw.println(" set state <value>");
pw.println(" reset");
}
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@Override // Binder call
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
final long ident = Binder.clearCallingIdentity();
try {
if (args.length > 0 && "--proto".equals(args[0])) {
dumpProto(fd);
} else {
dumpInternal(pw);
}
} finally {
Binder.restoreCallingIdentity(ident);
}
}
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
synchronized (mLock) {
pw.println(" mDisabled1=0x" + Integer.toHexString(mDisabled1));
pw.println(" mDisabled2=0x" + Integer.toHexString(mDisabled2));
final int N = mDisableRecords.size();
pw.println(" mDisableRecords.size=" + N);
for (int i=0; i<N; i++) {
DisableRecord tok = mDisableRecords.get(i);
pw.println(" [" + i + "] " + tok);
}
pw.println(" mCurrentUserId=" + mCurrentUserId);
pw.println(" mIcons=");
for (String slot : mIcons.keySet()) {
pw.println(" ");
pw.print(slot);
pw.print(" -> ");
final StatusBarIcon icon = mIcons.get(slot);
pw.print(icon);
if (!TextUtils.isEmpty(icon.contentDescription)) {
pw.print(" \"");
pw.print(icon.contentDescription);
pw.print("\"");
}
pw.println();
}
}
}
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
for (ClientInfo client : mClients.values()) {
pw.println("Client Info");
pw.println(client);
}
mNsdStateMachine.dump(fd, pw, args);
}
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " ");
synchronized (mSearchables) {
for (int i = 0; i < mSearchables.size(); i++) {
ipw.print("\nUser: "); ipw.println(mSearchables.keyAt(i));
ipw.increaseIndent();
mSearchables.valueAt(i).dump(fd, ipw, args);
ipw.decreaseIndent();
}
}
}
@Override
protected void dump(FileDescriptor fd, final PrintWriter writer, String[] args) {
if (!DumpUtils.checkDumpPermission(getContext(), TAG, writer)) return;
final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
pw.println("mHdmiControlEnabled: " + mHdmiControlEnabled);
pw.println("mProhibitMode: " + mProhibitMode);
if (mCecController != null) {
pw.println("mCecController: ");
pw.increaseIndent();
mCecController.dump(pw);
pw.decreaseIndent();
}
pw.println("mMhlController: ");
pw.increaseIndent();
mMhlController.dump(pw);
pw.decreaseIndent();
pw.println("mPortInfo: ");
pw.increaseIndent();
for (HdmiPortInfo hdmiPortInfo : mPortInfo) {
pw.println("- " + hdmiPortInfo);
}
pw.decreaseIndent();
pw.println("mPowerStatus: " + mPowerStatus);
}
@Override // Binder call
public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
final long token = Binder.clearCallingIdentity();
try {
MediaProjectionManagerService.this.dump(pw);
} finally {
Binder.restoreCallingIdentity(token);
}
}
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
pw.print("PollingIntervalMs: ");
TimeUtils.formatDuration(mPollingIntervalMs, pw);
pw.print("\nPollingIntervalShorterMs: ");
TimeUtils.formatDuration(mPollingIntervalShorterMs, pw);
pw.println("\nTryAgainTimesMax: " + mTryAgainTimesMax);
pw.print("TimeErrorThresholdMs: ");
TimeUtils.formatDuration(mTimeErrorThresholdMs, pw);
pw.println("\nTryAgainCounter: " + mTryAgainCounter);
pw.println("NTP cache age: " + mTime.getCacheAge());
pw.println("NTP cache certainty: " + mTime.getCacheCertainty());
pw.println();
}
@Override
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
pw.println("INPUT MANAGER (dumpsys input)\n");
String dumpStr = nativeDump(mPtr);
if (dumpStr != null) {
pw.println(dumpStr);
}
}
@Override // Binder call
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
final long ident = Binder.clearCallingIdentity();
try {
dumpInternal(pw);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@Override protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;
if (args.length > 0 && "--proto".equals(args[0])) {
dumpProto(fd);
} else {
dumpInternal(fd, pw, args);
}
}
@Override
protected void dump(final FileDescriptor fd, final PrintWriter writer, final String[] args) {
if (!DumpUtils.checkDumpPermission(mContext, TAG, writer)) return;
final long token = Binder.clearCallingIdentity();
try {
NetworkScorerAppData currentScorer = mNetworkScorerAppManager.getActiveScorer();
if (currentScorer == null) {
writer.println("Scoring is disabled.");
return;
}
writer.println("Current scorer: " + currentScorer);
sendCacheUpdateCallback(new BiConsumer<INetworkScoreCache, Object>() {
@Override
public void accept(INetworkScoreCache networkScoreCache, Object cookie) {
try {
TransferPipe.dumpAsync(networkScoreCache.asBinder(), fd, args);
} catch (IOException | RemoteException e) {
writer.println("Failed to dump score cache: " + e);
}
}
}, getScoreCacheLists());
synchronized (mServiceConnectionLock) {
if (mServiceConnection != null) {
mServiceConnection.dump(fd, writer, args);
} else {
writer.println("ScoringServiceConnection: null");
}
}
writer.flush();
} finally {
Binder.restoreCallingIdentity(token);
}
}
private boolean enforceDumpPermission(PrintWriter pw) {
if (Build.VERSION.SDK_INT >= O) return DumpUtils.checkDumpPermission(mContext, TAG, pw);
else {
try {
mContext.enforceCallingOrSelfPermission(Manifest.permission.DUMP, "enforceDumpPermission");
return true;
} catch (SecurityException e) {
pw.println(StringUtils.printStackTraceToString(e));
Log.e(TAG, "enforceDumpPermission: ", e);
}
}
return false;
}
@Override
protected synchronized void dump(FileDescriptor fd, PrintWriter pw_, String[] args) {
if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw_)) return;
final IndentingPrintWriter pw = new IndentingPrintWriter(pw_, " ");
final boolean dumpAll = ArrayUtils.contains(args, "-a");
// This makes it so that future permission checks will be in the context of this
// process rather than the caller's process. We will restore this before returning.
final long identityToken = clearCallingIdentity();
try {
if (mSyncManager == null) {
pw.println("No SyncManager created! (Disk full?)");
} else {
mSyncManager.dump(fd, pw, dumpAll);
}
pw.println();
pw.println("Observer tree:");
synchronized (mRootNode) {
int[] counts = new int[2];
final SparseIntArray pidCounts = new SparseIntArray();
mRootNode.dumpLocked(fd, pw, args, "", " ", counts, pidCounts);
pw.println();
ArrayList<Integer> sorted = new ArrayList<Integer>();
for (int i=0; i<pidCounts.size(); i++) {
sorted.add(pidCounts.keyAt(i));
}
Collections.sort(sorted, new Comparator<Integer>() {
@Override
public int compare(Integer lhs, Integer rhs) {
int lc = pidCounts.get(lhs);
int rc = pidCounts.get(rhs);
if (lc < rc) {
return 1;
} else if (lc > rc) {
return -1;
}
return 0;
}
});
for (int i=0; i<sorted.size(); i++) {
int pid = sorted.get(i);
pw.print(" pid "); pw.print(pid); pw.print(": ");
pw.print(pidCounts.get(pid)); pw.println(" observers");
}
pw.println();
pw.print(" Total number of nodes: "); pw.println(counts[0]);
pw.print(" Total number of observers: "); pw.println(counts[1]);
}
synchronized (mCache) {
pw.println();
pw.println("Cached content:");
pw.increaseIndent();
for (int i = 0; i < mCache.size(); i++) {
pw.println("User " + mCache.keyAt(i) + ":");
pw.increaseIndent();
pw.println(mCache.valueAt(i));
pw.decreaseIndent();
}
pw.decreaseIndent();
}
} finally {
restoreCallingIdentity(identityToken);
}
}
@Override
protected synchronized void dump(FileDescriptor fd, PrintWriter pw_, String[] args) {
if (!DumpUtils.checkDumpAndUsageStatsPermission(mContext, TAG, pw_)) return;
final IndentingPrintWriter pw = new IndentingPrintWriter(pw_, " ");
final boolean dumpAll = ArrayUtils.contains(args, "-a");
// This makes it so that future permission checks will be in the context of this
// process rather than the caller's process. We will restore this before returning.
final long identityToken = clearCallingIdentity();
try {
if (mSyncManager == null) {
pw.println("SyncManager not available yet");
} else {
mSyncManager.dump(fd, pw, dumpAll);
}
pw.println();
pw.println("Observer tree:");
synchronized (mRootNode) {
int[] counts = new int[2];
final SparseIntArray pidCounts = new SparseIntArray();
mRootNode.dumpLocked(fd, pw, args, "", " ", counts, pidCounts);
pw.println();
ArrayList<Integer> sorted = new ArrayList<Integer>();
for (int i=0; i<pidCounts.size(); i++) {
sorted.add(pidCounts.keyAt(i));
}
Collections.sort(sorted, new Comparator<Integer>() {
@Override
public int compare(Integer lhs, Integer rhs) {
int lc = pidCounts.get(lhs);
int rc = pidCounts.get(rhs);
if (lc < rc) {
return 1;
} else if (lc > rc) {
return -1;
}
return 0;
}
});
for (int i=0; i<sorted.size(); i++) {
int pid = sorted.get(i);
pw.print(" pid "); pw.print(pid); pw.print(": ");
pw.print(pidCounts.get(pid)); pw.println(" observers");
}
pw.println();
pw.print(" Total number of nodes: "); pw.println(counts[0]);
pw.print(" Total number of observers: "); pw.println(counts[1]);
sObserverDeathDispatcher.dump(pw, " ");
}
synchronized (sObserverLeakDetectedUid) {
pw.println();
pw.print("Observer leaking UIDs: ");
pw.println(sObserverLeakDetectedUid.toString());
}
synchronized (mCache) {
pw.println();
pw.println("Cached content:");
pw.increaseIndent();
for (int i = 0; i < mCache.size(); i++) {
pw.println("User " + mCache.keyAt(i) + ":");
pw.increaseIndent();
pw.println(mCache.valueAt(i));
pw.decreaseIndent();
}
pw.decreaseIndent();
}
} finally {
restoreCallingIdentity(identityToken);
}
}