Add deep link to caption settings for Android.
Adds 'Captions' entry to Accessibility preferences that opens corresponding system Settings.
Gated by the "Caption settings" feature flag.
Bug: 976966
Change-Id: I2cd4b2bec1412941971be5a828f6750ff92a2d92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1658640
Commit-Queue: Evan Liu <evliu@google.com>
Reviewed-by: Theresa <twellington@chromium.org>
Reviewed-by: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671116}
diff --git a/chrome/android/java/res/xml/accessibility_preferences.xml b/chrome/android/java/res/xml/accessibility_preferences.xml
index 36740e45..2a57b00 100644
--- a/chrome/android/java/res/xml/accessibility_preferences.xml
+++ b/chrome/android/java/res/xml/accessibility_preferences.xml
@@ -25,4 +25,8 @@
android:summary="@string/accessibility_tab_switcher_summary"
android:title="@string/accessibility_tab_switcher_title" />
+ <android.support.v7.preference.Preference
+ android:key="captions"
+ android:title="@string/accessibility_captions_title"/>
+
</android.support.v7.preference.PreferenceScreen>
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeFeatureList.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeFeatureList.java
index 0d3f770..475f7f7 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeFeatureList.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeFeatureList.java
@@ -175,6 +175,7 @@
public static final String AUTOFILL_KEYBOARD_ACCESSORY = "AutofillKeyboardAccessory";
public static final String BACKGROUND_TASK_SCHEDULER_FOR_BACKGROUND_SYNC =
"BackgroundTaskSchedulerForBackgroundSync";
+ public static final String CAPTION_SETTINGS = "CaptionSettings";
public static final String CAPTIVE_PORTAL_CERTIFICATE_LIST = "CaptivePortalCertificateList";
public static final String CCT_BACKGROUND_TAB = "CCTBackgroundTab";
public static final String CCT_MODULE = "CCTModule";
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/AccessibilityPreferences.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/AccessibilityPreferences.java
index e0076e72..28dd5cd8 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/AccessibilityPreferences.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/AccessibilityPreferences.java
@@ -4,11 +4,14 @@
package org.chromium.chrome.browser.preferences;
+import android.content.Intent;
import android.os.Bundle;
+import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.accessibility.FontSizePrefs;
import org.chromium.chrome.browser.accessibility.FontSizePrefs.FontSizePrefsObserver;
import org.chromium.chrome.browser.util.AccessibilityUtil;
@@ -23,6 +26,7 @@
static final String PREF_TEXT_SCALE = "text_scale";
static final String PREF_FORCE_ENABLE_ZOOM = "force_enable_zoom";
static final String PREF_READER_FOR_ACCESSIBILITY = "reader_for_accessibility";
+ static final String PREF_CAPTIONS = "captions";
private NumberFormat mFormat;
private FontSizePrefs mFontSizePrefs;
@@ -73,6 +77,22 @@
} else {
getPreferenceScreen().removePreference(mAccessibilityTabSwitcherPref);
}
+
+ Preference captions = findPreference(PREF_CAPTIONS);
+ if (ChromeFeatureList.isEnabled(ChromeFeatureList.CAPTION_SETTINGS)) {
+ captions.setOnPreferenceClickListener(preference -> {
+ Intent intent = new Intent(Settings.ACTION_CAPTIONING_SETTINGS);
+
+ // Open the activity in a new task because the back button on the caption
+ // settings page navigates to the previous settings page instead of Chrome.
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+
+ return true;
+ });
+ } else {
+ getPreferenceScreen().removePreference(captions);
+ }
}
@Override
diff --git a/chrome/android/java/strings/android_chrome_strings.grd b/chrome/android/java/strings/android_chrome_strings.grd
index d85d798f..8136f9a 100644
--- a/chrome/android/java/strings/android_chrome_strings.grd
+++ b/chrome/android/java/strings/android_chrome_strings.grd
@@ -893,6 +893,9 @@
<message name="IDS_ACCESSIBILITY_TAB_SWITCHER_SUMMARY" desc="Summary of the preference that allows the user to use a simplified tab switcher. The simplified tab switcher is recommended for use with TalkBack and Switch Access which are accessibility services provided by Android. TalkBack does not need to be translated. 'Switch Access' translation should match TC ID 382005103867249841.">
Recommended when TalkBack or Switch Access are on
</message>
+ <message name="IDS_ACCESSIBILITY_CAPTIONS_TITLE" desc="Title of the preference that allows the user to update caption settings.">
+ Captions
+ </message>
<!-- Site settings -->
<message name="IDS_PREFS_SITE_SETTINGS" desc="Title of the Website Settings screen. [CHAR-LIMIT=32]">
diff --git a/chrome/android/java/strings/android_chrome_strings_grd/IDS_ACCESSIBILITY_CAPTIONS.png.sha1 b/chrome/android/java/strings/android_chrome_strings_grd/IDS_ACCESSIBILITY_CAPTIONS.png.sha1
new file mode 100644
index 0000000..2d45e9c3
--- /dev/null
+++ b/chrome/android/java/strings/android_chrome_strings_grd/IDS_ACCESSIBILITY_CAPTIONS.png.sha1
@@ -0,0 +1 @@
+bdf6fac24fd777a97083724a1efa16007fb7a77c
\ No newline at end of file
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java
index 3a1e77d7..f5cb129 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java
@@ -14,9 +14,11 @@
import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
+import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
@@ -33,6 +35,7 @@
import org.chromium.base.test.util.FlakyTest;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.accessibility.FontSizePrefs;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.preferences.website.ContentSettingValues;
@@ -42,6 +45,7 @@
import org.chromium.chrome.browser.test.ChromeBrowserTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.ActivityUtils;
+import org.chromium.chrome.test.util.browser.Features.EnableFeatures;
import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.search_engines.TemplateUrlService;
import org.chromium.components.search_engines.TemplateUrlService.LoadListener;
@@ -63,6 +67,7 @@
* Tests for the Settings menu.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
+@EnableFeatures(ChromeFeatureList.CAPTION_SETTINGS)
public class PreferencesTest {
@Rule
public final ChromeBrowserTestRule mBrowserTestRule = new ChromeBrowserTestRule();
@@ -356,6 +361,29 @@
@Test
@SmallTest
+ @Feature({"Accessibility"})
+ public void testCaptionPreferences() throws Exception {
+ String accessibilityPrefClassname = AccessibilityPreferences.class.getName();
+ AccessibilityPreferences accessibilityPref = (AccessibilityPreferences) startPreferences(
+ InstrumentationRegistry.getInstrumentation(), accessibilityPrefClassname)
+ .getMainFragmentCompat();
+ android.support.v7.preference.Preference captionsPref =
+ accessibilityPref.findPreference(AccessibilityPreferences.PREF_CAPTIONS);
+ Assert.assertNotNull(captionsPref);
+ Assert.assertNotNull(captionsPref.getOnPreferenceClickListener());
+
+ Instrumentation.ActivityMonitor monitor =
+ InstrumentationRegistry.getInstrumentation().addMonitor(
+ new IntentFilter(Settings.ACTION_CAPTIONING_SETTINGS), null, false);
+
+ onView(withText(R.string.accessibility_captions_title)).perform(click());
+ monitor.waitForActivityWithTimeout(CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL);
+ Assert.assertEquals("Monitor for has not been called", 1, monitor.getHits());
+ InstrumentationRegistry.getInstrumentation().removeMonitor(monitor);
+ }
+
+ @Test
+ @SmallTest
@Policies.Add({ @Policies.Item(key = "PasswordManagerEnabled", string = "false") })
public void testSavePasswordsPreferences_ManagedAndDisabled() throws ExecutionException {
TestThreadUtils.runOnUiThreadBlocking(() -> {
diff --git a/chrome/browser/android/chrome_feature_list.cc b/chrome/browser/android/chrome_feature_list.cc
index 17361186..464cfa3aa 100644
--- a/chrome/browser/android/chrome_feature_list.cc
+++ b/chrome/browser/android/chrome_feature_list.cc
@@ -63,6 +63,7 @@
&download::features::kUseDownloadOfflineContentProvider,
&features::kAllowStartingServiceManagerOnly,
&features::kAppNotificationStatusMessaging,
+ &features::kCaptionSettings,
&features::kClearOldBrowsingData,
&features::kDownloadsLocationChange,
&features::kGenericSensorExtraClasses,