Skip to content
Snippets Groups Projects
Verified Commit b048ff1e authored by Sebastian's avatar Sebastian
Browse files

Fix formatting for recent commits

parent 70a08fb5
No related branches found
No related tags found
1 merge request!8Add checkstyle plugin and config
Pipeline #14597 passed
Showing
with 99 additions and 98 deletions
package org.briarproject.onionwrapper;
import static android.content.Context.TELEPHONY_SERVICE;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
......@@ -15,57 +13,60 @@ import java.util.logging.Logger;
import javax.inject.Inject;
import static android.content.Context.TELEPHONY_SERVICE;
@NotNullByDefault
class AndroidLocationUtils implements LocationUtils {
private static final Logger LOG =
Logger.getLogger(AndroidLocationUtils.class.getName());
private static final Logger LOG =
Logger.getLogger(AndroidLocationUtils.class.getName());
private final Context appContext;
private final Context appContext;
@Inject
AndroidLocationUtils(Application app) {
appContext = app.getApplicationContext();
}
@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();
}
/**
* 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>
* <p>
* 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 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();
}
private String getCountryFromSimCard() {
Object o = appContext.getSystemService(TELEPHONY_SERVICE);
TelephonyManager tm = (TelephonyManager) o;
return tm == null ? "" : tm.getSimCountryIso();
}
}
......@@ -7,8 +7,8 @@ import org.briarproject.nullsafety.NotNullByDefault;
@NotNullByDefault
public class AndroidLocationUtilsFactory {
public static LocationUtils createAndroidLocationUtils(Application app) {
return new AndroidLocationUtils(app);
}
public static LocationUtils createAndroidLocationUtils(Application app) {
return new AndroidLocationUtils(app);
}
}
......@@ -133,7 +133,7 @@ public class AndroidTorWrapper extends AbstractTorWrapper {
}
@Override
public File getObfs4ExecutableFile() {
public File getObfs4ExecutableFile() {
return obfs4Lib.exists() ? obfs4Lib : super.getObfs4ExecutableFile();
}
......
......@@ -107,7 +107,7 @@ abstract class AbstractTorWrapper implements EventHandler, TorWrapper {
return new File(torDirectory, "tor");
}
@Override
@Override
public File getObfs4ExecutableFile() {
return new File(torDirectory, "obfs4proxy");
}
......
......@@ -5,8 +5,8 @@ import org.briarproject.nullsafety.NotNullByDefault;
@NotNullByDefault
public class CircumventionProviderFactory {
public static CircumventionProvider createCircumventionProvider() {
return new CircumventionProviderImpl();
}
public static CircumventionProvider createCircumventionProvider() {
return new CircumventionProviderImpl();
}
}
......@@ -7,28 +7,28 @@ import java.util.Locale;
@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();
/**
* 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();
/**
* Returns the name of the country for display in the UI
* or the isoCode if none could be found.
*
* @param isoCode The result from {@link #getCurrentCountry()}.
*/
static String getCountryDisplayName(String isoCode) {
for (Locale locale : Locale.getAvailableLocales()) {
if (locale.getCountry().equalsIgnoreCase(isoCode)) {
return locale.getDisplayCountry();
}
}
// Name is unknown
return isoCode;
}
/**
* Returns the name of the country for display in the UI
* or the isoCode if none could be found.
*
* @param isoCode The result from {@link #getCurrentCountry()}.
*/
static String getCountryDisplayName(String isoCode) {
for (Locale locale : Locale.getAvailableLocales()) {
if (locale.getCountry().equalsIgnoreCase(isoCode)) {
return locale.getDisplayCountry();
}
}
// Name is unknown
return isoCode;
}
}
......@@ -18,7 +18,7 @@ public interface TorWrapper {
/**
* Starts the Tor process, but does not yet connect to the Tor Network.
* Call {@link #enableNetwork(boolean)} for this.
* 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.
......@@ -100,10 +100,10 @@ public interface TorWrapper {
*/
void enableIpv6(boolean ipv6Only) throws IOException;
/**
* Returns the Obfs4 executable as a File for use with Moat.
*/
File getObfs4ExecutableFile();
/**
* Returns the Obfs4 executable as a File for use with Moat.
*/
File getObfs4ExecutableFile();
/**
* The state of the Tor wrapper.
......
......@@ -10,17 +10,17 @@ 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();
}
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();
}
}
......@@ -5,8 +5,8 @@ import org.briarproject.nullsafety.NotNullByDefault;
@NotNullByDefault
public class JavaLocationUtilsFactory {
public static LocationUtils createJavaLocationUtils() {
return new JavaLocationUtils();
}
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