• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Define LOG_TAG before <log/log.h> to overwrite the default value.
18 #define LOG_TAG "GnssVisibilityControlJni"
19 
20 #include "GnssVisibilityControl.h"
21 
22 #include "Utils.h"
23 
24 using IGnssVisibilityControlAidl =
25         android::hardware::gnss::visibility_control::IGnssVisibilityControl;
26 using IGnssVisibilityControlHidl =
27         android::hardware::gnss::visibility_control::V1_0::IGnssVisibilityControl;
28 
29 namespace android::gnss {
30 
31 // Implementation of GnssVisibilityControl (AIDL HAL)
32 
GnssVisibilityControlAidl(const sp<IGnssVisibilityControlAidl> & iGnssVisibilityControl)33 GnssVisibilityControlAidl::GnssVisibilityControlAidl(
34         const sp<IGnssVisibilityControlAidl>& iGnssVisibilityControl)
35       : mIGnssVisibilityControlAidl(iGnssVisibilityControl) {
36     assert(mIGnssVisibilityControlAidl != nullptr);
37 }
38 
setCallback(const std::unique_ptr<GnssVisibilityControlCallback> & callback)39 jboolean GnssVisibilityControlAidl::setCallback(
40         const std::unique_ptr<GnssVisibilityControlCallback>& callback) {
41     auto status = mIGnssVisibilityControlAidl->setCallback(callback->getAidl());
42     return checkAidlStatus(status, "IGnssVisibilityControlAidl setCallback() failed.");
43 }
44 
enableNfwLocationAccess(JNIEnv * env,jobjectArray proxyApps)45 jboolean GnssVisibilityControlAidl::enableNfwLocationAccess(JNIEnv* env, jobjectArray proxyApps) {
46     int length = env->GetArrayLength(proxyApps);
47     std::vector<std::string> aidlProxyApps(length);
48     for (int i = 0; i < length; ++i) {
49         jstring proxyApp = (jstring)(env->GetObjectArrayElement(proxyApps, i));
50         ScopedJniString jniProxyApp(env, proxyApp);
51         aidlProxyApps[i] = std::string(jniProxyApp.c_str());
52     }
53     auto status = mIGnssVisibilityControlAidl->enableNfwLocationAccess(aidlProxyApps);
54     return checkAidlStatus(status, "IGnssVisibilityControlAidl enableNfwLocationAccess() failed");
55 }
56 
57 // Implementation of GnssVisibilityControlHidl
58 
GnssVisibilityControlHidl(const sp<IGnssVisibilityControlHidl> & iGnssVisibilityControl)59 GnssVisibilityControlHidl::GnssVisibilityControlHidl(
60         const sp<IGnssVisibilityControlHidl>& iGnssVisibilityControl)
61       : mIGnssVisibilityControlHidl(iGnssVisibilityControl) {
62     assert(mIGnssVisibilityControlHidl != nullptr);
63 }
64 
setCallback(const std::unique_ptr<GnssVisibilityControlCallback> & callback)65 jboolean GnssVisibilityControlHidl::setCallback(
66         const std::unique_ptr<GnssVisibilityControlCallback>& callback) {
67     auto result = mIGnssVisibilityControlHidl->setCallback(callback->getHidl());
68     return checkHidlReturn(result, "IGnssVisibilityControlHidl setCallback() failed.");
69 }
70 
enableNfwLocationAccess(JNIEnv * env,jobjectArray proxyApps)71 jboolean GnssVisibilityControlHidl::enableNfwLocationAccess(JNIEnv* env, jobjectArray proxyApps) {
72     const jsize length = env->GetArrayLength(proxyApps);
73     hardware::hidl_vec<hardware::hidl_string> hidlProxyApps(length);
74     for (int i = 0; i < length; ++i) {
75         jstring proxyApp = (jstring)(env->GetObjectArrayElement(proxyApps, i));
76         ScopedJniString jniProxyApp(env, proxyApp);
77         hidlProxyApps[i] = jniProxyApp;
78     }
79 
80     auto result = mIGnssVisibilityControlHidl->enableNfwLocationAccess(hidlProxyApps);
81     return checkHidlReturn(result, "IGnssVisibilityControlHidl enableNfwLocationAccess() failed.");
82 }
83 
84 } // namespace android::gnss
85