Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d9d4e1bc authored by Peng Xu's avatar Peng Xu
Browse files

Return correct value at initDataInjection and avoid crash

When data inject channel cannot be initialized return false, instead
of causing crash.

Bug: 37549731
Test: run GTS SensorHostTest, test succeed with no failures observed.
Change-Id: Ia7a078b9e7d4f61927da8d76a0206e588fd6686c
parent b0806f10
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -285,19 +285,24 @@ public class SystemSensorManager extends SensorManager {
                }
                // Initialize a client for data_injection.
                if (sInjectEventQueue == null) {
                    sInjectEventQueue = new InjectEventQueue(mMainLooper, this,
                            mContext.getPackageName());
                    try {
                        sInjectEventQueue = new InjectEventQueue(
                                mMainLooper, this, mContext.getPackageName());
                    } catch (RuntimeException e) {
                        Log.e(TAG, "Cannot create InjectEventQueue: " + e);
                    }
                }
                return sInjectEventQueue != null;
            } else {
                // If data injection is being disabled clean up the native resources.
                if (sInjectEventQueue != null) {
                    sInjectEventQueue.dispose();
                    sInjectEventQueue = null;
                }
            }
                return true;
            }
        }
    }

    protected boolean injectSensorDataImpl(Sensor sensor, float[] values, int accuracy,
            long timestamp) {
+5 −0
Original line number Diff line number Diff line
@@ -427,6 +427,11 @@ static jlong nativeInitSensorEventQueue(JNIEnv *env, jclass clazz, jlong sensorM
    String8 clientName(packageUtf.c_str());
    sp<SensorEventQueue> queue(mgr->createEventQueue(clientName, mode));

    if (queue == NULL) {
        jniThrowRuntimeException(env, "Cannot construct native SensorEventQueue.");
        return 0;
    }

    sp<MessageQueue> messageQueue = android_os_MessageQueue_getMessageQueue(env, msgQ);
    if (messageQueue == NULL) {
        jniThrowRuntimeException(env, "MessageQueue is not initialized.");