summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/AndroidManifest.xml3
-rw-r--r--packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java1
-rw-r--r--packages/SystemUI/res/color/caption_tint_color_selector.xml3
-rw-r--r--packages/SystemUI/res/layout-land-television/volume_dialog.xml3
-rw-r--r--packages/SystemUI/res/layout-land/volume_dialog.xml3
-rw-r--r--packages/SystemUI/res/layout/volume_dialog.xml3
-rw-r--r--packages/SystemUI/res/values/attrs.xml4
-rw-r--r--packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java7
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/CaptionsToggleImageButton.java21
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java26
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java5
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java8
12 files changed, 35 insertions, 52 deletions
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index 147f3e192207..4b1d00bb18e3 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -311,6 +311,9 @@
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.SUPPRESS_CLIPBOARD_ACCESS_NOTIFICATION" />
+ <!-- To change system captions state -->
+ <uses-permission android:name="android.permission.SET_SYSTEM_AUDIO_CAPTION" />
+
<protected-broadcast android:name="com.android.settingslib.action.REGISTER_SLICE_RECEIVER" />
<protected-broadcast android:name="com.android.settingslib.action.UNREGISTER_SLICE_RECEIVER" />
<protected-broadcast android:name="com.android.settings.flashlight.action.FLASHLIGHT_CHANGED" />
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java
index 0a0530c056af..3d2f570bde87 100644
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java
+++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/VolumeDialogController.java
@@ -60,7 +60,6 @@ public interface VolumeDialogController {
boolean areCaptionsEnabled();
void setCaptionsEnabled(boolean isEnabled);
- boolean isCaptionStreamOptedOut();
void getCaptionsComponentState(boolean fromTooltip);
diff --git a/packages/SystemUI/res/color/caption_tint_color_selector.xml b/packages/SystemUI/res/color/caption_tint_color_selector.xml
index 30843ec70f91..5239d269eb4a 100644
--- a/packages/SystemUI/res/color/caption_tint_color_selector.xml
+++ b/packages/SystemUI/res/color/caption_tint_color_selector.xml
@@ -16,8 +16,5 @@
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sysui="http://schemas.android.com/apk/res-auto">
- <item sysui:optedOut="true"
- android:color="?android:attr/colorButtonNormal"/>
-
<item android:color="?android:attr/colorAccent"/>
</selector> \ No newline at end of file
diff --git a/packages/SystemUI/res/layout-land-television/volume_dialog.xml b/packages/SystemUI/res/layout-land-television/volume_dialog.xml
index 6b5629facd41..0fbc519ca8dd 100644
--- a/packages/SystemUI/res/layout-land-television/volume_dialog.xml
+++ b/packages/SystemUI/res/layout-land-television/volume_dialog.xml
@@ -73,8 +73,7 @@
android:layout_height="match_parent"
android:tint="@color/caption_tint_color_selector"
android:layout_gravity="center"
- android:soundEffectsEnabled="false"
- sysui:optedOut="false"/>
+ android:soundEffectsEnabled="false"/>
</FrameLayout>
diff --git a/packages/SystemUI/res/layout-land/volume_dialog.xml b/packages/SystemUI/res/layout-land/volume_dialog.xml
index f1cda277f045..3b70dc060e84 100644
--- a/packages/SystemUI/res/layout-land/volume_dialog.xml
+++ b/packages/SystemUI/res/layout-land/volume_dialog.xml
@@ -136,8 +136,7 @@
android:layout_height="match_parent"
android:tint="?android:attr/colorAccent"
android:layout_gravity="center"
- android:soundEffectsEnabled="false"
- sysui:optedOut="false"/>
+ android:soundEffectsEnabled="false" />
</FrameLayout>
</LinearLayout>
diff --git a/packages/SystemUI/res/layout/volume_dialog.xml b/packages/SystemUI/res/layout/volume_dialog.xml
index 51718d9af054..6a192d4b7e05 100644
--- a/packages/SystemUI/res/layout/volume_dialog.xml
+++ b/packages/SystemUI/res/layout/volume_dialog.xml
@@ -135,8 +135,7 @@
android:layout_height="match_parent"
android:tint="?android:attr/colorAccent"
android:layout_gravity="center"
- android:soundEffectsEnabled="false"
- sysui:optedOut="false"/>
+ android:soundEffectsEnabled="false"/>
</FrameLayout>
</LinearLayout>
diff --git a/packages/SystemUI/res/values/attrs.xml b/packages/SystemUI/res/values/attrs.xml
index c5e005c556b2..62903d5a7b35 100644
--- a/packages/SystemUI/res/values/attrs.xml
+++ b/packages/SystemUI/res/values/attrs.xml
@@ -154,10 +154,6 @@
<attr name="showAirplaneMode" format="boolean" />
</declare-styleable>
- <declare-styleable name="CaptionsToggleImageButton">
- <attr name="optedOut" format="boolean" />
- </declare-styleable>
-
<declare-styleable name="IlluminationDrawable">
<attr name="highlight" format="integer" />
<attr name="cornerRadius" format="dimension" />
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
index bd472a48ab3e..71c538d9324b 100644
--- a/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
+++ b/packages/SystemUI/src/com/android/systemui/dagger/FrameworkServicesModule.java
@@ -71,6 +71,7 @@ import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.CaptioningManager;
import android.view.inputmethod.InputMethodManager;
import com.android.internal.app.IBatteryStats;
@@ -120,6 +121,12 @@ public class FrameworkServicesModule {
@Provides
@Singleton
+ static CaptioningManager provideCaptioningManager(Context context) {
+ return context.getSystemService(CaptioningManager.class);
+ }
+
+ @Provides
+ @Singleton
static ColorDisplayManager provideColorDisplayManager(Context context) {
return context.getSystemService(ColorDisplayManager.class);
}
diff --git a/packages/SystemUI/src/com/android/systemui/volume/CaptionsToggleImageButton.java b/packages/SystemUI/src/com/android/systemui/volume/CaptionsToggleImageButton.java
index 1862ed3a4de8..ae23ca64e31e 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/CaptionsToggleImageButton.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/CaptionsToggleImageButton.java
@@ -28,14 +28,11 @@ import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.Accessibilit
import com.android.keyguard.AlphaOptimizedImageButton;
import com.android.systemui.R;
-/** Toggle button in Volume Dialog that allows extra state for when streams are opted-out */
+/** Toggle button in Volume Dialog for controlling system captions state */
public class CaptionsToggleImageButton extends AlphaOptimizedImageButton {
- private static final int[] OPTED_OUT_STATE = new int[] { R.attr.optedOut };
-
private ConfirmedTapListener mConfirmedTapListener;
private boolean mCaptionsEnabled = false;
- private boolean mOptedOut = false;
private GestureDetector mGestureDetector;
private GestureDetector.SimpleOnGestureListener mGestureListener =
@@ -60,11 +57,7 @@ public class CaptionsToggleImageButton extends AlphaOptimizedImageButton {
@Override
public int[] onCreateDrawableState(int extraSpace) {
- int[] state = super.onCreateDrawableState(extraSpace + 1);
- if (mOptedOut) {
- mergeDrawableStates(state, OPTED_OUT_STATE);
- }
- return state;
+ return super.onCreateDrawableState(extraSpace + 1);
}
Runnable setCaptionsEnabled(boolean areCaptionsEnabled) {
@@ -95,16 +88,6 @@ public class CaptionsToggleImageButton extends AlphaOptimizedImageButton {
return this.mCaptionsEnabled;
}
- /** Sets whether or not the current stream has opted out of captions */
- void setOptedOut(boolean isOptedOut) {
- this.mOptedOut = isOptedOut;
- refreshDrawableState();
- }
-
- boolean getOptedOut() {
- return this.mOptedOut;
- }
-
void setOnConfirmedTapListener(ConfirmedTapListener listener, Handler handler) {
mConfirmedTapListener = listener;
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java
index 57c7f11b752d..97e03a68205c 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogControllerImpl.java
@@ -54,6 +54,7 @@ import android.util.ArrayMap;
import android.util.Log;
import android.util.Slog;
import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.CaptioningManager;
import androidx.lifecycle.Observer;
@@ -130,6 +131,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
private final Receiver mReceiver = new Receiver();
private final RingerModeObservers mRingerModeObservers;
private final MediaSessions mMediaSessions;
+ private final CaptioningManager mCaptioningManager;
protected C mCallbacks = new C();
private final State mState = new State();
protected final MediaSessionsCallbacks mMediaSessionsCallbacksW;
@@ -175,7 +177,8 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
IAudioService iAudioService,
AccessibilityManager accessibilityManager,
PackageManager packageManager,
- WakefulnessLifecycle wakefulnessLifecycle) {
+ WakefulnessLifecycle wakefulnessLifecycle,
+ CaptioningManager captioningManager) {
mContext = context.getApplicationContext();
mPackageManager = packageManager;
mWakefulnessLifecycle = wakefulnessLifecycle;
@@ -200,6 +203,7 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
mVibrator = vibrator;
mHasVibrator = mVibrator.hasVibrator();
mAudioService = iAudioService;
+ mCaptioningManager = captioningManager;
boolean accessibilityVolumeStreamActive = accessibilityManager
.isAccessibilityVolumeStreamActive();
@@ -307,20 +311,11 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
}
public boolean areCaptionsEnabled() {
- int currentValue = Settings.Secure.getIntForUser(mContext.getContentResolver(),
- Settings.Secure.ODI_CAPTIONS_ENABLED, 0, UserHandle.USER_CURRENT);
- return currentValue == 1;
+ return mCaptioningManager.isSystemAudioCaptioningEnabled();
}
public void setCaptionsEnabled(boolean isEnabled) {
- Settings.Secure.putIntForUser(mContext.getContentResolver(),
- Settings.Secure.ODI_CAPTIONS_ENABLED, isEnabled ? 1 : 0, UserHandle.USER_CURRENT);
- }
-
- @Override
- public boolean isCaptionStreamOptedOut() {
- // TODO(b/129768185): Removing secure setting, to be replaced by sound event listener
- return false;
+ mCaptioningManager.setSystemAudioCaptioningEnabled(isEnabled);
}
public void getCaptionsComponentState(boolean fromTooltip) {
@@ -423,6 +418,13 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
}
private void onGetCaptionsComponentStateW(boolean fromTooltip) {
+ if (mCaptioningManager.isSystemAudioCaptioningUiEnabled()) {
+ mCallbacks.onCaptionComponentStateChanged(true, fromTooltip);
+ return;
+ }
+
+ // TODO(b/220968335): Remove this check once system captions component migrates
+ // to new CaptioningManager APIs.
try {
String componentNameString = mContext.getString(
com.android.internal.R.string.config_defaultSystemCaptionsService);
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
index 58f74a0d2a02..bfdcbd6deb48 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java
@@ -1180,11 +1180,6 @@ public class VolumeDialogImpl implements VolumeDialog,
if (mODICaptionsIcon.getCaptionsEnabled() != captionsEnabled) {
mHandler.post(mODICaptionsIcon.setCaptionsEnabled(captionsEnabled));
}
-
- boolean isOptedOut = mController.isCaptionStreamOptedOut();
- if (mODICaptionsIcon.getOptedOut() != isOptedOut) {
- mHandler.post(() -> mODICaptionsIcon.setOptedOut(isOptedOut));
- }
}
private void onCaptionIconClicked() {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java
index b3805533cabd..ec619bb5952a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/volume/VolumeDialogControllerImplTest.java
@@ -36,6 +36,7 @@ import android.os.Process;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.accessibility.AccessibilityManager;
+import android.view.accessibility.CaptioningManager;
import androidx.test.filters.SmallTest;
@@ -88,6 +89,8 @@ public class VolumeDialogControllerImplTest extends SysuiTestCase {
private PackageManager mPackageManager;
@Mock
private WakefulnessLifecycle mWakefullnessLifcycle;
+ @Mock
+ private CaptioningManager mCaptioningManager;
@Before
@@ -109,7 +112,7 @@ public class VolumeDialogControllerImplTest extends SysuiTestCase {
mVolumeController = new TestableVolumeDialogControllerImpl(mContext,
mBroadcastDispatcher, mRingerModeTracker, mThreadFactory, mAudioManager,
mNotificationManager, mVibrator, mIAudioService, mAccessibilityManager,
- mPackageManager, mWakefullnessLifcycle, mCallback);
+ mPackageManager, mWakefullnessLifcycle, mCaptioningManager, mCallback);
mVolumeController.setEnableDialogs(true, true);
}
@@ -184,10 +187,11 @@ public class VolumeDialogControllerImplTest extends SysuiTestCase {
AccessibilityManager accessibilityManager,
PackageManager packageManager,
WakefulnessLifecycle wakefulnessLifecycle,
+ CaptioningManager captioningManager,
C callback) {
super(context, broadcastDispatcher, ringerModeTracker, theadFactory, audioManager,
notificationManager, optionalVibrator, iAudioService, accessibilityManager,
- packageManager, wakefulnessLifecycle);
+ packageManager, wakefulnessLifecycle, captioningManager);
mCallbacks = callback;
ArgumentCaptor<WakefulnessLifecycle.Observer> observerCaptor =