103b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta/*
203b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * Copyright (C) 2013 The Android Open Source Project
303b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta *
403b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * Licensed under the Apache License, Version 2.0 (the "License");
503b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * you may not use this file except in compliance with the License.
603b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * You may obtain a copy of the License at
703b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta *
803b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta *      http://www.apache.org/licenses/LICENSE-2.0
903b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta *
1003b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * Unless required by applicable law or agreed to in writing, software
1103b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * distributed under the License is distributed on an "AS IS" BASIS,
1203b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1303b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * See the License for the specific language governing permissions and
1403b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * limitations under the License.
1503b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta */
1603b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta
1703b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Battapackage com.android.bluetooth.gatt;
1803b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta
19c1d460a4ee15238f33e9c2a61b571965accf9838Wei Wangimport android.bluetooth.le.ResultStorageDescriptor;
2080e7d011fdb511a6583258458e97821176866baaWei Wangimport android.bluetooth.le.ScanFilter;
21cf7cb8478523185da2ff851bb0de96fe95b3e77cWei Wangimport android.bluetooth.le.ScanSettings;
2244f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinskiimport android.os.WorkSource;
231a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang
241a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wangimport java.util.List;
259c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wangimport java.util.Objects;
2603b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Battaimport java.util.UUID;
2703b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta
2803b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta/**
2903b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * Helper class identifying a client that has requested LE scan results.
301a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang *
3103b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta * @hide
3203b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta */
331a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang/* package */class ScanClient {
349c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang    int clientIf;
3503b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta    boolean isServer;
3603b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta    UUID[] uuids;
3780e7d011fdb511a6583258458e97821176866baaWei Wang    ScanSettings settings;
3880e7d011fdb511a6583258458e97821176866baaWei Wang    List<ScanFilter> filters;
39c1d460a4ee15238f33e9c2a61b571965accf9838Wei Wang    List<List<ResultStorageDescriptor>> storages;
40039bf1606bddb3794fd6aa9adee704733f89544fWei Wang    // App associated with the scan client died.
41039bf1606bddb3794fd6aa9adee704733f89544fWei Wang    boolean appDied;
42d2fc8cbd87c7a742223e8742a442a48690d426ceFyodor Kupolov    boolean hasLocationPermission;
43312e10ad5bcbb1e3d021c4798d55c40f99c7a6efFyodor Kupolov    boolean hasPeersMacAddressPermission;
44a072c9e05c551dba0a938e158cb3a650c18b4dedFyodor Kupolov    // Pre-M apps are allowed to get scan results even if location is disabled
45a072c9e05c551dba0a938e158cb3a650c18b4dedFyodor Kupolov    boolean legacyForegroundApp;
4650cc9194f72c040f04c2ae0f0322246a570e8bfaPrerepa Viswanadham
4744f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski    // Who is responsible for this scan.
4844f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski    WorkSource workSource;
4944f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski
50aef39f16e48cbae0ace8136c3235136c0a096061Ajay Panicker    AppScanStats stats = null;
51aef39f16e48cbae0ace8136c3235136c0a096061Ajay Panicker
52a2be7670787cc4576386bf4a8baea4b88d35e90bPrerepa Viswanadham    private static final ScanSettings DEFAULT_SCAN_SETTINGS = new ScanSettings.Builder()
53a2be7670787cc4576386bf4a8baea4b88d35e90bPrerepa Viswanadham            .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
5403b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta
5503b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta    ScanClient(int appIf, boolean isServer) {
5644f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski        this(appIf, isServer, new UUID[0], DEFAULT_SCAN_SETTINGS, null, null, null);
5703b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta    }
5803b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta
5903b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta    ScanClient(int appIf, boolean isServer, UUID[] uuids) {
6044f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski        this(appIf, isServer, uuids, DEFAULT_SCAN_SETTINGS, null, null, null);
611a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang    }
621a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang
6380e7d011fdb511a6583258458e97821176866baaWei Wang    ScanClient(int appIf, boolean isServer, ScanSettings settings,
6480e7d011fdb511a6583258458e97821176866baaWei Wang            List<ScanFilter> filters) {
6544f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski        this(appIf, isServer, new UUID[0], settings, filters, null, null);
66c1d460a4ee15238f33e9c2a61b571965accf9838Wei Wang    }
67c1d460a4ee15238f33e9c2a61b571965accf9838Wei Wang
68c1d460a4ee15238f33e9c2a61b571965accf9838Wei Wang    ScanClient(int appIf, boolean isServer, ScanSettings settings,
69039bf1606bddb3794fd6aa9adee704733f89544fWei Wang            List<ScanFilter> filters, List<List<ResultStorageDescriptor>> storages) {
7044f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski        this(appIf, isServer, new UUID[0], settings, filters, null, storages);
7144f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski    }
7244f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski
7344f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski    ScanClient(int appIf, boolean isServer, ScanSettings settings,
7444f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski               List<ScanFilter> filters, WorkSource workSource,
7544f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski               List<List<ResultStorageDescriptor>> storages) {
7644f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski        this(appIf, isServer, new UUID[0], settings, filters, workSource, storages);
771a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang    }
781a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang
79a2be7670787cc4576386bf4a8baea4b88d35e90bPrerepa Viswanadham    private ScanClient(int appIf, boolean isServer, UUID[] uuids, ScanSettings settings,
8044f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski            List<ScanFilter> filters, WorkSource workSource,
8144f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski            List<List<ResultStorageDescriptor>> storages) {
829c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang        this.clientIf = appIf;
8303b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta        this.isServer = isServer;
8403b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta        this.uuids = uuids;
851a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang        this.settings = settings;
861a2f87a202a4d634f0b6b5b6e9a8545796207288Wei Wang        this.filters = filters;
8744f6d970c611bb13000f4eae052a6de316191fa4Adam Lesinski        this.workSource = workSource;
88c1d460a4ee15238f33e9c2a61b571965accf9838Wei Wang        this.storages = storages;
8903b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta    }
909c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang
919c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang    @Override
929c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang    public boolean equals(Object obj) {
939c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang        if (this == obj) {
949c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang            return true;
959c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang        }
969c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang        if (obj == null || getClass() != obj.getClass()) {
979c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang            return false;
989c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang        }
999c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang        ScanClient other = (ScanClient) obj;
1009c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang        return clientIf == other.clientIf;
1019c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang    }
1029c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang
1039c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang    @Override
1049c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang    public int hashCode() {
1059c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang        return Objects.hash(clientIf);
1069c24a0ef159f3332a2e66648d8d3c7dfac26cbc8Wei Wang    }
10703b8386de26ba6500af2d66687bff9b01f2cbbd7Ganesh Ganapathi Batta}
108