Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 120de6c1 authored by Eugene Susla's avatar Eugene Susla
Browse files

Provide CDM API to associate without prompt

For use via FastPair(within GMSCore)

Bug: 165951651
Test: atest CompanionDeviceManagerTest
Change-Id: I7b94d52e59ad39e1d93360685cf64a3dc068d05e
parent eb8c8105
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -2178,6 +2178,7 @@ package android.bluetooth.le {
package android.companion {
package android.companion {
  public final class CompanionDeviceManager {
  public final class CompanionDeviceManager {
    method @RequiresPermission("android.permission.ASSOCIATE_COMPANION_DEVICES") public boolean associate(@NonNull String, @NonNull android.net.MacAddress);
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean canPairWithoutPrompt(@NonNull String, @NonNull String, int);
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean canPairWithoutPrompt(@NonNull String, @NonNull String, int);
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean isDeviceAssociatedForWifiConnection(@NonNull String, @NonNull android.net.MacAddress, @NonNull android.os.UserHandle);
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean isDeviceAssociatedForWifiConnection(@NonNull String, @NonNull android.net.MacAddress, @NonNull android.os.UserHandle);
  }
  }
+26 −0
Original line number Original line Diff line number Diff line
@@ -425,6 +425,32 @@ public final class CompanionDeviceManager {
                    mContext.getPackageName(), deviceAddress);
                    mContext.getPackageName(), deviceAddress);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class);
            ExceptionUtils.propagateIfInstanceOf(e.getCause(), DeviceNotAssociatedException.class);
        }
    }

    /**
     * Associates given device with given app for the given user directly, without UI prompt.
     *
     * @return whether successful
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.ASSOCIATE_COMPANION_DEVICES)
    public boolean associate(
            @NonNull String packageName,
            @NonNull MacAddress macAddress) {
        if (!checkFeaturePresent()) {
            return false;
        }
        Objects.requireNonNull(packageName, "package name cannot be null");
        Objects.requireNonNull(macAddress, "mac address cannot be null");

        UserHandle user = android.os.Process.myUserHandle();
        try {
            return mService.createAssociation(
                    packageName, macAddress.toString(), user.getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
    }
    }
+2 −0
Original line number Original line Diff line number Diff line
@@ -51,4 +51,6 @@ interface ICompanionDeviceManager {
    void unregisterDevicePresenceListenerService(in String packageName, in String deviceAddress);
    void unregisterDevicePresenceListenerService(in String packageName, in String deviceAddress);


    boolean canPairWithoutPrompt(in String packageName, in String deviceMacAddress, int userId);
    boolean canPairWithoutPrompt(in String packageName, in String deviceMacAddress, int userId);

    boolean createAssociation(in String packageName, in String macAddress, int userId);
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -4227,6 +4227,11 @@
    <permission android:name="android.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE"
    <permission android:name="android.permission.REQUEST_OBSERVE_COMPANION_DEVICE_PRESENCE"
                android:protectionLevel="normal" />
                android:protectionLevel="normal" />


    <!-- Allows an application to create new companion device associations.
         @hide -->
    <permission android:name="android.permission.ASSOCIATE_COMPANION_DEVICES"
        android:protectionLevel="internal|role" />

    <!-- @SystemApi Allows an application to use SurfaceFlinger's low level features.
    <!-- @SystemApi Allows an application to use SurfaceFlinger's low level features.
         <p>Not for use by third-party applications.
         <p>Not for use by third-party applications.
         @hide
         @hide
+7 −0
Original line number Original line Diff line number Diff line
@@ -3732,6 +3732,13 @@
     -->
     -->
    <string name="config_defaultWellbeingPackage" translatable="false"></string>
    <string name="config_defaultWellbeingPackage" translatable="false"></string>


    <!-- The package name for the companion provider app.
         This package must be trusted, as it has the permissions to associate apps with devices
         without a UI prompt.
         Example: "com.google.android.gms"
     -->
    <string name="config_companionProviderPackage" translatable="false"></string>

    <!-- The component name for the default system attention service.
    <!-- The component name for the default system attention service.
         This service must be trusted, as it can be activated without explicit consent of the user.
         This service must be trusted, as it can be activated without explicit consent of the user.
         See android.attention.AttentionManagerService.
         See android.attention.AttentionManagerService.
Loading