Add location system service
This commit is contained in:
parent
8e1a752024
commit
b39d3712ba
65
geocode-v1/build.gradle
Normal file
65
geocode-v1/build.gradle
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2019, microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
android {
|
||||
compileSdkVersion androidCompileSdk
|
||||
buildToolsVersion "$androidBuildVersionTools"
|
||||
|
||||
defaultConfig {
|
||||
versionName version
|
||||
minSdkVersion androidMinSdk
|
||||
targetSdkVersion androidTargetSdk
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':client')
|
||||
compileOnly project(':compat')
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
publishing {
|
||||
publications {
|
||||
release(MavenPublication) {
|
||||
pom {
|
||||
name = 'UnifiedNlp Geocode v1'
|
||||
description = 'UnifiedNlp service to implement Geocode API v1'
|
||||
url = 'https://github.com/microg/UnifiedNlp'
|
||||
licenses {
|
||||
license {
|
||||
name = 'The Apache Software License, Version 2.0'
|
||||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id = 'microg'
|
||||
name = 'microG Team'
|
||||
}
|
||||
developer {
|
||||
id = 'mar-v-in'
|
||||
name = 'Marvin W.'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url = 'https://github.com/microg/UnifiedNlp'
|
||||
connection = 'scm:git:https://github.com/microg/UnifiedNlp.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/microg/UnifiedNlp.git'
|
||||
}
|
||||
}
|
||||
|
||||
from components.release
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
47
geocode-v1/src/main/AndroidManifest.xml
Normal file
47
geocode-v1/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (C) 2013-2019 microG Project Team
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="org.microg.nlp.geocode.v1">
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.INSTALL_LOCATION_PROVIDER"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application>
|
||||
<uses-library android:name="com.android.location.provider" />
|
||||
|
||||
<service
|
||||
android:name=".GeocodeService"
|
||||
android:exported="true"
|
||||
android:permission="android.permission.INTERNET"
|
||||
android:process=":geocservice">
|
||||
<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" />
|
||||
<meta-data
|
||||
android:name="serviceIsMultiuser"
|
||||
android:value="false" />
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,54 @@
|
|||
package org.microg.nlp.geocode.v1;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Address;
|
||||
import android.location.GeocoderParams;
|
||||
import android.util.Log;
|
||||
|
||||
import org.microg.nlp.client.UnifiedLocationClient;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GeocodeProvider extends com.android.location.provider.GeocodeProvider {
|
||||
private static final String TAG = "UGeocode";
|
||||
private Context context;
|
||||
private static final long TIMEOUT = 10000;
|
||||
|
||||
public GeocodeProvider(Context context) {
|
||||
this.context = context;
|
||||
UnifiedLocationClient.get(context).ref();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
UnifiedLocationClient.get(context).unref();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onGetFromLocation(double latitude, double longitude, int maxResults, GeocoderParams params, List<Address> addrs) {
|
||||
try {
|
||||
return handleResult(addrs, UnifiedLocationClient.get(context).getFromLocationSync(latitude, longitude, maxResults, params.getLocale().toString(), TIMEOUT));
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onGetFromLocationName(String locationName, double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude, double upperRightLongitude, int maxResults, GeocoderParams params, List<Address> addrs) {
|
||||
try {
|
||||
return handleResult(addrs, UnifiedLocationClient.get(context).getFromLocationNameSync(locationName, maxResults, lowerLeftLatitude, lowerLeftLongitude, upperRightLatitude, upperRightLongitude, params.getLocale().toString(), TIMEOUT));
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, e);
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private String handleResult(List<Address> realResult, List<Address> fuserResult) {
|
||||
if (fuserResult.isEmpty()) {
|
||||
return "no result";
|
||||
} else {
|
||||
realResult.addAll(fuserResult);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.microg.nlp.geocode.v1;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
public class GeocodeService extends Service {
|
||||
private static final String TAG = "UnifiedGeocode";
|
||||
private GeocodeProvider provider;
|
||||
|
||||
@Override
|
||||
public synchronized IBinder onBind(Intent intent) {
|
||||
Log.d(TAG, "onBind: "+intent);
|
||||
if (provider == null) {
|
||||
provider = new GeocodeProvider(this);
|
||||
}
|
||||
return provider.getBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean onUnbind(Intent intent) {
|
||||
if (provider != null) {
|
||||
provider.onDisable();
|
||||
}
|
||||
return super.onUnbind(intent);
|
||||
}
|
||||
}
|
65
location-v2/build.gradle
Normal file
65
location-v2/build.gradle
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2019, microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
android {
|
||||
compileSdkVersion androidCompileSdk
|
||||
buildToolsVersion "$androidBuildVersionTools"
|
||||
|
||||
defaultConfig {
|
||||
versionName version
|
||||
minSdkVersion androidMinSdk
|
||||
targetSdkVersion androidTargetSdk
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':client')
|
||||
compileOnly project(':compat')
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
publishing {
|
||||
publications {
|
||||
release(MavenPublication) {
|
||||
pom {
|
||||
name = 'UnifiedNlp Location v2'
|
||||
description = 'UnifiedNlp service to implement Location API v2'
|
||||
url = 'https://github.com/microg/UnifiedNlp'
|
||||
licenses {
|
||||
license {
|
||||
name = 'The Apache Software License, Version 2.0'
|
||||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id = 'microg'
|
||||
name = 'microG Team'
|
||||
}
|
||||
developer {
|
||||
id = 'mar-v-in'
|
||||
name = 'Marvin W.'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url = 'https://github.com/microg/UnifiedNlp'
|
||||
connection = 'scm:git:https://github.com/microg/UnifiedNlp.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/microg/UnifiedNlp.git'
|
||||
}
|
||||
}
|
||||
|
||||
from components.release
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
location-v2/src/main/AndroidManifest.xml
Normal file
48
location-v2/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (C) 2013-2019 microG Project Team
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="org.microg.nlp.location.v2">
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.INSTALL_LOCATION_PROVIDER"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application>
|
||||
<uses-library android:name="com.android.location.provider" />
|
||||
|
||||
<service
|
||||
android:name=".LocationService"
|
||||
android:exported="true"
|
||||
android:process=":locservice"
|
||||
android:permission="android.permission.ACCESS_COARSE_LOCATION">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.location.service.v2.NetworkLocationProvider" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="serviceVersion"
|
||||
android:value="2" />
|
||||
<meta-data
|
||||
android:name="serviceIsMultiuser"
|
||||
android:value="false" />
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,73 @@
|
|||
package org.microg.nlp.location.v2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.location.Criteria;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.WorkSource;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.location.provider.LocationProviderBase;
|
||||
import com.android.location.provider.ProviderPropertiesUnbundled;
|
||||
import com.android.location.provider.ProviderRequestUnbundled;
|
||||
|
||||
import org.microg.nlp.client.UnifiedLocationClient;
|
||||
|
||||
import static android.location.LocationProvider.AVAILABLE;
|
||||
|
||||
public class LocationProvider extends LocationProviderBase implements UnifiedLocationClient.LocationListener {
|
||||
private static final long FASTEST_REFRESH_INTERVAL = 30000;
|
||||
private static final String TAG = "ULocation";
|
||||
private Context context;
|
||||
|
||||
public LocationProvider(Context context) {
|
||||
super(TAG, ProviderPropertiesUnbundled.create(false, false, false, false, true, true, true, Criteria.POWER_LOW, Criteria.ACCURACY_COARSE));
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
UnifiedLocationClient.get(context).ref();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
UnifiedLocationClient.get(context).unref();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetRequest(ProviderRequestUnbundled requests, WorkSource source) {
|
||||
Log.v(TAG, "onSetRequest: " + requests + " by " + source);
|
||||
|
||||
long autoTime = Math.max(requests.getInterval(), FASTEST_REFRESH_INTERVAL);
|
||||
boolean autoUpdate = requests.getReportLocation();
|
||||
|
||||
Log.v(TAG, "using autoUpdate=" + autoUpdate + " autoTime=" + autoTime);
|
||||
|
||||
if (autoUpdate) {
|
||||
UnifiedLocationClient.get(context).requestLocationUpdates(this, autoTime);
|
||||
} else {
|
||||
UnifiedLocationClient.get(context).removeLocationUpdates(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void unsetRequest() {
|
||||
UnifiedLocationClient.get(context).removeLocationUpdates(this);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int onGetStatus(Bundle extras) {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long onGetStatusUpdateTime() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocation(Location location) {
|
||||
reportLocation(location);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.microg.nlp.location.v2;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
public class LocationService extends Service {
|
||||
private static final String TAG = "ULocation";
|
||||
private LocationProvider provider;
|
||||
|
||||
@Override
|
||||
public synchronized IBinder onBind(Intent intent) {
|
||||
Log.d(TAG, "onBind: "+intent);
|
||||
if (provider == null) {
|
||||
provider = new LocationProvider(this);
|
||||
}
|
||||
return provider.getBinder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean onUnbind(Intent intent) {
|
||||
if (provider != null) {
|
||||
provider.unsetRequest();
|
||||
}
|
||||
return super.onUnbind(intent);
|
||||
}
|
||||
}
|
64
location-v3/build.gradle
Normal file
64
location-v3/build.gradle
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2019, microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'maven-publish'
|
||||
|
||||
android {
|
||||
compileSdkVersion androidCompileSdk
|
||||
buildToolsVersion "$androidBuildVersionTools"
|
||||
|
||||
defaultConfig {
|
||||
versionName version
|
||||
minSdkVersion androidMinSdk
|
||||
targetSdkVersion androidTargetSdk
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':location-v2')
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
publishing {
|
||||
publications {
|
||||
release(MavenPublication) {
|
||||
pom {
|
||||
name = 'UnifiedNlp Location v3'
|
||||
description = 'UnifiedNlp service to implement Location API v3'
|
||||
url = 'https://github.com/microg/UnifiedNlp'
|
||||
licenses {
|
||||
license {
|
||||
name = 'The Apache Software License, Version 2.0'
|
||||
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||
}
|
||||
}
|
||||
developers {
|
||||
developer {
|
||||
id = 'microg'
|
||||
name = 'microG Team'
|
||||
}
|
||||
developer {
|
||||
id = 'mar-v-in'
|
||||
name = 'Marvin W.'
|
||||
}
|
||||
}
|
||||
scm {
|
||||
url = 'https://github.com/microg/UnifiedNlp'
|
||||
connection = 'scm:git:https://github.com/microg/UnifiedNlp.git'
|
||||
developerConnection = 'scm:git:ssh://github.com/microg/UnifiedNlp.git'
|
||||
}
|
||||
}
|
||||
|
||||
from components.release
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
48
location-v3/src/main/AndroidManifest.xml
Normal file
48
location-v3/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (C) 2013-2019 microG Project Team
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="org.microg.nlp.location.v3">
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.INSTALL_LOCATION_PROVIDER"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application>
|
||||
<uses-library android:name="com.android.location.provider" />
|
||||
|
||||
<service
|
||||
android:name=".LocationService"
|
||||
android:exported="true"
|
||||
android:process=":locservice"
|
||||
android:permission="android.permission.ACCESS_COARSE_LOCATION">
|
||||
<intent-filter>
|
||||
<action android:name="com.android.location.service.v3.NetworkLocationProvider" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="serviceVersion"
|
||||
android:value="3" />
|
||||
<meta-data
|
||||
android:name="serviceIsMultiuser"
|
||||
android:value="false" />
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,4 @@
|
|||
package org.microg.nlp.location.v3;
|
||||
|
||||
public class LocationService extends org.microg.nlp.location.v2.LocationService {
|
||||
}
|
Loading…
Reference in a new issue