diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/tv/AudioRecordingDisclosureBar.java | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tv/AudioRecordingDisclosureBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tv/AudioRecordingDisclosureBar.java index 74739e19ede9..73ffe42daac5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tv/AudioRecordingDisclosureBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tv/AudioRecordingDisclosureBar.java @@ -43,7 +43,6 @@ import com.android.systemui.R; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Arrays; -import java.util.HashSet; import java.util.LinkedList; import java.util.Queue; import java.util.Set; @@ -98,8 +97,27 @@ class AudioRecordingDisclosureBar { private TextView mTextView; @State private int mState = STATE_NOT_SHOWN; - private final Set<String> mAudioRecordingApps = new HashSet<>(); - private final Queue<String> mPendingNotifications = new LinkedList<>(); + /** + * Set of the applications that currently are conducting audio recording. + */ + private final Set<String> mActiveAudioRecordingPackages = new ArraySet<>(); + /** + * 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. + * Used not to notify the user about the same application again while the indicator is shown. + * We empty this set every time the indicator goes off the screen (we always call {@code + * mSessionNotifiedPackages.clear()} before calling {@link #hide()}). + */ + private final Set<String> mSessionNotifiedPackages = new ArraySet<>(); + /** + * If an application starts recording while the TV indicator is neither in {@link + * #STATE_NOT_SHOWN} nor in {@link #STATE_MINIMIZED}, then we add the application's package + * name to the queue, from which we take packages names one by one to disclose the + * corresponding applications' titles to the user, whenever the indicator eventually comes to + * one of the two aforementioned states. + */ + private final Queue<String> mPendingNotificationPackages = new LinkedList<>(); AudioRecordingDisclosureBar(Context context) { mContext = context; @@ -116,10 +134,14 @@ class AudioRecordingDisclosureBar { } private void onStartedRecording(String packageName) { - if (!mAudioRecordingApps.add(packageName)) { + if (!mActiveAudioRecordingPackages.add(packageName)) { // This app is already known to perform recording return; } + if (!mSessionNotifiedPackages.add(packageName)) { + // We've already notified user about this app, no need to do it again. + return; + } switch (mState) { case STATE_NOT_SHOWN: @@ -137,13 +159,13 @@ class AudioRecordingDisclosureBar { case STATE_MINIMIZING: // Currently animating or expanded. Thus add to the pending notifications, and it // will be picked up once the indicator comes to the STATE_MINIMIZED. - mPendingNotifications.add(packageName); + mPendingNotificationPackages.add(packageName); break; } } private void onDoneRecording(String packageName) { - if (!mAudioRecordingApps.remove(packageName)) { + if (!mActiveAudioRecordingPackages.remove(packageName)) { // Was not marked as an active recorder, do nothing return; } @@ -151,7 +173,8 @@ class AudioRecordingDisclosureBar { // If not MINIMIZED, will check whether the indicator should be hidden when the indicator // comes to the STATE_MINIMIZED eventually. If is in the STATE_MINIMIZED, but there are // other active recorders - simply ignore. - if (mState == STATE_MINIMIZED && mAudioRecordingApps.isEmpty()) { + if (mState == STATE_MINIMIZED && mActiveAudioRecordingPackages.isEmpty()) { + mSessionNotifiedPackages.clear(); hide(); } } @@ -303,11 +326,12 @@ class AudioRecordingDisclosureBar { private void onMinimized() { mState = STATE_MINIMIZED; - if (!mPendingNotifications.isEmpty()) { + if (!mPendingNotificationPackages.isEmpty()) { // There is a new application that started recording, tell the user about it. - expand(mPendingNotifications.poll()); - } else if (mAudioRecordingApps.isEmpty()) { - // Nobody is recording anymore, remove the indicator. + expand(mPendingNotificationPackages.poll()); + } else if (mActiveAudioRecordingPackages.isEmpty()) { + // Nobody is recording anymore, clear state and remove the indicator. + mSessionNotifiedPackages.clear(); hide(); } } @@ -326,6 +350,12 @@ class AudioRecordingDisclosureBar { mBgRight = null; mState = STATE_NOT_SHOWN; + + // Check if anybody started recording while we were in STATE_DISAPPEARING + if (!mPendingNotificationPackages.isEmpty()) { + // There is a new application that started recording, tell the user about it. + show(mPendingNotificationPackages.poll()); + } } private void startPulsatingAnimation() { |