From bdf6c8ce39a0f182ea6b2b8bb398dd93433e23f8 Mon Sep 17 00:00:00 2001 From: Josep del Rio Date: Mon, 12 Dec 2022 22:06:26 +0000 Subject: [PATCH] Add toast messages when toggling mic from keyboard At the moment, the "microphone mute" key (KEYCODE_MUTE) will just toggle the microphone sensor without any feedback to the user; this change will add a toast message that will inform the user of the state the microphone is in. Test: tested on device Bug: 258853916 Change-Id: I98e04a11395ba0fcb88081b80ffd0098e2e2498c --- core/res/res/values/strings.xml | 4 ++++ core/res/res/values/symbols.xml | 2 ++ .../server/policy/PhoneWindowManager.java | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 8106e247ae638..add7307bbda40 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -6435,4 +6435,8 @@ ul. Start foreground services from background Allows a companion app to start foreground services from background. + + Microphone is available + + Microphone is blocked diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index e8304d801ab2a..35be4ebf3b6a5 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -836,6 +836,8 @@ + + diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java index d5fbe46c55824..7e7dec7d3b81e 100644 --- a/services/core/java/com/android/server/policy/PhoneWindowManager.java +++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java @@ -181,6 +181,7 @@ import android.view.accessibility.AccessibilityManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.autofill.AutofillManagerInternal; +import android.widget.Toast; import com.android.internal.R; import com.android.internal.accessibility.AccessibilityShortcutController; @@ -204,6 +205,7 @@ import com.android.server.ExtconUEventObserver; import com.android.server.GestureLauncherService; import com.android.server.LocalServices; import com.android.server.SystemServiceManager; +import com.android.server.UiThread; import com.android.server.input.InputManagerInternal; import com.android.server.inputmethod.InputMethodManagerInternal; import com.android.server.policy.KeyCombinationManager.TwoKeysCombinationRule; @@ -3220,8 +3222,23 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean isEnabled = mSensorPrivacyManager.isSensorPrivacyEnabled( SensorPrivacyManager.TOGGLE_TYPE_SOFTWARE, SensorPrivacyManager.Sensors.MICROPHONE); + mSensorPrivacyManager.setSensorPrivacy(SensorPrivacyManager.Sensors.MICROPHONE, !isEnabled); + + int toastTextResId; + if (isEnabled) { + toastTextResId = R.string.mic_access_on_toast; + } else { + toastTextResId = R.string.mic_access_off_toast; + } + + Toast.makeText( + mContext, + UiThread.get().getLooper(), + mContext.getString(toastTextResId), + Toast.LENGTH_SHORT) + .show(); } }