Reuse merged token and add additional checks.
Make sure we consistently use the same token to check and pass down to prevent any modification in the meantime between the 2 calls. The additional checks should fail closer to the source of the problem. Test: atest BackgroundActivityLaunchTest Bug: 269228725 Change-Id: I0017d8c24224d9d3ab7a284e81d5ff49630aa8e8
This commit is contained in:
@@ -16,10 +16,13 @@
|
||||
|
||||
package com.android.server.am;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkArgument;
|
||||
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
|
||||
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
|
||||
import static com.android.server.am.ActivityManagerService.MY_PID;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManager;
|
||||
@@ -63,7 +66,6 @@ import com.android.server.wm.WindowProcessListener;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Full information about a particular process that
|
||||
@@ -1345,16 +1347,19 @@ class ProcessRecord implements WindowProcessListener {
|
||||
* {@param originatingToken} if you have one such originating token, this is useful for tracing
|
||||
* back the grant in the case of the notification token.
|
||||
*/
|
||||
void addOrUpdateBackgroundStartPrivileges(Binder entity,
|
||||
BackgroundStartPrivileges backgroundStartPrivileges) {
|
||||
Objects.requireNonNull(entity);
|
||||
void addOrUpdateBackgroundStartPrivileges(@NonNull Binder entity,
|
||||
@NonNull BackgroundStartPrivileges backgroundStartPrivileges) {
|
||||
requireNonNull(entity, "entity");
|
||||
requireNonNull(backgroundStartPrivileges, "backgroundStartPrivileges");
|
||||
checkArgument(backgroundStartPrivileges.allowsAny(),
|
||||
"backgroundStartPrivileges does not allow anything");
|
||||
mWindowProcessController.addOrUpdateBackgroundStartPrivileges(entity,
|
||||
backgroundStartPrivileges);
|
||||
setBackgroundStartPrivileges(entity, backgroundStartPrivileges);
|
||||
}
|
||||
|
||||
void removeBackgroundStartPrivileges(Binder entity) {
|
||||
Objects.requireNonNull(entity);
|
||||
void removeBackgroundStartPrivileges(@NonNull Binder entity) {
|
||||
requireNonNull(entity, "entity");
|
||||
mWindowProcessController.removeBackgroundStartPrivileges(entity);
|
||||
setBackgroundStartPrivileges(entity, null);
|
||||
}
|
||||
|
||||
@@ -850,10 +850,11 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
|
||||
mAppForAllowingBgActivityStartsByStart =
|
||||
mBackgroundStartPrivilegesByStartMerged.allowsAny()
|
||||
? proc : null;
|
||||
if (mBackgroundStartPrivilegesByStartMerged.allowsAny()
|
||||
|| mIsAllowedBgActivityStartsByBinding) {
|
||||
BackgroundStartPrivileges backgroundStartPrivileges =
|
||||
getBackgroundStartPrivilegesWithExclusiveToken();
|
||||
if (backgroundStartPrivileges.allowsAny()) {
|
||||
proc.addOrUpdateBackgroundStartPrivileges(this,
|
||||
getBackgroundStartPrivilegesWithExclusiveToken());
|
||||
backgroundStartPrivileges);
|
||||
} else {
|
||||
proc.removeBackgroundStartPrivileges(this);
|
||||
}
|
||||
|
||||
@@ -254,11 +254,12 @@ class BackgroundLaunchProcessController {
|
||||
*
|
||||
* If {@code entity} is already added, this method will update its {@code originatingToken}.
|
||||
*/
|
||||
void addOrUpdateAllowBackgroundStartPrivileges(
|
||||
Binder entity, BackgroundStartPrivileges backgroundStartPrivileges) {
|
||||
void addOrUpdateAllowBackgroundStartPrivileges(@NonNull Binder entity,
|
||||
@NonNull BackgroundStartPrivileges backgroundStartPrivileges) {
|
||||
requireNonNull(entity, "entity");
|
||||
requireNonNull(backgroundStartPrivileges, "backgroundStartPrivileges");
|
||||
checkArgument(backgroundStartPrivileges.allowsAny());
|
||||
checkArgument(backgroundStartPrivileges.allowsAny(),
|
||||
"backgroundStartPrivileges does not allow anything");
|
||||
synchronized (this) {
|
||||
if (mBackgroundStartPrivileges == null) {
|
||||
mBackgroundStartPrivileges = new ArrayMap<>();
|
||||
@@ -271,7 +272,7 @@ class BackgroundLaunchProcessController {
|
||||
* Removes token {@code entity} that allowed background activity starts added via {@link
|
||||
* #addOrUpdateAllowBackgroundStartPrivileges(Binder, BackgroundStartPrivileges)}.
|
||||
*/
|
||||
void removeAllowBackgroundStartPrivileges(Binder entity) {
|
||||
void removeAllowBackgroundStartPrivileges(@NonNull Binder entity) {
|
||||
requireNonNull(entity, "entity");
|
||||
synchronized (this) {
|
||||
if (mBackgroundStartPrivileges != null) {
|
||||
|
||||
@@ -45,6 +45,8 @@ import static com.android.server.wm.ActivityTaskManagerService.RELAUNCH_REASON_N
|
||||
import static com.android.server.wm.BackgroundActivityStartController.BAL_BLOCK;
|
||||
import static com.android.server.wm.WindowManagerService.MY_PID;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
@@ -559,14 +561,19 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
|
||||
* @see BackgroundLaunchProcessController#addOrUpdateAllowBackgroundStartPrivileges(Binder,
|
||||
* BackgroundStartPrivileges)
|
||||
*/
|
||||
public void addOrUpdateBackgroundStartPrivileges(Binder entity,
|
||||
BackgroundStartPrivileges backgroundStartPrivileges) {
|
||||
public void addOrUpdateBackgroundStartPrivileges(@NonNull Binder entity,
|
||||
@NonNull BackgroundStartPrivileges backgroundStartPrivileges) {
|
||||
requireNonNull(entity, "entity");
|
||||
requireNonNull(backgroundStartPrivileges, "backgroundStartPrivileges");
|
||||
checkArgument(backgroundStartPrivileges.allowsAny(),
|
||||
"backgroundStartPrivileges does not allow anything");
|
||||
mBgLaunchController.addOrUpdateAllowBackgroundStartPrivileges(entity,
|
||||
backgroundStartPrivileges);
|
||||
}
|
||||
|
||||
/** @see BackgroundLaunchProcessController#removeAllowBackgroundStartPrivileges(Binder) */
|
||||
public void removeBackgroundStartPrivileges(Binder entity) {
|
||||
public void removeBackgroundStartPrivileges(@NonNull Binder entity) {
|
||||
requireNonNull(entity, "entity");
|
||||
mBgLaunchController.removeAllowBackgroundStartPrivileges(entity);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user