diff options
author | Michal Karpinski <mkarpinski@google.com> | 2019-04-02 19:46:52 +0100 |
---|---|---|
committer | Michal Karpinski <mkarpinski@google.com> | 2019-04-03 15:53:53 +0100 |
commit | da34cd4f0e1e91ff3027d70d709b2fb10b1cdbee (patch) | |
tree | 90b41992fd96b15f128a7b620b10a4e575e6abaf | |
parent | aa22f417e3c09874e31a034c0d4abb363be570a4 (diff) |
Allow companion apps to start background activities from
PendingIntents (even if they aren't foreground)
And push companion packages to ATMS after the user is
unlocked.
Bug: 129757565
Test: atest WmTests:ActivityStarterTests
Test: manual
Change-Id: Ic76d5c8a3fb096a8caf76dafb6c38212a8506f3a
3 files changed, 33 insertions, 11 deletions
diff --git a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java index a7404bc63e2a..a3e7d3685100 100644 --- a/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java @@ -164,6 +164,20 @@ public class CompanionDeviceManagerService extends SystemService implements Bind } @Override + public void onUnlockUser(int userHandle) { + Set<Association> associations = readAllAssociations(userHandle); + Set<String> companionAppPackages = new HashSet<>(); + for (Association association : associations) { + companionAppPackages.add(association.companionAppPackage); + } + ActivityTaskManagerInternal atmInternal = LocalServices.getService( + ActivityTaskManagerInternal.class); + if (atmInternal != null) { + atmInternal.setCompanionAppPackages(userHandle, companionAppPackages); + } + } + + @Override public void binderDied() { Handler.getMain().post(this::cleanup); } diff --git a/services/core/java/com/android/server/wm/ActivityStarter.java b/services/core/java/com/android/server/wm/ActivityStarter.java index cd15587918ec..3b358e897ccc 100644 --- a/services/core/java/com/android/server/wm/ActivityStarter.java +++ b/services/core/java/com/android/server/wm/ActivityStarter.java @@ -981,6 +981,11 @@ class ActivityStarter { if (isRealCallingUidPersistentSystemProcess && allowBackgroundActivityStart) { return false; } + // don't abort if the realCallingUid is an associated companion app + if (mService.isAssociatedCompanionApp(UserHandle.getUserId(realCallingUid), + realCallingUid)) { + return false; + } } // If we don't have callerApp at this point, no caller was provided to startActivity(). // That's the case for PendingIntent-based starts, since the creator's process might not be @@ -1026,7 +1031,7 @@ class ActivityStarter { } // don't abort if the callingPackage has companion device final int callingUserId = UserHandle.getUserId(callingUid); - if (mService.isAssociatedCompanionApp(callingUserId, callingPackage)) { + if (mService.isAssociatedCompanionApp(callingUserId, callingUid)) { return false; } // don't abort if the callingPackage is temporarily whitelisted diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index 4a687feb00d7..b64abdb48fba 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -443,8 +443,8 @@ 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<>(); + // A map userId and all its companion app uids + private final Map<Integer, Set<Integer>> mCompanionAppUidsMap = new ArrayMap<>(); VrController mVrController; KeyguardController mKeyguardController; @@ -5907,12 +5907,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } } - boolean isAssociatedCompanionApp(int userId, String packageName) { - final Set<String> allPackages = mCompanionAppPackageMap.get(userId); - if (allPackages == null) { + boolean isAssociatedCompanionApp(int userId, int uid) { + final Set<Integer> allUids = mCompanionAppUidsMap.get(userId); + if (allUids == null) { return false; } - return allPackages.contains(packageName); + return allUids.contains(uid); } final class H extends Handler { @@ -7291,13 +7291,16 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { @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<>(); + // Translate package names into UIDs + final Set<Integer> result = new HashSet<>(); for (String pkg : companionAppPackages) { - result.add(pkg); + final int uid = getPackageManagerInternalLocked().getPackageUid(pkg, 0, userId); + if (uid >= 0) { + result.add(uid); + } } synchronized (mGlobalLock) { - mCompanionAppPackageMap.put(userId, result); + mCompanionAppUidsMap.put(userId, result); } } } |