-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
246 additions
and
17 deletions.
There are no files selected for viewing
Submodule MicroGUiTools
updated
8 files
Submodule UnifiedNlpApi
updated
2 files
+16 −2 | unifiednlp-api/build.gradle | |
+47 −2 | unifiednlp-api/src/main/java/org/microg/nlp/api/CellBackendHelper.java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpOsCompatChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.microg.tools.selfcheck; | ||
|
||
import android.content.Context; | ||
|
||
import java.util.Arrays; | ||
|
||
import static android.os.Build.VERSION.SDK_INT; | ||
import static android.os.Build.VERSION_CODES.JELLY_BEAN; | ||
import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; | ||
import static android.os.Build.VERSION_CODES.KITKAT; | ||
import static android.os.Build.VERSION_CODES.M; | ||
|
||
public class NlpOsCompatChecks implements SelfCheckGroup { | ||
|
||
@Override | ||
public String getGroupName(Context context) { | ||
return "Network location provider support"; | ||
} | ||
|
||
@Override | ||
public void doChecks(Context context, ResultCollector collector) { | ||
checkSystemIsSupported(context, collector); | ||
checkSystemIsConfigured(context, 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."); | ||
return isSupported; | ||
} | ||
|
||
private boolean checkSystemIsConfigured(Context context, ResultCollector collector) { | ||
// 2.3+ com.android.internal.R.string.config_networkLocationProvider | ||
// 4.1+ com.android.internal.R.string.config_networkLocationProviderPackageName | ||
// 4.2+ com.android.internal.R.array.config_locationProviderPackageNames | ||
// 4.3+ com.android.internal.R.array.config_locationProviderPackageNames / | ||
// com.android.internal.R.string.config_networkLocationProviderPackageName / | ||
// com.android.internal.R.bool.config_enableNetworkLocationOverlay | ||
boolean systemMatchesPackage = false; | ||
if (SDK_INT < JELLY_BEAN) { | ||
systemMatchesPackage |= context.getPackageName().equals(getResourceString(context, "config_networkLocationProvider")); | ||
} else { | ||
boolean overlay = getResourceBool(context, "config_enableNetworkLocationOverlay"); | ||
if (SDK_INT < JELLY_BEAN_MR1 || (SDK_INT > JELLY_BEAN_MR1 && !overlay)) { | ||
systemMatchesPackage |= context.getPackageName().equals(getResourceString(context, "config_networkLocationProviderPackageName")); | ||
} | ||
if (SDK_INT == JELLY_BEAN_MR1 || (SDK_INT > JELLY_BEAN_MR1 && overlay)) { | ||
systemMatchesPackage |= Arrays.asList(getResourceArray(context, "config_locationProviderPackageNames")).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."); | ||
return systemMatchesPackage; | ||
} | ||
|
||
private String[] getResourceArray(Context context, String identifier) { | ||
try { | ||
int resId = context.getResources().getIdentifier(identifier, "array", "android"); | ||
if (resId == 0) | ||
resId = context.getResources().getIdentifier(identifier, "array", "com.android.internal"); | ||
return context.getResources().getStringArray(resId); | ||
} catch (Exception e) { | ||
return new String[0]; | ||
} | ||
} | ||
|
||
private boolean getResourceBool(Context context, String identifier) { | ||
try { | ||
int resId = context.getResources().getIdentifier(identifier, "bool", "android"); | ||
if (resId == 0) | ||
resId = context.getResources().getIdentifier(identifier, "bool", "com.android.internal"); | ||
return context.getResources().getBoolean(resId); | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
|
||
private String getResourceString(Context context, String identifier) { | ||
try { | ||
int resId = context.getResources().getIdentifier(identifier, "string", "android"); | ||
if (resId == 0) | ||
resId = context.getResources().getIdentifier(identifier, "string", "com.android.internal"); | ||
return context.getString(resId); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
unifiednlp-base/src/main/java/org/microg/tools/selfcheck/NlpStatusChecks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.microg.tools.selfcheck; | ||
|
||
import android.content.Context; | ||
import android.location.Location; | ||
import android.location.LocationListener; | ||
import android.location.LocationManager; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
|
||
import org.microg.nlp.Preferences; | ||
import org.microg.nlp.location.AbstractLocationService; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
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; | ||
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Positive; | ||
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Unknown; | ||
|
||
public class NlpStatusChecks implements SelfCheckGroup { | ||
@Override | ||
public String getGroupName(Context context) { | ||
return "UnifiedNlp status"; | ||
} | ||
|
||
@Override | ||
public void doChecks(Context context, ResultCollector collector) { | ||
providerWasBound(context, collector); | ||
isLocationProviderSetUp(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."); | ||
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,"); | ||
return setupLocationProvider; | ||
} | ||
|
||
private boolean isProvidingLastLocation(Context context, ResultCollector collector) { | ||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.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."); | ||
return hasKnown; | ||
} | ||
|
||
private void isProvidingLocation(Context context, final ResultCollector collector) { | ||
final AtomicBoolean result = new AtomicBoolean(false); | ||
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
synchronized (result) { | ||
try { | ||
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."); | ||
} | ||
} | ||
}).start(); | ||
locationManager.requestSingleUpdate(NETWORK_PROVIDER, new LocationListener() { | ||
@Override | ||
public void onLocationChanged(Location location) { | ||
synchronized (result) { | ||
result.set(location.getExtras().containsKey(LOCATION_EXTRA_BACKEND_PROVIDER)); | ||
result.notifyAll(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onStatusChanged(String provider, int status, Bundle extras) { | ||
} | ||
|
||
@Override | ||
public void onProviderEnabled(String provider) { | ||
} | ||
|
||
@Override | ||
public void onProviderDisabled(String provider) { | ||
} | ||
}, null); | ||
} | ||
} |