blob: 4dec1c6a852ea2dfe4835e3ae546e5383b380f03 [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,
Yu-Han Yang669be842021-04-26 20:17:53 -070053 .totalEnergyMilliJoule = 1.500e+3 + numLocationReported * 22.0,
54 .singlebandTrackingModeEnergyMilliJoule = 0.0,
55 .multibandTrackingModeEnergyMilliJoule = 1.28e+2 + numLocationReported * 4.0,
56 .singlebandAcquisitionModeEnergyMilliJoule = 0.0,
57 .multibandAcquisitionModeEnergyMilliJoule = 3.65e+2 + numLocationReported * 15.0,
Yu-Han Yang24753612020-10-27 14:42:14 -070058 .otherModesEnergyMilliJoule = {1.232e+2, 3.234e+3},
59 };
60 sCallback->gnssPowerStatsCb(gnssPowerStats);
61 return ndk::ScopedAStatus::ok();
62}
63
Yu-Han Yang669be842021-04-26 20:17:53 -070064void GnssPowerIndication::notePowerConsumption() {
65 numLocationReported++;
66}
67
Yu-Han Yang24753612020-10-27 14:42:14 -070068} // namespace aidl::android::hardware::gnss