• 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.ScanFilter;
20 import android.bluetooth.le.ScanSettings;
21 import android.os.Binder;
22 import android.os.UserHandle;
23 
24 import java.util.List;
25 import java.util.Objects;
26 
27 /**
28  * Helper class identifying a client that has requested LE scan results.
29  *
30  * @hide
31  */
32 /* package */class ScanClient {
33     public int scannerId;
34     public ScanSettings settings;
35     public int scanModeApp;
36     public boolean started = false;
37     public int appUid;
38     public List<ScanFilter> filters;
39     // App associated with the scan client died.
40     public boolean appDied;
41     public boolean hasLocationPermission;
42     public UserHandle userHandle;
43     public boolean isQApp;
44     public boolean eligibleForSanitizedExposureNotification;
45     public boolean hasNetworkSettingsPermission;
46     public boolean hasNetworkSetupWizardPermission;
47     public boolean hasScanWithoutLocationPermission;
48     public boolean hasDisavowedLocation;
49     public List<String> associatedDevices;
50 
51     public AppScanStats stats = null;
52 
53     private static final ScanSettings DEFAULT_SCAN_SETTINGS =
54             new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
55 
ScanClient(int scannerId)56     ScanClient(int scannerId) {
57         this(scannerId, DEFAULT_SCAN_SETTINGS, null);
58     }
59 
ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters)60     ScanClient(int scannerId, ScanSettings settings, List<ScanFilter> filters) {
61         this.scannerId = scannerId;
62         this.settings = settings;
63         this.scanModeApp = settings.getScanMode();
64         this.filters = filters;
65         this.appUid = Binder.getCallingUid();
66     }
67 
68     @Override
equals(Object obj)69     public boolean equals(Object obj) {
70         if (this == obj) {
71             return true;
72         }
73         if (obj == null || getClass() != obj.getClass()) {
74             return false;
75         }
76         ScanClient other = (ScanClient) obj;
77         return scannerId == other.scannerId;
78     }
79 
80     @Override
hashCode()81     public int hashCode() {
82         return Objects.hash(scannerId);
83     }
84 
85     @Override
toString()86     public String toString() {
87         StringBuilder sb = new StringBuilder();
88         sb.append(" [ScanClient")
89                 .append(" scanModeApp ").append(scanModeApp)
90                 .append(" scanModeUsed ").append(settings.getScanMode());
91         if (stats != null && stats.appName != null) {
92             sb.append(" [appScanStats ").append(stats.appName).append("]");
93         }
94         sb.append("]");
95         return sb.toString();
96     }
97 
98     /**
99      * Update scan settings with the new scan mode.
100      * @param newScanMode
101      * @return true if scan settings are updated, false otherwise.
102      */
updateScanMode(int newScanMode)103     public boolean updateScanMode(int newScanMode) {
104         if (settings.getScanMode() == newScanMode) {
105             return false;
106         }
107 
108         ScanSettings.Builder builder = new ScanSettings.Builder();
109         settings = builder.setScanMode(newScanMode)
110                 .setCallbackType(settings.getCallbackType())
111                 .setScanResultType(settings.getScanResultType())
112                 .setReportDelay(settings.getReportDelayMillis())
113                 .setNumOfMatches(settings.getNumOfMatches())
114                 .setMatchMode(settings.getMatchMode())
115                 .setLegacy(settings.getLegacy())
116                 .setPhy(settings.getPhy())
117                 .build();
118         return true;
119     }
120 }
121