Android12, SCHEDULE_EXACT_ALARM permission check value always returns true

Due to the Android12 upgrade, when calling the precise alarm clock method, the SCHEDULE_EXACT_ALARM permission must be checked. For specific operations, please refer to: Behavior changes adapted to Android 12-----Accurate alarm clock permissions_Yuan Meili..'s blog-CSDN blog_android alarm clock permissions

However, when I was working on a new model recently, on the S platform, although the clock called the precise alarm method, it did not check the SCHEDULE_EXACT_ALARM permission and had no impact (normally, if it is not processed, the precise alarm method will be called. It will definitely crash)

After investigation, it was found that
the framework added doze mode whitelist to the clock process.

<!-- Whitelist of what components are permitted to run in the background -->
<allow-in-power-save package="com.android.deskclock" />

As a result, the value of canScheduleExactAlarms always returns true.

AlarmManagerService$mService#canScheduleExactAlarms
@Override
public boolean canScheduleExactAlarms(String packageName) {
    ......
    if (!isExactAlarmChangeEnabled(packageName, userId)) { // Check the feature flag is on or off
        return true;
    }
    return isExemptFromExactAlarmPermission(packageUid) // ★ Will check DozeMode white list here
            || hasScheduleExactAlarmInternal(packageName, packageUid);
}

AlarmManagerService#isExemptFromExactAlarmPermission
boolean isExemptFromExactAlarmPermission(int uid) {
    return (UserHandle.isSameApp(mSystemUiUid, uid)
            || UserHandle.isCore(uid)
            || mLocalDeviceIdleController == null
            || mLocalDeviceIdleController.isAppOnWhitelist(UserHandle.getAppId(uid))); // ★ Check DozeMode white list
}

Not only does clock have this problem, but if other applications also add doze mode whitelist and have this logic, this phenomenon will also occur. You can refer to it.

Guess you like

Origin blog.csdn.net/m0_50408097/article/details/124457451