Loading core/java/android/companion/CompanionDeviceManager.java +3 −3 Original line number Diff line number Diff line Loading @@ -780,9 +780,9 @@ public final class CompanionDeviceManager { } /** * Notify the system that the given self-managed association has just 'appeared'. * Notify the system that the given self-managed association has just appeared. * This causes the system to bind to the companion app to keep it running until the association * is reported as 'disappeared' * is reported as disappeared * * <p>This API is only available for the companion apps that manage the connectivity by * themselves.</p> Loading @@ -803,7 +803,7 @@ public final class CompanionDeviceManager { } /** * Notify the system that the given self-managed association has just 'disappeared'. * Notify the system that the given self-managed association has just disappeared. * This causes the system to unbind to the companion app. * * <p>This API is only available for the companion apps that manage the connectivity by Loading core/java/android/companion/CompanionDeviceService.java +4 −3 Original line number Diff line number Diff line Loading @@ -77,10 +77,11 @@ import java.util.Objects; * {@link #onDeviceAppeared(AssociationInfo)} and {@link #onDeviceDisappeared(AssociationInfo)} * only to one "primary" services. * Applications that declare multiple {@link CompanionDeviceService}-s should indicate the "primary" * service using "android.companion.primary" tag. * service using "android.companion.PROPERTY_PRIMARY_COMPANION_DEVICE_SERVICE" service level * property. * <pre>{@code * <meta-data * android:name="android.companion.primary" * <property * android:name="android.companion.PROPERTY_PRIMARY_COMPANION_DEVICE_SERVICE" * android:value="true" /> * }</pre> * Loading services/companion/java/com/android/server/companion/PackageUtils.java +13 −8 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.server.companion; import static android.content.pm.PackageManager.FEATURE_COMPANION_DEVICE_SETUP; import static android.content.pm.PackageManager.GET_CONFIGURATIONS; import static android.content.pm.PackageManager.GET_META_DATA; import static android.content.pm.PackageManager.GET_PERMISSIONS; import static com.android.server.companion.CompanionDeviceManagerService.TAG; Loading Loading @@ -53,7 +52,8 @@ import java.util.Map; final class PackageUtils { private static final Intent COMPANION_SERVICE_INTENT = new Intent(CompanionDeviceService.SERVICE_INTERFACE); private static final String META_DATA_PRIMARY_TAG = "android.companion.primary"; private static final String PROPERTY_PRIMARY_TAG = "android.companion.PROPERTY_PRIMARY_COMPANION_DEVICE_SERVICE"; static @Nullable PackageInfo getPackageInfo(@NonNull Context context, @UserIdInt int userId, @NonNull String packageName) { Loading Loading @@ -84,9 +84,8 @@ final class PackageUtils { static @NonNull Map<String, List<ComponentName>> getCompanionServicesForUser( @NonNull Context context, @UserIdInt int userId) { final PackageManager pm = context.getPackageManager(); final ResolveInfoFlags flags = ResolveInfoFlags.of(GET_META_DATA); final List<ResolveInfo> companionServices = pm.queryIntentServicesAsUser(COMPANION_SERVICE_INTENT, flags, userId); final List<ResolveInfo> companionServices = pm.queryIntentServicesAsUser( COMPANION_SERVICE_INTENT, ResolveInfoFlags.of(0), userId); final Map<String, List<ComponentName>> packageNameToServiceInfoList = new HashMap<>(); Loading @@ -109,7 +108,8 @@ final class PackageUtils { service.packageName, it -> new LinkedList<>()); final ComponentName componentName = service.getComponentName(); if (isPrimaryCompanionDeviceService(service)) { if (isPrimaryCompanionDeviceService(pm, componentName)) { // "Primary" service should be at the head of the list. services.addFirst(componentName); } else { Loading @@ -120,7 +120,12 @@ final class PackageUtils { return packageNameToServiceInfoList; } private static boolean isPrimaryCompanionDeviceService(ServiceInfo service) { return service.metaData != null && service.metaData.getBoolean(META_DATA_PRIMARY_TAG); private static boolean isPrimaryCompanionDeviceService(@NonNull PackageManager pm, @NonNull ComponentName componentName) { try { return pm.getProperty(PROPERTY_PRIMARY_TAG, componentName).getBoolean(); } catch (PackageManager.NameNotFoundException e) { return false; } } } Loading
core/java/android/companion/CompanionDeviceManager.java +3 −3 Original line number Diff line number Diff line Loading @@ -780,9 +780,9 @@ public final class CompanionDeviceManager { } /** * Notify the system that the given self-managed association has just 'appeared'. * Notify the system that the given self-managed association has just appeared. * This causes the system to bind to the companion app to keep it running until the association * is reported as 'disappeared' * is reported as disappeared * * <p>This API is only available for the companion apps that manage the connectivity by * themselves.</p> Loading @@ -803,7 +803,7 @@ public final class CompanionDeviceManager { } /** * Notify the system that the given self-managed association has just 'disappeared'. * Notify the system that the given self-managed association has just disappeared. * This causes the system to unbind to the companion app. * * <p>This API is only available for the companion apps that manage the connectivity by Loading
core/java/android/companion/CompanionDeviceService.java +4 −3 Original line number Diff line number Diff line Loading @@ -77,10 +77,11 @@ import java.util.Objects; * {@link #onDeviceAppeared(AssociationInfo)} and {@link #onDeviceDisappeared(AssociationInfo)} * only to one "primary" services. * Applications that declare multiple {@link CompanionDeviceService}-s should indicate the "primary" * service using "android.companion.primary" tag. * service using "android.companion.PROPERTY_PRIMARY_COMPANION_DEVICE_SERVICE" service level * property. * <pre>{@code * <meta-data * android:name="android.companion.primary" * <property * android:name="android.companion.PROPERTY_PRIMARY_COMPANION_DEVICE_SERVICE" * android:value="true" /> * }</pre> * Loading
services/companion/java/com/android/server/companion/PackageUtils.java +13 −8 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.server.companion; import static android.content.pm.PackageManager.FEATURE_COMPANION_DEVICE_SETUP; import static android.content.pm.PackageManager.GET_CONFIGURATIONS; import static android.content.pm.PackageManager.GET_META_DATA; import static android.content.pm.PackageManager.GET_PERMISSIONS; import static com.android.server.companion.CompanionDeviceManagerService.TAG; Loading Loading @@ -53,7 +52,8 @@ import java.util.Map; final class PackageUtils { private static final Intent COMPANION_SERVICE_INTENT = new Intent(CompanionDeviceService.SERVICE_INTERFACE); private static final String META_DATA_PRIMARY_TAG = "android.companion.primary"; private static final String PROPERTY_PRIMARY_TAG = "android.companion.PROPERTY_PRIMARY_COMPANION_DEVICE_SERVICE"; static @Nullable PackageInfo getPackageInfo(@NonNull Context context, @UserIdInt int userId, @NonNull String packageName) { Loading Loading @@ -84,9 +84,8 @@ final class PackageUtils { static @NonNull Map<String, List<ComponentName>> getCompanionServicesForUser( @NonNull Context context, @UserIdInt int userId) { final PackageManager pm = context.getPackageManager(); final ResolveInfoFlags flags = ResolveInfoFlags.of(GET_META_DATA); final List<ResolveInfo> companionServices = pm.queryIntentServicesAsUser(COMPANION_SERVICE_INTENT, flags, userId); final List<ResolveInfo> companionServices = pm.queryIntentServicesAsUser( COMPANION_SERVICE_INTENT, ResolveInfoFlags.of(0), userId); final Map<String, List<ComponentName>> packageNameToServiceInfoList = new HashMap<>(); Loading @@ -109,7 +108,8 @@ final class PackageUtils { service.packageName, it -> new LinkedList<>()); final ComponentName componentName = service.getComponentName(); if (isPrimaryCompanionDeviceService(service)) { if (isPrimaryCompanionDeviceService(pm, componentName)) { // "Primary" service should be at the head of the list. services.addFirst(componentName); } else { Loading @@ -120,7 +120,12 @@ final class PackageUtils { return packageNameToServiceInfoList; } private static boolean isPrimaryCompanionDeviceService(ServiceInfo service) { return service.metaData != null && service.metaData.getBoolean(META_DATA_PRIMARY_TAG); private static boolean isPrimaryCompanionDeviceService(@NonNull PackageManager pm, @NonNull ComponentName componentName) { try { return pm.getProperty(PROPERTY_PRIMARY_TAG, componentName).getBoolean(); } catch (PackageManager.NameNotFoundException e) { return false; } } }