Skip to content

Commit

Permalink
Update build tools + versioning scheme, update sub library, add UI fo…
Browse files Browse the repository at this point in the history
…r Self-checks
  • Loading branch information
mar-v-in committed Jan 25, 2016
1 parent 4c1fd6d commit 39cc976
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 28 deletions.
10 changes: 10 additions & 0 deletions unifiednlp-app/build.gradle
Expand Up @@ -34,12 +34,22 @@ String getMyVersionName() {
return stdout.toString().trim()
}

int getMyVersionCode() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--count', "HEAD"
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
versionName getMyVersionName()
versionCode(20000 + getMyVersionCode())
}

productFlavors {
Expand Down
14 changes: 6 additions & 8 deletions unifiednlp-app/src/main/AndroidManifest.xml
Expand Up @@ -14,27 +14,25 @@
~ limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.microg.nlp.app"
android:versionName="1.4.0"
android:versionCode="10400">
<manifest package="org.microg.nlp.app"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
android:targetSdkVersion="23"/>

<application
android:icon="@mipmap/ic_nlp_app"
android:allowBackup="true"
android:icon="@mipmap/ic_nlp_app"
android:label="@string/nlp_app_name">

<activity
android:name="org.microg.nlp.ui.SettingsLauncherActivity"
android:icon="@mipmap/ic_nlp_settings"
android:label="@string/nlp_app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Expand Down
Expand Up @@ -17,12 +17,19 @@
package org.microg.nlp.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.preference.Preference;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.preference.PreferenceFragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import org.microg.nlp.R;
import org.microg.tools.selfcheck.NlpOsCompatChecks;
import org.microg.tools.selfcheck.NlpStatusChecks;
import org.microg.tools.selfcheck.SelfCheckGroup;
import org.microg.tools.ui.AbstractSelfCheckFragment;

import java.util.List;

public class SettingsActivity extends AppCompatActivity {
@Override
Expand All @@ -39,7 +46,33 @@ public static class MyPreferenceFragment extends PreferenceFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (!getContext().getPackageName().equals("com.google.android.gms")
|| getResources().getIdentifier("is_gmscore", "bool", "com.google.android.gms") == 0) {
addPreferencesFromResource(R.xml.nlp_setup_preferences);

findPreference(getString(R.string.self_check_title))
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
getFragmentManager().beginTransaction()
.addToBackStack("root")
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_wrapper, new MySelfCheckFragment())
.commit();
return true;
}
});
}
addPreferencesFromResource(R.xml.nlp_preferences);
}
}

public static class MySelfCheckFragment extends AbstractSelfCheckFragment {

@Override
protected void prepareSelfCheckList(List<SelfCheckGroup> checks) {
checks.add(new NlpOsCompatChecks());
checks.add(new NlpStatusChecks());
}
}
}
Expand Up @@ -18,6 +18,8 @@

import android.content.Context;

import org.microg.nlp.R;

import java.util.Arrays;

import static android.os.Build.VERSION.SDK_INT;
Expand All @@ -28,9 +30,14 @@

public class NlpOsCompatChecks implements SelfCheckGroup {

public static final String CONFIG_NL_PROVIDER = "config_networkLocationProvider";
public static final String CONFIG_NL_PROVIDER_PACKAGE_NAME = "config_networkLocationProviderPackageName";
public static final String CONFIG_ENABLE_NL_OVERLAY = "config_enableNetworkLocationOverlay";
public static final String CONFIG_NL_PROVIDER_PACKAGE_NAMES = "config_locationProviderPackageNames";

@Override
public String getGroupName(Context context) {
return "Network location provider support";
return context.getString(R.string.self_check_cat_nlpcompat);
}

@Override
Expand All @@ -41,7 +48,8 @@ public void doChecks(Context context, ResultCollector collector) {

private boolean checkSystemIsSupported(Context context, ResultCollector collector) {
boolean isSupported = (SDK_INT >= KITKAT && SDK_INT <= M);
collector.addResult("Android version supported:", isSupported ? Result.Positive : Result.Unknown, "Your Android version is not officially supported. This does not necessarily mean anything.");
collector.addResult(context.getString(R.string.self_check_name_system_supported),
isSupported ? Result.Positive : Result.Unknown, context.getString(R.string.self_check_resolution_system_supported));
return isSupported;
}

Expand All @@ -54,17 +62,18 @@ private boolean checkSystemIsConfigured(Context context, ResultCollector collect
// com.android.internal.R.bool.config_enableNetworkLocationOverlay
boolean systemMatchesPackage = false;
if (SDK_INT < JELLY_BEAN) {
systemMatchesPackage |= context.getPackageName().equals(getResourceString(context, "config_networkLocationProvider"));
systemMatchesPackage |= context.getPackageName().equals(getResourceString(context, CONFIG_NL_PROVIDER));
} else {
boolean overlay = getResourceBool(context, "config_enableNetworkLocationOverlay");
boolean overlay = getResourceBool(context, CONFIG_ENABLE_NL_OVERLAY);
if (SDK_INT < JELLY_BEAN_MR1 || (SDK_INT > JELLY_BEAN_MR1 && !overlay)) {
systemMatchesPackage |= context.getPackageName().equals(getResourceString(context, "config_networkLocationProviderPackageName"));
systemMatchesPackage |= context.getPackageName().equals(getResourceString(context, CONFIG_NL_PROVIDER_PACKAGE_NAME));
}
if (SDK_INT == JELLY_BEAN_MR1 || (SDK_INT > JELLY_BEAN_MR1 && overlay)) {
systemMatchesPackage |= Arrays.asList(getResourceArray(context, "config_locationProviderPackageNames")).contains(context.getPackageName());
systemMatchesPackage |= Arrays.asList(getResourceArray(context, CONFIG_NL_PROVIDER_PACKAGE_NAMES)).contains(context.getPackageName());
}
}
collector.addResult("System supports location provider:", systemMatchesPackage ? Result.Positive : Result.Negative, "Your system does not support this UnifiedNlp package. Either install a matching package or a compatibility Xposed module.");
collector.addResult(context.getString(R.string.self_check_name_nlp_package_name),
systemMatchesPackage ? Result.Positive : Result.Negative, context.getString(R.string.self_check_resolution_nlp_package_name));
return systemMatchesPackage;
}

Expand Down
Expand Up @@ -24,10 +24,12 @@
import android.text.TextUtils;

import org.microg.nlp.Preferences;
import org.microg.nlp.R;
import org.microg.nlp.location.AbstractLocationService;

import java.util.concurrent.atomic.AtomicBoolean;

import static android.content.Context.LOCATION_SERVICE;
import static android.location.LocationManager.NETWORK_PROVIDER;
import static org.microg.nlp.api.Constants.LOCATION_EXTRA_BACKEND_PROVIDER;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Negative;
Expand All @@ -37,39 +39,52 @@
public class NlpStatusChecks implements SelfCheckGroup {
@Override
public String getGroupName(Context context) {
return "UnifiedNlp status";
return context.getString(R.string.self_check_cat_nlp_status);
}

@Override
public void doChecks(Context context, ResultCollector collector) {
providerWasBound(context, collector);
isLocationProviderSetUp(context, collector);
isProvidingLastLocation(context, collector);
isProvidingLocation(context, collector);
if (isNetworkLocationEnabled(context, collector)) {
isProvidingLastLocation(context, collector);
isProvidingLocation(context, collector);
}
}

private boolean providerWasBound(Context context, ResultCollector collector) {
collector.addResult("UnifiedNlp is registered in system:", AbstractLocationService.WAS_BOUND ? Positive : Negative, "The system did not bind the UnifiedNlp service. If you just installed UnifiedNlp you should try to reboot this device.");
collector.addResult(context.getString(R.string.self_check_name_nlp_bound),
AbstractLocationService.WAS_BOUND ? Positive : Negative, context.getString(R.string.self_check_resolution_nlp_bound));
return AbstractLocationService.WAS_BOUND;
}

private boolean isLocationProviderSetUp(Context context, ResultCollector collector) {
boolean setupLocationProvider = !TextUtils.isEmpty(new Preferences(context).getLocationBackends());
collector.addResult("Location backend(s) set up:", setupLocationProvider ? Positive : Negative, "Install and configure a UnifiedNlp location backend to use network-based geolocation,");
collector.addResult(context.getString(R.string.self_check_name_nlp_setup),
setupLocationProvider ? Positive : Negative, context.getString(R.string.self_check_resolution_nlp_setup));
return setupLocationProvider;
}

private boolean isNetworkLocationEnabled(Context context, ResultCollector collector) {
LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
boolean networkEnabled = locationManager.getProviders(true).contains(NETWORK_PROVIDER);
collector.addResult(context.getString(R.string.self_check_name_network_enabled),
networkEnabled ? Positive : Negative, context.getString(R.string.self_check_resolution_network_enabled));
return networkEnabled;
}

private boolean isProvidingLastLocation(Context context, ResultCollector collector) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
boolean hasKnown = location != null && location.getExtras().containsKey(LOCATION_EXTRA_BACKEND_PROVIDER);
collector.addResult("UnifiedNlp has known location:", hasKnown ? Positive : Unknown, "UnifiedNlp has no last known location. This will cause some apps to fail.");
collector.addResult(context.getString(R.string.self_check_name_last_location),
hasKnown ? Positive : Unknown, context.getString(R.string.self_check_resolution_last_location));
return hasKnown;
}

private void isProvidingLocation(Context context, final ResultCollector collector) {
private void isProvidingLocation(final Context context, final ResultCollector collector) {
final AtomicBoolean result = new AtomicBoolean(false);
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
new Thread(new Runnable() {
@Override
public void run() {
Expand All @@ -78,7 +93,8 @@ public void run() {
result.wait(10000);
} catch (InterruptedException e) {
}
collector.addResult("UnifiedNlp provides location updates:", result.get() ? Positive : Unknown, "No UnifiedNlp location was provided by the system within 10 seconds.");
collector.addResult(context.getString(R.string.self_check_name_nlp_is_providing),
result.get() ? Positive : Unknown, context.getString(R.string.self_check_resolution_nlp_is_providing));
}
}
}).start();
Expand Down
20 changes: 19 additions & 1 deletion unifiednlp-base/src/main/res/values/strings.xml
Expand Up @@ -33,5 +33,23 @@
<string name="perm_force_coarse_location_desc">Force the network-based location provider to report a certain location</string>

<string name="pref_location_backends" translatable="false">location_backends</string>
<string name="pref_geocoder_backends" translatable="false">geocoder_backends</string>
<string name="pref_geocoder_backends" translatable="false">geocoder_backends</string>x

<string name="self_check_cat_nlpcompat">Network location provider support</string>
<string name="self_check_name_system_supported">Android version supported:</string>
<string name="self_check_resolution_system_supported">Your Android version is not officially supported. This does not necessarily mean anything.</string>
<string name="self_check_name_nlp_package_name">System supports location provider:</string>
<string name="self_check_resolution_nlp_package_name">Your system does not support this UnifiedNlp package. Either install a matching package or a compatibility Xposed module.</string>

<string name="self_check_cat_nlp_status">UnifiedNlp status</string>
<string name="self_check_name_nlp_bound">UnifiedNlp is registered in system:</string>
<string name="self_check_resolution_nlp_bound">The system did not bind the UnifiedNlp service. If you just installed UnifiedNlp you should try to reboot this device.</string>
<string name="self_check_name_nlp_setup">Location backend(s) set up:</string>
<string name="self_check_resolution_nlp_setup">Install and configure a UnifiedNlp location backend to use network-based geolocation,</string>
<string name="self_check_name_last_location">UnifiedNlp has known location:</string>
<string name="self_check_resolution_last_location">UnifiedNlp has no last known location. This will cause some apps to fail.</string>
<string name="self_check_name_nlp_is_providing">UnifiedNlp provides location updates:</string>
<string name="self_check_resolution_nlp_is_providing">No UnifiedNlp location was provided by the system within 10 seconds.</string>
<string name="self_check_name_network_enabled">Network-based location enabled:</string>
<string name="self_check_resolution_network_enabled">You either disabled network-based location (in system settings) or the system is not supported.</string>
</resources>
27 changes: 27 additions & 0 deletions unifiednlp-base/src/main/res/xml/nlp_setup_preferences.xml
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013-2016 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.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="nlp_self_check_preferences">
<PreferenceCategory android:title="@string/prefcat_setup">
<Preference
android:key="@string/self_check_title"
android:summary="@string/self_check_desc"
android:title="@string/self_check_title">
</Preference>
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 39cc976

Please sign in to comment.