Integrate captions volume button with new CaptioningManager API

The code that checks for the captions service component will be removed
once the integration in the system captions side will happen.

Also cleans up the unused stream opt-out property.

Change-Id: I606f0d7a5319bbdc54b2e853fb70ea44ff9645a0
Bug: 221021539.
Bug: 136282740.
Test: Manually.
This commit is contained in:
Nadav Bar
2022-02-23 12:24:11 +00:00
parent 038fd80ce8
commit 904975fd69
12 changed files with 35 additions and 52 deletions

View File

@@ -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" />

View File

@@ -60,7 +60,6 @@ public interface VolumeDialogController {
boolean areCaptionsEnabled();
void setCaptionsEnabled(boolean isEnabled);
boolean isCaptionStreamOptedOut();
void getCaptionsComponentState(boolean fromTooltip);

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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>

View File

@@ -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" />

View File

@@ -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;
@@ -118,6 +119,12 @@ public class FrameworkServicesModule {
return context.getSystemService(AudioManager.class);
}
@Provides
@Singleton
static CaptioningManager provideCaptioningManager(Context context) {
return context.getSystemService(CaptioningManager.class);
}
@Provides
@Singleton
static ColorDisplayManager provideColorDisplayManager(Context context) {

View File

@@ -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;

View File

@@ -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);

View File

@@ -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() {

View File

@@ -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 =