Merge "Do not show a recording app more than once" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-03-11 15:23:59 +00:00
committed by Android (Google) Code Review

View File

@@ -43,7 +43,6 @@ import com.android.systemui.R;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
@@ -98,8 +97,27 @@ class AudioRecordingDisclosureBar {
private TextView mTextView; private TextView mTextView;
@State private int mState = STATE_NOT_SHOWN; @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) { AudioRecordingDisclosureBar(Context context) {
mContext = context; mContext = context;
@@ -116,10 +134,14 @@ class AudioRecordingDisclosureBar {
} }
private void onStartedRecording(String packageName) { private void onStartedRecording(String packageName) {
if (!mAudioRecordingApps.add(packageName)) { if (!mActiveAudioRecordingPackages.add(packageName)) {
// This app is already known to perform recording // This app is already known to perform recording
return; return;
} }
if (!mSessionNotifiedPackages.add(packageName)) {
// We've already notified user about this app, no need to do it again.
return;
}
switch (mState) { switch (mState) {
case STATE_NOT_SHOWN: case STATE_NOT_SHOWN:
@@ -137,13 +159,13 @@ class AudioRecordingDisclosureBar {
case STATE_MINIMIZING: case STATE_MINIMIZING:
// Currently animating or expanded. Thus add to the pending notifications, and it // Currently animating or expanded. Thus add to the pending notifications, and it
// will be picked up once the indicator comes to the STATE_MINIMIZED. // will be picked up once the indicator comes to the STATE_MINIMIZED.
mPendingNotifications.add(packageName); mPendingNotificationPackages.add(packageName);
break; break;
} }
} }
private void onDoneRecording(String packageName) { private void onDoneRecording(String packageName) {
if (!mAudioRecordingApps.remove(packageName)) { if (!mActiveAudioRecordingPackages.remove(packageName)) {
// Was not marked as an active recorder, do nothing // Was not marked as an active recorder, do nothing
return; return;
} }
@@ -151,7 +173,8 @@ class AudioRecordingDisclosureBar {
// If not MINIMIZED, will check whether the indicator should be hidden when the indicator // 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 // comes to the STATE_MINIMIZED eventually. If is in the STATE_MINIMIZED, but there are
// other active recorders - simply ignore. // other active recorders - simply ignore.
if (mState == STATE_MINIMIZED && mAudioRecordingApps.isEmpty()) { if (mState == STATE_MINIMIZED && mActiveAudioRecordingPackages.isEmpty()) {
mSessionNotifiedPackages.clear();
hide(); hide();
} }
} }
@@ -303,11 +326,12 @@ class AudioRecordingDisclosureBar {
private void onMinimized() { private void onMinimized() {
mState = STATE_MINIMIZED; mState = STATE_MINIMIZED;
if (!mPendingNotifications.isEmpty()) { if (!mPendingNotificationPackages.isEmpty()) {
// There is a new application that started recording, tell the user about it. // There is a new application that started recording, tell the user about it.
expand(mPendingNotifications.poll()); expand(mPendingNotificationPackages.poll());
} else if (mAudioRecordingApps.isEmpty()) { } else if (mActiveAudioRecordingPackages.isEmpty()) {
// Nobody is recording anymore, remove the indicator. // Nobody is recording anymore, clear state and remove the indicator.
mSessionNotifiedPackages.clear();
hide(); hide();
} }
} }
@@ -326,6 +350,12 @@ class AudioRecordingDisclosureBar {
mBgRight = null; mBgRight = null;
mState = STATE_NOT_SHOWN; 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() { private void startPulsatingAnimation() {