diff options
20 files changed, 189 insertions, 212 deletions
diff --git a/core/java/android/hardware/camera2/CameraDevice.java b/core/java/android/hardware/camera2/CameraDevice.java index ec9b013c34cc..dca663d206d3 100644 --- a/core/java/android/hardware/camera2/CameraDevice.java +++ b/core/java/android/hardware/camera2/CameraDevice.java @@ -23,12 +23,14 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; import android.annotation.SystemApi; +import android.graphics.SurfaceTexture; import android.hardware.camera2.params.ExtensionSessionConfiguration; import android.hardware.camera2.params.InputConfiguration; import android.hardware.camera2.params.OutputConfiguration; import android.hardware.camera2.params.SessionConfiguration; import android.hardware.camera2.params.StreamConfigurationMap; import android.os.Handler; +import android.util.Size; import android.view.Surface; import com.android.internal.camera.flags.Flags; @@ -530,9 +532,10 @@ public abstract class CameraDevice implements AutoCloseable { * SurfaceTexture}: Set the size of the SurfaceTexture with {@link * android.graphics.SurfaceTexture#setDefaultBufferSize} to be one of the sizes returned by * {@link StreamConfigurationMap#getOutputSizes(Class) getOutputSizes(SurfaceTexture.class)} - * before creating a Surface from the SurfaceTexture with {@link Surface#Surface}. If the size - * is not set by the application, it will be set to be the smallest supported size less than - * 1080p, by the camera device.</li> + * before creating a Surface from the SurfaceTexture with + * {@link Surface#Surface(SurfaceTexture)}. If the size is not set by the application, + * it will be set to be the smallest supported size less than 1080p, by the camera + * device.</li> * * <li>For recording with {@link android.media.MediaCodec}: Call * {@link android.media.MediaCodec#createInputSurface} after configuring @@ -1405,10 +1408,16 @@ public abstract class CameraDevice implements AutoCloseable { * * <p><b>NOTE:</b> * For apps targeting {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM} and above, - * this method will ensure session parameters set through calls to - * {@link SessionConfiguration#setSessionParameters} are also supported if the Camera Device - * supports it. For apps targeting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} and - * below, session parameters will be ignored.</p> + * this method will automatically delegate to + * {@link CameraDeviceSetup#isSessionConfigurationSupported} whenever possible. This + * means that the output of this method will consider parameters set through + * {@link SessionConfiguration#setSessionParameters} as well. + * </p> + * + * <p>Session Parameters will be ignored for apps targeting <= + * {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, or if + * {@link CameraManager#isCameraDeviceSetupSupported} returns false for the camera id + * associated with this {@code CameraDevice}.</p> * * @return {@code true} if the given session configuration is supported by the camera device * {@code false} otherwise. @@ -1419,6 +1428,8 @@ public abstract class CameraDevice implements AutoCloseable { * encountered a fatal error * @throws IllegalStateException if the camera device has been closed * + * @see CameraManager#isCameraDeviceSetupSupported(String) + * @see CameraDeviceSetup#isSessionConfigurationSupported(SessionConfiguration) */ public boolean isSessionConfigurationSupported( @NonNull SessionConfiguration sessionConfig) throws CameraAccessException { @@ -1703,7 +1714,7 @@ public abstract class CameraDevice implements AutoCloseable { * SessionConfiguration} can then be created using the OutputConfiguration objects and * be used to query whether it's supported by the camera device. To create the * CameraCaptureSession, the application still needs to make sure all output surfaces - * are added via {@link OutputConfiguration#addSurfaces} with the exception of deferred + * are added via {@link OutputConfiguration#addSurface} with the exception of deferred * surfaces for {@link android.view.SurfaceView} and * {@link android.graphics.SurfaceTexture}.</li> * </ul> @@ -1751,7 +1762,7 @@ public abstract class CameraDevice implements AutoCloseable { * SessionConfiguration} can then be created using the OutputConfiguration objects and * be used for this function. To create the CameraCaptureSession, the application still * needs to make sure all output surfaces are added via {@link - * OutputConfiguration#addSurfaces} with the exception of deferred surfaces for {@link + * OutputConfiguration#addSurface} with the exception of deferred surfaces for {@link * android.view.SurfaceView} and {@link android.graphics.SurfaceTexture}.</p> * * @param sessionConfig The session configuration for which characteristics are fetched. diff --git a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java index 9481dc91bcc4..a0c405e31e79 100644 --- a/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java +++ b/core/java/com/android/internal/accessibility/AccessibilityShortcutController.java @@ -53,7 +53,6 @@ import android.util.Slog; import android.view.Window; import android.view.WindowManager; import android.view.accessibility.AccessibilityManager; -import android.view.accessibility.Flags; import android.widget.Toast; import com.android.internal.R; @@ -369,23 +368,17 @@ public class AccessibilityShortcutController { }) .setPositiveButton(R.string.accessibility_shortcut_off, (DialogInterface d, int which) -> { - if (Flags.updateAlwaysOnA11yService()) { - Set<String> targetServices = - ShortcutUtils.getShortcutTargetsFromSettings( - mContext, - HARDWARE, - userId); - - Settings.Secure.putStringForUser(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, "", - userId); - ShortcutUtils.updateInvisibleToggleAccessibilityServiceEnableState( - mContext, targetServices, userId); - } else { - Settings.Secure.putStringForUser(mContext.getContentResolver(), - Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, "", - userId); - } + Set<String> targetServices = + ShortcutUtils.getShortcutTargetsFromSettings( + mContext, + HARDWARE, + userId); + + Settings.Secure.putStringForUser(mContext.getContentResolver(), + Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE, "", + userId); + ShortcutUtils.updateInvisibleToggleAccessibilityServiceEnableState( + mContext, targetServices, userId); // If canceled, treat as if the dialog has never been shown Settings.Secure.putIntForUser(mContext.getContentResolver(), diff --git a/core/java/com/android/internal/accessibility/dialog/InvisibleToggleAccessibilityServiceTarget.java b/core/java/com/android/internal/accessibility/dialog/InvisibleToggleAccessibilityServiceTarget.java index 7831afb8798e..209778808764 100644 --- a/core/java/com/android/internal/accessibility/dialog/InvisibleToggleAccessibilityServiceTarget.java +++ b/core/java/com/android/internal/accessibility/dialog/InvisibleToggleAccessibilityServiceTarget.java @@ -16,17 +16,11 @@ package com.android.internal.accessibility.dialog; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.HARDWARE; -import static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE; -import static com.android.internal.accessibility.util.AccessibilityUtils.setAccessibilityServiceState; -import static com.android.internal.accessibility.util.ShortcutUtils.isComponentIdExistingInSettings; - import android.accessibilityservice.AccessibilityServiceInfo; import android.annotation.NonNull; import android.content.ComponentName; import android.content.Context; import android.os.UserHandle; -import android.view.accessibility.Flags; import com.android.internal.accessibility.common.ShortcutConstants.AccessibilityFragmentType; import com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType; @@ -53,31 +47,9 @@ public class InvisibleToggleAccessibilityServiceTarget extends AccessibilityServ @Override public void onCheckedChanged(boolean isChecked) { + super.onCheckedChanged(isChecked); final ComponentName componentName = ComponentName.unflattenFromString(getId()); - - if (Flags.updateAlwaysOnA11yService()) { - super.onCheckedChanged(isChecked); - ShortcutUtils.updateInvisibleToggleAccessibilityServiceEnableState( - getContext(), Set.of(componentName.flattenToString()), UserHandle.myUserId()); - } else { - if (!isComponentIdExistingInOtherShortcut()) { - setAccessibilityServiceState(getContext(), componentName, isChecked); - } - - super.onCheckedChanged(isChecked); - } - } - - private boolean isComponentIdExistingInOtherShortcut() { - switch (getShortcutType()) { - case SOFTWARE: - return isComponentIdExistingInSettings(getContext(), UserShortcutType.HARDWARE, - getId()); - case HARDWARE: - return isComponentIdExistingInSettings(getContext(), UserShortcutType.SOFTWARE, - getId()); - default: - throw new IllegalStateException("Unexpected shortcut type"); - } + ShortcutUtils.updateInvisibleToggleAccessibilityServiceEnableState( + getContext(), Set.of(componentName.flattenToString()), UserHandle.myUserId()); } } diff --git a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java index 180521ba7b70..365f3485d65c 100644 --- a/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java +++ b/core/tests/coretests/src/com/android/internal/accessibility/AccessibilityShortcutControllerTest.java @@ -64,9 +64,6 @@ import android.os.Build; import android.os.Handler; import android.os.Message; import android.os.Vibrator; -import android.platform.test.annotations.RequiresFlagsEnabled; -import android.platform.test.flag.junit.CheckFlagsRule; -import android.platform.test.flag.junit.DeviceFlagsValueProvider; import android.provider.Settings; import android.speech.tts.TextToSpeech; import android.speech.tts.Voice; @@ -74,7 +71,6 @@ import android.test.mock.MockContentResolver; import android.view.Window; import android.view.WindowManager; import android.view.accessibility.AccessibilityManager; -import android.view.accessibility.Flags; import android.view.accessibility.IAccessibilityManager; import android.widget.Toast; @@ -87,7 +83,6 @@ import com.android.internal.util.test.FakeSettingsProvider; import org.junit.AfterClass; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -103,9 +98,6 @@ import java.util.Set; @RunWith(AndroidJUnit4.class) public class AccessibilityShortcutControllerTest { - @Rule - public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); - private static final String SERVICE_NAME_STRING = "fake.package/fake.service.name"; private static final CharSequence PACKAGE_NAME_STRING = "Service name"; private static final String SERVICE_NAME_SUMMARY = "Summary"; @@ -440,7 +432,6 @@ public class AccessibilityShortcutControllerTest { } @Test - @RequiresFlagsEnabled(Flags.FLAG_UPDATE_ALWAYS_ON_A11Y_SERVICE) public void turnOffVolumeShortcutForAlwaysOnA11yService_shouldTurnOffA11yService() throws Exception { configureApplicationTargetSdkVersion(Build.VERSION_CODES.R); @@ -452,7 +443,6 @@ public class AccessibilityShortcutControllerTest { } @Test - @RequiresFlagsEnabled(Flags.FLAG_UPDATE_ALWAYS_ON_A11Y_SERVICE) public void turnOffVolumeShortcutForAlwaysOnA11yService_hasOtherTypesShortcut_shouldNotTurnOffA11yService() throws Exception { configureApplicationTargetSdkVersion(Build.VERSION_CODES.R); diff --git a/libs/WindowManager/Shell/res/values/strings.xml b/libs/WindowManager/Shell/res/values/strings.xml index fa6dd3914ddd..bf654d979856 100644 --- a/libs/WindowManager/Shell/res/values/strings.xml +++ b/libs/WindowManager/Shell/res/values/strings.xml @@ -282,6 +282,6 @@ <string name="expand_menu_text">Open Menu</string> <!-- Maximize menu maximize button string. --> <string name="desktop_mode_maximize_menu_maximize_text">Maximize Screen</string> - <!-- Maximize menu maximize button string. --> + <!-- Maximize menu snap buttons string. --> <string name="desktop_mode_maximize_menu_snap_text">Snap Screen</string> </resources> diff --git a/libs/WindowManager/Shell/tests/flicker/pip/csuiteDefaultTemplate.xml b/libs/WindowManager/Shell/tests/flicker/pip/csuiteDefaultTemplate.xml index b3eb2bfd9e9d..f5a8655b81f0 100644 --- a/libs/WindowManager/Shell/tests/flicker/pip/csuiteDefaultTemplate.xml +++ b/libs/WindowManager/Shell/tests/flicker/pip/csuiteDefaultTemplate.xml @@ -38,8 +38,6 @@ <!-- Increase trace size: 20mb for WM and 80mb for SF --> <option name="run-command" value="cmd window tracing size 20480"/> <option name="run-command" value="su root service call SurfaceFlinger 1029 i32 81920"/> - <!-- uninstall Maps, so that latest version can be installed from pStash directly --> - <option name="run-command" value="su root pm uninstall -k --user 0 com.google.android.apps.maps"/> </target_preparer> <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer"> <option name="test-user-token" value="%TEST_USER%"/> @@ -71,7 +69,6 @@ <option name="install-arg" value="-g"/> <option name="install-arg" value="-r"/> <option name="test-file-name" value="pstash://com.netflix.mediaclient"/> - <option name="test-file-name" value="pstash://com.google.android.apps.maps"/> </target_preparer> <!-- Enable mocking GPS location by the test app --> diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt index d21077ee7c5a..a30956ecf5a5 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/common/BiometricHandler.kt @@ -98,7 +98,8 @@ fun runBiometricFlow( context: Context, openMoreOptionsPage: () -> Unit, sendDataToProvider: (EntryInfo, BiometricPrompt.AuthenticationResult) -> Unit, - onCancelFlowAndFinish: (String) -> Unit, + onCancelFlowAndFinish: () -> Unit, + onIllegalStateAndFinish: (String) -> Unit, getRequestDisplayInfo: RequestDisplayInfo? = null, getProviderInfoList: List<ProviderInfo>? = null, getProviderDisplayInfo: ProviderDisplayInfo? = null, @@ -131,7 +132,7 @@ fun runBiometricFlow( val callback: BiometricPrompt.AuthenticationCallback = setupBiometricAuthenticationCallback(sendDataToProvider, biometricEntry, - onCancelFlowAndFinish) + onCancelFlowAndFinish, onIllegalStateAndFinish) val cancellationSignal = CancellationSignal() cancellationSignal.setOnCancelListener { @@ -211,7 +212,8 @@ private fun removeDeviceCredential(requestAllowedAuthenticators: Int): Int { private fun setupBiometricAuthenticationCallback( sendDataToProvider: (EntryInfo, BiometricPrompt.AuthenticationResult) -> Unit, selectedEntry: EntryInfo, - onCancelFlowAndFinish: (String) -> Unit + onCancelFlowAndFinish: () -> Unit, + onIllegalStateAndFinish: (String) -> Unit, ): BiometricPrompt.AuthenticationCallback { val callback: BiometricPrompt.AuthenticationCallback = object : BiometricPrompt.AuthenticationCallback() { @@ -224,14 +226,12 @@ private fun setupBiometricAuthenticationCallback( if (authResult != null) { sendDataToProvider(selectedEntry, authResult) } else { - onCancelFlowAndFinish("The biometric flow succeeded but unexpectedly " + + onIllegalStateAndFinish("The biometric flow succeeded but unexpectedly " + "returned a null value.") - // TODO(b/326243754) : Propagate to provider } } catch (e: Exception) { - onCancelFlowAndFinish("The biometric flow succeeded but failed on handling " + + onIllegalStateAndFinish("The biometric flow succeeded but failed on handling " + "the result. See: \n$e\n") - // TODO(b/326243754) : Propagate to provider } } @@ -245,6 +245,12 @@ private fun setupBiometricAuthenticationCallback( override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) { super.onAuthenticationError(errorCode, errString) Log.d(TAG, "Authentication error-ed out: $errorCode and $errString") + if (errorCode == BiometricPrompt.BIOMETRIC_ERROR_USER_CANCELED) { + // Note that because the biometric prompt is imbued directly + // into the selector, parity applies to the selector's cancellation instead + // of the provider's biometric prompt cancellation. + onCancelFlowAndFinish() + } // TODO(b/326243754) : Propagate to provider } diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt index b59ccc264630..4d7272c7716e 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt @@ -148,7 +148,8 @@ fun GetCredentialScreen( // activeEntry will always be what represents the single tap flow biometricEntry = getCredentialUiState.activeEntry, onMoreOptionSelected = viewModel::getFlowOnMoreOptionSelected, - onCancelFlowAndFinish = viewModel::onIllegalUiState, + onCancelFlowAndFinish = viewModel::onUserCancel, + onIllegalStateAndFinish = viewModel::onIllegalUiState, requestDisplayInfo = getCredentialUiState.requestDisplayInfo, providerInfoList = getCredentialUiState.providerInfoList, providerDisplayInfo = getCredentialUiState.providerDisplayInfo, @@ -212,7 +213,8 @@ fun GetCredentialScreen( @Composable internal fun BiometricSelectionPage( biometricEntry: EntryInfo?, - onCancelFlowAndFinish: (String) -> Unit, + onCancelFlowAndFinish: () -> Unit, + onIllegalStateAndFinish: (String) -> Unit, onMoreOptionSelected: () -> Unit, requestDisplayInfo: RequestDisplayInfo, providerInfoList: List<ProviderInfo>, @@ -230,6 +232,7 @@ internal fun BiometricSelectionPage( openMoreOptionsPage = onMoreOptionSelected, sendDataToProvider = onBiometricEntrySelected, onCancelFlowAndFinish = onCancelFlowAndFinish, + onIllegalStateAndFinish = onIllegalStateAndFinish, getRequestDisplayInfo = requestDisplayInfo, getProviderInfoList = providerInfoList, getProviderDisplayInfo = providerDisplayInfo, diff --git a/services/core/java/com/android/server/am/ActivityManagerDebugConfig.java b/services/core/java/com/android/server/am/ActivityManagerDebugConfig.java index 55b161ad6348..dcda5c228ceb 100644 --- a/services/core/java/com/android/server/am/ActivityManagerDebugConfig.java +++ b/services/core/java/com/android/server/am/ActivityManagerDebugConfig.java @@ -55,9 +55,7 @@ class ActivityManagerDebugConfig { static final boolean DEBUG_BACKGROUND_CHECK = DEBUG_ALL || false; static final boolean DEBUG_BACKUP = DEBUG_ALL || false; static final boolean DEBUG_BROADCAST = DEBUG_ALL || false; - static final boolean DEBUG_BROADCAST_BACKGROUND = DEBUG_BROADCAST || false; static final boolean DEBUG_BROADCAST_LIGHT = DEBUG_BROADCAST || false; - static final boolean DEBUG_BROADCAST_DEFERRAL = DEBUG_BROADCAST || false; static final boolean DEBUG_COMPACTION = DEBUG_ALL || false; static final boolean DEBUG_FREEZER = DEBUG_ALL || false; static final boolean DEBUG_LRU = DEBUG_ALL || false; diff --git a/services/core/java/com/android/server/broadcastradio/BroadcastRadioService.java b/services/core/java/com/android/server/broadcastradio/BroadcastRadioService.java index 3ede0a2597d9..028b9b0bcbc0 100644 --- a/services/core/java/com/android/server/broadcastradio/BroadcastRadioService.java +++ b/services/core/java/com/android/server/broadcastradio/BroadcastRadioService.java @@ -26,7 +26,7 @@ import com.android.server.SystemService; import java.util.ArrayList; -public class BroadcastRadioService extends SystemService { +public final class BroadcastRadioService extends SystemService { private final IRadioService mServiceImpl; public BroadcastRadioService(Context context) { diff --git a/services/core/java/com/android/server/broadcastradio/RadioServiceUserController.java b/services/core/java/com/android/server/broadcastradio/RadioServiceUserController.java index 4b847a27c4de..c705ebe686f2 100644 --- a/services/core/java/com/android/server/broadcastradio/RadioServiceUserController.java +++ b/services/core/java/com/android/server/broadcastradio/RadioServiceUserController.java @@ -48,8 +48,8 @@ public final class RadioServiceUserController { * @return foreground user id. */ public static int getCurrentUser() { - final long identity = Binder.clearCallingIdentity(); int userId = UserHandle.USER_NULL; + final long identity = Binder.clearCallingIdentity(); try { userId = ActivityManager.getCurrentUser(); } catch (RuntimeException e) { diff --git a/services/core/java/com/android/server/broadcastradio/hal1/Convert.java b/services/core/java/com/android/server/broadcastradio/hal1/Convert.java index 219ee4c3229a..08ff6627785a 100644 --- a/services/core/java/com/android/server/broadcastradio/hal1/Convert.java +++ b/services/core/java/com/android/server/broadcastradio/hal1/Convert.java @@ -18,12 +18,13 @@ package com.android.server.broadcastradio.hal1; import android.annotation.NonNull; import android.annotation.Nullable; -import android.util.Slog; + +import com.android.server.utils.Slogf; import java.util.Map; import java.util.Set; -class Convert { +final class Convert { private static final String TAG = "BcRadio1Srv.Convert"; @@ -34,12 +35,12 @@ class Convert { * side, which requires several separate java calls for each element. * * @param map map to convert. - * @returns array (sized the same as map) of two-element string arrays - * (first element is the key, second is value). + * @return array (sized the same as map) of two-element string arrays + * (first element is the key, second is value). */ static @NonNull String[][] stringMapToNative(@Nullable Map<String, String> map) { if (map == null) { - Slog.v(TAG, "map is null, returning zero-elements array"); + Slogf.v(TAG, "map is null, returning zero-elements array"); return new String[0][0]; } @@ -54,7 +55,7 @@ class Convert { i++; } - Slog.v(TAG, "converted " + i + " element(s)"); + Slogf.v(TAG, "converted " + i + " element(s)"); return arr; } } diff --git a/services/core/java/com/android/server/broadcastradio/hal1/Tuner.java b/services/core/java/com/android/server/broadcastradio/hal1/Tuner.java index 8e5f6b5b8624..7cac4091c583 100644 --- a/services/core/java/com/android/server/broadcastradio/hal1/Tuner.java +++ b/services/core/java/com/android/server/broadcastradio/hal1/Tuner.java @@ -26,7 +26,6 @@ import android.hardware.radio.ProgramSelector; import android.hardware.radio.RadioManager; import android.os.IBinder; import android.os.RemoteException; -import android.util.Slog; import com.android.server.broadcastradio.RadioServiceUserController; import com.android.server.utils.Slogf; @@ -44,9 +43,9 @@ class Tuner extends ITuner.Stub { private final long mNativeContext; private final Object mLock = new Object(); - @NonNull private final TunerCallback mTunerCallback; - @NonNull private final ITunerCallback mClientCallback; - @NonNull private final IBinder.DeathRecipient mDeathRecipient; + private final TunerCallback mTunerCallback; + private final ITunerCallback mClientCallback; + private final IBinder.DeathRecipient mDeathRecipient; private boolean mIsClosed = false; private boolean mIsMuted = false; @@ -122,7 +121,7 @@ class Tuner extends ITuner.Stub { private boolean checkConfiguredLocked() { if (mTunerCallback.isInitialConfigurationDone()) return true; - Slog.w(TAG, "Initial configuration is still pending, skipping the operation"); + Slogf.w(TAG, "Initial configuration is still pending, skipping the operation"); return false; } @@ -159,14 +158,14 @@ class Tuner extends ITuner.Stub { checkNotClosedLocked(); if (mIsMuted == mute) return; mIsMuted = mute; - Slog.w(TAG, "Mute via RadioService is not implemented - please handle it via app"); + Slogf.w(TAG, "Mute via RadioService is not implemented - please handle it via app"); } } @Override public boolean isMuted() { if (!mWithAudio) { - Slog.w(TAG, "Tuner did not request audio, pretending it was muted"); + Slogf.w(TAG, "Tuner did not request audio, pretending it was muted"); return true; } synchronized (mLock) { @@ -210,7 +209,7 @@ class Tuner extends ITuner.Stub { if (selector == null) { throw new IllegalArgumentException("The argument must not be a null pointer"); } - Slog.i(TAG, "Tuning to " + selector); + Slogf.i(TAG, "Tuning to " + selector); synchronized (mLock) { checkNotClosedLocked(); if (!checkConfiguredLocked()) return; diff --git a/services/core/java/com/android/server/broadcastradio/hal1/TunerCallback.java b/services/core/java/com/android/server/broadcastradio/hal1/TunerCallback.java index aa43b7581fe7..e013643a812d 100644 --- a/services/core/java/com/android/server/broadcastradio/hal1/TunerCallback.java +++ b/services/core/java/com/android/server/broadcastradio/hal1/TunerCallback.java @@ -25,7 +25,8 @@ import android.hardware.radio.RadioManager; import android.hardware.radio.RadioTuner; import android.os.IBinder; import android.os.RemoteException; -import android.util.Slog; + +import com.android.server.utils.Slogf; import java.util.List; import java.util.Map; @@ -42,8 +43,8 @@ class TunerCallback implements ITunerCallback { */ private final long mNativeContext; - @NonNull private final Tuner mTuner; - @NonNull private final ITunerCallback mClientCallback; + private final Tuner mTuner; + private final ITunerCallback mClientCallback; private final AtomicReference<ProgramList.Filter> mProgramListFilter = new AtomicReference<>(); private boolean mInitialConfigurationDone = false; @@ -76,7 +77,7 @@ class TunerCallback implements ITunerCallback { try { func.run(); } catch (RemoteException e) { - Slog.e(TAG, "client died", e); + Slogf.e(TAG, "client died", e); } } @@ -107,7 +108,7 @@ class TunerCallback implements ITunerCallback { @Override public void onTuneFailed(int result, ProgramSelector selector) { - Slog.e(TAG, "Not applicable for HAL 1.x"); + Slogf.e(TAG, "Not applicable for HAL 1.x"); } @Override @@ -160,7 +161,7 @@ class TunerCallback implements ITunerCallback { try { modified = mTuner.getProgramList(filter.getVendorFilter()); } catch (IllegalStateException ex) { - Slog.d(TAG, "Program list not ready yet"); + Slogf.d(TAG, "Program list not ready yet"); return; } Set<RadioManager.ProgramInfo> modifiedSet = modified.stream().collect(Collectors.toSet()); @@ -175,12 +176,12 @@ class TunerCallback implements ITunerCallback { @Override public void onConfigFlagUpdated(int flag, boolean value) { - Slog.w(TAG, "Not applicable for HAL 1.x"); + Slogf.w(TAG, "Not applicable for HAL 1.x"); } @Override public void onParametersUpdated(Map<String, String> parameters) { - Slog.w(TAG, "Not applicable for HAL 1.x"); + Slogf.w(TAG, "Not applicable for HAL 1.x"); } @Override diff --git a/services/core/java/com/android/server/broadcastradio/hal2/AnnouncementAggregator.java b/services/core/java/com/android/server/broadcastradio/hal2/AnnouncementAggregator.java index 85c13aee37c9..0327ee79d39c 100644 --- a/services/core/java/com/android/server/broadcastradio/hal2/AnnouncementAggregator.java +++ b/services/core/java/com/android/server/broadcastradio/hal2/AnnouncementAggregator.java @@ -23,20 +23,20 @@ import android.hardware.radio.IAnnouncementListener; import android.hardware.radio.ICloseHandle; import android.os.IBinder; import android.os.RemoteException; -import android.util.Slog; import com.android.internal.annotations.GuardedBy; +import com.android.server.utils.Slogf; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Objects; -public class AnnouncementAggregator extends ICloseHandle.Stub { +public final class AnnouncementAggregator extends ICloseHandle.Stub { private static final String TAG = "BcRadio2Srv.AnnAggr"; private final Object mLock; - @NonNull private final IAnnouncementListener mListener; + private final IAnnouncementListener mListener; private final IBinder.DeathRecipient mDeathRecipient = new DeathRecipient(); @GuardedBy("mLock") @@ -77,14 +77,16 @@ public class AnnouncementAggregator extends ICloseHandle.Stub { public void binderDied() { try { close(); - } catch (RemoteException ex) {} + } catch (RemoteException ex) { + Slogf.e(TAG, ex, "Cannot close Announcement aggregator for DeathRecipient"); + } } } private void onListUpdated() { synchronized (mLock) { if (mIsClosed) { - Slog.e(TAG, "Announcement aggregator is closed, it shouldn't receive callbacks"); + Slogf.e(TAG, "Announcement aggregator is closed, it shouldn't receive callbacks"); return; } List<Announcement> combined = new ArrayList<>(); @@ -94,7 +96,7 @@ public class AnnouncementAggregator extends ICloseHandle.Stub { try { mListener.onListUpdated(combined); } catch (RemoteException ex) { - Slog.e(TAG, "mListener.onListUpdated() failed: ", ex); + Slogf.e(TAG, "mListener.onListUpdated() failed: ", ex); } } } @@ -111,7 +113,7 @@ public class AnnouncementAggregator extends ICloseHandle.Stub { try { closeHandle = module.addAnnouncementListener(enabledTypes, watcher); } catch (RemoteException ex) { - Slog.e(TAG, "Failed to add announcement listener", ex); + Slogf.e(TAG, "Failed to add announcement listener", ex); return; } watcher.setCloseHandle(closeHandle); diff --git a/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java b/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java index 1e31f200fd47..3198842c1ff3 100644 --- a/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java +++ b/services/core/java/com/android/server/broadcastradio/hal2/BroadcastRadioService.java @@ -29,8 +29,8 @@ import android.hidl.manager.V1_0.IServiceManager; import android.hidl.manager.V1_0.IServiceNotification; import android.os.IHwBinder.DeathRecipient; import android.os.RemoteException; +import android.util.ArrayMap; import android.util.IndentingPrintWriter; -import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; @@ -38,7 +38,6 @@ import com.android.server.broadcastradio.RadioServiceUserController; import com.android.server.utils.Slogf; import java.util.Collection; -import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; @@ -55,16 +54,17 @@ public final class BroadcastRadioService { private int mNextModuleId; @GuardedBy("mLock") - private final Map<String, Integer> mServiceNameToModuleIdMap = new HashMap<>(); + private final Map<String, Integer> mServiceNameToModuleIdMap = new ArrayMap<>(); // Map from module ID to RadioModule created by mServiceListener.onRegistration(). @GuardedBy("mLock") - private final Map<Integer, RadioModule> mModules = new HashMap<>(); + private final Map<Integer, RadioModule> mModules = new ArrayMap<>(); - private IServiceNotification.Stub mServiceListener = new IServiceNotification.Stub() { + private final IServiceNotification.Stub mServiceListener = new IServiceNotification.Stub() { @Override public void onRegistration(String fqName, String serviceName, boolean preexisting) { - Slog.v(TAG, "onRegistration(" + fqName + ", " + serviceName + ", " + preexisting + ")"); + Slogf.v(TAG, "onRegistration(" + fqName + ", " + serviceName + ", " + preexisting + + ")"); Integer moduleId; synchronized (mLock) { // If the service has been registered before, reuse its previous module ID. @@ -75,13 +75,13 @@ public final class BroadcastRadioService { moduleId = mNextModuleId; } - RadioModule module = RadioModule.tryLoadingModule(moduleId, serviceName); - if (module == null) { + RadioModule radioModule = RadioModule.tryLoadingModule(moduleId, serviceName); + if (radioModule == null) { return; } - Slog.v(TAG, "loaded broadcast radio module " + moduleId + ": " + serviceName + Slogf.v(TAG, "loaded broadcast radio module " + moduleId + ": " + serviceName + " (HAL 2.0)"); - RadioModule prevModule = mModules.put(moduleId, module); + RadioModule prevModule = mModules.put(moduleId, radioModule); if (prevModule != null) { prevModule.closeSessions(RadioTuner.ERROR_HARDWARE_FAILURE); } @@ -92,7 +92,7 @@ public final class BroadcastRadioService { } try { - module.getService().linkToDeath(mDeathRecipient, moduleId); + radioModule.getService().linkToDeath(mDeathRecipient, moduleId); } catch (RemoteException ex) { // Service has already died, so remove its entry from mModules. mModules.remove(moduleId); @@ -101,10 +101,10 @@ public final class BroadcastRadioService { } }; - private DeathRecipient mDeathRecipient = new DeathRecipient() { + private final DeathRecipient mDeathRecipient = new DeathRecipient() { @Override public void serviceDied(long cookie) { - Slog.v(TAG, "serviceDied(" + cookie + ")"); + Slogf.v(TAG, "serviceDied(" + cookie + ")"); synchronized (mLock) { int moduleId = (int) cookie; RadioModule prevModule = mModules.remove(moduleId); @@ -114,7 +114,7 @@ public final class BroadcastRadioService { for (Map.Entry<String, Integer> entry : mServiceNameToModuleIdMap.entrySet()) { if (entry.getValue() == moduleId) { - Slog.i(TAG, "service " + entry.getKey() + Slogf.i(TAG, "service " + entry.getKey() + " died; removed RadioModule with ID " + moduleId); return; } @@ -128,12 +128,12 @@ public final class BroadcastRadioService { try { IServiceManager manager = IServiceManager.getService(); if (manager == null) { - Slog.e(TAG, "failed to get HIDL Service Manager"); + Slogf.e(TAG, "failed to get HIDL Service Manager"); return; } manager.registerForNotifications(IBroadcastRadio.kInterfaceName, "", mServiceListener); } catch (RemoteException ex) { - Slog.e(TAG, "failed to register for service notifications: ", ex); + Slogf.e(TAG, "failed to register for service notifications: ", ex); } } @@ -144,12 +144,12 @@ public final class BroadcastRadioService { try { manager.registerForNotifications(IBroadcastRadio.kInterfaceName, "", mServiceListener); } catch (RemoteException ex) { - Slog.e(TAG, "Failed to register for service notifications: ", ex); + Slogf.e(TAG, "Failed to register for service notifications: ", ex); } } public @NonNull Collection<RadioManager.ModuleProperties> listModules() { - Slog.v(TAG, "List HIDL 2.0 modules"); + Slogf.v(TAG, "List HIDL 2.0 modules"); synchronized (mLock) { return mModules.values().stream().map(module -> module.getProperties()) .collect(Collectors.toList()); @@ -170,7 +170,7 @@ public final class BroadcastRadioService { public ITuner openSession(int moduleId, @Nullable RadioManager.BandConfig legacyConfig, boolean withAudio, @NonNull ITunerCallback callback) throws RemoteException { - Slog.v(TAG, "Open HIDL 2.0 session with module id " + moduleId); + Slogf.v(TAG, "Open HIDL 2.0 session with module id " + moduleId); if (!RadioServiceUserController.isCurrentOrSystemUser()) { Slogf.e(TAG, "Cannot open tuner on HAL 2.0 client for non-current user"); throw new IllegalStateException("Cannot open session for non-current user"); @@ -198,7 +198,7 @@ public final class BroadcastRadioService { public ICloseHandle addAnnouncementListener(@NonNull int[] enabledTypes, @NonNull IAnnouncementListener listener) { - Slog.v(TAG, "Add announcementListener"); + Slogf.v(TAG, "Add announcementListener"); AnnouncementAggregator aggregator = new AnnouncementAggregator(listener, mLock); boolean anySupported = false; synchronized (mLock) { @@ -207,12 +207,12 @@ public final class BroadcastRadioService { aggregator.watchModule(module, enabledTypes); anySupported = true; } catch (UnsupportedOperationException ex) { - Slog.v(TAG, "Announcements not supported for this module", ex); + Slogf.v(TAG, "Announcements not supported for this module", ex); } } } if (!anySupported) { - Slog.i(TAG, "There are no HAL modules that support announcements"); + Slogf.i(TAG, "There are no HAL modules that support announcements"); } return aggregator; } diff --git a/services/core/java/com/android/server/broadcastradio/hal2/Convert.java b/services/core/java/com/android/server/broadcastradio/hal2/Convert.java index fb1138f4bc24..34bfa6cb2d46 100644 --- a/services/core/java/com/android/server/broadcastradio/hal2/Convert.java +++ b/services/core/java/com/android/server/broadcastradio/hal2/Convert.java @@ -37,21 +37,22 @@ import android.hardware.radio.RadioManager; import android.hardware.radio.RadioMetadata; import android.hardware.radio.RadioTuner; import android.os.ParcelableException; -import android.util.Slog; +import android.util.ArrayMap; +import android.util.ArraySet; +import android.util.SparseArray; + +import com.android.server.utils.Slogf; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -class Convert { +final class Convert { private static final String TAG = "BcRadio2Srv.convert"; @@ -111,7 +112,7 @@ class Convert { elem.key = entry.getKey(); elem.value = entry.getValue(); if (elem.key == null || elem.value == null) { - Slog.w(TAG, "VendorKeyValue contains null pointers"); + Slogf.w(TAG, "VendorKeyValue contains null pointers"); continue; } list.add(elem); @@ -120,20 +121,21 @@ class Convert { return list; } - static @NonNull Map<String, String> - vendorInfoFromHal(@Nullable List<VendorKeyValue> info) { - if (info == null) return Collections.emptyMap(); + static @NonNull Map<String, String> vendorInfoFromHal(@Nullable List<VendorKeyValue> info) { + Map<String, String> vendorInfoMap = new ArrayMap<>(); + if (info == null) { + return vendorInfoMap; + } - Map<String, String> map = new HashMap<>(); for (VendorKeyValue kvp : info) { if (kvp.key == null || kvp.value == null) { - Slog.w(TAG, "VendorKeyValue contains null pointers"); + Slogf.w(TAG, "VendorKeyValue contains null pointers"); continue; } - map.put(kvp.key, kvp.value); + vendorInfoMap.put(kvp.key, kvp.value); } - return map; + return vendorInfoMap; } private static @ProgramSelector.ProgramType int identifierTypeToProgramType( @@ -168,7 +170,7 @@ class Convert { private static @NonNull int[] identifierTypesToProgramTypes(@NonNull int[] idTypes) { - Set<Integer> pTypes = new HashSet<>(); + Set<Integer> pTypes = new ArraySet<>(); for (int idType : idTypes) { int pType = identifierTypeToProgramType(idType); @@ -202,7 +204,7 @@ class Convert { for (AmFmBandRange range : config.ranges) { FrequencyBand bandType = Utils.getBand(range.lowerBound); if (bandType == FrequencyBand.UNKNOWN) { - Slog.e(TAG, "Unknown frequency band at " + range.lowerBound + "kHz"); + Slogf.e(TAG, "Unknown frequency band at " + range.lowerBound + "kHz"); continue; } if (bandType == FrequencyBand.FM) { @@ -304,7 +306,7 @@ class Convert { @NonNull android.hardware.broadcastradio.V2_0.ProgramSelector sel) { if (sel.primaryId.type != 0) return false; if (sel.primaryId.value != 0) return false; - if (sel.secondaryIds.size() != 0) return false; + if (!sel.secondaryIds.isEmpty()) return false; return true; } @@ -319,7 +321,7 @@ class Convert { return new ProgramSelector( identifierTypeToProgramType(sel.primaryId.type), Objects.requireNonNull(programIdentifierFromHal(sel.primaryId)), - secondaryIds, null); + secondaryIds, /* vendorIds= */ null); } private enum MetadataType { @@ -335,40 +337,40 @@ class Convert { } } - private static final Map<Integer, MetadataDef> metadataKeys; + private static final SparseArray<MetadataDef> METADATA_KEYS; static { - metadataKeys = new HashMap<>(); - metadataKeys.put(MetadataKey.RDS_PS, new MetadataDef( + METADATA_KEYS = new SparseArray<>(); + METADATA_KEYS.put(MetadataKey.RDS_PS, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_RDS_PS)); - metadataKeys.put(MetadataKey.RDS_PTY, new MetadataDef( + METADATA_KEYS.put(MetadataKey.RDS_PTY, new MetadataDef( MetadataType.INT, RadioMetadata.METADATA_KEY_RDS_PTY)); - metadataKeys.put(MetadataKey.RBDS_PTY, new MetadataDef( + METADATA_KEYS.put(MetadataKey.RBDS_PTY, new MetadataDef( MetadataType.INT, RadioMetadata.METADATA_KEY_RBDS_PTY)); - metadataKeys.put(MetadataKey.RDS_RT, new MetadataDef( + METADATA_KEYS.put(MetadataKey.RDS_RT, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_RDS_RT)); - metadataKeys.put(MetadataKey.SONG_TITLE, new MetadataDef( + METADATA_KEYS.put(MetadataKey.SONG_TITLE, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_TITLE)); - metadataKeys.put(MetadataKey.SONG_ARTIST, new MetadataDef( + METADATA_KEYS.put(MetadataKey.SONG_ARTIST, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_ARTIST)); - metadataKeys.put(MetadataKey.SONG_ALBUM, new MetadataDef( + METADATA_KEYS.put(MetadataKey.SONG_ALBUM, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_ALBUM)); - metadataKeys.put(MetadataKey.STATION_ICON, new MetadataDef( + METADATA_KEYS.put(MetadataKey.STATION_ICON, new MetadataDef( MetadataType.INT, RadioMetadata.METADATA_KEY_ICON)); - metadataKeys.put(MetadataKey.ALBUM_ART, new MetadataDef( + METADATA_KEYS.put(MetadataKey.ALBUM_ART, new MetadataDef( MetadataType.INT, RadioMetadata.METADATA_KEY_ART)); - metadataKeys.put(MetadataKey.PROGRAM_NAME, new MetadataDef( + METADATA_KEYS.put(MetadataKey.PROGRAM_NAME, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_PROGRAM_NAME)); - metadataKeys.put(MetadataKey.DAB_ENSEMBLE_NAME, new MetadataDef( + METADATA_KEYS.put(MetadataKey.DAB_ENSEMBLE_NAME, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_DAB_ENSEMBLE_NAME)); - metadataKeys.put(MetadataKey.DAB_ENSEMBLE_NAME_SHORT, new MetadataDef( + METADATA_KEYS.put(MetadataKey.DAB_ENSEMBLE_NAME_SHORT, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_DAB_ENSEMBLE_NAME_SHORT)); - metadataKeys.put(MetadataKey.DAB_SERVICE_NAME, new MetadataDef( + METADATA_KEYS.put(MetadataKey.DAB_SERVICE_NAME, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_DAB_SERVICE_NAME)); - metadataKeys.put(MetadataKey.DAB_SERVICE_NAME_SHORT, new MetadataDef( + METADATA_KEYS.put(MetadataKey.DAB_SERVICE_NAME_SHORT, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_DAB_SERVICE_NAME_SHORT)); - metadataKeys.put(MetadataKey.DAB_COMPONENT_NAME, new MetadataDef( + METADATA_KEYS.put(MetadataKey.DAB_COMPONENT_NAME, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_DAB_COMPONENT_NAME)); - metadataKeys.put(MetadataKey.DAB_COMPONENT_NAME_SHORT, new MetadataDef( + METADATA_KEYS.put(MetadataKey.DAB_COMPONENT_NAME_SHORT, new MetadataDef( MetadataType.STRING, RadioMetadata.METADATA_KEY_DAB_COMPONENT_NAME_SHORT)); } @@ -376,9 +378,9 @@ class Convert { RadioMetadata.Builder builder = new RadioMetadata.Builder(); for (Metadata entry : meta) { - MetadataDef keyDef = metadataKeys.get(entry.key); + MetadataDef keyDef = METADATA_KEYS.get(entry.key); if (keyDef == null) { - Slog.i(TAG, "Ignored unknown metadata entry: " + MetadataKey.toString(entry.key)); + Slogf.i(TAG, "Ignored unknown metadata entry: " + MetadataKey.toString(entry.key)); continue; } if (keyDef.type == MetadataType.STRING) { diff --git a/services/core/java/com/android/server/broadcastradio/hal2/RadioEventLogger.java b/services/core/java/com/android/server/broadcastradio/hal2/RadioEventLogger.java index 48112c452f02..b8d12280ac05 100644 --- a/services/core/java/com/android/server/broadcastradio/hal2/RadioEventLogger.java +++ b/services/core/java/com/android/server/broadcastradio/hal2/RadioEventLogger.java @@ -19,7 +19,8 @@ package com.android.server.broadcastradio.hal2; import android.util.IndentingPrintWriter; import android.util.LocalLog; import android.util.Log; -import android.util.Slog; + +import com.android.server.utils.Slogf; final class RadioEventLogger { private final String mTag; @@ -30,11 +31,12 @@ final class RadioEventLogger { mEventLogger = new LocalLog(loggerQueueSize); } + @SuppressWarnings("AnnotateFormatMethod") void logRadioEvent(String logFormat, Object... args) { String log = String.format(logFormat, args); mEventLogger.log(log); if (Log.isLoggable(mTag, Log.DEBUG)) { - Slog.d(mTag, log); + Slogf.d(mTag, log); } } diff --git a/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java b/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java index a54af2ef6e44..0e11df8282a7 100644 --- a/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java +++ b/services/core/java/com/android/server/broadcastradio/hal2/RadioModule.java @@ -39,16 +39,16 @@ import android.os.Handler; import android.os.Looper; import android.os.RemoteException; import android.os.UserHandle; +import android.util.ArraySet; import android.util.IndentingPrintWriter; import android.util.MutableInt; -import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.internal.annotations.VisibleForTesting; import com.android.server.broadcastradio.RadioServiceUserController; +import com.android.server.utils.Slogf; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -59,12 +59,12 @@ final class RadioModule { private static final String TAG = "BcRadio2Srv.module"; private static final int RADIO_EVENT_LOGGER_QUEUE_SIZE = 25; - @NonNull private final IBroadcastRadio mService; - @NonNull private final RadioManager.ModuleProperties mProperties; + private final IBroadcastRadio mService; + private final RadioManager.ModuleProperties mProperties; private final Object mLock = new Object(); - @NonNull private final Handler mHandler; - @NonNull private final RadioEventLogger mEventLogger; + private final Handler mHandler; + private final RadioEventLogger mEventLogger; @GuardedBy("mLock") private ITunerSession mHalTunerSession; @@ -144,7 +144,7 @@ final class RadioModule { // Collection of active AIDL tuner sessions created through openSession(). @GuardedBy("mLock") - private final Set<TunerSession> mAidlTunerSessions = new HashSet<>(); + private final Set<TunerSession> mAidlTunerSessions = new ArraySet<>(); @VisibleForTesting RadioModule(@NonNull IBroadcastRadio service, @@ -158,10 +158,10 @@ final class RadioModule { @Nullable static RadioModule tryLoadingModule(int idx, @NonNull String fqName) { try { - Slog.i(TAG, "Try loading module for idx " + idx + ", fqName " + fqName); + Slogf.i(TAG, "Try loading module for idx " + idx + ", fqName " + fqName); IBroadcastRadio service = IBroadcastRadio.getService(fqName); if (service == null) { - Slog.w(TAG, "No service found for fqName " + fqName); + Slogf.w(TAG, "No service found for fqName " + fqName); return null; } @@ -180,7 +180,7 @@ final class RadioModule { return new RadioModule(service, prop); } catch (RemoteException ex) { - Slog.e(TAG, "Failed to load module " + fqName, ex); + Slogf.e(TAG, "Failed to load module " + fqName, ex); return null; } } @@ -256,8 +256,8 @@ final class RadioModule { } if (idTypes == null) { - idTypes = new HashSet<>(filter.getIdentifierTypes()); - ids = new HashSet<>(filter.getIdentifiers()); + idTypes = new ArraySet<>(filter.getIdentifierTypes()); + ids = new ArraySet<>(filter.getIdentifiers()); includeCategories = filter.areCategoriesIncluded(); excludeModifications = filter.areModificationsExcluded(); continue; @@ -305,7 +305,7 @@ final class RadioModule { try { mHalTunerSession.stopProgramListUpdates(); } catch (RemoteException ex) { - Slog.e(TAG, "mHalTunerSession.stopProgramListUpdates() failed: ", ex); + Slogf.e(TAG, "mHalTunerSession.stopProgramListUpdates() failed: ", ex); } return; } @@ -327,7 +327,7 @@ final class RadioModule { newFilter)); Convert.throwOnError("startProgramListUpdates", halResult); } catch (RemoteException ex) { - Slog.e(TAG, "mHalTunerSession.startProgramListUpdates() failed: ", ex); + Slogf.e(TAG, "mHalTunerSession.startProgramListUpdates() failed: ", ex); } } @@ -348,7 +348,7 @@ final class RadioModule { try { mHalTunerSession.close(); } catch (RemoteException ex) { - Slog.e(TAG, "mHalTunerSession.close() failed: ", ex); + Slogf.e(TAG, "mHalTunerSession.close() failed: ", ex); } mHalTunerSession = null; } @@ -385,18 +385,17 @@ final class RadioModule { runnable.run(tunerSession.mCallback); } catch (DeadObjectException ex) { // The other side died without calling close(), so just purge it from our records. - Slog.e(TAG, "Removing dead TunerSession"); + Slogf.e(TAG, "Removing dead TunerSession"); if (deadSessions == null) { deadSessions = new ArrayList<>(); } deadSessions.add(tunerSession); } catch (RemoteException ex) { - Slog.e(TAG, "Failed to invoke ITunerCallback: ", ex); + Slogf.e(TAG, "Failed to invoke ITunerCallback: ", ex); } } if (deadSessions != null) { - onTunerSessionsClosedLocked(deadSessions.toArray( - new TunerSession[deadSessions.size()])); + onTunerSessionsClosedLocked(deadSessions.toArray(new TunerSession[0])); } } @@ -429,7 +428,7 @@ final class RadioModule { try { hwCloseHandle.value.close(); } catch (RemoteException ex) { - Slog.e(TAG, "Failed closing announcement listener", ex); + Slogf.e(TAG, "Failed closing announcement listener", ex); } hwCloseHandle.value = null; } @@ -447,7 +446,9 @@ final class RadioModule { rawImage[i] = rawList.get(i); } - if (rawImage == null || rawImage.length == 0) return null; + if (rawImage.length == 0) { + return null; + } return BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length); } diff --git a/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java b/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java index 978dc01d1219..6d435e38117f 100644 --- a/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java +++ b/services/core/java/com/android/server/broadcastradio/hal2/TunerSession.java @@ -30,27 +30,25 @@ import android.hardware.radio.RadioManager; import android.os.Binder; import android.os.RemoteException; import android.util.ArrayMap; +import android.util.ArraySet; import android.util.IndentingPrintWriter; import android.util.MutableBoolean; import android.util.MutableInt; -import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.server.broadcastradio.RadioServiceUserController; import com.android.server.utils.Slogf; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; -class TunerSession extends ITuner.Stub { +final class TunerSession extends ITuner.Stub { private static final String TAG = "BcRadio2Srv.session"; - private static final String kAudioDeviceName = "Radio tuner source"; private static final int TUNER_EVENT_LOGGER_QUEUE_SIZE = 25; private final Object mLock = new Object(); - @NonNull private final RadioEventLogger mEventLogger; + private final RadioEventLogger mEventLogger; private final RadioModule mModule; private final ITunerSession mHwSession; @@ -99,7 +97,7 @@ class TunerSession extends ITuner.Stub { try { mCallback.onError(error); } catch (RemoteException ex) { - Slog.w(TAG, "mCallback.onError() failed: ", ex); + Slogf.w(TAG, "mCallback.onError() failed: ", ex); } } mModule.onTunerSessionClosed(this); @@ -129,7 +127,7 @@ class TunerSession extends ITuner.Stub { checkNotClosedLocked(); mDummyConfig = Objects.requireNonNull(config); } - Slog.i(TAG, "Ignoring setConfiguration - not applicable for broadcastradio HAL 2.0"); + Slogf.i(TAG, "Ignoring setConfiguration - not applicable for broadcastradio HAL 2.0"); mModule.fanoutAidlCallback(cb -> cb.onConfigurationChanged(config)); } @@ -148,7 +146,7 @@ class TunerSession extends ITuner.Stub { if (mIsMuted == mute) return; mIsMuted = mute; } - Slog.w(TAG, "Mute via RadioService is not implemented - please handle it via app"); + Slogf.w(TAG, "Mute via RadioService is not implemented - please handle it via app"); } @Override @@ -205,7 +203,7 @@ class TunerSession extends ITuner.Stub { @Override public void cancel() { - Slog.i(TAG, "Cancel"); + Slogf.i(TAG, "Cancel"); if (!RadioServiceUserController.isCurrentOrSystemUser()) { Slogf.w(TAG, "Cannot cancel on HAL 2.0 client from non-current user"); return; @@ -218,7 +216,8 @@ class TunerSession extends ITuner.Stub { @Override public void cancelAnnouncement() { - Slog.w(TAG, "Announcements control doesn't involve cancelling at the HAL level in HAL 2.0"); + Slogf.w(TAG, + "Announcements control doesn't involve cancelling at the HAL level in HAL 2.0"); } @Override @@ -229,7 +228,7 @@ class TunerSession extends ITuner.Stub { @Override public boolean startBackgroundScan() { - Slog.w(TAG, "Explicit background scan trigger is not supported with HAL 2.0"); + Slogf.w(TAG, "Explicit background scan trigger is not supported with HAL 2.0"); if (!RadioServiceUserController.isCurrentOrSystemUser()) { Slogf.w(TAG, "Cannot start background scan on HAL 2.0 client from non-current user"); @@ -240,7 +239,7 @@ class TunerSession extends ITuner.Stub { } @Override - public void startProgramListUpdates(ProgramList.Filter filter) throws RemoteException { + public void startProgramListUpdates(ProgramList.Filter filter) { mEventLogger.logRadioEvent("start programList updates %s", filter); if (!RadioServiceUserController.isCurrentOrSystemUser()) { Slogf.w(TAG, @@ -250,8 +249,8 @@ class TunerSession extends ITuner.Stub { // If the AIDL client provides a null filter, it wants all updates, so use the most broad // filter. if (filter == null) { - filter = new ProgramList.Filter(new HashSet<Integer>(), - new HashSet<android.hardware.radio.ProgramSelector.Identifier>(), true, false); + filter = new ProgramList.Filter(new ArraySet<>(), new ArraySet<>(), + /* includeCategories= */ true, /* excludeModifications= */ false); } synchronized (mLock) { checkNotClosedLocked(); @@ -285,7 +284,7 @@ class TunerSession extends ITuner.Stub { if (mProgramInfoCache == null) { return; } - clientUpdateChunks = mProgramInfoCache.filterAndUpdateFrom(halCache, true); + clientUpdateChunks = mProgramInfoCache.filterAndUpdateFrom(halCache, /* purge= */ true); } dispatchClientUpdateChunks(clientUpdateChunks); } @@ -298,7 +297,7 @@ class TunerSession extends ITuner.Stub { try { mCallback.onProgramListUpdated(chunk); } catch (RemoteException ex) { - Slog.w(TAG, "mCallback.onProgramListUpdated() failed: ", ex); + Slogf.w(TAG, "mCallback.onProgramListUpdated() failed: ", ex); } } } |