implement LocationManager and orientation sensor using libportal

This commit is contained in:
Julian Winkler
2023-07-14 20:02:34 +02:00
parent c72f3ba7d2
commit 696e0ce714
13 changed files with 167 additions and 3 deletions

View File

@@ -327,7 +327,8 @@ public final class Sensor {
private int mFifoReservedEventCount;
private int mFifoMaxEventCount;
Sensor() {
Sensor(int type) {
mType = type;
}
/**

View File

@@ -0,0 +1,11 @@
package android.hardware;
public class SensorEvent {
public final float[] values;
public SensorEvent(float[] values) {
this.values = values;
}
}

View File

@@ -1,4 +1,6 @@
package android.hardware;
public interface SensorEventListener {
public void onSensorChanged(SensorEvent event);
}

View File

@@ -1,13 +1,31 @@
package android.hardware;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Handler;
public class SensorManager {
public Sensor getDefaultSensor(int type) {
return null;
return new Sensor(type);
}
public boolean registerListener(SensorEventListener listener, Sensor sensor, int samplingPeriodUs, Handler handler) {
return true; // we could try saying that the sensor doesn't exist and hope the app just doesn't use it then, but as long as we never call the handler the app should leave this alone
}
public boolean registerListener(final SensorEventListener listener, Sensor sensor, int samplingPeriodUs) {
switch(sensor.getType()) {
case Sensor.TYPE_ORIENTATION:
new LocationManager().requestLocationUpdates(null, 0, 0, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
listener.onSensorChanged(new SensorEvent(new float[]{(float)location.getBearing()}));
}
});
return true;
default:
return false;
}
}
}