Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 308d833d authored by Anthony Tripaldi's avatar Anthony Tripaldi
Browse files

Add Live Caption preference to Accessibility page.

This reverts commit fa27a882.

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
parent d8665574
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -7368,6 +7368,12 @@
    <!-- Sound: Other sounds: Title for the option enabling boot sounds. [CHAR LIMIT=30] -->
    <string name="boot_sounds_title">Power on sounds</string>
    <!-- Setting title for controlling how caption text display in real time [CHAR LIMIT=40]-->
    <string name="live_caption_title">Live Caption</string>
    <!-- Setting summary for controlling how caption text display in real time [CHAR LIMIT=NONE]-->
    <string name="live_caption_summary">Automatically caption media</string>
    <!-- Sound: Summary for the Do not Disturb option when there is no automatic rules turned on. [CHAR LIMIT=NONE]-->
    <string name="zen_mode_settings_summary_off">Never</string>
+6 −0
Original line number Diff line number Diff line
@@ -132,6 +132,12 @@
            android:key="audio_and_captions_category"
            android:title="@string/audio_and_captions_category_title">

        <Preference
            android:key="live_caption"
            android:title="@string/live_caption_title"
            android:summary="@string/live_caption_summary"
            settings:controller="com.android.settings.accessibility.LiveCaptionPreferenceController"/>

        <SwitchPreference
                android:key="toggle_master_mono"
                android:title="@string/accessibility_toggle_master_mono_title"
+14 −2
Original line number Diff line number Diff line
@@ -136,6 +136,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
            "accessibility_control_timeout_preference_fragment";
    private static final String DARK_UI_MODE_PREFERENCE =
            "dark_ui_mode_accessibility";
    private static final String LIVE_CAPTION_PREFERENCE_KEY =
            "live_caption";


    // Extras passed to sub-fragments.
@@ -236,11 +238,13 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
    private Preference mDisplayDaltonizerPreferenceScreen;
    private Preference mHearingAidPreference;
    private Preference mVibrationPreferenceScreen;
    private Preference mLiveCaptionPreference;
    private SwitchPreference mToggleInversionPreference;
    private ColorInversionPreferenceController mInversionPreferenceController;
    private AccessibilityHearingAidPreferenceController mHearingAidPreferenceController;
    private ListPreference mDarkUIModePreference;
    private DarkUIPreferenceController mDarkUIPreferenceController;
    private LiveCaptionPreferenceController mLiveCaptionPreferenceController;

    private int mLongPressTimeoutDefault;

@@ -299,6 +303,9 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
                (context, HEARING_AID_PREFERENCE);
        mHearingAidPreferenceController.setFragmentManager(getFragmentManager());
        getLifecycle().addObserver(mHearingAidPreferenceController);

        mLiveCaptionPreferenceController = new LiveCaptionPreferenceController(context,
                LIVE_CAPTION_PREFERENCE_KEY);
    }

    @Override
@@ -487,6 +494,10 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
        // Captioning.
        mCaptioningPreferenceScreen = findPreference(CAPTIONING_PREFERENCE_SCREEN);

        // Live caption
        mLiveCaptionPreference = findPreference(LIVE_CAPTION_PREFERENCE_KEY);
        mLiveCaptionPreferenceController.displayPreference(getPreferenceScreen());

        // Display magnification.
        mDisplayMagnificationPreferenceScreen = findPreference(
                DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN);
@@ -732,6 +743,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements

        mHearingAidPreferenceController.updateState(mHearingAidPreference);

        mLiveCaptionPreferenceController.updateState(mLiveCaptionPreference);

        updateFeatureSummary(Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED,
                mCaptioningPreferenceScreen);
        updateFeatureSummary(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED,
@@ -752,7 +765,6 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
    }

    void updateAccessibilityTimeoutSummary(ContentResolver resolver, Preference pref) {

        String[] timeoutSummarys = getResources().getStringArray(
                R.array.accessibility_timeout_summaries);
        int[] timeoutValues = getResources().getIntArray(
@@ -821,7 +833,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
        pref.setSummary(entries[index]);
    }

    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
    @VisibleForTesting
    void updateVibrationSummary(Preference pref) {
        final Context context = getContext();
        final Vibrator vibrator = context.getSystemService(Vibrator.class);
+58 −0
Original line number Diff line number Diff line
/*
 * 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 android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;

import com.android.settings.core.BasePreferenceController;

import java.util.List;

public class LiveCaptionPreferenceController extends BasePreferenceController {

    @VisibleForTesting
    static final Intent LIVE_CAPTION_INTENT = new Intent(
            "com.android.settings.action.live_caption");

    private final PackageManager mPackageManager;

    public LiveCaptionPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mPackageManager = context.getPackageManager();
    }

    @Override
    public int getAvailabilityStatus() {
        final List<ResolveInfo> 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
+66 −0
Original line number Diff line number Diff line
/*
 * 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