Skip to content
Snippets Groups Projects
Commit 9697b351 authored by Ximin Luo's avatar Ximin Luo
Browse files

add the ability for briar-android to get the current country.

- this will be useful later for e.g. auto-disabling Tor
parent 39b7a972
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,7 @@ import org.briarproject.util.StringUtils; ...@@ -44,6 +44,7 @@ import org.briarproject.util.StringUtils;
import socks.Socks5Proxy; import socks.Socks5Proxy;
import socks.SocksSocket; import socks.SocksSocket;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
...@@ -275,6 +276,7 @@ class TorPlugin implements DuplexPlugin, EventHandler { ...@@ -275,6 +276,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
out.close(); out.close();
} }
@SuppressLint("NewApi")
private boolean setExecutable(File f) { private boolean setExecutable(File f) {
if(Build.VERSION.SDK_INT >= 9) { if(Build.VERSION.SDK_INT >= 9) {
return f.setExecutable(true, true); return f.setExecutable(true, true);
......
package org.briarproject.system;
import java.util.Locale;
import java.util.logging.Logger;
import org.briarproject.api.system.LocationUtils;
import roboguice.inject.ContextSingleton;
import android.annotation.SuppressLint;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.google.inject.Inject;
@ContextSingleton
class AndroidLocationUtils implements LocationUtils {
private static final Logger LOG =
Logger.getLogger(AndroidLocationUtils.class.getName());
final Context context;
@Inject
public AndroidLocationUtils(Context context) {
this.context = context;
}
@SuppressLint("DefaultLocale")
@Override
public String getCurrentCountry() {
String countryCode;
countryCode = getCountryFromPhoneNetwork();
if (!TextUtils.isEmpty(countryCode)) {
return countryCode.toUpperCase(); // android api gives lowercase for some reason
}
LOG.warning("Could not determine current country; fall back to user-defined locale");
return Locale.getDefault().getCountry();
}
String getCountryFromPhoneNetwork() {
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
return tm.getNetworkCountryIso();
}
}
...@@ -2,6 +2,7 @@ package org.briarproject.system; ...@@ -2,6 +2,7 @@ package org.briarproject.system;
import org.briarproject.api.system.Clock; import org.briarproject.api.system.Clock;
import org.briarproject.api.system.FileUtils; import org.briarproject.api.system.FileUtils;
import org.briarproject.api.system.LocationUtils;
import org.briarproject.api.system.SeedProvider; import org.briarproject.api.system.SeedProvider;
import org.briarproject.api.system.Timer; import org.briarproject.api.system.Timer;
...@@ -14,5 +15,6 @@ public class AndroidSystemModule extends AbstractModule { ...@@ -14,5 +15,6 @@ public class AndroidSystemModule extends AbstractModule {
bind(Timer.class).to(SystemTimer.class); bind(Timer.class).to(SystemTimer.class);
bind(SeedProvider.class).to(AndroidSeedProvider.class); bind(SeedProvider.class).to(AndroidSeedProvider.class);
bind(FileUtils.class).to(AndroidFileUtils.class); bind(FileUtils.class).to(AndroidFileUtils.class);
bind(LocationUtils.class).to(AndroidLocationUtils.class);
} }
} }
package org.briarproject.api.system;
public interface LocationUtils {
/** Get the country the device is currently-located in. */
String getCurrentCountry();
}
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