From c3cf2a85245c1c5712945c987617d09d8857de89 Mon Sep 17 00:00:00 2001 From: Ytai Ben-Tsvi Date: Tue, 14 Apr 2020 12:35:06 -0700 Subject: [PATCH 1/3] Pretty-print all arguments and return value Previously, we would print only parcelables, which would exclude arrays. There's no reason to. All arguments and return values we log are parcelables (or arrays of) anyway. Test: Manual verification of logs. Bug: 154020971 Change-Id: I24c06373f07bd46f58e520364f5b1753f20c75e3 --- .../SoundTriggerMiddlewareLogging.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java index 04ba6bfeb4eeb..8b6ed1ff50813 100644 --- a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java +++ b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareLogging.java @@ -377,11 +377,7 @@ public class SoundTriggerMiddlewareLogging implements ISoundTriggerMiddlewareInt } private static void printObject(@NonNull StringBuilder builder, @Nullable Object obj) { - if (obj instanceof Parcelable) { - ObjectPrinter.print(builder, obj, true, 16); - } else { - builder.append(obj.toString()); - } + ObjectPrinter.print(builder, obj, true, 16); } private static String printObject(@Nullable Object obj) { From 4d38fbb4861388c6055e2ff821a0905fe3207e47 Mon Sep 17 00:00:00 2001 From: Ytai Ben-Tsvi Date: Tue, 14 Apr 2020 13:11:54 -0700 Subject: [PATCH 2/3] Improve dumpsys printing of modules This includes the module properties in the listing. Bug: 154020971 Test: Manual verification of logging. Change-Id: I13ed6e225714fe49f0b6e09c9c676594a886e6e3 --- .../SoundTriggerMiddlewareValidation.java | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java index 23259558eeb79..220179e218ea1 100644 --- a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java +++ b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java @@ -32,9 +32,9 @@ import android.media.soundtrigger_middleware.RecognitionEvent; import android.media.soundtrigger_middleware.RecognitionStatus; import android.media.soundtrigger_middleware.SoundModel; import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor; +import android.media.soundtrigger_middleware.SoundTriggerModuleProperties; import android.media.soundtrigger_middleware.Status; import android.os.IBinder; -import android.os.Process; import android.os.RemoteException; import android.os.ServiceSpecificException; import android.util.Log; @@ -108,17 +108,26 @@ import java.util.Set; public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddlewareInternal, Dumpable { private static final String TAG = "SoundTriggerMiddlewareValidation"; - private enum ModuleState { + private enum ModuleStatus { ALIVE, DETACHED, DEAD }; + private class ModuleState { + final @NonNull SoundTriggerModuleProperties properties; + Set sessions = new HashSet<>(); + + private ModuleState(@NonNull SoundTriggerModuleProperties properties) { + this.properties = properties; + } + } + private Boolean mCaptureState; private final @NonNull ISoundTriggerMiddlewareInternal mDelegate; private final @NonNull Context mContext; - private Map> mModules; + private Map mModules; public SoundTriggerMiddlewareValidation( @NonNull ISoundTriggerMiddlewareInternal delegate, @NonNull Context context) { @@ -168,7 +177,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware SoundTriggerModuleDescriptor[] result = mDelegate.listModules(); mModules = new HashMap<>(result.length); for (SoundTriggerModuleDescriptor desc : result) { - mModules.put(desc.handle, new HashSet<>()); + mModules.put(desc.handle, new ModuleState(desc.properties)); } return result; } catch (Exception e) { @@ -278,18 +287,21 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware @Override public void dump(PrintWriter pw) { synchronized (this) { - pw.printf("Capture state is %s\n", mCaptureState == null ? "uninitialized" + pw.printf("Capture state is %s\n\n", mCaptureState == null ? "uninitialized" : (mCaptureState ? "active" : "inactive")); if (mModules != null) { for (int handle : mModules.keySet()) { + final ModuleState module = mModules.get(handle); pw.println("========================================="); - pw.printf("Active sessions for module %d", handle); - pw.println(); + pw.printf("Module %d\n%s\n", handle, + ObjectPrinter.print(module.properties, true, 16)); pw.println("========================================="); - for (ModuleService session : mModules.get(handle)) { + for (ModuleService session : module.sessions) { session.dump(pw); } } + } else { + pw.println("Modules have not yet been enumerated."); } } pw.println(); @@ -297,7 +309,6 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware if (mDelegate instanceof Dumpable) { ((Dumpable) mDelegate).dump(pw); } - } /** State of a sound model. */ @@ -375,7 +386,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware private ISoundTriggerModule mDelegate; private @NonNull Map mLoadedModels = new HashMap<>(); private final int mHandle; - private ModuleState mState = ModuleState.ALIVE; + private ModuleStatus mState = ModuleStatus.ALIVE; ModuleService(int handle, @NonNull ISoundTriggerCallback callback) { mCallback = callback; @@ -389,7 +400,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware void attach(@NonNull ISoundTriggerModule delegate) { mDelegate = delegate; - mModules.get(mHandle).add(this); + mModules.get(mHandle).sessions.add(this); } @Override @@ -401,7 +412,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } @@ -425,7 +436,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } @@ -448,7 +459,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } ModelState modelState = mLoadedModels.get( @@ -481,7 +492,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } ModelState modelState = mLoadedModels.get( @@ -515,7 +526,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } ModelState modelState = mLoadedModels.get( @@ -544,7 +555,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } ModelState modelState = mLoadedModels.get( @@ -572,7 +583,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } ModelState modelState = mLoadedModels.get( @@ -600,7 +611,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } ModelState modelState = mLoadedModels.get( @@ -629,7 +640,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has been detached."); } ModelState modelState = mLoadedModels.get( @@ -658,10 +669,10 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware synchronized (SoundTriggerMiddlewareValidation.this) { // State validation. - if (mState == ModuleState.DETACHED) { + if (mState == ModuleStatus.DETACHED) { throw new IllegalStateException("Module has already been detached."); } - if (mState == ModuleState.ALIVE && !mLoadedModels.isEmpty()) { + if (mState == ModuleStatus.ALIVE && !mLoadedModels.isEmpty()) { throw new IllegalStateException("Cannot detach while models are loaded."); } @@ -683,16 +694,16 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware private void detachInternal() { try { mDelegate.detach(); - mState = ModuleState.DETACHED; + mState = ModuleStatus.DETACHED; mCallback.asBinder().unlinkToDeath(this, 0); - mModules.get(mHandle).remove(this); + mModules.get(mHandle).sessions.remove(this); } catch (RemoteException e) { throw e.rethrowAsRuntimeException(); } } void dump(PrintWriter pw) { - if (mState == ModuleState.ALIVE) { + if (mState == ModuleStatus.ALIVE) { pw.printf("Loaded models for session %s (handle, active)", toString()); pw.println(); pw.println("-------------------------------"); @@ -762,7 +773,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware public void onModuleDied() { synchronized (SoundTriggerMiddlewareValidation.this) { try { - mState = ModuleState.DEAD; + mState = ModuleStatus.DEAD; mCallback.onModuleDied(); } catch (RemoteException e) { // Dead client will be handled by binderDied() - no need to handle here. From 58a1c3823f86217e3da79a5958f1c35729bb372e Mon Sep 17 00:00:00 2001 From: Ytai Ben-Tsvi Date: Tue, 14 Apr 2020 13:18:49 -0700 Subject: [PATCH 3/3] Print description of loaded models in dumpsys Bug: 154020971 Test: Manual verification of dumpsys. Change-Id: Ibae9d41ec7470cc0ddabfe087910e1eac172f39a --- .../SoundTriggerMiddlewareValidation.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java index 220179e218ea1..bae244179346f 100644 --- a/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java +++ b/services/core/java/com/android/server/soundtrigger_middleware/SoundTriggerMiddlewareValidation.java @@ -313,6 +313,14 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware /** State of a sound model. */ static class ModelState { + ModelState(SoundModel model) { + this.description = ObjectPrinter.print(model, true, 16); + } + + ModelState(PhraseSoundModel model) { + this.description = ObjectPrinter.print(model, true, 16); + } + /** Activity state of a sound model. */ enum Activity { /** Model is loaded, recognition is inactive. */ @@ -324,6 +332,9 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware /** Activity state. */ Activity activityState = Activity.LOADED; + /** Human-readable description of the model. */ + final String description; + /** * A map of known parameter support. A missing key means we don't know yet whether the * parameter is supported. A null value means it is known to not be supported. A non-null @@ -419,7 +430,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware // From here on, every exception isn't client's fault. try { int handle = mDelegate.loadModel(model); - mLoadedModels.put(handle, new ModelState()); + mLoadedModels.put(handle, new ModelState(model)); return handle; } catch (Exception e) { throw handleException(e); @@ -443,7 +454,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware // From here on, every exception isn't client's fault. try { int handle = mDelegate.loadPhraseModel(model); - mLoadedModels.put(handle, new ModelState()); + mLoadedModels.put(handle, new ModelState(model)); return handle; } catch (Exception e) { throw handleException(e); @@ -711,6 +722,8 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware pw.print(entry.getKey()); pw.print('\t'); pw.print(entry.getValue().activityState.name()); + pw.print('\t'); + pw.print(entry.getValue().description); pw.println(); } } else {