ScanClient.java revision d2fc8cbd87c7a742223e8742a442a48690d426ce
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
17package com.android.bluetooth.gatt;
18
19import android.bluetooth.le.ResultStorageDescriptor;
20import android.bluetooth.le.ScanFilter;
21import android.bluetooth.le.ScanSettings;
22
23import java.util.List;
24import java.util.Objects;
25import 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 clientIf;
34    boolean isServer;
35    UUID[] uuids;
36    ScanSettings settings;
37    List<ScanFilter> filters;
38    List<List<ResultStorageDescriptor>> storages;
39    // App associated with the scan client died.
40    boolean appDied;
41    boolean hasLocationPermission;
42
43    private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder()
44            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
45
46    ScanClient(int appIf, boolean isServer) {
47        this(appIf, isServer, new UUID[0], DEFAULT_SCAN_SETTINGS, null, null);
48    }
49
50    ScanClient(int appIf, boolean isServer, UUID[] uuids) {
51        this(appIf, isServer, uuids, DEFAULT_SCAN_SETTINGS, null, null);
52    }
53
54    ScanClient(int appIf, boolean isServer, ScanSettings settings,
55            List<ScanFilter> filters) {
56        this(appIf, isServer, new UUID[0], settings, filters, null);
57    }
58
59    ScanClient(int appIf, boolean isServer, ScanSettings settings,
60            List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages) {
61        this(appIf, isServer, new UUID[0], settings, filters, storages);
62    }
63
64    private ScanClient(int appIf, boolean isServer, UUID[] uuids, ScanSettings settings,
65            List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages) {
66        this.clientIf = appIf;
67        this.isServer = isServer;
68        this.uuids = uuids;
69        this.settings = settings;
70        this.filters = filters;
71        this.storages = storages;
72    }
73
74    @Override
75    public boolean equals(Object obj) {
76        if (this == obj) {
77            return true;
78        }
79        if (obj == null || getClass() != obj.getClass()) {
80            return false;
81        }
82        ScanClient other = (ScanClient) obj;
83        return clientIf == other.clientIf;
84    }
85
86    @Override
87    public int hashCode() {
88        return Objects.hash(clientIf);
89    }
90}
91