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

Commit 1bd437fc authored by Liang Li's avatar Liang Li
Browse files

Add logging for UwbActivityInfo to StatsPullAtomService

Test: manual with statsd_testdrive 10188
Bug: 236721026
Change-Id: Iad38a29909832133683a5d775a9f8c8cf031ae19
Merged-In: Iad38a29909832133683a5d775a9f8c8cf031ae19
parent cf2fc89d
Loading
Loading
Loading
Loading
+60 −2
Original line number Diff line number Diff line
@@ -171,6 +171,8 @@ import android.util.SparseArray;
import android.util.SparseIntArray;
import android.util.StatsEvent;
import android.util.proto.ProtoOutputStream;
import android.uwb.UwbActivityEnergyInfo;
import android.uwb.UwbManager;
import android.view.Display;

import com.android.internal.annotations.GuardedBy;
@@ -346,6 +348,7 @@ public class StatsPullAtomService extends SystemService {
    private StorageManager mStorageManager;
    private WifiManager mWifiManager;
    private TelephonyManager mTelephony;
    private UwbManager mUwbManager;
    private SubscriptionManager mSubscriptionManager;
    private NetworkStatsManager mNetworkStatsManager;

@@ -415,6 +418,7 @@ public class StatsPullAtomService extends SystemService {
    private final Object mWifiActivityInfoLock = new Object();
    private final Object mModemActivityInfoLock = new Object();
    private final Object mBluetoothActivityInfoLock = new Object();
    private final Object mUwbActivityInfoLock = new Object();
    private final Object mSystemElapsedRealtimeLock = new Object();
    private final Object mSystemUptimeLock = new Object();
    private final Object mProcessMemoryStateLock = new Object();
@@ -537,6 +541,10 @@ public class StatsPullAtomService extends SystemService {
                        synchronized (mBluetoothActivityInfoLock) {
                            return pullBluetoothActivityInfoLocked(atomTag, data);
                        }
                    case FrameworkStatsLog.UWB_ACTIVITY_INFO:
                        synchronized (mUwbActivityInfoLock) {
                            return pullUwbActivityInfoLocked(atomTag, data);
                        }
                    case FrameworkStatsLog.SYSTEM_ELAPSED_REALTIME:
                        synchronized (mSystemElapsedRealtimeLock) {
                            return pullSystemElapsedRealtimeLocked(atomTag, data);
@@ -776,8 +784,12 @@ public class StatsPullAtomService extends SystemService {
                registerEventListeners();
            });
        } else if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
            BackgroundThread.getHandler().post(() -> {
                // Network stats related pullers can only be initialized after service is ready.
            BackgroundThread.getHandler().post(() -> initAndRegisterNetworkStatsPullers());
                initAndRegisterNetworkStatsPullers();
                // For services that are not ready at boot phase PHASE_SYSTEM_SERVICES_READY
                initAndRegisterDeferredPullers();
            });
        }
    }

@@ -987,6 +999,12 @@ public class StatsPullAtomService extends SystemService {
        registerOemManagedBytesTransfer();
    }

    private void initAndRegisterDeferredPullers() {
        mUwbManager = mContext.getSystemService(UwbManager.class);

        registerUwbActivityInfo();
    }

    private IThermalService getIThermalService() {
        synchronized (mThermalLock) {
            if (mThermalService == null) {
@@ -2149,6 +2167,46 @@ public class StatsPullAtomService extends SystemService {
        return StatsManager.PULL_SUCCESS;
    }

    private void registerUwbActivityInfo() {
        int tagId = FrameworkStatsLog.UWB_ACTIVITY_INFO;
        mStatsManager.setPullAtomCallback(
                tagId,
                null, // use default PullAtomMetadata values
                DIRECT_EXECUTOR,
                mStatsCallbackImpl
        );
    }

    int pullUwbActivityInfoLocked(int atomTag, List<StatsEvent> pulledData) {
        final long token = Binder.clearCallingIdentity();
        try {
            SynchronousResultReceiver uwbReceiver = new SynchronousResultReceiver("uwb");
            mUwbManager.getUwbActivityEnergyInfoAsync(Runnable::run,
                    info -> {
                        Bundle bundle = new Bundle();
                        bundle.putParcelable(BatteryStats.RESULT_RECEIVER_CONTROLLER_KEY, info);
                        uwbReceiver.send(0, bundle);
                }
            );
            final UwbActivityEnergyInfo uwbInfo = awaitControllerInfo(uwbReceiver);
            if (uwbInfo == null) {
                return StatsManager.PULL_SKIP;
            }
            pulledData.add(
                    FrameworkStatsLog.buildStatsEvent(atomTag,
                            uwbInfo.getControllerTxDurationMillis(),
                            uwbInfo.getControllerRxDurationMillis(),
                            uwbInfo.getControllerIdleDurationMillis(),
                            uwbInfo.getControllerWakeCount()));
        } catch (RuntimeException e) {
            Slog.e(TAG, "failed to getUwbActivityEnergyInfoAsync", e);
            return StatsManager.PULL_SKIP;
        } finally {
            Binder.restoreCallingIdentity(token);
        }
        return StatsManager.PULL_SUCCESS;
    }

    private void registerSystemElapsedRealtime() {
        int tagId = FrameworkStatsLog.SYSTEM_ELAPSED_REALTIME;
        PullAtomMetadata metadata = new PullAtomMetadata.Builder()