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

Commit 47aafbe0 authored by Eugene Susla's avatar Eugene Susla
Browse files

Record app<->device association to xml file

Bug: 30932767
Test: Ensure file not exists -> query associations -> ensure result is empty list
  Associate device -> cat xml file -> ensure record appears as extected
  Disassociate device -> cat xml file -> ensure record is no longer present
Change-Id: Ibe456a6d9292e05e2391f5138e43fdaa37f87e1b
parent 280a9cfa
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -8046,6 +8046,8 @@ package android.companion {
  public final class CompanionDeviceManager {
    method public void associate(android.companion.AssociationRequest<?>, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
+2 −0
Original line number Diff line number Diff line
@@ -8546,6 +8546,8 @@ package android.companion {
  public final class CompanionDeviceManager {
    method public void associate(android.companion.AssociationRequest<?>, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
+2 −0
Original line number Diff line number Diff line
@@ -8073,6 +8073,8 @@ package android.companion {
  public final class CompanionDeviceManager {
    method public void associate(android.companion.AssociationRequest<?>, android.companion.CompanionDeviceManager.Callback, android.os.Handler);
    method public void disassociate(java.lang.String);
    method public java.util.List<java.lang.String> getAssociations();
    field public static final java.lang.String EXTRA_DEVICE = "android.companion.extra.DEVICE";
  }
+41 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;

import java.util.List;

/**
 * System level service for managing companion devices
 *
@@ -102,6 +104,11 @@ public final class CompanionDeviceManager {
     * special capabilities have a negative effect on the device's battery and user's data
     * usage, therefore you should requested them when absolutely necessary.</p>
     *
     * <p>You can call {@link #getAssociations} to get the list of currently associated
     * devices, and {@link #disassociate} to remove an association. Consider doing so when the
     * association is no longer relevant to avoid unnecessary battery and/or data drain resulting
     * from special privileges that the association provides</p>
     *
     * @param request specific details about this request
     * @param callback will be called once there's at least one device found for user to choose from
     * @param handler A handler to control which thread the callback will be delivered on, or null,
@@ -119,6 +126,8 @@ public final class CompanionDeviceManager {
        try {
            mService.associate(
                    request,
                    //TODO implicit pointer to outer class -> =null onDestroy
                    //TODO onStop if isFinishing -> stopScan
                    new IFindDeviceCallback.Stub() {
                        @Override
                        public void onSuccess(PendingIntent launcher) {
@@ -138,6 +147,38 @@ public final class CompanionDeviceManager {
        }
    }

    /**
     * @return a list of MAC addresses of devices that have been previously associated with the
     * current app. You can use these with {@link #disassociate}
     */
    @NonNull
    public List<String> getAssociations() {
        try {
            return mService.getAssociations(mContext.getPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Remove the association between this app and the device with the given mac address.
     *
     * <p>Any privileges provided via being associated with a given device will be revoked</p>
     *
     * <p>Consider doing so when the
     * association is no longer relevant to avoid unnecessary battery and/or data drain resulting
     * from special privileges that the association provides</p>
     *
     * @param deviceMacAddress the MAC address of device to disassociate from this app
     */
    public void disassociate(@NonNull String deviceMacAddress) {
        try {
            mService.disassociate(deviceMacAddress, mContext.getPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /** @hide */
    public void requestNotificationAccess() {
        //TODO implement
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.companion.AssociationRequest;
import android.companion.ICompanionDeviceDiscoveryServiceCallback;
import android.companion.IFindDeviceCallback;


/** @hide */
interface ICompanionDeviceDiscoveryService {
    void startDiscovery(
Loading