blob: 429cc8c0e05452688e33c6ed1aee2a21c4168543 [file] [log] [blame]
Yu-Han Yang24753612020-10-27 14:42:14 -07001/*
2 * Copyright (C) 2020 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 "GnssPowerIndicationAidl"
18
19#include "GnssPowerIndication.h"
20#include <aidl/android/hardware/gnss/BnGnss.h>
21#include <log/log.h>
Yu-Han Yang04832302020-11-20 09:51:18 -080022#include <utils/SystemClock.h>
Yu-Han Yang24753612020-10-27 14:42:14 -070023
24namespace aidl::android::hardware::gnss {
25
26std::shared_ptr<IGnssPowerIndicationCallback> GnssPowerIndication::sCallback = nullptr;
27
28ndk::ScopedAStatus GnssPowerIndication::setCallback(
29 const std::shared_ptr<IGnssPowerIndicationCallback>& callback) {
30 ALOGD("setCallback");
31 std::unique_lock<std::mutex> lock(mMutex);
32 sCallback = callback;
33 sCallback->setCapabilitiesCb(IGnssPowerIndicationCallback::CAPABILITY_TOTAL |
34 IGnssPowerIndicationCallback::CAPABILITY_SINGLEBAND_TRACKING |
35 IGnssPowerIndicationCallback::CAPABILITY_MULTIBAND_TRACKING |
36 IGnssPowerIndicationCallback::CAPABILITY_SINGLEBAND_ACQUISITION |
37 IGnssPowerIndicationCallback::CAPABILITY_MULTIBAND_ACQUISITION |
38 IGnssPowerIndicationCallback::CAPABILITY_OTHER_MODES);
39 return ndk::ScopedAStatus::ok();
40}
41
42ndk::ScopedAStatus GnssPowerIndication::requestGnssPowerStats() {
43 ALOGD("requestGnssPowerStats");
44 std::unique_lock<std::mutex> lock(mMutex);
45
46 ElapsedRealtime elapsedRealtime = {
Yu-Han Yang04832302020-11-20 09:51:18 -080047 .flags = ElapsedRealtime::HAS_TIMESTAMP_NS | ElapsedRealtime::HAS_TIME_UNCERTAINTY_NS,
48 .timestampNs = ::android::elapsedRealtimeNano(),
49 .timeUncertaintyNs = 1000,
Yu-Han Yang24753612020-10-27 14:42:14 -070050 };
51 GnssPowerStats gnssPowerStats = {
52 .elapsedRealtime = elapsedRealtime,
53 .totalEnergyMilliJoule = 1.59975e+3,
54 .singlebandTrackingModeEnergyMilliJoule = 1.2342e+3,
55 .multibandTrackingModeEnergyMilliJoule = 3.653e+2,
56 .otherModesEnergyMilliJoule = {1.232e+2, 3.234e+3},
57 };
58 sCallback->gnssPowerStatsCb(gnssPowerStats);
59 return ndk::ScopedAStatus::ok();
60}
61
62} // namespace aidl::android::hardware::gnss