• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 "StatsPullAtomService"
18 
19 #include <jni.h>
20 #include <log/log.h>
21 #include <nativehelper/JNIHelp.h>
22 #include <stats_event.h>
23 #include <stats_pull_atom_callback.h>
24 #include <statslog.h>
25 
26 #include "stats/PowerStatsPuller.h"
27 #include "stats/SubsystemSleepStatePuller.h"
28 
29 namespace android {
30 
31 static server::stats::PowerStatsPuller gPowerStatsPuller;
32 static server::stats::SubsystemSleepStatePuller gSubsystemSleepStatePuller;
33 
onDevicePowerMeasurementCallback(int32_t atom_tag,AStatsEventList * data,void * cookie)34 static AStatsManager_PullAtomCallbackReturn onDevicePowerMeasurementCallback(int32_t atom_tag,
35                                                                              AStatsEventList* data,
36                                                                              void* cookie) {
37     return gPowerStatsPuller.Pull(atom_tag, data);
38 }
39 
subsystemSleepStateCallback(int32_t atom_tag,AStatsEventList * data,void * cookie)40 static AStatsManager_PullAtomCallbackReturn subsystemSleepStateCallback(int32_t atom_tag,
41                                                                         AStatsEventList* data,
42                                                                         void* cookie) {
43     return gSubsystemSleepStatePuller.Pull(atom_tag, data);
44 }
45 
nativeInit(JNIEnv * env,jobject javaObject)46 static void nativeInit(JNIEnv* env, jobject javaObject) {
47     // on device power measurement
48     gPowerStatsPuller = server::stats::PowerStatsPuller();
49     AStatsManager_setPullAtomCallback(android::util::ON_DEVICE_POWER_MEASUREMENT,
50                                       /* metadata= */ nullptr, onDevicePowerMeasurementCallback,
51                                       /* cookie= */ nullptr);
52 
53     // subsystem sleep state
54     gSubsystemSleepStatePuller = server::stats::SubsystemSleepStatePuller();
55     AStatsManager_setPullAtomCallback(android::util::SUBSYSTEM_SLEEP_STATE,
56                                       /* metadata= */ nullptr, subsystemSleepStateCallback,
57                                       /* cookie= */ nullptr);
58 }
59 
60 static const JNINativeMethod sMethods[] = {{"nativeInit", "()V", (void*)nativeInit}};
61 
register_android_server_stats_pull_StatsPullAtomService(JNIEnv * env)62 int register_android_server_stats_pull_StatsPullAtomService(JNIEnv* env) {
63     int res = jniRegisterNativeMethods(env, "com/android/server/stats/pull/StatsPullAtomService",
64                                        sMethods, NELEM(sMethods));
65     if (res < 0) {
66         ALOGE("failed to register native methods");
67     }
68     return res;
69 }
70 
71 } // namespace android
72