Skip to content

Commit 25157e4

Browse files
author
Jeff Brown
committed
Refactor SensorManager to move non-API bits into a subclass.
Changed the SensorManager class so that it only contains API-related bits including what's needed to support legacy sensors. Mostly just moved stuff around. Making the class abstract is safe because it does not have a visible constructor in the API. One minor change is that the cache of sensor type to sensor lists is now per instance of SensorManager instead of being static. We can fix this if desired. Another small change is that we bail out early from registerListener if the listener has already been registered for the particular sensor. This happened for both legacy and standard listeners. The problem is that the ListenerDelegate maintains two lists of sensors, one is a Map and the other is a List. Adding a sensor twice causes one entry to be added to the Map and two entries to be added to the List, but when the sensor is removed the next time, only one entry is removed from the List, leaving it in an inconsistent state. Removed Sensor.getLegacyType() since the value it provides is only needed in LegacyListener and we don't really save any significant computation by caching it. Removing the field makes support for legacy sensors a little more self-contained. Bug: 6339552 Change-Id: I50d41ac97cf535924f2bfa2026d28547a4d00286
1 parent a5d552f commit 25157e4

File tree

8 files changed

+787
-719
lines changed

8 files changed

+787
-719
lines changed

api/16.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9513,7 +9513,7 @@ package android.hardware {
95139513
method public abstract void onSensorChanged(int, float[]);
95149514
}
95159515

9516-
public class SensorManager {
9516+
public abstract class SensorManager {
95179517
method public static float getAltitude(float, float);
95189518
method public static void getAngleChange(float[], float[], float[]);
95199519
method public android.hardware.Sensor getDefaultSensor(int);

api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9779,7 +9779,7 @@ package android.hardware {
97799779
method public abstract void onSensorChanged(int, float[]);
97809780
}
97819781

9782-
public class SensorManager {
9782+
public abstract class SensorManager {
97839783
method public static float getAltitude(float, float);
97849784
method public static void getAngleChange(float[], float[], float[]);
97859785
method public android.hardware.Sensor getDefaultSensor(int);

core/java/android/app/ContextImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import android.hardware.ISerialManager;
4646
import android.hardware.SensorManager;
4747
import android.hardware.SerialManager;
48+
import android.hardware.SystemSensorManager;
4849
import android.hardware.input.IInputManager;
4950
import android.hardware.input.InputManager;
5051
import android.hardware.usb.IUsbManager;
@@ -407,7 +408,7 @@ public Object createService(ContextImpl ctx) {
407408

408409
registerService(SENSOR_SERVICE, new ServiceFetcher() {
409410
public Object createService(ContextImpl ctx) {
410-
return new SensorManager(ctx.mMainThread.getHandler().getLooper());
411+
return new SystemSensorManager(ctx.mMainThread.getHandler().getLooper());
411412
}});
412413

413414
registerService(STATUS_BAR_SERVICE, new ServiceFetcher() {

core/java/android/hardware/Sensor.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public class Sensor {
131131
private float mResolution;
132132
private float mPower;
133133
private int mMinDelay;
134-
private int mLegacyType;
135134

136135

137136
Sensor() {
@@ -203,12 +202,4 @@ void setRange(float max, float res) {
203202
mMaxRange = max;
204203
mResolution = res;
205204
}
206-
207-
void setLegacyType(int legacyType) {
208-
mLegacyType = legacyType;
209-
}
210-
211-
int getLegacyType() {
212-
return mLegacyType;
213-
}
214205
}

0 commit comments

Comments
 (0)