Merge "Pipe potential wakeup events from sensor service" into udc-dev

This commit is contained in:
Suprabh Shukla
2023-04-14 00:31:09 +00:00
committed by Android (Google) Code Review
4 changed files with 50 additions and 1 deletions

View File

@@ -449,6 +449,27 @@ public abstract class SensorManager {
return list;
}
/**
* Returns the {@link Sensor} object identified by the given sensor handle.
*
* The raw sensor handle integer is an implementation detail and as such this method should only
* be used by internal system components.
*
* @param sensorHandle The integer handle uniquely identifying the sensor.
* @return A Sensor object identified by the given {@code sensorHandle}, if such a sensor
* exists, {@code null} otherwise.
*
* @hide
*/
public @Nullable Sensor getSensorByHandle(int sensorHandle) {
for (final Sensor sensor : getFullSensorList()) {
if (sensor.getHandle() == sensorHandle) {
return sensor;
}
}
return null;
}
/**
* Use this method to get a list of available dynamic sensors of a certain type.
* Make multiple calls to get sensors of different types or use

View File

@@ -220,6 +220,12 @@ public class SystemSensorManager extends SensorManager {
return fullList;
}
/** @hide */
@Override
public Sensor getSensorByHandle(int sensorHandle) {
return mHandleToSensor.get(sensorHandle);
}
/** @hide */
@Override
protected List<Sensor> getFullDynamicSensorList() {

View File

@@ -63,6 +63,7 @@ interface IBatteryStats {
void noteResetCamera();
@EnforcePermission("UPDATE_DEVICE_STATS")
void noteResetFlashlight();
void noteWakeupSensorEvent(long elapsedNanos, int uid, int handle);
// Remaining methods are only used in Java.
@EnforcePermission("BATTERY_STATS")

View File

@@ -37,6 +37,8 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.hardware.power.stats.PowerEntity;
import android.hardware.power.stats.State;
import android.hardware.power.stats.StateResidency;
@@ -149,7 +151,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub
private final PowerProfile mPowerProfile;
final BatteryStatsImpl mStats;
@GuardedBy("mWakeupStats")
final CpuWakeupStats mCpuWakeupStats;
private final BatteryUsageStatsStore mBatteryUsageStatsStore;
private final BatteryStatsImpl.UserInfoProvider mUserManagerUserInfoProvider;
@@ -1260,6 +1261,26 @@ public final class BatteryStatsService extends IBatteryStats.Stub
null, sensor, FrameworkStatsLog.SENSOR_STATE_CHANGED__STATE__ON);
}
@Override
public void noteWakeupSensorEvent(long elapsedNanos, int uid, int sensorHandle) {
final int callingUid = Binder.getCallingUid();
if (callingUid != Process.SYSTEM_UID) {
throw new SecurityException("Calling uid " + callingUid + " is not system uid");
}
final SensorManager sm = mContext.getSystemService(SensorManager.class);
final Sensor sensor = sm.getSensorByHandle(sensorHandle);
if (sensor == null) {
Slog.w(TAG, "Unknown sensor handle " + sensorHandle
+ " received in noteWakeupSensorEvent");
return;
}
Slog.i(TAG, "Sensor " + sensor + " wakeup event at " + elapsedNanos + " sent to uid "
+ uid);
// TODO (b/275436924): Remove log and pipe to CpuWakeupStats for wakeup attribution
// This method should return as quickly as possible. Use mHandler#post to do longer work.
}
@Override
@EnforcePermission(UPDATE_DEVICE_STATS)
public void noteStopSensor(final int uid, final int sensor) {