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

Commit 4db21376 authored by Tim Tsai's avatar Tim Tsai
Browse files

Suppress "Long press power button to turn off TV" toast

The toast can be distracting and annoying when the user presses the
power button multiple times in a row,

This CL suppresses the toast if it was shown in the previous
`turnOffTvToastSuppressionDelay` milliseconds.

Bug: 427116348
Test: manual on device
Flag: NONE small change for TV only

Change-Id: Ib0aa65d19231edf81a08f3ad8a9fc55bffc3623d
parent 156b0ed8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -7663,4 +7663,8 @@
    <!-- Action for opening trusted location settings page [CHAR LIMIT=NONE] [DO NOT TRANSLATE] -->
    <string name="trusted_location_settings_action" translatable="false"></string>

    <!-- The delay in milliseconds to suppress the toast after the user presses the
         power button. -->
    <integer name="config_turnOffTvToastSuppressionDelayMs">0</integer>

</resources>
+1 −0
Original line number Diff line number Diff line
@@ -833,6 +833,7 @@
  <java-symbol type="string" name="lockscreen_emergency_call" />
  <java-symbol type="string" name="lockscreen_return_to_call" />
  <java-symbol type="string" name="long_press_power_to_turn_off_tv_toast" />
  <java-symbol type="integer" name="config_turnOffTvToastSuppressionDelayMs" />
  <java-symbol type="string" name="low_memory" />
  <java-symbol type="string" name="mic_access_off_toast" />
  <java-symbol type="string" name="mic_access_on_toast" />
+15 −6
Original line number Diff line number Diff line
@@ -609,6 +609,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    boolean mWakeOnBackKeyPress;
    boolean mSilenceRingerOnSleepKey;
    long mWakeUpToLastStateTimeout;
    long mTurnOffTvToastSuppressionDelay;
    long mLastShortPressTurnOffTvHintToastTime = 0;
    ComponentName mSearchKeyTargetActivity;

    // Key Behavior - Stem Primary
@@ -1311,6 +1313,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        dreamManagerInternal.requestDream();
        if (mHasFeatureLeanback
                && getResolvedLongPressOnPowerBehavior() == LONG_PRESS_POWER_GO_TO_SLEEP) {
            final long now = SystemClock.uptimeMillis();
            if (now - mLastShortPressTurnOffTvHintToastTime >= mTurnOffTvToastSuppressionDelay) {
                mLastShortPressTurnOffTvHintToastTime = now;
                Toast.makeText(
                        mContext,
                        UiThread.get().getLooper(),
@@ -1319,6 +1324,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                        .show();
            }
        }
    }

    /**
     * Sends the default display to sleep as a result of a power button press.
@@ -2411,6 +2417,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                com.android.internal.R.string.config_searchKeyTargetActivity));
        readConfigurationDependentBehaviors();

        mTurnOffTvToastSuppressionDelay = mContext.getResources().getInteger(
                com.android.internal.R.integer.config_turnOffTvToastSuppressionDelayMs);

        mDisplayFoldController = DisplayFoldController.create(mContext, DEFAULT_DISPLAY);

        mAccessibilityManager = mContext.getSystemService(AccessibilityManager.class);