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

Commit f4513ab0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Bring back AudioRecordingDisclosureBar"

parents f60c8ff0 bcf812b7
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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>
+6 −0
Original line number Diff line number Diff line
@@ -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
+67 −24
Original line number Diff line number Diff line
@@ -111,6 +111,13 @@ public class AudioRecordingDisclosureBar implements
     * microphone foreground services
     */
    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
@@ -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:
                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,6 +252,8 @@ public class AudioRecordingDisclosureBar implements
        mTextView = mTextsContainers.findViewById(R.id.text);
        mBgEnd = mIndicatorView.findViewById(R.id.bg_end);

        // 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) {
@@ -257,8 +264,18 @@ public class AudioRecordingDisclosureBar implements
                mIconContainerBg.setBackgroundResource(R.drawable.tv_rect_dark_right_rounded);
            }

        // Set up the notification text
            final String label = getApplicationLabel(packageName);
            mTextView.setText(mContext.getString(R.string.app_accessed_mic, label));
        } else {
            mTextsContainers.setVisibility(View.GONE);
            mIconContainerBg.setVisibility(View.GONE);
            mTextView.setVisibility(View.GONE);
            mBgEnd.setVisibility(View.GONE);
            mTextsContainers = null;
            mIconContainerBg = null;
            mTextView = null;
            mBgEnd = null;
        }

        // Initially change the visibility to INVISIBLE, wait until and receives the size and
        // then animate it moving from "off" the screen correctly
@@ -296,7 +313,11 @@ public class AudioRecordingDisclosureBar implements
                                            @Override
                                            public void onAnimationEnd(Animator animation) {
                                                startPulsatingAnimation();
                                                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,6 +431,7 @@ public class AudioRecordingDisclosureBar implements
        if (DEBUG) Log.d(TAG, "Minimized");
        mState = STATE_MINIMIZED;

        if (mRevealRecordingPackages) {
            if (!mPendingNotificationPackages.isEmpty()) {
                // There is a new application that started recording, tell the user about it.
                expand(mPendingNotificationPackages.poll());
@@ -411,6 +439,7 @@ public class AudioRecordingDisclosureBar implements
                hideIndicatorIfNeeded();
            }
        }
    }

    @UiThread
    private void onHidden() {
@@ -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);
        }
    }
}