Skip to content

Enter api key / build with circle CI #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ dependencies {
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
lintOptions {
abortOnError false
}
}

if (file('user.gradle').exists()) {
Expand Down
190 changes: 190 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
machine:
timezone:
Europe/Vienna
java:
version: oraclejdk8
environment:
###### custom 1 ######
ZEMU_: "appemu23"
EMU_: "appemu21"
XEMU_: "appemu10"
Zsdpath: "/sdcard"
sdpath: "/storage/sdcard"
Xsdpath: "/mnt/sdcard"
###### custom 1 ######

###### custom 2 ######
XGRADLE_HOME: ~/g/gradle-2.10
XPATH: ~/g/gradle-2.10/bin:$PATH
GRADLE_CUSTOM_VERSION: N
###### custom 2 ######

###### custom 3 ######
CLASS_P: org.microg.nlp.backend.nominatim
START_INTENT_P: .SettingsActivity
# switch glibc to a memory conserving mode
MALLOC_ARENA_MAX: "2"
###### custom 3 ######

###############################
# 0 -> no
# 1 -> C
# 2 -> Java
COVERITY_BUILD_: 0
COV_PROJ: zoff99%2Fxyz
###############################

ANDROID_HOME: /usr/local/android-sdk-linux
ANDROID_SDK: /usr/local/android-sdk-linux/
_SDK_: /usr/local/android-sdk-linux/
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx1000m -XX:+HeapDumpOnOutOfMemoryError"'
dependencies:
cache_directories:
- ~/.android
- ~/.gradle
override:
- echo "dummy"
pre:
- sudo apt-get update > /dev/null 2> /dev/null
- sudo apt-get install xvfb > /dev/null 2> /dev/null
- sudo apt-get install xdotool > /dev/null 2> /dev/null
- sudo apt-get install telnet > /dev/null 2> /dev/null
- sudo apt-get install x11-utils > /dev/null 2> /dev/null
- sudo apt-get install xvkbd > /dev/null 2> /dev/null
- sudo apt-get install qrencode > /dev/null 2> /dev/null
- sudo apt-get install zip > /dev/null 2> /dev/null
- sudo apt-get install bc > /dev/null 2> /dev/null

- gradle -v # display gradle version
- if [ "$GRADLE_CUSTOM_VERSION""x" == "1x" ]; then cd ~ ; wget https://services.gradle.org/distributions/gradle-2.10-bin.zip ; fi
- if [ "$GRADLE_CUSTOM_VERSION""x" == "1x" ]; then mkdir ~/g ; cd ~/g ; unzip ~/gradle-2.10-bin.zip ; fi
- gradle -v # display gradle version

- echo y | android update sdk --no-ui --all --filter "tools"
- android list sdk --all | grep -i tools
- android list sdk --all --extended

- echo y | android update sdk --no-ui --all --filter build-tools-22.0.0 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter build-tools-23.0.1 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter build-tools-23.0.2 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter build-tools-23.0.3 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter build-tools-24.0.0 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter android-21 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter android-22 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter android-23 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter android-24 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter platform-tools > /dev/null 2> /dev/null

- echo y | android update sdk --no-ui --all --filter extra-android-m2repository > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter extra-google-m2repository > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter extra-android-support > /dev/null 2> /dev/null

# - echo y | android update sdk --no-ui --all --filter extra-google-google_play_services > /dev/null 2> /dev/null
# - echo y | android update sdk --no-ui --all --filter extra-google-google_play_services_froyo > /dev/null 2> /dev/null
# - echo y | android update sdk --no-ui --all --filter extra-google-gcm > /dev/null 2> /dev/null

#- echo y | android update sdk --no-ui --all --filter platform-tools-preview > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter sys-img-armeabi-v7a-android-23 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter sys-img-armeabi-v7a-android-24 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter sys-img-armeabi-v7a-addon-google_apis-google-23 > /dev/null 2> /dev/null
- echo y | android update sdk --no-ui --all --filter addon-google_apis-google-23 > /dev/null 2> /dev/null

- if [ "$COVERITY_BUILD_""x" != "0x" ]; then mkdir ~/cov_scan/ && wget https://scan.coverity.com/download/linux-64 --post-data "token=$COVERITY_TOKEN&project=$COV_PROJ" -O ~/cov_scan/coverity_tool.tgz && wget 'http://www.catb.org/~esr/coverity-submit/coverity-submit-1.17.tar.gz' -O ~/cov_scan/coverity-submit.tar.gz && cd ~/cov_scan/ && tar -xzvf coverity_tool.tgz ; fi

- pwd ; ls -al

###### custom ######
- sed -i -e 's,textReport .*,textReport true,' build.gradle ; exit 0
###### custom ######

- ./gradlew lint --info
- ./gradlew assembleDebug --stacktrace --info --no-daemon

- ls -al build/outputs/apk/ ; exit 0
- find . -name '*.apk' ; exit 0

- if [ "$COVERITY_BUILD_""x" != "0x" ]; then ls -al build/cov-int/ ; exit 0 ; fi
- if [ "$COVERITY_BUILD_""x" != "0x" ]; then cp -v build/cov-int/build-log.txt $CIRCLE_ARTIFACTS/ ; exit 0 ; fi
- if [ "$COVERITY_BUILD_""x" != "0x" ]; then cd build/ ; tar -czvf $CIRCLE_ARTIFACTS/covint.tar.gz cov-int ; exit 0 ; fi

# --- copy apk file to generic location ---
- mkdir -p ./app/build/outputs/apk/
- if [ ! -e ./app/build/outputs/apk/app-debug-unaligned.apk ]; then cp -v `find ./build/outputs/apk/ -name '*.apk' 2> /dev/null | tail -1 2> /dev/null` ./app/build/outputs/apk/app-debug-unaligned.apk ; fi
# --- copy apk file to generic location ---

- zip -d app/build/outputs/apk/app-debug-unaligned.apk META-INF/\* # remove signature !!
- cp -av app/build/outputs/apk/app-debug-unaligned.apk ~/app.apk ;
cd ~/ ;
echo xxxxxxrm -f ~/.android/debug.keystore ;
ls -al ~/.android/debug.keystore ;
if [ ! -f ~/.android/debug.keystore ]; then echo "*** generating new signer key ***" ;
echo "*** generating new signer key ***";
echo "*** generating new signer key ***";
keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -keyalg RSA -keysize 2048 -validity 10000 -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US" ;
fi ;
ls -al ~/ ;
jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android -sigalg SHA1withRSA -digestalg SHA1 -sigfile CERT -signedjar app-signed.apk app.apk androiddebugkey ;
ls -al ~/ ;
$_SDK_/build-tools/23.0.3/zipalign -v 4 app-signed.apk app-signed-aligned.apk ;
ls -al ~/ ;
pwd ;
ls -al ;
cp -av app-signed-aligned.apk $CIRCLE_ARTIFACTS/${CIRCLE_PROJECT_REPONAME}.apk || exit 1

## also make apk files with different names for each build (for individual downloads)
- cp -av $CIRCLE_ARTIFACTS/${CIRCLE_PROJECT_REPONAME}.apk $CIRCLE_ARTIFACTS/${CIRCLE_PROJECT_REPONAME}_circleci_$CIRCLE_SHA1.apk ; exit 0
## qr code to scan with your phone to directly download the apk file (for convenience)
- qrencode -o $CIRCLE_ARTIFACTS/QR_apk.png 'https://circle-artifacts.com/gh/'${CIRCLE_PROJECT_USERNAME}'/'${CIRCLE_PROJECT_REPONAME}'/'${CIRCLE_BUILD_NUM}'/artifacts/'${CIRCLE_NODE_INDEX}'/tmp/'`basename $CIRCLE_ARTIFACTS`'/'"${CIRCLE_PROJECT_REPONAME}_circleci_$CIRCLE_SHA1.apk" ; exit 0
## qr code to go directly to the aritfacts (to scan with phone)
- qrencode -o $CIRCLE_ARTIFACTS/QR_artifacts.png 'https://circleci.com/gh/'${CIRCLE_PROJECT_USERNAME}'/'${CIRCLE_PROJECT_REPONAME}'/'${CIRCLE_BUILD_NUM}'#artifacts' ; exit 0

test:
pre:
- mksdcard -l e 180M sdcard.img
- echo 'mtools_skip_check=1' > ~/.mtoolsrc
- android list targets
#
- if [ "$EMU_" == "appemu23" ]; then echo "no" | android create avd -n appemu23 -f -t android-23 --abi default/armeabi-v7a --skin "WXGA720" ; fi
- if [ "$EMU_" == "appemu23" ]; then cat ~/.android/avd/appemu23.avd/config.ini ; fi
#
- if [ "$EMU_" == "appemu21" ]; then echo "no" | android create avd -n appemu21 -f -t android-21 --abi default/armeabi-v7a --skin "WXGA720" ; fi
- if [ "$EMU_" == "appemu21" ]; then cat ~/.android/avd/appemu21.avd/config.ini ; fi
#
- if [ "$EMU_" == "appemu10" ]; then echo "no" | android create avd -n appemu10 -f -t android-10 --abi default/armeabi --skin "WQVGA432" ; fi
- if [ "$EMU_" == "appemu10" ]; then cat ~/.android/avd/appemu10.avd/config.ini ; fi
#
- echo "$EMU_"
- echo "$sdpath"
override:
- emulator -avd "$EMU_" -sdcard sdcard.img -no-audio:
background: true
parallel: true
- circle-android wait-for-boot

- sleep 210 # let the emulator settle down first

- adb shell input keyevent 82 # remove lock screen on emulator
- sleep 10
- import -window root $CIRCLE_ARTIFACTS/capture_emulator_running.png

- fb-adb shell "cat /proc/meminfo" ; exit 0

- adb shell ls -al / ; exit 0
- adb shell ls -al /storage/ ; exit 0
- adb shell ls -al /sdcard/ ; exit 0

- adb install ~/app-signed-aligned.apk

- adb logcat -v time > $CIRCLE_ARTIFACTS/adb_out.txt 2>&1 :
background: true
- sleep 60 # let the emulator settle down first

- fb-adb shell am start -n $CLASS_P/$START_INTENT_P
- sleep 60
- sleep 120 # wait to be sure the app has started fully

- died_count=`cat $CIRCLE_ARTIFACTS/adb_out.txt|grep 'Process. '"$CLASS_P"', PID.'|wc -l|tr -d ' '` ; if [ $died_count -gt 0 ]; then echo "app crashed"; exit 1; fi

- import -window root $CIRCLE_ARTIFACTS/capture_app_running.png # get proof that the app is running
- adb shell screencap -p | sed 's/\r$//' > $CIRCLE_ARTIFACTS/capture_app_running_2.png

25 changes: 18 additions & 7 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="1.1.1"
android:versionCode="10101"
package="org.microg.nlp.backend.nominatim">
android:versionName="1.1.1"
android:versionCode="10101"
package="org.microg.nlp.backend.nominatim">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="22"/>
android:minSdkVersion="11"
android:targetSdkVersion="22" />

<application
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
Expand All @@ -17,8 +18,18 @@
android:name=".BackendService"
android:label="@string/backend_name">
<intent-filter>
<action android:name="org.microg.nlp.GEOCODER_BACKEND"/>
<action android:name="org.microg.nlp.GEOCODER_BACKEND" />
</intent-filter>
<meta-data
android:name="org.microg.nlp.BACKEND_SETTINGS_ACTIVITY"
android:value="org.microg.nlp.backend.nominatim.SettingsActivity" />
</service>

<activity android:name=".SettingsActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>

</manifest>
22 changes: 16 additions & 6 deletions src/main/java/org/microg/nlp/backend/nominatim/BackendService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.microg.nlp.backend.nominatim;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Address;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;

import org.json.JSONArray;
Expand All @@ -28,11 +30,11 @@ public class BackendService extends GeocoderBackendService {
private static final String SERVICE_URL_MAPQUEST = "http://open.mapquestapi.com/nominatim/v1/";
private static final String SERVICE_URL_OSM = " http://nominatim.openstreetmap.org/";
private static final String REVERSE_GEOCODE_URL =
"%sreverse?format=json&accept-language=%s&lat=%f&lon=%f";
"%sreverse?format=json&key=%s&accept-language=%s&lat=%f&lon=%f";
private static final String SEARCH_GEOCODE_URL =
"%ssearch?format=json&accept-language=%s&addressdetails=1&bounded=1&q=%s&limit=%d";
"%ssearch?format=json&key=%s&accept-language=%s&addressdetails=1&bounded=1&q=%s&limit=%d";
private static final String SEARCH_GEOCODE_WITH_BOX_URL =
"%ssearch?format=json&accept-language=%s&addressdetails=1&bounded=1&q=%s&limit=%d" +
"%ssearch?format=json&key=%s&accept-language=%s&addressdetails=1&bounded=1&q=%s&limit=%d" +
"&viewbox=%f,%f,%f,%f";
private static final String WIRE_LATITUDE = "lat";
private static final String WIRE_LONGITUDE = "lon";
Expand All @@ -51,8 +53,12 @@ public class BackendService extends GeocoderBackendService {
@Override
protected List<Address> getFromLocation(double latitude, double longitude, int maxResults,
String locale) {

SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String mapquestApiKey = SP.getString("api_preference", "NA");

String url = String.format(Locale.US, REVERSE_GEOCODE_URL, SERVICE_URL_MAPQUEST,
locale.split("_")[0], latitude, longitude);
mapquestApiKey, locale.split("_")[0], latitude, longitude);
try {
JSONObject result = new JSONObject(new AsyncGetRequest(this,
url).asyncStart().retrieveString());
Expand Down Expand Up @@ -84,15 +90,19 @@ private static Locale localeFromLocaleString(String localeString) {
protected List<Address> getFromLocationName(String locationName, int maxResults,
double lowerLeftLatitude, double lowerLeftLongitude, double upperRightLatitude,
double upperRightLongitude, String locale) {

SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String mapquestApiKey = SP.getString("api_preference", "NA");

String query = Uri.encode(locationName);
String url;
if (lowerLeftLatitude == 0 && lowerLeftLongitude == 0 && upperRightLatitude == 0 &&
upperRightLongitude == 0) {
url = String.format(Locale.US, SEARCH_GEOCODE_URL, SERVICE_URL_MAPQUEST,
locale.split("_")[0], query, maxResults);
mapquestApiKey, locale.split("_")[0], query, maxResults);
} else {
url = String.format(Locale.US, SEARCH_GEOCODE_WITH_BOX_URL, SERVICE_URL_MAPQUEST,
locale.split("_")[0], query, maxResults, lowerLeftLongitude,
mapquestApiKey, locale.split("_")[0], query, maxResults, lowerLeftLongitude,
upperRightLatitude, upperRightLongitude, lowerLeftLatitude);
}
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.microg.nlp.backend.nominatim;

import android.content.SharedPreferences;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.os.Bundle;

public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new PrefsFragment()).commit();

}

public static class PrefsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
setSummaries();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updatePreference(findPreference(key), key);
}

private void setSummaries(){

final SharedPreferences sh = getPreferenceManager().getSharedPreferences() ;

Preference stylePref = findPreference("api_preference");
stylePref.setSummary(sh.getString("api_preference", ""));

}
private void updatePreference(Preference preference, String key) {
if (preference == null) return;
if (preference instanceof ListPreference) {
ListPreference listPreference = (ListPreference) preference;
listPreference.setSummary(listPreference.getEntry());
return;
}
SharedPreferences sharedPrefs = getPreferenceManager().getSharedPreferences();
preference.setSummary(sharedPrefs.getString(key, "Default"));
}
}

}
7 changes: 6 additions & 1 deletion src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">NominatimGeocoderBackend</string>
<string name="app_name">Nominatim Geocoder Backend</string>
<string name="backend_name">Nominatim</string>

<string name="server_access">MapQuest Server Access</string>
<string name="api_title">MapQuest Developer API Key</string>
<string name="api_summary">MapQuest Developer API Key</string>
<string name="api_dialog_title">Enter your MapQuest developer API key.</string>
</resources>
16 changes: 16 additions & 0 deletions src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<PreferenceCategory
android:title="@string/server_access">

<EditTextPreference
android:key="api_preference"
android:title="@string/api_title"
android:summary=""
android:dialogTitle="@string/api_dialog_title"
android:defaultValue=""/>

</PreferenceCategory>

</PreferenceScreen>