1 /*
2  * Copyright (C) 2021 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 #include "permissions_util.h"
18 
19 #include "chre/util/macros.h"
20 #include "chre/util/system/napp_permissions.h"
21 
22 namespace android {
23 namespace hardware {
24 namespace contexthub {
25 namespace common {
26 namespace implementation {
27 
chreToAndroidPermissions(uint32_t chrePermissions)28 std::vector<std::string> chreToAndroidPermissions(uint32_t chrePermissions) {
29   std::vector<std::string> androidPermissions;
30   if (BITMASK_HAS_VALUE(chrePermissions,
31                         ::chre::NanoappPermissions::CHRE_PERMS_AUDIO)) {
32     androidPermissions.push_back(kRecordAudioPerm);
33   }
34 
35   if (BITMASK_HAS_VALUE(chrePermissions,
36                         ::chre::NanoappPermissions::CHRE_PERMS_GNSS) ||
37       BITMASK_HAS_VALUE(chrePermissions,
38                         ::chre::NanoappPermissions::CHRE_PERMS_WIFI) ||
39       BITMASK_HAS_VALUE(chrePermissions,
40                         ::chre::NanoappPermissions::CHRE_PERMS_WWAN)) {
41     androidPermissions.push_back(kFineLocationPerm);
42     androidPermissions.push_back(kBackgroundLocationPerm);
43   }
44 
45   if (BITMASK_HAS_VALUE(chrePermissions,
46                         ::chre::NanoappPermissions::CHRE_PERMS_BLE)) {
47     androidPermissions.push_back(kBluetoothScanPerm);
48   }
49 
50   return androidPermissions;
51 }
52 
53 }  // namespace implementation
54 }  // namespace common
55 }  // namespace contexthub
56 }  // namespace hardware
57 }  // namespace android
58