diff --git a/extern/MicroGUiTools b/extern/MicroGUiTools index f0e7d6b..b2f08ac 160000 --- a/extern/MicroGUiTools +++ b/extern/MicroGUiTools @@ -1 +1 @@ -Subproject commit f0e7d6b1c806effee3f5040e5e8595e128c575e4 +Subproject commit b2f08accd9b8b75d9b1b3f7aecbb06d2d12c9658 diff --git a/unifiednlp-app/build.gradle b/unifiednlp-app/build.gradle index 8becff5..3b62ea0 100644 --- a/unifiednlp-app/build.gradle +++ b/unifiednlp-app/build.gradle @@ -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 { diff --git a/unifiednlp-app/src/main/AndroidManifest.xml b/unifiednlp-app/src/main/AndroidManifest.xml index adc5d79..f8a65e0 100644 --- a/unifiednlp-app/src/main/AndroidManifest.xml +++ b/unifiednlp-app/src/main/AndroidManifest.xml @@ -14,18 +14,16 @@ ~ limitations under the License. --> - + + android:targetSdkVersion="23"/> - - + + diff --git a/unifiednlp-base/src/main/java/org/microg/nlp/ui/SettingsActivity.java b/unifiednlp-base/src/main/java/org/microg/nlp/ui/SettingsActivity.java index 5ca4343..7b2e90f 100644 --- a/unifiednlp-base/src/main/java/org/microg/nlp/ui/SettingsActivity.java +++ b/unifiednlp-base/src/main/java/org/microg/nlp/ui/SettingsActivity.java @@ -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 @@ -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 checks) { + checks.add(new NlpOsCompatChecks()); + checks.add(new NlpStatusChecks()); + } + } } diff --git a/unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpOsCompatChecks.java b/unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpOsCompatChecks.java index b57d7bb..4388b12 100644 --- a/unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpOsCompatChecks.java +++ b/unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpOsCompatChecks.java @@ -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; @@ -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 @@ -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; } @@ -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; } diff --git a/unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpStatusChecks.java b/unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpStatusChecks.java index 4f25efb..0fdd76e 100644 --- a/unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpStatusChecks.java +++ b/unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpStatusChecks.java @@ -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; @@ -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() { @@ -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(); diff --git a/unifiednlp-base/src/main/res/values/strings.xml b/unifiednlp-base/src/main/res/values/strings.xml index f544e22..f3c4214 100644 --- a/unifiednlp-base/src/main/res/values/strings.xml +++ b/unifiednlp-base/src/main/res/values/strings.xml @@ -33,5 +33,23 @@ Force the network-based location provider to report a certain location location_backends - geocoder_backends + geocoder_backendsx + + Network location provider support + Android version supported: + Your Android version is not officially supported. This does not necessarily mean anything. + System supports location provider: + Your system does not support this UnifiedNlp package. Either install a matching package or a compatibility Xposed module. + + UnifiedNlp status + UnifiedNlp is registered in system: + The system did not bind the UnifiedNlp service. If you just installed UnifiedNlp you should try to reboot this device. + Location backend(s) set up: + Install and configure a UnifiedNlp location backend to use network-based geolocation, + UnifiedNlp has known location: + UnifiedNlp has no last known location. This will cause some apps to fail. + UnifiedNlp provides location updates: + No UnifiedNlp location was provided by the system within 10 seconds. + Network-based location enabled: + You either disabled network-based location (in system settings) or the system is not supported. diff --git a/unifiednlp-base/src/main/res/xml/nlp_setup_preferences.xml b/unifiednlp-base/src/main/res/xml/nlp_setup_preferences.xml new file mode 100644 index 0000000..baa63d3 --- /dev/null +++ b/unifiednlp-base/src/main/res/xml/nlp_setup_preferences.xml @@ -0,0 +1,27 @@ + + + + + + + + + \ No newline at end of file