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