CarService dump() improvements:
- Use IndentingPrintWriter by default
- dump() PerUserCarServiceHelper
- Replaced some string concatenations by printf()
- Dump isLocationEnabled()
Test: adb shell dumpsys activity service com.android.car/.PerUserCarService
Test: adb shell dumpsys car_service --services CarBluetoothService
Test: m ExperimentalCarService
Test: atest GarageModeServiceTest CarStatsServiceTest
Bug: 143815470
Bug: 178040439
Change-Id: I4c863e6f287aa0a6794dc0854d866647ed9fb671
diff --git a/experimental/service/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureService.java b/experimental/service/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureService.java
index 6b6a05c..a2d5264 100644
--- a/experimental/service/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureService.java
+++ b/experimental/service/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureService.java
@@ -44,6 +44,7 @@
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.UserHandle;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Pair;
@@ -52,7 +53,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Comparator;
@@ -311,7 +311,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*DriverDistractionExperimentalFeatureService*");
mDistractionClients.dump(writer, "Distraction Clients ");
writer.println("Prioritized Driver Awareness Suppliers (highest to lowest priority):");
diff --git a/experimental/service/src/com/android/experimentalcar/IExperimentalCarImpl.java b/experimental/service/src/com/android/experimentalcar/IExperimentalCarImpl.java
index 905b268..eb2211c 100644
--- a/experimental/service/src/com/android/experimentalcar/IExperimentalCarImpl.java
+++ b/experimental/service/src/com/android/experimentalcar/IExperimentalCarImpl.java
@@ -31,6 +31,7 @@
import android.os.Looper;
import android.os.Process;
import android.os.RemoteException;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import com.android.car.CarServiceBase;
@@ -145,18 +146,23 @@
/** dump */
public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
- ArrayList<CarServiceBase> services;
- synchronized (mLock) {
- writer.println("mReleased:" + mReleased);
- writer.println("ALL_AVAILABLE_FEATURES:" + ALL_AVAILABLE_FEATURES);
- services = new ArrayList<>(mRunningServices);
- }
- writer.println(" Number of running services:" + services.size());
- int i = 0;
- for (CarServiceBase service : services) {
- writer.print(i + ":");
- service.dump(writer);
- i++;
+ try (IndentingPrintWriter pw = new IndentingPrintWriter(writer)) {
+ ArrayList<CarServiceBase> services;
+ synchronized (mLock) {
+ pw.printf("mReleased: %b\n", mReleased);
+ pw.printf("ALL_AVAILABLE_FEATURES: %s\n", ALL_AVAILABLE_FEATURES);
+ services = new ArrayList<>(mRunningServices);
+ }
+ pw.printf(" Number of running services: %d\n", services.size());
+ int i = 0;
+
+ for (CarServiceBase service : services) {
+ writer.printf("%d:\n", i);
+ pw.increaseIndent();
+ service.dump(pw);
+ pw.decreaseIndent();
+ i++;
+ }
}
}
diff --git a/experimental/service/src/com/android/experimentalcar/TestDemoExperimentalFeatureService.java b/experimental/service/src/com/android/experimentalcar/TestDemoExperimentalFeatureService.java
index 1309dd2..5a9637b 100644
--- a/experimental/service/src/com/android/experimentalcar/TestDemoExperimentalFeatureService.java
+++ b/experimental/service/src/com/android/experimentalcar/TestDemoExperimentalFeatureService.java
@@ -17,11 +17,10 @@
package com.android.experimentalcar;
import android.car.experimental.ITestDemoExperimental;
+import android.util.IndentingPrintWriter;
import com.android.car.CarServiceBase;
-import java.io.PrintWriter;
-
/**
* Demo service for testing experimental feature.
*/
@@ -39,7 +38,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*TestExperimentalFeatureService*");
}
diff --git a/service/src/com/android/car/AppFocusService.java b/service/src/com/android/car/AppFocusService.java
index 897e939..764c70c 100644
--- a/service/src/com/android/car/AppFocusService.java
+++ b/service/src/com/android/car/AppFocusService.java
@@ -27,13 +27,13 @@
import android.os.Message;
import android.os.RemoteException;
import android.util.ArraySet;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
@@ -262,7 +262,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("**AppFocusService**");
synchronized (mLock) {
writer.println("mActiveAppTypes:" + mActiveAppTypes);
diff --git a/service/src/com/android/car/CarBluetoothService.java b/service/src/com/android/car/CarBluetoothService.java
index 71ec781..f4ff9fb 100644
--- a/service/src/com/android/car/CarBluetoothService.java
+++ b/service/src/com/android/car/CarBluetoothService.java
@@ -26,13 +26,13 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -493,29 +493,34 @@
* Print out the verbose debug status of this object
*/
@Override
- public void dump(PrintWriter writer) {
- writer.println("*" + TAG + "*");
+ public void dump(IndentingPrintWriter writer) {
+ writer.printf("* %s *\n", TAG);
+ mUserServiceHelper.dump(writer);
+
synchronized (mPerUserLock) {
- writer.println("\tUser ID: " + mUserId);
- writer.println("\tUser Proxies: " + (mCarBluetoothUserService != null ? "Yes" : "No"));
+ writer.printf("User ID: %d\n", mUserId);
+ writer.printf("User Proxies: %s\n", (mCarBluetoothUserService != null ? "Yes" : "No"));
// Profile Device Manager statuses
for (int i = 0; i < mProfileDeviceManagers.size(); i++) {
int key = mProfileDeviceManagers.keyAt(i);
BluetoothProfileDeviceManager deviceManager =
(BluetoothProfileDeviceManager) mProfileDeviceManagers.get(key);
+ // TODO(b/178040439): use IndentingPrintWriter
deviceManager.dump(writer, "\t");
}
// Profile Inhibits
+ // TODO(b/TBD): use IndentingPrintWriter
if (mInhibitManager != null) mInhibitManager.dump(writer, "\t");
- else writer.println("\tBluetoothProfileInhibitManager: null");
+ else writer.println("BluetoothProfileInhibitManager: null");
// Device Connection Policy
- writer.println("\tUsing default policy? " + (mUseDefaultPolicy ? "Yes" : "No"));
+ writer.printf("Using default policy? %s\n", (mUseDefaultPolicy ? "Yes" : "No"));
if (mBluetoothDeviceConnectionPolicy == null) {
- writer.println("\tBluetoothDeviceConnectionPolicy: null");
+ writer.println("BluetoothDeviceConnectionPolicy: null");
} else {
+ // TODO(b/178040439): use IndentingPrintWriter
mBluetoothDeviceConnectionPolicy.dump(writer, "\t");
}
}
diff --git a/service/src/com/android/car/CarBugreportManagerService.java b/service/src/com/android/car/CarBugreportManagerService.java
index 9251a8d..470274c 100644
--- a/service/src/com/android/car/CarBugreportManagerService.java
+++ b/service/src/com/android/car/CarBugreportManagerService.java
@@ -38,6 +38,7 @@
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
@@ -49,7 +50,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.io.PrintWriter;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -332,7 +332,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
// TODO(sgurun) implement
}
diff --git a/service/src/com/android/car/CarDiagnosticService.java b/service/src/com/android/car/CarDiagnosticService.java
index da21b54..f532d65 100644
--- a/service/src/com/android/car/CarDiagnosticService.java
+++ b/service/src/com/android/car/CarDiagnosticService.java
@@ -27,6 +27,7 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.util.ArrayMap;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.car.Listeners.ClientWithRate;
@@ -35,7 +36,6 @@
import com.android.car.internal.CarPermission;
import com.android.internal.annotations.GuardedBy;
-import java.io.PrintWriter;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
@@ -664,7 +664,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*CarDiagnosticService*");
writer.println("**last events for diagnostics**");
if (null != mLiveFrameDiagnosticRecord.getLastEvent()) {
diff --git a/service/src/com/android/car/CarDrivingStateService.java b/service/src/com/android/car/CarDrivingStateService.java
index 356f58a..97b9b05 100644
--- a/service/src/com/android/car/CarDrivingStateService.java
+++ b/service/src/com/android/car/CarDrivingStateService.java
@@ -35,12 +35,12 @@
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.SystemClock;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.List;
@@ -247,7 +247,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*CarDrivingStateService*");
mDrivingStateClients.dump(writer, "Driving State Clients ");
writer.println("Driving state change log:");
diff --git a/service/src/com/android/car/CarExperimentalFeatureServiceController.java b/service/src/com/android/car/CarExperimentalFeatureServiceController.java
index 263c65a..8920088 100644
--- a/service/src/com/android/car/CarExperimentalFeatureServiceController.java
+++ b/service/src/com/android/car/CarExperimentalFeatureServiceController.java
@@ -27,12 +27,12 @@
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.ArrayMap;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
@@ -185,7 +185,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*CarExperimentalFeatureServiceController*");
synchronized (mLock) {
diff --git a/service/src/com/android/car/CarFeatureController.java b/service/src/com/android/car/CarFeatureController.java
index 5e0cd61..b505ea8 100644
--- a/service/src/com/android/car/CarFeatureController.java
+++ b/service/src/com/android/car/CarFeatureController.java
@@ -25,6 +25,7 @@
import android.os.Handler;
import android.os.HandlerThread;
import android.util.AtomicFile;
+import android.util.IndentingPrintWriter;
import android.util.Pair;
import android.util.Slog;
@@ -40,7 +41,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
@@ -178,7 +178,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*CarFeatureController*");
writer.println(" mEnabledFeatures:" + mEnabledFeatures);
writer.println(" mDefaultEnabledFeaturesFromConfig:" + mDefaultEnabledFeaturesFromConfig);
diff --git a/service/src/com/android/car/CarInputService.java b/service/src/com/android/car/CarInputService.java
index 5d2082b..824e2e2 100644
--- a/service/src/com/android/car/CarInputService.java
+++ b/service/src/com/android/car/CarInputService.java
@@ -49,6 +49,7 @@
import android.provider.Settings;
import android.telecom.TelecomManager;
import android.text.TextUtils;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import android.view.Display;
import android.view.InputDevice;
@@ -63,7 +64,6 @@
import com.android.internal.app.AssistUtils;
import com.android.internal.app.IVoiceInteractionSessionShowCallback;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
@@ -686,7 +686,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*Input Service*");
writer.println("Long-press delay: " + mLongPressDelaySupplier.getAsInt() + "ms");
writer.println("Call button ends ongoing call: "
diff --git a/service/src/com/android/car/CarLocationService.java b/service/src/com/android/car/CarLocationService.java
index 4306ab4..0ccf63b 100644
--- a/service/src/com/android/car/CarLocationService.java
+++ b/service/src/com/android/car/CarLocationService.java
@@ -37,6 +37,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.util.AtomicFile;
+import android.util.IndentingPrintWriter;
import android.util.JsonReader;
import android.util.JsonWriter;
import android.util.Slog;
@@ -51,7 +52,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
import java.util.concurrent.CompletableFuture;
/**
@@ -208,10 +208,11 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println(TAG);
- writer.println("Context: " + mContext);
- writer.println("MAX_LOCATION_INJECTION_ATTEMPTS: " + MAX_LOCATION_INJECTION_ATTEMPTS);
+ mPerUserCarServiceHelper.dump(writer);
+ writer.printf("Context: %s\n", mContext);
+ writer.printf("MAX_LOCATION_INJECTION_ATTEMPTS: %d\n", MAX_LOCATION_INJECTION_ATTEMPTS);
}
@Override
diff --git a/service/src/com/android/car/CarMediaService.java b/service/src/com/android/car/CarMediaService.java
index adbb4ca..e6b58ce 100644
--- a/service/src/com/android/car/CarMediaService.java
+++ b/service/src/com/android/car/CarMediaService.java
@@ -55,6 +55,7 @@
import android.os.UserManager;
import android.service.media.MediaBrowserService;
import android.text.TextUtils;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
@@ -63,7 +64,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
@@ -397,7 +397,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
synchronized (mLock) {
writer.println("*CarMediaService*");
writer.println("\tCurrent playback media component: "
diff --git a/service/src/com/android/car/CarNightService.java b/service/src/com/android/car/CarNightService.java
index 5910997..c654baa 100644
--- a/service/src/com/android/car/CarNightService.java
+++ b/service/src/com/android/car/CarNightService.java
@@ -24,11 +24,11 @@
import android.content.Context;
import android.hardware.automotive.vehicle.V2_0.VehicleProperty;
import android.os.RemoteException;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
-import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
@@ -187,7 +187,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
synchronized (mLock) {
writer.println("*DAY NIGHT POLICY*");
writer.println(
diff --git a/service/src/com/android/car/CarOccupantZoneService.java b/service/src/com/android/car/CarOccupantZoneService.java
index f267be2..c9726fe 100644
--- a/service/src/com/android/car/CarOccupantZoneService.java
+++ b/service/src/com/android/car/CarOccupantZoneService.java
@@ -46,6 +46,7 @@
import android.os.UserManager;
import android.util.ArrayMap;
import android.util.ArraySet;
+import android.util.IndentingPrintWriter;
import android.util.IntArray;
import android.util.Log;
import android.util.Slog;
@@ -59,7 +60,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -389,7 +389,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*OccupantZoneService*");
synchronized (mLock) {
writer.println("**mOccupantsConfig**");
diff --git a/service/src/com/android/car/CarProjectionService.java b/service/src/com/android/car/CarProjectionService.java
index 0fcd0db..79d1484 100644
--- a/service/src/com/android/car/CarProjectionService.java
+++ b/service/src/com/android/car/CarProjectionService.java
@@ -64,13 +64,13 @@
import android.os.RemoteException;
import android.os.UserHandle;
import android.text.TextUtils;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.car.BinderInterfaceContainer.BinderInterface;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
-import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.net.NetworkInterface;
import java.net.SocketException;
@@ -788,7 +788,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("**CarProjectionService**");
synchronized (mLock) {
writer.println("Registered key event handlers:");
diff --git a/service/src/com/android/car/CarPropertyService.java b/service/src/com/android/car/CarPropertyService.java
index 83c25a9..39c416e 100644
--- a/service/src/com/android/car/CarPropertyService.java
+++ b/service/src/com/android/car/CarPropertyService.java
@@ -29,6 +29,7 @@
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.RemoteException;
+import android.util.IndentingPrintWriter;
import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
@@ -36,7 +37,6 @@
import com.android.car.hal.PropertyHalService;
import com.android.internal.annotations.GuardedBy;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -171,7 +171,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*CarPropertyService*");
synchronized (mLock) {
writer.println(" Listener is set for PropertyHalService: " + mListenerIsSet);
diff --git a/service/src/com/android/car/CarServiceBase.java b/service/src/com/android/car/CarServiceBase.java
index c4b578d..ec5d297 100644
--- a/service/src/com/android/car/CarServiceBase.java
+++ b/service/src/com/android/car/CarServiceBase.java
@@ -16,7 +16,7 @@
package com.android.car;
-import java.io.PrintWriter;
+import android.util.IndentingPrintWriter;
/**
* Base class for all Car specific services.
@@ -35,5 +35,6 @@
/** Called when connection to Vehicle HAL was restored. */
default void vehicleHalReconnected() {}
- void dump(PrintWriter writer);
+ /** Dumps its state. */
+ void dump(IndentingPrintWriter writer);
}
diff --git a/service/src/com/android/car/CarShellCommand.java b/service/src/com/android/car/CarShellCommand.java
index 37e7df9..36ffda0 100644
--- a/service/src/com/android/car/CarShellCommand.java
+++ b/service/src/com/android/car/CarShellCommand.java
@@ -78,6 +78,7 @@
import android.os.UserManager;
import android.text.TextUtils;
import android.util.ArrayMap;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import android.util.SparseArray;
import android.view.KeyEvent;
@@ -94,7 +95,6 @@
import com.android.car.systeminterface.SystemInterface;
import com.android.car.user.CarUserService;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -337,15 +337,19 @@
} while (arg != null);
String[] args = new String[argsList.size()];
argsList.toArray(args);
- return exec(args, getOutPrintWriter());
+ try (IndentingPrintWriter pw = new IndentingPrintWriter(getOutPrintWriter())) {
+ return exec(args, pw);
+ }
}
@Override
public void onHelp() {
- showHelp(getOutPrintWriter());
+ try (IndentingPrintWriter pw = new IndentingPrintWriter(getOutPrintWriter())) {
+ showHelp(pw);
+ }
}
- private static void showHelp(PrintWriter pw) {
+ private static void showHelp(IndentingPrintWriter pw) {
pw.println("Car service commands:");
pw.println("\t-h");
pw.println("\t Print this help text.");
@@ -487,7 +491,7 @@
pw.println("\t Powers off the car.");
}
- private static int showInvalidArguments(PrintWriter pw) {
+ private static int showInvalidArguments(IndentingPrintWriter pw) {
pw.println("Incorrect number of arguments.");
showHelp(pw);
return RESULT_ERROR;
@@ -531,7 +535,7 @@
+ Arrays.toString(requiredPermissions));
}
- int exec(String[] args, PrintWriter writer) {
+ int exec(String[] args, IndentingPrintWriter writer) {
String cmd = args[0];
String[] requiredPermissions = USER_BUILD_COMMAND_TO_PERMISSIONS_MAP.get(cmd);
if (requiredPermissions == null) {
@@ -767,7 +771,7 @@
return RESULT_OK;
}
- private void startFixedActivity(String[] args, PrintWriter writer) {
+ private void startFixedActivity(String[] args, IndentingPrintWriter writer) {
if (args.length != 4) {
writer.println("Incorrect number of arguments");
showHelp(writer);
@@ -795,7 +799,7 @@
writer.println("Succeeded");
}
- private void stopFixedMode(String[] args, PrintWriter writer) {
+ private void stopFixedMode(String[] args, IndentingPrintWriter writer) {
if (args.length != 2) {
writer.println("Incorrect number of arguments");
showHelp(writer);
@@ -811,7 +815,7 @@
mFixedActivityService.stopFixedActivityMode(displayId);
}
- private void enableDisableFeature(String[] args, PrintWriter writer, boolean enable) {
+ private void enableDisableFeature(String[] args, IndentingPrintWriter writer, boolean enable) {
if (Binder.getCallingUid() != Process.ROOT_UID) {
writer.println("Only allowed to root/su");
return;
@@ -853,7 +857,7 @@
Binder.restoreCallingIdentity(id);
}
- private void injectKey(String[] args, PrintWriter writer) {
+ private void injectKey(String[] args, IndentingPrintWriter writer) {
int i = 1; // 0 is command itself
int display = CarOccupantZoneManager.DISPLAY_TYPE_MAIN;
int delayMs = 0;
@@ -923,7 +927,7 @@
mCarInputService.onKeyEvent(new KeyEvent(action, keyCode), display);
}
- private void injectRotary(String[] args, PrintWriter writer) {
+ private void injectRotary(String[] args, IndentingPrintWriter writer) {
int i = 1; // 0 is command itself
int display = CarOccupantZoneManager.DISPLAY_TYPE_MAIN;
int inputType = CarInputManager.INPUT_TYPE_ROTARY_NAVIGATION;
@@ -991,7 +995,7 @@
writer.println("Succeeded in injecting: " + rotaryEvent);
}
- private void injectCustomInputEvent(String[] args, PrintWriter writer) {
+ private void injectCustomInputEvent(String[] args, IndentingPrintWriter writer) {
int display = CarOccupantZoneManager.DISPLAY_TYPE_MAIN;
int repeatCounter = 1;
@@ -1036,7 +1040,7 @@
writer.printf("Succeeded in injecting {%s}\n", event);
}
- private boolean checkVehicleDisplay(int vehicleDisplay, PrintWriter writer) {
+ private boolean checkVehicleDisplay(int vehicleDisplay, IndentingPrintWriter writer) {
if (vehicleDisplay != VehicleDisplay.MAIN
&& vehicleDisplay != VehicleDisplay.INSTRUMENT_CLUSTER) {
writer.println("Invalid display:" + vehicleDisplay);
@@ -1046,7 +1050,7 @@
return true;
}
- private void getInitialUserInfo(String[] args, PrintWriter writer) {
+ private void getInitialUserInfo(String[] args, IndentingPrintWriter writer) {
if (args.length < 2) {
writer.println("Insufficient number of args");
return;
@@ -1115,7 +1119,8 @@
return UserHalHelper.getFlags(UserManager.get(mContext), userId);
}
- private static void waitForHal(PrintWriter writer, CountDownLatch latch, int timeoutMs) {
+ private static void waitForHal(IndentingPrintWriter writer, CountDownLatch latch,
+ int timeoutMs) {
try {
if (!latch.await(timeoutMs, TimeUnit.MILLISECONDS)) {
writer.printf("HAL didn't respond in %dms\n", timeoutMs);
@@ -1127,7 +1132,7 @@
return;
}
- private void switchUser(String[] args, PrintWriter writer) {
+ private void switchUser(String[] args, IndentingPrintWriter writer) {
if (args.length < 2) {
writer.println("Insufficient number of args");
return;
@@ -1208,7 +1213,7 @@
writer.println();
}
- private void createUser(String[] args, PrintWriter writer) {
+ private void createUser(String[] args, IndentingPrintWriter writer) {
int timeout = DEFAULT_HAL_TIMEOUT_MS;
int flags = 0;
boolean halOnly = false;
@@ -1315,7 +1320,7 @@
}
}
- private void removeUser(String[] args, PrintWriter writer) {
+ private void removeUser(String[] args, IndentingPrintWriter writer) {
if (args.length < 2) {
writer.println("Insufficient number of args");
return;
@@ -1360,7 +1365,7 @@
UserRemovalResult.statusToString(result.getStatus()));
}
- private static <T> T waitForFuture(@NonNull PrintWriter writer,
+ private static <T> T waitForFuture(@NonNull IndentingPrintWriter writer,
@NonNull AsyncFuture<T> future, int timeoutMs) {
T result = null;
try {
@@ -1376,12 +1381,12 @@
return result;
}
- private void getInitialUser(PrintWriter writer) {
+ private void getInitialUser(IndentingPrintWriter writer) {
android.content.pm.UserInfo user = mCarUserService.getInitialUser();
writer.println(user == null ? NO_INITIAL_USER : user.id);
}
- private void getUserAuthAssociation(String[] args, PrintWriter writer) {
+ private void getUserAuthAssociation(String[] args, IndentingPrintWriter writer) {
if (args.length < 2) {
writer.println("invalid usage, must pass at least 1 argument");
return;
@@ -1443,7 +1448,8 @@
showResponse(writer, response);
}
- private CarUserManager getCarUserManager(@NonNull PrintWriter writer, @UserIdInt int userId) {
+ private CarUserManager getCarUserManager(@NonNull IndentingPrintWriter writer,
+ @UserIdInt int userId) {
Context context;
if (userId == mContext.getUserId()) {
context = mContext;
@@ -1465,7 +1471,7 @@
return carUserManager;
}
- private void showResponse(@NonNull PrintWriter writer,
+ private void showResponse(@NonNull IndentingPrintWriter writer,
@NonNull UserIdentificationResponse response) {
if (response == null) {
writer.println("null response");
@@ -1483,7 +1489,7 @@
}
}
- private void showResponse(@NonNull PrintWriter writer,
+ private void showResponse(@NonNull IndentingPrintWriter writer,
@NonNull UserIdentificationAssociationResponse response) {
if (response == null) {
writer.println("null response");
@@ -1508,7 +1514,7 @@
}
}
- private void setUserAuthAssociation(String[] args, PrintWriter writer) {
+ private void setUserAuthAssociation(String[] args, IndentingPrintWriter writer) {
if (args.length < 3) {
writer.println("invalid usage, must pass at least 4 arguments");
return;
@@ -1603,7 +1609,7 @@
return INVALID_USER_AUTH_TYPE_OR_VALUE;
}
- private void forceDayNightMode(String arg, PrintWriter writer) {
+ private void forceDayNightMode(String arg, IndentingPrintWriter writer) {
int mode;
switch (arg) {
case PARAM_DAY_MODE:
@@ -1636,7 +1642,7 @@
writer.println("DayNightMode changed to: " + currentMode);
}
- private void forceGarageMode(String arg, PrintWriter writer) {
+ private void forceGarageMode(String arg, IndentingPrintWriter writer) {
switch (arg) {
case PARAM_ON_MODE:
mSystemInterface.setDisplayState(false);
@@ -1661,7 +1667,7 @@
}
}
- private void runSilentCommand(String arg, PrintWriter writer) {
+ private void runSilentCommand(String arg, IndentingPrintWriter writer) {
switch (arg) {
case "forced-silent":
writer.println("Forcing silent mode to silent");
@@ -1686,7 +1692,7 @@
}
}
- private void emulateDrivingState(String[] args, PrintWriter writer) {
+ private void emulateDrivingState(String[] args, IndentingPrintWriter writer) {
if (args.length != 2) {
writer.println("invalid usage, must pass driving state");
return;
@@ -1748,7 +1754,7 @@
/* zone= */ "0", Integer.toString(VehicleGear.GEAR_PARK), /* delayTime= */ "0");
}
- private void powerOff(String[] args, PrintWriter writer) {
+ private void powerOff(String[] args, IndentingPrintWriter writer) {
int index = 1;
boolean skipGarageMode = false;
boolean shutdown = false;
@@ -1777,10 +1783,10 @@
* @param isErrorEvent indicates the type of event
* @param value Data value of the event
* @param delayTime the event timestamp is increased by delayTime
- * @param writer PrintWriter
+ * @param writer IndentingPrintWriter
*/
private void injectVhalEvent(String property, String zone, String value,
- boolean isErrorEvent, String delayTime, PrintWriter writer) {
+ boolean isErrorEvent, String delayTime, IndentingPrintWriter writer) {
Slog.i(TAG, "Injecting VHAL event: prop=" + property + ", zone=" + zone + ", value="
+ value + ", isError=" + isErrorEvent
+ (TextUtils.isEmpty(delayTime) ? "" : ", delayTime=" + delayTime));
diff --git a/service/src/com/android/car/CarStorageMonitoringService.java b/service/src/com/android/car/CarStorageMonitoringService.java
index ae32d9e..0149f86 100644
--- a/service/src/com/android/car/CarStorageMonitoringService.java
+++ b/service/src/com/android/car/CarStorageMonitoringService.java
@@ -34,6 +34,7 @@
import android.content.res.Resources;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
+import android.util.IndentingPrintWriter;
import android.util.JsonWriter;
import android.util.Log;
import android.util.Slog;
@@ -56,7 +57,6 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.PrintWriter;
import java.nio.file.Files;
import java.time.Duration;
import java.time.Instant;
@@ -503,7 +503,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*CarStorageMonitoringService*");
synchronized (mLock) {
doInitServiceIfNeededLocked();
diff --git a/service/src/com/android/car/CarTestService.java b/service/src/com/android/car/CarTestService.java
index ad65121..123afb9 100644
--- a/service/src/com/android/car/CarTestService.java
+++ b/service/src/com/android/car/CarTestService.java
@@ -20,11 +20,11 @@
import android.content.Context;
import android.os.IBinder;
import android.os.RemoteException;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
-import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -64,7 +64,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*CarTestService*");
writer.println(" mTokens:" + Arrays.toString(mTokens.entrySet().toArray()));
}
diff --git a/service/src/com/android/car/CarUxRestrictionsManagerService.java b/service/src/com/android/car/CarUxRestrictionsManagerService.java
index 844477d..1604ca9 100644
--- a/service/src/com/android/car/CarUxRestrictionsManagerService.java
+++ b/service/src/com/android/car/CarUxRestrictionsManagerService.java
@@ -54,6 +54,7 @@
import android.os.SystemClock;
import android.util.ArraySet;
import android.util.AtomicFile;
+import android.util.IndentingPrintWriter;
import android.util.JsonReader;
import android.util.JsonToken;
import android.util.JsonWriter;
@@ -74,7 +75,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.charset.StandardCharsets;
@@ -686,7 +686,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
synchronized (mLock) {
writer.println("*CarUxRestrictionsManagerService*");
mUxRClients.dump(writer, "UX Restrictions Clients ");
diff --git a/service/src/com/android/car/ICarImpl.java b/service/src/com/android/car/ICarImpl.java
index 83e744e..202e13f 100644
--- a/service/src/com/android/car/ICarImpl.java
+++ b/service/src/com/android/car/ICarImpl.java
@@ -44,6 +44,7 @@
import android.os.Trace;
import android.os.UserManager;
import android.util.EventLog;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import android.util.TimingsTraceLog;
@@ -646,6 +647,12 @@
return;
}
+ try (IndentingPrintWriter pw = new IndentingPrintWriter(writer)) {
+ dumpIndenting(fd, pw, args);
+ }
+ }
+
+ private void dumpIndenting(FileDescriptor fd, IndentingPrintWriter writer, String[] args) {
if (args == null || args.length == 0 || (args.length > 0 && "-a".equals(args[0]))) {
writer.println("*Dump car service*");
dumpAllServices(writer);
@@ -666,7 +673,7 @@
} else if ("--metrics".equals(args[0])) {
// Strip the --metrics flag when passing dumpsys arguments to CarStatsService
// allowing for nested flag selection
- mCarStatsService.dump(fd, writer, Arrays.copyOfRange(args, 1, args.length));
+ mCarStatsService.dump(writer, Arrays.copyOfRange(args, 1, args.length));
} else if ("--vms-hal".equals(args[0])) {
mHal.getVmsHal().dumpMetrics(fd);
} else if ("--hal".equals(args[0])) {
@@ -689,7 +696,7 @@
}
}
- private void dumpAllHals(PrintWriter writer) {
+ private void dumpAllHals(IndentingPrintWriter writer) {
writer.println("*Dump Vehicle HAL*");
writer.println("Vehicle HAL Interface: " + mVehicleInterfaceName);
try {
@@ -701,7 +708,7 @@
}
}
- private void showDumpHelp(PrintWriter writer) {
+ private void showDumpHelp(IndentingPrintWriter writer) {
writer.println("Car service dump usage:");
writer.println("[NO ARG]");
writer.println("\t dumps everything (all services and HALs)");
@@ -745,13 +752,13 @@
mSilentModeController);
}
- private void dumpListOfServices(PrintWriter writer) {
+ private void dumpListOfServices(IndentingPrintWriter writer) {
for (CarServiceBase service : mAllServices) {
writer.println(service.getClass().getName());
}
}
- private void dumpAllServices(PrintWriter writer) {
+ private void dumpAllServices(IndentingPrintWriter writer) {
writer.println("*Dump all services*");
for (CarServiceBase service : mAllServices) {
dumpService(service, writer);
@@ -761,9 +768,9 @@
}
}
- private void dumpIndividualServices(PrintWriter writer, String... serviceNames) {
+ private void dumpIndividualServices(IndentingPrintWriter writer, String... serviceNames) {
for (String serviceName : serviceNames) {
- writer.println("** Dumping " + serviceName + "\n");
+ writer.printf("** Dumping %s\n\n", serviceName);
CarServiceBase service = getCarServiceBySubstring(serviceName);
if (service == null) {
writer.println("No such service!");
@@ -781,7 +788,7 @@
.findFirst().orElse(null);
}
- private void dumpService(CarServiceBase service, PrintWriter writer) {
+ private void dumpService(CarServiceBase service, IndentingPrintWriter writer) {
try {
service.dump(writer);
} catch (Exception e) {
@@ -790,7 +797,7 @@
}
}
- void execShellCmd(String[] args, PrintWriter writer) {
+ void execShellCmd(String[] args, IndentingPrintWriter writer) {
newCarShellCommand().exec(args, writer);
}
diff --git a/service/src/com/android/car/LocationManagerProxy.java b/service/src/com/android/car/LocationManagerProxy.java
index 132da52..e661244 100644
--- a/service/src/com/android/car/LocationManagerProxy.java
+++ b/service/src/com/android/car/LocationManagerProxy.java
@@ -21,13 +21,14 @@
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
-import android.util.Log;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
/** Wraps a {@link LocationManager}. */
public class LocationManagerProxy extends ILocationManagerProxy.Stub {
- private static final String TAG = "LocationManagerProxy";
- private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
+
+ private static final String TAG = LocationManagerProxy.class.getSimpleName();
+ private static final boolean DBG = false;
private final LocationManager mLocationManager;
@@ -58,4 +59,8 @@
}
return mLocationManager.getLastKnownLocation(provider);
}
+
+ void dump(IndentingPrintWriter pw) {
+ pw.printf("isLocationEnabled: %b\n", isLocationEnabled());
+ }
}
diff --git a/service/src/com/android/car/OccupantAwarenessService.java b/service/src/com/android/car/OccupantAwarenessService.java
index 13104b4..aeb12eb 100644
--- a/service/src/com/android/car/OccupantAwarenessService.java
+++ b/service/src/com/android/car/OccupantAwarenessService.java
@@ -29,12 +29,12 @@
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.os.ServiceManager;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.lang.ref.WeakReference;
/**
@@ -124,7 +124,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*OccupantAwarenessService*");
writer.println(
String.format(
diff --git a/service/src/com/android/car/PerUserCarService.java b/service/src/com/android/car/PerUserCarService.java
index b58c9f3..da89a09 100644
--- a/service/src/com/android/car/PerUserCarService.java
+++ b/service/src/com/android/car/PerUserCarService.java
@@ -113,6 +113,13 @@
} else {
pw.println("PerUserCarDevicePolicyService not needed");
}
+ pw.println();
+
+ pw.println("LocationManagerProxy");
+ pw.increaseIndent();
+ mLocationManagerProxy.dump(pw);
+ pw.decreaseIndent();
+ pw.println();
}
}
diff --git a/service/src/com/android/car/PerUserCarServiceHelper.java b/service/src/com/android/car/PerUserCarServiceHelper.java
index 30877ba..05c6d1f 100644
--- a/service/src/com/android/car/PerUserCarServiceHelper.java
+++ b/service/src/com/android/car/PerUserCarServiceHelper.java
@@ -25,12 +25,12 @@
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.UserHandle;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.car.user.CarUserService;
import com.android.internal.annotations.GuardedBy;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
@@ -41,17 +41,18 @@
*
*/
public class PerUserCarServiceHelper implements CarServiceBase {
+
private static final String TAG = "PerUserCarSvcHelper";
private static boolean DBG = false;
+
private final Context mContext;
private final CarUserService mUserService;
private IPerUserCarService mPerUserCarService;
// listener to call on a ServiceConnection to PerUserCarService
private List<ServiceCallback> mServiceCallbacks;
- private static final String EXTRA_USER_HANDLE = "android.intent.extra.user_handle";
private final Object mServiceBindLock = new Object();
@GuardedBy("mServiceBindLock")
- private boolean mBound = false;
+ private boolean mBound;
public PerUserCarServiceHelper(Context context, CarUserService userService) {
mContext = context;
@@ -236,7 +237,18 @@
}
@Override
- public synchronized void dump(PrintWriter writer) {
-
+ public final void dump(IndentingPrintWriter pw) {
+ pw.println("PerUserCarServiceHelper");
+ pw.increaseIndent();
+ synchronized (mServiceBindLock) {
+ pw.printf("bound: %b\n", mBound);
+ if (mServiceCallbacks == null) {
+ pw.println("no callbacks");
+ } else {
+ int size = mServiceCallbacks.size();
+ pw.printf("%d callback%s\n", size, (size > 1 ? "s" : ""));
+ }
+ }
+ pw.decreaseIndent();
}
}
diff --git a/service/src/com/android/car/SystemActivityMonitoringService.java b/service/src/com/android/car/SystemActivityMonitoringService.java
index 514748e..897fde3 100644
--- a/service/src/com/android/car/SystemActivityMonitoringService.java
+++ b/service/src/com/android/car/SystemActivityMonitoringService.java
@@ -34,6 +34,7 @@
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
@@ -42,7 +43,6 @@
import com.android.internal.annotations.GuardedBy;
-import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.LinkedList;
@@ -155,7 +155,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*SystemActivityMonitoringService*");
writer.println(" Top Tasks per display:");
synchronized (mLock) {
diff --git a/service/src/com/android/car/SystemStateControllerService.java b/service/src/com/android/car/SystemStateControllerService.java
index c15ab6d..04c1c07 100644
--- a/service/src/com/android/car/SystemStateControllerService.java
+++ b/service/src/com/android/car/SystemStateControllerService.java
@@ -17,11 +17,10 @@
import android.content.Context;
import android.content.res.Resources;
+import android.util.IndentingPrintWriter;
import com.android.car.audio.CarAudioService;
-import java.io.PrintWriter;
-
public class SystemStateControllerService implements CarServiceBase {
private final CarAudioService mCarAudioService;
private final ICarImpl mICarImpl;
@@ -44,6 +43,6 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
}
}
diff --git a/service/src/com/android/car/admin/CarDevicePolicyService.java b/service/src/com/android/car/admin/CarDevicePolicyService.java
index a91f4c1..c5e3b2a 100644
--- a/service/src/com/android/car/admin/CarDevicePolicyService.java
+++ b/service/src/com/android/car/admin/CarDevicePolicyService.java
@@ -28,6 +28,7 @@
import android.content.pm.UserInfo;
import android.os.UserManager;
import android.sysprop.CarProperties;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.car.CarServiceBase;
@@ -36,7 +37,6 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.infra.AndroidFuture;
-import java.io.PrintWriter;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -124,7 +124,7 @@
}
@Override
- public void dump(@NonNull PrintWriter writer) {
+ public void dump(@NonNull IndentingPrintWriter writer) {
checkHasDumpPermissionGranted("dump()");
writer.println("*CarDevicePolicyService*");
diff --git a/service/src/com/android/car/am/FixedActivityService.java b/service/src/com/android/car/am/FixedActivityService.java
index de2f774..0515f02 100644
--- a/service/src/com/android/car/am/FixedActivityService.java
+++ b/service/src/com/android/car/am/FixedActivityService.java
@@ -51,6 +51,7 @@
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
@@ -64,7 +65,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.util.List;
/**
@@ -340,7 +340,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*FixedActivityService*");
synchronized (mLock) {
writer.println("mRunningActivities:" + mRunningActivities
diff --git a/service/src/com/android/car/audio/CarAudioService.java b/service/src/com/android/car/audio/CarAudioService.java
index 7c41bc6..9c5a147 100644
--- a/service/src/com/android/car/audio/CarAudioService.java
+++ b/service/src/com/android/car/audio/CarAudioService.java
@@ -53,6 +53,7 @@
import android.telephony.Annotation.CallState;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
@@ -78,7 +79,6 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -301,7 +301,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*CarAudioService*");
writer.println("\tRun in legacy mode? " + (!mUseDynamicRouting));
writer.println("\tPersist master mute state? " + mPersistMasterMuteState);
diff --git a/service/src/com/android/car/cluster/InstrumentClusterService.java b/service/src/com/android/car/cluster/InstrumentClusterService.java
index cec1731..7b561b5 100644
--- a/service/src/com/android/car/cluster/InstrumentClusterService.java
+++ b/service/src/com/android/car/cluster/InstrumentClusterService.java
@@ -42,6 +42,7 @@
import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.view.KeyEvent;
@@ -60,7 +61,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.Objects;
@@ -301,7 +301,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("**" + getClass().getSimpleName() + "**");
synchronized (mLock) {
writer.println("bound with renderer: " + mRendererBound);
diff --git a/service/src/com/android/car/garagemode/GarageModeService.java b/service/src/com/android/car/garagemode/GarageModeService.java
index 601a930..a968939 100644
--- a/service/src/com/android/car/garagemode/GarageModeService.java
+++ b/service/src/com/android/car/garagemode/GarageModeService.java
@@ -18,12 +18,11 @@
import android.content.Context;
import android.os.Looper;
+import android.util.IndentingPrintWriter;
import com.android.car.CarServiceBase;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
-
/**
* Main service container for car Garage Mode.
* Garage Mode enables idle time in cars.
@@ -66,7 +65,7 @@
* @param writer Where to dump the information
*/
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
boolean isActive = mController.isGarageModeActive();
writer.println("GarageModeInProgress " + isActive);
mController.dump(writer);
diff --git a/service/src/com/android/car/pm/CarPackageManagerService.java b/service/src/com/android/car/pm/CarPackageManagerService.java
index 80374ea..b9c2256 100644
--- a/service/src/com/android/car/pm/CarPackageManagerService.java
+++ b/service/src/com/android/car/pm/CarPackageManagerService.java
@@ -55,6 +55,7 @@
import android.os.UserHandle;
import android.text.format.DateFormat;
import android.util.ArraySet;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
@@ -75,7 +76,6 @@
import com.google.android.collect.Sets;
-import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
@@ -935,7 +935,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
synchronized (mLock) {
writer.println("*CarPackageManagerService*");
writer.println("mEnableActivityBlocking:" + mEnableActivityBlocking);
diff --git a/service/src/com/android/car/power/CarPowerManagementService.java b/service/src/com/android/car/power/CarPowerManagementService.java
index baa7e32..41ceb0e 100644
--- a/service/src/com/android/car/power/CarPowerManagementService.java
+++ b/service/src/com/android/car/power/CarPowerManagementService.java
@@ -53,6 +53,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.util.AtomicFile;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.car.CarLocalServices;
@@ -339,7 +340,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
synchronized (mLock) {
writer.println("*PowerManagementService*");
writer.printf("mCurrentState: %s\n", mCurrentState);
diff --git a/service/src/com/android/car/power/SilentModeController.java b/service/src/com/android/car/power/SilentModeController.java
index 8225bad..d6dbd81 100644
--- a/service/src/com/android/car/power/SilentModeController.java
+++ b/service/src/com/android/car/power/SilentModeController.java
@@ -27,6 +27,7 @@
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.car.CarLocalServices;
@@ -42,7 +43,6 @@
import libcore.io.IoUtils;
import java.io.File;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Objects;
@@ -179,7 +179,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
boolean isSilent;
boolean powerStateIsOn;
boolean kernelAllowsSilent;
diff --git a/service/src/com/android/car/stats/CarStatsService.java b/service/src/com/android/car/stats/CarStatsService.java
index 9b0af05..befcd65 100644
--- a/service/src/com/android/car/stats/CarStatsService.java
+++ b/service/src/com/android/car/stats/CarStatsService.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.util.ArrayMap;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import android.util.StatsEvent;
@@ -29,8 +30,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.ConcurrentUtils;
-import java.io.FileDescriptor;
-import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@@ -124,14 +123,17 @@
}
}
- public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
+ /**
+ * Dump its state.
+ */
+ public void dump(IndentingPrintWriter writer, String[] args) {
List<String> flags = Arrays.asList(args);
if (args.length == 0 || flags.contains("--vms-client")) {
dumpVmsStats(writer);
}
}
- private void dumpVmsStats(PrintWriter writer) {
+ private void dumpVmsStats(IndentingPrintWriter writer) {
synchronized (mVmsClientStats) {
writer.println(VMS_CONNECTION_STATS_DUMPSYS_HEADER);
mVmsClientStats.values().stream()
diff --git a/service/src/com/android/car/user/CarUserNoticeService.java b/service/src/com/android/car/user/CarUserNoticeService.java
index ab28dd2..17ca524 100644
--- a/service/src/com/android/car/user/CarUserNoticeService.java
+++ b/service/src/com/android/car/user/CarUserNoticeService.java
@@ -46,6 +46,7 @@
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.view.IWindowManager;
@@ -57,8 +58,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
-
/**
* Service to show initial notice UI to user. It only launches it when setting is enabled and
* it is up to notice UI (=Service) to dismiss itself upon user's request.
@@ -400,7 +399,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
synchronized (mLock) {
if (mServiceIntent == null) {
writer.println("*CarUserNoticeService* disabled");
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index 92f32f1..cd21c3e 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -83,6 +83,7 @@
import android.sysprop.CarProperties;
import android.text.TextUtils;
import android.util.EventLog;
+import android.util.IndentingPrintWriter;
import android.util.Log;
import android.util.Slog;
import android.util.SparseArray;
@@ -334,7 +335,7 @@
}
@Override
- public void dump(@NonNull PrintWriter writer) {
+ public void dump(@NonNull IndentingPrintWriter writer) {
checkHasDumpPermissionGranted("dump()");
writer.println("*CarUserService*");
diff --git a/service/src/com/android/car/vms/VmsBrokerService.java b/service/src/com/android/car/vms/VmsBrokerService.java
index cae6d1f..885c777 100644
--- a/service/src/com/android/car/vms/VmsBrokerService.java
+++ b/service/src/com/android/car/vms/VmsBrokerService.java
@@ -38,6 +38,7 @@
import android.os.SharedMemory;
import android.util.ArrayMap;
import android.util.ArraySet;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import com.android.car.CarServiceBase;
@@ -47,7 +48,6 @@
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.FunctionalUtils.ThrowingConsumer;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -109,7 +109,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
writer.println("*" + TAG + "*");
synchronized (mLock) {
writer.println("mAvailableLayers: " + mAvailableLayers.getAvailableLayers());
diff --git a/service/src/com/android/car/watchdog/CarWatchdogService.java b/service/src/com/android/car/watchdog/CarWatchdogService.java
index 3276291..4f7a5ce 100644
--- a/service/src/com/android/car/watchdog/CarWatchdogService.java
+++ b/service/src/com/android/car/watchdog/CarWatchdogService.java
@@ -45,6 +45,7 @@
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
+import android.util.IndentingPrintWriter;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
@@ -56,7 +57,6 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
-import java.io.PrintWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
@@ -143,7 +143,7 @@
}
@Override
- public void dump(PrintWriter writer) {
+ public void dump(IndentingPrintWriter writer) {
String indent = " ";
int count = 1;
synchronized (mLock) {
diff --git a/tests/carservice_test/src/com/android/car/garagemode/GarageModeServiceTest.java b/tests/carservice_test/src/com/android/car/garagemode/GarageModeServiceTest.java
index 89e41cf..c1b45d3 100644
--- a/tests/carservice_test/src/com/android/car/garagemode/GarageModeServiceTest.java
+++ b/tests/carservice_test/src/com/android/car/garagemode/GarageModeServiceTest.java
@@ -24,6 +24,7 @@
import android.content.ContentResolver;
import android.content.Context;
+import android.util.IndentingPrintWriter;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -38,7 +39,6 @@
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
-import java.io.PrintWriter;
import java.util.List;
@RunWith(AndroidJUnit4.class)
@@ -48,7 +48,7 @@
@Mock private Context mMockContext;
@Mock private Controller mMockController;
@Mock private ContentResolver mMockContentResolver;
- @Mock private PrintWriter mMockPrintWriter;
+ @Mock private IndentingPrintWriter mMockPrintWriter;
@Captor private ArgumentCaptor<String> mCaptorString;
private GarageModeService mService;
diff --git a/tests/carservice_unit_test/src/com/android/car/stats/CarStatsServiceTest.java b/tests/carservice_unit_test/src/com/android/car/stats/CarStatsServiceTest.java
index 9bdcaa6..b846f09 100644
--- a/tests/carservice_unit_test/src/com/android/car/stats/CarStatsServiceTest.java
+++ b/tests/carservice_unit_test/src/com/android/car/stats/CarStatsServiceTest.java
@@ -22,6 +22,7 @@
import android.car.vms.VmsLayer;
import android.content.Context;
import android.content.pm.PackageManager;
+import android.util.IndentingPrintWriter;
import androidx.test.filters.SmallTest;
@@ -59,7 +60,7 @@
private CarStatsService mCarStatsService;
private StringWriter mDumpsysOutput;
- private PrintWriter mDumpsysWriter;
+ private IndentingPrintWriter mDumpsysWriter;
@Before
public void setUp() {
@@ -69,12 +70,12 @@
mCarStatsService = new CarStatsService(mContext);
mDumpsysOutput = new StringWriter();
- mDumpsysWriter = new PrintWriter(mDumpsysOutput);
+ mDumpsysWriter = new IndentingPrintWriter(new PrintWriter(mDumpsysOutput));
}
@Test
public void testEmptyStats() {
- mCarStatsService.dump(null, mDumpsysWriter, new String[0]);
+ mCarStatsService.dump(mDumpsysWriter, new String[0]);
assertEquals(
"uid,packageName,attempts,connected,disconnected,terminated,errors\n"
+ "\nuid,layerType,layerChannel,layerVersion,"
@@ -344,7 +345,7 @@
}
private void validateDumpsys(String vmsConnectionStats, String vmsClientStats) {
- mCarStatsService.dump(null, mDumpsysWriter, new String[0]);
+ mCarStatsService.dump(mDumpsysWriter, new String[0]);
assertEquals(
"uid,packageName,attempts,connected,disconnected,terminated,errors\n"
+ vmsConnectionStats