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

Verified Commit b39d3712 authored by Marvin W.'s avatar Marvin W. 🐿️
Browse files

Add location system service

parent 8e1a7520
Loading
Loading
Loading
Loading
+65 −0
Original line number Diff line number Diff line
/*
 * 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 −0
Original line number Diff line number Diff line
<?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>
+54 −0
Original line number Diff line number Diff line
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;
        }
    }
}
+28 −0
Original line number Diff line number Diff line
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 −0
Original line number Diff line number Diff line
/*
 * 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
            }
        }
    }
}
Loading