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

Commit 4b5bf9e2 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Do not show a recording app more than once" into rvc-dev am: d514712c...

Merge "Do not show a recording app more than once" into rvc-dev am: d514712c am: e4fdd0cf am: d45d4f91

Change-Id: I4edef5acec8aa053b5133a0a796d7c5ab10daf80
parents 093169a8 d45d4f91
Loading
Loading
Loading
Loading
+41 −11
Original line number Diff line number Diff line
@@ -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() {