diff options
3 files changed, 82 insertions, 24 deletions
diff --git a/packages/SystemUI/res/values/config_tv.xml b/packages/SystemUI/res/values/config_tv.xml index ffd58dcfd50d..d8c9428f2676 100644 --- a/packages/SystemUI/res/values/config_tv.xml +++ b/packages/SystemUI/res/values/config_tv.xml @@ -22,4 +22,13 @@ <!-- Bounds [left top right bottom] on screen for picture-in-picture (PIP) windows, when the PIP menu is shown in center. --> <string translatable="false" name="pip_menu_bounds">"596 280 1324 690"</string> + + <!-- Whether to enable microphone disclosure indicator + (com.android.systemui.statusbar.tv.micdisclosure.AudioRecordingDisclosureBar). --> + <bool name="audio_recording_disclosure_enabled">true</bool> + + <!-- Whether the indicator should expand and show the recording application's label. + When disabled (false) the "minimized" indicator would appear on the screen whenever an + application is recording, but will not reveal to the user what application this is. --> + <bool name="audio_recording_disclosure_reveal_packages">false</bool> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java index 6bc0565510a2..c0602762ef29 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tv/TvStatusBar.java @@ -26,6 +26,7 @@ import android.os.ServiceManager; import android.os.UserHandle; import com.android.internal.statusbar.IStatusBarService; +import com.android.systemui.R; import com.android.systemui.SystemUI; import com.android.systemui.assist.AssistManager; import com.android.systemui.statusbar.CommandQueue; @@ -72,6 +73,11 @@ public class TvStatusBar extends SystemUI implements CommandQueue.Callbacks { } catch (RemoteException ex) { // If the system process isn't there we're doomed anyway. } + + if (mContext.getResources().getBoolean(R.bool.audio_recording_disclosure_enabled)) { + // Creating AudioRecordingDisclosureBar and just letting it run + new AudioRecordingDisclosureBar(mContext); + } } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tv/micdisclosure/AudioRecordingDisclosureBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tv/micdisclosure/AudioRecordingDisclosureBar.java index 36e360da857f..8e4e12358836 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tv/micdisclosure/AudioRecordingDisclosureBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tv/micdisclosure/AudioRecordingDisclosureBar.java @@ -112,6 +112,13 @@ public class AudioRecordingDisclosureBar implements */ private final AudioActivityObserver[] mAudioActivityObservers; /** + * Whether the indicator should expand and show the recording application's label. + * If disabled ({@code false}) the "minimized" ({@link #STATE_MINIMIZED}) indicator would appear + * on the screen whenever an application is recording, but will not reveal to the user what + * application this is. + */ + private final boolean mRevealRecordingPackages; + /** * Set of applications that we've notified the user about since the indicator came up. Meaning * that if an application is in this list then at some point since the indicator came up, it * was expanded showing this application's title. @@ -137,6 +144,8 @@ public class AudioRecordingDisclosureBar implements public AudioRecordingDisclosureBar(Context context) { mContext = context; + mRevealRecordingPackages = mContext.getResources().getBoolean( + R.bool.audio_recording_disclosure_reveal_packages); mExemptPackages = new ArraySet<>( Arrays.asList(mContext.getResources().getStringArray( R.array.audio_recording_disclosure_exempt_apps))); @@ -149,11 +158,6 @@ public class AudioRecordingDisclosureBar implements }; } - private String[] getGlobalStringArray(String setting) { - String result = Settings.Global.getString(mContext.getContentResolver(), setting); - return TextUtils.isEmpty(result) ? new String[0] : result.split(","); - } - @UiThread @Override public void onAudioActivityStateChange(boolean active, String packageName) { @@ -190,7 +194,9 @@ public class AudioRecordingDisclosureBar implements break; case STATE_MINIMIZED: - expand(packageName); + if (mRevealRecordingPackages) { + expand(packageName); + } break; case STATE_DISAPPEARING: @@ -228,9 +234,8 @@ public class AudioRecordingDisclosureBar implements @UiThread private void show(String packageName) { - final String label = getApplicationLabel(packageName); if (DEBUG) { - Log.d(TAG, "Showing indicator for " + packageName + " (" + label + ")..."); + Log.d(TAG, "Showing indicator for " + packageName); } mIsLtr = mContext.getResources().getConfiguration().getLayoutDirection() @@ -247,19 +252,31 @@ public class AudioRecordingDisclosureBar implements mTextView = mTextsContainers.findViewById(R.id.text); mBgEnd = mIndicatorView.findViewById(R.id.bg_end); - // Swap background drawables depending on layout directions (both drawables have rounded - // corners only on one side) - if (mIsLtr) { - mBgEnd.setBackgroundResource(R.drawable.tv_rect_dark_right_rounded); - mIconContainerBg.setBackgroundResource(R.drawable.tv_rect_dark_left_rounded); + // Set up the notification text + if (mRevealRecordingPackages) { + // Swap background drawables depending on layout directions (both drawables have rounded + // corners only on one side) + if (mIsLtr) { + mBgEnd.setBackgroundResource(R.drawable.tv_rect_dark_right_rounded); + mIconContainerBg.setBackgroundResource(R.drawable.tv_rect_dark_left_rounded); + } else { + mBgEnd.setBackgroundResource(R.drawable.tv_rect_dark_left_rounded); + mIconContainerBg.setBackgroundResource(R.drawable.tv_rect_dark_right_rounded); + } + + final String label = getApplicationLabel(packageName); + mTextView.setText(mContext.getString(R.string.app_accessed_mic, label)); } else { - mBgEnd.setBackgroundResource(R.drawable.tv_rect_dark_left_rounded); - mIconContainerBg.setBackgroundResource(R.drawable.tv_rect_dark_right_rounded); + mTextsContainers.setVisibility(View.GONE); + mIconContainerBg.setVisibility(View.GONE); + mTextView.setVisibility(View.GONE); + mBgEnd.setVisibility(View.GONE); + mTextsContainers = null; + mIconContainerBg = null; + mTextView = null; + mBgEnd = null; } - // Set up the notification text - mTextView.setText(mContext.getString(R.string.app_accessed_mic, label)); - // Initially change the visibility to INVISIBLE, wait until and receives the size and // then animate it moving from "off" the screen correctly mIndicatorView.setVisibility(View.INVISIBLE); @@ -296,7 +313,11 @@ public class AudioRecordingDisclosureBar implements @Override public void onAnimationEnd(Animator animation) { startPulsatingAnimation(); - onExpanded(); + if (mRevealRecordingPackages) { + onExpanded(); + } else { + onMinimized(); + } } }); set.start(); @@ -321,6 +342,8 @@ public class AudioRecordingDisclosureBar implements @UiThread private void expand(String packageName) { + assertRevealingRecordingPackages(); + final String label = getApplicationLabel(packageName); if (DEBUG) { Log.d(TAG, "Expanding for " + packageName + " (" + label + ")..."); @@ -348,6 +371,8 @@ public class AudioRecordingDisclosureBar implements @UiThread private void minimize() { + assertRevealingRecordingPackages(); + if (DEBUG) Log.d(TAG, "Minimizing..."); final int targetOffset = (mIsLtr ? 1 : -1) * mTextsContainers.getWidth(); final AnimatorSet set = new AnimatorSet(); @@ -393,6 +418,8 @@ public class AudioRecordingDisclosureBar implements @UiThread private void onExpanded() { + assertRevealingRecordingPackages(); + if (DEBUG) Log.d(TAG, "Expanded"); mState = STATE_SHOWN; @@ -404,11 +431,13 @@ public class AudioRecordingDisclosureBar implements if (DEBUG) Log.d(TAG, "Minimized"); mState = STATE_MINIMIZED; - if (!mPendingNotificationPackages.isEmpty()) { - // There is a new application that started recording, tell the user about it. - expand(mPendingNotificationPackages.poll()); - } else { - hideIndicatorIfNeeded(); + if (mRevealRecordingPackages) { + if (!mPendingNotificationPackages.isEmpty()) { + // There is a new application that started recording, tell the user about it. + expand(mPendingNotificationPackages.poll()); + } else { + hideIndicatorIfNeeded(); + } } } @@ -451,7 +480,14 @@ public class AudioRecordingDisclosureBar implements animator.start(); } + private String[] getGlobalStringArray(String setting) { + String result = Settings.Global.getString(mContext.getContentResolver(), setting); + return TextUtils.isEmpty(result) ? new String[0] : result.split(","); + } + private String getApplicationLabel(String packageName) { + assertRevealingRecordingPackages(); + final PackageManager pm = mContext.getPackageManager(); final ApplicationInfo appInfo; try { @@ -461,4 +497,11 @@ public class AudioRecordingDisclosureBar implements } return pm.getApplicationLabel(appInfo).toString(); } + + private void assertRevealingRecordingPackages() { + if (!mRevealRecordingPackages) { + Log.e(TAG, "Not revealing recording packages", + DEBUG ? new RuntimeException("Should not be called") : null); + } + } } |