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

Commit 6d31735c authored by Yu-Han Yang's avatar Yu-Han Yang
Browse files

Move HIDL calls away from the main thread

class_init is running under application main thread. A sequence
of 10 back to back HIDL calls is a power up vulnerability, as
watchdog may kick in if application main thread is taking too
long.

Bug: 63707763
Fixes: 63707763
Test: Tested on Taimen and verified GPS works.
Change-Id: Ia8833e7bc5f2bd6186c1f74f84c5387640cc44df
parent fc704e2f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2513,6 +2513,8 @@ public class GnssLocationProvider implements LocationProviderInterface {
         * this handler.
         */
        private void handleInitialize() {
            native_init_once();

            /*
             * A cycle of native_init() and native_cleanup() is needed so that callbacks are
             * registered after bootup even when location is disabled.
@@ -2899,6 +2901,8 @@ public class GnssLocationProvider implements LocationProviderInterface {

    private static native boolean native_is_gnss_configuration_supported();

    private static native void native_init_once();

    private native boolean native_init();

    private native void native_cleanup();
+12 −9
Original line number Diff line number Diff line
@@ -1125,6 +1125,16 @@ Return<void> GnssBatchingCallback::gnssLocationBatchCb(
}

static void android_location_GnssLocationProvider_class_init_native(JNIEnv* env, jclass clazz) {
    gnssHal_V1_1 = IGnss_V1_1::getService();
    if (gnssHal_V1_1 == nullptr) {
        ALOGD("gnssHal 1.1 was null, trying 1.0");
        gnssHal = IGnss_V1_0::getService();
    } else {
        gnssHal = gnssHal_V1_1;
    }
}

static void android_location_GnssLocationProvider_init_once(JNIEnv* env, jclass clazz) {
    method_reportLocation = env->GetMethodID(clazz, "reportLocation",
            "(ZLandroid/location/Location;)V");
    method_reportStatus = env->GetMethodID(clazz, "reportStatus", "(I)V");
@@ -1175,15 +1185,6 @@ static void android_location_GnssLocationProvider_class_init_native(JNIEnv* env,
        LOG_ALWAYS_FATAL("Unable to get Java VM. Error: %d", jvmStatus);
    }

    // TODO(b/31632518)
    gnssHal_V1_1 = IGnss_V1_1::getService();
    if (gnssHal_V1_1 == nullptr) {
        ALOGD("gnssHal 1.1 was null, trying 1.0");
        gnssHal = IGnss_V1_0::getService();
    } else {
        gnssHal = gnssHal_V1_1;
    }

    if (gnssHal != nullptr) {
      gnssHalDeathRecipient = new GnssDeathRecipient();
      hardware::Return<bool> linked = gnssHal->linkToDeath(
@@ -2068,6 +2069,8 @@ static const JNINativeMethod sMethods[] = {
    {"native_is_gnss_configuration_supported", "()Z",
            reinterpret_cast<void *>(
                    android_location_gpsLocationProvider_is_gnss_configuration_supported)},
    {"native_init_once", "()V", reinterpret_cast<void *>(
            android_location_GnssLocationProvider_init_once)},
    {"native_init", "()Z", reinterpret_cast<void *>(android_location_GnssLocationProvider_init)},
    {"native_cleanup", "()V", reinterpret_cast<void *>(
            android_location_GnssLocationProvider_cleanup)},