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

Commit fff9fd87 authored by Adrian Roos's avatar Adrian Roos
Browse files

Assist: Allow disabling the disclosure animation

Change-Id: I18a2e4144c762a0833d2384c51f916b841dfc8b3
Fixes: 30809067
parent 7f6d27b1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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>
+6 −0
Original line number Diff line number Diff line
@@ -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"
+35 −10
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.os.Handler;
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 @@ public class ManageAssist extends SettingsPreferenceFragment
    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 @@ public class ManageAssist extends SettingsPreferenceFragment
        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 @@ public class ManageAssist extends SettingsPreferenceFragment
        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 @@ public class ManageAssist extends SettingsPreferenceFragment
                    (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 @@ public class ManageAssist extends SettingsPreferenceFragment
        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 @@ public class ManageAssist extends SettingsPreferenceFragment
        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 @@ public class ManageAssist extends SettingsPreferenceFragment
        } 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 @@ public class ManageAssist extends SettingsPreferenceFragment
        }

        guardScreenshotPref();
        guardFlashPref();
    }

    private boolean isCurrentAssistVoiceService() {