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

Commit 53f4d6d8 authored by Yu-Han Yang's avatar Yu-Han Yang
Browse files

Handle emergency mode in requestLocation

Bug: 124106337

Test: on device
Change-Id: I9fc0db53d9a2eff02dd3c2722785eac221c7f7c2
parent e2791fc1
Loading
Loading
Loading
Loading
+17 −7
Original line number Original line Diff line number Diff line
@@ -687,7 +687,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
        }
        }
    }
    }


    private void handleRequestLocation(boolean independentFromGnss) {
    private void handleRequestLocation(boolean independentFromGnss, boolean isUserEmergency) {
        if (isRequestLocationRateLimited()) {
        if (isRequestLocationRateLimited()) {
            if (DEBUG) {
            if (DEBUG) {
                Log.d(TAG, "RequestLocation is denied due to too frequent requests.");
                Log.d(TAG, "RequestLocation is denied due to too frequent requests.");
@@ -723,9 +723,17 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
                String.format(
                String.format(
                        "GNSS HAL Requesting location updates from %s provider for %d millis.",
                        "GNSS HAL Requesting location updates from %s provider for %d millis.",
                        provider, durationMillis));
                        provider, durationMillis));
        try {

            locationManager.requestLocationUpdates(provider,
        LocationRequest locationRequest = LocationRequest.createFromDeprecatedProvider(provider,
                LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /* minDistance= */ 0,
                LOCATION_UPDATE_MIN_TIME_INTERVAL_MILLIS, /* minDistance= */ 0,
                /* singleShot= */ false);

        // Ignore location settings if in emergency mode.
        if (isUserEmergency && mNIHandler.getInEmergency()) {
            locationRequest.setLocationSettingsIgnored(true);
        }
        try {
            locationManager.requestLocationUpdates(locationRequest,
                    locationListener, mHandler.getLooper());
                    locationListener, mHandler.getLooper());
            locationListener.mNumLocationUpdateRequest++;
            locationListener.mNumLocationUpdateRequest++;
            mHandler.postDelayed(() -> {
            mHandler.postDelayed(() -> {
@@ -1828,11 +1836,13 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
    }
    }


    @NativeEntryPoint
    @NativeEntryPoint
    private void requestLocation(boolean independentFromGnss) {
    private void requestLocation(boolean independentFromGnss, boolean isUserEmergency) {
        if (DEBUG) {
        if (DEBUG) {
            Log.d(TAG, "requestLocation. independentFromGnss: " + independentFromGnss);
            Log.d(TAG, "requestLocation. independentFromGnss: " + independentFromGnss
                    + ", isUserEmergency: "
                    + isUserEmergency);
        }
        }
        sendMessage(REQUEST_LOCATION, 0, independentFromGnss);
        sendMessage(REQUEST_LOCATION, independentFromGnss ? 1 : 0, isUserEmergency);
    }
    }


    @NativeEntryPoint
    @NativeEntryPoint
@@ -1923,7 +1933,7 @@ public class GnssLocationProvider extends AbstractLocationProvider implements
                    mNtpTimeHelper.retrieveAndInjectNtpTime();
                    mNtpTimeHelper.retrieveAndInjectNtpTime();
                    break;
                    break;
                case REQUEST_LOCATION:
                case REQUEST_LOCATION:
                    handleRequestLocation((boolean) msg.obj);
                    handleRequestLocation(msg.arg1 == 1, (boolean) msg.obj);
                    break;
                    break;
                case DOWNLOAD_XTRA_DATA:
                case DOWNLOAD_XTRA_DATA:
                    handleDownloadXtraData();
                    handleDownloadXtraData();
+12 −2
Original line number Original line Diff line number Diff line
@@ -548,12 +548,15 @@ struct GnssCallback : public IGnssCallback {
    Return<void> gnssReleaseWakelockCb() override;
    Return<void> gnssReleaseWakelockCb() override;
    Return<void> gnssRequestTimeCb() override;
    Return<void> gnssRequestTimeCb() override;
    Return<void> gnssRequestLocationCb(const bool independentFromGnss) override;
    Return<void> gnssRequestLocationCb(const bool independentFromGnss) override;

    Return<void> gnssSetSystemInfoCb(const IGnssCallback::GnssSystemInfo& info) override;
    Return<void> gnssSetSystemInfoCb(const IGnssCallback::GnssSystemInfo& info) override;


    // New in 1.1
    // New in 1.1
    Return<void> gnssNameCb(const android::hardware::hidl_string& name) override;
    Return<void> gnssNameCb(const android::hardware::hidl_string& name) override;


    // New in 2.0
    // New in 2.0
    Return<void> gnssRequestLocationCb_2_0(const bool independentFromGnss, const bool isUserEmergency)
            override;
    Return<void> gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override;
    Return<void> gnssSetCapabilitiesCb_2_0(uint32_t capabilities) override;
    Return<void> gnssLocationCb_2_0(const GnssLocation_V2_0& location) override;
    Return<void> gnssLocationCb_2_0(const GnssLocation_V2_0& location) override;


@@ -713,8 +716,15 @@ Return<void> GnssCallback::gnssRequestTimeCb() {
}
}


Return<void> GnssCallback::gnssRequestLocationCb(const bool independentFromGnss) {
Return<void> GnssCallback::gnssRequestLocationCb(const bool independentFromGnss) {
    return GnssCallback::gnssRequestLocationCb_2_0(independentFromGnss, /* isUserEmergency= */
            false);
}

Return<void> GnssCallback::gnssRequestLocationCb_2_0(const bool independentFromGnss, const bool
        isUserEmergency) {
    JNIEnv* env = getJniEnv();
    JNIEnv* env = getJniEnv();
    env->CallVoidMethod(mCallbacksObj, method_requestLocation, boolToJbool(independentFromGnss));
    env->CallVoidMethod(mCallbacksObj, method_requestLocation, boolToJbool(independentFromGnss),
            boolToJbool(isUserEmergency));
    checkAndClearExceptionFromCallback(env, __FUNCTION__);
    checkAndClearExceptionFromCallback(env, __FUNCTION__);
    return Void();
    return Void();
}
}
@@ -1422,7 +1432,7 @@ static void android_location_GnssLocationProvider_init_once(JNIEnv* env, jclass
    method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V");
    method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V");
    method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification",
    method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification",
            "(IIIIILjava/lang/String;Ljava/lang/String;II)V");
            "(IIIIILjava/lang/String;Ljava/lang/String;II)V");
    method_requestLocation = env->GetMethodID(clazz, "requestLocation", "(Z)V");
    method_requestLocation = env->GetMethodID(clazz, "requestLocation", "(ZZ)V");
    method_requestRefLocation = env->GetMethodID(clazz, "requestRefLocation", "()V");
    method_requestRefLocation = env->GetMethodID(clazz, "requestRefLocation", "()V");
    method_requestSetID = env->GetMethodID(clazz, "requestSetID", "(I)V");
    method_requestSetID = env->GetMethodID(clazz, "requestSetID", "(I)V");
    method_requestUtcTime = env->GetMethodID(clazz, "requestUtcTime", "()V");
    method_requestUtcTime = env->GetMethodID(clazz, "requestUtcTime", "()V");