• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 package com.android.bluetooth.gatt;
18 
19 import android.bluetooth.le.ResultStorageDescriptor;
20 import android.bluetooth.le.ScanFilter;
21 import android.bluetooth.le.ScanSettings;
22 
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.UUID;
26 
27 /**
28  * Helper class identifying a client that has requested LE scan results.
29  *
30  * @hide
31  */
32 /* package */class ScanClient {
33     int scannerId;
34     UUID[] uuids;
35     ScanSettings settings;
36     List<ScanFilter> filters;
37     List<List<ResultStorageDescriptor>> storages;
38     // App associated with the scan client died.
39     boolean appDied;
40     boolean hasLocationPermission;
41     boolean hasPeersMacAddressPermission;
42     // Pre-M apps are allowed to get scan results even if location is disabled
43     boolean legacyForegroundApp;
44 
45     AppScanStats stats = null;
46 
47     private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder()
48             .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
49 
ScanClient(int scannerId)50     ScanClient(int scannerId) {
51         this(scannerId, new UUID[0], DEFAULT_SCAN_SETTINGS, null, null);
52     }
53 
ScanClient(int scannerId, UUID[] uuids)54     ScanClient(int scannerId, UUID[] uuids) {
55         this(scannerId, uuids, DEFAULT_SCAN_SETTINGS, null, null);
56     }
57 
ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters)58     ScanClient(int scannerId, ScanSettings settings,
59             List<ScanFilter> filters) {
60         this(scannerId, new UUID[0], settings, filters, null);
61     }
62 
ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages)63     ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters,
64             List<List<ResultStorageDescriptor>> storages) {
65         this(scannerId, new UUID[0], settings, filters, storages);
66     }
67 
ScanClient(int scannerId, UUID[] uuids, ScanSettings settings, List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages)68     private ScanClient(int scannerId, UUID[] uuids, ScanSettings settings, List<ScanFilter> filters,
69             List<List<ResultStorageDescriptor>> storages) {
70         this.scannerId = scannerId;
71         this.uuids = uuids;
72         this.settings = settings;
73         this.filters = filters;
74         this.storages = storages;
75     }
76 
77     @Override
equals(Object obj)78     public boolean equals(Object obj) {
79         if (this == obj) {
80             return true;
81         }
82         if (obj == null || getClass() != obj.getClass()) {
83             return false;
84         }
85         ScanClient other = (ScanClient) obj;
86         return scannerId == other.scannerId;
87     }
88 
89     @Override
hashCode()90     public int hashCode() {
91         return Objects.hash(scannerId);
92     }
93 }
94