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

Commit 8988888f authored by Alex Shabalin's avatar Alex Shabalin Committed by Alexandr Shabalin
Browse files

Check user volume adjustment restrictions only once.

Perform volume restriction check only on dialog opening. Before this
 change the check was performed upon rendering every item in the
 device list which is unnecessary.

Bug: 414668703
Flag: com.android.media.flags.avoid_binder_calls_during_render
Test: atest MediaSwitchingControllerTest, on a device.
Change-Id: I75463830cb842cd1b0d132382b731f28150bd9ca
parent 7aa7beae
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static android.media.RouteListingPreference.ACTION_TRANSFER_MEDIA;
import static android.media.RouteListingPreference.EXTRA_ROUTE_ID;
import static android.provider.Settings.ACTION_BLUETOOTH_SETTINGS;

import static com.android.media.flags.Flags.avoidBinderCallsDuringRender;

import android.annotation.CallbackExecutor;
import android.app.AlertDialog;
import android.app.KeyguardManager;
@@ -173,6 +175,7 @@ public class MediaSwitchingController
    @NonNull private MediaOutputColorScheme mMediaOutputColorScheme;
    @NonNull private MediaOutputColorSchemeLegacy mMediaOutputColorSchemeLegacy;
    private boolean mIsGroupListCollapsed = true;
    private boolean mHasAdjustVolumeUserRestriction = false;

    public enum BroadcastNotifyDialog {
        ACTION_FIRST_LAUNCH,
@@ -276,6 +279,9 @@ public class MediaSwitchingController
        if (enableInputRouting()) {
            mInputRouteManager.registerCallback(mInputDeviceCallback);
        }
        if (avoidBinderCallsDuringRender()) {
            mHasAdjustVolumeUserRestriction = checkIfAdjustVolumeRestrictionEnforced();
        }
    }

    public boolean isRefreshing() {
@@ -1010,6 +1016,13 @@ public class MediaSwitchingController
    }

    boolean hasAdjustVolumeUserRestriction() {
        if (avoidBinderCallsDuringRender()) {
            return mHasAdjustVolumeUserRestriction;
        }
        return checkIfAdjustVolumeRestrictionEnforced();
    }

    private boolean checkIfAdjustVolumeRestrictionEnforced() {
        if (RestrictedLockUtilsInternal.checkIfRestrictionEnforced(
                mContext, UserManager.DISALLOW_ADJUST_VOLUME, UserHandle.myUserId()) != null) {
            return true;