forked from microg/GmsCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Location: Move network location provider to independent module
- Loading branch information
Showing
69 changed files
with
417 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
play-services-location/core/base/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ SPDX-FileCopyrightText: 2023 microG Project Team | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
<manifest package="org.microg.gms.location.base" /> |
File renamed without changes.
95 changes: 95 additions & 0 deletions
95
play-services-location/core/base/src/main/kotlin/org/microg/gms/location/extensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
play-services-location/core/provider/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
~ SPDX-FileCopyrightText: 2023 microG Project Team | ||
~ SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
<manifest xmlns:tools="http://schemas.android.com/tools" | ||
package="org.microg.gms.location.provider" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> | ||
<uses-permission android:name="android.permission.BODY_SENSORS" /> | ||
|
||
<uses-permission | ||
android:name="android.permission.LOCATION_HARDWARE" | ||
tools:ignore="ProtectedPermissions" /> | ||
<uses-permission | ||
android:name="android.permission.INSTALL_LOCATION_PROVIDER" | ||
tools:ignore="ProtectedPermissions" /> | ||
<uses-permission | ||
android:name="android.permission.NETWORK_SCAN" | ||
tools:ignore="ProtectedPermissions" /> | ||
<uses-permission | ||
android:name="android.permission.MODIFY_PHONE_STATE" | ||
tools:ignore="ProtectedPermissions" /> | ||
|
||
<application> | ||
<uses-library android:name="com.android.location.provider" /> | ||
|
||
<service | ||
android:name="org.microg.gms.location.network.NetworkLocationService" | ||
android:exported="false"> | ||
<intent-filter> | ||
<action android:name="org.microg.gms.location.network.ACTION_NETWORK_LOCATION_SERVICE" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
</intent-filter> | ||
</service> | ||
<service | ||
android:name="org.microg.gms.location.provider.NetworkLocationProviderService" | ||
android:exported="true" | ||
android:permission="android.permission.WRITE_SECURE_SETTINGS"> | ||
<intent-filter> | ||
<action android:name="com.android.location.service.v2.NetworkLocationProvider" /> | ||
<action android:name="com.android.location.service.v3.NetworkLocationProvider" /> | ||
</intent-filter> | ||
<meta-data | ||
android:name="serviceVersion" | ||
android:value="2" /> | ||
</service> | ||
<service | ||
android:name="org.microg.gms.location.provider.GeocodeProviderService" | ||
android:exported="true" | ||
android:permission="android.permission.WRITE_SECURE_SETTINGS"> | ||
<intent-filter> | ||
<action android:name="com.android.location.service.GeocodeProvider" /> | ||
<action android:name="com.google.android.location.GeocodeProvider" /> | ||
</intent-filter> | ||
<meta-data | ||
android:name="serviceVersion" | ||
android:value="2" /> | ||
</service> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.