MotoActions: Don't crash settings
authorMichael W <baddaemon87@gmail.com>
Tue, 29 Dec 2020 17:23:17 +0000 (18:23 +0100)
committerMichael W <baddaemon87@gmail.com>
Tue, 29 Dec 2020 17:23:17 +0000 (18:23 +0100)
* Registering a non-existing sensor causes a RuntimeException which crashes
  the Settings app which in turn takes down the whole system
* Change the RuntimeExceptions to normal error loggings

Change-Id: I18a73adc311bec6b70440a3266c7e2af74baa55a

MotoActions/src/org/lineageos/settings/device/SensorHelper.java

index 6cb3647a2b2c03ae76cb3f4bb321705b9e9a7b16..5d08a93f142fda17c03388e4ea2d98cbbbdc35f7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2020 The LineageOS Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -101,8 +101,8 @@ public class SensorHelper {
 
     public void registerListener(Sensor sensor, SensorEventListener listener) {
         if (!mSensorManager.registerListener(listener, sensor,
-            SensorManager.SENSOR_DELAY_NORMAL, BATCH_LATENCY_IN_MS * 1000)) {
-            throw new RuntimeException("Failed to registerListener for sensor " + sensor);
+                SensorManager.SENSOR_DELAY_NORMAL, BATCH_LATENCY_IN_MS * 1000)) {
+            Log.e(TAG, "Failed to registerListener for sensor " + sensor);
         }
     }
 
@@ -113,7 +113,7 @@ public class SensorHelper {
     /* TriggerSensor */
     public void requestTriggerSensor(Sensor sensor, TriggerEventListener listener) {
         if (!mSensorManager.requestTriggerSensor(listener, sensor)) {
-            throw new RuntimeException("Failed to requestTriggerSensor for sensor " + sensor);
+            Log.e(TAG, "Failed to requestTriggerSensor for sensor " + sensor);
         }
     }