Changes to 'Alarms & reminders' permission setting

Not showing apps that are targeting SDK < 31, because the change is not
enabled for them.

Now alarm manager service manages killing the process whenever the
permission gets revoked, so we don't need to do it here.
This also lets us kill the app on "Reset app preferences" if needed.

Adding the preference under "Advanced" in the app info page so it
appears for apps that have requested this permission.

Test: atest SettingsUnitTests:AppStateAlarmsAndRemindersBridgeTest
make -j64 RunSettingsRoboTests \
ROBOTEST_FILTER="AlarmsAndRemindersDetailsTest|
AlarmsAndRemindersDetailPreferenceControllerTest"

Manually:
- There should be no observable difference in behavior when
toggling the setting. ActivityManager logs should still indicate that
the app is killed when the permission is revoked.
- "Alarms & Reminders" should appear under "Advanced" when looking at
the app info detail of an app that appears under "Alarms & reminders"
special app access page.

Bug: 179541791
Bug: 190070171
Change-Id: I2d437cec10ee10e4326fb25b2820de9ef9c31c67
This commit is contained in:
Suprabh Shukla
2021-06-10 17:25:09 -07:00
parent ad84b3dd39
commit 3f5bd0931e
6 changed files with 204 additions and 22 deletions

View File

@@ -19,6 +19,7 @@ package com.android.settings.applications;
import android.Manifest;
import android.app.AlarmManager;
import android.app.AppGlobals;
import android.app.compat.CompatChanges;
import android.content.Context;
import android.content.pm.IPackageManager;
import android.os.RemoteException;
@@ -63,14 +64,21 @@ public class AppStateAlarmsAndRemindersBridge extends AppStateBaseBridge {
}
}
private boolean isChangeEnabled(String packageName, int userId) {
return CompatChanges.isChangeEnabled(AlarmManager.REQUIRE_EXACT_ALARM_PERMISSION,
packageName, UserHandle.of(userId));
}
/**
* Returns information regarding {@link Manifest.permission#SCHEDULE_EXACT_ALARM} for the given
* package and uid.
*/
public AlarmsAndRemindersState createPermissionState(String packageName, int uid) {
final boolean permissionRequested = ArrayUtils.contains(mRequesterPackages, packageName);
final boolean permissionGranted = mAlarmManager.hasScheduleExactAlarm(packageName,
UserHandle.getUserId(uid));
final int userId = UserHandle.getUserId(uid);
final boolean permissionRequested = ArrayUtils.contains(mRequesterPackages, packageName)
&& isChangeEnabled(packageName, userId);
final boolean permissionGranted = mAlarmManager.hasScheduleExactAlarm(packageName, userId);
return new AlarmsAndRemindersState(permissionRequested, permissionGranted);
}