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
This commit is contained in:
Sudheer Shanka
2023-01-18 08:01:39 +00:00
parent 020ca8995f
commit 13452f6e41

View File

@@ -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);
}
});
}