diff --git a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java index 6112889ffb7a654ff8743d64fca94047009387a7..99e92959233126a39be059c905bbb82eb4edbbfb 100644 --- a/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java +++ b/briar-android/src/org/briarproject/plugins/tor/TorPlugin.java @@ -44,6 +44,7 @@ import org.briarproject.util.StringUtils; import socks.Socks5Proxy; import socks.SocksSocket; +import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -275,6 +276,7 @@ class TorPlugin implements DuplexPlugin, EventHandler { out.close(); } + @SuppressLint("NewApi") private boolean setExecutable(File f) { if(Build.VERSION.SDK_INT >= 9) { return f.setExecutable(true, true); diff --git a/briar-android/src/org/briarproject/system/AndroidLocationUtils.java b/briar-android/src/org/briarproject/system/AndroidLocationUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..7f3f1e110a9b348272df434742f255fbbd7db2f2 --- /dev/null +++ b/briar-android/src/org/briarproject/system/AndroidLocationUtils.java @@ -0,0 +1,46 @@ +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(); + } + +} diff --git a/briar-android/src/org/briarproject/system/AndroidSystemModule.java b/briar-android/src/org/briarproject/system/AndroidSystemModule.java index 570d4fbbc79b0fba9f7ceff17c741de14f70b0b0..aa6769e59bf8bcf53723af9494985d1f38e36c6c 100644 --- a/briar-android/src/org/briarproject/system/AndroidSystemModule.java +++ b/briar-android/src/org/briarproject/system/AndroidSystemModule.java @@ -2,6 +2,7 @@ package org.briarproject.system; import org.briarproject.api.system.Clock; import org.briarproject.api.system.FileUtils; +import org.briarproject.api.system.LocationUtils; import org.briarproject.api.system.SeedProvider; import org.briarproject.api.system.Timer; @@ -14,5 +15,6 @@ public class AndroidSystemModule extends AbstractModule { bind(Timer.class).to(SystemTimer.class); bind(SeedProvider.class).to(AndroidSeedProvider.class); bind(FileUtils.class).to(AndroidFileUtils.class); + bind(LocationUtils.class).to(AndroidLocationUtils.class); } } diff --git a/briar-api/src/org/briarproject/api/system/LocationUtils.java b/briar-api/src/org/briarproject/api/system/LocationUtils.java new file mode 100644 index 0000000000000000000000000000000000000000..a5f94e5a0db2a9f6fb417f121200e55a5d1f962b --- /dev/null +++ b/briar-api/src/org/briarproject/api/system/LocationUtils.java @@ -0,0 +1,8 @@ +package org.briarproject.api.system; + +public interface LocationUtils { + + /** Get the country the device is currently-located in. */ + String getCurrentCountry(); + +}