ScanClient.java revision 039bf1606bddb3794fd6aa9adee704733f89544f
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
42    private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder()
43            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
44
45    ScanClient(int appIf, boolean isServer) {
46        this(appIf, isServer, new UUID[0], DEFAULT_SCAN_SETTINGS, null, null);
47    }
48
49    ScanClient(int appIf, boolean isServer, UUID[] uuids) {
50        this(appIf, isServer, uuids, DEFAULT_SCAN_SETTINGS, null, null);
51    }
52
53    ScanClient(int appIf, boolean isServer, ScanSettings settings,
54            List<ScanFilter> filters) {
55        this(appIf, isServer, new UUID[0], settings, filters, null);
56    }
57
58    ScanClient(int appIf, boolean isServer, ScanSettings settings,
59            List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages) {
60        this(appIf, isServer, new UUID[0], settings, filters, storages);
61    }
62
63    private ScanClient(int appIf, boolean isServer, UUID[] uuids, ScanSettings settings,
64            List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages) {
65        this.clientIf = appIf;
66        this.isServer = isServer;
67        this.uuids = uuids;
68        this.settings = settings;
69        this.filters = filters;
70        this.storages = storages;
71    }
72
73    @Override
74    public boolean equals(Object obj) {
75        if (this == obj) {
76            return true;
77        }
78        if (obj == null || getClass() != obj.getClass()) {
79            return false;
80        }
81        ScanClient other = (ScanClient) obj;
82        return clientIf == other.clientIf;
83    }
84
85    @Override
86    public int hashCode() {
87        return Objects.hash(clientIf);
88    }
89}
90