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

Commit 3f01a7a8 authored by Chiachang Wang's avatar Chiachang Wang
Browse files

[IT02] Expose system api to report radio power state

In order to support ConnectivityService mainline, the dependency
with NMS should be removed. The idle timer control API should be
replaced with calling INetd interface instead of using NMS hidden
API.

The state reporting will be triggered from updating idle timer
and netd unsolicited interface activity changed events.
BatteryStatsService should be able to get the netd event by
registering the listener directly. This commit exposes two system
APIs to report the radio power state for wifi and mobile for
supporting update idle timer from CS directly to INetd.

Bug: 170598012
Test: make update-api ; m
Change-Id: I286d6aa237ecb2653e1464e26a3581b8eeeb9e63
parent 4ba82f5d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6968,12 +6968,14 @@ package android.os {
    method @NonNull @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public android.os.connectivity.WifiBatteryStats getWifiBatteryStats();
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportFullWifiLockAcquiredFromSource(@NonNull android.os.WorkSource);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportFullWifiLockReleasedFromSource(@NonNull android.os.WorkSource);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportMobileRadioPowerState(boolean, int) throws java.lang.RuntimeException;
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiBatchedScanStartedFromSource(@NonNull android.os.WorkSource, @IntRange(from=0) int);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiBatchedScanStoppedFromSource(@NonNull android.os.WorkSource);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiMulticastDisabled(@NonNull android.os.WorkSource);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiMulticastEnabled(@NonNull android.os.WorkSource);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiOff();
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiOn();
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiRadioPowerState(boolean, int) throws java.lang.RuntimeException;
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiRssiChanged(@IntRange(from=0xffffff81, to=0) int);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiScanStartedFromSource(@NonNull android.os.WorkSource);
    method @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) public void reportWifiScanStoppedFromSource(@NonNull android.os.WorkSource);
+47 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.annotation.SystemService;
import android.content.Context;
import android.os.connectivity.CellularBatteryStats;
import android.os.connectivity.WifiBatteryStats;
import android.telephony.DataConnectionRealTimeInfo;

import com.android.internal.app.IBatteryStats;

@@ -376,4 +377,50 @@ public final class BatteryStatsManager {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Indicates that the radio power state has changed.
     *
     * @param isActive indicates if the mobile radio is powered.
     * @param uid Uid of this event. For the active state it represents the uid that was responsible
     *            for waking the radio, or -1 if the system was responsible for waking the radio.
     *            For inactive state, the UID should always be -1.
     * @throws RuntimeException if there are binder remote-invocation errors.
     */
    @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
    public void reportMobileRadioPowerState(boolean isActive, int uid) throws RuntimeException {
        try {
            mBatteryStats.noteMobileRadioPowerState(getDataConnectionPowerState(isActive),
                    SystemClock.elapsedRealtimeNanos(), uid);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    /**
     * Indicates that the wifi power state has changed.
     *
     * @param isActive indicates if the wifi radio is powered.
     * @param uid Uid of this event. For the active state it represents the uid that was responsible
     *            for waking the radio, or -1 if the system was responsible for waking the radio.
     *            For inactive state, the UID should always be -1.
     * @throws RuntimeException if there are binder remote-invocation errors.
     */
    @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
    public void reportWifiRadioPowerState(boolean isActive, int uid) throws RuntimeException {
        try {
            mBatteryStats.noteWifiRadioPowerState(getDataConnectionPowerState(isActive),
                    SystemClock.elapsedRealtimeNanos(), uid);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
    }

    private static int getDataConnectionPowerState(boolean isActive) {
        // TODO: DataConnectionRealTimeInfo is under telephony package but the constants are used
        // for both Wifi and mobile. It would make more sense to separate the constants to a generic
        // class or move it to generic package.
        return isActive ? DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH
                : DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
    }
}