diff options
Diffstat (limited to 'app')
11 files changed, 99 insertions, 73 deletions
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java index 3e176fc1..b5ce824f 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java @@ -75,7 +75,7 @@ public class ConfigurationWizard extends BaseConfigurationWizard { private void autoSelectProvider(Provider provider, boolean danger_on) { preferences.edit().putBoolean(ProviderItem.DANGER_ON, danger_on).apply(); - provider = provider; + this.provider = provider; onItemSelectedLogic(); showProgressBar(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java b/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java index b780e5f8..fbb27b58 100644 --- a/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java @@ -40,8 +40,8 @@ public abstract class AbstractProviderDetailActivity extends ConfigWizardBaseAct try { JSONObject providerJson = new JSONObject(preferences.getString(Provider.KEY, "")); - setProviderHeaderText(getProviderName()); - description.setText(providerJson.getJSONObject(Provider.DESCRIPTION).getString("en")); + setProviderHeaderText(ConfigHelper.getProviderName(preferences)); + description.setText(ConfigHelper.getDescription(preferences)); // Show only the options allowed by the provider ArrayList<String> optionsList = new ArrayList<>(); diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 375ef038..ec4bbaec 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -448,8 +448,8 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity Bundle resultData = intent.getParcelableExtra(RESULT_KEY); String handledProvider = resultData.getString(Provider.KEY); - String providerName = getProviderName(handledProvider); - String providerDomain = getProviderDomain(handledProvider); + String providerName = ConfigHelper.getProviderName(handledProvider); + String providerDomain = ConfigHelper.getProviderDomain(handledProvider); if (providerName != null && providerName.equalsIgnoreCase(provider.getName()) && providerDomain != null && diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java index ccdf5064..f93fb36c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigHelper.java @@ -18,8 +18,10 @@ package se.leap.bitmaskclient; import android.content.SharedPreferences; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.Log; +import org.jetbrains.annotations.NotNull; import org.json.JSONException; import org.json.JSONObject; import org.spongycastle.util.encoders.Base64; @@ -45,6 +47,7 @@ import java.security.cert.X509Certificate; import java.security.interfaces.RSAPrivateKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; +import java.util.Locale; import static android.R.attr.name; import static se.leap.bitmaskclient.Constants.PROVIDER_CONFIGURED; @@ -261,16 +264,6 @@ public class ConfigHelper { } - public static String getCurrentProviderName(@NonNull SharedPreferences preferences) { - try { - JSONObject providerDefintion = new JSONObject(preferences.getString(Provider.KEY, "")); - return providerDefintion.getString(Provider.DOMAIN); - } catch (JSONException e) { - e.printStackTrace(); - } - return null; - } - public static boolean providerInSharedPreferences(@NonNull SharedPreferences preferences) { return preferences.getBoolean(PROVIDER_CONFIGURED, false); } @@ -288,4 +281,72 @@ public class ConfigHelper { return provider; } + public static String getProviderName(String provider) { + return getProviderName(null, provider); + } + + public static String getProviderName(SharedPreferences preferences) { + return getProviderName(preferences,null); + } + + public static String getProviderName(SharedPreferences preferences, @Nullable String provider) { + if (provider == null) { + provider = preferences.getString(Provider.KEY, ""); + } + try { + JSONObject providerJson = new JSONObject(provider); + String lang = Locale.getDefault().getLanguage(); + return providerJson.getJSONObject(Provider.NAME).getString(lang); + } catch (JSONException e) { + try { + JSONObject providerJson = new JSONObject(provider); + return providerJson.getJSONObject(Provider.NAME).getString("en"); + } catch (JSONException e2) { + return null; + } + } + } + + public static String getProviderDomain(SharedPreferences preferences) { + return getProviderDomain(preferences, null); + } + + public static String getProviderDomain(String provider) { + return getProviderDomain(null, provider); + } + + public static String getProviderDomain(SharedPreferences preferences, @Nullable String provider) { + if (provider == null) { + provider = preferences.getString(Provider.KEY, ""); + } + try { + JSONObject providerJson = new JSONObject(provider); + return providerJson.getString(Provider.DOMAIN); + } catch (JSONException e) { + return null; + } + } + + public static String getDescription(SharedPreferences preferences) { + try { + JSONObject providerJson = new JSONObject(preferences.getString(Provider.KEY, "")); + String lang = Locale.getDefault().getLanguage(); + return providerJson.getJSONObject(Provider.DESCRIPTION).getString(lang); + } catch (JSONException e) { + try { + JSONObject providerJson = new JSONObject(preferences.getString(Provider.KEY, "")); + return providerJson.getJSONObject(Provider.DESCRIPTION).getString("en"); + } catch (JSONException e1) { + return null; + } + } + } + + public static void storeProviderInPreferences(SharedPreferences preferences, Provider provider) { + preferences.edit().putBoolean(PROVIDER_CONFIGURED, true). + putString(Provider.MAIN_URL, provider.getMainUrlString()). + putString(Provider.KEY, provider.getDefinitionString()). + putString(Provider.CA_CERT, provider.getCaCert()). + apply(); + } } diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java index 1ad12042..79a78fe1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java @@ -11,11 +11,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Locale; - import butterknife.InjectView; import static android.view.View.GONE; @@ -61,19 +56,19 @@ public abstract class ConfigWizardBaseActivity extends ButterKnifeActivity { @Override public void setContentView(View view) { super.setContentView(view); - setProviderHeaderText(getProviderName()); + setProviderHeaderText(ConfigHelper.getProviderName(preferences)); } @Override public void setContentView(int layoutResID) { super.setContentView(layoutResID); - setProviderHeaderText(getProviderName()); + setProviderHeaderText(ConfigHelper.getProviderName(preferences)); } @Override public void setContentView(View view, ViewGroup.LayoutParams params) { super.setContentView(view, params); - setProviderHeaderText(getProviderName()); + setProviderHeaderText(ConfigHelper.getProviderName(preferences)); } protected void setProviderHeaderLogo(@DrawableRes int providerHeaderLogo) { @@ -88,43 +83,6 @@ public abstract class ConfigWizardBaseActivity extends ButterKnifeActivity { this.providerHeaderText.setText(providerHeaderText); } - protected String getProviderName() { - return getProviderName(null); - } - - protected String getProviderName(@Nullable String provider) { - if (provider == null) { - provider = preferences.getString(Provider.KEY, ""); - } - try { - JSONObject providerJson = new JSONObject(provider); - String lang = Locale.getDefault().getLanguage(); - return providerJson.getJSONObject(Provider.NAME).getString(lang); - } catch (JSONException e) { - try { - JSONObject providerJson = new JSONObject(provider); - return providerJson.getJSONObject(Provider.NAME).getString("en"); - } catch (JSONException e2) { - return null; - } - } - } - - protected String getProviderDomain() { - return getProviderDomain(null); - } - - protected String getProviderDomain(@Nullable String provider) { - if (provider == null) { - provider = preferences.getString(Provider.KEY, ""); - } - try { - JSONObject providerJson = new JSONObject(provider); - return providerJson.getString(Provider.DOMAIN); - } catch (JSONException e) { - return null; - } - } protected void hideProgressBar() { loadingScreen.setVisibility(GONE); content.setVisibility(VISIBLE); diff --git a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java index 6ae288c2..a407b0a9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java @@ -22,11 +22,6 @@ public class LoginActivity extends ProviderCredentialsBaseActivity { } @Override - protected void onResume() { - super.onResume(); - } - - @Override @OnClick(R.id.button) void handleButton() { super.handleButton(); diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java index 3fc1637e..f4e2ac5f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java @@ -89,10 +89,14 @@ public class MainActivity extends AppCompatActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (data == null) { + return; + } + if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) { if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { Provider provider = data.getParcelableExtra(Provider.KEY); - provider.storeInPreferences(preferences); + ConfigHelper.storeProviderInPreferences(preferences, provider); } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index 30504080..ae329cd1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -121,10 +121,18 @@ public final class Provider implements Parcelable { return definition; } + String getDefinitionString() { + return getDefinition().toString(); + } + protected String getDomain() { return mainUrl.getDomain(); } + String getMainUrlString() { + return getMainUrl().toString(); + } + protected DefaultedURL getMainUrl() { return mainUrl; } @@ -301,9 +309,4 @@ public final class Provider implements Parcelable { this.caCert = cert; } - public void storeInPreferences(SharedPreferences preferences) { - preferences.edit().putBoolean(PROVIDER_CONFIGURED, true). - putString(Provider.MAIN_URL, getMainUrl().toString()). - putString(Provider.KEY, getDefinition().toString()).apply(); - } } diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 69079735..61e65f2d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -170,10 +170,14 @@ public class StartActivity extends Activity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (data == null) { + return; + } + if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) { if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { Provider provider = data.getParcelableExtra(Provider.KEY); - provider.storeInPreferences(preferences); + ConfigHelper.storeProviderInPreferences(preferences, provider); showMainActivity(); } else if (resultCode == RESULT_CANCELED) { diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index dbe99dce..aae1e1ea 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -143,7 +143,7 @@ public class NavigationDrawerFragment extends Fragment { android.R.layout.simple_list_item_activated_1, android.R.id.text1); - String providerName = ConfigHelper.getCurrentProviderName(preferences); + String providerName = ConfigHelper.getProviderName(preferences); if (providerName == null) { //TODO: ADD A header to the ListView containing a useful message. //TODO 2: disable switchProvider diff --git a/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java index f7102508..53bc8f0b 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/app/src/production/java/se/leap/bitmaskclient/ConfigurationWizard.java @@ -52,6 +52,7 @@ public class ConfigurationWizard extends BaseConfigurationWizard { private void autoSelectProvider(Provider provider) { this.provider = provider; onItemSelectedLogic(); + showProgressBar(); } /** |