Skip to content
Snippets Groups Projects
Commit 4fa5de7f authored by akwizgran's avatar akwizgran
Browse files

Merge branch 'improvements' into 'master'

Implement various tickets

See merge request !4
parents e8118189 a2fbf9ca
No related branches found
No related tags found
1 merge request!4Implement various tickets
Pipeline #14507 passed
Showing
with 165 additions and 6 deletions
......@@ -28,8 +28,8 @@ android {
}
dependencies {
implementation project(':onionwrapper-core')
implementation 'org.briarproject:dont-kill-me-lib:0.2.6'
api project(':onionwrapper-core')
api 'org.briarproject:dont-kill-me-lib:0.2.7'
}
mavenPublishing {
......
package org.briarproject.onionwrapper;
import static android.content.Context.TELEPHONY_SERVICE;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import org.briarproject.nullsafety.NotNullByDefault;
import java.util.Locale;
import java.util.logging.Logger;
import javax.inject.Inject;
@NotNullByDefault
class AndroidLocationUtils implements LocationUtils {
private static final Logger LOG =
Logger.getLogger(AndroidLocationUtils.class.getName());
private final Context appContext;
@Inject
AndroidLocationUtils(Application app) {
appContext = app.getApplicationContext();
}
/**
* This guesses the current country from the first of these sources that
* succeeds (also in order of likelihood of being correct):
*
* <ul>
* <li>Phone network. This works even when no SIM card is inserted, or a
* foreign SIM card is inserted.</li>
* <li>SIM card. This is only an heuristic and assumes the user is not
* roaming.</li>
* <li>User locale. This is an even worse heuristic.</li>
* </ul>
*
* Note: this is very similar to <a href="https://android.googlesource.com/platform/frameworks/base/+/cd92588%5E/location/java/android/location/CountryDetector.java">
* this API</a> except it seems that Google doesn't want us to use it for
* some reason - both that class and {@code Context.COUNTRY_CODE} are
* annotated {@code @hide}.
*/
@Override
@SuppressLint("DefaultLocale")
public String getCurrentCountry() {
String countryCode = getCountryFromPhoneNetwork();
if (!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
LOG.info("Falling back to SIM card country");
countryCode = getCountryFromSimCard();
if (!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
LOG.info("Falling back to user-defined locale");
return Locale.getDefault().getCountry();
}
private String getCountryFromPhoneNetwork() {
Object o = appContext.getSystemService(TELEPHONY_SERVICE);
TelephonyManager tm = (TelephonyManager) o;
return tm == null ? "" : tm.getNetworkCountryIso();
}
private String getCountryFromSimCard() {
Object o = appContext.getSystemService(TELEPHONY_SERVICE);
TelephonyManager tm = (TelephonyManager) o;
return tm == null ? "" : tm.getSimCountryIso();
}
}
package org.briarproject.onionwrapper;
import android.app.Application;
import org.briarproject.nullsafety.NotNullByDefault;
@NotNullByDefault
public class AndroidLocationUtilsFactory {
public static LocationUtils createAndroidLocationUtils(Application app) {
return new AndroidLocationUtils(app);
}
}
......@@ -133,7 +133,7 @@ public class AndroidTorWrapper extends AbstractTorWrapper {
}
@Override
protected File getObfs4ExecutableFile() {
public File getObfs4ExecutableFile() {
return obfs4Lib.exists() ? obfs4Lib : super.getObfs4ExecutableFile();
}
......
......@@ -107,7 +107,8 @@ abstract class AbstractTorWrapper implements EventHandler, TorWrapper {
return new File(torDirectory, "tor");
}
protected File getObfs4ExecutableFile() {
@Override
public File getObfs4ExecutableFile() {
return new File(torDirectory, "obfs4proxy");
}
......
package org.briarproject.onionwrapper;
import org.briarproject.nullsafety.NotNullByDefault;
@NotNullByDefault
public class CircumventionProviderFactory {
public static CircumventionProvider createCircumventionProvider() {
return new CircumventionProviderImpl();
}
}
package org.briarproject.onionwrapper;
import org.briarproject.nullsafety.NotNullByDefault;
@NotNullByDefault
public interface LocationUtils {
/**
* Get the country the device is currently located in, or "" if it cannot
* be determined.
* <p>
* The country codes are formatted upper-case and as per <a href="
* https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166-1 alpha 2</a>.
*/
String getCurrentCountry();
}
......@@ -2,6 +2,7 @@ package org.briarproject.onionwrapper;
import org.briarproject.nullsafety.NotNullByDefault;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;
......@@ -16,7 +17,8 @@ public interface TorWrapper {
Logger LOG = getLogger(TorWrapper.class.getName());
/**
* Starts the Tor process.
* Starts the Tor process, but does not yet connect to the Tor Network.
* Call {@link #enableNetwork(boolean)} for this.
* <p>
* This method must only be called once. To restart the Tor process, stop
* this wrapper instance and then create a new instance.
......@@ -98,6 +100,11 @@ public interface TorWrapper {
*/
void enableIpv6(boolean ipv6Only) throws IOException;
/**
* Returns the Obfs4 executable as a File for use with Moat.
*/
File getObfs4ExecutableFile();
/**
* The state of the Tor wrapper.
*/
......
......@@ -9,7 +9,7 @@ java {
}
dependencies {
implementation project(':onionwrapper-core')
api project(':onionwrapper-core')
def jna_version = '4.5.2'
implementation "net.java.dev.jna:jna:$jna_version"
implementation "net.java.dev.jna:jna-platform:$jna_version"
......
package org.briarproject.onionwrapper;
import org.briarproject.nullsafety.NotNullByDefault;
import java.util.Locale;
import java.util.logging.Logger;
import javax.inject.Inject;
@NotNullByDefault
class JavaLocationUtils implements LocationUtils {
private static final Logger LOG =
Logger.getLogger(JavaLocationUtils.class.getName());
@Inject
JavaLocationUtils() {
}
@Override
public String getCurrentCountry() {
LOG.info("Using user-defined locale");
return Locale.getDefault().getCountry();
}
}
package org.briarproject.onionwrapper;
import org.briarproject.nullsafety.NotNullByDefault;
@NotNullByDefault
public class JavaLocationUtilsFactory {
public static LocationUtils createJavaLocationUtils() {
return new JavaLocationUtils();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment