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

Commit 907c3f16 authored by Chiachang Wang's avatar Chiachang Wang Committed by Android (Google) Code Review
Browse files

Merge "[IT4.3] Listen interface change in BSS"

parents 39f8ea46 9a81afdc
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -405,6 +405,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
            if (mLastPowerStateFromRadio != powerState) {
                mLastPowerStateFromRadio = powerState;
                try {
                    // TODO: The interface changes that comes from netd are handled by BSS itself.
                    // There are still events caused by setting or removing idle timer, so keep
                    // reporting from here until setting idler timer moved to CS.
                    getBatteryStats().noteMobileRadioPowerState(powerState, tsNanos, uid);
                } catch (RemoteException e) {
                }
@@ -415,6 +418,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
            if (mLastPowerStateFromWifi != powerState) {
                mLastPowerStateFromWifi = powerState;
                try {
                    // TODO: The interface changes that comes from netd are handled by BSS itself.
                    // There are still events caused by setting or removing idle timer, so keep
                    // reporting from here until setting idler timer moved to CS.
                    getBatteryStats().noteWifiRadioPowerState(powerState, tsNanos, uid);
                } catch (RemoteException e) {
                }
+55 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.INetworkManagementEventObserver;
import android.net.NetworkCapabilities;
import android.os.BatteryStats;
import android.os.BatteryStatsInternal;
import android.os.BatteryUsageStats;
@@ -29,6 +31,7 @@ import android.os.Binder;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFormatException;
@@ -36,6 +39,7 @@ import android.os.PowerManager.ServiceType;
import android.os.PowerManagerInternal;
import android.os.PowerSaveState;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
@@ -54,6 +58,7 @@ import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.Slog;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IBatteryStats;
import com.android.internal.os.BatteryStatsHelper;
import com.android.internal.os.BatteryStatsImpl;
@@ -68,6 +73,7 @@ import com.android.internal.util.ParseUtils;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.server.LocalServices;
import com.android.server.Watchdog;
import com.android.server.net.BaseNetworkObserver;
import com.android.server.pm.UserManagerInternal;

import java.io.File;
@@ -123,6 +129,40 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    private final Handler mHandler;
    private final Object mLock = new Object();

    @GuardedBy("mStats")
    private int mLastPowerStateFromRadio = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
    @GuardedBy("mStats")
    private int mLastPowerStateFromWifi = DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
    private final INetworkManagementEventObserver mActivityChangeObserver =
            new BaseNetworkObserver() {
                @Override
                public void interfaceClassDataActivityChanged(int transportType, boolean active,
                        long tsNanos, int uid) {
                    final int powerState = active
                            ? DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH
                            : DataConnectionRealTimeInfo.DC_POWER_STATE_LOW;
                    final long timestampNanos;
                    if (tsNanos <= 0) {
                        timestampNanos = SystemClock.elapsedRealtimeNanos();
                    } else {
                        timestampNanos = tsNanos;
                    }

                    switch (transportType) {
                        case NetworkCapabilities.TRANSPORT_CELLULAR:
                            noteMobileRadioPowerState(powerState, timestampNanos, uid);
                            break;
                        case NetworkCapabilities.TRANSPORT_WIFI:
                            noteWifiRadioPowerState(powerState, timestampNanos, uid);
                            break;
                        default:
                            Slog.d(TAG, "Received unexpected transport in "
                                    + "interfaceClassDataActivityChanged unexpected type: "
                                    + transportType);
                    }
                }
            };

    /**
     * Replaces the information in the given rpmStats with up-to-date information.
     */
@@ -225,6 +265,13 @@ public final class BatteryStatsService extends IBatteryStats.Stub
    public void systemServicesReady() {
        mStats.systemServicesReady(mContext);
        mWorker.systemServicesReady();
        final INetworkManagementService mNMService = INetworkManagementService.Stub.asInterface(
                ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
        try {
            mNMService.registerObserver(mActivityChangeObserver);
        } catch (RemoteException e) {
            Slog.e(TAG, "Could not register INetworkManagement event observer " + e);
        }
        Watchdog.getInstance().addMonitor(this);
    }

@@ -1040,6 +1087,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
            mHandler.post(() -> {
                final boolean update;
                synchronized (mStats) {
                    // Ignore if no power state change.
                    if (mLastPowerStateFromRadio == powerState) return;

                    mLastPowerStateFromRadio = powerState;
                    update = mStats.noteMobileRadioPowerStateLocked(powerState, timestampNs, uid,
                            elapsedRealtime, uptime);
                }
@@ -1343,6 +1394,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
                // There was a change in WiFi power state.
                // Collect data now for the past activity.
                synchronized (mStats) {
                    // Ignore if no power state change.
                    if (mLastPowerStateFromWifi == powerState) return;

                    mLastPowerStateFromWifi = powerState;
                    if (mStats.isOnBattery()) {
                        final String type =
                                (powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH