Merge "Change SoundTriggerMiddleware to log to Slog" into udc-qpr-dev

This commit is contained in:
Atneya Nair
2023-06-27 15:39:48 +00:00
committed by Android (Google) Code Review
8 changed files with 40 additions and 40 deletions

View File

@@ -22,7 +22,7 @@ import android.os.HwBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.util.Log; import android.util.Slog;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -62,7 +62,7 @@ class DefaultHalFactory implements HalFactory {
android.hardware.soundtrigger3.ISoundTriggerHw.class.getCanonicalName() android.hardware.soundtrigger3.ISoundTriggerHw.class.getCanonicalName()
+ "/default"; + "/default";
if (ServiceManager.isDeclared(aidlServiceName)) { if (ServiceManager.isDeclared(aidlServiceName)) {
Log.i(TAG, "Connecting to default soundtrigger3.ISoundTriggerHw"); Slog.i(TAG, "Connecting to default soundtrigger3.ISoundTriggerHw");
return new SoundTriggerHw3Compat(ServiceManager.waitForService(aidlServiceName), return new SoundTriggerHw3Compat(ServiceManager.waitForService(aidlServiceName),
() -> { () -> {
// This property needs to be defined in an init.rc script and // This property needs to be defined in an init.rc script and
@@ -72,7 +72,7 @@ class DefaultHalFactory implements HalFactory {
} }
// Fallback to soundtrigger-V2.x (HIDL). // Fallback to soundtrigger-V2.x (HIDL).
Log.i(TAG, "Connecting to default soundtrigger-V2.x.ISoundTriggerHw"); Slog.i(TAG, "Connecting to default soundtrigger-V2.x.ISoundTriggerHw");
ISoundTriggerHw driver = ISoundTriggerHw.getService(true); ISoundTriggerHw driver = ISoundTriggerHw.getService(true);
return SoundTriggerHw2Compat.create(driver, () -> { return SoundTriggerHw2Compat.create(driver, () -> {
// This property needs to be defined in an init.rc script and // This property needs to be defined in an init.rc script and
@@ -81,7 +81,7 @@ class DefaultHalFactory implements HalFactory {
}, mCaptureStateNotifier); }, mCaptureStateNotifier);
} else if (mockHal == USE_MOCK_HAL_V2) { } else if (mockHal == USE_MOCK_HAL_V2) {
// Use V2 mock. // Use V2 mock.
Log.i(TAG, "Connecting to mock soundtrigger-V2.x.ISoundTriggerHw"); Slog.i(TAG, "Connecting to mock soundtrigger-V2.x.ISoundTriggerHw");
HwBinder.setTrebleTestingOverride(true); HwBinder.setTrebleTestingOverride(true);
try { try {
ISoundTriggerHw driver = ISoundTriggerHw.getService("mock", true); ISoundTriggerHw driver = ISoundTriggerHw.getService("mock", true);
@@ -89,7 +89,7 @@ class DefaultHalFactory implements HalFactory {
try { try {
driver.debug(null, new ArrayList<>(Arrays.asList("reboot"))); driver.debug(null, new ArrayList<>(Arrays.asList("reboot")));
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Failed to reboot mock HAL", e); Slog.e(TAG, "Failed to reboot mock HAL", e);
} }
}, mCaptureStateNotifier); }, mCaptureStateNotifier);
} finally { } finally {
@@ -100,14 +100,14 @@ class DefaultHalFactory implements HalFactory {
final String aidlServiceName = final String aidlServiceName =
android.hardware.soundtrigger3.ISoundTriggerHw.class.getCanonicalName() android.hardware.soundtrigger3.ISoundTriggerHw.class.getCanonicalName()
+ "/mock"; + "/mock";
Log.i(TAG, "Connecting to mock soundtrigger3.ISoundTriggerHw"); Slog.i(TAG, "Connecting to mock soundtrigger3.ISoundTriggerHw");
return new SoundTriggerHw3Compat(ServiceManager.waitForService(aidlServiceName), return new SoundTriggerHw3Compat(ServiceManager.waitForService(aidlServiceName),
() -> { () -> {
try { try {
ServiceManager.waitForService(aidlServiceName).shellCommand(null, ServiceManager.waitForService(aidlServiceName).shellCommand(null,
null, null, new String[]{"reboot"}, null, null); null, null, new String[]{"reboot"}, null, null);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Failed to reboot mock HAL", e); Slog.e(TAG, "Failed to reboot mock HAL", e);
} }
}); });
} else { } else {

View File

@@ -17,7 +17,7 @@
package com.android.server.soundtrigger_middleware; package com.android.server.soundtrigger_middleware;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.util.Log; import android.util.Slog;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@@ -94,7 +94,7 @@ class ExternalCaptureStateTracker implements ICaptureStateNotifier {
} }
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Exception caught while setting capture state", e); Slog.e(TAG, "Exception caught while setting capture state", e);
} }
} }
@@ -102,7 +102,7 @@ class ExternalCaptureStateTracker implements ICaptureStateNotifier {
* Called by native code when the remote service died. * Called by native code when the remote service died.
*/ */
private void binderDied() { private void binderDied() {
Log.w(TAG, "Audio policy service died"); Slog.w(TAG, "Audio policy service died");
mNeedToConnect.release(); mNeedToConnect.release();
} }
} }

View File

@@ -27,7 +27,7 @@ import android.media.soundtrigger_middleware.PhraseRecognitionEventSys;
import android.media.soundtrigger_middleware.RecognitionEventSys; import android.media.soundtrigger_middleware.RecognitionEventSys;
import android.os.DeadObjectException; import android.os.DeadObjectException;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Slog;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -227,10 +227,10 @@ public class SoundTriggerHalEnforcer implements ISoundTriggerHal {
} }
if (e.getCause() instanceof DeadObjectException) { if (e.getCause() instanceof DeadObjectException) {
// Server is dead, no need to reboot. // Server is dead, no need to reboot.
Log.e(TAG, "HAL died"); Slog.e(TAG, "HAL died");
throw new RecoverableException(Status.DEAD_OBJECT); throw new RecoverableException(Status.DEAD_OBJECT);
} }
Log.e(TAG, "Exception caught from HAL, rebooting HAL"); Slog.e(TAG, "Exception caught from HAL, rebooting HAL");
reboot(); reboot();
throw e; throw e;
} }
@@ -257,14 +257,14 @@ public class SoundTriggerHalEnforcer implements ISoundTriggerHal {
synchronized (mModelStates) { synchronized (mModelStates) {
ModelState state = mModelStates.get(model); ModelState state = mModelStates.get(model);
if (state == null) { if (state == null) {
Log.wtfStack(TAG, "Unexpected recognition event for model: " + model); Slog.wtfStack(TAG, "Unexpected recognition event for model: " + model);
reboot(); reboot();
return; return;
} }
if (event.recognitionEvent.recognitionStillActive if (event.recognitionEvent.recognitionStillActive
&& event.recognitionEvent.status != RecognitionStatus.SUCCESS && event.recognitionEvent.status != RecognitionStatus.SUCCESS
&& event.recognitionEvent.status != RecognitionStatus.FORCED) { && event.recognitionEvent.status != RecognitionStatus.FORCED) {
Log.wtfStack(TAG, Slog.wtfStack(TAG,
"recognitionStillActive is only allowed when the recognition status " "recognitionStillActive is only allowed when the recognition status "
+ "is SUCCESS"); + "is SUCCESS");
reboot(); reboot();
@@ -283,14 +283,14 @@ public class SoundTriggerHalEnforcer implements ISoundTriggerHal {
synchronized (mModelStates) { synchronized (mModelStates) {
ModelState state = mModelStates.get(model); ModelState state = mModelStates.get(model);
if (state == null) { if (state == null) {
Log.wtfStack(TAG, "Unexpected recognition event for model: " + model); Slog.wtfStack(TAG, "Unexpected recognition event for model: " + model);
reboot(); reboot();
return; return;
} }
if (event.phraseRecognitionEvent.common.recognitionStillActive if (event.phraseRecognitionEvent.common.recognitionStillActive
&& event.phraseRecognitionEvent.common.status != RecognitionStatus.SUCCESS && event.phraseRecognitionEvent.common.status != RecognitionStatus.SUCCESS
&& event.phraseRecognitionEvent.common.status != RecognitionStatus.FORCED) { && event.phraseRecognitionEvent.common.status != RecognitionStatus.FORCED) {
Log.wtfStack(TAG, Slog.wtfStack(TAG,
"recognitionStillActive is only allowed when the recognition status " "recognitionStillActive is only allowed when the recognition status "
+ "is SUCCESS"); + "is SUCCESS");
reboot(); reboot();
@@ -309,13 +309,13 @@ public class SoundTriggerHalEnforcer implements ISoundTriggerHal {
synchronized (mModelStates) { synchronized (mModelStates) {
ModelState state = mModelStates.get(modelHandle); ModelState state = mModelStates.get(modelHandle);
if (state == null) { if (state == null) {
Log.wtfStack(TAG, "Unexpected unload event for model: " + modelHandle); Slog.wtfStack(TAG, "Unexpected unload event for model: " + modelHandle);
reboot(); reboot();
return; return;
} }
if (state == ModelState.ACTIVE) { if (state == ModelState.ACTIVE) {
Log.wtfStack(TAG, "Trying to unload an active model: " + modelHandle); Slog.wtfStack(TAG, "Trying to unload an active model: " + modelHandle);
reboot(); reboot();
return; return;
} }

View File

@@ -23,7 +23,7 @@ import android.media.soundtrigger.Properties;
import android.media.soundtrigger.RecognitionConfig; import android.media.soundtrigger.RecognitionConfig;
import android.media.soundtrigger.SoundModel; import android.media.soundtrigger.SoundModel;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Slog;
import java.util.Objects; import java.util.Objects;
@@ -172,7 +172,7 @@ public class SoundTriggerHalWatchdog implements ISoundTriggerHal {
Watchdog() { Watchdog() {
mTask = mTimer.createTask(() -> { mTask = mTimer.createTask(() -> {
Log.e(TAG, "HAL deadline expired. Rebooting.", mException); Slog.e(TAG, "HAL deadline expired. Rebooting.", mException);
reboot(); reboot();
}, TIMEOUT_MS); }, TIMEOUT_MS);
} }

View File

@@ -32,7 +32,7 @@ import android.os.IHwBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.SystemClock; import android.os.SystemClock;
import android.system.OsConstants; import android.system.OsConstants;
import android.util.Log; import android.util.Slog;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@@ -240,7 +240,7 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
try { try {
hidlModel.data.close(); hidlModel.data.close();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Failed to close file", e); Slog.e(TAG, "Failed to close file", e);
} }
} }
} }
@@ -276,7 +276,7 @@ final class SoundTriggerHw2Compat implements ISoundTriggerHal {
try { try {
hidlModel.common.data.close(); hidlModel.common.data.close();
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Failed to close file", e); Slog.e(TAG, "Failed to close file", e);
} }
} }
} }

View File

@@ -20,7 +20,7 @@ import android.annotation.NonNull;
import android.media.soundtrigger_middleware.ISoundTriggerCallback; import android.media.soundtrigger_middleware.ISoundTriggerCallback;
import android.media.soundtrigger_middleware.ISoundTriggerModule; import android.media.soundtrigger_middleware.ISoundTriggerModule;
import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor; import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor;
import android.util.Log; import android.util.Slog;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -85,7 +85,7 @@ public class SoundTriggerMiddlewareImpl implements ISoundTriggerMiddlewareIntern
try { try {
modules.add(new SoundTriggerModule(halFactory, audioSessionProvider)); modules.add(new SoundTriggerModule(halFactory, audioSessionProvider));
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Failed to add a SoundTriggerModule instance", e); Slog.e(TAG, "Failed to add a SoundTriggerModule instance", e);
} }
} }

View File

@@ -36,7 +36,7 @@ import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceSpecificException; import android.os.ServiceSpecificException;
import android.util.Log; import android.util.Slog;
import android.util.SparseArray; import android.util.SparseArray;
import com.android.internal.util.Preconditions; import com.android.internal.util.Preconditions;
@@ -150,7 +150,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
e.getMessage()); e.getMessage());
} }
Log.wtf(TAG, "Unexpected exception", e); Slog.wtf(TAG, "Unexpected exception", e);
throw new ServiceSpecificException(Status.INTERNAL_ERROR, e.getMessage()); throw new ServiceSpecificException(Status.INTERNAL_ERROR, e.getMessage());
} }
@@ -701,7 +701,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
try { try {
mCallback.onRecognition(modelHandle, event, captureSession); mCallback.onRecognition(modelHandle, event, captureSession);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Client callback exception.", e); Slog.w(TAG, "Client callback exception.", e);
} }
} }
@@ -719,7 +719,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
try { try {
mCallback.onPhraseRecognition(modelHandle, event, captureSession); mCallback.onPhraseRecognition(modelHandle, event, captureSession);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Client callback exception.", e); Slog.w(TAG, "Client callback exception.", e);
} }
} }
@@ -734,7 +734,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
try { try {
mCallback.onModelUnloaded(modelHandle); mCallback.onModelUnloaded(modelHandle);
} catch (Exception e) { } catch (Exception e) {
Log.w(TAG, "Client callback exception.", e); Slog.w(TAG, "Client callback exception.", e);
} }
} }
@@ -746,7 +746,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
} catch (RemoteException e) { } catch (RemoteException e) {
// Dead client will be handled by binderDied() - no need to handle here. // Dead client will be handled by binderDied() - no need to handle here.
// In any case, client callbacks are considered best effort. // In any case, client callbacks are considered best effort.
Log.e(TAG, "Client callback exception.", e); Slog.e(TAG, "Client callback exception.", e);
} }
} }
@@ -761,7 +761,7 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
} catch (RemoteException e) { } catch (RemoteException e) {
// Dead client will be handled by binderDied() - no need to handle here. // Dead client will be handled by binderDied() - no need to handle here.
// In any case, client callbacks are considered best effort. // In any case, client callbacks are considered best effort.
Log.e(TAG, "Client callback exception.", e); Slog.e(TAG, "Client callback exception.", e);
} }
} }
@@ -795,11 +795,11 @@ public class SoundTriggerMiddlewareValidation implements ISoundTriggerMiddleware
// Check if state updated unexpectedly to log race conditions. // Check if state updated unexpectedly to log race conditions.
for (Map.Entry<Integer, ModelState> entry : mLoadedModels.entrySet()) { for (Map.Entry<Integer, ModelState> entry : mLoadedModels.entrySet()) {
if (cachedMap.get(entry.getKey()) != entry.getValue().activityState) { if (cachedMap.get(entry.getKey()) != entry.getValue().activityState) {
Log.e(TAG, "Unexpected state update in binderDied. Race occurred!"); Slog.e(TAG, "Unexpected state update in binderDied. Race occurred!");
} }
} }
if (mLoadedModels.size() != cachedMap.size()) { if (mLoadedModels.size() != cachedMap.size()) {
Log.e(TAG, "Unexpected state update in binderDied. Race occurred!"); Slog.e(TAG, "Unexpected state update in binderDied. Race occurred!");
} }
try { try {
// Detach // Detach

View File

@@ -31,7 +31,7 @@ import android.media.soundtrigger_middleware.RecognitionEventSys;
import android.os.Binder; import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import android.util.Slog;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -136,7 +136,7 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
@Override @Override
public void binderDied() { public void binderDied() {
Log.w(TAG, "Underlying HAL driver died."); Slog.w(TAG, "Underlying HAL driver died.");
List<ISoundTriggerCallback> callbacks; List<ISoundTriggerCallback> callbacks;
synchronized (this) { synchronized (this) {
callbacks = new ArrayList<>(mActiveSessions.size()); callbacks = new ArrayList<>(mActiveSessions.size());
@@ -270,7 +270,7 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
try { try {
mAudioSessionProvider.releaseSession(audioSession.mSessionHandle); mAudioSessionProvider.releaseSession(audioSession.mSessionHandle);
} catch (Exception ee) { } catch (Exception ee) {
Log.e(TAG, "Failed to release session.", ee); Slog.e(TAG, "Failed to release session.", ee);
} }
throw e; throw e;
} }
@@ -286,7 +286,7 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
checkValid(); checkValid();
Model loadedModel = new Model(); Model loadedModel = new Model();
int result = loadedModel.load(model, audioSession); int result = loadedModel.load(model, audioSession);
Log.d(TAG, String.format("loadPhraseModel()->%d", result)); Slog.d(TAG, String.format("loadPhraseModel()->%d", result));
return result; return result;
} catch (Exception e) { } catch (Exception e) {
// We must do this outside the lock, to avoid possible deadlocks with the remote // We must do this outside the lock, to avoid possible deadlocks with the remote
@@ -294,7 +294,7 @@ class SoundTriggerModule implements IBinder.DeathRecipient, ISoundTriggerHal.Glo
try { try {
mAudioSessionProvider.releaseSession(audioSession.mSessionHandle); mAudioSessionProvider.releaseSession(audioSession.mSessionHandle);
} catch (Exception ee) { } catch (Exception ee) {
Log.e(TAG, "Failed to release session.", ee); Slog.e(TAG, "Failed to release session.", ee);
} }
throw e; throw e;
} }