Merge "[IT4.3] Listen interface change in BSS" am: c95ab361c7 am: 97b07f5b2e
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1531807 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ib51a30f6c2b7836df82e250c82194d73cb8caa80
This commit is contained in:
@@ -405,6 +405,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
if (mLastPowerStateFromRadio != powerState) {
|
if (mLastPowerStateFromRadio != powerState) {
|
||||||
mLastPowerStateFromRadio = powerState;
|
mLastPowerStateFromRadio = powerState;
|
||||||
try {
|
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);
|
getBatteryStats().noteMobileRadioPowerState(powerState, tsNanos, uid);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
@@ -415,6 +418,9 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
|
|||||||
if (mLastPowerStateFromWifi != powerState) {
|
if (mLastPowerStateFromWifi != powerState) {
|
||||||
mLastPowerStateFromWifi = powerState;
|
mLastPowerStateFromWifi = powerState;
|
||||||
try {
|
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);
|
getBatteryStats().noteWifiRadioPowerState(powerState, tsNanos, uid);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,14 @@ import android.content.ContentResolver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.net.INetworkManagementEventObserver;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
import android.os.BatteryStats;
|
import android.os.BatteryStats;
|
||||||
import android.os.BatteryStatsInternal;
|
import android.os.BatteryStatsInternal;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.INetworkManagementService;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.ParcelFormatException;
|
import android.os.ParcelFormatException;
|
||||||
@@ -33,6 +36,7 @@ import android.os.PowerManager.ServiceType;
|
|||||||
import android.os.PowerManagerInternal;
|
import android.os.PowerManagerInternal;
|
||||||
import android.os.PowerSaveState;
|
import android.os.PowerSaveState;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -52,6 +56,7 @@ import android.telephony.SignalStrength;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.internal.app.IBatteryStats;
|
import com.android.internal.app.IBatteryStats;
|
||||||
import com.android.internal.os.BatteryStatsHelper;
|
import com.android.internal.os.BatteryStatsHelper;
|
||||||
import com.android.internal.os.BatteryStatsImpl;
|
import com.android.internal.os.BatteryStatsImpl;
|
||||||
@@ -62,6 +67,7 @@ import com.android.internal.util.DumpUtils;
|
|||||||
import com.android.internal.util.FrameworkStatsLog;
|
import com.android.internal.util.FrameworkStatsLog;
|
||||||
import com.android.internal.util.ParseUtils;
|
import com.android.internal.util.ParseUtils;
|
||||||
import com.android.server.LocalServices;
|
import com.android.server.LocalServices;
|
||||||
|
import com.android.server.net.BaseNetworkObserver;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
@@ -108,6 +114,39 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
private CharBuffer mUtf16BufferStat = CharBuffer.allocate(MAX_LOW_POWER_STATS_SIZE);
|
private CharBuffer mUtf16BufferStat = CharBuffer.allocate(MAX_LOW_POWER_STATS_SIZE);
|
||||||
private static final int MAX_LOW_POWER_STATS_SIZE = 4096;
|
private static final int MAX_LOW_POWER_STATS_SIZE = 4096;
|
||||||
|
|
||||||
|
@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.
|
* Replaces the information in the given rpmStats with up-to-date information.
|
||||||
*/
|
*/
|
||||||
@@ -203,6 +242,13 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void systemServicesReady() {
|
public void systemServicesReady() {
|
||||||
|
final INetworkManagementService nms = INetworkManagementService.Stub.asInterface(
|
||||||
|
ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE));
|
||||||
|
try {
|
||||||
|
nms.registerObserver(mActivityChangeObserver);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Slog.e(TAG, "Could not register INetworkManagement event observer " + e);
|
||||||
|
}
|
||||||
mStats.systemServicesReady(mContext);
|
mStats.systemServicesReady(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -680,8 +726,13 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
|
|
||||||
public void noteMobileRadioPowerState(int powerState, long timestampNs, int uid) {
|
public void noteMobileRadioPowerState(int powerState, long timestampNs, int uid) {
|
||||||
enforceCallingPermission();
|
enforceCallingPermission();
|
||||||
|
|
||||||
final boolean update;
|
final boolean update;
|
||||||
synchronized (mStats) {
|
synchronized (mStats) {
|
||||||
|
// Ignore if no power state change.
|
||||||
|
if (mLastPowerStateFromRadio == powerState) return;
|
||||||
|
|
||||||
|
mLastPowerStateFromRadio = powerState;
|
||||||
update = mStats.noteMobileRadioPowerStateLocked(powerState, timestampNs, uid);
|
update = mStats.noteMobileRadioPowerStateLocked(powerState, timestampNs, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -863,6 +914,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
// There was a change in WiFi power state.
|
// There was a change in WiFi power state.
|
||||||
// Collect data now for the past activity.
|
// Collect data now for the past activity.
|
||||||
synchronized (mStats) {
|
synchronized (mStats) {
|
||||||
|
// Ignore if no power state change.
|
||||||
|
if (mLastPowerStateFromWifi == powerState) return;
|
||||||
|
|
||||||
|
mLastPowerStateFromWifi = powerState;
|
||||||
if (mStats.isOnBattery()) {
|
if (mStats.isOnBattery()) {
|
||||||
final String type = (powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH ||
|
final String type = (powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_HIGH ||
|
||||||
powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM) ? "active"
|
powerState == DataConnectionRealTimeInfo.DC_POWER_STATE_MEDIUM) ? "active"
|
||||||
|
|||||||
Reference in New Issue
Block a user