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

Commit 13452f6e authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Apply "most-recent" delivery policy to ACTION_USER_RESTRICTIONS_CHANGED.

This allows us to skip any older ACTION_USER_RESTRICTIONS_CHANGED
broadcasts waiting to be delivered when a new broadcast is dispatched.
It should be safe to discard the older ones as the broadcast is only
indicating that something has changed.

Bug: 265079364
Test: atest tests/devicepolicy/src/android/devicepolicy/cts/UserRestrictionsTest.java
Test: atest hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/UserRestrictionsTest.java
Change-Id: I97c7495f13520b5c8a894b76343deae20d1824e9
parent 020ca899
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.annotation.UserIdInt;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.ActivityManagerNative;
import android.app.BroadcastOptions;
import android.app.IActivityManager;
import android.app.IStopUserCallback;
import android.app.KeyguardManager;
@@ -2924,7 +2925,13 @@ public class UserManagerService extends IUserManager.Stub {

                final Intent broadcast = new Intent(UserManager.ACTION_USER_RESTRICTIONS_CHANGED)
                        .setFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
                mContext.sendBroadcastAsUser(broadcast, UserHandle.of(userId));
                // Setting the MOST_RECENT policy allows us to discard older broadcasts
                // still waiting to be delivered.
                final Bundle options = BroadcastOptions.makeBasic()
                        .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
                        .toBundle();
                mContext.sendBroadcastAsUser(broadcast, UserHandle.of(userId),
                        null /* receiverPermission */, options);
            }
        });
    }