Loading services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +11 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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 { Loading @@ -542,6 +550,9 @@ public class CompanionDeviceManagerService extends SystemService implements Bind } }); ActivityTaskManagerInternal atmInternal = LocalServices.getService( ActivityTaskManagerInternal.class); atmInternal.setCompanionAppPackages(userId, companionAppPackages); } } Loading services/core/java/com/android/server/wm/ActivityStarter.java +5 −0 Original line number Diff line number Diff line Loading @@ -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 Loading services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java +3 −0 Original line number Diff line number Diff line Loading @@ -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); } services/core/java/com/android/server/wm/ActivityTaskManagerService.java +23 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); } } } } Loading
services/companion/java/com/android/server/companion/CompanionDeviceManagerService.java +11 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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 { Loading @@ -542,6 +550,9 @@ public class CompanionDeviceManagerService extends SystemService implements Bind } }); ActivityTaskManagerInternal atmInternal = LocalServices.getService( ActivityTaskManagerInternal.class); atmInternal.setCompanionAppPackages(userId, companionAppPackages); } } Loading
services/core/java/com/android/server/wm/ActivityStarter.java +5 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java +3 −0 Original line number Diff line number Diff line Loading @@ -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); }
services/core/java/com/android/server/wm/ActivityTaskManagerService.java +23 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); } } } }