Merge "Allow setting lock task features without setting packages" into udc-dev am: f0a411d69c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22761399

Change-Id: Ia15bb42a5bf67be22c8e2fb7ca8c1ffeaaf59653
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Kholoud Mohamed
2023-04-24 12:08:25 +00:00
committed by Automerger Merge Worker
3 changed files with 48 additions and 33 deletions

View File

@@ -38,6 +38,7 @@ public final class LockTaskPolicy extends PolicyValue<LockTaskPolicy> {
/** /**
* @hide * @hide
*/ */
// We default on the power button menu, in order to be consistent with pre-P behaviour
public static final int DEFAULT_LOCK_TASK_FLAG = public static final int DEFAULT_LOCK_TASK_FLAG =
DevicePolicyManager.LOCK_TASK_FEATURE_GLOBAL_ACTIONS; DevicePolicyManager.LOCK_TASK_FEATURE_GLOBAL_ACTIONS;
@@ -72,18 +73,28 @@ public final class LockTaskPolicy extends PolicyValue<LockTaskPolicy> {
/** /**
* @hide * @hide
*/ */
public LockTaskPolicy(@NonNull Set<String> packages) { public LockTaskPolicy(@Nullable Set<String> packages) {
Objects.requireNonNull(packages); if (packages != null) {
mPackages.addAll(packages); mPackages.addAll(packages);
}
setValue(this); setValue(this);
} }
/** /**
* @hide * @hide
*/ */
public LockTaskPolicy(@NonNull Set<String> packages, int flags) { public LockTaskPolicy(int flags) {
Objects.requireNonNull(packages); mFlags = flags;
mPackages = new HashSet<>(packages); setValue(this);
}
/**
* @hide
*/
public LockTaskPolicy(@Nullable Set<String> packages, int flags) {
if (packages != null) {
mPackages.addAll(packages);
}
mFlags = flags; mFlags = flags;
setValue(this); setValue(this);
} }

View File

@@ -14744,12 +14744,6 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
synchronized (getLockObject()) { synchronized (getLockObject()) {
enforcingAdmin = enforceCanCallLockTaskLocked(who, caller.getPackageName()); enforcingAdmin = enforceCanCallLockTaskLocked(who, caller.getPackageName());
} }
if (packages.length == 0) {
mDevicePolicyEngine.removeLocalPolicy(
PolicyDefinition.LOCK_TASK,
enforcingAdmin,
caller.getUserId());
} else {
LockTaskPolicy currentPolicy = mDevicePolicyEngine.getLocalPolicySetByAdmin( LockTaskPolicy currentPolicy = mDevicePolicyEngine.getLocalPolicySetByAdmin(
PolicyDefinition.LOCK_TASK, PolicyDefinition.LOCK_TASK,
enforcingAdmin, enforcingAdmin,
@@ -14761,7 +14755,13 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
policy = new LockTaskPolicy(currentPolicy); policy = new LockTaskPolicy(currentPolicy);
policy.setPackages(Set.of(packages)); policy.setPackages(Set.of(packages));
} }
if (policy.getPackages().isEmpty()
&& policy.getFlags() == DevicePolicyManager.LOCK_TASK_FEATURE_NONE) {
mDevicePolicyEngine.removeLocalPolicy(
PolicyDefinition.LOCK_TASK,
enforcingAdmin,
caller.getUserId());
} else {
mDevicePolicyEngine.setLocalPolicy( mDevicePolicyEngine.setLocalPolicy(
PolicyDefinition.LOCK_TASK, PolicyDefinition.LOCK_TASK,
enforcingAdmin, enforcingAdmin,
@@ -14876,18 +14876,26 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
PolicyDefinition.LOCK_TASK, PolicyDefinition.LOCK_TASK,
enforcingAdmin, enforcingAdmin,
caller.getUserId()); caller.getUserId());
LockTaskPolicy policy;
if (currentPolicy == null) { if (currentPolicy == null) {
throw new IllegalArgumentException("Can't set a lock task flags without setting " policy = new LockTaskPolicy(flags);
+ "lock task packages first."); } else {
} policy = new LockTaskPolicy(currentPolicy);
LockTaskPolicy policy = new LockTaskPolicy(currentPolicy);
policy.setFlags(flags); policy.setFlags(flags);
}
if (policy.getPackages().isEmpty()
&& policy.getFlags() == DevicePolicyManager.LOCK_TASK_FEATURE_NONE) {
mDevicePolicyEngine.removeLocalPolicy(
PolicyDefinition.LOCK_TASK,
enforcingAdmin,
caller.getUserId());
} else {
mDevicePolicyEngine.setLocalPolicy( mDevicePolicyEngine.setLocalPolicy(
PolicyDefinition.LOCK_TASK, PolicyDefinition.LOCK_TASK,
enforcingAdmin, enforcingAdmin,
policy, policy,
caller.getUserId()); caller.getUserId());
}
} else { } else {
Objects.requireNonNull(who, "ComponentName is null"); Objects.requireNonNull(who, "ComponentName is null");
synchronized (getLockObject()) { synchronized (getLockObject()) {

View File

@@ -42,10 +42,6 @@ final class LockTaskPolicySerializer extends PolicySerializer<LockTaskPolicy> {
void saveToXml(PolicyKey policyKey, TypedXmlSerializer serializer, void saveToXml(PolicyKey policyKey, TypedXmlSerializer serializer,
@NonNull LockTaskPolicy value) throws IOException { @NonNull LockTaskPolicy value) throws IOException {
Objects.requireNonNull(value); Objects.requireNonNull(value);
if (value.getPackages() == null || value.getPackages().isEmpty()) {
throw new IllegalArgumentException("Error saving LockTaskPolicy to file, lock task "
+ "packages must be present");
}
serializer.attribute( serializer.attribute(
/* namespace= */ null, /* namespace= */ null,
ATTR_PACKAGES, ATTR_PACKAGES,