Merge "Pipe potential wakeup events from sensor service" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cb5bc8ee43
@@ -449,6 +449,27 @@ public abstract class SensorManager {
|
|||||||
return list;
|
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.
|
* 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
|
* Make multiple calls to get sensors of different types or use
|
||||||
|
|||||||
@@ -220,6 +220,12 @@ public class SystemSensorManager extends SensorManager {
|
|||||||
return fullList;
|
return fullList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
@Override
|
||||||
|
public Sensor getSensorByHandle(int sensorHandle) {
|
||||||
|
return mHandleToSensor.get(sensorHandle);
|
||||||
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@Override
|
@Override
|
||||||
protected List<Sensor> getFullDynamicSensorList() {
|
protected List<Sensor> getFullDynamicSensorList() {
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ interface IBatteryStats {
|
|||||||
void noteResetCamera();
|
void noteResetCamera();
|
||||||
@EnforcePermission("UPDATE_DEVICE_STATS")
|
@EnforcePermission("UPDATE_DEVICE_STATS")
|
||||||
void noteResetFlashlight();
|
void noteResetFlashlight();
|
||||||
|
void noteWakeupSensorEvent(long elapsedNanos, int uid, int handle);
|
||||||
|
|
||||||
// Remaining methods are only used in Java.
|
// Remaining methods are only used in Java.
|
||||||
@EnforcePermission("BATTERY_STATS")
|
@EnforcePermission("BATTERY_STATS")
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ 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.hardware.Sensor;
|
||||||
|
import android.hardware.SensorManager;
|
||||||
import android.hardware.power.stats.PowerEntity;
|
import android.hardware.power.stats.PowerEntity;
|
||||||
import android.hardware.power.stats.State;
|
import android.hardware.power.stats.State;
|
||||||
import android.hardware.power.stats.StateResidency;
|
import android.hardware.power.stats.StateResidency;
|
||||||
@@ -149,7 +151,6 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
|
|
||||||
private final PowerProfile mPowerProfile;
|
private final PowerProfile mPowerProfile;
|
||||||
final BatteryStatsImpl mStats;
|
final BatteryStatsImpl mStats;
|
||||||
@GuardedBy("mWakeupStats")
|
|
||||||
final CpuWakeupStats mCpuWakeupStats;
|
final CpuWakeupStats mCpuWakeupStats;
|
||||||
private final BatteryUsageStatsStore mBatteryUsageStatsStore;
|
private final BatteryUsageStatsStore mBatteryUsageStatsStore;
|
||||||
private final BatteryStatsImpl.UserInfoProvider mUserManagerUserInfoProvider;
|
private final BatteryStatsImpl.UserInfoProvider mUserManagerUserInfoProvider;
|
||||||
@@ -1260,6 +1261,26 @@ public final class BatteryStatsService extends IBatteryStats.Stub
|
|||||||
null, sensor, FrameworkStatsLog.SENSOR_STATE_CHANGED__STATE__ON);
|
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
|
@Override
|
||||||
@EnforcePermission(UPDATE_DEVICE_STATS)
|
@EnforcePermission(UPDATE_DEVICE_STATS)
|
||||||
public void noteStopSensor(final int uid, final int sensor) {
|
public void noteStopSensor(final int uid, final int sensor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user