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 #ifndef _ANDROID_SERVER_GNSS_AGNSSRILCALLBACK_H
18 #define _ANDROID_SERVER_GNSS_AGNSSRILCALLBACK_H
19 
20 #pragma once
21 
22 #ifndef LOG_TAG
23 #error LOG_TAG must be defined before including this file.
24 #endif
25 
26 #include <android/hardware/gnss/1.0/IAGnssRil.h>
27 #include <android/hardware/gnss/BnAGnssRilCallback.h>
28 #include <log/log.h>
29 
30 #include "Utils.h"
31 #include "jni.h"
32 
33 namespace android::gnss {
34 
35 void AGnssRil_class_init_once(JNIEnv* env, jclass clazz);
36 
37 /*
38  * AGnssRilCallbackAidl class implements the callback methods required by the
39  * android::hardware::gnss::IAGnssRil interface.
40  */
41 class AGnssRilCallbackAidl : public android::hardware::gnss::BnAGnssRilCallback {
42 public:
43     binder::Status requestSetIdCb(int setIdflag) override;
44     binder::Status requestRefLocCb() override;
45 };
46 
47 /*
48  * AGnssRilCallback_V1_0 implements callback methods required by the IAGnssRilCallback 1.0
49  * interface.
50  */
51 class AGnssRilCallback_V1_0 : public android::hardware::gnss::V1_0::IAGnssRilCallback {
52 public:
53     // Methods from ::android::hardware::gps::V1_0::IAGnssRilCallback follow.
54     hardware::Return<void> requestSetIdCb(uint32_t setIdflag) override;
55     hardware::Return<void> requestRefLocCb() override;
56 };
57 
58 class AGnssRilCallback {
59 public:
AGnssRilCallback()60     AGnssRilCallback() {}
getAidl()61     sp<AGnssRilCallbackAidl> getAidl() {
62         if (callbackAidl == nullptr) {
63             callbackAidl = sp<AGnssRilCallbackAidl>::make();
64         }
65         return callbackAidl;
66     }
67 
getV1_0()68     sp<AGnssRilCallback_V1_0> getV1_0() {
69         if (callbackV1_0 == nullptr) {
70             callbackV1_0 = sp<AGnssRilCallback_V1_0>::make();
71         }
72         return callbackV1_0;
73     }
74 
75 private:
76     sp<AGnssRilCallbackAidl> callbackAidl;
77     sp<AGnssRilCallback_V1_0> callbackV1_0;
78 };
79 
80 struct AGnssRilCallbackUtil {
81     static void requestSetIdCb(int setIdflag);
82     static void requestRefLocCb();
83 
84 private:
85     AGnssRilCallbackUtil() = delete;
86 };
87 
88 } // namespace android::gnss
89 
90 #endif // _ANDROID_SERVER_GNSS_AGNSSRILCALLBACK_H