1*4d7e907cSAndroid Build Coastguard Worker /*
2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2020 The Android Open Source Project
3*4d7e907cSAndroid Build Coastguard Worker *
4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*4d7e907cSAndroid Build Coastguard Worker *
8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*4d7e907cSAndroid Build Coastguard Worker *
10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License.
15*4d7e907cSAndroid Build Coastguard Worker */
16*4d7e907cSAndroid Build Coastguard Worker
17*4d7e907cSAndroid Build Coastguard Worker #define LOG_TAG "GnssPowerIndicationAidl"
18*4d7e907cSAndroid Build Coastguard Worker
19*4d7e907cSAndroid Build Coastguard Worker #include "GnssPowerIndication.h"
20*4d7e907cSAndroid Build Coastguard Worker #include <aidl/android/hardware/gnss/BnGnss.h>
21*4d7e907cSAndroid Build Coastguard Worker #include <log/log.h>
22*4d7e907cSAndroid Build Coastguard Worker #include <utils/SystemClock.h>
23*4d7e907cSAndroid Build Coastguard Worker
24*4d7e907cSAndroid Build Coastguard Worker namespace aidl::android::hardware::gnss {
25*4d7e907cSAndroid Build Coastguard Worker
26*4d7e907cSAndroid Build Coastguard Worker std::shared_ptr<IGnssPowerIndicationCallback> GnssPowerIndication::sCallback = nullptr;
27*4d7e907cSAndroid Build Coastguard Worker
setCallback(const std::shared_ptr<IGnssPowerIndicationCallback> & callback)28*4d7e907cSAndroid Build Coastguard Worker ndk::ScopedAStatus GnssPowerIndication::setCallback(
29*4d7e907cSAndroid Build Coastguard Worker const std::shared_ptr<IGnssPowerIndicationCallback>& callback) {
30*4d7e907cSAndroid Build Coastguard Worker ALOGD("setCallback");
31*4d7e907cSAndroid Build Coastguard Worker std::unique_lock<std::mutex> lock(mMutex);
32*4d7e907cSAndroid Build Coastguard Worker sCallback = callback;
33*4d7e907cSAndroid Build Coastguard Worker sCallback->setCapabilitiesCb(IGnssPowerIndicationCallback::CAPABILITY_TOTAL |
34*4d7e907cSAndroid Build Coastguard Worker IGnssPowerIndicationCallback::CAPABILITY_SINGLEBAND_TRACKING |
35*4d7e907cSAndroid Build Coastguard Worker IGnssPowerIndicationCallback::CAPABILITY_MULTIBAND_TRACKING |
36*4d7e907cSAndroid Build Coastguard Worker IGnssPowerIndicationCallback::CAPABILITY_SINGLEBAND_ACQUISITION |
37*4d7e907cSAndroid Build Coastguard Worker IGnssPowerIndicationCallback::CAPABILITY_MULTIBAND_ACQUISITION |
38*4d7e907cSAndroid Build Coastguard Worker IGnssPowerIndicationCallback::CAPABILITY_OTHER_MODES);
39*4d7e907cSAndroid Build Coastguard Worker return ndk::ScopedAStatus::ok();
40*4d7e907cSAndroid Build Coastguard Worker }
41*4d7e907cSAndroid Build Coastguard Worker
requestGnssPowerStats()42*4d7e907cSAndroid Build Coastguard Worker ndk::ScopedAStatus GnssPowerIndication::requestGnssPowerStats() {
43*4d7e907cSAndroid Build Coastguard Worker ALOGD("requestGnssPowerStats");
44*4d7e907cSAndroid Build Coastguard Worker std::unique_lock<std::mutex> lock(mMutex);
45*4d7e907cSAndroid Build Coastguard Worker
46*4d7e907cSAndroid Build Coastguard Worker ElapsedRealtime elapsedRealtime = {
47*4d7e907cSAndroid Build Coastguard Worker .flags = ElapsedRealtime::HAS_TIMESTAMP_NS | ElapsedRealtime::HAS_TIME_UNCERTAINTY_NS,
48*4d7e907cSAndroid Build Coastguard Worker .timestampNs = ::android::elapsedRealtimeNano(),
49*4d7e907cSAndroid Build Coastguard Worker .timeUncertaintyNs = 1000,
50*4d7e907cSAndroid Build Coastguard Worker };
51*4d7e907cSAndroid Build Coastguard Worker GnssPowerStats gnssPowerStats = {
52*4d7e907cSAndroid Build Coastguard Worker .elapsedRealtime = elapsedRealtime,
53*4d7e907cSAndroid Build Coastguard Worker .totalEnergyMilliJoule = 1.500e+3 + numLocationReported * 22.0,
54*4d7e907cSAndroid Build Coastguard Worker .singlebandTrackingModeEnergyMilliJoule = 0.0,
55*4d7e907cSAndroid Build Coastguard Worker .multibandTrackingModeEnergyMilliJoule = 1.28e+2 + numLocationReported * 4.0,
56*4d7e907cSAndroid Build Coastguard Worker .singlebandAcquisitionModeEnergyMilliJoule = 0.0,
57*4d7e907cSAndroid Build Coastguard Worker .multibandAcquisitionModeEnergyMilliJoule = 3.65e+2 + numLocationReported * 15.0,
58*4d7e907cSAndroid Build Coastguard Worker .otherModesEnergyMilliJoule = {1.232e+2, 3.234e+3},
59*4d7e907cSAndroid Build Coastguard Worker };
60*4d7e907cSAndroid Build Coastguard Worker sCallback->gnssPowerStatsCb(gnssPowerStats);
61*4d7e907cSAndroid Build Coastguard Worker return ndk::ScopedAStatus::ok();
62*4d7e907cSAndroid Build Coastguard Worker }
63*4d7e907cSAndroid Build Coastguard Worker
notePowerConsumption()64*4d7e907cSAndroid Build Coastguard Worker void GnssPowerIndication::notePowerConsumption() {
65*4d7e907cSAndroid Build Coastguard Worker numLocationReported++;
66*4d7e907cSAndroid Build Coastguard Worker }
67*4d7e907cSAndroid Build Coastguard Worker
68*4d7e907cSAndroid Build Coastguard Worker } // namespace aidl::android::hardware::gnss
69