microg / GmsCore

Free implementation of Play Services
https://microg.org
Apache License 2.0
8.26k stars 1.7k forks source link

[ENF] Warning when disabling location servies on Android 11 #1610

Open Diapolo opened 2 years ago

Diapolo commented 2 years ago

As far as I know, under Android 11 it should not be necessary to have location services active for exposure notifications to work. But when I disable them I get a microG warning, telling me they need to be active. Could this be fixed with a new release :)?

Thanks, Dia

Bubu commented 2 years ago

See https://github.com/microg/GmsCore/issues/1356 where we tried to get to the bottom of this.

Tl;DR: it doesn't work without enabled location services.

Also refer to https://codeberg.org/corona-contact-tracing-germany/cwa-android#why-does-the-app-need-location-permission which explains why this works for google ENF but not for us.

ale5000-git commented 1 year ago

This code isn't complete and need testing but it theoretically should be able to detect when EN may work with location setting disabled in the device. I have just written it in notepad.

boolean need_device_location_enabled = true;
boolean strict_location_check = true;
string exposure_notification_package = "";

if (Build.VERSION.SDK_INT < 23) {
    strict_location_check = false;
} else {
    try
    {
        PackageManager manager = getPackageManager();
        Resources resources = manager.getResourcesForApplication("com.android.bluetooth");

        try
        {
            int resId = resources.getIdentifier("strict_location_check", "boolean", "com.android.bluetooth");
            strict_location_check = resources.getBoolean(resId);
        }
        catch (Exception e)
        {
        }

        if (Build.VERSION.SDK_INT >= 30) {
            try
            {
                int resId = resources.getIdentifier("exposure_notification_package", "string", "com.android.bluetooth");
                exposure_notification_package = resources.getString(resId);
            }
            catch (Exception e)
            {
            }
        }
    }
    catch (Exception e)
    {
    }
}

if (strict_location_check != true) {
    need_device_location_enabled = false;
} else if (microg_en_is_used == true && exposure_notification_package == "com.google.android.gms") {
    need_device_location_enabled = false;
} else if (internal_package_en_is_used == true && exposure_notification_package == package_internal_name) {
    need_device_location_enabled = false;
}

PS: Moved from here => https://github.com/microg/GmsCore/issues/1796#issuecomment-1269534917