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

Commit e62958cb authored by Eugene Susla's avatar Eugene Susla
Browse files

Add CDM system api to check for association presence

Per agreement with wifi team, wifi stack will call into CDM when wifi
connection is requested, treating CDM record similarly to the previously
approved networks records, i.e. skipping UI when association exists.

Test: atest android.os.cts.CompanionDeviceManagerTest
Fixes: 143572863
Change-Id: I28b44076e594fb9357b5a543176d285414ef06f8
parent 4a0b1750
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1370,6 +1370,14 @@ package android.bluetooth.le {
}
package android.companion {
  public final class CompanionDeviceManager {
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean isDeviceAssociated(@NonNull String, @NonNull android.net.MacAddress, @NonNull android.os.UserHandle);
  }
}
package android.content {
  public class ContentProviderClient implements java.lang.AutoCloseable {
+8 −0
Original line number Diff line number Diff line
@@ -640,6 +640,14 @@ package android.bluetooth {

}

package android.companion {

  public final class CompanionDeviceManager {
    method @RequiresPermission("android.permission.MANAGE_COMPANION_DEVICES") public boolean isDeviceAssociated(@NonNull String, @NonNull android.net.MacAddress, @NonNull android.os.UserHandle);
  }

}

package android.content {

  public final class AutofillOptions implements android.os.Parcelable {
+37 −0
Original line number Diff line number Diff line
@@ -21,7 +21,10 @@ import static com.android.internal.util.Preconditions.checkNotNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.Activity;
import android.app.Application;
import android.app.PendingIntent;
@@ -29,9 +32,11 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.net.MacAddress;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.service.notification.NotificationListenerService;
import android.util.Log;

@@ -252,6 +257,38 @@ public final class CompanionDeviceManager {
        }
    }

    /**
     * Check if a given package was {@link #associate associated} with a device with given
     * mac address by given user.
     *
     * @param packageName the package to check for
     * @param macAddress the mac address or BSSID of the device to check for
     * @param user the user to check for
     * @return whether a corresponding association record exists
     *
     * @hide
     */
    @SystemApi
    @TestApi
    @RequiresPermission(android.Manifest.permission.MANAGE_COMPANION_DEVICES)
    public boolean isDeviceAssociated(
            @NonNull String packageName,
            @NonNull MacAddress macAddress,
            @NonNull UserHandle user) {
        if (!checkFeaturePresent()) {
            return false;
        }
        checkNotNull(packageName, "package name cannot be null");
        checkNotNull(macAddress, "mac address cannot be null");
        checkNotNull(user, "user cannot be null");
        try {
            return mService.isDeviceAssociated(
                    packageName, macAddress.toString(), user.getIdentifier());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    private boolean checkFeaturePresent() {
        boolean featurePresent = mService != null;
        if (!featurePresent && DEBUG) {
+2 −0
Original line number Diff line number Diff line
@@ -39,4 +39,6 @@ interface ICompanionDeviceManager {

    boolean hasNotificationAccess(in ComponentName component);
    PendingIntent requestNotificationAccess(in ComponentName component);

    boolean isDeviceAssociated(in String packageName, in String macAddress, int userId);
}
+40 −0
Original line number Diff line number Diff line
@@ -230,6 +230,15 @@ public class CollectionUtils {
        return find(items, predicate) != null;
    }

    /**
     * Returns whether there exists at least one element in the set for which
     * condition {@code predicate} is true
     */
    public static <T> boolean any(@Nullable Set<T> items,
            java.util.function.Predicate<T> predicate) {
        return find(items, predicate) != null;
    }

    /**
     * Returns the first element from the list for which
     * condition {@code predicate} is true, or null if there is no such element
@@ -244,6 +253,37 @@ public class CollectionUtils {
        return null;
    }

    /**
     * Returns the first element from the set for which
     * condition {@code predicate} is true, or null if there is no such element
     */
    public static @Nullable <T> T find(@Nullable Set<T> cur,
            java.util.function.Predicate<T> predicate) {
        if (cur == null || predicate == null) return null;
        int size = cur.size();
        if (size == 0) return null;
        try {
            if (cur instanceof ArraySet) {
                ArraySet<T> arraySet = (ArraySet<T>) cur;
                for (int i = 0; i < size; i++) {
                    T item = arraySet.valueAt(i);
                    if (predicate.test(item)) {
                        return item;
                    }
                }
            } else {
                for (T t : cur) {
                    if (predicate.test(t)) {
                        return t;
                    }
                }
            }
        } catch (Exception e) {
            throw ExceptionUtils.propagate(e);
        }
        return null;
    }

    /**
     * Similar to {@link List#add}, but with support for list values of {@code null} and
     * {@link Collections#emptyList}
Loading