1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 package android.companion;
19 
20 import android.annotation.IntDef;
21 import android.annotation.Nullable;
22 import android.compat.annotation.UnsupportedAppUsage;
23 import android.os.Build;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /**
30  * A filter for companion devices of type {@code D}
31  *
32  * @param <D> Type of devices, filtered by this filter,
33  *           e.g. {@link android.bluetooth.BluetoothDevice}, {@link android.net.wifi.ScanResult}
34  */
35 public interface DeviceFilter<D extends Parcelable> extends Parcelable {
36 
37     /** @hide */
38     int MEDIUM_TYPE_BLUETOOTH = 0;
39     /** @hide */
40     int MEDIUM_TYPE_BLUETOOTH_LE = 1;
41     /** @hide */
42     int MEDIUM_TYPE_WIFI = 2;
43 
44     /**
45      * @return whether the given device matches this filter
46      *
47      * @hide
48      */
49     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
matches(D device)50     boolean matches(D device);
51 
52     /** @hide */
53     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
getDeviceDisplayName(D device)54     String getDeviceDisplayName(D device);
55 
56     /**  @hide */
getMediumType()57     @MediumType int getMediumType();
58 
59     /**
60      * A nullsafe {@link #matches(Parcelable)}, returning true if the filter is null
61      *
62      * @hide
63      */
matches(@ullable DeviceFilter<D> filter, D device)64     static <D extends Parcelable> boolean matches(@Nullable DeviceFilter<D> filter, D device) {
65         return filter == null || filter.matches(device);
66     }
67 
68     /** @hide */
69     @IntDef(prefix = { "MEDIUM_TYPE_" }, value = {
70             MEDIUM_TYPE_BLUETOOTH,
71             MEDIUM_TYPE_BLUETOOTH_LE,
72             MEDIUM_TYPE_WIFI
73     })
74     @Retention(RetentionPolicy.SOURCE)
75     @interface MediumType {}
76 }
77