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 "GnssVisibilityControlCbJni"
18
19 #include "GnssVisibilityControlCallback.h"
20
21 namespace android::gnss {
22
23 // using android::hardware::hidl_vec;
24 using binder::Status;
25 using hardware::Return;
26
27 namespace {
28 jmethodID method_reportNfwNotification;
29 jmethodID method_isInEmergencySession;
30 } // anonymous namespace
31
GnssVisibilityControl_class_init_once(JNIEnv * env,jclass clazz)32 void GnssVisibilityControl_class_init_once(JNIEnv* env, jclass clazz) {
33 method_reportNfwNotification =
34 env->GetMethodID(clazz, "reportNfwNotification",
35 "(Ljava/lang/String;BLjava/lang/String;BLjava/lang/String;BZZ)V");
36 method_isInEmergencySession = env->GetMethodID(clazz, "isInEmergencySession", "()Z");
37 }
38
39 // Implementation of GnssVisibilityControlCallbackAidl class.
40
nfwNotifyCb(const android::hardware::gnss::visibility_control::IGnssVisibilityControlCallback::NfwNotification & notification)41 Status GnssVisibilityControlCallbackAidl::nfwNotifyCb(
42 const android::hardware::gnss::visibility_control::IGnssVisibilityControlCallback::
43 NfwNotification& notification) {
44 GnssVisibilityControlCallbackUtil::nfwNotifyCb(notification);
45 return Status::ok();
46 }
47
isInEmergencySession(bool * _aidl_return)48 Status GnssVisibilityControlCallbackAidl::isInEmergencySession(bool* _aidl_return) {
49 *_aidl_return = GnssVisibilityControlCallbackUtil::isInEmergencySession();
50 return Status::ok();
51 }
52
53 // Implementation of GnssVisibilityControlCallbackHidl class.
54
nfwNotifyCb(const IGnssVisibilityControlCallback::NfwNotification & notification)55 Return<void> GnssVisibilityControlCallbackHidl::nfwNotifyCb(
56 const IGnssVisibilityControlCallback::NfwNotification& notification) {
57 GnssVisibilityControlCallbackUtil::nfwNotifyCb(notification);
58 return hardware::Void();
59 }
60
isInEmergencySession()61 Return<bool> GnssVisibilityControlCallbackHidl::isInEmergencySession() {
62 return GnssVisibilityControlCallbackUtil::isInEmergencySession();
63 }
64
65 // Implementation of GnssVisibilityControlCallbackUtil class.
66
isInEmergencySession()67 bool GnssVisibilityControlCallbackUtil::isInEmergencySession() {
68 JNIEnv* env = getJniEnv();
69 auto result = env->CallBooleanMethod(mCallbacksObj, method_isInEmergencySession);
70 checkAndClearExceptionFromCallback(env, __FUNCTION__);
71 return result;
72 }
73
74 template <>
ToJstring(JNIEnv * env,const String16 & value)75 jstring ToJstring(JNIEnv* env, const String16& value) {
76 const char16_t* str = value.c_str();
77 size_t len = value.size();
78 return env->NewString(reinterpret_cast<const jchar*>(str), len);
79 }
80
81 template <>
ToJstring(JNIEnv * env,const hardware::hidl_string & value)82 jstring ToJstring(JNIEnv* env, const hardware::hidl_string& value) {
83 return env->NewStringUTF(value.c_str());
84 }
85
86 } // namespace android::gnss
87