Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c0ce432 authored by Jeffrey Huang's avatar Jeffrey Huang Committed by Android (Google) Code Review
Browse files

Merge changes I08c9a64e,I21e13dfa,I719c3164

* changes:
  Migrate onDevicePowerMeasurement to JNI code
  Move PowerStatsPuller
  Create new Stats directory for pullers in jni
parents 1ffc19b2 4c527162
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -66,7 +66,6 @@ cc_defaults {
        "src/config/ConfigManager.cpp",
        "src/external/GpuStatsPuller.cpp",
        "src/external/Perfetto.cpp",
        "src/external/PowerStatsPuller.cpp",
        "src/external/PullResultReceiver.cpp",
        "src/external/puller_util.cpp",
        "src/external/StatsCallbackPuller.cpp",
+0 −4
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@
#include "../stats_log_util.h"
#include "../statscompanion_util.h"
#include "GpuStatsPuller.h"
#include "PowerStatsPuller.h"
#include "StatsCallbackPuller.h"
#include "SubsystemSleepStatePuller.h"
#include "TrainInfoPuller.h"
@@ -58,9 +57,6 @@ StatsPullerManager::StatsPullerManager()
              // subsystem_sleep_state
              {{.atomTag = android::util::SUBSYSTEM_SLEEP_STATE}, new SubsystemSleepStatePuller()},

              // on_device_power_measurement
              {{.atomTag = android::util::ON_DEVICE_POWER_MEASUREMENT}, new PowerStatsPuller()},

              // TrainInfo.
              {{.atomTag = android::util::TRAIN_INFO}, new TrainInfoPuller()},

+3 −0
Original line number Diff line number Diff line
@@ -256,6 +256,8 @@ public class StatsPullAtomService extends SystemService {
        mContext = context;
    }

    private native void nativeInit();

    /**
     * Use of this StatsPullAtomCallbackImpl means we avoid one class per tagId, which we would
     * get if we used lambdas.
@@ -399,6 +401,7 @@ public class StatsPullAtomService extends SystemService {
        super.onBootPhase(phase);
        if (phase == PHASE_SYSTEM_SERVICES_READY) {
            BackgroundThread.getHandler().post(() -> {
                nativeInit();
                initializePullersState();
                registerAllPullers();
                registerEventListeners();
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ cc_library_static {
        "BroadcastRadio/TunerCallback.cpp",
        "BroadcastRadio/convert.cpp",
        "BroadcastRadio/regions.cpp",
        "stats/PowerStatsPuller.cpp",
        "com_android_server_am_BatteryStatsService.cpp",
        "com_android_server_connectivity_Vpn.cpp",
        "com_android_server_ConsumerIrService.cpp",
@@ -37,6 +38,7 @@ cc_library_static {
        "com_android_server_security_VerityUtils.cpp",
        "com_android_server_SerialService.cpp",
        "com_android_server_soundtrigger_middleware_AudioSessionProviderImpl.cpp",
        "com_android_server_stats_pull_StatsPullAtomService.cpp",
        "com_android_server_storage_AppFuseBridge.cpp",
        "com_android_server_SystemServer.cpp",
        "com_android_server_TestNetworkService.cpp",
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "StatsPullAtomService"

#include <jni.h>
#include <log/log.h>
#include <nativehelper/JNIHelp.h>
#include <stats_event.h>
#include <stats_pull_atom_callback.h>
#include <statslog.h>

#include "stats/PowerStatsPuller.h"

namespace android {

static server::stats::PowerStatsPuller gPowerStatsPuller;

static status_pull_atom_return_t onDevicePowerMeasurementCallback(int32_t atom_tag,
                                                                  pulled_stats_event_list* data,
                                                                  void* cookie) {
    return gPowerStatsPuller.Pull(atom_tag, data);
}

static void nativeInit(JNIEnv* env, jobject javaObject) {
    // on device power measurement
    gPowerStatsPuller = server::stats::PowerStatsPuller();
    register_stats_pull_atom_callback(android::util::ON_DEVICE_POWER_MEASUREMENT,
                                      onDevicePowerMeasurementCallback,
                                      /* metadata= */ nullptr,
                                      /* cookie= */ nullptr);
}

static const JNINativeMethod sMethods[] = {{"nativeInit", "()V", (void*)nativeInit}};

int register_android_server_stats_pull_StatsPullAtomService(JNIEnv* env) {
    int res = jniRegisterNativeMethods(env, "com/android/server/stats/pull/StatsPullAtomService",
                                       sMethods, NELEM(sMethods));
    if (res < 0) {
        ALOGE("failed to register native methods");
    }
    return res;
}

} // namespace android
Loading