hannesa2 / panoramaGL

PanoramaGL Android
Apache License 2.0
164 stars 59 forks source link

Mandatory HIGH_SAMPLING_RATE_SENSORS special permission in Android 12 + #317

Closed MarcoSanz12 closed 2 months ago

MarcoSanz12 commented 2 months ago

Hello ! I've seen the library currently requires the permission HIGH_SAMPLING_RATE SENSORS in API 31+ .

When SensorManager registers the listener for the sensors, it uses a sampling rate of 33 microseconds and this is called at least during plManager.startSensorialRotation() & plManager.onResume().

These functions call activateAccelerometer(), activateGyroscope() and activateMagnetometer() registering the listener. I don't know If there's any way to change the sampling rate to avoid using the permission which makes publishing apps in the Play Store harder because it requires a google review

The listener -> protected fun activateGyroscope(): Boolean { return sensorManager.registerListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), (PLConstants.kDefaultGyroscopeInterval * 1000.0f).toInt() ) }

The error -> java.lang.RuntimeException: Unable to resume activity {com.myapplication.app/com.myapplication.app.SampleActivity}: java.lang.SecurityException: To use the sampling rate of 33 microseconds, app needs to declare the normal permission HIGH_SAMPLING_RATE_SENSORS.

Thanks

hannesa2 commented 2 months ago

I'm open minded to approve any pull request which makes sense

hannesa2 commented 2 months ago

As an easy step you could remove this permission in your app by <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE" tools:node="remove"/>

hannesa2 commented 2 months ago

Even with a higher rate I see

java.lang.SecurityException: To use the sampling rate of 1333 microseconds, app needs to declare the normal permission HIGH_SAMPLING_RATE_SENSORS.

The documentation tells us

Use a sampling rate lower than 200Hz for all sensors: The HIGH_SAMPLING_RATE_SENSORS permission is only required for sampling rates higher than 200Hz. By using a lower sampling rate, you can avoid the need for this permission.

hannesa2 commented 2 months ago

With this https://github.com/hannesa2/panoramaGL/pull/322 the permission is no more needed

hannesa2 commented 2 months ago

Here you go https://github.com/hannesa2/panoramaGL/releases/tag/1.10