From 308d833d16802eb2a6b7ea00fc0f0181824ec23b Mon Sep 17 00:00:00 2001 From: Anthony Tripaldi Date: Tue, 26 Mar 2019 10:55:17 -0400 Subject: [PATCH] Add Live Caption preference to Accessibility page. This reverts commit fa27a88292c974eed478fe6a09c3b8be235441d4. The original was only a temporary revert in order to remove from initial beta release for dogfooding before the feature was ready. Reason for revert: b/123652115 Bug:123652115 Test: manual Change-Id: Id647c2992e30289d72a4f6144829a997677be3fa --- res/values/strings.xml | 6 ++ res/xml/accessibility_settings.xml | 6 ++ .../accessibility/AccessibilitySettings.java | 16 ++++- .../LiveCaptionPreferenceController.java | 58 ++++++++++++++++ .../LiveCaptionPreferenceControllerTest.java | 66 +++++++++++++++++++ 5 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 src/com/android/settings/accessibility/LiveCaptionPreferenceController.java create mode 100644 tests/robotests/src/com/android/settings/accessibility/LiveCaptionPreferenceControllerTest.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 9b23ca9a1b1..15f1d9f7f8b 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7368,6 +7368,12 @@ Power on sounds + + Live Caption + + + Automatically caption media + Never diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml index da103c57bf4..1efe2c255f0 100644 --- a/res/xml/accessibility_settings.xml +++ b/res/xml/accessibility_settings.xml @@ -132,6 +132,12 @@ android:key="audio_and_captions_category" android:title="@string/audio_and_captions_category_title"> + + resolved = + mPackageManager.queryIntentActivities(LIVE_CAPTION_INTENT, 0 /* flags */); + return resolved != null && !resolved.isEmpty() + ? AVAILABLE + : UNSUPPORTED_ON_DEVICE; + } + + @Override + public void updateState(Preference preference) { + super.updateState(preference); + preference.setIntent(LIVE_CAPTION_INTENT); + } +} \ No newline at end of file diff --git a/tests/robotests/src/com/android/settings/accessibility/LiveCaptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/accessibility/LiveCaptionPreferenceControllerTest.java new file mode 100644 index 00000000000..9e0ce9c53bd --- /dev/null +++ b/tests/robotests/src/com/android/settings/accessibility/LiveCaptionPreferenceControllerTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.accessibility; + +import static com.android.settings.core.BasePreferenceController.AVAILABLE; +import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.pm.ResolveInfo; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.Shadows; +import org.robolectric.shadows.ShadowPackageManager; + +import java.util.Collections; + +@RunWith(RobolectricTestRunner.class) +public class LiveCaptionPreferenceControllerTest { + + private LiveCaptionPreferenceController mController; + + @Before + public void setUp() { + mController = new LiveCaptionPreferenceController(RuntimeEnvironment.application, + "test_key"); + } + + @Test + public void getAvailabilityStatus_canResolveIntent_shouldReturnAvailable() { + final ShadowPackageManager pm = Shadows.shadowOf( + RuntimeEnvironment.application.getPackageManager()); + pm.addResolveInfoForIntent(LiveCaptionPreferenceController.LIVE_CAPTION_INTENT, + new ResolveInfo()); + + assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); + } + + @Test + public void getAvailabilityStatus_noResolveIntent_shouldReturnUnavailable() { + final ShadowPackageManager pm = Shadows.shadowOf( + RuntimeEnvironment.application.getPackageManager()); + pm.setResolveInfosForIntent(LiveCaptionPreferenceController.LIVE_CAPTION_INTENT, + Collections.emptyList()); + + assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); + } +} \ No newline at end of file