Call new API setTemporaryAppAllowlist() and specify temp-allowlist reasonCode.
Deprecate/delete setTemporaryAppWhitelistDuration(int type, long duration) which is also a new API added very recently. Bug: 171305836 Test: atest cts/tests/app/src/android/app/cts/ActivityManagerFgsBgStartTest.java Reboot device, observe "tempAllowListReason" in logcat. Change-Id: I29181ce224c28277db1d45ec7fd0f79e032e5c90 BYPASS_INCLUSIVE_LANGUAGE_REASON=existing public API
This commit is contained in:
@@ -28,6 +28,8 @@ import static android.app.AlarmManager.INTERVAL_HOUR;
|
||||
import static android.app.AlarmManager.RTC;
|
||||
import static android.app.AlarmManager.RTC_WAKEUP;
|
||||
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
|
||||
import static android.os.PowerWhitelistManager.REASON_ALARM_MANAGER_WHILE_IDLE;
|
||||
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
|
||||
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED;
|
||||
import static android.os.UserHandle.USER_SYSTEM;
|
||||
|
||||
@@ -524,10 +526,12 @@ public class AlarmManagerService extends SystemService {
|
||||
if (mLastAllowWhileIdleWhitelistDuration != ALLOW_WHILE_IDLE_WHITELIST_DURATION) {
|
||||
mLastAllowWhileIdleWhitelistDuration = ALLOW_WHILE_IDLE_WHITELIST_DURATION;
|
||||
|
||||
mOptsWithFgs.setTemporaryAppWhitelistDuration(ALLOW_WHILE_IDLE_WHITELIST_DURATION);
|
||||
mOptsWithoutFgs.setTemporaryAppWhitelistDuration(
|
||||
mOptsWithFgs.setTemporaryAppAllowlist(ALLOW_WHILE_IDLE_WHITELIST_DURATION,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
REASON_ALARM_MANAGER_WHILE_IDLE, "");
|
||||
mOptsWithoutFgs.setTemporaryAppAllowlist(ALLOW_WHILE_IDLE_WHITELIST_DURATION,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_NOT_ALLOWED,
|
||||
ALLOW_WHILE_IDLE_WHITELIST_DURATION);
|
||||
REASON_ALARM_MANAGER_WHILE_IDLE, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -645,7 +645,6 @@ package android.app {
|
||||
method public void setDontSendToRestrictedApps(boolean);
|
||||
method @RequiresPermission(anyOf={android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND, android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND}) public void setTemporaryAppAllowlist(long, int, int, @Nullable String);
|
||||
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND, android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND}) public void setTemporaryAppWhitelistDuration(long);
|
||||
method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST, android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND, android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND}) public void setTemporaryAppWhitelistDuration(int, long);
|
||||
method public android.os.Bundle toBundle();
|
||||
}
|
||||
|
||||
|
||||
@@ -140,23 +140,6 @@ public class BroadcastOptions {
|
||||
PowerWhitelistManager.REASON_UNKNOWN, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a duration for which the system should temporary place an application on the
|
||||
* power allowlist when this broadcast is being delivered to it, specify the temp allowlist
|
||||
* type.
|
||||
* @param type one of {@link TempAllowListType}
|
||||
* @param duration the duration in milliseconds; 0 means to not place on allowlist.
|
||||
* @deprecated use {@link #setTemporaryAppAllowlist(long, int, int, String)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@RequiresPermission(anyOf = {android.Manifest.permission.CHANGE_DEVICE_IDLE_TEMP_WHITELIST,
|
||||
android.Manifest.permission.START_ACTIVITIES_FROM_BACKGROUND,
|
||||
android.Manifest.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND})
|
||||
public void setTemporaryAppWhitelistDuration(@TempAllowListType int type, long duration) {
|
||||
setTemporaryAppAllowlist(duration, type,
|
||||
PowerWhitelistManager.REASON_UNKNOWN, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a duration for which the system should temporary place an application on the
|
||||
* power allowlist when this broadcast is being delivered to it, specify the temp allowlist
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package com.android.server.am;
|
||||
|
||||
import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY;
|
||||
import static android.os.PowerWhitelistManager.REASON_PRE_BOOT_COMPLETED;
|
||||
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
|
||||
|
||||
import android.app.ActivityManagerInternal;
|
||||
import android.app.AppOpsManager;
|
||||
@@ -117,9 +119,9 @@ public abstract class PreBootBroadcaster extends IIntentReceiver.Stub {
|
||||
duration = amInternal.getBootTimeTempAllowListDuration();
|
||||
}
|
||||
final BroadcastOptions bOptions = BroadcastOptions.makeBasic();
|
||||
bOptions.setTemporaryAppWhitelistDuration(
|
||||
BroadcastOptions.TEMPORARY_WHITELIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
duration);
|
||||
bOptions.setTemporaryAppAllowlist(duration,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
REASON_PRE_BOOT_COMPLETED, "");
|
||||
synchronized (mService) {
|
||||
mService.broadcastIntentLocked(null, null, null, mIntent, null, this, 0, null, null,
|
||||
null, AppOpsManager.OP_NONE, bOptions.toBundle(), true,
|
||||
|
||||
@@ -27,6 +27,9 @@ import static android.app.ActivityManagerInternal.ALLOW_ALL_PROFILE_PERMISSIONS_
|
||||
import static android.app.ActivityManagerInternal.ALLOW_FULL_ONLY;
|
||||
import static android.app.ActivityManagerInternal.ALLOW_NON_FULL;
|
||||
import static android.app.ActivityManagerInternal.ALLOW_NON_FULL_IN_PROFILE;
|
||||
import static android.os.PowerWhitelistManager.REASON_BOOT_COMPLETED;
|
||||
import static android.os.PowerWhitelistManager.REASON_LOCKED_BOOT_COMPLETED;
|
||||
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
|
||||
import static android.os.Process.SHELL_UID;
|
||||
import static android.os.Process.SYSTEM_UID;
|
||||
|
||||
@@ -74,6 +77,7 @@ import android.os.IRemoteCallback;
|
||||
import android.os.IUserManager;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.PowerWhitelistManager;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
@@ -522,7 +526,8 @@ class UserController implements Handler.Callback {
|
||||
mInjector.broadcastIntent(intent, null, resultTo, 0, null, null,
|
||||
new String[]{android.Manifest.permission.RECEIVE_BOOT_COMPLETED},
|
||||
AppOpsManager.OP_NONE,
|
||||
getTemporaryAppWhitelistBroadcastOptions().toBundle(), true,
|
||||
getTemporaryAppAllowlistBroadcastOptions(REASON_LOCKED_BOOT_COMPLETED)
|
||||
.toBundle(), true,
|
||||
false, MY_PID, SYSTEM_UID,
|
||||
Binder.getCallingUid(), Binder.getCallingPid(), userId);
|
||||
}
|
||||
@@ -770,9 +775,8 @@ class UserController implements Handler.Callback {
|
||||
}, 0, null, null,
|
||||
new String[]{android.Manifest.permission.RECEIVE_BOOT_COMPLETED},
|
||||
AppOpsManager.OP_NONE,
|
||||
getTemporaryAppWhitelistBroadcastOptions().toBundle(), true,
|
||||
false, MY_PID, SYSTEM_UID,
|
||||
callingUid, callingPid, userId);
|
||||
getTemporaryAppAllowlistBroadcastOptions(REASON_BOOT_COMPLETED).toBundle(),
|
||||
true, false, MY_PID, SYSTEM_UID, callingUid, callingPid, userId);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2811,7 +2815,8 @@ class UserController implements Handler.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
private BroadcastOptions getTemporaryAppWhitelistBroadcastOptions() {
|
||||
private BroadcastOptions getTemporaryAppAllowlistBroadcastOptions(
|
||||
@PowerWhitelistManager.ReasonCode int reasonCode) {
|
||||
long duration = 10_000;
|
||||
final ActivityManagerInternal amInternal =
|
||||
LocalServices.getService(ActivityManagerInternal.class);
|
||||
@@ -2819,9 +2824,8 @@ class UserController implements Handler.Callback {
|
||||
duration = amInternal.getBootTimeTempAllowListDuration();
|
||||
}
|
||||
final BroadcastOptions bOptions = BroadcastOptions.makeBasic();
|
||||
bOptions.setTemporaryAppWhitelistDuration(
|
||||
BroadcastOptions.TEMPORARY_WHITELIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
duration);
|
||||
bOptions.setTemporaryAppAllowlist(duration,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED, reasonCode, "");
|
||||
return bOptions;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +97,10 @@ import static android.content.pm.PackageManager.UNINSTALL_REASON_UNKNOWN;
|
||||
import static android.content.pm.PackageManagerInternal.LAST_KNOWN_PACKAGE;
|
||||
import static android.content.pm.PackageParser.SigningDetails.SignatureSchemeVersion.SIGNING_BLOCK_V4;
|
||||
import static android.content.pm.parsing.ApkLiteParseUtils.isApkFile;
|
||||
import static android.os.PowerWhitelistManager.REASON_LOCKED_BOOT_COMPLETED;
|
||||
import static android.os.PowerWhitelistManager.REASON_PACKAGE_REPLACED;
|
||||
import static android.os.PowerWhitelistManager.REASON_PACKAGE_VERIFIER;
|
||||
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
|
||||
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
|
||||
import static android.os.incremental.IncrementalManager.isIncrementalPath;
|
||||
import static android.os.storage.StorageManager.FLAG_STORAGE_CE;
|
||||
@@ -270,6 +274,7 @@ import android.os.Parcel;
|
||||
import android.os.ParcelableException;
|
||||
import android.os.PatternMatcher;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.PowerWhitelistManager;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteCallbackList;
|
||||
import android.os.RemoteException;
|
||||
@@ -5575,7 +5580,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
packageName /*targetPackage*/,
|
||||
null /*finishedReceiver*/, updateUserIds, instantUserIds,
|
||||
null /*broadcastAllowList*/,
|
||||
getTemporaryAppWhitelistBroadcastOptions().toBundle());
|
||||
getTemporaryAppAllowlistBroadcastOptions(REASON_PACKAGE_REPLACED)
|
||||
.toBundle());
|
||||
} else if (launchedForRestore && !res.pkg.isSystem()) {
|
||||
// First-install and we did a restore, so we're responsible for the
|
||||
// first-launch broadcast.
|
||||
@@ -15215,7 +15221,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
lockedBcIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
}
|
||||
final String[] requiredPermissions = {Manifest.permission.RECEIVE_BOOT_COMPLETED};
|
||||
final BroadcastOptions bOptions = getTemporaryAppWhitelistBroadcastOptions();
|
||||
final BroadcastOptions bOptions = getTemporaryAppAllowlistBroadcastOptions(
|
||||
REASON_LOCKED_BOOT_COMPLETED);
|
||||
am.broadcastIntentWithFeature(null, null, lockedBcIntent, null, null, 0, null, null,
|
||||
requiredPermissions, android.app.AppOpsManager.OP_NONE, bOptions.toBundle(),
|
||||
false, false,
|
||||
@@ -17604,7 +17611,9 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
mInjector.getLocalService(DeviceIdleInternal.class);
|
||||
final long idleDuration = getVerificationTimeout();
|
||||
final BroadcastOptions options = BroadcastOptions.makeBasic();
|
||||
options.setTemporaryAppWhitelistDuration(idleDuration);
|
||||
options.setTemporaryAppAllowlist(idleDuration,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
REASON_PACKAGE_VERIFIER, "");
|
||||
|
||||
/*
|
||||
* If any sufficient verifiers were listed in the package
|
||||
@@ -17620,7 +17629,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
final ComponentName verifierComponent = sufficientVerifiers.get(i);
|
||||
idleController.addPowerSaveTempWhitelistApp(Process.myUid(),
|
||||
verifierComponent.getPackageName(), idleDuration,
|
||||
verifierUser.getIdentifier(), false, "package verifier");
|
||||
verifierUser.getIdentifier(), false,
|
||||
REASON_PACKAGE_VERIFIER,"package verifier");
|
||||
|
||||
final Intent sufficientIntent = new Intent(verification);
|
||||
sufficientIntent.setComponent(verifierComponent);
|
||||
@@ -17642,7 +17652,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
verification.setComponent(requiredVerifierComponent);
|
||||
idleController.addPowerSaveTempWhitelistApp(Process.myUid(),
|
||||
mRequiredVerifierPackage, idleDuration,
|
||||
verifierUser.getIdentifier(), false, "package verifier");
|
||||
verifierUser.getIdentifier(), false,
|
||||
REASON_PACKAGE_VERIFIER, "package verifier");
|
||||
mContext.sendOrderedBroadcastAsUser(verification, verifierUser,
|
||||
android.Manifest.permission.PACKAGE_VERIFICATION_AGENT,
|
||||
/* appOp= */ AppOpsManager.OP_NONE,
|
||||
@@ -20962,7 +20973,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
extras, 0, null /*targetPackage*/, null, null, null, broadcastAllowList, null);
|
||||
packageSender.sendPackageBroadcast(Intent.ACTION_MY_PACKAGE_REPLACED, null, null, 0,
|
||||
removedPackage, null, null, null, null /* broadcastAllowList */,
|
||||
getTemporaryAppWhitelistBroadcastOptions().toBundle());
|
||||
getTemporaryAppAllowlistBroadcastOptions(REASON_PACKAGE_REPLACED).toBundle());
|
||||
if (installerPackageName != null) {
|
||||
packageSender.sendPackageBroadcast(Intent.ACTION_PACKAGE_ADDED,
|
||||
removedPackage, extras, 0 /*flags*/,
|
||||
@@ -27809,7 +27820,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
return result.toArray(new PerUidReadTimeouts[result.size()]);
|
||||
}
|
||||
|
||||
static @NonNull BroadcastOptions getTemporaryAppWhitelistBroadcastOptions() {
|
||||
static @NonNull BroadcastOptions getTemporaryAppAllowlistBroadcastOptions(
|
||||
@PowerWhitelistManager.ReasonCode int reasonCode) {
|
||||
long duration = 10_000;
|
||||
final ActivityManagerInternal amInternal =
|
||||
LocalServices.getService(ActivityManagerInternal.class);
|
||||
@@ -27817,9 +27829,9 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
duration = amInternal.getBootTimeTempAllowListDuration();
|
||||
}
|
||||
final BroadcastOptions bOptions = BroadcastOptions.makeBasic();
|
||||
bOptions.setTemporaryAppWhitelistDuration(
|
||||
BroadcastOptions.TEMPORARY_WHITELIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
duration);
|
||||
bOptions.setTemporaryAppAllowlist(duration,
|
||||
TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED,
|
||||
reasonCode, "");
|
||||
return bOptions;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user