From ba8e0524e0f5e3a7df4f2b03ae7a3dedbfe21338 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 1 Jul 2023 17:14:47 +0200 Subject: [PATCH] Location: Move network location provider to independent module --- play-services-core/build.gradle | 1 + .../org/microg/gms/ui/SafetyNetFragment.kt | 3 - .../org/microg/gms/ui/SettingsFragment.kt | 8 +- play-services-location/core/base/build.gradle | 32 ++++++ .../core/base/src/main/AndroidManifest.xml | 6 ++ .../microg/gms/location/LocationSettings.kt | 0 .../org/microg/gms/location/extensions.kt | 95 +++++++++++++++++ play-services-location/core/build.gradle | 3 +- .../core/provider/build.gradle | 46 ++++++++ .../provider/src/main/AndroidManifest.xml | 65 ++++++++++++ .../location/network/LocationCacheDatabase.kt | 22 ++-- .../network/NetworkLocationRequest.kt | 3 +- .../network/NetworkLocationService.kt | 18 +--- .../gms/location/network/cell/CellDetails.kt | 0 .../network/cell/CellDetailsCallback.kt | 0 .../network/cell/CellDetailsSource.kt | 1 - .../gms/location/network/cell/extensions.kt | 2 - .../microg/gms/location/network/extensions.kt | 3 +- .../gms/location/network/mozilla/CellTower.kt | 0 .../gms/location/network/mozilla/Fallback.kt | 0 .../network/mozilla/GeolocateRequest.kt | 0 .../network/mozilla/GeolocateResponse.kt | 0 .../mozilla/MozillaLocationServiceClient.kt | 13 +-- .../gms/location/network/mozilla/RadioType.kt | 0 .../location/network/mozilla/ResponseError.kt | 0 .../network/mozilla/ResponseLocation.kt | 0 .../network/mozilla/ServiceException.kt | 0 .../network/mozilla/WifiAccessPoint.kt | 0 .../location/network/mozilla/extensions.kt | 0 .../location/network/wifi/MovingWifiHelper.kt | 3 +- .../gms/location/network/wifi/WifiDetails.kt | 0 .../network/wifi/WifiDetailsCallback.kt | 0 .../network/wifi/WifiDetailsSource.kt | 0 .../network/wifi/WifiManagerSource.kt | 3 +- .../network/wifi/WifiScannerSource.kt | 10 +- .../gms/location/network/wifi/extensions.kt | 1 - .../AbstractLocationProviderPreTiramisu.kt | 1 - .../provider/GenericLocationProvider.kt | 0 .../provider/GeocodeProviderService.kt | 0 .../NetworkLocationProviderPreTiramisu.kt | 22 ++-- .../NetworkLocationProviderService.kt | 9 +- .../OpenStreetMapNominatimGeocodeProvider.kt | 0 .../gms/location/provider/extensions.kt | 2 - .../core/src/main/AndroidManifest.xml | 35 ------ .../org/microg/gms/location/extensions.kt | 58 ---------- .../location/manager/LastLocationCapsule.kt | 2 - .../gms/location/manager/LocationManager.kt | 100 ++++++++---------- .../manager/LocationManagerService.kt | 14 +-- .../microg/gms/location/manager/extensions.kt | 20 ++++ .../reporting/ReportingAndroidService.kt | 2 +- .../ui/LocationPreferencesFragment.kt | 15 ++- .../src/main/res/xml/preferences_location.xml | 76 ++++++------- .../{ => core}/system-api/build.gradle | 0 .../system-api/src/main/AndroidManifest.xml | 0 .../java/android/location/GeocoderParams.java | 0 .../main/java/android/location/Geofence.java | 0 .../main/java/android/location/Location.java | 0 .../android/location/LocationManager.java | 0 .../android/location/LocationRequest.java | 0 .../java/android/net/wifi/WifiScanner.java | 0 .../internal/location/ProviderProperties.java | 0 .../internal/location/ProviderRequest.java | 0 .../location/provider/GeocodeProvider.java | 0 .../location/provider/LocationProvider.java | 0 .../provider/LocationProviderBase.java | 0 .../provider/LocationRequestUnbundled.java | 0 .../provider/ProviderPropertiesUnbundled.java | 0 .../provider/ProviderRequestUnbundled.java | 0 settings.gradle | 4 +- 69 files changed, 417 insertions(+), 281 deletions(-) create mode 100644 play-services-location/core/base/build.gradle create mode 100644 play-services-location/core/base/src/main/AndroidManifest.xml rename play-services-location/core/{ => base}/src/main/kotlin/org/microg/gms/location/LocationSettings.kt (100%) create mode 100644 play-services-location/core/base/src/main/kotlin/org/microg/gms/location/extensions.kt create mode 100644 play-services-location/core/provider/build.gradle create mode 100644 play-services-location/core/provider/src/main/AndroidManifest.xml rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/LocationCacheDatabase.kt (96%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/NetworkLocationRequest.kt (90%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/NetworkLocationService.kt (96%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/cell/CellDetails.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsCallback.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsSource.kt (97%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/cell/extensions.kt (99%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/extensions.kt (86%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/CellTower.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/Fallback.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateRequest.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateResponse.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/MozillaLocationServiceClient.kt (87%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/RadioType.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseError.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseLocation.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/ServiceException.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/WifiAccessPoint.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/mozilla/extensions.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt (98%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetails.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsCallback.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsSource.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/wifi/WifiManagerSource.kt (94%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/wifi/WifiScannerSource.kt (80%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/network/wifi/extensions.kt (98%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/provider/AbstractLocationProviderPreTiramisu.kt (98%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/provider/GenericLocationProvider.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/provider/GeocodeProviderService.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderPreTiramisu.kt (80%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderService.kt (90%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/provider/OpenStreetMapNominatimGeocodeProvider.kt (100%) rename play-services-location/core/{ => provider}/src/main/kotlin/org/microg/gms/location/provider/extensions.kt (89%) delete mode 100644 play-services-location/core/src/main/kotlin/org/microg/gms/location/extensions.kt rename play-services-location/{ => core}/system-api/build.gradle (100%) rename play-services-location/{ => core}/system-api/src/main/AndroidManifest.xml (100%) rename play-services-location/{ => core}/system-api/src/main/java/android/location/GeocoderParams.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/android/location/Geofence.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/android/location/Location.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/android/location/LocationManager.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/android/location/LocationRequest.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/android/net/wifi/WifiScanner.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/com/android/internal/location/ProviderProperties.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/com/android/internal/location/ProviderRequest.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/com/android/location/provider/GeocodeProvider.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/com/android/location/provider/LocationProvider.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/com/android/location/provider/LocationProviderBase.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/com/android/location/provider/LocationRequestUnbundled.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/com/android/location/provider/ProviderPropertiesUnbundled.java (100%) rename play-services-location/{ => core}/system-api/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java (100%) diff --git a/play-services-core/build.gradle b/play-services-core/build.gradle index 2c7afbcaa9..b339b2dadd 100644 --- a/play-services-core/build.gradle +++ b/play-services-core/build.gradle @@ -33,6 +33,7 @@ dependencies { implementation project(':play-services-fido-core') implementation project(':play-services-gmscompliance-core') implementation project(':play-services-location-core') + implementation project(':play-services-location-core-provider') withNearbyImplementation project(':play-services-nearby-core') implementation project(':play-services-oss-licenses-core') implementation project(':play-services-pay-core') diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/SafetyNetFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/SafetyNetFragment.kt index fe5b91cb74..df1f6641a3 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/SafetyNetFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/SafetyNetFragment.kt @@ -54,10 +54,7 @@ class SafetyNetFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.preferences_safetynet) - } - @SuppressLint("RestrictedApi") - override fun onBindPreferences() { switchBarPreference = preferenceScreen.findPreference("pref_safetynet_enabled") ?: switchBarPreference runAttest = preferenceScreen.findPreference("pref_safetynet_run_attest") ?: runAttest runReCaptcha = preferenceScreen.findPreference("pref_recaptcha_run_test") ?: runReCaptcha diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt index f522488013..336ae1dc3d 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt @@ -47,6 +47,10 @@ class SettingsFragment : ResourceSettingsFragment() { true } findPreference(PREF_ABOUT)!!.summary = getString(R.string.about_version_str, AboutFragment.getSelfVersion(context)) + + findPreference(PREF_EXPOSURE)?.isVisible = NearbyPreferencesIntegration.isAvailable + findPreference(PREF_EXPOSURE)?.icon = NearbyPreferencesIntegration.getIcon(requireContext()) + findPreference(PREF_EXPOSURE)?.summary = NearbyPreferencesIntegration.getExposurePreferenceSummary(requireContext()) } override fun onResume() { @@ -63,10 +67,6 @@ class SettingsFragment : ResourceSettingsFragment() { findPreference(PREF_CHECKIN)!!.setSummary(if (CheckinPreferences.isEnabled(requireContext())) R.string.service_status_enabled_short else R.string.service_status_disabled_short) findPreference(PREF_SNET)!!.setSummary(if (SafetyNetPreferences.isEnabled(requireContext())) R.string.service_status_enabled_short else R.string.service_status_disabled_short) - - findPreference(PREF_EXPOSURE)?.isVisible = NearbyPreferencesIntegration.isAvailable - findPreference(PREF_EXPOSURE)?.icon = NearbyPreferencesIntegration.getIcon(requireContext()) - findPreference(PREF_EXPOSURE)?.summary = NearbyPreferencesIntegration.getExposurePreferenceSummary(context) } companion object { diff --git a/play-services-location/core/base/build.gradle b/play-services-location/core/base/build.gradle new file mode 100644 index 0000000000..8f6663fe62 --- /dev/null +++ b/play-services-location/core/base/build.gradle @@ -0,0 +1,32 @@ +/* + * SPDX-FileCopyrightText: 2023 microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +dependencies { + api project(':play-services-location') + implementation project(':play-services-base-core') +} + +android { + compileSdkVersion androidCompileSdk + buildToolsVersion "$androidBuildVersionTools" + + defaultConfig { + versionName version + minSdkVersion androidMinSdk + targetSdkVersion androidTargetSdk + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + compileOptions { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + } +} diff --git a/play-services-location/core/base/src/main/AndroidManifest.xml b/play-services-location/core/base/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..671251d213 --- /dev/null +++ b/play-services-location/core/base/src/main/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/LocationSettings.kt b/play-services-location/core/base/src/main/kotlin/org/microg/gms/location/LocationSettings.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/LocationSettings.kt rename to play-services-location/core/base/src/main/kotlin/org/microg/gms/location/LocationSettings.kt diff --git a/play-services-location/core/base/src/main/kotlin/org/microg/gms/location/extensions.kt b/play-services-location/core/base/src/main/kotlin/org/microg/gms/location/extensions.kt new file mode 100644 index 0000000000..d5a5c79d23 --- /dev/null +++ b/play-services-location/core/base/src/main/kotlin/org/microg/gms/location/extensions.kt @@ -0,0 +1,95 @@ +/* + * SPDX-FileCopyrightText: 2023 microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.microg.gms.location + +import android.content.Context +import android.content.Intent +import android.content.pm.PackageManager +import android.location.Location +import android.os.SystemClock +import android.text.format.DateUtils +import android.util.Log +import androidx.core.location.LocationCompat + +const val ACTION_NETWORK_LOCATION_SERVICE = "org.microg.gms.location.network.ACTION_NETWORK_LOCATION_SERVICE" +const val EXTRA_LOCATION = "location" +const val EXTRA_PENDING_INTENT = "pending_intent" +const val EXTRA_ENABLE = "enable" +const val EXTRA_INTERVAL_MILLIS = "interval" +const val EXTRA_FORCE_NOW = "force_now" +const val EXTRA_LOW_POWER = "low_power" +const val EXTRA_WORK_SOURCE = "work_source" +const val EXTRA_BYPASS = "bypass" + +val Location.elapsedMillis: Long + get() = LocationCompat.getElapsedRealtimeMillis(this) + +fun Long.formatRealtime(): CharSequence = if (this <= 0) "n/a" else DateUtils.getRelativeTimeSpanString((this - SystemClock.elapsedRealtime()) + System.currentTimeMillis(), System.currentTimeMillis(), 0) +fun Long.formatDuration(): CharSequence { + if (this == 0L) return "0ms" + if (this > 315360000000L /* ten years */) return "\u221e" + val interval = listOf(1000, 60, 60, 24, Long.MAX_VALUE) + val intervalName = listOf("ms", "s", "m", "h", "d") + var ret = "" + var rem = this + for (i in 0 until interval.size) { + val mod = rem % interval[i] + if (mod != 0L) { + ret = "$mod${intervalName[i]}$ret" + } + rem /= interval[i] + if (mod == 0L && rem == 1L) { + ret = "${interval[i]}${intervalName[i]}$ret" + break + } else if (rem == 0L) { + break + } + } + return ret +} + +private var hasMozillaLocationServiceSupportFlag: Boolean? = null +fun Context.hasMozillaLocationServiceSupport(): Boolean { + if (!hasNetworkLocationServiceBuiltIn()) return false + var flag = hasMozillaLocationServiceSupportFlag + if (flag == null) { + return try { + val clazz = Class.forName("org.microg.gms.location.network.mozilla.MozillaLocationServiceClient") + val apiKey = clazz.getDeclaredField("API_KEY").get(null) as? String? + flag = apiKey != null + hasMozillaLocationServiceSupportFlag = flag + flag + } catch (e: Exception) { + Log.w("Location", e) + hasMozillaLocationServiceSupportFlag = false + false + } + } else { + return flag + } +} + +private var hasNetworkLocationServiceBuiltInFlag: Boolean? = null +fun Context.hasNetworkLocationServiceBuiltIn(): Boolean { + var flag = hasNetworkLocationServiceBuiltInFlag + if (flag == null) { + try { + val serviceIntent = Intent().apply { + action = ACTION_NETWORK_LOCATION_SERVICE + setPackage(packageName) + } + val services = packageManager?.queryIntentServices(serviceIntent, PackageManager.MATCH_DEFAULT_ONLY) + flag = services?.isNotEmpty() ?: false + hasNetworkLocationServiceBuiltInFlag = flag + return flag + } catch (e: Exception) { + hasNetworkLocationServiceBuiltInFlag = false + return false + } + } else { + return flag + } +} \ No newline at end of file diff --git a/play-services-location/core/build.gradle b/play-services-location/core/build.gradle index 719a6ea54f..d048274a0e 100644 --- a/play-services-location/core/build.gradle +++ b/play-services-location/core/build.gradle @@ -8,8 +8,8 @@ apply plugin: 'kotlin-android' dependencies { api project(':play-services-location') - compileOnly project(':play-services-location-system-api') implementation project(':play-services-base-core') + implementation project(':play-services-location-core-base') implementation "androidx.lifecycle:lifecycle-service:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion" @@ -23,7 +23,6 @@ dependencies { implementation "com.android.volley:volley:$volleyVersion" - implementation 'org.microg:address-formatter:0.3.1' compileOnly project(':play-services-maps') } diff --git a/play-services-location/core/provider/build.gradle b/play-services-location/core/provider/build.gradle new file mode 100644 index 0000000000..1aa2e2948d --- /dev/null +++ b/play-services-location/core/provider/build.gradle @@ -0,0 +1,46 @@ +/* + * SPDX-FileCopyrightText: 2023 microG Project Team + * SPDX-License-Identifier: Apache-2.0 + */ + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +dependencies { + api project(':play-services-location') + compileOnly project(':play-services-location-core-system-api') + implementation project(':play-services-base-core') + implementation project(':play-services-location-core-base') + + implementation "androidx.lifecycle:lifecycle-service:$lifecycleVersion" + implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion" + + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion" + + implementation "com.android.volley:volley:$volleyVersion" + + implementation 'org.microg:address-formatter:0.3.1' +} + +android { + compileSdkVersion androidCompileSdk + buildToolsVersion "$androidBuildVersionTools" + + defaultConfig { + versionName version + minSdkVersion androidMinSdk + targetSdkVersion androidTargetSdk + buildConfigField "String", "ICHNAEA_KEY", "\"${localProperties.get("ichnaea.key", "")}\"" + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + compileOptions { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 + } +} diff --git a/play-services-location/core/provider/src/main/AndroidManifest.xml b/play-services-location/core/provider/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..e75eb59df5 --- /dev/null +++ b/play-services-location/core/provider/src/main/AndroidManifest.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/LocationCacheDatabase.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/LocationCacheDatabase.kt similarity index 96% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/LocationCacheDatabase.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/LocationCacheDatabase.kt index 60abaf7f89..33403f2f33 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/LocationCacheDatabase.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/LocationCacheDatabase.kt @@ -12,7 +12,6 @@ import android.database.DatabaseUtils import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper import android.location.Location -import android.util.Log import androidx.core.content.contentValuesOf import androidx.core.os.bundleOf import org.microg.gms.location.network.cell.CellDetails @@ -133,22 +132,25 @@ internal class LocationCacheDatabase(context: Context?) : SQLiteOpenHelper(conte ).use { cursor -> if (cursor.moveToNext()) { val midLocation = cursor.getMidLocation(Long.MAX_VALUE, 0f) - (midLocation != null) to (midLocation?.let { it.distanceTo(location) > LEARN_BAD_SIZE_CELL} == true) + (midLocation != null) to (midLocation?.let { it.distanceTo(location) > LEARN_BAD_SIZE_CELL } == true) } else { false to false } } if (exists && isBad) { - writableDatabase.update(TABLE_CELLS_LEARN, contentValuesOf( + writableDatabase.update( + TABLE_CELLS_LEARN, contentValuesOf( FIELD_LATITUDE_HIGH to location.latitude, FIELD_LATITUDE_LOW to location.latitude, FIELD_LONGITUDE_HIGH to location.longitude, FIELD_LONGITUDE_LOW to location.longitude, FIELD_TIME to location.time, FIELD_BAD_TIME to location.time - ), CELLS_SELECTION, getCellSelectionArgs(cell)) + ), CELLS_SELECTION, getCellSelectionArgs(cell) + ) } else if (!exists) { - writableDatabase.insertWithOnConflict(TABLE_CELLS_LEARN, null, contentValuesOf( + writableDatabase.insertWithOnConflict( + TABLE_CELLS_LEARN, null, contentValuesOf( FIELD_MCC to cell.mcc, FIELD_MNC to cell.mnc, FIELD_LAC_TAC to (cell.lac ?: cell.tac ?: 0), @@ -180,13 +182,14 @@ internal class LocationCacheDatabase(context: Context?) : SQLiteOpenHelper(conte ).use { cursor -> if (cursor.moveToNext()) { val midLocation = cursor.getMidLocation(Long.MAX_VALUE, 0f) - (midLocation != null) to (midLocation?.let { it.distanceTo(location) > LEARN_BAD_SIZE_WIFI} == true) + (midLocation != null) to (midLocation?.let { it.distanceTo(location) > LEARN_BAD_SIZE_WIFI } == true) } else { false to false } } if (exists && isBad) { - writableDatabase.update(TABLE_WIFI_LEARN, contentValuesOf( + writableDatabase.update( + TABLE_WIFI_LEARN, contentValuesOf( FIELD_LATITUDE_HIGH to location.latitude, FIELD_LATITUDE_LOW to location.latitude, FIELD_LONGITUDE_HIGH to location.longitude, @@ -195,7 +198,8 @@ internal class LocationCacheDatabase(context: Context?) : SQLiteOpenHelper(conte FIELD_BAD_TIME to location.time ), getWifiSelection(wifi), null) } else if (!exists) { - writableDatabase.insertWithOnConflict(TABLE_WIFI_LEARN, null, contentValuesOf( + writableDatabase.insertWithOnConflict( + TABLE_WIFI_LEARN, null, contentValuesOf( FIELD_MAC to wifi.macBytes, FIELD_LATITUDE_HIGH to location.latitude, FIELD_LATITUDE_LOW to location.latitude, @@ -225,7 +229,7 @@ internal class LocationCacheDatabase(context: Context?) : SQLiteOpenHelper(conte db.execSQL("CREATE INDEX IF NOT EXISTS ${TABLE_WIFIS}_time_index ON $TABLE_WIFIS($FIELD_TIME);") db.execSQL("CREATE INDEX IF NOT EXISTS ${TABLE_CELLS_LEARN}_time_index ON $TABLE_CELLS_LEARN($FIELD_TIME);") db.execSQL("CREATE INDEX IF NOT EXISTS ${TABLE_WIFI_LEARN}_time_index ON $TABLE_WIFI_LEARN($FIELD_TIME);") - db.execSQL("DROP TABLE IF EXISTS ${TABLE_WIFI_SCANS};") + db.execSQL("DROP TABLE IF EXISTS $TABLE_WIFI_SCANS;") } fun cleanup(db: SQLiteDatabase) { diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/NetworkLocationRequest.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/NetworkLocationRequest.kt similarity index 90% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/NetworkLocationRequest.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/NetworkLocationRequest.kt index 1bf4e2faf9..6c10cf72a1 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/NetworkLocationRequest.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/NetworkLocationRequest.kt @@ -11,6 +11,7 @@ import android.content.Intent import android.location.Location import android.os.SystemClock import android.os.WorkSource +import org.microg.gms.location.EXTRA_LOCATION class NetworkLocationRequest( var pendingIntent: PendingIntent, @@ -23,6 +24,6 @@ class NetworkLocationRequest( fun send(context: Context, location: Location) { lastRealtime = SystemClock.elapsedRealtime() - pendingIntent.send(context, 0, Intent().apply { putExtra(NetworkLocationService.EXTRA_LOCATION, location) }) + pendingIntent.send(context, 0, Intent().apply { putExtra(EXTRA_LOCATION, location) }) } } \ No newline at end of file diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/NetworkLocationService.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/NetworkLocationService.kt similarity index 96% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/NetworkLocationService.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/NetworkLocationService.kt index d2079afb23..29432c2ebc 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/NetworkLocationService.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/NetworkLocationService.kt @@ -28,10 +28,7 @@ import androidx.lifecycle.lifecycleScope import com.android.volley.VolleyError import kotlinx.coroutines.launch import kotlinx.coroutines.withTimeout -import org.microg.gms.location.LocationSettings -import org.microg.gms.location.elapsedMillis -import org.microg.gms.location.formatDuration -import org.microg.gms.location.formatRealtime +import org.microg.gms.location.* import org.microg.gms.location.network.LocationCacheDatabase.Companion.NEGATIVE_CACHE_ENTRY import org.microg.gms.location.network.cell.CellDetails import org.microg.gms.location.network.cell.CellDetailsCallback @@ -425,15 +422,6 @@ class NetworkLocationService : LifecycleService(), WifiDetailsCallback, CellDeta } companion object { - const val ACTION_REPORT_LOCATION = "org.microg.gms.location.network.ACTION_REPORT_LOCATION" - const val EXTRA_PENDING_INTENT = "pending_intent" - const val EXTRA_ENABLE = "enable" - const val EXTRA_INTERVAL_MILLIS = "interval" - const val EXTRA_FORCE_NOW = "force_now" - const val EXTRA_LOW_POWER = "low_power" - const val EXTRA_WORK_SOURCE = "work_source" - const val EXTRA_BYPASS = "bypass" - const val EXTRA_LOCATION = "location" const val GPS_BUFFER_SIZE = 60 const val GPS_PASSIVE_INTERVAL = 1000L const val GPS_PASSIVE_MIN_ACCURACY = 25f @@ -449,8 +437,8 @@ private operator fun LruCache.set(key: K, value: V) { fun List.hash(): ByteArray? { val filtered = sortedBy { it.macClean } - .filter { it.timestamp == null || it.timestamp > System.currentTimeMillis() - 60000 } - .filter { it.signalStrength == null || it.signalStrength > -90 } + .filter { it.timestamp == null || it.timestamp!! > System.currentTimeMillis() - 60000 } + .filter { it.signalStrength == null || it.signalStrength!! > -90 } if (filtered.size < 3) return null val maxTimestamp = maxOf { it.timestamp ?: 0L } fun WifiDetails.hashBytes(): ByteArray { diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/CellDetails.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/CellDetails.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/CellDetails.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/CellDetails.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsCallback.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsCallback.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsCallback.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsCallback.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsSource.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsSource.kt similarity index 97% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsSource.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsSource.kt index 8a49fee8b3..316da16aa9 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsSource.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/CellDetailsSource.kt @@ -12,7 +12,6 @@ import android.os.WorkSource import android.telephony.CellInfo import android.telephony.TelephonyManager import androidx.core.content.getSystemService -import org.microg.gms.location.network.LocationCacheDatabase class CellDetailsSource(private val context: Context, private val callback: CellDetailsCallback) { fun enable() = Unit diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/extensions.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/extensions.kt similarity index 99% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/extensions.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/extensions.kt index e5af415602..0e1b1966d6 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/cell/extensions.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/cell/extensions.kt @@ -26,10 +26,8 @@ import android.telephony.CellLocation import android.telephony.TelephonyManager import android.telephony.cdma.CdmaCellLocation import android.telephony.gsm.GsmCellLocation -import android.util.Log import androidx.annotation.RequiresApi import androidx.core.content.getSystemService -import org.microg.gms.location.network.TAG private fun locationFromCdma(latitude: Int, longitude: Int) = if (latitude == Int.MAX_VALUE || longitude == Int.MAX_VALUE) null else Location("cdma").also { it.latitude = latitude.toDouble() / 14400.0 diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/extensions.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/extensions.kt similarity index 86% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/extensions.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/extensions.kt index e20e43ada8..565901a24b 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/extensions.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/extensions.kt @@ -7,11 +7,10 @@ package org.microg.gms.location.network import android.location.Location import android.os.Bundle -import androidx.core.location.LocationCompat import java.security.MessageDigest const val TAG = "NetworkLocation" -internal const val LOCATION_EXTRA_PRECISION = "precision" +const val LOCATION_EXTRA_PRECISION = "precision" internal var Location.precision: Double get() = extras?.getDouble(LOCATION_EXTRA_PRECISION, 1.0) ?: 1.0 diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/CellTower.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/CellTower.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/CellTower.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/CellTower.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/Fallback.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/Fallback.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/Fallback.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/Fallback.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateRequest.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateRequest.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateRequest.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateRequest.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateResponse.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateResponse.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateResponse.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/GeolocateResponse.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/MozillaLocationServiceClient.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/MozillaLocationServiceClient.kt similarity index 87% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/MozillaLocationServiceClient.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/MozillaLocationServiceClient.kt index bb14f71f30..a3ab400420 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/MozillaLocationServiceClient.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/MozillaLocationServiceClient.kt @@ -13,32 +13,28 @@ import android.util.Log import com.android.volley.Request.Method import com.android.volley.toolbox.JsonObjectRequest import com.android.volley.toolbox.Volley -import org.microg.gms.location.core.BuildConfig -import org.microg.gms.location.network.NetworkLocationService -import org.microg.gms.location.network.cell.CellDetails +import org.microg.gms.location.provider.BuildConfig import org.microg.gms.location.network.precision import org.microg.gms.location.network.wifi.WifiDetails import org.microg.gms.location.network.wifi.isMoving import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException import kotlin.coroutines.suspendCoroutine -import kotlin.math.log10 -import kotlin.math.log2 class MozillaLocationServiceClient(context: Context) { private val queue = Volley.newRequestQueue(context) - suspend fun retrieveMultiWifiLocation(wifis: List): Location = geoLocate( + suspend fun retrieveMultiWifiLocation(wifis: List): Location = geoLocate( GeolocateRequest( considerIp = false, wifiAccessPoints = wifis.filter { it.ssid?.endsWith("_nomap") != true && !it.isMoving }.map(WifiDetails::toWifiAccessPoint), fallbacks = Fallback(lacf = false, ipf = false) ) ).apply { - precision = wifis.size.toDouble()/WIFI_BASE_PRECISION_COUNT + precision = wifis.size.toDouble()/ WIFI_BASE_PRECISION_COUNT } - suspend fun retrieveSingleCellLocation(cell: CellDetails): Location = geoLocate( + suspend fun retrieveSingleCellLocation(cell: org.microg.gms.location.network.cell.CellDetails): Location = geoLocate( GeolocateRequest( considerIp = false, cellTowers = listOf(cell.toCellTower()), @@ -84,6 +80,7 @@ class MozillaLocationServiceClient(context: Context) { private const val WIFI_BASE_PRECISION_COUNT = 4.0 private const val CELL_DEFAULT_PRECISION = 1.0 private const val CELL_FALLBACK_PRECISION = 0.5 + @JvmField val API_KEY: String? = BuildConfig.ICHNAEA_KEY.takeIf { it.isNotBlank() } const val LOCATION_EXTRA_FALLBACK = "fallback" } diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/RadioType.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/RadioType.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/RadioType.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/RadioType.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseError.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseError.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseError.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseError.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseLocation.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseLocation.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseLocation.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/ResponseLocation.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/ServiceException.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/ServiceException.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/ServiceException.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/ServiceException.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/WifiAccessPoint.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/WifiAccessPoint.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/WifiAccessPoint.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/WifiAccessPoint.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/extensions.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/extensions.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/mozilla/extensions.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/mozilla/extensions.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt similarity index 98% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt index eaa58c3272..fdf896fc8c 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/MovingWifiHelper.kt @@ -17,7 +17,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.json.JSONArray import org.json.JSONObject -import org.microg.gms.location.network.TAG import java.net.HttpURLConnection import java.net.URL import java.text.SimpleDateFormat @@ -92,7 +91,7 @@ class MovingWifiHelper(private val context: Context) { @Suppress("DEPRECATION") (connectivityManager.allNetworks.singleOrNull { val networkInfo = connectivityManager.getNetworkInfo(it) - Log.d(TAG, "Network info: $networkInfo") + Log.d(org.microg.gms.location.network.TAG, "Network info: $networkInfo") networkInfo?.type == TYPE_WIFI && networkInfo.isConnected }) } else { diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetails.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetails.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetails.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetails.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsCallback.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsCallback.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsCallback.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsCallback.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsSource.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsSource.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsSource.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiDetailsSource.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiManagerSource.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiManagerSource.kt similarity index 94% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiManagerSource.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiManagerSource.kt index faa6d4d5de..71cbb4180a 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiManagerSource.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiManagerSource.kt @@ -15,7 +15,6 @@ import android.net.wifi.WifiManager import android.os.WorkSource import android.util.Log import androidx.core.content.getSystemService -import org.microg.gms.location.network.TAG class WifiManagerSource(private val context: Context, private val callback: WifiDetailsCallback) : BroadcastReceiver(), WifiDetailsSource { @@ -24,7 +23,7 @@ class WifiManagerSource(private val context: Context, private val callback: Wifi try { callback.onWifiDetailsAvailable(this.context.getSystemService()?.scanResults.orEmpty().map(ScanResult::toWifiDetails)) } catch (e: Exception) { - Log.w(TAG, e) + Log.w(org.microg.gms.location.network.TAG, e) } } diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiScannerSource.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiScannerSource.kt similarity index 80% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiScannerSource.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiScannerSource.kt index 8f7b80d0e4..d9a6fd45d8 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/WifiScannerSource.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/WifiScannerSource.kt @@ -8,7 +8,6 @@ package org.microg.gms.location.network.wifi import android.Manifest import android.annotation.SuppressLint import android.content.Context -import android.content.pm.PackageManager import android.content.pm.PackageManager.PERMISSION_GRANTED import android.net.wifi.ScanResult import android.net.wifi.WifiScanner @@ -16,7 +15,6 @@ import android.os.Build.VERSION.SDK_INT import android.os.WorkSource import android.util.Log import androidx.core.content.ContextCompat -import org.microg.gms.location.network.TAG @SuppressLint("WrongConstant") class WifiScannerSource(private val context: Context, private val callback: WifiDetailsCallback) : WifiDetailsSource { @@ -24,15 +22,15 @@ class WifiScannerSource(private val context: Context, private val callback: Wifi val scanner = context.getSystemService("wifiscanner") as WifiScanner scanner.startScan(WifiScanner.ScanSettings(), object : WifiScanner.ScanListener { override fun onSuccess() { - Log.d(TAG, "Not yet implemented: onSuccess") + Log.d(org.microg.gms.location.network.TAG, "Not yet implemented: onSuccess") } override fun onFailure(reason: Int, description: String?) { - Log.d(TAG, "Not yet implemented: onFailure ${reason} ${description}") + Log.d(org.microg.gms.location.network.TAG, "Not yet implemented: onFailure ${reason} ${description}") } override fun onPeriodChanged(periodInMs: Int) { - Log.d(TAG, "Not yet implemented: onPeriodChanged") + Log.d(org.microg.gms.location.network.TAG, "Not yet implemented: onPeriodChanged") } override fun onResults(results: Array) { @@ -40,7 +38,7 @@ class WifiScannerSource(private val context: Context, private val callback: Wifi } override fun onFullResult(fullScanResult: ScanResult) { - Log.d(TAG, "Not yet implemented: onFullResult") + Log.d(org.microg.gms.location.network.TAG, "Not yet implemented: onFullResult") } }, workSource) } diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/extensions.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/extensions.kt similarity index 98% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/extensions.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/extensions.kt index 610d8ca2d1..2d5617261a 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/network/wifi/extensions.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/network/wifi/extensions.kt @@ -6,7 +6,6 @@ package org.microg.gms.location.network.wifi import android.net.wifi.ScanResult -import android.net.wifi.WifiInfo import android.os.Build import android.os.SystemClock diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/AbstractLocationProviderPreTiramisu.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/AbstractLocationProviderPreTiramisu.kt similarity index 98% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/AbstractLocationProviderPreTiramisu.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/AbstractLocationProviderPreTiramisu.kt index 74cd11c337..c737ea25ba 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/AbstractLocationProviderPreTiramisu.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/AbstractLocationProviderPreTiramisu.kt @@ -6,7 +6,6 @@ package org.microg.gms.location.provider import android.content.Context -import android.location.Location import android.location.LocationProvider import android.os.Bundle import android.os.SystemClock diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/GenericLocationProvider.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/GenericLocationProvider.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/GenericLocationProvider.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/GenericLocationProvider.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/GeocodeProviderService.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/GeocodeProviderService.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/GeocodeProviderService.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/GeocodeProviderService.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderPreTiramisu.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderPreTiramisu.kt similarity index 80% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderPreTiramisu.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderPreTiramisu.kt index 28ead1ad2c..40972f4efb 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderPreTiramisu.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderPreTiramisu.kt @@ -14,13 +14,13 @@ import android.location.Criteria import android.location.Location import android.os.Build.VERSION.SDK_INT import android.os.WorkSource -import android.util.Log import androidx.annotation.RequiresApi import com.android.location.provider.ProviderPropertiesUnbundled import com.android.location.provider.ProviderRequestUnbundled +import org.microg.gms.location.* import org.microg.gms.location.network.LOCATION_EXTRA_PRECISION import org.microg.gms.location.network.NetworkLocationService -import org.microg.gms.location.network.NetworkLocationService.Companion.ACTION_REPORT_LOCATION +import org.microg.gms.location.provider.NetworkLocationProviderService.Companion.ACTION_REPORT_LOCATION import java.io.PrintWriter import kotlin.math.max @@ -53,16 +53,16 @@ class NetworkLocationProviderPreTiramisu : AbstractLocationProviderPreTiramisu { intervalMillis = Long.MAX_VALUE } val intent = Intent(context, NetworkLocationService::class.java) - intent.putExtra(NetworkLocationService.EXTRA_PENDING_INTENT, pendingIntent) - intent.putExtra(NetworkLocationService.EXTRA_ENABLE, true) - intent.putExtra(NetworkLocationService.EXTRA_INTERVAL_MILLIS, intervalMillis) - intent.putExtra(NetworkLocationService.EXTRA_FORCE_NOW, forceNow) + intent.putExtra(EXTRA_PENDING_INTENT, pendingIntent) + intent.putExtra(EXTRA_ENABLE, true) + intent.putExtra(EXTRA_INTERVAL_MILLIS, intervalMillis) + intent.putExtra(EXTRA_FORCE_NOW, forceNow) if (SDK_INT >= 31) { - intent.putExtra(NetworkLocationService.EXTRA_LOW_POWER, currentRequest?.isLowPower ?: false) - intent.putExtra(NetworkLocationService.EXTRA_WORK_SOURCE, currentRequest?.workSource) + intent.putExtra(EXTRA_LOW_POWER, currentRequest?.isLowPower ?: false) + intent.putExtra(EXTRA_WORK_SOURCE, currentRequest?.workSource) } if (SDK_INT >= 29) { - intent.putExtra(NetworkLocationService.EXTRA_BYPASS, currentRequest?.isLocationSettingsIgnored ?: false) + intent.putExtra(EXTRA_BYPASS, currentRequest?.isLocationSettingsIgnored ?: false) } context.startService(intent) } @@ -100,8 +100,8 @@ class NetworkLocationProviderPreTiramisu : AbstractLocationProviderPreTiramisu { synchronized(this) { if (!enabled) throw IllegalStateException() val intent = Intent(context, NetworkLocationService::class.java) - intent.putExtra(NetworkLocationService.EXTRA_PENDING_INTENT, pendingIntent) - intent.putExtra(NetworkLocationService.EXTRA_ENABLE, false) + intent.putExtra(EXTRA_PENDING_INTENT, pendingIntent) + intent.putExtra(EXTRA_ENABLE, false) context.startService(intent) pendingIntent?.cancel() pendingIntent = null diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderService.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderService.kt similarity index 90% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderService.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderService.kt index 2d4a813b74..fb2cd9e279 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderService.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/NetworkLocationProviderService.kt @@ -10,8 +10,7 @@ import android.content.Intent import android.location.Location import android.os.* import android.os.Build.VERSION.SDK_INT -import org.microg.gms.location.network.NetworkLocationService.Companion.ACTION_REPORT_LOCATION -import org.microg.gms.location.network.NetworkLocationService.Companion.EXTRA_LOCATION +import org.microg.gms.location.EXTRA_LOCATION import java.io.FileDescriptor import java.io.PrintWriter @@ -51,7 +50,7 @@ class NetworkLocationProviderService : Service() { else -> @Suppress("DEPRECATION") - NetworkLocationProviderPreTiramisu(this, Unit) + (NetworkLocationProviderPreTiramisu(this, Unit)) } provider?.enable() } @@ -71,4 +70,8 @@ class NetworkLocationProviderService : Service() { bound = false super.onDestroy() } + + companion object { + const val ACTION_REPORT_LOCATION = "org.microg.gms.location.provider.ACTION_REPORT_LOCATION" + } } \ No newline at end of file diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/OpenStreetMapNominatimGeocodeProvider.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/OpenStreetMapNominatimGeocodeProvider.kt similarity index 100% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/OpenStreetMapNominatimGeocodeProvider.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/OpenStreetMapNominatimGeocodeProvider.kt diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/extensions.kt b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/extensions.kt similarity index 89% rename from play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/extensions.kt rename to play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/extensions.kt index eea68e661a..a99592a812 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/provider/extensions.kt +++ b/play-services-location/core/provider/src/main/kotlin/org/microg/gms/location/provider/extensions.kt @@ -6,11 +6,9 @@ package org.microg.gms.location.provider import android.content.Context -import android.content.pm.PackageManager import android.location.GeocoderParams import android.os.Build.VERSION.SDK_INT import com.google.android.gms.location.internal.ClientIdentity -import org.microg.gms.utils.getApplicationLabel const val TAG = "LocationProvider" diff --git a/play-services-location/core/src/main/AndroidManifest.xml b/play-services-location/core/src/main/AndroidManifest.xml index b5e7c720b2..3af5571577 100644 --- a/play-services-location/core/src/main/AndroidManifest.xml +++ b/play-services-location/core/src/main/AndroidManifest.xml @@ -10,18 +10,8 @@ - - - - - - - - @@ -48,28 +36,5 @@ - - - - - - - - - - - - - - - diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/extensions.kt b/play-services-location/core/src/main/kotlin/org/microg/gms/location/extensions.kt deleted file mode 100644 index 5e13e729d0..0000000000 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/extensions.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 microG Project Team - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.microg.gms.location - -import android.location.Location -import android.os.SystemClock -import android.text.format.DateUtils -import androidx.core.location.LocationCompat -import com.google.android.gms.common.Feature - -internal val Location.elapsedMillis: Long - get() = LocationCompat.getElapsedRealtimeMillis(this) - -internal val FEATURES = arrayOf( - Feature("name_ulr_private", 1), - Feature("driving_mode", 6), - Feature("name_sleep_segment_request", 1), - Feature("support_context_feature_id", 1), - Feature("get_current_location", 2), - Feature("get_last_activity_feature_id", 1), - Feature("get_last_location_with_request", 1), - Feature("set_mock_mode_with_callback", 1), - Feature("set_mock_location_with_callback", 1), - Feature("inject_location_with_callback", 1), - Feature("location_updates_with_callback", 1), - Feature("user_service_developer_features", 1), - Feature("user_service_location_accuracy", 1), - Feature("user_service_safety_and_emergency", 1), - - Feature("use_safe_parcelable_in_intents", 1) -) - -internal fun Long.formatRealtime(): CharSequence = if (this <= 0) "n/a" else DateUtils.getRelativeTimeSpanString((this - SystemClock.elapsedRealtime()) + System.currentTimeMillis(), System.currentTimeMillis(), 0) -internal fun Long.formatDuration(): CharSequence { - if (this == 0L) return "0ms" - if (this > 315360000000L /* ten years */) return "\u221e" - val interval = listOf(1000, 60, 60, 24, Long.MAX_VALUE) - val intervalName = listOf("ms", "s", "m", "h", "d") - var ret = "" - var rem = this - for (i in 0 until interval.size) { - val mod = rem % interval[i] - if (mod != 0L) { - ret = "$mod${intervalName[i]}$ret" - } - rem /= interval[i] - if (mod == 0L && rem == 1L) { - ret = "${interval[i]}${intervalName[i]}$ret" - break - } else if (rem == 0L) { - break - } - } - return ret -} \ No newline at end of file diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LastLocationCapsule.kt b/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LastLocationCapsule.kt index 59b1f95af1..69ceeb7295 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LastLocationCapsule.kt +++ b/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LastLocationCapsule.kt @@ -9,8 +9,6 @@ import android.content.Context import android.location.Location import android.location.LocationManager import android.os.Build.VERSION.SDK_INT -import android.os.Parcel -import android.os.Parcelable import android.os.SystemClock import android.util.Log import androidx.core.content.getSystemService diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LocationManager.kt b/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LocationManager.kt index 7ee780e4b2..2e7af73869 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LocationManager.kt +++ b/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LocationManager.kt @@ -13,6 +13,7 @@ import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.location.Location +import android.location.LocationManager import android.os.Build.VERSION.SDK_INT import android.os.IBinder import android.util.Log @@ -28,9 +29,7 @@ import com.google.android.gms.location.Granularity.GRANULARITY_COARSE import com.google.android.gms.location.Granularity.GRANULARITY_FINE import com.google.android.gms.location.Priority.PRIORITY_HIGH_ACCURACY import com.google.android.gms.location.internal.ClientIdentity -import org.microg.gms.location.GranularityUtil -import org.microg.gms.location.elapsedMillis -import org.microg.gms.location.network.NetworkLocationService +import org.microg.gms.location.* import org.microg.gms.utils.IntentCacheManager import java.io.PrintWriter import kotlin.math.max @@ -44,6 +43,8 @@ class LocationManager(private val context: Context, private val lifecycle: Lifec val database by lazy { LocationAppsDatabase(context) } private val requestManager by lazy { LocationRequestManager(context, lifecycle, postProcessor, database) { onRequestManagerUpdated() } } private val gpsLocationListener by lazy { LocationListenerCompat { updateGpsLocation(it) } } + private val networkLocationListener by lazy { LocationListenerCompat { updateNetworkLocation(it) } } + private var boundToSystemNetworkLocation: Boolean = false val deviceOrientationManager = DeviceOrientationManager(context, lifecycle) @@ -135,7 +136,7 @@ class LocationManager(private val context: Context, private val lifecycle: Lifec started = true } val intent = Intent(context, LocationManagerService::class.java) - intent.action = NetworkLocationService.ACTION_REPORT_LOCATION + intent.action = LocationManagerService.ACTION_REPORT_LOCATION coarsePendingIntent = PendingIntent.getService(context, 0, intent, (if (SDK_INT >= 31) FLAG_MUTABLE else 0) or FLAG_UPDATE_CURRENT) lastLocationCapsule.start() requestManager.start() @@ -150,13 +151,20 @@ class LocationManager(private val context: Context, private val lifecycle: Lifec lastLocationCapsule.stop() deviceOrientationManager.stop() - val intent = Intent(context, NetworkLocationService::class.java) - intent.putExtra(NetworkLocationService.EXTRA_PENDING_INTENT, coarsePendingIntent) - intent.putExtra(NetworkLocationService.EXTRA_ENABLE, false) - context.startService(intent) + if (context.hasNetworkLocationServiceBuiltIn()) { + val intent = Intent(ACTION_NETWORK_LOCATION_SERVICE) + intent.`package` = context.packageName + intent.putExtra(EXTRA_PENDING_INTENT, coarsePendingIntent) + intent.putExtra(EXTRA_ENABLE, false) + context.startService(intent) + } val locationManager = context.getSystemService() ?: return try { + if (boundToSystemNetworkLocation) { + LocationManagerCompat.removeUpdates(locationManager, networkLocationListener) + boundToSystemNetworkLocation = false + } LocationManagerCompat.removeUpdates(locationManager, gpsLocationListener) } catch (e: SecurityException) { // Ignore @@ -174,39 +182,34 @@ class LocationManager(private val context: Context, private val lifecycle: Lifec else -> Long.MAX_VALUE } - val intent = Intent(context, NetworkLocationService::class.java) - intent.putExtra(NetworkLocationService.EXTRA_PENDING_INTENT, coarsePendingIntent) - intent.putExtra(NetworkLocationService.EXTRA_ENABLE, true) - intent.putExtra(NetworkLocationService.EXTRA_INTERVAL_MILLIS, networkInterval) - intent.putExtra(NetworkLocationService.EXTRA_LOW_POWER, requestManager.granularity <= GRANULARITY_COARSE) - intent.putExtra(NetworkLocationService.EXTRA_WORK_SOURCE, requestManager.workSource) - context.startService(intent) + if (context.hasNetworkLocationServiceBuiltIn()) { + val intent = Intent(ACTION_NETWORK_LOCATION_SERVICE) + intent.`package` = context.packageName + intent.putExtra(EXTRA_PENDING_INTENT, coarsePendingIntent) + intent.putExtra(EXTRA_ENABLE, true) + intent.putExtra(EXTRA_INTERVAL_MILLIS, networkInterval) + intent.putExtra(EXTRA_LOW_POWER, requestManager.granularity <= GRANULARITY_COARSE) + intent.putExtra(EXTRA_WORK_SOURCE, requestManager.workSource) + context.startService(intent) + } val locationManager = context.getSystemService() ?: return - if (gpsInterval != Long.MAX_VALUE) { - try { - LocationManagerCompat.requestLocationUpdates( - locationManager, - SystemLocationManager.GPS_PROVIDER, - LocationRequestCompat.Builder(gpsInterval).build(), - gpsLocationListener, - context.mainLooper - ) - } catch (e: SecurityException) { - // Ignore - } - } else { - try { - LocationManagerCompat.requestLocationUpdates( - locationManager, - SystemLocationManager.GPS_PROVIDER, - LocationRequestCompat.Builder(LocationRequestCompat.PASSIVE_INTERVAL).setMinUpdateIntervalMillis(MAX_FINE_UPDATE_INTERVAL).build(), - gpsLocationListener, - context.mainLooper - ) - } catch (e: SecurityException) { - // Ignore + locationManager.requestSystemProviderUpdates(SystemLocationManager.GPS_PROVIDER, gpsInterval, gpsLocationListener) + if (!context.hasNetworkLocationServiceBuiltIn() && LocationManagerCompat.hasProvider(locationManager, SystemLocationManager.NETWORK_PROVIDER)) { + boundToSystemNetworkLocation = true + locationManager.requestSystemProviderUpdates(SystemLocationManager.NETWORK_PROVIDER, networkInterval, networkLocationListener) + } + } + + private fun SystemLocationManager.requestSystemProviderUpdates(provider: String, interval: Long, listener: LocationListenerCompat) { + try { + if (interval != Long.MAX_VALUE) { + LocationManagerCompat.requestLocationUpdates(this, provider, LocationRequestCompat.Builder(interval).build(), listener, context.mainLooper) + } else { + LocationManagerCompat.requestLocationUpdates(this, provider, LocationRequestCompat.Builder(LocationRequestCompat.PASSIVE_INTERVAL).setMinUpdateIntervalMillis(MAX_FINE_UPDATE_INTERVAL).build(), listener, context.mainLooper) } + } catch (e: SecurityException) { + // Ignore } } @@ -240,24 +243,9 @@ class LocationManager(private val context: Context, private val lifecycle: Lifec fun dump(writer: PrintWriter) { writer.println("Location availability: ${lastLocationCapsule.locationAvailability}") - writer.println( - "Last coarse location: ${ - postProcessor.process( - lastLocationCapsule.getLocation(GRANULARITY_COARSE, Long.MAX_VALUE), - GRANULARITY_COARSE, - true - ) - }" - ) - writer.println( - "Last fine location: ${ - postProcessor.process( - lastLocationCapsule.getLocation(GRANULARITY_FINE, Long.MAX_VALUE), - GRANULARITY_FINE, - true - ) - }" - ) + writer.println("Last coarse location: ${postProcessor.process(lastLocationCapsule.getLocation(GRANULARITY_COARSE, Long.MAX_VALUE), GRANULARITY_COARSE, true)}") + writer.println("Last fine location: ${postProcessor.process(lastLocationCapsule.getLocation(GRANULARITY_FINE, Long.MAX_VALUE), GRANULARITY_FINE, true)}") + writer.println("Network location: built-in=${context.hasNetworkLocationServiceBuiltIn()} system=$boundToSystemNetworkLocation") requestManager.dump(writer) deviceOrientationManager.dump(writer) } diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LocationManagerService.kt b/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LocationManagerService.kt index bfb311ead7..194cdbd711 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LocationManagerService.kt +++ b/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/LocationManagerService.kt @@ -5,16 +5,10 @@ package org.microg.gms.location.manager -import android.app.AlarmManager -import android.app.PendingIntent import android.content.Intent import android.location.Location -import android.net.Uri import android.os.Binder import android.os.Process -import android.os.SystemClock -import android.util.Log -import androidx.core.content.getSystemService import com.google.android.gms.common.api.CommonStatusCodes import com.google.android.gms.common.internal.ConnectionInfo import com.google.android.gms.common.internal.GetServiceRequest @@ -22,9 +16,7 @@ import com.google.android.gms.common.internal.IGmsCallbacks import org.microg.gms.BaseService import org.microg.gms.common.GmsService import org.microg.gms.common.PackageUtils -import org.microg.gms.location.FEATURES -import org.microg.gms.location.network.NetworkLocationService.Companion.ACTION_REPORT_LOCATION -import org.microg.gms.location.network.NetworkLocationService.Companion.EXTRA_LOCATION +import org.microg.gms.location.EXTRA_LOCATION import org.microg.gms.utils.IntentCacheManager import java.io.FileDescriptor import java.io.PrintWriter @@ -67,4 +59,8 @@ class LocationManagerService : BaseService(TAG, GmsService.LOCATION_MANAGER) { super.dump(fd, writer, args) locationManager.dump(writer) } + + companion object { + const val ACTION_REPORT_LOCATION = "org.microg.gms.location.manager.ACTION_REPORT_LOCATION" + } } \ No newline at end of file diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/extensions.kt b/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/extensions.kt index c790141684..bd518bd085 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/extensions.kt +++ b/play-services-location/core/src/main/kotlin/org/microg/gms/location/manager/extensions.kt @@ -18,6 +18,7 @@ import android.util.Log import androidx.annotation.RequiresApi import androidx.core.app.AppOpsManagerCompat import androidx.core.content.getSystemService +import com.google.android.gms.common.Feature import com.google.android.gms.location.* import com.google.android.gms.location.internal.ClientIdentity import com.google.android.gms.location.internal.IFusedLocationProviderCallback @@ -27,6 +28,25 @@ import org.microg.gms.utils.WorkSourceUtil const val TAG = "LocationManager" +internal val FEATURES = arrayOf( + Feature("name_ulr_private", 1), + Feature("driving_mode", 6), + Feature("name_sleep_segment_request", 1), + Feature("support_context_feature_id", 1), + Feature("get_current_location", 2), + Feature("get_last_activity_feature_id", 1), + Feature("get_last_location_with_request", 1), + Feature("set_mock_mode_with_callback", 1), + Feature("set_mock_location_with_callback", 1), + Feature("inject_location_with_callback", 1), + Feature("location_updates_with_callback", 1), + Feature("user_service_developer_features", 1), + Feature("user_service_location_accuracy", 1), + Feature("user_service_safety_and_emergency", 1), + + Feature("use_safe_parcelable_in_intents", 1) +) + fun ILocationListener.asCallback(): ILocationCallback { return object : ILocationCallback.Stub() { override fun onLocationResult(result: LocationResult) { diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/reporting/ReportingAndroidService.kt b/play-services-location/core/src/main/kotlin/org/microg/gms/location/reporting/ReportingAndroidService.kt index 68f260875b..2ee0d84ee2 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/reporting/ReportingAndroidService.kt +++ b/play-services-location/core/src/main/kotlin/org/microg/gms/location/reporting/ReportingAndroidService.kt @@ -12,7 +12,7 @@ import com.google.android.gms.common.internal.IGmsCallbacks import org.microg.gms.BaseService import org.microg.gms.common.GmsService import org.microg.gms.common.PackageUtils -import org.microg.gms.location.FEATURES +import org.microg.gms.location.manager.FEATURES class ReportingAndroidService : BaseService("GmsLocReportingSvc", GmsService.LOCATION_REPORTING) { @Throws(RemoteException::class) diff --git a/play-services-location/core/src/main/kotlin/org/microg/gms/location/ui/LocationPreferencesFragment.kt b/play-services-location/core/src/main/kotlin/org/microg/gms/location/ui/LocationPreferencesFragment.kt index 72e0e6ad0f..e6b10a2f15 100644 --- a/play-services-location/core/src/main/kotlin/org/microg/gms/location/ui/LocationPreferencesFragment.kt +++ b/play-services-location/core/src/main/kotlin/org/microg/gms/location/ui/LocationPreferencesFragment.kt @@ -9,7 +9,6 @@ import android.annotation.SuppressLint import android.os.Build import android.os.Bundle import androidx.core.os.bundleOf -import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.preference.Preference @@ -19,10 +18,10 @@ import androidx.preference.TwoStatePreference import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.microg.gms.location.LocationSettings -import org.microg.gms.location.core.BuildConfig import org.microg.gms.location.core.R +import org.microg.gms.location.hasMozillaLocationServiceSupport +import org.microg.gms.location.hasNetworkLocationServiceBuiltIn import org.microg.gms.location.manager.LocationAppsDatabase -import org.microg.gms.location.network.mozilla.MozillaLocationServiceClient import org.microg.gms.ui.AppIconPreference import org.microg.gms.ui.getApplicationInfoIfExists import org.microg.gms.ui.navigate @@ -31,6 +30,7 @@ class LocationPreferencesFragment : PreferenceFragmentCompat() { private lateinit var locationApps: PreferenceCategory private lateinit var locationAppsAll: Preference private lateinit var locationAppsNone: Preference + private lateinit var networkProviderCategory: PreferenceCategory private lateinit var wifiMls: TwoStatePreference private lateinit var wifiMoving: TwoStatePreference private lateinit var wifiLearning: TwoStatePreference @@ -45,13 +45,11 @@ class LocationPreferencesFragment : PreferenceFragmentCompat() { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.preferences_location) - } - @SuppressLint("RestrictedApi") - override fun onBindPreferences() { locationApps = preferenceScreen.findPreference("prefcat_location_apps") ?: locationApps locationAppsAll = preferenceScreen.findPreference("pref_location_apps_all") ?: locationAppsAll locationAppsNone = preferenceScreen.findPreference("pref_location_apps_none") ?: locationAppsNone + networkProviderCategory = preferenceScreen.findPreference("prefcat_location_network_provider") ?: networkProviderCategory wifiMls = preferenceScreen.findPreference("pref_location_wifi_mls_enabled") ?: wifiMls wifiMoving = preferenceScreen.findPreference("pref_location_wifi_moving_enabled") ?: wifiMoving wifiLearning = preferenceScreen.findPreference("pref_location_wifi_learning_enabled") ?: wifiLearning @@ -83,8 +81,9 @@ class LocationPreferencesFragment : PreferenceFragmentCompat() { true } - wifiMls.isVisible = MozillaLocationServiceClient.API_KEY != null - cellMls.isVisible = MozillaLocationServiceClient.API_KEY != null + networkProviderCategory.isVisible = requireContext().hasNetworkLocationServiceBuiltIn() + wifiMls.isVisible = requireContext().hasMozillaLocationServiceSupport() + cellMls.isVisible = requireContext().hasMozillaLocationServiceSupport() wifiLearning.isVisible = Build.VERSION.SDK_INT >= 17 cellLearning.isVisible = Build.VERSION.SDK_INT >= 17 } diff --git a/play-services-location/core/src/main/res/xml/preferences_location.xml b/play-services-location/core/src/main/res/xml/preferences_location.xml index 4467f0ef45..372071633f 100644 --- a/play-services-location/core/src/main/res/xml/preferences_location.xml +++ b/play-services-location/core/src/main/res/xml/preferences_location.xml @@ -19,41 +19,45 @@ android:title="@string/list_item_see_all" /> - - - - - - - + android:key="prefcat_location_network_provider" + android:layout="@layout/preference_category_no_label"> + + + + + + + + + \ No newline at end of file diff --git a/play-services-location/system-api/build.gradle b/play-services-location/core/system-api/build.gradle similarity index 100% rename from play-services-location/system-api/build.gradle rename to play-services-location/core/system-api/build.gradle diff --git a/play-services-location/system-api/src/main/AndroidManifest.xml b/play-services-location/core/system-api/src/main/AndroidManifest.xml similarity index 100% rename from play-services-location/system-api/src/main/AndroidManifest.xml rename to play-services-location/core/system-api/src/main/AndroidManifest.xml diff --git a/play-services-location/system-api/src/main/java/android/location/GeocoderParams.java b/play-services-location/core/system-api/src/main/java/android/location/GeocoderParams.java similarity index 100% rename from play-services-location/system-api/src/main/java/android/location/GeocoderParams.java rename to play-services-location/core/system-api/src/main/java/android/location/GeocoderParams.java diff --git a/play-services-location/system-api/src/main/java/android/location/Geofence.java b/play-services-location/core/system-api/src/main/java/android/location/Geofence.java similarity index 100% rename from play-services-location/system-api/src/main/java/android/location/Geofence.java rename to play-services-location/core/system-api/src/main/java/android/location/Geofence.java diff --git a/play-services-location/system-api/src/main/java/android/location/Location.java b/play-services-location/core/system-api/src/main/java/android/location/Location.java similarity index 100% rename from play-services-location/system-api/src/main/java/android/location/Location.java rename to play-services-location/core/system-api/src/main/java/android/location/Location.java diff --git a/play-services-location/system-api/src/main/java/android/location/LocationManager.java b/play-services-location/core/system-api/src/main/java/android/location/LocationManager.java similarity index 100% rename from play-services-location/system-api/src/main/java/android/location/LocationManager.java rename to play-services-location/core/system-api/src/main/java/android/location/LocationManager.java diff --git a/play-services-location/system-api/src/main/java/android/location/LocationRequest.java b/play-services-location/core/system-api/src/main/java/android/location/LocationRequest.java similarity index 100% rename from play-services-location/system-api/src/main/java/android/location/LocationRequest.java rename to play-services-location/core/system-api/src/main/java/android/location/LocationRequest.java diff --git a/play-services-location/system-api/src/main/java/android/net/wifi/WifiScanner.java b/play-services-location/core/system-api/src/main/java/android/net/wifi/WifiScanner.java similarity index 100% rename from play-services-location/system-api/src/main/java/android/net/wifi/WifiScanner.java rename to play-services-location/core/system-api/src/main/java/android/net/wifi/WifiScanner.java diff --git a/play-services-location/system-api/src/main/java/com/android/internal/location/ProviderProperties.java b/play-services-location/core/system-api/src/main/java/com/android/internal/location/ProviderProperties.java similarity index 100% rename from play-services-location/system-api/src/main/java/com/android/internal/location/ProviderProperties.java rename to play-services-location/core/system-api/src/main/java/com/android/internal/location/ProviderProperties.java diff --git a/play-services-location/system-api/src/main/java/com/android/internal/location/ProviderRequest.java b/play-services-location/core/system-api/src/main/java/com/android/internal/location/ProviderRequest.java similarity index 100% rename from play-services-location/system-api/src/main/java/com/android/internal/location/ProviderRequest.java rename to play-services-location/core/system-api/src/main/java/com/android/internal/location/ProviderRequest.java diff --git a/play-services-location/system-api/src/main/java/com/android/location/provider/GeocodeProvider.java b/play-services-location/core/system-api/src/main/java/com/android/location/provider/GeocodeProvider.java similarity index 100% rename from play-services-location/system-api/src/main/java/com/android/location/provider/GeocodeProvider.java rename to play-services-location/core/system-api/src/main/java/com/android/location/provider/GeocodeProvider.java diff --git a/play-services-location/system-api/src/main/java/com/android/location/provider/LocationProvider.java b/play-services-location/core/system-api/src/main/java/com/android/location/provider/LocationProvider.java similarity index 100% rename from play-services-location/system-api/src/main/java/com/android/location/provider/LocationProvider.java rename to play-services-location/core/system-api/src/main/java/com/android/location/provider/LocationProvider.java diff --git a/play-services-location/system-api/src/main/java/com/android/location/provider/LocationProviderBase.java b/play-services-location/core/system-api/src/main/java/com/android/location/provider/LocationProviderBase.java similarity index 100% rename from play-services-location/system-api/src/main/java/com/android/location/provider/LocationProviderBase.java rename to play-services-location/core/system-api/src/main/java/com/android/location/provider/LocationProviderBase.java diff --git a/play-services-location/system-api/src/main/java/com/android/location/provider/LocationRequestUnbundled.java b/play-services-location/core/system-api/src/main/java/com/android/location/provider/LocationRequestUnbundled.java similarity index 100% rename from play-services-location/system-api/src/main/java/com/android/location/provider/LocationRequestUnbundled.java rename to play-services-location/core/system-api/src/main/java/com/android/location/provider/LocationRequestUnbundled.java diff --git a/play-services-location/system-api/src/main/java/com/android/location/provider/ProviderPropertiesUnbundled.java b/play-services-location/core/system-api/src/main/java/com/android/location/provider/ProviderPropertiesUnbundled.java similarity index 100% rename from play-services-location/system-api/src/main/java/com/android/location/provider/ProviderPropertiesUnbundled.java rename to play-services-location/core/system-api/src/main/java/com/android/location/provider/ProviderPropertiesUnbundled.java diff --git a/play-services-location/system-api/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java b/play-services-location/core/system-api/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java similarity index 100% rename from play-services-location/system-api/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java rename to play-services-location/core/system-api/src/main/java/com/android/location/provider/ProviderRequestUnbundled.java diff --git a/settings.gradle b/settings.gradle index e50234f82a..2edca60727 100644 --- a/settings.gradle +++ b/settings.gradle @@ -68,7 +68,9 @@ sublude ':play-services-droidguard:core' sublude ':play-services-fido:core' sublude ':play-services-gmscompliance:core' sublude ':play-services-location:core' -sublude ':play-services-location:system-api' +sublude ':play-services-location:core:base' +sublude ':play-services-location:core:provider' +sublude ':play-services-location:core:system-api' include ':play-services-maps-core-mapbox' include ':play-services-maps-core-vtm' include ':play-services-maps-core-vtm:vtm-microg-theme'