diff options
4 files changed, 42 insertions, 0 deletions
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index 3865b2779466..a7404bc63e2a 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -72,7 +72,9 @@ import com.android.internal.util.ArrayUtils; import com.android.internal.util.CollectionUtils; import com.android.internal.util.function.pooled.PooledLambda; import com.android.server.FgThread; +import com.android.server.LocalServices; import com.android.server.SystemService; +import com.android.server.wm.ActivityTaskManagerInternal; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -84,6 +86,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; @@ -519,6 +522,11 @@ public class CompanionDeviceManagerService extends SystemService implements Bind if (size(old) == size(associations)) return; Set<Association> finalAssociations = associations; + Set<String> companionAppPackages = new HashSet<>(); + for (Association association : finalAssociations) { + companionAppPackages.add(association.companionAppPackage); + } + file.write((out) -> { XmlSerializer xml = Xml.newSerializer(); try { @@ -542,6 +550,9 @@ public class CompanionDeviceManagerService extends SystemService implements Bind } }); + ActivityTaskManagerInternal atmInternal = LocalServices.getService( + ActivityTaskManagerInternal.class); + atmInternal.setCompanionAppPackages(userId, companionAppPackages); } } diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index ea1db406b8df..47745d599145 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -1015,6 +1015,11 @@ class ActivityStarter { if (mService.isDeviceOwner(callingPackage)) { return false; } + // don't abort if the callingPackage has companion device + final int callingUserId = UserHandle.getUserId(callingUid); + if (mService.isAssociatedCompanionApp(callingUserId, callingPackage)) { + return false; + } // don't abort if the callingPackage is temporarily whitelisted if (mService.isPackageNameWhitelistedForBgActivityStarts(callingPackage)) { Slog.w(TAG, "Background activity start for " + callingPackage diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java b/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java index fc7646f8ae4e..b2e5b6ab7a1a 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java @@ -510,4 +510,7 @@ public abstract class ActivityTaskManagerInternal { * Called by DevicePolicyManagerService to set the package name of the device owner. */ public abstract void setDeviceOwnerPackageName(String deviceOwnerPkg); + + /** Set all associated companion app that belongs to an userId. */ + public abstract void setCompanionAppPackages(int userId, Set<String> companionAppPackages); } diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index faa98fa79be9..9a8824f1b717 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -443,6 +443,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { // VoiceInteractionManagerService ComponentName mActiveVoiceInteractionServiceComponent; + // A map userId and all its companion app packages + private final Map<Integer, Set<String>> mCompanionAppPackageMap = new ArrayMap<>(); + VrController mVrController; KeyguardController mKeyguardController; private final ClientLifecycleManager mLifecycleManager; @@ -5909,6 +5912,14 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } } + boolean isAssociatedCompanionApp(int userId, String packageName) { + final Set<String> allPackages = mCompanionAppPackageMap.get(userId); + if (allPackages == null) { + return false; + } + return allPackages.contains(packageName); + } + final class H extends Handler { static final int REPORT_TIME_TRACKER_MSG = 1; @@ -7282,5 +7293,17 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { ActivityTaskManagerService.this.setDeviceOwnerPackageName(deviceOwnerPkg); } } + + @Override + public void setCompanionAppPackages(int userId, Set<String> companionAppPackages) { + // Deep copy all content to make sure we do not rely on the source + final Set<String> result = new HashSet<>(); + for (String pkg : companionAppPackages) { + result.add(pkg); + } + synchronized (mGlobalLock) { + mCompanionAppPackageMap.put(userId, result); + } + } } } |