Assist: Allow disabling the disclosure animation

Change-Id: I18a2e4144c762a0833d2384c51f916b841dfc8b3
Fixes: 30809067
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ad14781..f683d80 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6951,6 +6951,11 @@
     <!-- Summary for the "screenshot" preference to determine whether assist can access the screenshot of your screen [CHAR LIMIT=NONE] -->
     <string name="assist_access_screenshot_summary">Allow the assist app to access an image of the screen</string>
 
+    <!-- Title for the "flash" preference to determine whether a flash is shown on screen when an assistant accesses the contents of the screeen. [CHAR LIMIT=40] -->
+    <string name="assist_flash_title">Flash screen</string>
+
+    <!-- Summary for the "flash" preference to determine whether a flash is shown on screen when an assistant accesses the contents of the screeen. [CHAR LIMIT=NONE] -->
+    <string name="assist_flash_summary">Flash edges of screen when assist app accesses text from screen or screenshot</string>
 
     <!-- Footer text in the manage assist screen. [CHAR LIMIT=NONE] -->
     <string name="assist_footer">Assist apps can help you based on information from the screen you\u2019re viewing. Some apps support both launcher and voice input services to give you integrated assistance.</string>
@@ -7759,4 +7764,5 @@
 
     <string name="automatic_storage_manager_freed_bytes"><xliff:g id="size" example="3.25MB">%1$s</xliff:g> total made available\n\nLast ran on <xliff:g id="date" example="Jan 12">%2$s</xliff:g></string>
 
+
 </resources>
diff --git a/res/xml/manage_assist.xml b/res/xml/manage_assist.xml
index 6984f88..7d4928d 100644
--- a/res/xml/manage_assist.xml
+++ b/res/xml/manage_assist.xml
@@ -36,6 +36,12 @@
         android:title="@string/assist_access_screenshot_title"
         android:summary="@string/assist_access_screenshot_summary"/>
 
+    <SwitchPreference
+            android:key="flash"
+            android:title="@string/assist_flash_title"
+            android:summary="@string/assist_flash_summary"
+    />
+
     <com.android.settings.voice.VoiceInputListPreference
             android:key="voice_input_settings"
             android:title="@string/voice_input_settings_title"
diff --git a/src/com/android/settings/applications/ManageAssist.java b/src/com/android/settings/applications/ManageAssist.java
index 02875b6..9947aa2 100644
--- a/src/com/android/settings/applications/ManageAssist.java
+++ b/src/com/android/settings/applications/ManageAssist.java
@@ -24,6 +24,8 @@
 import android.provider.Settings;
 import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.Preference;
+
+import com.android.internal.app.AssistUtils;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.SettingsPreferenceFragment;
@@ -39,10 +41,12 @@
     private static final String KEY_CONTEXT = "context";
     private static final String KEY_SCREENSHOT = "screenshot";
     private static final String KEY_VOICE_INPUT = "voice_input_settings";
+    private static final String KEY_FLASH = "flash";
 
     private DefaultAssistPreference mDefaultAssitPref;
     private SwitchPreference mContextPref;
     private SwitchPreference mScreenshotPref;
+    private SwitchPreference mFlashPref;
     private VoiceInputListPreference mVoiceInputPref;
     private Handler mHandler = new Handler();
 
@@ -62,6 +66,9 @@
         mScreenshotPref = (SwitchPreference) findPreference(KEY_SCREENSHOT);
         mScreenshotPref.setOnPreferenceChangeListener(this);
 
+        mFlashPref = (SwitchPreference) findPreference(KEY_FLASH);
+        mFlashPref.setOnPreferenceChangeListener(this);
+
         mVoiceInputPref = (VoiceInputListPreference) findPreference(KEY_VOICE_INPUT);
         updateUi();
     }
@@ -76,7 +83,10 @@
         if (preference == mContextPref) {
             Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSIST_STRUCTURE_ENABLED,
                     (boolean) newValue ? 1 : 0);
-            postGuardScreenshotPref();
+            mHandler.post(() -> {
+                guardScreenshotPref();
+                guardFlashPref();
+            });
             return true;
         }
         if (preference == mScreenshotPref) {
@@ -84,6 +94,11 @@
                     (boolean) newValue ? 1 : 0);
             return true;
         }
+        if (preference == mFlashPref) {
+            Settings.Secure.putInt(getContentResolver(), Settings.Secure.ASSIST_DISCLOSURE_ENABLED,
+                    (boolean) newValue ? 1 : 0);
+            return true;
+        }
         if (preference == mDefaultAssitPref) {
             String newAssitPackage = (String)newValue;
             if (newAssitPackage == null ||
@@ -101,15 +116,6 @@
         return false;
     }
 
-    private void postGuardScreenshotPref() {
-        mHandler.post(new Runnable() {
-            @Override
-            public void run() {
-                guardScreenshotPref();
-            }
-        });
-    }
-
     private void guardScreenshotPref() {
         boolean isChecked = mContextPref.isChecked();
         boolean screenshotPrefWasSet = Settings.Secure.getInt(
@@ -118,6 +124,17 @@
         mScreenshotPref.setChecked(isChecked && screenshotPrefWasSet);
     }
 
+    private void guardFlashPref() {
+        ComponentName assistant = mDefaultAssitPref.getCurrentAssist();
+
+        boolean isContextChecked = mContextPref.isChecked();
+        boolean willShowFlash = AssistUtils.shouldDisclose(getContext(), assistant);
+        boolean isSystemAssistant = AssistUtils.isPreinstalledAssistant(getContext(), assistant);
+
+        mFlashPref.setEnabled(isContextChecked && isSystemAssistant);
+        mFlashPref.setChecked(willShowFlash);
+    }
+
     private void updateUi() {
         mDefaultAssitPref.refreshAssistApps();
         mVoiceInputPref.refreshVoiceInputs();
@@ -130,6 +147,13 @@
         } else {
             getPreferenceScreen().removePreference(mContextPref);
             getPreferenceScreen().removePreference(mScreenshotPref);
+            getPreferenceScreen().removePreference(mFlashPref);
+        }
+
+        if (hasAssistant && AssistUtils.allowDisablingAssistDisclosure(getContext())) {
+            getPreferenceScreen().addPreference(mFlashPref);
+        } else {
+            getPreferenceScreen().removePreference(mFlashPref);
         }
 
         if (isCurrentAssistVoiceService()) {
@@ -140,6 +164,7 @@
         }
 
         guardScreenshotPref();
+        guardFlashPref();
     }
 
     private boolean isCurrentAssistVoiceService() {