Home | History | Annotate | Download | only in gatt
      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.WorkSource;
     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     int clientIf;
     35     boolean isServer;
     36     UUID[] uuids;
     37     ScanSettings settings;
     38     List<ScanFilter> filters;
     39     List<List<ResultStorageDescriptor>> storages;
     40     // App associated with the scan client died.
     41     boolean appDied;
     42     boolean hasLocationPermission;
     43     boolean hasPeersMacAddressPermission;
     44     // Pre-M apps are allowed to get scan results even if location is disabled
     45     boolean legacyForegroundApp;
     46 
     47     // Who is responsible for this scan.
     48     WorkSource workSource;
     49 
     50     AppScanStats stats = null;
     51 
     52     private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder()
     53             .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
     54 
     55     ScanClient(int appIf, boolean isServer) {
     56         this(appIf, isServer, new UUID[0], DEFAULT_SCAN_SETTINGS, null, null, null);
     57     }
     58 
     59     ScanClient(int appIf, boolean isServer, UUID[] uuids) {
     60         this(appIf, isServer, uuids, DEFAULT_SCAN_SETTINGS, null, null, null);
     61     }
     62 
     63     ScanClient(int appIf, boolean isServer, ScanSettings settings,
     64             List<ScanFilter> filters) {
     65         this(appIf, isServer, new UUID[0], settings, filters, null, null);
     66     }
     67 
     68     ScanClient(int appIf, boolean isServer, ScanSettings settings,
     69             List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages) {
     70         this(appIf, isServer, new UUID[0], settings, filters, null, storages);
     71     }
     72 
     73     ScanClient(int appIf, boolean isServer, ScanSettings settings,
     74                List<ScanFilter> filters, WorkSource workSource,
     75                List<List<ResultStorageDescriptor>> storages) {
     76         this(appIf, isServer, new UUID[0], settings, filters, workSource, storages);
     77     }
     78 
     79     private ScanClient(int appIf, boolean isServer, UUID[] uuids, ScanSettings settings,
     80             List<ScanFilter> filters, WorkSource workSource,
     81             List<List<ResultStorageDescriptor>> storages) {
     82         this.clientIf = appIf;
     83         this.isServer = isServer;
     84         this.uuids = uuids;
     85         this.settings = settings;
     86         this.filters = filters;
     87         this.workSource = workSource;
     88         this.storages = storages;
     89     }
     90 
     91     @Override
     92     public boolean equals(Object obj) {
     93         if (this == obj) {
     94             return true;
     95         }
     96         if (obj == null || getClass() != obj.getClass()) {
     97             return false;
     98         }
     99         ScanClient other = (ScanClient) obj;
    100         return clientIf == other.clientIf;
    101     }
    102 
    103     @Override
    104     public int hashCode() {
    105         return Objects.hash(clientIf);
    106     }
    107 }
    108