From 38796aeb892379b8c2b7e4e1d7af00c4c050e8dc Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 23 Nov 2017 11:34:52 +0100 Subject: Add Splash StartActivity * added Splash StartActivity to handle updates and initialization * created global Constants * renamed EIP Constants --- app/build.gradle | 5 +- .../bitmaskclient/test/TestGatewaysManager.java | 4 +- .../java/se/leap/bitmaskclient/ProviderAPI.java | 10 +- .../leap/bitmaskclient/ProviderDetailFragment.java | 8 +- app/src/main/AndroidManifest.xml | 8 ++ .../bitmaskclient/BaseConfigurationWizard.java | 8 +- .../main/java/se/leap/bitmaskclient/Constants.java | 6 ++ .../main/java/se/leap/bitmaskclient/Dashboard.java | 41 ++------ .../java/se/leap/bitmaskclient/LeapSRPSession.java | 3 - .../java/se/leap/bitmaskclient/OnBootReceiver.java | 7 +- .../se/leap/bitmaskclient/ProviderApiBase.java | 8 +- .../java/se/leap/bitmaskclient/StartActivity.java | 115 +++++++++++++++++++++ .../java/se/leap/bitmaskclient/VpnFragment.java | 33 +++--- .../java/se/leap/bitmaskclient/eip/Constants.java | 44 -------- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 4 +- .../se/leap/bitmaskclient/eip/EIPConstants.java | 44 ++++++++ .../se/leap/bitmaskclient/eip/GatewaysManager.java | 4 +- .../se/leap/bitmaskclient/eip/VoidVpnLauncher.java | 2 +- .../se/leap/bitmaskclient/eip/VoidVpnService.java | 2 +- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 4 +- .../main/res/drawable-hdpi/splash_background.png | Bin 0 -> 66619 bytes .../res/drawable-land-hdpi/splash_background.png | Bin 0 -> 68637 bytes .../res/drawable-land-ldpi/splash_background.png | Bin 0 -> 43127 bytes .../res/drawable-land-mdpi/splash_background.png | Bin 0 -> 33924 bytes .../drawable-land-xxxhdpi/splash_background.png | Bin 0 -> 182692 bytes app/src/main/res/drawable-ldpi/mask.png | Bin 0 -> 8743 bytes .../main/res/drawable-ldpi/splash_background.png | Bin 0 -> 41839 bytes app/src/main/res/drawable-mdpi/mask.png | Bin 0 -> 6324 bytes .../main/res/drawable-mdpi/splash_background.png | Bin 0 -> 32718 bytes app/src/main/res/drawable-xxxhdpi/mask.png | Bin 0 -> 43251 bytes .../res/drawable-xxxhdpi/splash_background.png | Bin 0 -> 187062 bytes app/src/main/res/drawable/splash_page.xml | 10 ++ app/src/main/res/values/attrs.xml | 8 -- app/src/main/res/values/colors.xml | 5 + app/src/main/res/values/themes.xml | 12 +++ .../java/se/leap/bitmaskclient/ProviderAPI.java | 10 +- .../leap/bitmaskclient/ProviderDetailFragment.java | 10 +- .../bitmaskclient/eip/GatewaysManagerTest.java | 4 +- build.gradle | 8 ++ 39 files changed, 280 insertions(+), 147 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/Constants.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/StartActivity.java delete mode 100644 app/src/main/java/se/leap/bitmaskclient/eip/Constants.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java create mode 100644 app/src/main/res/drawable-hdpi/splash_background.png create mode 100644 app/src/main/res/drawable-land-hdpi/splash_background.png create mode 100644 app/src/main/res/drawable-land-ldpi/splash_background.png create mode 100644 app/src/main/res/drawable-land-mdpi/splash_background.png create mode 100644 app/src/main/res/drawable-land-xxxhdpi/splash_background.png create mode 100644 app/src/main/res/drawable-ldpi/mask.png create mode 100644 app/src/main/res/drawable-ldpi/splash_background.png create mode 100644 app/src/main/res/drawable-mdpi/mask.png create mode 100644 app/src/main/res/drawable-mdpi/splash_background.png create mode 100644 app/src/main/res/drawable-xxxhdpi/mask.png create mode 100644 app/src/main/res/drawable-xxxhdpi/splash_background.png create mode 100644 app/src/main/res/drawable/splash_page.xml delete mode 100644 app/src/main/res/values/attrs.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/themes.xml diff --git a/app/build.gradle b/app/build.gradle index cdeccb6c..b9db8cd6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,8 +75,9 @@ dependencies { compile 'org.thoughtcrime.ssl.pinning:AndroidPinning:1.0.0' compile 'com.squareup.okhttp3:okhttp:3.9.0' compile 'mbanje.kurt:fabbutton:1.1.4' - compile 'com.android.support:support-annotations:25.3.1' - compile 'com.android.support:support-v4:26.0.0-alpha1' + compile 'com.android.support:support-annotations:27.0.1' + compile 'com.android.support:support-v4:26.1.0' + compile 'com.android.support:appcompat-v7:26.1.0' } def processFileInplace(file, Closure processText) { diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java index 0a76638f..b8cc9715 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestGatewaysManager.java @@ -25,7 +25,7 @@ import org.json.*; import java.io.IOException; import java.util.Arrays; -import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.Constants; import se.leap.bitmaskclient.eip.*; /** @@ -109,7 +109,7 @@ public class TestGatewaysManager extends InstrumentationTestCase { private void mockGatewaysManager() { context = getInstrumentation().getContext(); - preferences = context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE); + preferences = context.getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE); gateways_manager = new GatewaysManager(context, preferences); } diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java index 87fff283..fd6d4b79 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java @@ -45,7 +45,7 @@ import javax.net.ssl.X509TrustManager; import okhttp3.OkHttpClient; import se.leap.bitmaskclient.ProviderListContent.ProviderItem; -import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.eip.EIP; import static se.leap.bitmaskclient.R.string.certificate_error; @@ -138,8 +138,8 @@ public class ProviderAPI extends ProviderApiBase { //TODO setProviderName(name); preferences.edit().putString(Provider.KEY, provider_json.toString()).commit(); - preferences.edit().putBoolean(Constants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit(); - preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit(); + preferences.edit().putBoolean(EIPConstants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIPConstants.ALLOWED_ANON)).commit(); + preferences.edit().putBoolean(EIPConstants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIPConstants.ALLOWED_REGISTERED)).commit(); result.putBoolean(RESULT_KEY, true); } catch (JSONException e) { @@ -168,7 +168,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject eip_service_json = new JSONObject(eip_service_json_string); eip_service_json.getInt(Provider.API_RETURN_SERIAL); - preferences.edit().putString(Constants.KEY, eip_service_json.toString()).commit(); + preferences.edit().putString(EIPConstants.KEY, eip_service_json.toString()).commit(); result.putBoolean(RESULT_KEY, true); } catch (NullPointerException | JSONException e) { @@ -191,7 +191,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); String provider_main_url = provider_json.getString(Provider.API_URL); - URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.VPN_CERTIFICATE); + URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIPConstants.VPN_CERTIFICATE); String cert_string = downloadWithProviderCA(new_cert_string_url.toString(), last_danger_on); diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java index 629867e6..9c401da4 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -23,7 +23,7 @@ public class ProviderDetailFragment extends DialogFragment { LayoutInflater inflater = getActivity().getLayoutInflater(); View provider_detail_view = inflater.inflate(R.layout.provider_detail_fragment, null); - JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, "")); + JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, "")); final TextView domain = (TextView) provider_detail_view.findViewById(R.id.provider_detail_domain); domain.setText(provider_json.getString(Provider.DOMAIN)); @@ -60,7 +60,7 @@ public class ProviderDetailFragment extends DialogFragment { private boolean anon_allowed(JSONObject provider_json) { try { JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON); + return service_description.has(EIPConstants.ALLOWED_ANON) && service_description.getBoolean(EIPConstants.ALLOWED_ANON); } catch (JSONException e) { return false; } @@ -78,8 +78,8 @@ public class ProviderDetailFragment extends DialogFragment { @Override public void onCancel(DialogInterface dialog) { super.onCancel(dialog); - SharedPreferences.Editor editor = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit(); + SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); + editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(EIPConstants.ALLOWED_ANON).remove(EIPConstants.KEY).commit(); interface_with_configuration_wizard.cancelAndShowAllProviders(); } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8c6b25d5..16168e0f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -88,6 +88,14 @@ android:uiOptions="splitActionBarWhenNarrow" android:launchMode="singleTop" > + + diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 4f6163bc..5dae1227 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -51,7 +51,7 @@ import javax.inject.Inject; import butterknife.ButterKnife; import butterknife.InjectView; import butterknife.OnItemClick; -import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.userstatus.SessionDialog; import static android.view.View.GONE; @@ -134,7 +134,7 @@ public abstract class BaseConfigurationWizard extends Activity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE); + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); provider_manager = ProviderManager.getInstance(getAssets(), getExternalFilesDir(null)); @@ -220,7 +220,7 @@ public abstract class BaseConfigurationWizard extends Activity e.printStackTrace(); } - if (preferences.getBoolean(Constants.ALLOWED_ANON, false)) { + if (preferences.getBoolean(EIPConstants.ALLOWED_ANON, false)) { mConfigState.putExtra(SERVICES_RETRIEVED, true); downloadVpnCertificate(); @@ -297,7 +297,7 @@ public abstract class BaseConfigurationWizard extends Activity public void cancelSettingUpProvider() { mConfigState.setAction(PROVIDER_NOT_SET); adapter.showAllProviders(); - preferences.edit().remove(Provider.KEY).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).apply(); + preferences.edit().remove(Provider.KEY).remove(EIPConstants.ALLOWED_ANON).remove(EIPConstants.KEY).apply(); } private void askDashboardToQuitApp() { diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java new file mode 100644 index 00000000..4ce09892 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java @@ -0,0 +1,6 @@ +package se.leap.bitmaskclient; + +public interface Constants { + String SHARED_PREFERENCES = "LEAPPreferences"; + String PREFERENCES_APP_VERSION = "bitmask version"; +} diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 3f1663d0..e2366551 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -1,20 +1,4 @@ -/** - * Copyright (c) 2013 LEAP Encryption Access Project and contributers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -/** +/* * Copyright (c) 2013 LEAP Encryption Access Project and contributers * * This program is free software: you can redistribute it and/or modify @@ -57,8 +41,7 @@ import java.net.URL; import butterknife.ButterKnife; import butterknife.InjectView; -import de.blinkt.openvpn.core.VpnStatus; -import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.userstatus.SessionDialog; import se.leap.bitmaskclient.userstatus.User; import se.leap.bitmaskclient.userstatus.UserStatusFragment; @@ -76,7 +59,6 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec protected static final int SWITCH_PROVIDER = 1; public static final String TAG = Dashboard.class.getSimpleName(); - public static final String SHARED_PREFERENCES = "LEAPPreferences"; public static final String ACTION_QUIT = "quit"; public static final String ACTION_ASK_TO_CANCEL_VPN = "ask to cancel vpn"; public static final String REQUEST_CODE = "request_code"; @@ -84,7 +66,6 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec public static final String START_ON_BOOT = "dashboard start on boot"; //FIXME: remove OR FIX ON_BOOT public static final String ON_BOOT = "dashboard on boot"; - public static final String APP_VERSION = "bitmask version"; private static Context app; protected static SharedPreferences preferences; @@ -102,18 +83,14 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); - ProviderAPICommand.initialize(this); providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), this); if (app == null) { app = this; - - VpnStatus.initLogCache(getApplicationContext().getCacheDir()); handleVersion(); - User.init(getString(R.string.default_username)); } boolean provider_exists = previousProviderExists(savedInstanceState); if (provider_exists) { @@ -154,7 +131,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec private boolean providerInSharedPreferences() { return preferences != null && - preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false); + preferences.getBoolean(EIPConstants.PROVIDER_CONFIGURED, false); } @@ -179,13 +156,11 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec private void handleVersion() { try { int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; - int lastDetectedVersion = preferences.getInt(APP_VERSION, 0); - preferences.edit().putInt(APP_VERSION, versionCode).apply(); switch (versionCode) { case 91: // 0.6.0 without Bug #5999 case 101: // 0.8.0 - if (!preferences.getString(Constants.KEY, "").isEmpty()) + if (!preferences.getString(EIPConstants.KEY, "").isEmpty()) eip_fragment.updateEipService(); break; } @@ -230,7 +205,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec @SuppressLint("CommitPrefEdits") private void providerToPreferences(Provider provider) { - preferences.edit().putBoolean(Constants.PROVIDER_CONFIGURED, true).commit(); + preferences.edit().putBoolean(EIPConstants.PROVIDER_CONFIGURED, true).commit(); preferences.edit().putString(Provider.MAIN_URL, provider.mainUrl().toString()).apply(); preferences.edit().putString(Provider.KEY, provider.definition().toString()).apply(); } @@ -250,7 +225,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec .setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_CONFIGURED).apply(); + preferences.edit().remove(Provider.KEY).remove(EIPConstants.PROVIDER_CONFIGURED).apply(); finish(); } }) @@ -341,7 +316,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec public void downloadVpnCertificate() { boolean is_authenticated = User.loggedIn(); - boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false); + boolean allowed_anon = preferences.getBoolean(EIPConstants.ALLOWED_ANON, false); if (allowed_anon || is_authenticated) ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_CERTIFICATE, providerAPI_result_receiver); else diff --git a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java index 49cf3774..3a1fd6e0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java +++ b/app/src/main/java/se/leap/bitmaskclient/LeapSRPSession.java @@ -72,7 +72,6 @@ public class LeapSRPSession { * * @param username, the user ID * @param password, the user clear text password - * @param params, the SRP parameters for the session */ public LeapSRPSession(String username, String password) { this(username, password, null); @@ -84,7 +83,6 @@ public class LeapSRPSession { * * @param username, the user ID * @param password, the user clear text password - * @param params, the SRP parameters for the session * @param abytes, the random exponent used in the A public key */ public LeapSRPSession(String username, String password, byte[] abytes) { @@ -187,7 +185,6 @@ public class LeapSRPSession { * * @param b1 the positive source to build first BigInteger * @param b2 the positive source to build second BigInteger - * @param length * @return */ public byte[] xor(byte[] b1, byte[] b2) { diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java index 9171e816..a72a8809 100644 --- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java @@ -2,7 +2,8 @@ package se.leap.bitmaskclient; import android.content.*; -import se.leap.bitmaskclient.eip.*; +import se.leap.bitmaskclient.eip.EIPConstants; + public class OnBootReceiver extends BroadcastReceiver { @@ -11,12 +12,12 @@ public class OnBootReceiver extends BroadcastReceiver { // Debug: am broadcast -a android.intent.action.BOOT_COMPLETED @Override public void onReceive(Context context, Intent intent) { - preferences = context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE); + preferences = context.getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE); boolean provider_configured = !preferences.getString(Provider.KEY, "").isEmpty(); boolean start_on_boot = preferences.getBoolean(Dashboard.START_ON_BOOT, false); if (provider_configured && start_on_boot) { Intent dashboard_intent = new Intent(context, Dashboard.class); - dashboard_intent.setAction(Constants.ACTION_START_EIP); + dashboard_intent.setAction(EIPConstants.ACTION_START_EIP); dashboard_intent.putExtra(Dashboard.ON_BOOT, true); dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(dashboard_intent); diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java index acac607c..81852983 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java @@ -67,7 +67,7 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.TlsVersion; -import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.userstatus.SessionDialog; import se.leap.bitmaskclient.userstatus.User; import se.leap.bitmaskclient.userstatus.UserStatus; @@ -151,7 +151,7 @@ public abstract class ProviderApiBase extends IntentService { public void onCreate() { super.onCreate(); - preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE); + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); resources = getResources(); } @@ -817,11 +817,11 @@ public abstract class ProviderApiBase extends IntentService { RSAPrivateKey key = ConfigHelper.parseRsaKeyFromString(keyString); keyString = Base64.encodeToString(key.getEncoded(), Base64.DEFAULT); - preferences.edit().putString(Constants.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----").commit(); + preferences.edit().putString(EIPConstants.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----").commit(); X509Certificate certificate = ConfigHelper.parseX509CertificateFromString(certificateString); certificateString = Base64.encodeToString(certificate.getEncoded(), Base64.DEFAULT); - preferences.edit().putString(Constants.VPN_CERTIFICATE, "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----").commit(); + preferences.edit().putString(EIPConstants.VPN_CERTIFICATE, "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----").commit(); return true; } catch (CertificateException e) { // TODO Auto-generated catch block diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java new file mode 100644 index 00000000..410daf7d --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -0,0 +1,115 @@ +package se.leap.bitmaskclient; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.support.annotation.IntDef; +import android.support.annotation.Nullable; +import android.util.Log; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import de.blinkt.openvpn.core.VpnStatus; +import se.leap.bitmaskclient.userstatus.User; + +/** + * Activity shown at startup. Evaluates if App is started for the first time or has been upgraded + * and acts and calls another activity accordingly. + * + */ +public class StartActivity extends Activity { + public static final String TAG = Dashboard.class.getSimpleName(); + + @Retention(RetentionPolicy.SOURCE) + @IntDef({FIRST, NORMAL, UPGRADE, DOWNGRADE}) + private @interface StartupMode {} + private static final int FIRST = 0; + private static final int NORMAL = 1; + private static final int UPGRADE = 2; + private static final int DOWNGRADE = 3; + + /** + * check if normal start, first run, up or downgrade + * @return @StartupMode + */ + @StartupMode + private int checkAppStart() { + SharedPreferences preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); + try { + int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; + int lastDetectedVersion = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1); + + // versions do match -> normal start + if (versionCode == lastDetectedVersion) { + Log.d(TAG, "App start was: NORMAL START"); + return NORMAL; + } + + // something changed -> save current version + preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); + + // no previous app version -> first start + if (lastDetectedVersion == -1 ) { + Log.d(TAG, "App start was: FIRST START"); + return FIRST; + } + + // version has increased -> upgrade + if (versionCode > lastDetectedVersion) { + Log.d(TAG, "App start was: UPGRADE"); + return UPGRADE; + } + // version has decreased -> downgrade + if (versionCode < lastDetectedVersion) { + Log.d(TAG, "App start was: DOWNGRADE"); + return DOWNGRADE; + } + + } catch (PackageManager.NameNotFoundException e) { + Log.d(TAG, "Splash screen didn't find any " + getPackageName() + " package"); + } + + return NORMAL; + } + + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent intent; + + Log.d(TAG, "Started"); + + switch (checkAppStart()) { + case NORMAL: + break; + + case FIRST: + // TODO start ProfileCreation & replace below code + intent = new Intent(this, Dashboard.class); + startActivity(intent); + break; + + case UPGRADE: + // TODO appropriate data copying + // TODO show donation dialog + break; + + case DOWNGRADE: + // TODO think how and why this should happen and what todo + break; + } + + // initialize app necessities + ProviderAPICommand.initialize(this); + VpnStatus.initLogCache(getApplicationContext().getCacheDir()); + User.init(getString(R.string.default_username)); + + // go to Dashboard + intent = new Intent(this, Dashboard.class); + startActivity(intent); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java index c85b0151..eff02193 100644 --- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java @@ -33,7 +33,10 @@ import de.blinkt.openvpn.core.OpenVPNService; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; import mbanje.kurt.fabbutton.*; -import se.leap.bitmaskclient.eip.*; +import se.leap.bitmaskclient.eip.EIPConstants; +import se.leap.bitmaskclient.eip.EIP; +import se.leap.bitmaskclient.eip.EipStatus; +import se.leap.bitmaskclient.eip.VoidVpnService; public class VpnFragment extends Fragment implements Observer { @@ -112,7 +115,7 @@ public class VpnFragment extends Fragment implements Observer { public void onResume() { super.onResume(); //FIXME: avoid race conditions while checking certificate an logging in at about the same time - //eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY); + //eipCommand(EIPConstants.ACTION_CHECK_CERT_VALIDITY); handleNewState(eip_status); bindOpenVpnService(); } @@ -161,13 +164,13 @@ public class VpnFragment extends Fragment implements Observer { } private boolean canStartEIP() { - boolean certificateExists = !Dashboard.preferences.getString(Constants.VPN_CERTIFICATE, "").isEmpty(); - boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false); + boolean certificateExists = !Dashboard.preferences.getString(EIPConstants.VPN_CERTIFICATE, "").isEmpty(); + boolean isAllowedAnon = Dashboard.preferences.getBoolean(EIPConstants.ALLOWED_ANON, false); return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting(); } private boolean canLogInToStartEIP() { - boolean isAllowedRegistered = Dashboard.preferences.getBoolean(Constants.ALLOWED_REGISTERED, false); + boolean isAllowedRegistered = Dashboard.preferences.getBoolean(EIPConstants.ALLOWED_REGISTERED, false); boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty(); return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); } @@ -204,7 +207,7 @@ public class VpnFragment extends Fragment implements Observer { eip_status.setConnecting(); saveStatus(); - eipCommand(Constants.ACTION_START_EIP); + eipCommand(EIPConstants.ACTION_START_EIP); } private void stop() { @@ -227,7 +230,7 @@ public class VpnFragment extends Fragment implements Observer { } protected void stopEipIfPossible() { - eipCommand(Constants.ACTION_STOP_EIP); + eipCommand(EIPConstants.ACTION_STOP_EIP); } private void downloadEIPServiceConfig() { @@ -255,7 +258,7 @@ public class VpnFragment extends Fragment implements Observer { } protected void updateEipService() { - eipCommand(Constants.ACTION_UPDATE_EIP_SERVICE); + eipCommand(EIPConstants.ACTION_UPDATE_EIP_SERVICE); } /** @@ -268,7 +271,7 @@ public class VpnFragment extends Fragment implements Observer { // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); vpn_intent.setAction(action); - vpn_intent.putExtra(Constants.RECEIVER_TAG, eip_receiver); + vpn_intent.putExtra(EIPConstants.RECEIVER_TAG, eip_receiver); dashboard.startService(vpn_intent); } @@ -341,9 +344,9 @@ public class VpnFragment extends Fragment implements Observer { protected void onReceiveResult(int resultCode, Bundle resultData) { super.onReceiveResult(resultCode, resultData); - String request = resultData.getString(Constants.REQUEST_TAG); + String request = resultData.getString(EIPConstants.REQUEST_TAG); - if (request.equals(Constants.ACTION_START_EIP)) { + if (request.equals(EIPConstants.ACTION_START_EIP)) { switch (resultCode) { case Activity.RESULT_OK: break; @@ -351,7 +354,7 @@ public class VpnFragment extends Fragment implements Observer { break; } - } else if (request.equals(Constants.ACTION_STOP_EIP)) { + } else if (request.equals(EIPConstants.ACTION_STOP_EIP)) { switch (resultCode) { case Activity.RESULT_OK: stop(); @@ -359,14 +362,14 @@ public class VpnFragment extends Fragment implements Observer { case Activity.RESULT_CANCELED: break; } - } else if (request.equals(Constants.EIP_NOTIFICATION)) { + } else if (request.equals(EIPConstants.EIP_NOTIFICATION)) { switch (resultCode) { case Activity.RESULT_OK: break; case Activity.RESULT_CANCELED: break; } - } else if (request.equals(Constants.ACTION_CHECK_CERT_VALIDITY)) { + } else if (request.equals(EIPConstants.ACTION_CHECK_CERT_VALIDITY)) { switch (resultCode) { case Activity.RESULT_OK: break; @@ -374,7 +377,7 @@ public class VpnFragment extends Fragment implements Observer { dashboard.downloadVpnCertificate(); break; } - } else if (request.equals(Constants.ACTION_UPDATE_EIP_SERVICE)) { + } else if (request.equals(EIPConstants.ACTION_UPDATE_EIP_SERVICE)) { switch (resultCode) { case Activity.RESULT_OK: if (wants_to_connect) diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java b/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java deleted file mode 100644 index db1cb4a1..00000000 --- a/app/src/main/java/se/leap/bitmaskclient/eip/Constants.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2013 LEAP Encryption Access Project and contributers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package se.leap.bitmaskclient.eip; - -/** - * Constants for intent passing, shared preferences - * - * @author Parménides GV - */ -public interface Constants { - - public final static String TAG = Constants.class.getSimpleName(); - - public final static String ACTION_CHECK_CERT_VALIDITY = TAG + ".CHECK_CERT_VALIDITY"; - public final static String ACTION_START_EIP = TAG + ".START_EIP"; - public final static String ACTION_STOP_EIP = TAG + ".STOP_EIP"; - public final static String ACTION_UPDATE_EIP_SERVICE = TAG + ".UPDATE_EIP_SERVICE"; - public final static String ACTION_IS_EIP_RUNNING = TAG + ".IS_RUNNING"; - public final static String EIP_NOTIFICATION = TAG + ".EIP_NOTIFICATION"; - public final static String ALLOWED_ANON = "allow_anonymous"; - public final static String ALLOWED_REGISTERED = "allow_registration"; - public final static String VPN_CERTIFICATE = "cert"; - public final static String PRIVATE_KEY = TAG + ".PRIVATE_KEY"; - public final static String KEY = TAG + ".KEY"; - public final static String RECEIVER_TAG = TAG + ".RECEIVER_TAG"; - public final static String REQUEST_TAG = TAG + ".REQUEST_TAG"; - public final static String START_BLOCKING_VPN_PROFILE = TAG + ".START_BLOCKING_VPN_PROFILE"; - public final static String PROVIDER_CONFIGURED = TAG + ".PROVIDER_CONFIGURED"; - -} diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 28a9bb50..8bbdf901 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -25,7 +25,7 @@ import org.json.*; import de.blinkt.openvpn.*; import se.leap.bitmaskclient.*; -import static se.leap.bitmaskclient.eip.Constants.*; +import static se.leap.bitmaskclient.eip.EIPConstants.*; /** * EIP is the abstract base class for interacting with and managing the Encrypted @@ -59,7 +59,7 @@ public final class EIP extends IntentService { super.onCreate(); context = getApplicationContext(); - preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE); + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); eip_definition = eipDefinitionFromPreferences(); if (gateways_manager.isEmpty()) gatewaysFromPreferences(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java new file mode 100644 index 00000000..a56868f1 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2013 LEAP Encryption Access Project and contributers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package se.leap.bitmaskclient.eip; + +/** + * EIPConstants for intent passing, shared preferences + * + * @author Parménides GV + */ +public interface EIPConstants { + + String TAG = "Constants"; + + String ACTION_CHECK_CERT_VALIDITY = TAG + ".CHECK_CERT_VALIDITY"; + String ACTION_START_EIP = TAG + ".START_EIP"; + String ACTION_STOP_EIP = TAG + ".STOP_EIP"; + String ACTION_UPDATE_EIP_SERVICE = TAG + ".UPDATE_EIP_SERVICE"; + String ACTION_IS_EIP_RUNNING = TAG + ".IS_RUNNING"; + String EIP_NOTIFICATION = TAG + ".EIP_NOTIFICATION"; + String ALLOWED_ANON = "allow_anonymous"; + String ALLOWED_REGISTERED = "allow_registration"; + String VPN_CERTIFICATE = "cert"; + String PRIVATE_KEY = TAG + ".PRIVATE_KEY"; + String KEY = TAG + ".KEY"; + String RECEIVER_TAG = TAG + ".RECEIVER_TAG"; + String REQUEST_TAG = TAG + ".REQUEST_TAG"; + String START_BLOCKING_VPN_PROFILE = TAG + ".START_BLOCKING_VPN_PROFILE"; + String PROVIDER_CONFIGURED = TAG + ".PROVIDER_CONFIGURED"; + +} diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 177f553e..25c99098 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -123,8 +123,8 @@ public class GatewaysManager { JSONObject result = new JSONObject(); try { result.put(Provider.CA_CERT, preferences.getString(Provider.CA_CERT, "")); - result.put(Constants.PRIVATE_KEY, preferences.getString(Constants.PRIVATE_KEY, "")); - result.put(Constants.VPN_CERTIFICATE, preferences.getString(Constants.VPN_CERTIFICATE, "")); + result.put(EIPConstants.PRIVATE_KEY, preferences.getString(EIPConstants.PRIVATE_KEY, "")); + result.put(EIPConstants.VPN_CERTIFICATE, preferences.getString(EIPConstants.VPN_CERTIFICATE, "")); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java index 5c9263b3..8ce8aa81 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java @@ -28,7 +28,7 @@ public class VoidVpnLauncher extends Activity { if (requestCode == VPN_USER_PERMISSION) { if (resultCode == RESULT_OK) { Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class); - void_vpn_service.setAction(Constants.START_BLOCKING_VPN_PROFILE); + void_vpn_service.setAction(EIPConstants.START_BLOCKING_VPN_PROFILE); startService(void_vpn_service); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index cbf0fed2..629b4304 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -16,7 +16,7 @@ public class VoidVpnService extends VpnService { @Override public int onStartCommand(Intent intent, int flags, int startId) { String action = intent != null ? intent.getAction() : ""; - if (action == Constants.START_BLOCKING_VPN_PROFILE) { + if (action == EIPConstants.START_BLOCKING_VPN_PROFILE) { thread = new Thread(new Runnable() { public void run() { Builder builder = new Builder(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index f428099e..33993139 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -118,14 +118,14 @@ public class VpnConfigGenerator { String key = "" + new_line - + secrets.getString(Constants.PRIVATE_KEY) + + secrets.getString(EIPConstants.PRIVATE_KEY) + new_line + ""; String openvpn_cert = "" + new_line - + secrets.getString(Constants.VPN_CERTIFICATE) + + secrets.getString(EIPConstants.VPN_CERTIFICATE) + new_line + ""; diff --git a/app/src/main/res/drawable-hdpi/splash_background.png b/app/src/main/res/drawable-hdpi/splash_background.png new file mode 100644 index 00000000..11dfd005 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/splash_background.png differ diff --git a/app/src/main/res/drawable-land-hdpi/splash_background.png b/app/src/main/res/drawable-land-hdpi/splash_background.png new file mode 100644 index 00000000..c2e123ce Binary files /dev/null and b/app/src/main/res/drawable-land-hdpi/splash_background.png differ diff --git a/app/src/main/res/drawable-land-ldpi/splash_background.png b/app/src/main/res/drawable-land-ldpi/splash_background.png new file mode 100644 index 00000000..29f9e7cb Binary files /dev/null and b/app/src/main/res/drawable-land-ldpi/splash_background.png differ diff --git a/app/src/main/res/drawable-land-mdpi/splash_background.png b/app/src/main/res/drawable-land-mdpi/splash_background.png new file mode 100644 index 00000000..bf43f632 Binary files /dev/null and b/app/src/main/res/drawable-land-mdpi/splash_background.png differ diff --git a/app/src/main/res/drawable-land-xxxhdpi/splash_background.png b/app/src/main/res/drawable-land-xxxhdpi/splash_background.png new file mode 100644 index 00000000..12a9e8a8 Binary files /dev/null and b/app/src/main/res/drawable-land-xxxhdpi/splash_background.png differ diff --git a/app/src/main/res/drawable-ldpi/mask.png b/app/src/main/res/drawable-ldpi/mask.png new file mode 100644 index 00000000..4e22d99f Binary files /dev/null and b/app/src/main/res/drawable-ldpi/mask.png differ diff --git a/app/src/main/res/drawable-ldpi/splash_background.png b/app/src/main/res/drawable-ldpi/splash_background.png new file mode 100644 index 00000000..eaae5efb Binary files /dev/null and b/app/src/main/res/drawable-ldpi/splash_background.png differ diff --git a/app/src/main/res/drawable-mdpi/mask.png b/app/src/main/res/drawable-mdpi/mask.png new file mode 100644 index 00000000..e53cb15c Binary files /dev/null and b/app/src/main/res/drawable-mdpi/mask.png differ diff --git a/app/src/main/res/drawable-mdpi/splash_background.png b/app/src/main/res/drawable-mdpi/splash_background.png new file mode 100644 index 00000000..4df57929 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/splash_background.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/mask.png b/app/src/main/res/drawable-xxxhdpi/mask.png new file mode 100644 index 00000000..4297d90c Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/mask.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/splash_background.png b/app/src/main/res/drawable-xxxhdpi/splash_background.png new file mode 100644 index 00000000..4ad0e2c3 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/splash_background.png differ diff --git a/app/src/main/res/drawable/splash_page.xml b/app/src/main/res/drawable/splash_page.xml new file mode 100644 index 00000000..1d8a6bf6 --- /dev/null +++ b/app/src/main/res/drawable/splash_page.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml deleted file mode 100644 index cb503b86..00000000 --- a/app/src/main/res/values/attrs.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..9f5d8813 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #8080b0 + #555575 + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 00000000..80607409 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java index 70a2c27c..eebc54c1 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java @@ -33,7 +33,7 @@ import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLHandshakeException; import okhttp3.OkHttpClient; -import se.leap.bitmaskclient.eip.Constants; +import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.eip.EIP; import static se.leap.bitmaskclient.R.string.error_io_exception_user_message; @@ -120,8 +120,8 @@ public class ProviderAPI extends ProviderApiBase { //TODO setProviderName(name); preferences.edit().putString(Provider.KEY, provider_json.toString()).commit(); - preferences.edit().putBoolean(Constants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit(); - preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit(); + preferences.edit().putBoolean(EIPConstants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIPConstants.ALLOWED_ANON)).commit(); + preferences.edit().putBoolean(EIPConstants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIPConstants.ALLOWED_REGISTERED)).commit(); result.putBoolean(RESULT_KEY, true); } catch (JSONException e) { @@ -150,7 +150,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject eip_service_json = new JSONObject(eip_service_json_string); eip_service_json.getInt(Provider.API_RETURN_SERIAL); - preferences.edit().putString(Constants.KEY, eip_service_json.toString()).commit(); + preferences.edit().putString(EIPConstants.KEY, eip_service_json.toString()).commit(); result.putBoolean(RESULT_KEY, true); } catch (NullPointerException | JSONException e) { @@ -173,7 +173,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); String provider_main_url = provider_json.getString(Provider.API_URL); - URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.VPN_CERTIFICATE); + URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIPConstants.VPN_CERTIFICATE); String cert_string = downloadWithProviderCA(new_cert_string_url.toString()); diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java index da7f8763..bd4c0d72 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -2,7 +2,7 @@ package se.leap.bitmaskclient; import org.json.*; -import se.leap.bitmaskclient.eip.*; +import se.leap.bitmaskclient.eip.EIPConstants; import android.app.*; import android.content.*; @@ -22,7 +22,7 @@ public class ProviderDetailFragment extends DialogFragment { LayoutInflater inflater = getActivity().getLayoutInflater(); View provider_detail_view = inflater.inflate(R.layout.provider_detail_fragment, null); - JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, "")); + JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, "")); final TextView domain = (TextView) provider_detail_view.findViewById(R.id.provider_detail_domain); domain.setText(provider_json.getString(Provider.DOMAIN)); @@ -59,7 +59,7 @@ public class ProviderDetailFragment extends DialogFragment { private boolean anon_allowed(JSONObject provider_json) { try { JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON); + return service_description.has(EIPConstants.ALLOWED_ANON) && service_description.getBoolean(EIPConstants.ALLOWED_ANON); } catch (JSONException e) { return false; } @@ -77,8 +77,8 @@ public class ProviderDetailFragment extends DialogFragment { @Override public void onCancel(DialogInterface dialog) { super.onCancel(dialog); - SharedPreferences.Editor editor = getActivity().getSharedPreferences(Dashboard.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit(); + SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); + editor.remove(Provider.KEY).remove(EIPConstants.ALLOWED_ANON).remove(EIPConstants.KEY).commit(); interface_with_configuration_wizard.cancelAndShowAllProviders(); } diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java index 833346fa..291d027e 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -42,9 +42,9 @@ public class GatewaysManagerTest { JSONObject secrets = new JSONObject(getJsonStringFor("secrets.json")); - when(sharedPreferences.getString(eq(Constants.PRIVATE_KEY), anyString())).thenReturn(secrets.getString(Constants.PRIVATE_KEY)); + when(sharedPreferences.getString(eq(EIPConstants.PRIVATE_KEY), anyString())).thenReturn(secrets.getString(EIPConstants.PRIVATE_KEY)); when(sharedPreferences.getString(eq(Provider.CA_CERT), anyString())).thenReturn(secrets.getString(Provider.CA_CERT)); - when(sharedPreferences.getString(eq(Constants.VPN_CERTIFICATE), anyString())).thenReturn(secrets.getString(Constants.VPN_CERTIFICATE)); + when(sharedPreferences.getString(eq(EIPConstants.VPN_CERTIFICATE), anyString())).thenReturn(secrets.getString(EIPConstants.VPN_CERTIFICATE)); when(mockContext.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPreferences); diff --git a/build.gradle b/build.gradle index dc2396d7..3970daf0 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,10 @@ buildscript { repositories { mavenCentral() jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } dependencies { classpath 'com.android.tools.build:gradle:2.3.1' @@ -16,5 +20,9 @@ allprojects { repositories { mavenCentral() jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } } -- cgit v1.2.3 From 21ea067cf29becf6ea85a56fa258259e8c5208b0 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 28 Nov 2017 01:51:19 +0100 Subject: base for sidebar --- app/build.gradle | 7 +- app/src/main/AndroidManifest.xml | 99 ++++---- .../java/se/leap/bitmaskclient/MainActivity.java | 115 +++++++++ .../bitmaskclient/NavigationDrawerFragment.java | 282 +++++++++++++++++++++ .../java/se/leap/bitmaskclient/StartActivity.java | 2 +- app/src/main/res/drawable-hdpi/drawer_shadow.9.png | Bin 0 -> 161 bytes app/src/main/res/drawable-hdpi/ic_drawer.png | Bin 0 -> 2829 bytes app/src/main/res/drawable-mdpi/drawer_shadow.9.png | Bin 0 -> 142 bytes app/src/main/res/drawable-mdpi/ic_drawer.png | Bin 0 -> 2820 bytes .../main/res/drawable-xhdpi/drawer_shadow.9.png | Bin 0 -> 174 bytes app/src/main/res/drawable-xhdpi/ic_drawer.png | Bin 0 -> 2836 bytes .../main/res/drawable-xxhdpi/drawer_shadow.9.png | Bin 0 -> 208 bytes app/src/main/res/drawable-xxhdpi/ic_drawer.png | Bin 0 -> 202 bytes app/src/main/res/layout/activity_main.xml | 42 +++ app/src/main/res/layout/drawer_main.xml | 22 ++ app/src/main/res/layout/fragment_main.xml | 16 ++ app/src/main/res/menu/main.xml | 13 + app/src/main/res/values-w820dp/dimens.xml | 6 + app/src/main/res/values/dimens.xml | 10 +- app/src/main/res/values/strings.xml | 14 +- app/src/main/res/values/themes.xml | 2 +- 21 files changed, 568 insertions(+), 62 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/MainActivity.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java create mode 100644 app/src/main/res/drawable-hdpi/drawer_shadow.9.png create mode 100644 app/src/main/res/drawable-hdpi/ic_drawer.png create mode 100644 app/src/main/res/drawable-mdpi/drawer_shadow.9.png create mode 100644 app/src/main/res/drawable-mdpi/ic_drawer.png create mode 100644 app/src/main/res/drawable-xhdpi/drawer_shadow.9.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_drawer.png create mode 100644 app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_drawer.png create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/drawer_main.xml create mode 100644 app/src/main/res/layout/fragment_main.xml create mode 100644 app/src/main/res/menu/main.xml create mode 100644 app/src/main/res/values-w820dp/dimens.xml diff --git a/app/build.gradle b/app/build.gradle index b9db8cd6..c19309fc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,6 +78,8 @@ dependencies { compile 'com.android.support:support-annotations:27.0.1' compile 'com.android.support:support-v4:26.1.0' compile 'com.android.support:appcompat-v7:26.1.0' + compile 'com.android.support:design:26.1.0' + compile 'com.android.support:support-fragment:26.1.0' } def processFileInplace(file, Closure processText) { @@ -100,8 +102,6 @@ task copyIcsOpenVPNClasses( type: Copy ) { include '**/log_fragment.xml' include '**/log_silders.xml' include '**/vpnstatus.xml' - include '**/styles.xml' - include '**/dimens.xml' include '**/logmenu.xml' include '**/core/**.java' include '**/activities/BaseActivity.java' @@ -129,10 +129,7 @@ task copyIcsOpenVPNXml( type: Copy ) { include '**/strings.xml' include '**/log_*.xml' include '**/vpnstatus.xml' - include '**/styles.xml' - include '**/dimens.xml' include '**/refs.xml' - include '**/colours.xml' include '**/logmenu.xml' include '**/white_rect.xml' include '**/plurals.xml' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 16168e0f..72d2ce54 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - - - + android:versionName="0.9.7"> + + - - - + + + - + android:logo="@drawable/icon" + android:theme="@style/AppTheme"> - @@ -53,50 +52,42 @@ - - + + - - - + android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> + + + - - - + android:name=".eip.VoidVpnLauncher" + android:theme="@android:style/Theme.Translucent.NoTitleBar" /> + - - + android:label="@string/vpn_launch_title"> - - + android:uiOptions="splitActionBarWhenNarrow"> - + android:theme="@style/SplashTheme"> @@ -104,22 +95,26 @@ - + android:uiOptions="splitActionBarWhenNarrow"> - - - + android:name=".AboutActivity" + android:label="@string/title_about_activity"> + + - - - + + + + + - + \ No newline at end of file diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java new file mode 100644 index 00000000..d28d0784 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java @@ -0,0 +1,115 @@ +package se.leap.bitmaskclient; + + +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.support.v4.widget.DrawerLayout; + +public class MainActivity extends AppCompatActivity + implements NavigationDrawerFragment.NavigationDrawerCallbacks { + + /** + * Fragment managing the behaviors, interactions and presentation of the navigation drawer. + */ + private NavigationDrawerFragment mNavigationDrawerFragment; + + /** + * Used to store the last screen title. For use in {@link #restoreActionBar()}. + */ + private CharSequence mTitle; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); + + mNavigationDrawerFragment = (NavigationDrawerFragment) + getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); + mTitle = getTitle(); + + // Set up the drawer. + mNavigationDrawerFragment.setUp( + R.id.navigation_drawer, + (DrawerLayout) findViewById(R.id.drawer_layout)); + } + + @Override + public void onNavigationDrawerItemSelected(int position) { + // update the main content by replacing fragments + FragmentManager fragmentManager = getSupportFragmentManager(); + fragmentManager.beginTransaction() + .replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) + .commit(); + } + + public void onSectionAttached(int number) { + switch (number) { + case 1: + mTitle = getString(R.string.title_section1); + break; + case 2: + mTitle = getString(R.string.title_section2); + break; + case 3: + mTitle = getString(R.string.title_section3); + break; + } + } + + public void restoreActionBar() { + ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setTitle(mTitle); + } + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + /** + * The fragment argument representing the section number for this + * fragment. + */ + private static final String ARG_SECTION_NUMBER = "section_number"; + + public PlaceholderFragment() { + } + + /** + * Returns a new instance of this fragment for the given section + * number. + */ + public static PlaceholderFragment newInstance(int sectionNumber) { + PlaceholderFragment fragment = new PlaceholderFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + fragment.setArguments(args); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_main, container, false); + return rootView; + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + ((MainActivity) context).onSectionAttached( + getArguments().getInt(ARG_SECTION_NUMBER)); + } + } + +} diff --git a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java new file mode 100644 index 00000000..22a4f8a0 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java @@ -0,0 +1,282 @@ +package se.leap.bitmaskclient; + + +import android.content.Context; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v4.app.Fragment; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +/** + * Fragment used for managing interactions for and presentation of a navigation drawer. + * See the + * design guidelines for a complete explanation of the behaviors implemented here. + */ +public class NavigationDrawerFragment extends Fragment { + + /** + * Remember the position of the selected item. + */ + private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; + + /** + * Per the design guidelines, you should show the drawer on launch until the user manually + * expands it. This shared preference tracks this. + */ + private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; + + /** + * A pointer to the current callbacks instance (the Activity). + */ + private NavigationDrawerCallbacks mCallbacks; + + /** + * Helper component that ties the action bar to the navigation drawer. + */ + private ActionBarDrawerToggle mDrawerToggle; + + private DrawerLayout mDrawerLayout; + private View mDrawerView; + private ListView mDrawerListView; + private View mFragmentContainerView; + + private int mCurrentSelectedPosition = 0; + private boolean mFromSavedInstanceState; + private boolean mUserLearnedDrawer; + + public NavigationDrawerFragment() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Read in the flag indicating whether or not the user has demonstrated awareness of the + // drawer. See PREF_USER_LEARNED_DRAWER for details. + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); + mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); + + if (savedInstanceState != null) { + mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); + mFromSavedInstanceState = true; + } + + // Select either the default item (0) or the last selected item. + selectItem(mCurrentSelectedPosition); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + // Indicate that this fragment would like to influence the set of actions in the action bar. + setHasOptionsMenu(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mDrawerView = inflater.inflate(R.layout.drawer_main, container, false); + return mDrawerView; + } + + public boolean isDrawerOpen() { + return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); + } + + /** + * Users of this fragment must call this method to set up the navigation drawer interactions. + * + * @param fragmentId The android:id of this fragment in its activity's layout. + * @param drawerLayout The DrawerLayout containing this fragment's UI. + */ + public void setUp(int fragmentId, DrawerLayout drawerLayout) { + AppCompatActivity activity = (AppCompatActivity) getActivity(); + + mDrawerListView = mDrawerView.findViewById(R.id.accountList); + mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(position); + } + }); + + ActionBar actionBar = activity.getSupportActionBar(); + mDrawerListView.setAdapter(new ArrayAdapter( + actionBar.getThemedContext(), + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + new String[]{ + getString(R.string.title_section1), + getString(R.string.title_section2), + getString(R.string.title_section3), + })); + mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); + mFragmentContainerView = activity.findViewById(fragmentId); + mDrawerLayout = drawerLayout; + + // set a custom shadow that overlays the main content when the drawer opens + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); + + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + // ActionBarDrawerToggle ties together the the proper interactions + // between the navigation drawer and the action bar app icon. + mDrawerToggle = new ActionBarDrawerToggle( + getActivity(), + mDrawerLayout, + (Toolbar) drawerLayout.findViewById(R.id.toolbar), + R.string.navigation_drawer_open, + R.string.navigation_drawer_close + ) { + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + if (!isAdded()) { + return; + } + + getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + if (!isAdded()) { + return; + } + + if (!mUserLearnedDrawer) { + // The user manually opened the drawer; store this flag to prevent auto-showing + // the navigation drawer automatically in the future. + mUserLearnedDrawer = true; + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences(getActivity()); + sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); + } + + getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + }; + + // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, + // per the navigation drawer design guidelines. + if (!mUserLearnedDrawer && !mFromSavedInstanceState) { + mDrawerLayout.openDrawer(mFragmentContainerView); + } + + // Defer code dependent on restoration of previous instance state. + mDrawerLayout.post(new Runnable() { + @Override + public void run() { + mDrawerToggle.syncState(); + } + }); + + mDrawerLayout.addDrawerListener(mDrawerToggle); + } + + private void selectItem(int position) { + mCurrentSelectedPosition = position; + if (mDrawerListView != null) { + mDrawerListView.setItemChecked(position, true); + } + if (mDrawerLayout != null) { + mDrawerLayout.closeDrawer(mFragmentContainerView); + } + if (mCallbacks != null) { + mCallbacks.onNavigationDrawerItemSelected(position); + } + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + try { + mCallbacks = (NavigationDrawerCallbacks) context; + } catch (ClassCastException e) { + throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mCallbacks = null; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + // Forward the new configuration the drawer toggle component. + mDrawerToggle.onConfigurationChanged(newConfig); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if (mDrawerLayout != null && isDrawerOpen()) { + showGlobalContextActionBar(); + } + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; + } + + if (item.getItemId() == R.id.action_example) { + Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show(); + return true; + } + + return super.onOptionsItemSelected(item); + } + + /** + * Per the navigation drawer design guidelines, updates the action bar to show the global app + * 'context', rather than just what's in the current screen. + */ + private void showGlobalContextActionBar() { + ActionBar actionBar = getActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setTitle(R.string.app_name); + } + + private ActionBar getActionBar() { + return ((AppCompatActivity) getActivity()).getSupportActionBar(); + } + + /** + * Callbacks interface that all activities using this fragment must implement. + */ + public interface NavigationDrawerCallbacks { + /** + * Called when an item in the navigation drawer is selected. + */ + void onNavigationDrawerItemSelected(int position); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 410daf7d..0ccc5b41 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -109,7 +109,7 @@ public class StartActivity extends Activity { User.init(getString(R.string.default_username)); // go to Dashboard - intent = new Intent(this, Dashboard.class); + intent = new Intent(this, MainActivity.class); startActivity(intent); } } diff --git a/app/src/main/res/drawable-hdpi/drawer_shadow.9.png b/app/src/main/res/drawable-hdpi/drawer_shadow.9.png new file mode 100644 index 00000000..236bff55 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/drawer_shadow.9.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_drawer.png b/app/src/main/res/drawable-hdpi/ic_drawer.png new file mode 100644 index 00000000..c59f601c Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_drawer.png differ diff --git a/app/src/main/res/drawable-mdpi/drawer_shadow.9.png b/app/src/main/res/drawable-mdpi/drawer_shadow.9.png new file mode 100644 index 00000000..ffe3a28d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/drawer_shadow.9.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_drawer.png b/app/src/main/res/drawable-mdpi/ic_drawer.png new file mode 100644 index 00000000..1ed2c56e Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_drawer.png differ diff --git a/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png b/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png new file mode 100644 index 00000000..fabe9d96 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_drawer.png b/app/src/main/res/drawable-xhdpi/ic_drawer.png new file mode 100644 index 00000000..a5fa74de Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_drawer.png differ diff --git a/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png b/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png new file mode 100644 index 00000000..b91e9d7f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_drawer.png b/app/src/main/res/drawable-xxhdpi/ic_drawer.png new file mode 100644 index 00000000..9c4685d6 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_drawer.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..28c23503 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/drawer_main.xml b/app/src/main/res/layout/drawer_main.xml new file mode 100644 index 00000000..9327d03f --- /dev/null +++ b/app/src/main/res/layout/drawer_main.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml new file mode 100644 index 00000000..31dbd11e --- /dev/null +++ b/app/src/main/res/layout/fragment_main.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml new file mode 100644 index 00000000..56f43959 --- /dev/null +++ b/app/src/main/res/menu/main.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 00000000..63fc8164 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index f8fafecd..c92860be 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,5 +1,4 @@ - - @@ -17,4 +16,11 @@ 56dp 16dp 16dp + + 16dp + 16dp + + + 240dp \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 04e83a18..762655b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,7 +30,7 @@ password User message About Bitmask - Try again: server math error. + Try again: server math error. Incorrect username or password. It should have at least 8 characters. Try again: Client HTTP error @@ -77,4 +77,16 @@ Turn on Turn off Bitmask Log + MainActivity + + Section 1 + Section 2 + Section 3 + + Open navigation drawer + Close navigation drawer + + Example action + + Settings diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 80607409..a64779e5 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,6 +1,6 @@ - -- cgit v1.2.3 From da7293252f197e9b54c1abd8127b4abe45b95110 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Wed, 6 Dec 2017 01:58:21 +0100 Subject: move constants * move EIPConstants to Constants * unify EIPConstants where possible * create Updater --- .../java/se/leap/bitmaskclient/test/TestEIP.java | 4 +- .../java/se/leap/bitmaskclient/ProviderAPI.java | 9 +- .../leap/bitmaskclient/ProviderDetailFragment.java | 4 +- .../bitmaskclient/BaseConfigurationWizard.java | 5 +- .../main/java/se/leap/bitmaskclient/Constants.java | 34 ++++++ .../main/java/se/leap/bitmaskclient/Dashboard.java | 11 +- .../java/se/leap/bitmaskclient/OnBootReceiver.java | 4 +- .../se/leap/bitmaskclient/ProviderApiBase.java | 5 +- .../java/se/leap/bitmaskclient/StartActivity.java | 116 +++++++++++++-------- .../se/leap/bitmaskclient/VersionMilestone.java | 6 ++ .../java/se/leap/bitmaskclient/VpnFragment.java | 31 +++--- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 32 +++--- .../se/leap/bitmaskclient/eip/EIPConstants.java | 44 -------- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 4 +- .../se/leap/bitmaskclient/eip/VoidVpnLauncher.java | 4 +- .../se/leap/bitmaskclient/eip/VoidVpnService.java | 4 +- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 4 +- .../bitmaskclient/updates/ConstantUnification.java | 18 ++++ .../java/se/leap/bitmaskclient/ProviderAPI.java | 9 +- .../leap/bitmaskclient/ProviderDetailFragment.java | 6 +- .../bitmaskclient/eip/GatewaysManagerTest.java | 5 +- 21 files changed, 195 insertions(+), 164 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/VersionMilestone.java delete mode 100644 app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/updates/ConstantUnification.java diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java index 15bb53e1..f06846a9 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java @@ -60,13 +60,13 @@ public class TestEIP extends ServiceTestCase { private void testEmptyCertificate() { preferences.edit().putString(Constants.VPN_CERTIFICATE, "").apply(); - startService(Constants.ACTION_CHECK_CERT_VALIDITY); + startService(Constants.EIP_ACTION_CHECK_CERT_VALIDITY); } private void testExpiredCertificate() { String expired_certificate = "expired certificate"; preferences.edit().putString(Constants.VPN_CERTIFICATE, expired_certificate).apply(); - startService(Constants.ACTION_CHECK_CERT_VALIDITY); + startService(Constants.EIP_ACTION_CHECK_CERT_VALIDITY); } private void startService(String action) { diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java index fd6d4b79..c6826a53 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java @@ -45,7 +45,6 @@ import javax.net.ssl.X509TrustManager; import okhttp3.OkHttpClient; import se.leap.bitmaskclient.ProviderListContent.ProviderItem; -import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.eip.EIP; import static se.leap.bitmaskclient.R.string.certificate_error; @@ -138,8 +137,8 @@ public class ProviderAPI extends ProviderApiBase { //TODO setProviderName(name); preferences.edit().putString(Provider.KEY, provider_json.toString()).commit(); - preferences.edit().putBoolean(EIPConstants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIPConstants.ALLOWED_ANON)).commit(); - preferences.edit().putBoolean(EIPConstants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIPConstants.ALLOWED_REGISTERED)).commit(); + preferences.edit().putBoolean(Constants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit(); + preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit(); result.putBoolean(RESULT_KEY, true); } catch (JSONException e) { @@ -168,7 +167,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject eip_service_json = new JSONObject(eip_service_json_string); eip_service_json.getInt(Provider.API_RETURN_SERIAL); - preferences.edit().putString(EIPConstants.KEY, eip_service_json.toString()).commit(); + preferences.edit().putString(Constants.KEY, eip_service_json.toString()).commit(); result.putBoolean(RESULT_KEY, true); } catch (NullPointerException | JSONException e) { @@ -191,7 +190,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); String provider_main_url = provider_json.getString(Provider.API_URL); - URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIPConstants.VPN_CERTIFICATE); + URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.VPN_CERTIFICATE); String cert_string = downloadWithProviderCA(new_cert_string_url.toString(), last_danger_on); diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java index 9c401da4..f6ebfc4b 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -60,7 +60,7 @@ public class ProviderDetailFragment extends DialogFragment { private boolean anon_allowed(JSONObject provider_json) { try { JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(EIPConstants.ALLOWED_ANON) && service_description.getBoolean(EIPConstants.ALLOWED_ANON); + return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON); } catch (JSONException e) { return false; } @@ -79,7 +79,7 @@ public class ProviderDetailFragment extends DialogFragment { public void onCancel(DialogInterface dialog) { super.onCancel(dialog); SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(EIPConstants.ALLOWED_ANON).remove(EIPConstants.KEY).commit(); + editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit(); interface_with_configuration_wizard.cancelAndShowAllProviders(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 5dae1227..2ff8a088 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -51,7 +51,6 @@ import javax.inject.Inject; import butterknife.ButterKnife; import butterknife.InjectView; import butterknife.OnItemClick; -import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.userstatus.SessionDialog; import static android.view.View.GONE; @@ -220,7 +219,7 @@ public abstract class BaseConfigurationWizard extends Activity e.printStackTrace(); } - if (preferences.getBoolean(EIPConstants.ALLOWED_ANON, false)) { + if (preferences.getBoolean(Constants.ALLOWED_ANON, false)) { mConfigState.putExtra(SERVICES_RETRIEVED, true); downloadVpnCertificate(); @@ -297,7 +296,7 @@ public abstract class BaseConfigurationWizard extends Activity public void cancelSettingUpProvider() { mConfigState.setAction(PROVIDER_NOT_SET); adapter.showAllProviders(); - preferences.edit().remove(Provider.KEY).remove(EIPConstants.ALLOWED_ANON).remove(EIPConstants.KEY).apply(); + preferences.edit().remove(Provider.KEY).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).apply(); } private void askDashboardToQuitApp() { diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java index 4ce09892..f330ef68 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java @@ -1,6 +1,40 @@ package se.leap.bitmaskclient; public interface Constants { + + ////////////////////////////////////////////// + // PREFERENCES CONSTANTS + ///////////////////////////////////////////// + String SHARED_PREFERENCES = "LEAPPreferences"; String PREFERENCES_APP_VERSION = "bitmask version"; + + + ////////////////////////////////////////////// + // EIP CONSTANTS + ///////////////////////////////////////////// + + String EIP_ACTION_CHECK_CERT_VALIDITY = "EIP.CHECK_CERT_VALIDITY"; + String EIP_ACTION_START = "EIP.START"; + String EIP_ACTION_STOP = "EIP.STOP"; + String EIP_ACTION_UPDATE = "EIP.UPDATE"; + String EIP_ACTION_IS_RUNNING = "EIP.IS_RUNNING"; + String EIP_ACTION_BLOCK_VPN_PROFILE = "EIP.ACTION_BLOCK_VPN_PROFILE"; + + String EIP_NOTIFICATION = "EIP.NOTIFICATION"; + String EIP_RECEIVER = "EIP.RECEIVER"; + String EIP_REQUEST = "EIP.REQUEST"; + + + ////////////////////////////////////////////// + // ? CONSTANTS + ///////////////////////////////////////////// + + // TODO FIND BETTER NAMES AND DO NOT USE AS PREFERENCES KEY + String ALLOWED_ANON = "allow_anonymous"; + String ALLOWED_REGISTERED = "allow_registration"; + String VPN_CERTIFICATE = "cert"; + String PRIVATE_KEY = "Constants.PRIVATE_KEY"; + String KEY = "Constants.KEY"; + String PROVIDER_CONFIGURED = "Constants.PROVIDER_CONFIGURED"; } diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index e2366551..df558e08 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -41,7 +41,6 @@ import java.net.URL; import butterknife.ButterKnife; import butterknife.InjectView; -import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.userstatus.SessionDialog; import se.leap.bitmaskclient.userstatus.User; import se.leap.bitmaskclient.userstatus.UserStatusFragment; @@ -131,7 +130,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec private boolean providerInSharedPreferences() { return preferences != null && - preferences.getBoolean(EIPConstants.PROVIDER_CONFIGURED, false); + preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false); } @@ -160,7 +159,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec switch (versionCode) { case 91: // 0.6.0 without Bug #5999 case 101: // 0.8.0 - if (!preferences.getString(EIPConstants.KEY, "").isEmpty()) + if (!preferences.getString(Constants.KEY, "").isEmpty()) eip_fragment.updateEipService(); break; } @@ -205,7 +204,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec @SuppressLint("CommitPrefEdits") private void providerToPreferences(Provider provider) { - preferences.edit().putBoolean(EIPConstants.PROVIDER_CONFIGURED, true).commit(); + preferences.edit().putBoolean(Constants.PROVIDER_CONFIGURED, true).commit(); preferences.edit().putString(Provider.MAIN_URL, provider.mainUrl().toString()).apply(); preferences.edit().putString(Provider.KEY, provider.definition().toString()).apply(); } @@ -225,7 +224,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec .setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - preferences.edit().remove(Provider.KEY).remove(EIPConstants.PROVIDER_CONFIGURED).apply(); + preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_CONFIGURED).apply(); finish(); } }) @@ -316,7 +315,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec public void downloadVpnCertificate() { boolean is_authenticated = User.loggedIn(); - boolean allowed_anon = preferences.getBoolean(EIPConstants.ALLOWED_ANON, false); + boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false); if (allowed_anon || is_authenticated) ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_CERTIFICATE, providerAPI_result_receiver); else diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java index a72a8809..9394e1b1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java @@ -2,8 +2,6 @@ package se.leap.bitmaskclient; import android.content.*; -import se.leap.bitmaskclient.eip.EIPConstants; - public class OnBootReceiver extends BroadcastReceiver { @@ -17,7 +15,7 @@ public class OnBootReceiver extends BroadcastReceiver { boolean start_on_boot = preferences.getBoolean(Dashboard.START_ON_BOOT, false); if (provider_configured && start_on_boot) { Intent dashboard_intent = new Intent(context, Dashboard.class); - dashboard_intent.setAction(EIPConstants.ACTION_START_EIP); + dashboard_intent.setAction(Constants.EIP_ACTION_START); dashboard_intent.putExtra(Dashboard.ON_BOOT, true); dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(dashboard_intent); diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java index 81852983..b9063f18 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java @@ -67,7 +67,6 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.TlsVersion; -import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.userstatus.SessionDialog; import se.leap.bitmaskclient.userstatus.User; import se.leap.bitmaskclient.userstatus.UserStatus; @@ -817,11 +816,11 @@ public abstract class ProviderApiBase extends IntentService { RSAPrivateKey key = ConfigHelper.parseRsaKeyFromString(keyString); keyString = Base64.encodeToString(key.getEncoded(), Base64.DEFAULT); - preferences.edit().putString(EIPConstants.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----").commit(); + preferences.edit().putString(Constants.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----").commit(); X509Certificate certificate = ConfigHelper.parseX509CertificateFromString(certificateString); certificateString = Base64.encodeToString(certificate.getEncoded(), Base64.DEFAULT); - preferences.edit().putString(EIPConstants.VPN_CERTIFICATE, "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----").commit(); + preferences.edit().putString(Constants.VPN_CERTIFICATE, "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----").commit(); return true; } catch (CertificateException e) { // TODO Auto-generated catch block diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 410daf7d..ade43701 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -13,6 +13,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import de.blinkt.openvpn.core.VpnStatus; +import se.leap.bitmaskclient.updates.ConstantUnification; import se.leap.bitmaskclient.userstatus.User; /** @@ -31,40 +32,76 @@ public class StartActivity extends Activity { private static final int UPGRADE = 2; private static final int DOWNGRADE = 3; + private int versionCode; + private int previousVersionCode; + + private SharedPreferences preferences; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); + + Log.d(TAG, "Started"); + + switch (checkAppStart()) { + case NORMAL: + break; + + case FIRST: + // TODO start ProfileCreation & replace below code + break; + + case UPGRADE: + executeUpgrade(); + // TODO show donation dialog + break; + + case DOWNGRADE: + // TODO think how and why this should happen and what todo + break; + } + + // initialize app necessities + ProviderAPICommand.initialize(this); + VpnStatus.initLogCache(getApplicationContext().getCacheDir()); + User.init(getString(R.string.default_username)); + + // go to Dashboard + Intent intent = new Intent(this, Dashboard.class); + startActivity(intent); + } + /** * check if normal start, first run, up or downgrade * @return @StartupMode */ @StartupMode private int checkAppStart() { - SharedPreferences preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); try { - int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; - int lastDetectedVersion = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1); + versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; + previousVersionCode = preferences.getInt(Constants.PREFERENCES_APP_VERSION, -1); // versions do match -> normal start - if (versionCode == lastDetectedVersion) { + if (versionCode == previousVersionCode) { Log.d(TAG, "App start was: NORMAL START"); return NORMAL; } - // something changed -> save current version - preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); - // no previous app version -> first start - if (lastDetectedVersion == -1 ) { - Log.d(TAG, "App start was: FIRST START"); + if (previousVersionCode == -1 ) { + Log.d(TAG, "FIRST START"); return FIRST; } // version has increased -> upgrade - if (versionCode > lastDetectedVersion) { - Log.d(TAG, "App start was: UPGRADE"); + if (versionCode > previousVersionCode) { + Log.d(TAG, "UPGRADE"); return UPGRADE; } // version has decreased -> downgrade - if (versionCode < lastDetectedVersion) { - Log.d(TAG, "App start was: DOWNGRADE"); + if (versionCode < previousVersionCode) { + Log.d(TAG, "DOWNGRADE"); return DOWNGRADE; } @@ -75,41 +112,28 @@ public class StartActivity extends Activity { return NORMAL; } - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Intent intent; - - Log.d(TAG, "Started"); - - switch (checkAppStart()) { - case NORMAL: - break; - - case FIRST: - // TODO start ProfileCreation & replace below code - intent = new Intent(this, Dashboard.class); - startActivity(intent); - break; - - case UPGRADE: - // TODO appropriate data copying - // TODO show donation dialog - break; - - case DOWNGRADE: - // TODO think how and why this should happen and what todo - break; + /** + * execute necessary updates for version change + */ + private void executeUpgrade() { + if (passedMilestone(VersionMilestone.MULTIPLE_PROFILES)) { + // TODO prepare usage of multiple profiles + } + if (passedMilestone(VersionMilestone.CONSTANT_UNIFICATION)) { + ConstantUnification.upgrade(preferences); } - // initialize app necessities - ProviderAPICommand.initialize(this); - VpnStatus.initLogCache(getApplicationContext().getCacheDir()); - User.init(getString(R.string.default_username)); + // ensure all upgrades have passed before storing new information + preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); + } - // go to Dashboard - intent = new Intent(this, Dashboard.class); - startActivity(intent); + /** + * check if an upgrade passed or moved to given milestone + * @param milestone Version code of the Milestone VersionMilestone.MILE_STONE + * @return true if milestone is reached - false otherwise + */ + private boolean passedMilestone(int milestone) { + return previousVersionCode < milestone && versionCode >= milestone; } + } diff --git a/app/src/main/java/se/leap/bitmaskclient/VersionMilestone.java b/app/src/main/java/se/leap/bitmaskclient/VersionMilestone.java new file mode 100644 index 00000000..eac57d72 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/VersionMilestone.java @@ -0,0 +1,6 @@ +package se.leap.bitmaskclient; + +public interface VersionMilestone { + int MULTIPLE_PROFILES = 132; + int CONSTANT_UNIFICATION = 132; +} diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java index eff02193..7b01714f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java @@ -32,11 +32,10 @@ import de.blinkt.openvpn.core.IOpenVPNServiceInternal; import de.blinkt.openvpn.core.OpenVPNService; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; -import mbanje.kurt.fabbutton.*; -import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.VoidVpnService; +import se.leap.bitmaskclient.userstatus.FabButton; public class VpnFragment extends Fragment implements Observer { @@ -115,7 +114,7 @@ public class VpnFragment extends Fragment implements Observer { public void onResume() { super.onResume(); //FIXME: avoid race conditions while checking certificate an logging in at about the same time - //eipCommand(EIPConstants.ACTION_CHECK_CERT_VALIDITY); + //eipCommand(Constants.EIP_ACTION_CHECK_CERT_VALIDITY); handleNewState(eip_status); bindOpenVpnService(); } @@ -164,13 +163,13 @@ public class VpnFragment extends Fragment implements Observer { } private boolean canStartEIP() { - boolean certificateExists = !Dashboard.preferences.getString(EIPConstants.VPN_CERTIFICATE, "").isEmpty(); - boolean isAllowedAnon = Dashboard.preferences.getBoolean(EIPConstants.ALLOWED_ANON, false); + boolean certificateExists = !Dashboard.preferences.getString(Constants.VPN_CERTIFICATE, "").isEmpty(); + boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false); return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting(); } private boolean canLogInToStartEIP() { - boolean isAllowedRegistered = Dashboard.preferences.getBoolean(EIPConstants.ALLOWED_REGISTERED, false); + boolean isAllowedRegistered = Dashboard.preferences.getBoolean(Constants.ALLOWED_REGISTERED, false); boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty(); return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); } @@ -207,7 +206,7 @@ public class VpnFragment extends Fragment implements Observer { eip_status.setConnecting(); saveStatus(); - eipCommand(EIPConstants.ACTION_START_EIP); + eipCommand(Constants.EIP_ACTION_START); } private void stop() { @@ -230,7 +229,7 @@ public class VpnFragment extends Fragment implements Observer { } protected void stopEipIfPossible() { - eipCommand(EIPConstants.ACTION_STOP_EIP); + eipCommand(Constants.EIP_ACTION_STOP); } private void downloadEIPServiceConfig() { @@ -258,7 +257,7 @@ public class VpnFragment extends Fragment implements Observer { } protected void updateEipService() { - eipCommand(EIPConstants.ACTION_UPDATE_EIP_SERVICE); + eipCommand(Constants.EIP_ACTION_UPDATE); } /** @@ -271,7 +270,7 @@ public class VpnFragment extends Fragment implements Observer { // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); vpn_intent.setAction(action); - vpn_intent.putExtra(EIPConstants.RECEIVER_TAG, eip_receiver); + vpn_intent.putExtra(Constants.EIP_RECEIVER, eip_receiver); dashboard.startService(vpn_intent); } @@ -344,9 +343,9 @@ public class VpnFragment extends Fragment implements Observer { protected void onReceiveResult(int resultCode, Bundle resultData) { super.onReceiveResult(resultCode, resultData); - String request = resultData.getString(EIPConstants.REQUEST_TAG); + String request = resultData.getString(Constants.EIP_REQUEST); - if (request.equals(EIPConstants.ACTION_START_EIP)) { + if (request.equals(Constants.EIP_ACTION_START)) { switch (resultCode) { case Activity.RESULT_OK: break; @@ -354,7 +353,7 @@ public class VpnFragment extends Fragment implements Observer { break; } - } else if (request.equals(EIPConstants.ACTION_STOP_EIP)) { + } else if (request.equals(Constants.EIP_ACTION_STOP)) { switch (resultCode) { case Activity.RESULT_OK: stop(); @@ -362,14 +361,14 @@ public class VpnFragment extends Fragment implements Observer { case Activity.RESULT_CANCELED: break; } - } else if (request.equals(EIPConstants.EIP_NOTIFICATION)) { + } else if (request.equals(Constants.EIP_NOTIFICATION)) { switch (resultCode) { case Activity.RESULT_OK: break; case Activity.RESULT_CANCELED: break; } - } else if (request.equals(EIPConstants.ACTION_CHECK_CERT_VALIDITY)) { + } else if (request.equals(Constants.EIP_ACTION_CHECK_CERT_VALIDITY)) { switch (resultCode) { case Activity.RESULT_OK: break; @@ -377,7 +376,7 @@ public class VpnFragment extends Fragment implements Observer { dashboard.downloadVpnCertificate(); break; } - } else if (request.equals(EIPConstants.ACTION_UPDATE_EIP_SERVICE)) { + } else if (request.equals(Constants.EIP_ACTION_UPDATE)) { switch (resultCode) { case Activity.RESULT_OK: if (wants_to_connect) diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 8bbdf901..929a0c70 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -25,8 +25,6 @@ import org.json.*; import de.blinkt.openvpn.*; import se.leap.bitmaskclient.*; -import static se.leap.bitmaskclient.eip.EIPConstants.*; - /** * EIP is the abstract base class for interacting with and managing the Encrypted * Internet Proxy connection. Connections are started, stopped, and queried through @@ -68,17 +66,17 @@ public final class EIP extends IntentService { @Override protected void onHandleIntent(Intent intent) { String action = intent.getAction(); - mReceiver = intent.getParcelableExtra(RECEIVER_TAG); + mReceiver = intent.getParcelableExtra(Constants.EIP_RECEIVER); - if (action.equals(ACTION_START_EIP)) + if (action.equals(Constants.EIP_ACTION_START)) startEIP(); - else if (action.equals(ACTION_STOP_EIP)) + else if (action.equals(Constants.EIP_ACTION_STOP)) stopEIP(); - else if (action.equals(ACTION_IS_EIP_RUNNING)) + else if (action.equals(Constants.EIP_ACTION_IS_RUNNING)) isRunning(); - else if (action.equals(ACTION_UPDATE_EIP_SERVICE)) + else if (action.equals(Constants.EIP_ACTION_UPDATE)) updateEIPService(); - else if (action.equals(ACTION_CHECK_CERT_VALIDITY)) + else if (action.equals(Constants.EIP_ACTION_CHECK_CERT_VALIDITY)) checkCertValidity(); } @@ -96,9 +94,9 @@ public final class EIP extends IntentService { if (gateway != null && gateway.getProfile() != null) { mReceiver = VpnFragment.getReceiver(); launchActiveGateway(); - tellToReceiver(ACTION_START_EIP, Activity.RESULT_OK); + tellToReceiver(Constants.EIP_ACTION_START, Activity.RESULT_OK); } else - tellToReceiver(ACTION_START_EIP, Activity.RESULT_CANCELED); + tellToReceiver(Constants.EIP_ACTION_START, Activity.RESULT_CANCELED); } /** @@ -126,7 +124,7 @@ public final class EIP extends IntentService { if (eip_status.isConnected() || eip_status.isConnecting()) result_code = Activity.RESULT_OK; - tellToReceiver(ACTION_STOP_EIP, result_code); + tellToReceiver(Constants.EIP_ACTION_STOP, result_code); } /** @@ -139,7 +137,7 @@ public final class EIP extends IntentService { int resultCode = (eip_status.isConnected()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; - tellToReceiver(ACTION_IS_EIP_RUNNING, resultCode); + tellToReceiver(Constants.EIP_ACTION_IS_RUNNING, resultCode); } /** @@ -150,13 +148,13 @@ public final class EIP extends IntentService { eip_definition = eipDefinitionFromPreferences(); if (eip_definition.length() > 0) updateGateways(); - tellToReceiver(ACTION_UPDATE_EIP_SERVICE, Activity.RESULT_OK); + tellToReceiver(Constants.EIP_ACTION_UPDATE, Activity.RESULT_OK); } private JSONObject eipDefinitionFromPreferences() { JSONObject result = new JSONObject(); try { - String eip_definition_string = preferences.getString(KEY, ""); + String eip_definition_string = preferences.getString(Constants.KEY, ""); if (!eip_definition_string.isEmpty()) { result = new JSONObject(eip_definition_string); } @@ -186,17 +184,17 @@ public final class EIP extends IntentService { } private void checkCertValidity() { - VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(VPN_CERTIFICATE, "")); + VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(Constants.VPN_CERTIFICATE, "")); int resultCode = validator.isValid() ? Activity.RESULT_OK : Activity.RESULT_CANCELED; - tellToReceiver(ACTION_CHECK_CERT_VALIDITY, resultCode); + tellToReceiver(Constants.EIP_ACTION_CHECK_CERT_VALIDITY, resultCode); } private void tellToReceiver(String action, int resultCode) { if (mReceiver != null) { Bundle resultData = new Bundle(); - resultData.putString(REQUEST_TAG, action); + resultData.putString(Constants.EIP_REQUEST, action); mReceiver.send(resultCode, resultData); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java deleted file mode 100644 index a56868f1..00000000 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIPConstants.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2013 LEAP Encryption Access Project and contributers - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package se.leap.bitmaskclient.eip; - -/** - * EIPConstants for intent passing, shared preferences - * - * @author Parménides GV - */ -public interface EIPConstants { - - String TAG = "Constants"; - - String ACTION_CHECK_CERT_VALIDITY = TAG + ".CHECK_CERT_VALIDITY"; - String ACTION_START_EIP = TAG + ".START_EIP"; - String ACTION_STOP_EIP = TAG + ".STOP_EIP"; - String ACTION_UPDATE_EIP_SERVICE = TAG + ".UPDATE_EIP_SERVICE"; - String ACTION_IS_EIP_RUNNING = TAG + ".IS_RUNNING"; - String EIP_NOTIFICATION = TAG + ".EIP_NOTIFICATION"; - String ALLOWED_ANON = "allow_anonymous"; - String ALLOWED_REGISTERED = "allow_registration"; - String VPN_CERTIFICATE = "cert"; - String PRIVATE_KEY = TAG + ".PRIVATE_KEY"; - String KEY = TAG + ".KEY"; - String RECEIVER_TAG = TAG + ".RECEIVER_TAG"; - String REQUEST_TAG = TAG + ".REQUEST_TAG"; - String START_BLOCKING_VPN_PROFILE = TAG + ".START_BLOCKING_VPN_PROFILE"; - String PROVIDER_CONFIGURED = TAG + ".PROVIDER_CONFIGURED"; - -} diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 25c99098..177f553e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -123,8 +123,8 @@ public class GatewaysManager { JSONObject result = new JSONObject(); try { result.put(Provider.CA_CERT, preferences.getString(Provider.CA_CERT, "")); - result.put(EIPConstants.PRIVATE_KEY, preferences.getString(EIPConstants.PRIVATE_KEY, "")); - result.put(EIPConstants.VPN_CERTIFICATE, preferences.getString(EIPConstants.VPN_CERTIFICATE, "")); + result.put(Constants.PRIVATE_KEY, preferences.getString(Constants.PRIVATE_KEY, "")); + result.put(Constants.VPN_CERTIFICATE, preferences.getString(Constants.VPN_CERTIFICATE, "")); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java index 8ce8aa81..b1aab79c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java @@ -5,6 +5,8 @@ import android.content.*; import android.net.*; import android.os.*; +import se.leap.bitmaskclient.Constants; + public class VoidVpnLauncher extends Activity { private static final int VPN_USER_PERMISSION = 71; @@ -28,7 +30,7 @@ public class VoidVpnLauncher extends Activity { if (requestCode == VPN_USER_PERMISSION) { if (resultCode == RESULT_OK) { Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class); - void_vpn_service.setAction(EIPConstants.START_BLOCKING_VPN_PROFILE); + void_vpn_service.setAction(Constants.EIP_ACTION_BLOCK_VPN_PROFILE); startService(void_vpn_service); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java index 629b4304..ff375553 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java @@ -6,6 +6,8 @@ import android.os.*; import java.io.*; +import se.leap.bitmaskclient.Constants; + public class VoidVpnService extends VpnService { static final String TAG = VoidVpnService.class.getSimpleName(); @@ -16,7 +18,7 @@ public class VoidVpnService extends VpnService { @Override public int onStartCommand(Intent intent, int flags, int startId) { String action = intent != null ? intent.getAction() : ""; - if (action == EIPConstants.START_BLOCKING_VPN_PROFILE) { + if (action == Constants.EIP_ACTION_BLOCK_VPN_PROFILE) { thread = new Thread(new Runnable() { public void run() { Builder builder = new Builder(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 33993139..f428099e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -118,14 +118,14 @@ public class VpnConfigGenerator { String key = "" + new_line - + secrets.getString(EIPConstants.PRIVATE_KEY) + + secrets.getString(Constants.PRIVATE_KEY) + new_line + ""; String openvpn_cert = "" + new_line - + secrets.getString(EIPConstants.VPN_CERTIFICATE) + + secrets.getString(Constants.VPN_CERTIFICATE) + new_line + ""; diff --git a/app/src/main/java/se/leap/bitmaskclient/updates/ConstantUnification.java b/app/src/main/java/se/leap/bitmaskclient/updates/ConstantUnification.java new file mode 100644 index 00000000..ba78fa00 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/updates/ConstantUnification.java @@ -0,0 +1,18 @@ +package se.leap.bitmaskclient.updates; + +import android.content.SharedPreferences; + +public class ConstantUnification { + + private String OLD_ALLOWED_ANON = "allow_anonymous"; + private String OLD_ALLOWED_REGISTERED = "allow_registration"; + private String OLD_VPN_CERTIFICATE = "cert"; + private String OLD_PRIVATE_KEY = "Constants.PRIVATE_KEY"; + private String OLD_KEY = "Constants.KEY"; + private String OLD_PROVIDER_CONFIGURED = "Constants.PROVIDER_CONFIGURED"; + + public static void upgrade(SharedPreferences preferences) { + // TODO MOVE SAVED DATA + } + +} diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java index eebc54c1..9ab90cc2 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java @@ -33,7 +33,6 @@ import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLHandshakeException; import okhttp3.OkHttpClient; -import se.leap.bitmaskclient.eip.EIPConstants; import se.leap.bitmaskclient.eip.EIP; import static se.leap.bitmaskclient.R.string.error_io_exception_user_message; @@ -120,8 +119,8 @@ public class ProviderAPI extends ProviderApiBase { //TODO setProviderName(name); preferences.edit().putString(Provider.KEY, provider_json.toString()).commit(); - preferences.edit().putBoolean(EIPConstants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIPConstants.ALLOWED_ANON)).commit(); - preferences.edit().putBoolean(EIPConstants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIPConstants.ALLOWED_REGISTERED)).commit(); + preferences.edit().putBoolean(Constants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit(); + preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit(); result.putBoolean(RESULT_KEY, true); } catch (JSONException e) { @@ -150,7 +149,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject eip_service_json = new JSONObject(eip_service_json_string); eip_service_json.getInt(Provider.API_RETURN_SERIAL); - preferences.edit().putString(EIPConstants.KEY, eip_service_json.toString()).commit(); + preferences.edit().putString(Constants.KEY, eip_service_json.toString()).commit(); result.putBoolean(RESULT_KEY, true); } catch (NullPointerException | JSONException e) { @@ -173,7 +172,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); String provider_main_url = provider_json.getString(Provider.API_URL); - URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + EIPConstants.VPN_CERTIFICATE); + URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.VPN_CERTIFICATE); String cert_string = downloadWithProviderCA(new_cert_string_url.toString()); diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java index bd4c0d72..e288ebf8 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -2,8 +2,6 @@ package se.leap.bitmaskclient; import org.json.*; -import se.leap.bitmaskclient.eip.EIPConstants; - import android.app.*; import android.content.*; import android.os.*; @@ -59,7 +57,7 @@ public class ProviderDetailFragment extends DialogFragment { private boolean anon_allowed(JSONObject provider_json) { try { JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(EIPConstants.ALLOWED_ANON) && service_description.getBoolean(EIPConstants.ALLOWED_ANON); + return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON); } catch (JSONException e) { return false; } @@ -78,7 +76,7 @@ public class ProviderDetailFragment extends DialogFragment { public void onCancel(DialogInterface dialog) { super.onCancel(dialog); SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(EIPConstants.ALLOWED_ANON).remove(EIPConstants.KEY).commit(); + editor.remove(Provider.KEY).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit(); interface_with_configuration_wizard.cancelAndShowAllProviders(); } diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java index 291d027e..01cd50dc 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -14,6 +14,7 @@ import org.mockito.junit.MockitoJUnitRunner; import java.io.IOException; +import se.leap.bitmaskclient.Constants; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.TestUtils; @@ -42,9 +43,9 @@ public class GatewaysManagerTest { JSONObject secrets = new JSONObject(getJsonStringFor("secrets.json")); - when(sharedPreferences.getString(eq(EIPConstants.PRIVATE_KEY), anyString())).thenReturn(secrets.getString(EIPConstants.PRIVATE_KEY)); + when(sharedPreferences.getString(eq(Constants.PRIVATE_KEY), anyString())).thenReturn(secrets.getString(Constants.PRIVATE_KEY)); when(sharedPreferences.getString(eq(Provider.CA_CERT), anyString())).thenReturn(secrets.getString(Provider.CA_CERT)); - when(sharedPreferences.getString(eq(EIPConstants.VPN_CERTIFICATE), anyString())).thenReturn(secrets.getString(EIPConstants.VPN_CERTIFICATE)); + when(sharedPreferences.getString(eq(Constants.VPN_CERTIFICATE), anyString())).thenReturn(secrets.getString(Constants.VPN_CERTIFICATE)); when(mockContext.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPreferences); -- cgit v1.2.3 From f8c2f76971f5a7f26d18e5e669d5e0ce9c560f3f Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 7 Dec 2017 12:52:29 +0100 Subject: Rename constants * renamed last constants * remove unnecessary updates/ConstantUnification --- .../java/se/leap/bitmaskclient/test/TestEIP.java | 4 ++-- .../java/se/leap/bitmaskclient/ProviderAPI.java | 8 ++++---- .../se/leap/bitmaskclient/ProviderDetailFragment.java | 5 ++--- app/src/main/java/de/blinkt/openvpn/VpnProfile.java | 2 +- .../se/leap/bitmaskclient/BaseConfigurationWizard.java | 4 ++-- app/src/main/java/se/leap/bitmaskclient/Constants.java | 14 ++++++-------- app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 4 ++-- .../java/se/leap/bitmaskclient/FeatureVersionCode.java | 5 +++++ .../java/se/leap/bitmaskclient/ProviderApiBase.java | 6 +++--- .../main/java/se/leap/bitmaskclient/StartActivity.java | 14 +++++--------- .../java/se/leap/bitmaskclient/VersionMilestone.java | 6 ------ .../main/java/se/leap/bitmaskclient/VpnFragment.java | 6 +++--- app/src/main/java/se/leap/bitmaskclient/eip/EIP.java | 4 ++-- .../se/leap/bitmaskclient/eip/GatewaysManager.java | 5 +++-- .../se/leap/bitmaskclient/eip/VpnConfigGenerator.java | 4 ++-- .../bitmaskclient/updates/ConstantUnification.java | 18 ------------------ .../se/leap/bitmaskclient/eip/GatewaysManagerTest.java | 4 ++-- .../leap/bitmaskclient/eip/VpnConfigGeneratorTest.java | 8 ++++---- 18 files changed, 48 insertions(+), 73 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/FeatureVersionCode.java delete mode 100644 app/src/main/java/se/leap/bitmaskclient/VersionMilestone.java delete mode 100644 app/src/main/java/se/leap/bitmaskclient/updates/ConstantUnification.java diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java index f06846a9..c5a6e809 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestEIP.java @@ -59,13 +59,13 @@ public class TestEIP extends ServiceTestCase { } private void testEmptyCertificate() { - preferences.edit().putString(Constants.VPN_CERTIFICATE, "").apply(); + preferences.edit().putString(Constants.PROVIDER_VPN_CERTIFICATE, "").apply(); startService(Constants.EIP_ACTION_CHECK_CERT_VALIDITY); } private void testExpiredCertificate() { String expired_certificate = "expired certificate"; - preferences.edit().putString(Constants.VPN_CERTIFICATE, expired_certificate).apply(); + preferences.edit().putString(Constants.PROVIDER_VPN_CERTIFICATE, expired_certificate).apply(); startService(Constants.EIP_ACTION_CHECK_CERT_VALIDITY); } diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java index c6826a53..7689c343 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderAPI.java @@ -137,8 +137,8 @@ public class ProviderAPI extends ProviderApiBase { //TODO setProviderName(name); preferences.edit().putString(Provider.KEY, provider_json.toString()).commit(); - preferences.edit().putBoolean(Constants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit(); - preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit(); + preferences.edit().putBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS)).commit(); + preferences.edit().putBoolean(Constants.PROVIDER_ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.PROVIDER_ALLOWED_REGISTERED)).commit(); result.putBoolean(RESULT_KEY, true); } catch (JSONException e) { @@ -167,7 +167,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject eip_service_json = new JSONObject(eip_service_json_string); eip_service_json.getInt(Provider.API_RETURN_SERIAL); - preferences.edit().putString(Constants.KEY, eip_service_json.toString()).commit(); + preferences.edit().putString(Constants.PROVIDER_KEY, eip_service_json.toString()).commit(); result.putBoolean(RESULT_KEY, true); } catch (NullPointerException | JSONException e) { @@ -190,7 +190,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); String provider_main_url = provider_json.getString(Provider.API_URL); - URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.VPN_CERTIFICATE); + URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.PROVIDER_VPN_CERTIFICATE); String cert_string = downloadWithProviderCA(new_cert_string_url.toString(), last_danger_on); diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java index f6ebfc4b..390d4aeb 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -2,7 +2,6 @@ package se.leap.bitmaskclient; import org.json.*; -import se.leap.bitmaskclient.eip.*; import se.leap.bitmaskclient.ProviderListContent.ProviderItem; import android.app.*; @@ -60,7 +59,7 @@ public class ProviderDetailFragment extends DialogFragment { private boolean anon_allowed(JSONObject provider_json) { try { JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON); + return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); } catch (JSONException e) { return false; } @@ -79,7 +78,7 @@ public class ProviderDetailFragment extends DialogFragment { public void onCancel(DialogInterface dialog) { super.onCancel(dialog); SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit(); + editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).commit(); interface_with_configuration_wizard.cancelAndShowAllProviders(); } diff --git a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java index aa25da48..cc8d987c 100644 --- a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -1017,7 +1017,7 @@ public class VpnProfile implements Serializable, Cloneable { if (data.contains("Proc-Type: 4,ENCRYPTED")) return true; - else if (data.contains("-----BEGIN ENCRYPTED PRIVATE KEY-----")) + else if (data.contains("-----BEGIN ENCRYPTED PRIVATE PROVIDER_KEY-----")) return true; else return false; diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 2ff8a088..21520dc4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -219,7 +219,7 @@ public abstract class BaseConfigurationWizard extends Activity e.printStackTrace(); } - if (preferences.getBoolean(Constants.ALLOWED_ANON, false)) { + if (preferences.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, false)) { mConfigState.putExtra(SERVICES_RETRIEVED, true); downloadVpnCertificate(); @@ -296,7 +296,7 @@ public abstract class BaseConfigurationWizard extends Activity public void cancelSettingUpProvider() { mConfigState.setAction(PROVIDER_NOT_SET); adapter.showAllProviders(); - preferences.edit().remove(Provider.KEY).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).apply(); + preferences.edit().remove(Provider.KEY).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).apply(); } private void askDashboardToQuitApp() { diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java index f330ef68..8723191c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java @@ -27,14 +27,12 @@ public interface Constants { ////////////////////////////////////////////// - // ? CONSTANTS + // PROVIDER CONSTANTS ///////////////////////////////////////////// - - // TODO FIND BETTER NAMES AND DO NOT USE AS PREFERENCES KEY - String ALLOWED_ANON = "allow_anonymous"; - String ALLOWED_REGISTERED = "allow_registration"; - String VPN_CERTIFICATE = "cert"; - String PRIVATE_KEY = "Constants.PRIVATE_KEY"; - String KEY = "Constants.KEY"; + String PROVIDER_ALLOW_ANONYMOUS = "allow_anonymous"; + String PROVIDER_ALLOWED_REGISTERED = "allow_registration"; + String PROVIDER_VPN_CERTIFICATE = "cert"; + String PROVIDER_PRIVATE_KEY = "Constants.PROVIDER_PRIVATE_KEY"; + String PROVIDER_KEY = "Constants.PROVIDER_KEY"; String PROVIDER_CONFIGURED = "Constants.PROVIDER_CONFIGURED"; } diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index df558e08..1f0477c9 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -159,7 +159,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec switch (versionCode) { case 91: // 0.6.0 without Bug #5999 case 101: // 0.8.0 - if (!preferences.getString(Constants.KEY, "").isEmpty()) + if (!preferences.getString(Constants.PROVIDER_KEY, "").isEmpty()) eip_fragment.updateEipService(); break; } @@ -315,7 +315,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec public void downloadVpnCertificate() { boolean is_authenticated = User.loggedIn(); - boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false); + boolean allowed_anon = preferences.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, false); if (allowed_anon || is_authenticated) ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_CERTIFICATE, providerAPI_result_receiver); else diff --git a/app/src/main/java/se/leap/bitmaskclient/FeatureVersionCode.java b/app/src/main/java/se/leap/bitmaskclient/FeatureVersionCode.java new file mode 100644 index 00000000..b2a39c1a --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/FeatureVersionCode.java @@ -0,0 +1,5 @@ +package se.leap.bitmaskclient; + +public interface FeatureVersionCode { + int MULTIPLE_PROFILES = 132; +} diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java index b9063f18..38981289 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java @@ -807,7 +807,7 @@ public abstract class ProviderApiBase extends IntentService { String certificateString = null, keyString = null; String[] certAndKey = cert_string.split("(?<=-\n)"); for (int i = 0; i < certAndKey.length - 1; i++) { - if (certAndKey[i].contains("KEY")) { + if (certAndKey[i].contains("PROVIDER_KEY")) { keyString = certAndKey[i++] + certAndKey[i]; } else if (certAndKey[i].contains("CERTIFICATE")) { certificateString = certAndKey[i++] + certAndKey[i]; @@ -816,11 +816,11 @@ public abstract class ProviderApiBase extends IntentService { RSAPrivateKey key = ConfigHelper.parseRsaKeyFromString(keyString); keyString = Base64.encodeToString(key.getEncoded(), Base64.DEFAULT); - preferences.edit().putString(Constants.PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----").commit(); + preferences.edit().putString(Constants.PROVIDER_PRIVATE_KEY, "-----BEGIN RSA PRIVATE PROVIDER_KEY-----\n" + keyString + "-----END RSA PRIVATE PROVIDER_KEY-----").commit(); X509Certificate certificate = ConfigHelper.parseX509CertificateFromString(certificateString); certificateString = Base64.encodeToString(certificate.getEncoded(), Base64.DEFAULT); - preferences.edit().putString(Constants.VPN_CERTIFICATE, "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----").commit(); + preferences.edit().putString(Constants.PROVIDER_VPN_CERTIFICATE, "-----BEGIN CERTIFICATE-----\n" + certificateString + "-----END CERTIFICATE-----").commit(); return true; } catch (CertificateException e) { // TODO Auto-generated catch block diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index ade43701..dd2be212 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -13,7 +13,6 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import de.blinkt.openvpn.core.VpnStatus; -import se.leap.bitmaskclient.updates.ConstantUnification; import se.leap.bitmaskclient.userstatus.User; /** @@ -113,15 +112,12 @@ public class StartActivity extends Activity { } /** - * execute necessary updates for version change + * execute necessary upgrades for version change */ private void executeUpgrade() { - if (passedMilestone(VersionMilestone.MULTIPLE_PROFILES)) { + if (hasNewFeature(FeatureVersionCode.MULTIPLE_PROFILES)) { // TODO prepare usage of multiple profiles } - if (passedMilestone(VersionMilestone.CONSTANT_UNIFICATION)) { - ConstantUnification.upgrade(preferences); - } // ensure all upgrades have passed before storing new information preferences.edit().putInt(Constants.PREFERENCES_APP_VERSION, versionCode).apply(); @@ -129,11 +125,11 @@ public class StartActivity extends Activity { /** * check if an upgrade passed or moved to given milestone - * @param milestone Version code of the Milestone VersionMilestone.MILE_STONE + * @param featureVersionCode Version code of the Milestone FeatureVersionCode.MILE_STONE * @return true if milestone is reached - false otherwise */ - private boolean passedMilestone(int milestone) { - return previousVersionCode < milestone && versionCode >= milestone; + private boolean hasNewFeature(int featureVersionCode) { + return previousVersionCode < featureVersionCode && versionCode >= featureVersionCode; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/VersionMilestone.java b/app/src/main/java/se/leap/bitmaskclient/VersionMilestone.java deleted file mode 100644 index eac57d72..00000000 --- a/app/src/main/java/se/leap/bitmaskclient/VersionMilestone.java +++ /dev/null @@ -1,6 +0,0 @@ -package se.leap.bitmaskclient; - -public interface VersionMilestone { - int MULTIPLE_PROFILES = 132; - int CONSTANT_UNIFICATION = 132; -} diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java index 7b01714f..f787a955 100644 --- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java @@ -163,13 +163,13 @@ public class VpnFragment extends Fragment implements Observer { } private boolean canStartEIP() { - boolean certificateExists = !Dashboard.preferences.getString(Constants.VPN_CERTIFICATE, "").isEmpty(); - boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false); + boolean certificateExists = !Dashboard.preferences.getString(Constants.PROVIDER_VPN_CERTIFICATE, "").isEmpty(); + boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, false); return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting(); } private boolean canLogInToStartEIP() { - boolean isAllowedRegistered = Dashboard.preferences.getBoolean(Constants.ALLOWED_REGISTERED, false); + boolean isAllowedRegistered = Dashboard.preferences.getBoolean(Constants.PROVIDER_ALLOWED_REGISTERED, false); boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty(); return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index 929a0c70..0b35dc3d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -154,7 +154,7 @@ public final class EIP extends IntentService { private JSONObject eipDefinitionFromPreferences() { JSONObject result = new JSONObject(); try { - String eip_definition_string = preferences.getString(Constants.KEY, ""); + String eip_definition_string = preferences.getString(Constants.PROVIDER_KEY, ""); if (!eip_definition_string.isEmpty()) { result = new JSONObject(eip_definition_string); } @@ -184,7 +184,7 @@ public final class EIP extends IntentService { } private void checkCertValidity() { - VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(Constants.VPN_CERTIFICATE, "")); + VpnCertificateValidator validator = new VpnCertificateValidator(preferences.getString(Constants.PROVIDER_VPN_CERTIFICATE, "")); int resultCode = validator.isValid() ? Activity.RESULT_OK : Activity.RESULT_CANCELED; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java index 177f553e..43c16d00 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/GatewaysManager.java @@ -36,6 +36,7 @@ import java.util.List; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.Connection; import de.blinkt.openvpn.core.ProfileManager; +import se.leap.bitmaskclient.Constants; import se.leap.bitmaskclient.Provider; /** @@ -123,8 +124,8 @@ public class GatewaysManager { JSONObject result = new JSONObject(); try { result.put(Provider.CA_CERT, preferences.getString(Provider.CA_CERT, "")); - result.put(Constants.PRIVATE_KEY, preferences.getString(Constants.PRIVATE_KEY, "")); - result.put(Constants.VPN_CERTIFICATE, preferences.getString(Constants.VPN_CERTIFICATE, "")); + result.put(Constants.PROVIDER_PRIVATE_KEY, preferences.getString(Constants.PROVIDER_PRIVATE_KEY, "")); + result.put(Constants.PROVIDER_VPN_CERTIFICATE, preferences.getString(Constants.PROVIDER_VPN_CERTIFICATE, "")); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index f428099e..54563ec4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -118,14 +118,14 @@ public class VpnConfigGenerator { String key = "" + new_line - + secrets.getString(Constants.PRIVATE_KEY) + + secrets.getString(Constants.PROVIDER_PRIVATE_KEY) + new_line + ""; String openvpn_cert = "" + new_line - + secrets.getString(Constants.VPN_CERTIFICATE) + + secrets.getString(Constants.PROVIDER_VPN_CERTIFICATE) + new_line + ""; diff --git a/app/src/main/java/se/leap/bitmaskclient/updates/ConstantUnification.java b/app/src/main/java/se/leap/bitmaskclient/updates/ConstantUnification.java deleted file mode 100644 index ba78fa00..00000000 --- a/app/src/main/java/se/leap/bitmaskclient/updates/ConstantUnification.java +++ /dev/null @@ -1,18 +0,0 @@ -package se.leap.bitmaskclient.updates; - -import android.content.SharedPreferences; - -public class ConstantUnification { - - private String OLD_ALLOWED_ANON = "allow_anonymous"; - private String OLD_ALLOWED_REGISTERED = "allow_registration"; - private String OLD_VPN_CERTIFICATE = "cert"; - private String OLD_PRIVATE_KEY = "Constants.PRIVATE_KEY"; - private String OLD_KEY = "Constants.KEY"; - private String OLD_PROVIDER_CONFIGURED = "Constants.PROVIDER_CONFIGURED"; - - public static void upgrade(SharedPreferences preferences) { - // TODO MOVE SAVED DATA - } - -} diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java index 01cd50dc..ea212480 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/GatewaysManagerTest.java @@ -43,9 +43,9 @@ public class GatewaysManagerTest { JSONObject secrets = new JSONObject(getJsonStringFor("secrets.json")); - when(sharedPreferences.getString(eq(Constants.PRIVATE_KEY), anyString())).thenReturn(secrets.getString(Constants.PRIVATE_KEY)); + when(sharedPreferences.getString(eq(Constants.PROVIDER_PRIVATE_KEY), anyString())).thenReturn(secrets.getString(Constants.PROVIDER_PRIVATE_KEY)); when(sharedPreferences.getString(eq(Provider.CA_CERT), anyString())).thenReturn(secrets.getString(Provider.CA_CERT)); - when(sharedPreferences.getString(eq(Constants.VPN_CERTIFICATE), anyString())).thenReturn(secrets.getString(Constants.VPN_CERTIFICATE)); + when(sharedPreferences.getString(eq(Constants.PROVIDER_VPN_CERTIFICATE), anyString())).thenReturn(secrets.getString(Constants.PROVIDER_VPN_CERTIFICATE)); when(mockContext.getSharedPreferences(anyString(), anyInt())).thenReturn(sharedPreferences); diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java index 7e60edb9..25aba956 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java @@ -62,7 +62,7 @@ public class VpnConfigGeneratorTest { "\n" + "\n" + "\n" + - "-----BEGIN RSA PRIVATE KEY-----\n" + + "-----BEGIN RSA PRIVATE PROVIDER_KEY-----\n" + "MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDUTYWeGgsHS+fjijmziniNqw6h\n" + "MBpyK4S/cM6PxV28C33VuOWPTMcIYesctjZANWFCggfFTQSjV5Qaxq9UK4i27tayLbCdlVS6hpbl\n" + "Vf4DuI3Gj1Pv1rtITBShtvCf3T7yBnjW4wVpOpsUAAOViKUSvUU3kPPMFWhiGQw8yHYr82ts6XMo\n" + @@ -85,7 +85,7 @@ public class VpnConfigGeneratorTest { "ispy6Y0CgYEAgl1o2lo+ACyk+oVQPaaPqK3d7WOBFp4eR2nXFor/vsx9igQOlZUgzRDQsR8jo1o9\n" + "efOSBf87igrZGgssys89pWa2dnXnz5PMmzkKr6bw4D9Ez6u6Puc9UZhGw/8wDYg6fSosdB9utspm\n" + "M698ycef7jBNMDgmhpSvfw5GctoNQ4s=\n" + - "-----END RSA PRIVATE KEY-----\n" + + "-----END RSA PRIVATE PROVIDER_KEY-----\n" + "\n" + "\n" + "-----BEGIN CERTIFICATE-----\n" + @@ -160,7 +160,7 @@ public class VpnConfigGeneratorTest { "\n" + "\n" + "\n" + - "-----BEGIN RSA PRIVATE KEY-----\n" + + "-----BEGIN RSA PRIVATE PROVIDER_KEY-----\n" + "MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDUTYWeGgsHS+fjijmziniNqw6h\n" + "MBpyK4S/cM6PxV28C33VuOWPTMcIYesctjZANWFCggfFTQSjV5Qaxq9UK4i27tayLbCdlVS6hpbl\n" + "Vf4DuI3Gj1Pv1rtITBShtvCf3T7yBnjW4wVpOpsUAAOViKUSvUU3kPPMFWhiGQw8yHYr82ts6XMo\n" + @@ -183,7 +183,7 @@ public class VpnConfigGeneratorTest { "ispy6Y0CgYEAgl1o2lo+ACyk+oVQPaaPqK3d7WOBFp4eR2nXFor/vsx9igQOlZUgzRDQsR8jo1o9\n" + "efOSBf87igrZGgssys89pWa2dnXnz5PMmzkKr6bw4D9Ez6u6Puc9UZhGw/8wDYg6fSosdB9utspm\n" + "M698ycef7jBNMDgmhpSvfw5GctoNQ4s=\n" + - "-----END RSA PRIVATE KEY-----\n" + + "-----END RSA PRIVATE PROVIDER_KEY-----\n" + "\n" + "\n" + "-----BEGIN CERTIFICATE-----\n" + -- cgit v1.2.3 From 9aff13ef2a00fd4fec4756aafac7a033298035b3 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 7 Dec 2017 13:37:57 +0100 Subject: update production --- .../main/java/de/blinkt/openvpn/VpnProfile.java | 2 +- app/src/main/res/values/colors.xml | 22 ++++++++++++++++++++-- .../java/se/leap/bitmaskclient/ProviderAPI.java | 8 ++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java index cc8d987c..aa25da48 100644 --- a/app/src/main/java/de/blinkt/openvpn/VpnProfile.java +++ b/app/src/main/java/de/blinkt/openvpn/VpnProfile.java @@ -1017,7 +1017,7 @@ public class VpnProfile implements Serializable, Cloneable { if (data.contains("Proc-Type: 4,ENCRYPTED")) return true; - else if (data.contains("-----BEGIN ENCRYPTED PRIVATE PROVIDER_KEY-----")) + else if (data.contains("-----BEGIN ENCRYPTED PRIVATE KEY-----")) return true; else return false; diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 9f5d8813..1818312e 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,5 +1,23 @@ - #8080b0 - #555575 + #b39ddb + #ac97d2 + + #ef9a9a + #f48fb1 + #ce93d8 + #b39ddb + #9fa8da + #90caf9 + #81d4fa + #80deea + #80cbc4 + #a5d6a7 + #c5e1a5 + #e6ee9c + #fff59d + #ffe082 + #ffcc80 + #ffab91 + diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java index 9ab90cc2..fadb03c3 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java @@ -119,8 +119,8 @@ public class ProviderAPI extends ProviderApiBase { //TODO setProviderName(name); preferences.edit().putString(Provider.KEY, provider_json.toString()).commit(); - preferences.edit().putBoolean(Constants.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_ANON)).commit(); - preferences.edit().putBoolean(Constants.ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.ALLOWED_REGISTERED)).commit(); + preferences.edit().putBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS)).commit(); + preferences.edit().putBoolean(Constants.PROVIDER_ALLOWED_REGISTERED, provider_json.getJSONObject(Provider.SERVICE).getBoolean(Constants.PROVIDER_ALLOWED_REGISTERED)).commit(); result.putBoolean(RESULT_KEY, true); } catch (JSONException e) { @@ -149,7 +149,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject eip_service_json = new JSONObject(eip_service_json_string); eip_service_json.getInt(Provider.API_RETURN_SERIAL); - preferences.edit().putString(Constants.KEY, eip_service_json.toString()).commit(); + preferences.edit().putString(Constants.PROVIDER_KEY, eip_service_json.toString()).commit(); result.putBoolean(RESULT_KEY, true); } catch (NullPointerException | JSONException e) { @@ -172,7 +172,7 @@ public class ProviderAPI extends ProviderApiBase { JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); String provider_main_url = provider_json.getString(Provider.API_URL); - URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.VPN_CERTIFICATE); + URL new_cert_string_url = new URL(provider_main_url + "/" + provider_json.getString(Provider.API_VERSION) + "/" + Constants.PROVIDER_VPN_CERTIFICATE); String cert_string = downloadWithProviderCA(new_cert_string_url.toString()); -- cgit v1.2.3 From 58900d8452a1c09a55a99c40658437b1a2d3f51a Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 7 Dec 2017 14:58:48 +0100 Subject: update production --- .../production/java/se/leap/bitmaskclient/ProviderDetailFragment.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java index e288ebf8..c7224ede 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -57,7 +57,7 @@ public class ProviderDetailFragment extends DialogFragment { private boolean anon_allowed(JSONObject provider_json) { try { JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Constants.ALLOWED_ANON) && service_description.getBoolean(Constants.ALLOWED_ANON); + return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); } catch (JSONException e) { return false; } @@ -76,7 +76,7 @@ public class ProviderDetailFragment extends DialogFragment { public void onCancel(DialogInterface dialog) { super.onCancel(dialog); SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(Constants.ALLOWED_ANON).remove(Constants.KEY).commit(); + editor.remove(Provider.KEY).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).commit(); interface_with_configuration_wizard.cancelAndShowAllProviders(); } -- cgit v1.2.3 From b99938b1dc32f70800363f0faba88e7fd771abb4 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 7 Dec 2017 15:27:30 +0100 Subject: Undo renaming of KEY to PROVIDER_KEY * undo unwanted changes --- app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java | 4 ++-- .../java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java index 38981289..6e3b8b08 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiBase.java @@ -807,7 +807,7 @@ public abstract class ProviderApiBase extends IntentService { String certificateString = null, keyString = null; String[] certAndKey = cert_string.split("(?<=-\n)"); for (int i = 0; i < certAndKey.length - 1; i++) { - if (certAndKey[i].contains("PROVIDER_KEY")) { + if (certAndKey[i].contains("KEY")) { keyString = certAndKey[i++] + certAndKey[i]; } else if (certAndKey[i].contains("CERTIFICATE")) { certificateString = certAndKey[i++] + certAndKey[i]; @@ -816,7 +816,7 @@ public abstract class ProviderApiBase extends IntentService { RSAPrivateKey key = ConfigHelper.parseRsaKeyFromString(keyString); keyString = Base64.encodeToString(key.getEncoded(), Base64.DEFAULT); - preferences.edit().putString(Constants.PROVIDER_PRIVATE_KEY, "-----BEGIN RSA PRIVATE PROVIDER_KEY-----\n" + keyString + "-----END RSA PRIVATE PROVIDER_KEY-----").commit(); + preferences.edit().putString(Constants.PROVIDER_PRIVATE_KEY, "-----BEGIN RSA PRIVATE KEY-----\n" + keyString + "-----END RSA PRIVATE KEY-----").commit(); X509Certificate certificate = ConfigHelper.parseX509CertificateFromString(certificateString); certificateString = Base64.encodeToString(certificate.getEncoded(), Base64.DEFAULT); diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java index 25aba956..7e60edb9 100644 --- a/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java +++ b/app/src/test/java/se/leap/bitmaskclient/eip/VpnConfigGeneratorTest.java @@ -62,7 +62,7 @@ public class VpnConfigGeneratorTest { "\n" + "\n" + "\n" + - "-----BEGIN RSA PRIVATE PROVIDER_KEY-----\n" + + "-----BEGIN RSA PRIVATE KEY-----\n" + "MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDUTYWeGgsHS+fjijmziniNqw6h\n" + "MBpyK4S/cM6PxV28C33VuOWPTMcIYesctjZANWFCggfFTQSjV5Qaxq9UK4i27tayLbCdlVS6hpbl\n" + "Vf4DuI3Gj1Pv1rtITBShtvCf3T7yBnjW4wVpOpsUAAOViKUSvUU3kPPMFWhiGQw8yHYr82ts6XMo\n" + @@ -85,7 +85,7 @@ public class VpnConfigGeneratorTest { "ispy6Y0CgYEAgl1o2lo+ACyk+oVQPaaPqK3d7WOBFp4eR2nXFor/vsx9igQOlZUgzRDQsR8jo1o9\n" + "efOSBf87igrZGgssys89pWa2dnXnz5PMmzkKr6bw4D9Ez6u6Puc9UZhGw/8wDYg6fSosdB9utspm\n" + "M698ycef7jBNMDgmhpSvfw5GctoNQ4s=\n" + - "-----END RSA PRIVATE PROVIDER_KEY-----\n" + + "-----END RSA PRIVATE KEY-----\n" + "\n" + "\n" + "-----BEGIN CERTIFICATE-----\n" + @@ -160,7 +160,7 @@ public class VpnConfigGeneratorTest { "\n" + "\n" + "\n" + - "-----BEGIN RSA PRIVATE PROVIDER_KEY-----\n" + + "-----BEGIN RSA PRIVATE KEY-----\n" + "MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDUTYWeGgsHS+fjijmziniNqw6h\n" + "MBpyK4S/cM6PxV28C33VuOWPTMcIYesctjZANWFCggfFTQSjV5Qaxq9UK4i27tayLbCdlVS6hpbl\n" + "Vf4DuI3Gj1Pv1rtITBShtvCf3T7yBnjW4wVpOpsUAAOViKUSvUU3kPPMFWhiGQw8yHYr82ts6XMo\n" + @@ -183,7 +183,7 @@ public class VpnConfigGeneratorTest { "ispy6Y0CgYEAgl1o2lo+ACyk+oVQPaaPqK3d7WOBFp4eR2nXFor/vsx9igQOlZUgzRDQsR8jo1o9\n" + "efOSBf87igrZGgssys89pWa2dnXnz5PMmzkKr6bw4D9Ez6u6Puc9UZhGw/8wDYg6fSosdB9utspm\n" + "M698ycef7jBNMDgmhpSvfw5GctoNQ4s=\n" + - "-----END RSA PRIVATE PROVIDER_KEY-----\n" + + "-----END RSA PRIVATE KEY-----\n" + "\n" + "\n" + "-----BEGIN CERTIFICATE-----\n" + -- cgit v1.2.3 From d835a9b8f38acf1970acc18ce2030f7d5f7377dd Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 28 Nov 2017 01:51:19 +0100 Subject: base for sidebar --- app/build.gradle | 7 +- app/src/main/AndroidManifest.xml | 99 ++++---- .../de/blinkt/openvpn/fragments/LogFragment.java | 39 --- .../java/se/leap/bitmaskclient/MainActivity.java | 115 +++++++++ .../bitmaskclient/NavigationDrawerFragment.java | 282 +++++++++++++++++++++ .../java/se/leap/bitmaskclient/StartActivity.java | 2 +- app/src/main/res/drawable-hdpi/drawer_shadow.9.png | Bin 0 -> 161 bytes app/src/main/res/drawable-hdpi/ic_drawer.png | Bin 0 -> 2829 bytes app/src/main/res/drawable-mdpi/drawer_shadow.9.png | Bin 0 -> 142 bytes app/src/main/res/drawable-mdpi/ic_drawer.png | Bin 0 -> 2820 bytes .../main/res/drawable-xhdpi/drawer_shadow.9.png | Bin 0 -> 174 bytes app/src/main/res/drawable-xhdpi/ic_drawer.png | Bin 0 -> 2836 bytes .../main/res/drawable-xxhdpi/drawer_shadow.9.png | Bin 0 -> 208 bytes app/src/main/res/drawable-xxhdpi/ic_drawer.png | Bin 0 -> 202 bytes app/src/main/res/layout/activity_main.xml | 42 +++ app/src/main/res/layout/drawer_main.xml | 22 ++ app/src/main/res/layout/fragment_main.xml | 16 ++ app/src/main/res/menu/main.xml | 13 + app/src/main/res/values-w820dp/dimens.xml | 6 + app/src/main/res/values/dimens.xml | 10 +- app/src/main/res/values/strings.xml | 14 +- app/src/main/res/values/themes.xml | 2 +- 22 files changed, 568 insertions(+), 101 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/MainActivity.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java create mode 100644 app/src/main/res/drawable-hdpi/drawer_shadow.9.png create mode 100644 app/src/main/res/drawable-hdpi/ic_drawer.png create mode 100644 app/src/main/res/drawable-mdpi/drawer_shadow.9.png create mode 100644 app/src/main/res/drawable-mdpi/ic_drawer.png create mode 100644 app/src/main/res/drawable-xhdpi/drawer_shadow.9.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_drawer.png create mode 100644 app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_drawer.png create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/drawer_main.xml create mode 100644 app/src/main/res/layout/fragment_main.xml create mode 100644 app/src/main/res/menu/main.xml create mode 100644 app/src/main/res/values-w820dp/dimens.xml diff --git a/app/build.gradle b/app/build.gradle index b9db8cd6..c19309fc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,6 +78,8 @@ dependencies { compile 'com.android.support:support-annotations:27.0.1' compile 'com.android.support:support-v4:26.1.0' compile 'com.android.support:appcompat-v7:26.1.0' + compile 'com.android.support:design:26.1.0' + compile 'com.android.support:support-fragment:26.1.0' } def processFileInplace(file, Closure processText) { @@ -100,8 +102,6 @@ task copyIcsOpenVPNClasses( type: Copy ) { include '**/log_fragment.xml' include '**/log_silders.xml' include '**/vpnstatus.xml' - include '**/styles.xml' - include '**/dimens.xml' include '**/logmenu.xml' include '**/core/**.java' include '**/activities/BaseActivity.java' @@ -129,10 +129,7 @@ task copyIcsOpenVPNXml( type: Copy ) { include '**/strings.xml' include '**/log_*.xml' include '**/vpnstatus.xml' - include '**/styles.xml' - include '**/dimens.xml' include '**/refs.xml' - include '**/colours.xml' include '**/logmenu.xml' include '**/white_rect.xml' include '**/plurals.xml' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 16168e0f..72d2ce54 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - - - + android:versionName="0.9.7"> + + - - - + + + - + android:logo="@drawable/icon" + android:theme="@style/AppTheme"> - @@ -53,50 +52,42 @@ - - + + - - - + android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> + + + - - - + android:name=".eip.VoidVpnLauncher" + android:theme="@android:style/Theme.Translucent.NoTitleBar" /> + - - + android:label="@string/vpn_launch_title"> - - + android:uiOptions="splitActionBarWhenNarrow"> - + android:theme="@style/SplashTheme"> @@ -104,22 +95,26 @@ - + android:uiOptions="splitActionBarWhenNarrow"> - - - + android:name=".AboutActivity" + android:label="@string/title_about_activity"> + + - - - + + + + + - + \ No newline at end of file diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java index a1fc7cdc..d5931c83 100644 --- a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -423,45 +423,6 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. private TextView mSpeedView; - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.clearlog) { - ladapter.clearLog(); - return true; - } else if (item.getItemId() == R.id.cancel) { - Intent intent = new Intent(getActivity(), DisconnectVPN.class); - startActivity(intent); - return true; - } else if (item.getItemId() == R.id.send) { - ladapter.shareLog(); - } else if (item.getItemId() == R.id.edit_vpn) { - VpnProfile lastConnectedprofile = ProfileManager.get(getActivity(), VpnStatus.getLastConnectedVPNProfile()); - - if (lastConnectedprofile != null) { - Intent vprefintent = new Intent(getActivity(), Dashboard.class) - .putExtra(VpnProfile.EXTRA_PROFILEUUID, lastConnectedprofile.getUUIDString()); - startActivityForResult(vprefintent, START_VPN_CONFIG); - } else { - Toast.makeText(getActivity(), R.string.log_no_last_vpn, Toast.LENGTH_LONG).show(); - } - } else if (item.getItemId() == R.id.toggle_time) { - showHideOptionsPanel(); - } else if (item.getItemId() == android.R.id.home) { - // This is called when the Home (Up) button is pressed - // in the Action Bar. - Intent parentActivityIntent = new Intent(getActivity(), Dashboard.class); - parentActivityIntent.addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | - Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(parentActivityIntent); - getActivity().finish(); - return true; - - } - return super.onOptionsItemSelected(item); - - } - private void showHideOptionsPanel() { boolean optionsVisible = (mOptionsLayout.getVisibility() != View.GONE); diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java new file mode 100644 index 00000000..d28d0784 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java @@ -0,0 +1,115 @@ +package se.leap.bitmaskclient; + + +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.support.v4.widget.DrawerLayout; + +public class MainActivity extends AppCompatActivity + implements NavigationDrawerFragment.NavigationDrawerCallbacks { + + /** + * Fragment managing the behaviors, interactions and presentation of the navigation drawer. + */ + private NavigationDrawerFragment mNavigationDrawerFragment; + + /** + * Used to store the last screen title. For use in {@link #restoreActionBar()}. + */ + private CharSequence mTitle; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); + + mNavigationDrawerFragment = (NavigationDrawerFragment) + getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); + mTitle = getTitle(); + + // Set up the drawer. + mNavigationDrawerFragment.setUp( + R.id.navigation_drawer, + (DrawerLayout) findViewById(R.id.drawer_layout)); + } + + @Override + public void onNavigationDrawerItemSelected(int position) { + // update the main content by replacing fragments + FragmentManager fragmentManager = getSupportFragmentManager(); + fragmentManager.beginTransaction() + .replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) + .commit(); + } + + public void onSectionAttached(int number) { + switch (number) { + case 1: + mTitle = getString(R.string.title_section1); + break; + case 2: + mTitle = getString(R.string.title_section2); + break; + case 3: + mTitle = getString(R.string.title_section3); + break; + } + } + + public void restoreActionBar() { + ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setTitle(mTitle); + } + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + /** + * The fragment argument representing the section number for this + * fragment. + */ + private static final String ARG_SECTION_NUMBER = "section_number"; + + public PlaceholderFragment() { + } + + /** + * Returns a new instance of this fragment for the given section + * number. + */ + public static PlaceholderFragment newInstance(int sectionNumber) { + PlaceholderFragment fragment = new PlaceholderFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + fragment.setArguments(args); + return fragment; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_main, container, false); + return rootView; + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + ((MainActivity) context).onSectionAttached( + getArguments().getInt(ARG_SECTION_NUMBER)); + } + } + +} diff --git a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java new file mode 100644 index 00000000..22a4f8a0 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java @@ -0,0 +1,282 @@ +package se.leap.bitmaskclient; + + +import android.content.Context; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v4.app.Fragment; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +/** + * Fragment used for managing interactions for and presentation of a navigation drawer. + * See the + * design guidelines for a complete explanation of the behaviors implemented here. + */ +public class NavigationDrawerFragment extends Fragment { + + /** + * Remember the position of the selected item. + */ + private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; + + /** + * Per the design guidelines, you should show the drawer on launch until the user manually + * expands it. This shared preference tracks this. + */ + private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; + + /** + * A pointer to the current callbacks instance (the Activity). + */ + private NavigationDrawerCallbacks mCallbacks; + + /** + * Helper component that ties the action bar to the navigation drawer. + */ + private ActionBarDrawerToggle mDrawerToggle; + + private DrawerLayout mDrawerLayout; + private View mDrawerView; + private ListView mDrawerListView; + private View mFragmentContainerView; + + private int mCurrentSelectedPosition = 0; + private boolean mFromSavedInstanceState; + private boolean mUserLearnedDrawer; + + public NavigationDrawerFragment() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Read in the flag indicating whether or not the user has demonstrated awareness of the + // drawer. See PREF_USER_LEARNED_DRAWER for details. + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); + mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); + + if (savedInstanceState != null) { + mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); + mFromSavedInstanceState = true; + } + + // Select either the default item (0) or the last selected item. + selectItem(mCurrentSelectedPosition); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + // Indicate that this fragment would like to influence the set of actions in the action bar. + setHasOptionsMenu(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mDrawerView = inflater.inflate(R.layout.drawer_main, container, false); + return mDrawerView; + } + + public boolean isDrawerOpen() { + return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); + } + + /** + * Users of this fragment must call this method to set up the navigation drawer interactions. + * + * @param fragmentId The android:id of this fragment in its activity's layout. + * @param drawerLayout The DrawerLayout containing this fragment's UI. + */ + public void setUp(int fragmentId, DrawerLayout drawerLayout) { + AppCompatActivity activity = (AppCompatActivity) getActivity(); + + mDrawerListView = mDrawerView.findViewById(R.id.accountList); + mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(position); + } + }); + + ActionBar actionBar = activity.getSupportActionBar(); + mDrawerListView.setAdapter(new ArrayAdapter( + actionBar.getThemedContext(), + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + new String[]{ + getString(R.string.title_section1), + getString(R.string.title_section2), + getString(R.string.title_section3), + })); + mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); + mFragmentContainerView = activity.findViewById(fragmentId); + mDrawerLayout = drawerLayout; + + // set a custom shadow that overlays the main content when the drawer opens + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); + + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + // ActionBarDrawerToggle ties together the the proper interactions + // between the navigation drawer and the action bar app icon. + mDrawerToggle = new ActionBarDrawerToggle( + getActivity(), + mDrawerLayout, + (Toolbar) drawerLayout.findViewById(R.id.toolbar), + R.string.navigation_drawer_open, + R.string.navigation_drawer_close + ) { + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + if (!isAdded()) { + return; + } + + getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + if (!isAdded()) { + return; + } + + if (!mUserLearnedDrawer) { + // The user manually opened the drawer; store this flag to prevent auto-showing + // the navigation drawer automatically in the future. + mUserLearnedDrawer = true; + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences(getActivity()); + sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); + } + + getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + }; + + // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, + // per the navigation drawer design guidelines. + if (!mUserLearnedDrawer && !mFromSavedInstanceState) { + mDrawerLayout.openDrawer(mFragmentContainerView); + } + + // Defer code dependent on restoration of previous instance state. + mDrawerLayout.post(new Runnable() { + @Override + public void run() { + mDrawerToggle.syncState(); + } + }); + + mDrawerLayout.addDrawerListener(mDrawerToggle); + } + + private void selectItem(int position) { + mCurrentSelectedPosition = position; + if (mDrawerListView != null) { + mDrawerListView.setItemChecked(position, true); + } + if (mDrawerLayout != null) { + mDrawerLayout.closeDrawer(mFragmentContainerView); + } + if (mCallbacks != null) { + mCallbacks.onNavigationDrawerItemSelected(position); + } + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + try { + mCallbacks = (NavigationDrawerCallbacks) context; + } catch (ClassCastException e) { + throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mCallbacks = null; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + // Forward the new configuration the drawer toggle component. + mDrawerToggle.onConfigurationChanged(newConfig); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if (mDrawerLayout != null && isDrawerOpen()) { + showGlobalContextActionBar(); + } + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; + } + + if (item.getItemId() == R.id.action_example) { + Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show(); + return true; + } + + return super.onOptionsItemSelected(item); + } + + /** + * Per the navigation drawer design guidelines, updates the action bar to show the global app + * 'context', rather than just what's in the current screen. + */ + private void showGlobalContextActionBar() { + ActionBar actionBar = getActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setTitle(R.string.app_name); + } + + private ActionBar getActionBar() { + return ((AppCompatActivity) getActivity()).getSupportActionBar(); + } + + /** + * Callbacks interface that all activities using this fragment must implement. + */ + public interface NavigationDrawerCallbacks { + /** + * Called when an item in the navigation drawer is selected. + */ + void onNavigationDrawerItemSelected(int position); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index dd2be212..1bf81aea 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -67,7 +67,7 @@ public class StartActivity extends Activity { User.init(getString(R.string.default_username)); // go to Dashboard - Intent intent = new Intent(this, Dashboard.class); + Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } diff --git a/app/src/main/res/drawable-hdpi/drawer_shadow.9.png b/app/src/main/res/drawable-hdpi/drawer_shadow.9.png new file mode 100644 index 00000000..236bff55 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/drawer_shadow.9.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_drawer.png b/app/src/main/res/drawable-hdpi/ic_drawer.png new file mode 100644 index 00000000..c59f601c Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_drawer.png differ diff --git a/app/src/main/res/drawable-mdpi/drawer_shadow.9.png b/app/src/main/res/drawable-mdpi/drawer_shadow.9.png new file mode 100644 index 00000000..ffe3a28d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/drawer_shadow.9.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_drawer.png b/app/src/main/res/drawable-mdpi/ic_drawer.png new file mode 100644 index 00000000..1ed2c56e Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_drawer.png differ diff --git a/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png b/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png new file mode 100644 index 00000000..fabe9d96 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/drawer_shadow.9.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_drawer.png b/app/src/main/res/drawable-xhdpi/ic_drawer.png new file mode 100644 index 00000000..a5fa74de Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_drawer.png differ diff --git a/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png b/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png new file mode 100644 index 00000000..b91e9d7f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/drawer_shadow.9.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_drawer.png b/app/src/main/res/drawable-xxhdpi/ic_drawer.png new file mode 100644 index 00000000..9c4685d6 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_drawer.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..28c23503 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/drawer_main.xml b/app/src/main/res/layout/drawer_main.xml new file mode 100644 index 00000000..9327d03f --- /dev/null +++ b/app/src/main/res/layout/drawer_main.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml new file mode 100644 index 00000000..31dbd11e --- /dev/null +++ b/app/src/main/res/layout/fragment_main.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml new file mode 100644 index 00000000..56f43959 --- /dev/null +++ b/app/src/main/res/menu/main.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 00000000..63fc8164 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index f8fafecd..c92860be 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,5 +1,4 @@ - - @@ -17,4 +16,11 @@ 56dp 16dp 16dp + + 16dp + 16dp + + + 240dp \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 04e83a18..762655b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,7 +30,7 @@ password User message About Bitmask - Try again: server math error. + Try again: server math error. Incorrect username or password. It should have at least 8 characters. Try again: Client HTTP error @@ -77,4 +77,16 @@ Turn on Turn off Bitmask Log + MainActivity + + Section 1 + Section 2 + Section 3 + + Open navigation drawer + Close navigation drawer + + Example action + + Settings diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 80607409..a64779e5 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,6 +1,6 @@ - -- cgit v1.2.3 From 41d8aeef77d93db93dd508045f1d05228480067a Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 12 Dec 2017 15:39:12 +0100 Subject: Use VectorDrawable instead of Images --- app/build.gradle | 1 + .../de/blinkt/openvpn/fragments/LogFragment.java | 39 ---------------- .../main/res/drawable-hdpi/splash_background.png | Bin 66619 -> 0 bytes .../res/drawable-land-hdpi/splash_background.png | Bin 68637 -> 0 bytes .../res/drawable-land-ldpi/splash_background.png | Bin 43127 -> 0 bytes .../res/drawable-land-mdpi/splash_background.png | Bin 33924 -> 0 bytes .../drawable-land-xxxhdpi/splash_background.png | Bin 182692 -> 0 bytes .../main/res/drawable-ldpi/splash_background.png | Bin 41839 -> 0 bytes .../main/res/drawable-mdpi/splash_background.png | Bin 32718 -> 0 bytes .../res/drawable-xxxhdpi/splash_background.png | Bin 187062 -> 0 bytes app/src/main/res/drawable/ic_colorsquare.xml | 52 +++++++++++++++++++++ app/src/main/res/drawable/splash_page.xml | 3 +- 12 files changed, 55 insertions(+), 40 deletions(-) delete mode 100644 app/src/main/res/drawable-hdpi/splash_background.png delete mode 100644 app/src/main/res/drawable-land-hdpi/splash_background.png delete mode 100644 app/src/main/res/drawable-land-ldpi/splash_background.png delete mode 100644 app/src/main/res/drawable-land-mdpi/splash_background.png delete mode 100644 app/src/main/res/drawable-land-xxxhdpi/splash_background.png delete mode 100644 app/src/main/res/drawable-ldpi/splash_background.png delete mode 100644 app/src/main/res/drawable-mdpi/splash_background.png delete mode 100644 app/src/main/res/drawable-xxxhdpi/splash_background.png create mode 100644 app/src/main/res/drawable/ic_colorsquare.xml diff --git a/app/build.gradle b/app/build.gradle index b9db8cd6..35665852 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,6 +10,7 @@ android { defaultConfig { applicationId "se.leap.bitmaskclient" resValue "string", "app_name", "Bitmask" + vectorDrawables.useSupportLibrary = true } signingConfigs { diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java index a1fc7cdc..d5931c83 100644 --- a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -423,45 +423,6 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. private TextView mSpeedView; - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.clearlog) { - ladapter.clearLog(); - return true; - } else if (item.getItemId() == R.id.cancel) { - Intent intent = new Intent(getActivity(), DisconnectVPN.class); - startActivity(intent); - return true; - } else if (item.getItemId() == R.id.send) { - ladapter.shareLog(); - } else if (item.getItemId() == R.id.edit_vpn) { - VpnProfile lastConnectedprofile = ProfileManager.get(getActivity(), VpnStatus.getLastConnectedVPNProfile()); - - if (lastConnectedprofile != null) { - Intent vprefintent = new Intent(getActivity(), Dashboard.class) - .putExtra(VpnProfile.EXTRA_PROFILEUUID, lastConnectedprofile.getUUIDString()); - startActivityForResult(vprefintent, START_VPN_CONFIG); - } else { - Toast.makeText(getActivity(), R.string.log_no_last_vpn, Toast.LENGTH_LONG).show(); - } - } else if (item.getItemId() == R.id.toggle_time) { - showHideOptionsPanel(); - } else if (item.getItemId() == android.R.id.home) { - // This is called when the Home (Up) button is pressed - // in the Action Bar. - Intent parentActivityIntent = new Intent(getActivity(), Dashboard.class); - parentActivityIntent.addFlags( - Intent.FLAG_ACTIVITY_CLEAR_TOP | - Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(parentActivityIntent); - getActivity().finish(); - return true; - - } - return super.onOptionsItemSelected(item); - - } - private void showHideOptionsPanel() { boolean optionsVisible = (mOptionsLayout.getVisibility() != View.GONE); diff --git a/app/src/main/res/drawable-hdpi/splash_background.png b/app/src/main/res/drawable-hdpi/splash_background.png deleted file mode 100644 index 11dfd005..00000000 Binary files a/app/src/main/res/drawable-hdpi/splash_background.png and /dev/null differ diff --git a/app/src/main/res/drawable-land-hdpi/splash_background.png b/app/src/main/res/drawable-land-hdpi/splash_background.png deleted file mode 100644 index c2e123ce..00000000 Binary files a/app/src/main/res/drawable-land-hdpi/splash_background.png and /dev/null differ diff --git a/app/src/main/res/drawable-land-ldpi/splash_background.png b/app/src/main/res/drawable-land-ldpi/splash_background.png deleted file mode 100644 index 29f9e7cb..00000000 Binary files a/app/src/main/res/drawable-land-ldpi/splash_background.png and /dev/null differ diff --git a/app/src/main/res/drawable-land-mdpi/splash_background.png b/app/src/main/res/drawable-land-mdpi/splash_background.png deleted file mode 100644 index bf43f632..00000000 Binary files a/app/src/main/res/drawable-land-mdpi/splash_background.png and /dev/null differ diff --git a/app/src/main/res/drawable-land-xxxhdpi/splash_background.png b/app/src/main/res/drawable-land-xxxhdpi/splash_background.png deleted file mode 100644 index 12a9e8a8..00000000 Binary files a/app/src/main/res/drawable-land-xxxhdpi/splash_background.png and /dev/null differ diff --git a/app/src/main/res/drawable-ldpi/splash_background.png b/app/src/main/res/drawable-ldpi/splash_background.png deleted file mode 100644 index eaae5efb..00000000 Binary files a/app/src/main/res/drawable-ldpi/splash_background.png and /dev/null differ diff --git a/app/src/main/res/drawable-mdpi/splash_background.png b/app/src/main/res/drawable-mdpi/splash_background.png deleted file mode 100644 index 4df57929..00000000 Binary files a/app/src/main/res/drawable-mdpi/splash_background.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxxhdpi/splash_background.png b/app/src/main/res/drawable-xxxhdpi/splash_background.png deleted file mode 100644 index 4ad0e2c3..00000000 Binary files a/app/src/main/res/drawable-xxxhdpi/splash_background.png and /dev/null differ diff --git a/app/src/main/res/drawable/ic_colorsquare.xml b/app/src/main/res/drawable/ic_colorsquare.xml new file mode 100644 index 00000000..4b60e9dc --- /dev/null +++ b/app/src/main/res/drawable/ic_colorsquare.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/splash_page.xml b/app/src/main/res/drawable/splash_page.xml index 1d8a6bf6..0a083c7e 100644 --- a/app/src/main/res/drawable/splash_page.xml +++ b/app/src/main/res/drawable/splash_page.xml @@ -1,7 +1,8 @@ - + -- cgit v1.2.3 From 9a35f971f917ef4141923d50deb25fa0d2f9b7dd Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 12 Dec 2017 16:17:03 +0100 Subject: set background --- app/src/main/res/layout/drawer_main.xml | 5 +++-- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/dimens.xml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/layout/drawer_main.xml b/app/src/main/res/layout/drawer_main.xml index 9327d03f..b2254d2a 100644 --- a/app/src/main/res/layout/drawer_main.xml +++ b/app/src/main/res/layout/drawer_main.xml @@ -3,17 +3,18 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" + android:background="@color/colorBackground" tools:context="se.leap.bitmaskclient.NavigationDrawerFragment"> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1818312e..49415189 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -2,6 +2,7 @@ #b39ddb #ac97d2 + #fffafafa #ef9a9a #f48fb1 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index c92860be..b9a3890f 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -22,5 +22,5 @@ - 240dp + 300dp \ No newline at end of file -- cgit v1.2.3 From 1312c0dab26508f41246ea925176709fffeb465c Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 12 Dec 2017 20:23:11 +0100 Subject: make downward compatible --- app/src/main/res/layout/drawer_main.xml | 37 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/app/src/main/res/layout/drawer_main.xml b/app/src/main/res/layout/drawer_main.xml index b2254d2a..e1f7b15c 100644 --- a/app/src/main/res/layout/drawer_main.xml +++ b/app/src/main/res/layout/drawer_main.xml @@ -1,23 +1,40 @@ - + android:layout_height="wrap_content"> - + + + + + + + + android:layout_height="match_parent" /> - \ No newline at end of file -- cgit v1.2.3 From 08ec840de9657085d9a0baaab54f6b33e16a12d0 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 14 Dec 2017 21:21:22 +0100 Subject: add LogFragment --- .../leap/bitmaskclient/test/VpnTestController.java | 1 - app/src/main/AndroidManifest.xml | 6 - .../de/blinkt/openvpn/fragments/LogFragment.java | 39 ++ .../java/se/leap/bitmaskclient/MainActivity.java | 44 +- .../bitmaskclient/NavigationDrawerFragment.java | 2 +- .../leap/bitmaskclient/fragments/LogFragment.java | 688 +++++++++++++++++++++ app/src/main/res/layout-sw600dp-port/f_log.xml | 45 ++ app/src/main/res/layout-sw600dp/f_log.xml | 34 + app/src/main/res/layout-v21/f_log.xml | 37 ++ app/src/main/res/layout/drawer_main.xml | 20 +- app/src/main/res/layout/f_log_sliders.xml | 73 +++ app/src/main/res/menu/f_log.xml | 39 ++ app/src/main/res/values/strings.xml | 4 +- 13 files changed, 999 insertions(+), 33 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/fragments/LogFragment.java create mode 100644 app/src/main/res/layout-sw600dp-port/f_log.xml create mode 100644 app/src/main/res/layout-sw600dp/f_log.xml create mode 100644 app/src/main/res/layout-v21/f_log.xml create mode 100644 app/src/main/res/layout/f_log_sliders.xml create mode 100644 app/src/main/res/menu/f_log.xml diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java index 4c6a6370..f6760161 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/VpnTestController.java @@ -6,7 +6,6 @@ import android.widget.Button; import com.robotium.solo.Condition; import com.robotium.solo.Solo; -import de.blinkt.openvpn.activities.DisconnectVPN; import mbanje.kurt.fabbutton.ProgressRingView; import se.leap.bitmaskclient.Dashboard; import se.leap.bitmaskclient.R; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 72d2ce54..bf49b152 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -68,15 +68,9 @@ - - allEntries = new Vector<>(); + + private Vector currentLevelEntries = new Vector(); + + private Handler mHandler; + + private Vector observers = new Vector(); + + private int mTimeFormat = 0; + private int mLogLevel = 3; + + + public LogWindowListAdapter() { + initLogBuffer(); + if (mHandler == null) { + mHandler = new Handler(this); + } + + VpnStatus.addLogListener(this); + } + + + private void initLogBuffer() { + allEntries.clear(); + Collections.addAll(allEntries, VpnStatus.getlogbuffer()); + initCurrentMessages(); + } + + String getLogStr() { + String str = ""; + for (LogItem entry : allEntries) { + str += getTime(entry, TIME_FORMAT_ISO) + entry.getString(getActivity()) + '\n'; + } + return str; + } + + + private void shareLog() { + Intent shareIntent = new Intent(Intent.ACTION_SEND); + shareIntent.putExtra(Intent.EXTRA_TEXT, getLogStr()); + shareIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.ics_openvpn_log_file)); + shareIntent.setType("text/plain"); + startActivity(Intent.createChooser(shareIntent, "Send Logfile")); + } + + @Override + public void registerDataSetObserver(DataSetObserver observer) { + observers.add(observer); + + } + + @Override + public void unregisterDataSetObserver(DataSetObserver observer) { + observers.remove(observer); + } + + @Override + public int getCount() { + return currentLevelEntries.size(); + } + + @Override + public Object getItem(int position) { + return currentLevelEntries.get(position); + } + + @Override + public long getItemId(int position) { + return ((Object) currentLevelEntries.get(position)).hashCode(); + } + + @Override + public boolean hasStableIds() { + return true; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + TextView v; + if (convertView == null) + v = new TextView(getActivity()); + else + v = (TextView) convertView; + + LogItem le = currentLevelEntries.get(position); + String msg = le.getString(getActivity()); + String time = getTime(le, mTimeFormat); + msg = time + msg; + + int spanStart = time.length(); + + SpannableString t = new SpannableString(msg); + + //t.setSpan(getSpanImage(le,(int)v.getTextSize()),spanStart,spanStart+1, Spanned.SPAN_INCLUSIVE_INCLUSIVE); + v.setText(t); + return v; + } + + private String getTime(LogItem le, int time) { + if (time != TIME_FORMAT_NONE) { + Date d = new Date(le.getLogtime()); + java.text.DateFormat timeformat; + if (time == TIME_FORMAT_ISO) + timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + else + timeformat = DateFormat.getTimeFormat(getActivity()); + + return timeformat.format(d) + " "; + + } else { + return ""; + } + + } + + private ImageSpan getSpanImage(LogItem li, int imageSize) { + int imageRes = android.R.drawable.ic_menu_call; + + switch (li.getLogLevel()) { + case ERROR: + imageRes = android.R.drawable.ic_notification_clear_all; + break; + case INFO: + imageRes = android.R.drawable.ic_menu_compass; + break; + case VERBOSE: + imageRes = android.R.drawable.ic_menu_info_details; + break; + case WARNING: + imageRes = android.R.drawable.ic_menu_camera; + break; + } + + Drawable d = getResources().getDrawable(imageRes); + + + //d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); + d.setBounds(0, 0, imageSize, imageSize); + ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM); + + return span; + } + + @Override + public int getItemViewType(int position) { + return 0; + } + + @Override + public int getViewTypeCount() { + return 1; + } + + @Override + public boolean isEmpty() { + return currentLevelEntries.isEmpty(); + + } + + @Override + public boolean areAllItemsEnabled() { + return true; + } + + @Override + public boolean isEnabled(int position) { + return true; + } + + @Override + public void newLog(LogItem logMessage) { + Message msg = Message.obtain(); + assert (msg != null); + msg.what = MESSAGE_NEWLOG; + Bundle bundle = new Bundle(); + bundle.putParcelable("logmessage", logMessage); + msg.setData(bundle); + mHandler.sendMessage(msg); + } + + @Override + public boolean handleMessage(Message msg) { + // We have been called + if (msg.what == MESSAGE_NEWLOG) { + + LogItem logMessage = msg.getData().getParcelable("logmessage"); + if (addLogMessage(logMessage)) + for (DataSetObserver observer : observers) { + observer.onChanged(); + } + } else if (msg.what == MESSAGE_CLEARLOG) { + for (DataSetObserver observer : observers) { + observer.onInvalidated(); + } + initLogBuffer(); + } else if (msg.what == MESSAGE_NEWTS) { + for (DataSetObserver observer : observers) { + observer.onInvalidated(); + } + } else if (msg.what == MESSAGE_NEWLOGLEVEL) { + initCurrentMessages(); + + for (DataSetObserver observer : observers) { + observer.onChanged(); + } + + } + + return true; + } + + private void initCurrentMessages() { + currentLevelEntries.clear(); + for (LogItem li : allEntries) { + if (li.getVerbosityLevel() <= mLogLevel || + mLogLevel == VpnProfile.MAXLOGLEVEL) + currentLevelEntries.add(li); + } + } + + /** + * @param logmessage + * @return True if the current entries have changed + */ + private boolean addLogMessage(LogItem logmessage) { + allEntries.add(logmessage); + + if (allEntries.size() > MAX_STORED_LOG_ENTRIES) { + Vector oldAllEntries = allEntries; + allEntries = new Vector(allEntries.size()); + for (int i = 50; i < oldAllEntries.size(); i++) { + allEntries.add(oldAllEntries.elementAt(i)); + } + initCurrentMessages(); + return true; + } else { + if (logmessage.getVerbosityLevel() <= mLogLevel) { + currentLevelEntries.add(logmessage); + return true; + } else { + return false; + } + } + } + + void clearLog() { + // Actually is probably called from GUI Thread as result of the user + // pressing a button. But better safe than sorry + VpnStatus.clearLog(); + VpnStatus.logInfo(R.string.logCleared); + mHandler.sendEmptyMessage(MESSAGE_CLEARLOG); + } + + + public void setTimeFormat(int newTimeFormat) { + mTimeFormat = newTimeFormat; + mHandler.sendEmptyMessage(MESSAGE_NEWTS); + } + + public void setLogLevel(int logLevel) { + mLogLevel = logLevel; + mHandler.sendEmptyMessage(MESSAGE_NEWLOGLEVEL); + } + + } + + + private LogWindowListAdapter ladapter; + private TextView mSpeedView; + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == R.id.clearlog) { + ladapter.clearLog(); + return true; + } else if (item.getItemId() == R.id.send) { + ladapter.shareLog(); + } else if (item.getItemId() == R.id.edit_vpn) { + VpnProfile lastConnectedprofile = ProfileManager.get(getActivity(), VpnStatus.getLastConnectedVPNProfile()); + + if (lastConnectedprofile != null) { + Intent vprefintent = new Intent(getActivity(), Dashboard.class) + .putExtra(VpnProfile.EXTRA_PROFILEUUID, lastConnectedprofile.getUUIDString()); + startActivityForResult(vprefintent, START_VPN_CONFIG); + } else { + Toast.makeText(getActivity(), R.string.log_no_last_vpn, Toast.LENGTH_LONG).show(); + } + } else if (item.getItemId() == R.id.toggle_time) { + showHideOptionsPanel(); + } else if (item.getItemId() == android.R.id.home) { + // This is called when the Home (Up) button is pressed + // in the Action Bar. + Intent parentActivityIntent = new Intent(getActivity(), Dashboard.class); + parentActivityIntent.addFlags( + Intent.FLAG_ACTIVITY_CLEAR_TOP | + Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(parentActivityIntent); + getActivity().finish(); + return true; + + } + return super.onOptionsItemSelected(item); + + } + + private void showHideOptionsPanel() { + boolean optionsVisible = (mOptionsLayout.getVisibility() != View.GONE); + + ObjectAnimator anim; + if (optionsVisible) { + anim = ObjectAnimator.ofFloat(mOptionsLayout, "alpha", 1.0f, 0f); + anim.addListener(collapseListener); + + } else { + mOptionsLayout.setVisibility(View.VISIBLE); + anim = ObjectAnimator.ofFloat(mOptionsLayout, "alpha", 0f, 1.0f); + //anim = new TranslateAnimation(0.0f, 0.0f, mOptionsLayout.getHeight(), 0.0f); + + } + + //anim.setInterpolator(new AccelerateInterpolator(1.0f)); + //anim.setDuration(300); + //mOptionsLayout.startAnimation(anim); + anim.start(); + + } + + AnimatorListenerAdapter collapseListener = new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animator) { + mOptionsLayout.setVisibility(View.GONE); + } + + }; + + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.f_log, menu); + if (getResources().getBoolean(R.bool.logSildersAlwaysVisible)) + menu.removeItem(R.id.toggle_time); + } + + + @Override + public void onResume() { + super.onResume(); + Intent intent = new Intent(getActivity(), OpenVPNService.class); + intent.setAction(OpenVPNService.START_SERVICE); + } + + @Override + public void onStart() { + super.onStart(); + VpnStatus.addStateListener(this); + VpnStatus.addByteCountListener(this); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == START_VPN_CONFIG && resultCode == Activity.RESULT_OK) { + String configuredVPN = data.getStringExtra(VpnProfile.EXTRA_PROFILEUUID); + + final VpnProfile profile = ProfileManager.get(getActivity(), configuredVPN); + ProfileManager.getInstance(getActivity()).saveProfile(getActivity(), profile); + // Name could be modified, reset List adapter + + AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); + dialog.setTitle(R.string.configuration_changed); + dialog.setMessage(R.string.restart_vpn_after_change); + + + dialog.setPositiveButton(R.string.restart, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(getActivity(), LaunchVPN.class); + intent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUIDString()); + intent.setAction(Intent.ACTION_MAIN); + startActivity(intent); + } + + + }); + dialog.setNegativeButton(R.string.ignore, null); + dialog.create().show(); + } + super.onActivityResult(requestCode, resultCode, data); + } + + + @Override + public void onStop() { + super.onStop(); + VpnStatus.removeStateListener(this); + VpnStatus.removeByteCountListener(this); + + getActivity().getPreferences(0).edit().putInt(LOGTIMEFORMAT, ladapter.mTimeFormat) + .putInt(VERBOSITYLEVEL, ladapter.mLogLevel).apply(); + + } + + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + ListView lv = getListView(); + + lv.setOnItemLongClickListener(new OnItemLongClickListener() { + + @Override + public boolean onItemLongClick(AdapterView parent, View view, + int position, long id) { + ClipboardManager clipboard = (ClipboardManager) + getActivity().getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("Log Entry", ((TextView) view).getText()); + clipboard.setPrimaryClip(clip); + Toast.makeText(getActivity(), R.string.copied_entry, Toast.LENGTH_SHORT).show(); + return true; + } + }); + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View v = inflater.inflate(R.layout.f_log, container, false); + + setHasOptionsMenu(true); + + ladapter = new LogWindowListAdapter(); + ladapter.mTimeFormat = getActivity().getPreferences(0).getInt(LOGTIMEFORMAT, 1); + int logLevel = getActivity().getPreferences(0).getInt(VERBOSITYLEVEL, 1); + ladapter.setLogLevel(logLevel); + + setListAdapter(ladapter); + + mTimeRadioGroup = (RadioGroup) v.findViewById(R.id.timeFormatRadioGroup); + mTimeRadioGroup.setOnCheckedChangeListener(this); + + if (ladapter.mTimeFormat == LogWindowListAdapter.TIME_FORMAT_ISO) { + mTimeRadioGroup.check(R.id.radioISO); + } else if (ladapter.mTimeFormat == LogWindowListAdapter.TIME_FORMAT_NONE) { + mTimeRadioGroup.check(R.id.radioNone); + } else if (ladapter.mTimeFormat == LogWindowListAdapter.TIME_FORMAT_SHORT) { + mTimeRadioGroup.check(R.id.radioShort); + } + + mClearLogCheckBox = (CheckBox) v.findViewById(R.id.clearlogconnect); + mClearLogCheckBox.setChecked(PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean(LaunchVPN.CLEARLOG, true)); + mClearLogCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + Preferences.getDefaultSharedPreferences(getActivity()).edit().putBoolean(LaunchVPN.CLEARLOG, isChecked).apply(); + } + }); + + mSpeedView = (TextView) v.findViewById(R.id.speed); + + mOptionsLayout = (LinearLayout) v.findViewById(R.id.logOptionsLayout); + mLogLevelSlider = (SeekBar) v.findViewById(R.id.LogLevelSlider); + mLogLevelSlider.setMax(VpnProfile.MAXLOGLEVEL - 1); + mLogLevelSlider.setProgress(logLevel - 1); + + mLogLevelSlider.setOnSeekBarChangeListener(this); + + if (getResources().getBoolean(R.bool.logSildersAlwaysVisible)) + mOptionsLayout.setVisibility(View.VISIBLE); + + mUpStatus = (TextView) v.findViewById(R.id.speedUp); + mDownStatus = (TextView) v.findViewById(R.id.speedDown); + mConnectStatus = (TextView) v.findViewById(R.id.speedStatus); + if (mShowOptionsLayout) + mOptionsLayout.setVisibility(View.VISIBLE); + return v; + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + // Scroll to the end of the list end + //getListView().setSelection(getListView().getAdapter().getCount()-1); + } + + @Override + public void onAttach(Context activity) { + super.onAttach(activity); + if (getResources().getBoolean(R.bool.logSildersAlwaysVisible)) { + mShowOptionsLayout = true; + if (mOptionsLayout != null) + mOptionsLayout.setVisibility(View.VISIBLE); + } + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + + @Override + public void updateState(final String status, final String logMessage, final int resId, final ConnectionStatus level) { + if (isAdded()) { + final String cleanLogMessage = VpnStatus.getLastCleanLogMessage(getActivity()); + + getActivity().runOnUiThread(new Runnable() { + + @Override + public void run() { + if (isAdded()) { + if (mSpeedView != null) { + mSpeedView.setText(cleanLogMessage); + } + if (mConnectStatus != null) + mConnectStatus.setText(cleanLogMessage); + } + } + }); + } + } + + @Override + public void setConnectedVPN(String uuid) { + } + + + @Override + public void onDestroy() { + VpnStatus.removeLogListener(ladapter); + super.onDestroy(); + } + +} diff --git a/app/src/main/res/layout-sw600dp-port/f_log.xml b/app/src/main/res/layout-sw600dp-port/f_log.xml new file mode 100644 index 00000000..7a4b60fe --- /dev/null +++ b/app/src/main/res/layout-sw600dp-port/f_log.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-sw600dp/f_log.xml b/app/src/main/res/layout-sw600dp/f_log.xml new file mode 100644 index 00000000..26f63df4 --- /dev/null +++ b/app/src/main/res/layout-sw600dp/f_log.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-v21/f_log.xml b/app/src/main/res/layout-v21/f_log.xml new file mode 100644 index 00000000..41c72d99 --- /dev/null +++ b/app/src/main/res/layout-v21/f_log.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/drawer_main.xml b/app/src/main/res/layout/drawer_main.xml index e1f7b15c..a2bda8b6 100644 --- a/app/src/main/res/layout/drawer_main.xml +++ b/app/src/main/res/layout/drawer_main.xml @@ -17,7 +17,7 @@ android:layout_height="match_parent" android:adjustViewBounds="false" android:cropToPadding="false" - android:scaleType="fitStart" + android:scaleType="fitXY" app:srcCompat="@drawable/ic_colorsquare" /> - + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/f_log_sliders.xml b/app/src/main/res/layout/f_log_sliders.xml new file mode 100644 index 00000000..4196e243 --- /dev/null +++ b/app/src/main/res/layout/f_log_sliders.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/f_log.xml b/app/src/main/res/menu/f_log.xml new file mode 100644 index 00000000..5e0af56c --- /dev/null +++ b/app/src/main/res/menu/f_log.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 762655b2..6d63c619 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,9 +77,9 @@ Turn on Turn off Bitmask Log - MainActivity + Bitmask - Section 1 + Log Section 2 Section 3 -- cgit v1.2.3 From f10380f7d8bc85d8127328a9d9c092bc109bb340 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Thu, 14 Dec 2017 21:41:46 +0100 Subject: add missing files --- app/src/main/java/se/leap/bitmaskclient/MainActivity.java | 2 +- app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java | 2 +- app/src/main/res/values/themes.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java index ceff8b20..8cd6357c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java @@ -75,7 +75,7 @@ public class MainActivity extends AppCompatActivity mTitle = getString(R.string.title_section3); break; default: - mTitle = getString(R.string.title_log_fragment); + mTitle = getString(R.string.log_fragment_title); break; } restoreActionBar(); diff --git a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java index a417b51a..bb0d8f46 100644 --- a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java @@ -123,7 +123,7 @@ public class NavigationDrawerFragment extends Fragment { android.R.layout.simple_list_item_activated_1, android.R.id.text1, new String[]{ - getString(R.string.title_log_fragment), + getString(R.string.log_fragment_title), getString(R.string.title_section2), getString(R.string.title_section3), })); diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 80607409..a64779e5 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,6 +1,6 @@ - -- cgit v1.2.3 From 7cd685e486e735c3994d59c01df98ac2f82dc0b2 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 19 Dec 2017 15:09:40 +0100 Subject: refactor dashboard --- .../de/blinkt/openvpn/fragments/LogFragment.java | 20 +-- .../bitmaskclient/BaseConfigurationWizard.java | 2 +- .../main/java/se/leap/bitmaskclient/Constants.java | 18 ++- .../main/java/se/leap/bitmaskclient/Dashboard.java | 140 ++++++++++--------- .../java/se/leap/bitmaskclient/OnBootReceiver.java | 2 +- .../java/se/leap/bitmaskclient/VpnFragment.java | 155 +++++++++++---------- .../main/java/se/leap/bitmaskclient/eip/EIP.java | 18 ++- .../bitmaskclient/eip/VpnCertificateValidator.java | 9 +- .../leap/bitmaskclient/eip/VpnConfigGenerator.java | 9 +- .../userstatus/UserStatusFragment.java | 17 +-- .../java/se/leap/bitmaskclient/ProviderAPI.java | 4 +- 11 files changed, 212 insertions(+), 182 deletions(-) diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java index a1fc7cdc..d75d6d53 100644 --- a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -23,7 +23,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Handler.Callback; import android.os.Message; -import android.preference.Preference; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.text.SpannableString; @@ -54,30 +53,27 @@ import java.util.Locale; import java.util.Vector; import de.blinkt.openvpn.LaunchVPN; -import se.leap.bitmaskclient.R; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.activities.DisconnectVPN; import de.blinkt.openvpn.core.ConnectionStatus; +import de.blinkt.openvpn.core.LogItem; import de.blinkt.openvpn.core.OpenVPNManagement; import de.blinkt.openvpn.core.OpenVPNService; import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; -import de.blinkt.openvpn.core.LogItem; import de.blinkt.openvpn.core.VpnStatus.LogListener; import de.blinkt.openvpn.core.VpnStatus.StateListener; +import se.leap.bitmaskclient.Dashboard; +import se.leap.bitmaskclient.R; import static de.blinkt.openvpn.core.OpenVPNService.humanReadableByteCount; -import se.leap.bitmaskclient.Dashboard; - public class LogFragment extends ListFragment implements StateListener, SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener, VpnStatus.ByteCountListener { private static final String LOGTIMEFORMAT = "logtimeformat"; private static final int START_VPN_CONFIG = 0; private static final String VERBOSITYLEVEL = "verbositylevel"; - - private SeekBar mLogLevelSlider; private LinearLayout mOptionsLayout; private RadioGroup mTimeRadioGroup; @@ -434,16 +430,6 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. return true; } else if (item.getItemId() == R.id.send) { ladapter.shareLog(); - } else if (item.getItemId() == R.id.edit_vpn) { - VpnProfile lastConnectedprofile = ProfileManager.get(getActivity(), VpnStatus.getLastConnectedVPNProfile()); - - if (lastConnectedprofile != null) { - Intent vprefintent = new Intent(getActivity(), Dashboard.class) - .putExtra(VpnProfile.EXTRA_PROFILEUUID, lastConnectedprofile.getUUIDString()); - startActivityForResult(vprefintent, START_VPN_CONFIG); - } else { - Toast.makeText(getActivity(), R.string.log_no_last_vpn, Toast.LENGTH_LONG).show(); - } } else if (item.getItemId() == R.id.toggle_time) { showHideOptionsPanel(); } else if (item.getItemId() == android.R.id.home) { diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 21520dc4..52c8f8e5 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -301,7 +301,7 @@ public abstract class BaseConfigurationWizard extends Activity private void askDashboardToQuitApp() { Intent ask_quit = new Intent(); - ask_quit.putExtra(Dashboard.ACTION_QUIT, Dashboard.ACTION_QUIT); + ask_quit.putExtra(Constants.APP_ACTION_QUIT, Constants.APP_ACTION_QUIT); setResult(RESULT_CANCELED, ask_quit); } diff --git a/app/src/main/java/se/leap/bitmaskclient/Constants.java b/app/src/main/java/se/leap/bitmaskclient/Constants.java index a7ab56fd..7ee3adab 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/Constants.java @@ -10,6 +10,23 @@ public interface Constants { String PREFERENCES_APP_VERSION = "bitmask version"; + ////////////////////////////////////////////// + // REQUEST CODE CONSTANTS + ///////////////////////////////////////////// + + String REQUEST_CODE_KEY = "request_code"; + int REQUEST_CODE_CONFIGURE_LEAP = 0; + int REQUEST_CODE_SWITCH_PROVIDER = 1; + + + ////////////////////////////////////////////// + // APP CONSTANTS + ///////////////////////////////////////////// + + String APP_ACTION_QUIT = "quit"; + String APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE = "configure always-on profile"; + + ////////////////////////////////////////////// // EIP CONSTANTS ///////////////////////////////////////////// @@ -30,7 +47,6 @@ public interface Constants { String EIP_IS_ALWAYS_ON = "EIP.EIP_IS_ALWAYS_ON"; - ////////////////////////////////////////////// // PROVIDER CONSTANTS ///////////////////////////////////////////// diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index f1e7b3bd..1eed484c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -20,7 +20,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.app.FragmentTransaction; -import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; @@ -47,6 +46,8 @@ import se.leap.bitmaskclient.userstatus.UserStatusFragment; import static se.leap.bitmaskclient.Constants.EIP_IS_ALWAYS_ON; import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT; +import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP; +import static se.leap.bitmaskclient.Constants.REQUEST_CODE_SWITCH_PROVIDER; /** * The main user facing Activity of Bitmask Android, consisting of status, controls, @@ -55,13 +56,9 @@ import static se.leap.bitmaskclient.Constants.EIP_RESTART_ON_BOOT; * @author Sean Leonard * @author parmegv */ -public class Dashboard extends Activity implements ProviderAPIResultReceiver.Receiver { - - protected static final int CONFIGURE_LEAP = 0; - protected static final int SWITCH_PROVIDER = 1; +public class Dashboard extends Activity { public static final String TAG = Dashboard.class.getSimpleName(); - public static final String ACTION_QUIT = "quit"; /** * When "Disconnect" is clicked from the notification this extra gets added to the calling intent. @@ -69,39 +66,38 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec public static final String ACTION_ASK_TO_CANCEL_VPN = "ask to cancel vpn"; /** * if always-on feature is enabled, but there's no provider configured the EIP Service - * adds this intent extra. ACTION_CONFIGURE_ALWAYS_ON_PROFILE + * adds this intent extra. Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE * serves to start the Configuration Wizard on top of the Dashboard Activity. */ - public static final String ACTION_CONFIGURE_ALWAYS_ON_PROFILE = "configure always-on profile"; - public static final String REQUEST_CODE = "request_code"; - public static final String PARAMETERS = "dashboard parameters"; - public static final String APP_VERSION = "bitmask version"; - //FIXME: context classes in static fields lead to memory leaks! - private static Context dashboardContext; protected static SharedPreferences preferences; - private FragmentManagerEnhanced fragment_manager; + private static FragmentManagerEnhanced fragment_manager; @InjectView(R.id.providerName) TextView provider_name; - VpnFragment eip_fragment; - UserStatusFragment user_status_fragment; + private VpnFragment eip_fragment; + private UserStatusFragment user_status_fragment; + private static Provider provider = new Provider(); - public ProviderAPIResultReceiver providerAPI_result_receiver; - private boolean switching_provider; + public static ProviderAPIResultReceiver providerAPI_result_receiver; + private static boolean switching_provider; + private boolean handledVersion; + + public static DashboardReceiver dashboardReceiver; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + dashboardReceiver = new DashboardReceiver(this); preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), this); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), dashboardReceiver); - if (dashboardContext == null) { - dashboardContext = this; + if (handledVersion) { handleVersion(); + handledVersion = true; } prepareEIP(savedInstanceState); @@ -183,15 +179,15 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec } else if (intent.hasExtra(EIP_RESTART_ON_BOOT)) { Log.d(TAG, "Dashboard: EIP_RESTART_ON_BOOT"); prepareEIP(null); - } else if (intent.hasExtra(ACTION_CONFIGURE_ALWAYS_ON_PROFILE)) { - Log.d(TAG, "Dashboard: ACTION_CONFIGURE_ALWAYS_ON_PROFILE"); + } else if (intent.hasExtra(Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE)) { + Log.d(TAG, "Dashboard: Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE"); handleConfigureAlwaysOn(getIntent()); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) { + if (requestCode == REQUEST_CODE_CONFIGURE_LEAP || requestCode == REQUEST_CODE_SWITCH_PROVIDER) { if (resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) { provider = data.getParcelableExtra(Provider.KEY); providerToPreferences(provider); @@ -202,7 +198,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec sessionDialog(Bundle.EMPTY); } - } else if (resultCode == RESULT_CANCELED && data != null && data.hasExtra(ACTION_QUIT)) { + } else if (resultCode == RESULT_CANCELED && data != null && data.hasExtra(Constants.APP_ACTION_QUIT)) { finish(); } else configErrorDialog(); @@ -217,9 +213,9 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec } private void handleConfigureAlwaysOn(Intent intent) { - intent.removeExtra(ACTION_CONFIGURE_ALWAYS_ON_PROFILE); + intent.removeExtra(Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE); Log.d(TAG, "start Configuration wizard!"); - startActivityForResult(new Intent(this, ConfigurationWizard.class), CONFIGURE_LEAP); + startActivityForResult(new Intent(this, ConfigurationWizard.class), Constants.REQUEST_CODE_CONFIGURE_LEAP); } private void prepareEIP(Bundle savedInstanceState) { @@ -239,10 +235,10 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec } private void configureLeapProvider() { - if (getIntent().hasExtra(ACTION_CONFIGURE_ALWAYS_ON_PROFILE)) { - getIntent().removeExtra(ACTION_CONFIGURE_ALWAYS_ON_PROFILE); + if (getIntent().hasExtra(Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE)) { + getIntent().removeExtra(Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE); } - startActivityForResult(new Intent(this, ConfigurationWizard.class), CONFIGURE_LEAP); + startActivityForResult(new Intent(this, ConfigurationWizard.class), Constants.REQUEST_CODE_CONFIGURE_LEAP); } @SuppressLint("CommitPrefEdits") private void providerToPreferences(Provider provider) { @@ -253,7 +249,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec } private void configErrorDialog() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext()); + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); alertBuilder.setTitle(getResources().getString(R.string.setup_error_title)); alertBuilder .setMessage(getResources().getString(R.string.setup_error_text)) @@ -261,7 +257,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec .setPositiveButton(getResources().getString(R.string.setup_error_configure_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - startActivityForResult(new Intent(getContext(), ConfigurationWizard.class), CONFIGURE_LEAP); + startActivityForResult(new Intent(getApplicationContext(), ConfigurationWizard.class), Constants.REQUEST_CODE_CONFIGURE_LEAP); } }) .setNegativeButton(getResources().getString(R.string.setup_error_close_button), new DialogInterface.OnClickListener() { @@ -307,7 +303,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec * * @param hideAndTurnOnEipOnBoot Flag that indicates if system intent android.intent.action.BOOT_COMPLETED * has caused to start Dashboard - * @return + * @return the created VPNFragment */ private VpnFragment prepareEipFragment(boolean hideAndTurnOnEipOnBoot) { VpnFragment eip_fragment = new VpnFragment(); @@ -325,7 +321,7 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec /** * checks if Android's VPN feature 'always-on' is enabled for Bitmask - * @return + * @return true if 'always-on' is enabled false if not */ private boolean isAlwaysOn() { return preferences.getBoolean(EIP_IS_ALWAYS_ON, false); @@ -374,11 +370,13 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec } public void showLog() { - LogWindowWrapper log_window_wrapper = LogWindowWrapper.getInstance(getContext()); + LogWindowWrapper log_window_wrapper = LogWindowWrapper.getInstance(this); log_window_wrapper.showLog(); } - public void downloadVpnCertificate() { + + // TODO MOVE TO VPNManager(?) + public static void downloadVpnCertificate() { boolean is_authenticated = User.loggedIn(); boolean allowed_anon = preferences.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS, false); if (allowed_anon || is_authenticated) @@ -387,7 +385,8 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec sessionDialog(Bundle.EMPTY); } - public void sessionDialog(Bundle resultData) { + // TODO how can we replace this + public static void sessionDialog(Bundle resultData) { try { FragmentTransaction transaction = fragment_manager.removePreviousFragment(SessionDialog.TAG); SessionDialog.getInstance(provider, resultData).show(transaction, SessionDialog.TAG); @@ -401,47 +400,52 @@ public class Dashboard extends Activity implements ProviderAPIResultReceiver.Rec preferences.edit().clear().apply(); switching_provider = false; - startActivityForResult(new Intent(this, ConfigurationWizard.class), SWITCH_PROVIDER); + startActivityForResult(new Intent(this, ConfigurationWizard.class), Constants.REQUEST_CODE_SWITCH_PROVIDER); } - @Override - public void onReceiveResult(int resultCode, Bundle resultData) { - if (resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) { - String username = resultData.getString(SessionDialog.USERNAME); - String password = resultData.getString(SessionDialog.PASSWORD); - user_status_fragment.logIn(username, password); - } else if (resultCode == ProviderAPI.FAILED_SIGNUP) { - sessionDialog(resultData); - } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { - downloadVpnCertificate(); - } else if (resultCode == ProviderAPI.FAILED_LOGIN) { - sessionDialog(resultData); - } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { - if (switching_provider) switchProvider(); - } else if (resultCode == ProviderAPI.LOGOUT_FAILED) { - setResult(RESULT_CANCELED); - } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { - eip_fragment.updateEipService(); - setResult(RESULT_OK); - } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { - setResult(RESULT_CANCELED); - } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) { - eip_fragment.updateEipService(); - setResult(RESULT_OK); - } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE) { - setResult(RESULT_CANCELED); + public static class DashboardReceiver implements ProviderAPIResultReceiver.Receiver{ + + private Dashboard dashboard; + + DashboardReceiver(Dashboard dashboard) { + this.dashboard = dashboard; } - } - public static Context getContext() { - return dashboardContext; + @Override + public void onReceiveResult(int resultCode, Bundle resultData) { + if (resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) { + String username = resultData.getString(SessionDialog.USERNAME); + String password = resultData.getString(SessionDialog.PASSWORD); + dashboard.user_status_fragment.logIn(username, password); + } else if (resultCode == ProviderAPI.FAILED_SIGNUP) { + Dashboard.sessionDialog(resultData); + } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { + Dashboard.downloadVpnCertificate(); + } else if (resultCode == ProviderAPI.FAILED_LOGIN) { + Dashboard.sessionDialog(resultData); + } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { + if (switching_provider) dashboard.switchProvider(); + } else if (resultCode == ProviderAPI.LOGOUT_FAILED) { + dashboard.setResult(RESULT_CANCELED); + } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { + dashboard.eip_fragment.updateEipService(); + dashboard.setResult(RESULT_OK); + } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { + dashboard.setResult(RESULT_CANCELED); + } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) { + dashboard.eip_fragment.updateEipService(); + dashboard.setResult(RESULT_OK); + } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE) { + dashboard.setResult(RESULT_CANCELED); + } + } } public static Provider getProvider() { return provider; } @Override public void startActivityForResult(Intent intent, int requestCode) { - intent.putExtra(Dashboard.REQUEST_CODE, requestCode); + intent.putExtra(Constants.REQUEST_CODE_KEY, requestCode); super.startActivityForResult(intent, requestCode); } diff --git a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java index f9aa2660..a87e0460 100644 --- a/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/OnBootReceiver.java @@ -41,7 +41,7 @@ public class OnBootReceiver extends BroadcastReceiver { } else { if (isAlwaysOnConfigured) { Intent dashboard_intent = new Intent(context, Dashboard.class); - dashboard_intent.putExtra(Dashboard.ACTION_CONFIGURE_ALWAYS_ON_PROFILE, true); + dashboard_intent.putExtra(Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE, true); dashboard_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(dashboard_intent); } diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java index f1a15efd..2b968769 100644 --- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java @@ -24,6 +24,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; @@ -72,12 +73,13 @@ public class VpnFragment extends Fragment implements Observer { protected static final String IS_CONNECTED = TAG + ".is_connected"; public static final String START_EIP_ON_BOOT = "start on boot"; + private SharedPreferences preferences; + @InjectView(R.id.vpn_status_image) FabButton vpn_status_image; @InjectView(R.id.vpn_main_button) Button main_button; - private Dashboard dashboard; private static EIPReceiver eip_receiver; private static EipStatus eip_status; private boolean wants_to_connect; @@ -104,8 +106,6 @@ public class VpnFragment extends Fragment implements Observer { //FIXME: replace with onAttach(Context context) public void onAttach(Activity activity) { super.onAttach(activity); - - dashboard = (Dashboard) activity; downloadEIPServiceConfig(); } @@ -115,6 +115,7 @@ public class VpnFragment extends Fragment implements Observer { eip_status = EipStatus.getInstance(); eip_status.addObserver(this); eip_receiver = new EIPReceiver(new Handler()); + preferences = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE); } @Override @@ -142,7 +143,7 @@ public class VpnFragment extends Fragment implements Observer { @Override public void onPause() { super.onPause(); - dashboard.unbindService(openVpnConnection); + getActivity().unbindService(openVpnConnection); } @Override @@ -152,7 +153,7 @@ public class VpnFragment extends Fragment implements Observer { } private void saveStatus(boolean restartOnBoot) { - Dashboard.preferences.edit().putBoolean(EIP_RESTART_ON_BOOT, restartOnBoot).apply(); + preferences.edit().putBoolean(EIP_RESTART_ON_BOOT, restartOnBoot).apply(); } @OnClick(R.id.vpn_main_button) @@ -169,7 +170,7 @@ public class VpnFragment extends Fragment implements Observer { else if (canLogInToStartEIP()) { wants_to_connect = true; Bundle bundle = new Bundle(); - dashboard.sessionDialog(bundle); + Dashboard.sessionDialog(bundle); } else { Log.d(TAG, "WHAT IS GOING ON HERE?!"); // TODO: implement a fallback: check if vpncertificate was not downloaded properly or give @@ -178,13 +179,13 @@ public class VpnFragment extends Fragment implements Observer { } private boolean canStartEIP() { - boolean certificateExists = !Dashboard.preferences.getString(PROVIDER_VPN_CERTIFICATE, "").isEmpty(); - boolean isAllowedAnon = Dashboard.preferences.getBoolean(PROVIDER_ALLOW_ANONYMOUS, false); + boolean certificateExists = !preferences.getString(PROVIDER_VPN_CERTIFICATE, "").isEmpty(); + boolean isAllowedAnon = preferences.getBoolean(PROVIDER_ALLOW_ANONYMOUS, false); return (isAllowedAnon || certificateExists) && !eip_status.isConnected() && !eip_status.isConnecting(); } private boolean canLogInToStartEIP() { - boolean isAllowedRegistered = Dashboard.preferences.getBoolean(PROVIDER_ALLOWED_REGISTERED, false); + boolean isAllowedRegistered = preferences.getBoolean(PROVIDER_ALLOWED_REGISTERED, false); boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty(); return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); } @@ -200,16 +201,17 @@ public class VpnFragment extends Fragment implements Observer { } private void askPendingStartCancellation() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); - alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) - .setMessage(dashboard.getString(R.string.eip_cancel_connect_text)) + Activity activity = getActivity(); + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getActivity()); + alertBuilder.setTitle(activity.getString(R.string.eip_cancel_connect_title)) + .setMessage(activity.getString(R.string.eip_cancel_connect_text)) .setPositiveButton((android.R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { askToStopEIP(); } }) - .setNegativeButton(dashboard.getString(android.R.string.no), new DialogInterface.OnClickListener() { + .setNegativeButton(activity.getString(android.R.string.no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } @@ -233,13 +235,14 @@ public class VpnFragment extends Fragment implements Observer { private void stopBlockingVpn() { Log.d(TAG, "stop VoidVpn!"); - Intent stopVoidVpnIntent = new Intent(dashboard, VoidVpnService.class); + Activity activity = getActivity(); + Intent stopVoidVpnIntent = new Intent(activity, VoidVpnService.class); stopVoidVpnIntent.setAction(EIP_ACTION_STOP_BLOCKING_VPN); - dashboard.startService(stopVoidVpnIntent); + activity.startService(stopVoidVpnIntent); } private void disconnect() { - ProfileManager.setConntectedVpnProfileDisconnected(dashboard); + ProfileManager.setConntectedVpnProfileDisconnected(getActivity()); if (mService != null) { try { mService.stopVPN(false); @@ -255,22 +258,23 @@ public class VpnFragment extends Fragment implements Observer { } private void downloadEIPServiceConfig() { - ProviderAPIResultReceiver provider_api_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); + ProviderAPIResultReceiver provider_api_receiver = new ProviderAPIResultReceiver(new Handler(), Dashboard.dashboardReceiver); if(eip_receiver != null) ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_EIP_SERVICE, provider_api_receiver); } protected void askToStopEIP() { - AlertDialog.Builder alertBuilder = new AlertDialog.Builder(dashboard); - alertBuilder.setTitle(dashboard.getString(R.string.eip_cancel_connect_title)) - .setMessage(dashboard.getString(R.string.eip_warning_browser_inconsistency)) + Activity activity = getActivity(); + AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity); + alertBuilder.setTitle(activity.getString(R.string.eip_cancel_connect_title)) + .setMessage(activity.getString(R.string.eip_warning_browser_inconsistency)) .setPositiveButton((android.R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { stopEipIfPossible(); } }) - .setNegativeButton(dashboard.getString(android.R.string.no), new DialogInterface.OnClickListener() { + .setNegativeButton(activity.getString(android.R.string.no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } @@ -289,18 +293,19 @@ public class VpnFragment extends Fragment implements Observer { * filter for the EIP class */ private void eipCommand(String action) { + Activity activity = getActivity(); // TODO validate "action"...how do we get the list of intent-filters for a class via Android API? - Intent vpn_intent = new Intent(dashboard.getApplicationContext(), EIP.class); + Intent vpn_intent = new Intent(activity.getApplicationContext(), EIP.class); vpn_intent.setAction(action); vpn_intent.putExtra(EIP_RECEIVER, eip_receiver); - dashboard.startService(vpn_intent); + activity.startService(vpn_intent); } @Override public void update(Observable observable, Object data) { if (observable instanceof EipStatus) { eip_status = (EipStatus) observable; - dashboard.runOnUiThread(new Runnable() { + getActivity().runOnUiThread(new Runnable() { @Override public void run() { handleNewState(); @@ -335,12 +340,13 @@ public class VpnFragment extends Fragment implements Observer { } private void updateButton() { + Activity activity = getActivity(); if (eip_status.isConnecting()) { - main_button.setText(dashboard.getString(android.R.string.cancel)); + main_button.setText(activity.getString(android.R.string.cancel)); } else if (eip_status.isConnected() || isOpenVpnRunningWithoutNetwork()) { - main_button.setText(dashboard.getString(R.string.vpn_button_turn_off)); + main_button.setText(activity.getString(R.string.vpn_button_turn_off)); } else { - main_button.setText(dashboard.getString(R.string.vpn_button_turn_on)); + main_button.setText(activity.getString(R.string.vpn_button_turn_on)); } } @@ -358,14 +364,15 @@ public class VpnFragment extends Fragment implements Observer { } private void bindOpenVpnService() { - Intent intent = new Intent(dashboard, OpenVPNService.class); + Activity activity = getActivity(); + Intent intent = new Intent(activity, OpenVPNService.class); intent.setAction(OpenVPNService.START_SERVICE); - dashboard.bindService(intent, openVpnConnection, Context.BIND_AUTO_CREATE); + activity.bindService(intent, openVpnConnection, Context.BIND_AUTO_CREATE); } protected class EIPReceiver extends ResultReceiver { - protected EIPReceiver(Handler handler) { + EIPReceiver(Handler handler) { super(handler); } @@ -375,47 +382,55 @@ public class VpnFragment extends Fragment implements Observer { String request = resultData.getString(EIP_REQUEST); - if (request.equals(EIP_ACTION_START)) { - switch (resultCode) { - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: + if (request == null) { + return; + } - break; - } - } else if (request.equals(EIP_ACTION_STOP)) { - switch (resultCode) { - case Activity.RESULT_OK: - stop(); - break; - case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(EIP_NOTIFICATION)) { - switch (resultCode) { - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - break; - } - } else if (request.equals(EIP_ACTION_CHECK_CERT_VALIDITY)) { - switch (resultCode) { - case Activity.RESULT_OK: - break; - case Activity.RESULT_CANCELED: - dashboard.downloadVpnCertificate(); - break; - } - } else if (request.equals(EIP_ACTION_UPDATE)) { - switch (resultCode) { - case Activity.RESULT_OK: - if (wants_to_connect) - startEipFromScratch(); - break; - case Activity.RESULT_CANCELED: - handleNewState(); - break; - } + switch (request) { + case EIP_ACTION_START: + switch (resultCode) { + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + break; + } + break; + case EIP_ACTION_STOP: + switch (resultCode) { + case Activity.RESULT_OK: + stop(); + break; + case Activity.RESULT_CANCELED: + break; + } + break; + case EIP_NOTIFICATION: + switch (resultCode) { + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + break; + } + break; + case EIP_ACTION_CHECK_CERT_VALIDITY: + switch (resultCode) { + case Activity.RESULT_OK: + break; + case Activity.RESULT_CANCELED: + Dashboard.downloadVpnCertificate(); + break; + } + break; + case EIP_ACTION_UPDATE: + switch (resultCode) { + case Activity.RESULT_OK: + if (wants_to_connect) + startEipFromScratch(); + break; + case Activity.RESULT_CANCELED: + handleNewState(); + break; + } } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index a84ab941..998d2c87 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -16,15 +16,21 @@ */ package se.leap.bitmaskclient.eip; -import android.app.*; -import android.content.*; -import android.os.*; +import android.app.Activity; +import android.app.IntentService; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.os.ResultReceiver; import android.util.Log; -import org.json.*; +import org.json.JSONException; +import org.json.JSONObject; -import de.blinkt.openvpn.*; -import se.leap.bitmaskclient.*; +import de.blinkt.openvpn.LaunchVPN; +import se.leap.bitmaskclient.OnBootReceiver; +import se.leap.bitmaskclient.VpnFragment; import static se.leap.bitmaskclient.Constants.EIP_ACTION_CHECK_CERT_VALIDITY; import static se.leap.bitmaskclient.Constants.EIP_ACTION_IS_RUNNING; diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java index 28099f06..197a080b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnCertificateValidator.java @@ -16,10 +16,13 @@ */ package se.leap.bitmaskclient.eip; -import java.security.cert.*; -import java.util.*; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.X509Certificate; +import java.util.Calendar; +import java.util.Date; -import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.ConfigHelper; public class VpnCertificateValidator { public final static String TAG = VpnCertificateValidator.class.getSimpleName(); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java index 54563ec4..b1318def 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/VpnConfigGenerator.java @@ -16,11 +16,14 @@ */ package se.leap.bitmaskclient.eip; -import org.json.*; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; -import java.util.*; +import java.util.Iterator; -import se.leap.bitmaskclient.*; +import se.leap.bitmaskclient.Constants; +import se.leap.bitmaskclient.Provider; public class VpnConfigGenerator { diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java index 14323f8e..f4be3ea1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -28,7 +28,6 @@ import se.leap.bitmaskclient.R; public class UserStatusFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface { public static String TAG = UserStatusFragment.class.getSimpleName(); - private static Dashboard dashboard; private ProviderAPIResultReceiver providerAPI_result_receiver; @InjectView(R.id.user_status_username) @@ -74,16 +73,14 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia @Override public void onAttach(Activity activity) { super.onAttach(activity); - dashboard = (Dashboard) activity; - - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), dashboard); + providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), Dashboard.dashboardReceiver); } public void restoreSessionStatus(Bundle savedInstanceState) { if (savedInstanceState != null) if (savedInstanceState.containsKey(UserStatus.TAG)) { UserStatus.SessionStatus status = (UserStatus.SessionStatus) savedInstanceState.getSerializable(UserStatus.TAG); - this.status.updateStatus(status, getResources()); + UserStatus.updateStatus(status, getResources()); } } @@ -93,7 +90,7 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia if(status.isLoggedIn()) logOut(); else if(status.isLoggedOut()) - dashboard.sessionDialog(Bundle.EMPTY); + Dashboard.sessionDialog(Bundle.EMPTY); else if(status.inProgress()) cancelLoginOrSignup(); } @@ -102,7 +99,7 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia public void update(Observable observable, Object data) { if (observable instanceof UserStatus) { final UserStatus status = (UserStatus) observable; - dashboard.runOnUiThread(new Runnable() { + getActivity().runOnUiThread(new Runnable() { @Override public void run() { handleNewStatus(status); @@ -138,12 +135,12 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia private void updateButton() { if(status.isLoggedIn() || status.didntLogOut()) - button.setText(dashboard.getString(R.string.logout_button)); + button.setText(getActivity().getString(R.string.logout_button)); else if(allows_registration) { if (status.isLoggedOut() || status.notLoggedIn()) - button.setText(dashboard.getString(R.string.login_button)); + button.setText(getActivity().getString(R.string.login_button)); else if (status.inProgress()) - button.setText(dashboard.getString(android.R.string.cancel)); + button.setText(getActivity().getString(android.R.string.cancel)); } } diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java index fadb03c3..a818e508 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java @@ -53,7 +53,7 @@ public class ProviderAPI extends ProviderApiBase { /** * Downloads a provider.json from a given URL, adding a new provider using the given name. - * + */ * @param task containing a boolean meaning if the provider is custom or not, another boolean meaning if the user completely trusts this provider, the provider name and its provider.json url. * @return a bundle with a boolean value mapped to a key named RESULT_KEY, and which is true if the update was successful. */ @@ -224,7 +224,7 @@ public class ProviderAPI extends ProviderApiBase { String[] pins = new String[] {ca_cert_fingerprint}; try { URL url = new URL(url_string); - HttpsURLConnection connection = PinningHelper.getPinnedHttpsURLConnection(Dashboard.getContext(), pins, url); + HttpsURLConnection connection = PinningHelper.getPinnedHttpsURLConnection(getApplicationContext(), pins, url); connection.setConnectTimeout(seconds_of_timeout * 1000); if (!LeapSRPSession.getToken().isEmpty()) connection.addRequestProperty(LeapSRPSession.AUTHORIZATION_HEADER, "Token token=" + LeapSRPSession.getToken()); -- cgit v1.2.3 From d1d34f0bf995f48dac7781711656b8cb8e387707 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 19 Dec 2017 16:08:49 +0100 Subject: move log fragment layout --- app/src/main/res/layout-sw600dp-port/f_log.xml | 34 +---------------------- app/src/main/res/layout-sw600dp/f_log.xml | 3 +-- app/src/main/res/layout-v21/f_log.xml | 37 -------------------------- app/src/main/res/menu/f_log.xml | 8 ------ 4 files changed, 2 insertions(+), 80 deletions(-) delete mode 100644 app/src/main/res/layout-v21/f_log.xml diff --git a/app/src/main/res/layout-sw600dp-port/f_log.xml b/app/src/main/res/layout-sw600dp-port/f_log.xml index 7a4b60fe..500461b7 100644 --- a/app/src/main/res/layout-sw600dp-port/f_log.xml +++ b/app/src/main/res/layout-sw600dp-port/f_log.xml @@ -8,38 +8,6 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical" - tools:context=".LogWindow"> - - - - - - - - - - - - - - + android:orientation="vertical" > \ No newline at end of file diff --git a/app/src/main/res/layout-sw600dp/f_log.xml b/app/src/main/res/layout-sw600dp/f_log.xml index 26f63df4..9ad30208 100644 --- a/app/src/main/res/layout-sw600dp/f_log.xml +++ b/app/src/main/res/layout-sw600dp/f_log.xml @@ -9,8 +9,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" - android:padding="20dp" - tools:context=".LogWindow"> + android:padding="20dp" > - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/f_log.xml b/app/src/main/res/menu/f_log.xml index 5e0af56c..d30b13cb 100644 --- a/app/src/main/res/menu/f_log.xml +++ b/app/src/main/res/menu/f_log.xml @@ -28,12 +28,4 @@ android:title="@string/send_logfile" android:titleCondensed="@string/send"/> - - -- cgit v1.2.3 From 4f7200c55032d17c9bdbdb30cfd83dc757c63fe7 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 19 Dec 2017 17:37:57 +0100 Subject: adjust Fragments --- .../se/leap/bitmaskclient/ConfigurationWizard.java | 4 +- .../se/leap/bitmaskclient/NewProviderDialog.java | 23 +++++++---- .../leap/bitmaskclient/ProviderDetailFragment.java | 20 ++++++---- .../de/blinkt/openvpn/fragments/LogFragment.java | 20 ++++++++-- .../bitmaskclient/BaseConfigurationWizard.java | 10 ++--- .../main/java/se/leap/bitmaskclient/Dashboard.java | 16 ++++---- .../leap/bitmaskclient/DownloadFailedDialog.java | 9 +++-- .../bitmaskclient/FragmentManagerEnhanced.java | 4 +- .../java/se/leap/bitmaskclient/MainActivity.java | 46 +++++++++++++++++----- .../bitmaskclient/NavigationDrawerFragment.java | 4 +- .../java/se/leap/bitmaskclient/VpnFragment.java | 22 ++++++----- .../bitmaskclient/userstatus/SessionDialog.java | 21 +++++----- .../userstatus/UserStatusFragment.java | 5 ++- app/src/main/res/layout/f_log.xml | 37 +++++++++++++++++ app/src/main/res/values/strings.xml | 3 +- 15 files changed, 174 insertions(+), 70 deletions(-) create mode 100644 app/src/main/res/layout/f_log.xml diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java index df1a59ff..7466f90a 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ConfigurationWizard.java @@ -16,10 +16,10 @@ */ package se.leap.bitmaskclient; -import android.app.DialogFragment; -import android.app.FragmentTransaction; import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentTransaction; import java.net.MalformedURLException; import java.net.URL; diff --git a/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java b/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java index c1426708..4b7edb58 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/NewProviderDialog.java @@ -16,21 +16,28 @@ */ package se.leap.bitmaskclient; -import butterknife.*; -import se.leap.bitmaskclient.ProviderListContent.ProviderItem; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.Toast; -import android.app.*; -import android.content.*; -import android.os.*; -import android.view.*; -import android.widget.*; +import butterknife.ButterKnife; +import butterknife.InjectView; +import se.leap.bitmaskclient.ProviderListContent.ProviderItem; /** * Implements the new custom provider dialog. * * @author parmegv */ -public class NewProviderDialog extends DialogFragment { +public class NewProviderDialog extends DialogFragment{ final public static String TAG = "newProviderDialog"; diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java index 390d4aeb..8c61ecc8 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java @@ -1,15 +1,21 @@ package se.leap.bitmaskclient; -import org.json.*; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import org.json.JSONException; +import org.json.JSONObject; import se.leap.bitmaskclient.ProviderListContent.ProviderItem; -import android.app.*; -import android.content.*; -import android.os.*; -import android.view.*; -import android.widget.*; - public class ProviderDetailFragment extends DialogFragment { final public static String TAG = "providerDetailFragment"; diff --git a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java index d75d6d53..a1fc7cdc 100644 --- a/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java +++ b/app/src/main/java/de/blinkt/openvpn/fragments/LogFragment.java @@ -23,6 +23,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.Handler.Callback; import android.os.Message; +import android.preference.Preference; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.text.SpannableString; @@ -53,27 +54,30 @@ import java.util.Locale; import java.util.Vector; import de.blinkt.openvpn.LaunchVPN; +import se.leap.bitmaskclient.R; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.activities.DisconnectVPN; import de.blinkt.openvpn.core.ConnectionStatus; -import de.blinkt.openvpn.core.LogItem; import de.blinkt.openvpn.core.OpenVPNManagement; import de.blinkt.openvpn.core.OpenVPNService; import de.blinkt.openvpn.core.Preferences; import de.blinkt.openvpn.core.ProfileManager; import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.LogItem; import de.blinkt.openvpn.core.VpnStatus.LogListener; import de.blinkt.openvpn.core.VpnStatus.StateListener; -import se.leap.bitmaskclient.Dashboard; -import se.leap.bitmaskclient.R; import static de.blinkt.openvpn.core.OpenVPNService.humanReadableByteCount; +import se.leap.bitmaskclient.Dashboard; + public class LogFragment extends ListFragment implements StateListener, SeekBar.OnSeekBarChangeListener, RadioGroup.OnCheckedChangeListener, VpnStatus.ByteCountListener { private static final String LOGTIMEFORMAT = "logtimeformat"; private static final int START_VPN_CONFIG = 0; private static final String VERBOSITYLEVEL = "verbositylevel"; + + private SeekBar mLogLevelSlider; private LinearLayout mOptionsLayout; private RadioGroup mTimeRadioGroup; @@ -430,6 +434,16 @@ public class LogFragment extends ListFragment implements StateListener, SeekBar. return true; } else if (item.getItemId() == R.id.send) { ladapter.shareLog(); + } else if (item.getItemId() == R.id.edit_vpn) { + VpnProfile lastConnectedprofile = ProfileManager.get(getActivity(), VpnStatus.getLastConnectedVPNProfile()); + + if (lastConnectedprofile != null) { + Intent vprefintent = new Intent(getActivity(), Dashboard.class) + .putExtra(VpnProfile.EXTRA_PROFILEUUID, lastConnectedprofile.getUUIDString()); + startActivityForResult(vprefintent, START_VPN_CONFIG); + } else { + Toast.makeText(getActivity(), R.string.log_no_last_vpn, Toast.LENGTH_LONG).show(); + } } else if (item.getItemId() == R.id.toggle_time) { showHideOptionsPanel(); } else if (item.getItemId() == android.R.id.home) { diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 52c8f8e5..75a653c0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -17,9 +17,6 @@ package se.leap.bitmaskclient; -import android.app.Activity; -import android.app.DialogFragment; -import android.app.FragmentTransaction; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -27,6 +24,9 @@ import android.content.IntentFilter; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; import android.view.Display; import android.view.Menu; import android.view.MenuItem; @@ -68,7 +68,7 @@ import static android.view.View.VISIBLE; * @author cyberta */ -public abstract class BaseConfigurationWizard extends Activity +public abstract class BaseConfigurationWizard extends AppCompatActivity implements NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, DownloadFailedDialog.DownloadFailedDialogInterface, ProviderAPIResultReceiver.Receiver { @InjectView(R.id.progressbar_configuration_wizard) protected ProgressBar mProgressBar; @@ -134,7 +134,7 @@ public abstract class BaseConfigurationWizard extends Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); - fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); + fragment_manager = new FragmentManagerEnhanced(getSupportFragmentManager()); provider_manager = ProviderManager.getInstance(getAssets(), getExternalFilesDir(null)); setUpInitialUI(); diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 1eed484c..0d3af13f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -17,15 +17,15 @@ package se.leap.bitmaskclient; import android.annotation.SuppressLint; -import android.app.Activity; import android.app.AlertDialog; -import android.app.FragmentTransaction; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; import android.os.Handler; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -56,7 +56,7 @@ import static se.leap.bitmaskclient.Constants.REQUEST_CODE_SWITCH_PROVIDER; * @author Sean Leonard * @author parmegv */ -public class Dashboard extends Activity { +public class Dashboard extends AppCompatActivity { public static final String TAG = Dashboard.class.getSimpleName(); @@ -91,7 +91,7 @@ public class Dashboard extends Activity { super.onCreate(savedInstanceState); dashboardReceiver = new DashboardReceiver(this); preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); - fragment_manager = new FragmentManagerEnhanced(getFragmentManager()); + fragment_manager = new FragmentManagerEnhanced(getSupportFragmentManager()); providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), dashboardReceiver); @@ -305,7 +305,7 @@ public class Dashboard extends Activity { * has caused to start Dashboard * @return the created VPNFragment */ - private VpnFragment prepareEipFragment(boolean hideAndTurnOnEipOnBoot) { + public static VpnFragment prepareEipFragment(boolean hideAndTurnOnEipOnBoot) { VpnFragment eip_fragment = new VpnFragment(); if (hideAndTurnOnEipOnBoot && !isAlwaysOn()) { @@ -323,7 +323,7 @@ public class Dashboard extends Activity { * checks if Android's VPN feature 'always-on' is enabled for Bitmask * @return true if 'always-on' is enabled false if not */ - private boolean isAlwaysOn() { + private static boolean isAlwaysOn() { return preferences.getBoolean(EIP_IS_ALWAYS_ON, false); } @@ -418,11 +418,11 @@ public class Dashboard extends Activity { String password = resultData.getString(SessionDialog.PASSWORD); dashboard.user_status_fragment.logIn(username, password); } else if (resultCode == ProviderAPI.FAILED_SIGNUP) { - Dashboard.sessionDialog(resultData); + MainActivity.sessionDialog(resultData); } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { Dashboard.downloadVpnCertificate(); } else if (resultCode == ProviderAPI.FAILED_LOGIN) { - Dashboard.sessionDialog(resultData); + MainActivity.sessionDialog(resultData); } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { if (switching_provider) dashboard.switchProvider(); } else if (resultCode == ProviderAPI.LOGOUT_FAILED) { diff --git a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java index da32dbd4..d6d89b58 100644 --- a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java @@ -16,9 +16,12 @@ */ package se.leap.bitmaskclient; -import android.app.*; -import android.content.*; -import android.os.*; +import android.app.Activity; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; /** * Implements a dialog to show why a download failed. diff --git a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java index 8ba7fa34..9594cea0 100644 --- a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java +++ b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java @@ -16,7 +16,9 @@ */ package se.leap.bitmaskclient; -import android.app.*; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; public class FragmentManagerEnhanced { diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java index 8cd6357c..2f07f162 100644 --- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java @@ -2,9 +2,12 @@ package se.leap.bitmaskclient; import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; @@ -14,11 +17,17 @@ import android.view.ViewGroup; import android.support.v4.widget.DrawerLayout; import se.leap.bitmaskclient.fragments.LogFragment; +import se.leap.bitmaskclient.userstatus.SessionDialog; public class MainActivity extends AppCompatActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks { + private static Provider provider = new Provider(); + private static FragmentManagerEnhanced fragmentManager; + private SharedPreferences preferences; + + /** * Fragment managing the behaviors, interactions and presentation of the navigation drawer. */ @@ -40,42 +49,52 @@ public class MainActivity extends AppCompatActivity getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); + fragmentManager = new FragmentManagerEnhanced(getSupportFragmentManager()); + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); // Set up the drawer. mNavigationDrawerFragment.setUp( R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); + } @Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments FragmentManager fragmentManager = getSupportFragmentManager(); - Fragment fragment; + Fragment fragment = null; switch (position) { case 1: + // TODO STOP VPN + // if (provider.hasEIP()) eip_fragment.stopEipIfPossible(); + preferences.edit().clear().apply(); + startActivityForResult(new Intent(this, ConfigurationWizard.class), Constants.REQUEST_CODE_SWITCH_PROVIDER); + break; case 2: - fragment = PlaceholderFragment.newInstance(); + fragment = new LogFragment(); break; default: - fragment = new LogFragment(); + fragment = new VpnFragment(); break; } - fragmentManager.beginTransaction() - .replace(R.id.container, fragment) - .commit(); + if (fragment != null) { + fragmentManager.beginTransaction() + .replace(R.id.container, fragment) + .commit(); + } onSectionAttached(position); } public void onSectionAttached(int number) { switch (number) { case 1: - mTitle = getString(R.string.title_section2); + mTitle = getString(R.string.switch_provider_menu_option); break; case 2: - mTitle = getString(R.string.title_section3); + mTitle = getString(R.string.log_fragment_title); break; default: - mTitle = getString(R.string.log_fragment_title); + mTitle = getString(R.string.vpn_fragment_title); break; } restoreActionBar(); @@ -118,4 +137,13 @@ public class MainActivity extends AppCompatActivity } } + public static void sessionDialog(Bundle resultData) { + try { + FragmentTransaction transaction = fragmentManager.removePreviousFragment(SessionDialog.TAG); + SessionDialog.getInstance(provider, resultData).show(transaction, SessionDialog.TAG); + } catch (IllegalStateException e) { + e.printStackTrace(); + } + } + } diff --git a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java index bb0d8f46..b8a9e5b1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java @@ -123,9 +123,9 @@ public class NavigationDrawerFragment extends Fragment { android.R.layout.simple_list_item_activated_1, android.R.id.text1, new String[]{ + getString(R.string.vpn_fragment_title), + getString(R.string.switch_provider_menu_option), getString(R.string.log_fragment_title), - getString(R.string.title_section2), - getString(R.string.title_section3), })); mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); mFragmentContainerView = activity.findViewById(fragmentId); diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java index 2b968769..e16ab75c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java @@ -18,7 +18,6 @@ package se.leap.bitmaskclient; import android.app.Activity; import android.app.AlertDialog; -import android.app.Fragment; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; @@ -30,6 +29,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; import android.os.ResultReceiver; +import android.support.v4.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -127,7 +127,6 @@ public class VpnFragment extends Fragment implements Observer { if (arguments != null && arguments.containsKey(START_EIP_ON_BOOT) && arguments.getBoolean(START_EIP_ON_BOOT)) { startEipFromScratch(); } - return view; } @@ -170,7 +169,7 @@ public class VpnFragment extends Fragment implements Observer { else if (canLogInToStartEIP()) { wants_to_connect = true; Bundle bundle = new Bundle(); - Dashboard.sessionDialog(bundle); + MainActivity.sessionDialog(bundle); } else { Log.d(TAG, "WHAT IS GOING ON HERE?!"); // TODO: implement a fallback: check if vpncertificate was not downloaded properly or give @@ -305,12 +304,17 @@ public class VpnFragment extends Fragment implements Observer { public void update(Observable observable, Object data) { if (observable instanceof EipStatus) { eip_status = (EipStatus) observable; - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - handleNewState(); - } - }); + Activity activity = getActivity(); + if (activity != null) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + handleNewState(); + } + }); + } else { + Log.e("VpnFragment", "activity is null"); + } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java index 61349490..440b02fa 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java @@ -16,15 +16,18 @@ */ package se.leap.bitmaskclient.userstatus; -import android.app.*; -import android.content.*; -import android.os.*; -import android.view.*; -import android.widget.*; - -import butterknife.*; -import se.leap.bitmaskclient.ProviderAPI; -import se.leap.bitmaskclient.VpnFragment; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import android.widget.TextView; + +import butterknife.ButterKnife; +import butterknife.InjectView; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.R; diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java index f4be3ea1..a991e88e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -1,9 +1,9 @@ package se.leap.bitmaskclient.userstatus; import android.app.Activity; -import android.app.Fragment; import android.os.Bundle; import android.os.Handler; +import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,6 +19,7 @@ import butterknife.ButterKnife; import butterknife.InjectView; import butterknife.OnClick; import se.leap.bitmaskclient.Dashboard; +import se.leap.bitmaskclient.MainActivity; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.ProviderAPI; import se.leap.bitmaskclient.ProviderAPICommand; @@ -90,7 +91,7 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia if(status.isLoggedIn()) logOut(); else if(status.isLoggedOut()) - Dashboard.sessionDialog(Bundle.EMPTY); + MainActivity.sessionDialog(Bundle.EMPTY); else if(status.inProgress()) cancelLoginOrSignup(); } diff --git a/app/src/main/res/layout/f_log.xml b/app/src/main/res/layout/f_log.xml new file mode 100644 index 00000000..41c72d99 --- /dev/null +++ b/app/src/main/res/layout/f_log.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c82fad35..c854948c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -81,8 +81,7 @@ Bitmask Log - Section 2 - Section 3 + VPN Open navigation drawer Close navigation drawer -- cgit v1.2.3 From bd99fc61a2e8217c41b70c6f2ff0df87e7008ea0 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Mon, 8 Jan 2018 15:49:34 +0100 Subject: seperate accountList and settingsList in drawer --- app/build.gradle | 4 +- .../java/se/leap/bitmaskclient/MainActivity.java | 57 +--- .../bitmaskclient/NavigationDrawerFragment.java | 282 ----------------- .../java/se/leap/bitmaskclient/StartActivity.java | 2 +- .../drawer/NavigationDrawerFragment.java | 349 +++++++++++++++++++++ .../leap/bitmaskclient/fragments/LogFragment.java | 2 - .../bitmaskclient/userstatus/SessionDialog.java | 7 +- .../userstatus/UserStatusFragment.java | 4 +- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/drawer_main.xml | 18 +- .../java/se/leap/bitmaskclient/ProviderAPI.java | 2 +- 11 files changed, 375 insertions(+), 354 deletions(-) delete mode 100644 app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java diff --git a/app/build.gradle b/app/build.gradle index f510b098..e90f5be7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 26 - buildToolsVersion '26.0.0' + buildToolsVersion '26.0.2' defaultConfig { applicationId "se.leap.bitmaskclient" @@ -77,7 +77,7 @@ dependencies { compile 'com.squareup.okhttp3:okhttp:3.9.0' compile 'mbanje.kurt:fabbutton:1.1.4' compile "com.android.support:support-core-utils:26.1.0" - compile 'com.android.support:support-annotations:27.0.1' + compile 'com.android.support:support-annotations:27.0.2' compile 'com.android.support:support-v4:26.1.0' compile 'com.android.support:appcompat-v7:26.1.0' compile 'com.android.support:design:26.1.0' diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java index 2f07f162..82a193e7 100644 --- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java @@ -11,17 +11,20 @@ import android.support.v4.app.FragmentTransaction; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.support.v4.widget.DrawerLayout; +import se.leap.bitmaskclient.drawer.NavigationDrawerFragment; import se.leap.bitmaskclient.fragments.LogFragment; import se.leap.bitmaskclient.userstatus.SessionDialog; +import se.leap.bitmaskclient.userstatus.User; +import se.leap.bitmaskclient.userstatus.UserStatusFragment; -public class MainActivity extends AppCompatActivity - implements NavigationDrawerFragment.NavigationDrawerCallbacks { +public class MainActivity extends AppCompatActivity { private static Provider provider = new Provider(); private static FragmentManagerEnhanced fragmentManager; @@ -58,56 +61,6 @@ public class MainActivity extends AppCompatActivity } - @Override - public void onNavigationDrawerItemSelected(int position) { - // update the main content by replacing fragments - FragmentManager fragmentManager = getSupportFragmentManager(); - Fragment fragment = null; - switch (position) { - case 1: - // TODO STOP VPN - // if (provider.hasEIP()) eip_fragment.stopEipIfPossible(); - preferences.edit().clear().apply(); - startActivityForResult(new Intent(this, ConfigurationWizard.class), Constants.REQUEST_CODE_SWITCH_PROVIDER); - break; - case 2: - fragment = new LogFragment(); - break; - default: - fragment = new VpnFragment(); - break; - } - if (fragment != null) { - fragmentManager.beginTransaction() - .replace(R.id.container, fragment) - .commit(); - } - onSectionAttached(position); - } - - public void onSectionAttached(int number) { - switch (number) { - case 1: - mTitle = getString(R.string.switch_provider_menu_option); - break; - case 2: - mTitle = getString(R.string.log_fragment_title); - break; - default: - mTitle = getString(R.string.vpn_fragment_title); - break; - } - restoreActionBar(); - } - - public void restoreActionBar() { - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setSubtitle(mTitle); - } - } - /** * A placeholder fragment containing a simple view. */ diff --git a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java deleted file mode 100644 index b8a9e5b1..00000000 --- a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java +++ /dev/null @@ -1,282 +0,0 @@ -package se.leap.bitmaskclient; - - -import android.content.Context; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v4.app.Fragment; -import android.support.v4.view.GravityCompat; -import android.support.v4.widget.DrawerLayout; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; -import android.widget.Toast; - -/** - * Fragment used for managing interactions for and presentation of a navigation drawer. - * See the - * design guidelines for a complete explanation of the behaviors implemented here. - */ -public class NavigationDrawerFragment extends Fragment { - - /** - * Remember the position of the selected item. - */ - private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; - - /** - * Per the design guidelines, you should show the drawer on launch until the user manually - * expands it. This shared preference tracks this. - */ - private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; - - /** - * A pointer to the current callbacks instance (the Activity). - */ - private NavigationDrawerCallbacks mCallbacks; - - /** - * Helper component that ties the action bar to the navigation drawer. - */ - private ActionBarDrawerToggle mDrawerToggle; - - private DrawerLayout mDrawerLayout; - private View mDrawerView; - private ListView mDrawerListView; - private View mFragmentContainerView; - - private int mCurrentSelectedPosition = 0; - private boolean mFromSavedInstanceState; - private boolean mUserLearnedDrawer; - - public NavigationDrawerFragment() { - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - // Read in the flag indicating whether or not the user has demonstrated awareness of the - // drawer. See PREF_USER_LEARNED_DRAWER for details. - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); - mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); - - if (savedInstanceState != null) { - mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); - mFromSavedInstanceState = true; - } - - // Select either the default item (0) or the last selected item. - selectItem(mCurrentSelectedPosition); - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - // Indicate that this fragment would like to influence the set of actions in the action bar. - setHasOptionsMenu(true); - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - mDrawerView = inflater.inflate(R.layout.drawer_main, container, false); - return mDrawerView; - } - - public boolean isDrawerOpen() { - return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); - } - - /** - * Users of this fragment must call this method to set up the navigation drawer interactions. - * - * @param fragmentId The android:id of this fragment in its activity's layout. - * @param drawerLayout The DrawerLayout containing this fragment's UI. - */ - public void setUp(int fragmentId, DrawerLayout drawerLayout) { - AppCompatActivity activity = (AppCompatActivity) getActivity(); - - mDrawerListView = mDrawerView.findViewById(R.id.accountList); - mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - selectItem(position); - } - }); - - ActionBar actionBar = activity.getSupportActionBar(); - mDrawerListView.setAdapter(new ArrayAdapter( - actionBar.getThemedContext(), - android.R.layout.simple_list_item_activated_1, - android.R.id.text1, - new String[]{ - getString(R.string.vpn_fragment_title), - getString(R.string.switch_provider_menu_option), - getString(R.string.log_fragment_title), - })); - mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); - mFragmentContainerView = activity.findViewById(fragmentId); - mDrawerLayout = drawerLayout; - - // set a custom shadow that overlays the main content when the drawer opens - mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); - - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setHomeButtonEnabled(true); - // ActionBarDrawerToggle ties together the the proper interactions - // between the navigation drawer and the action bar app icon. - mDrawerToggle = new ActionBarDrawerToggle( - getActivity(), - mDrawerLayout, - (Toolbar) drawerLayout.findViewById(R.id.toolbar), - R.string.navigation_drawer_open, - R.string.navigation_drawer_close - ) { - @Override - public void onDrawerClosed(View drawerView) { - super.onDrawerClosed(drawerView); - if (!isAdded()) { - return; - } - - getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() - } - - @Override - public void onDrawerOpened(View drawerView) { - super.onDrawerOpened(drawerView); - if (!isAdded()) { - return; - } - - if (!mUserLearnedDrawer) { - // The user manually opened the drawer; store this flag to prevent auto-showing - // the navigation drawer automatically in the future. - mUserLearnedDrawer = true; - SharedPreferences sp = PreferenceManager - .getDefaultSharedPreferences(getActivity()); - sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); - } - - getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() - } - }; - - // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, - // per the navigation drawer design guidelines. - if (!mUserLearnedDrawer && !mFromSavedInstanceState) { - mDrawerLayout.openDrawer(mFragmentContainerView); - } - - // Defer code dependent on restoration of previous instance state. - mDrawerLayout.post(new Runnable() { - @Override - public void run() { - mDrawerToggle.syncState(); - } - }); - - mDrawerLayout.addDrawerListener(mDrawerToggle); - } - - private void selectItem(int position) { - mCurrentSelectedPosition = position; - if (mDrawerListView != null) { - mDrawerListView.setItemChecked(position, true); - } - if (mDrawerLayout != null) { - mDrawerLayout.closeDrawer(mFragmentContainerView); - } - if (mCallbacks != null) { - mCallbacks.onNavigationDrawerItemSelected(position); - } - } - - @Override - public void onAttach(Context context) { - super.onAttach(context); - try { - mCallbacks = (NavigationDrawerCallbacks) context; - } catch (ClassCastException e) { - throw new ClassCastException("Activity must implement NavigationDrawerCallbacks."); - } - } - - @Override - public void onDetach() { - super.onDetach(); - mCallbacks = null; - } - - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - // Forward the new configuration the drawer toggle component. - mDrawerToggle.onConfigurationChanged(newConfig); - } - - @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (mDrawerLayout != null && isDrawerOpen()) { - showGlobalContextActionBar(); - } - super.onCreateOptionsMenu(menu, inflater); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (mDrawerToggle.onOptionsItemSelected(item)) { - return true; - } - - if (item.getItemId() == R.id.action_example) { - Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show(); - return true; - } - - return super.onOptionsItemSelected(item); - } - - /** - * Per the navigation drawer design guidelines, updates the action bar to show the global app - * 'context', rather than just what's in the current screen. - */ - private void showGlobalContextActionBar() { - ActionBar actionBar = getActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setTitle(R.string.app_name); - } - - private ActionBar getActionBar() { - return ((AppCompatActivity) getActivity()).getSupportActionBar(); - } - - /** - * Callbacks interface that all activities using this fragment must implement. - */ - public interface NavigationDrawerCallbacks { - /** - * Called when an item in the navigation drawer is selected. - */ - void onNavigationDrawerItemSelected(int position); - } -} diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java index 1bf81aea..55760cb3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java @@ -48,7 +48,7 @@ public class StartActivity extends Activity { break; case FIRST: - // TODO start ProfileCreation & replace below code + // (new Intent(getActivity(), ConfigurationWizard.class), Constants.REQUEST_CODE_SWITCH_PROVIDER); break; case UPGRADE: diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java new file mode 100644 index 00000000..60c38fbc --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -0,0 +1,349 @@ +package se.leap.bitmaskclient.drawer; + + +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.FragmentManager; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v4.app.Fragment; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +import se.leap.bitmaskclient.ConfigurationWizard; +import se.leap.bitmaskclient.Constants; +import se.leap.bitmaskclient.Provider; +import se.leap.bitmaskclient.R; +import se.leap.bitmaskclient.VpnFragment; +import se.leap.bitmaskclient.fragments.LogFragment; +import se.leap.bitmaskclient.userstatus.User; +import se.leap.bitmaskclient.userstatus.UserStatusFragment; + +/** + * Fragment used for managing interactions for and presentation of a navigation drawer. + * See the + * design guidelines for a complete explanation of the behaviors implemented here. + */ +public class NavigationDrawerFragment extends Fragment { + + /** + * Remember the position of the selected item. + */ + private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position"; + + /** + * Per the design guidelines, you should show the drawer on launch until the user manually + * expands it. This shared preference tracks this. + */ + private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; + + /** + * Helper component that ties the action bar to the navigation drawer. + */ + private ActionBarDrawerToggle mDrawerToggle; + + private DrawerLayout mDrawerLayout; + private View mDrawerView; + private ListView mDrawerSettingsListView; + private ListView mDrawerAccountsListView; + private View mFragmentContainerView; + + private int mCurrentSelectedPosition = 0; + private boolean mFromSavedInstanceState; + private boolean mUserLearnedDrawer; + + private String mTitle; + + private SharedPreferences preferences; + + public NavigationDrawerFragment() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Read in the flag indicating whether or not the user has demonstrated awareness of the + // drawer. See PREF_USER_LEARNED_DRAWER for details. + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); + mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false); + + preferences = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE); + + if (savedInstanceState != null) { + mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION); + mFromSavedInstanceState = true; + } + + // Select either the default item (0) or the last selected item. + if (mDrawerSettingsListView != null) { + selectItem(mDrawerSettingsListView, mCurrentSelectedPosition); + } + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + // Indicate that this fragment would like to influence the set of actions in the action bar. + setHasOptionsMenu(true); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mDrawerView = inflater.inflate(R.layout.drawer_main, container, false); + return mDrawerView; + } + + public boolean isDrawerOpen() { + return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); + } + + /** + * Users of this fragment must call this method to set up the navigation drawer interactions. + * + * @param fragmentId The android:id of this fragment in its activity's layout. + * @param drawerLayout The DrawerLayout containing this fragment's UI. + */ + public void setUp(int fragmentId, DrawerLayout drawerLayout) { + AppCompatActivity activity = (AppCompatActivity) getActivity(); + ActionBar actionBar = activity.getSupportActionBar(); + + mDrawerSettingsListView = mDrawerView.findViewById(R.id.settingsList); + mDrawerSettingsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(parent, position); + } + }); + + mDrawerSettingsListView.setAdapter(new ArrayAdapter( + actionBar.getThemedContext(), + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + new String[]{ + getString(R.string.vpn_fragment_title), + getString(R.string.switch_provider_menu_option), + getString(R.string.log_fragment_title), + })); + mDrawerSettingsListView.setItemChecked(mCurrentSelectedPosition, true); + + mDrawerAccountsListView = mDrawerView.findViewById(R.id.accountList); + mDrawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(parent, position); + } + }); + + mDrawerAccountsListView.setAdapter(new ArrayAdapter( + actionBar.getThemedContext(), + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + new String[]{ + User.userName(), + })); + mDrawerAccountsListView.setItemChecked(mCurrentSelectedPosition, true); + + mFragmentContainerView = activity.findViewById(fragmentId); + mDrawerLayout = drawerLayout; + + // set a custom shadow that overlays the main content when the drawer opens + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); + + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + // ActionBarDrawerToggle ties together the the proper interactions + // between the navigation drawer and the action bar app icon. + mDrawerToggle = new ActionBarDrawerToggle( + getActivity(), + mDrawerLayout, + (Toolbar) drawerLayout.findViewById(R.id.toolbar), + R.string.navigation_drawer_open, + R.string.navigation_drawer_close + ) { + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + if (!isAdded()) { + return; + } + + getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + if (!isAdded()) { + return; + } + + if (!mUserLearnedDrawer) { + // The user manually opened the drawer; store this flag to prevent auto-showing + // the navigation drawer automatically in the future. + mUserLearnedDrawer = true; + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences(getActivity()); + sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); + } + + getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + } + }; + + // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, + // per the navigation drawer design guidelines. + if (!mUserLearnedDrawer && !mFromSavedInstanceState) { + mDrawerLayout.openDrawer(mFragmentContainerView); + } + + // Defer code dependent on restoration of previous instance state. + mDrawerLayout.post(new Runnable() { + @Override + public void run() { + mDrawerToggle.syncState(); + } + }); + mDrawerLayout.addDrawerListener(mDrawerToggle); + + selectItem(mDrawerSettingsListView, 0); + } + + private void selectItem(AdapterView list, int position) { + mCurrentSelectedPosition = position; + if (list != null) { + ((ListView) list).setItemChecked(position, true); + } + if (mDrawerLayout != null) { + mDrawerLayout.closeDrawer(mFragmentContainerView); + } + onNavigationDrawerItemSelected(list, position); + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + } + + @Override + public void onDetach() { + super.onDetach(); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + // Forward the new configuration the drawer toggle component. + mDrawerToggle.onConfigurationChanged(newConfig); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + if (mDrawerLayout != null && isDrawerOpen()) { + showGlobalContextActionBar(); + } + super.onCreateOptionsMenu(menu, inflater); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (mDrawerToggle.onOptionsItemSelected(item)) { + return true; + } + + if (item.getItemId() == R.id.action_example) { + Toast.makeText(getActivity(), "Example action.", Toast.LENGTH_SHORT).show(); + return true; + } + + return super.onOptionsItemSelected(item); + } + + /** + * Per the navigation drawer design guidelines, updates the action bar to show the global app + * 'context', rather than just what's in the current screen. + */ + private void showGlobalContextActionBar() { + ActionBar actionBar = getActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setTitle(R.string.app_name); + } + + private ActionBar getActionBar() { + return ((AppCompatActivity) getActivity()).getSupportActionBar(); + } + + public void onNavigationDrawerItemSelected(AdapterView parent, int position) { + // update the main content by replacing fragments + FragmentManager fragmentManager = getFragmentManager(); + Fragment fragment = null; + + if (parent == mDrawerAccountsListView) { + mTitle = User.userName(); + fragment = new UserStatusFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(Provider.ALLOW_REGISTRATION, new Provider().allowsRegistration()); + fragment.setArguments(bundle); + } else { + Log.d("Drawer", String.format("Selected position %d", position)); + switch (position) { + case 1: + // TODO STOP VPN + // if (provider.hasEIP()) eip_fragment.stopEipIfPossible(); + preferences.edit().clear().apply(); + startActivityForResult(new Intent(getActivity(), ConfigurationWizard.class), Constants.REQUEST_CODE_SWITCH_PROVIDER); + break; + case 2: + mTitle = getString(R.string.log_fragment_title); + fragment = new LogFragment(); + break; + default: + mTitle = getString(R.string.vpn_fragment_title); + fragment = new VpnFragment(); + break; + } + } + + if (fragment != null) { + fragmentManager.beginTransaction() + .replace(R.id.container, fragment) + .commit(); + } + + restoreActionBar(); + } + + public void restoreActionBar() { + ActionBar actionBar = getActionBar(); + if (actionBar != null) { + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setSubtitle(mTitle); + } + } + + +} diff --git a/app/src/main/java/se/leap/bitmaskclient/fragments/LogFragment.java b/app/src/main/java/se/leap/bitmaskclient/fragments/LogFragment.java index b72e53d5..3917683d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/fragments/LogFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/fragments/LogFragment.java @@ -25,7 +25,6 @@ import android.os.Message; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.support.v4.app.ListFragment; -import android.support.v7.app.AppCompatActivity; import android.text.SpannableString; import android.text.format.DateFormat; import android.text.style.ImageSpan; @@ -65,7 +64,6 @@ import de.blinkt.openvpn.core.VpnStatus; import de.blinkt.openvpn.core.VpnStatus.LogListener; import de.blinkt.openvpn.core.VpnStatus.StateListener; import se.leap.bitmaskclient.Dashboard; -import se.leap.bitmaskclient.NavigationDrawerFragment; import se.leap.bitmaskclient.R; import static de.blinkt.openvpn.core.OpenVPNService.humanReadableByteCount; diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java index 440b02fa..1256c619 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java @@ -16,11 +16,12 @@ */ package se.leap.bitmaskclient.userstatus; -import android.app.Activity; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.support.v4.app.DialogFragment; +import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.widget.EditText; @@ -164,11 +165,11 @@ public class SessionDialog extends DialogFragment { SessionDialogInterface interface_with_Dashboard; @Override - public void onAttach(Activity activity) { + public void onAttach(Context activity) { super.onAttach(activity); try { - interface_with_Dashboard = (SessionDialogInterface) activity.getFragmentManager().findFragmentById(R.id.user_status_fragment);; + interface_with_Dashboard = (SessionDialogInterface) ((AppCompatActivity) activity).getSupportFragmentManager().getFragments().get(0); } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement LogInDialogListener"); diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java index a991e88e..a6439a16 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -1,6 +1,6 @@ package se.leap.bitmaskclient.userstatus; -import android.app.Activity; +import android.content.Context; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.Fragment; @@ -72,7 +72,7 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia } @Override - public void onAttach(Activity activity) { + public void onAttach(Context activity) { super.onAttach(activity); providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), Dashboard.dashboardReceiver); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 28c23503..de06efc7 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -33,7 +33,7 @@ the container. --> + tools:context="se.leap.bitmaskclient.drawer.NavigationDrawerFragment"> - + android:layout_height="wrap_content" /> - + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:layout_alignParentBottom="true" /> - + \ No newline at end of file diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java index a818e508..df9697fb 100644 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderAPI.java @@ -53,7 +53,7 @@ public class ProviderAPI extends ProviderApiBase { /** * Downloads a provider.json from a given URL, adding a new provider using the given name. - */ + * * @param task containing a boolean meaning if the provider is custom or not, another boolean meaning if the user completely trusts this provider, the provider name and its provider.json url. * @return a bundle with a boolean value mapped to a key named RESULT_KEY, and which is true if the update was successful. */ -- cgit v1.2.3 From 245982bdb6fda879827ab3c89617b8dd591fb7f4 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Mon, 8 Jan 2018 16:11:23 +0100 Subject: AboutActivity to AboutFragment --- .../test/TestConfigurationWizard.java | 4 +- app/src/main/AndroidManifest.xml | 4 +- .../java/se/leap/bitmaskclient/AboutActivity.java | 35 ---------------- .../bitmaskclient/BaseConfigurationWizard.java | 5 ++- .../main/java/se/leap/bitmaskclient/Dashboard.java | 3 +- .../drawer/NavigationDrawerFragment.java | 6 +++ .../bitmaskclient/fragments/AboutFragment.java | 49 ++++++++++++++++++++++ app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 9 files changed, 66 insertions(+), 44 deletions(-) delete mode 100644 app/src/main/java/se/leap/bitmaskclient/AboutActivity.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/fragments/AboutFragment.java diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java index 12e88af8..1a47bf24 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java @@ -7,7 +7,7 @@ import com.robotium.solo.Solo; import java.io.IOException; -import se.leap.bitmaskclient.AboutActivity; +import se.leap.bitmaskclient.fragments.AboutFragment; import se.leap.bitmaskclient.ConfigurationWizard; import se.leap.bitmaskclient.R; @@ -119,7 +119,7 @@ public class TestConfigurationWizard extends ActivityInstrumentationTestCase2 + android:name=".fragments.AboutFragment" + android:label="@string/about_fragment_title"> Por favor, introduce tu usuario contraseña Mensaje al usuario - Acerca de Bitmask" + Acerca de Bitmask" Inténtalo de nuevo: error en el servidor. Usuario o contraseña incorrectos. Al menos 8 caracteres. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c854948c..38e47f1d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,7 +29,7 @@ Please enter your username password User message - About Bitmask + About Bitmask Try again: server math error. Incorrect username or password. It should have at least 8 characters. -- cgit v1.2.3 From bc9c6ef38348af8719358aa7d8426439519bc7f1 Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Mon, 8 Jan 2018 20:06:41 +0100 Subject: remove test for AboutActivtiy since it's a fragment now --- .../se/leap/bitmaskclient/test/TestConfigurationWizard.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java index 1a47bf24..b224ecd3 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java @@ -112,14 +112,4 @@ public class TestConfigurationWizard extends ActivityInstrumentationTestCase2 Date: Tue, 9 Jan 2018 14:02:57 +0100 Subject: create ProviderDetail Activity --- .../test/BaseTestDashboardFragment.java | 2 +- .../test/TestConfigurationWizard.java | 3 +- .../se/leap/bitmaskclient/NewProviderDialog.java | 18 ++-- .../leap/bitmaskclient/ProviderDetailActivity.java | 115 ++++++++++++++++++++ .../leap/bitmaskclient/ProviderDetailFragment.java | 116 --------------------- app/src/main/AndroidManifest.xml | 8 +- .../bitmaskclient/BaseConfigurationWizard.java | 45 +------- .../res/layout-xlarge/provider_detail_fragment.xml | 5 + .../main/res/layout/provider_detail_fragment.xml | 5 + app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- .../se/leap/bitmaskclient/NewProviderDialog.java | 32 +++--- .../leap/bitmaskclient/ProviderDetailActivity.java | 115 ++++++++++++++++++++ .../leap/bitmaskclient/ProviderDetailFragment.java | 108 ------------------- 14 files changed, 282 insertions(+), 294 deletions(-) create mode 100644 app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java delete mode 100644 app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java create mode 100644 app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java delete mode 100644 app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java index d0b8cf6f..956049dc 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/BaseTestDashboardFragment.java @@ -84,7 +84,7 @@ public abstract class BaseTestDashboardFragment extends ActivityInstrumentationT } private void waitForProviderDetails() { - String text = solo.getString(R.string.provider_details_fragment_title); + String text = solo.getString(R.string.provider_details_title); assertTrue("Provider details dialog did not appear", solo.waitForText(text, 1, 60*1000)); Screenshot.take("Provider details"); } diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java index b224ecd3..c0d3aab1 100644 --- a/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/TestConfigurationWizard.java @@ -7,7 +7,6 @@ import com.robotium.solo.Solo; import java.io.IOException; -import se.leap.bitmaskclient.fragments.AboutFragment; import se.leap.bitmaskclient.ConfigurationWizard; import se.leap.bitmaskclient.R; @@ -71,7 +70,7 @@ public class TestConfigurationWizard extends ActivityInstrumentationTestCase2 optionsList = new ArrayList<>(); + optionsList.add(getString(R.string.login_button)); + if (registration_allowed(provider_json)) { + optionsList.add(getString(R.string.signup_button)); + } + if (anon_allowed(provider_json)) { + optionsList.add(getString(R.string.use_anonymously_button)); + } + + options.setAdapter(new ArrayAdapter<>( + this, + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + optionsList.toArray(new String[optionsList.size()]) + )); + options.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String text = ((TextView) view).getText().toString(); + if (text.equals(getString(R.string.login_button))) { + Log.d(TAG, "login selected"); + } else if (text.equals(getString(R.string.signup_button))) { + Log.d(TAG, "signup selected"); + } else if (text.equals(getString(R.string.use_anonymously_button))) { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + } + }); + } catch (JSONException e) { + // TODO show error and return + } + } + + private boolean anon_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); + } catch (JSONException e) { + return false; + } + } + + private boolean registration_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION); + } catch (JSONException e) { + return false; + } + } + + @Override + public void onBackPressed() { + SharedPreferences.Editor editor = preferences.edit(); + editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).apply(); + super.onBackPressed(); + } + +} diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java deleted file mode 100644 index 8c61ecc8..00000000 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ /dev/null @@ -1,116 +0,0 @@ -package se.leap.bitmaskclient; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.TextView; - -import org.json.JSONException; -import org.json.JSONObject; - -import se.leap.bitmaskclient.ProviderListContent.ProviderItem; - -public class ProviderDetailFragment extends DialogFragment { - - final public static String TAG = "providerDetailFragment"; - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - try { - - LayoutInflater inflater = getActivity().getLayoutInflater(); - View provider_detail_view = inflater.inflate(R.layout.provider_detail_fragment, null); - - JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, "")); - - final TextView domain = (TextView) provider_detail_view.findViewById(R.id.provider_detail_domain); - domain.setText(provider_json.getString(Provider.DOMAIN)); - final TextView name = (TextView) provider_detail_view.findViewById(R.id.provider_detail_name); - name.setText(provider_json.getJSONObject(Provider.NAME).getString("en")); - final TextView description = (TextView) provider_detail_view.findViewById(R.id.provider_detail_description); - description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en")); - - builder.setView(provider_detail_view); - builder.setTitle(R.string.provider_details_fragment_title); - - if (anon_allowed(provider_json)) { - builder.setPositiveButton(R.string.use_anonymously_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - interface_with_configuration_wizard.use_anonymously(); - } - }); - } - - if (registration_allowed(provider_json)) { - builder.setNegativeButton(R.string.signup_or_login_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - interface_with_configuration_wizard.login(); - } - }); - } - - return builder.create(); - } catch (JSONException e) { - return null; - } - } - - private boolean anon_allowed(JSONObject provider_json) { - try { - JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); - } catch (JSONException e) { - return false; - } - } - - private boolean registration_allowed(JSONObject provider_json) { - try { - JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION); - } catch (JSONException e) { - return false; - } - } - - @Override - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).commit(); - interface_with_configuration_wizard.cancelAndShowAllProviders(); - } - - public static DialogFragment newInstance() { - ProviderDetailFragment provider_detail_fragment = new ProviderDetailFragment(); - return provider_detail_fragment; - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - interface_with_configuration_wizard = (ProviderDetailFragmentInterface) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() - + " must implement LogInDialogListener"); - } - } - - public interface ProviderDetailFragmentInterface { - public void login(); - - public void use_anonymously(); - - public void cancelAndShowAllProviders(); - } - - ProviderDetailFragmentInterface interface_with_configuration_wizard; -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 43c31a88..8407d76d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -91,11 +91,11 @@ + android:label="@string/configuration_wizard_title" /> + + android:name=".ProviderDetailActivity" + android:label="@string/provider_details_title" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/provider_detail_fragment.xml b/app/src/main/res/layout/provider_detail_fragment.xml index 3b35bae7..3db32b2c 100644 --- a/app/src/main/res/layout/provider_detail_fragment.xml +++ b/app/src/main/res/layout/provider_detail_fragment.xml @@ -38,4 +38,9 @@ android:textStyle="normal" android:textAppearance="?android:attr/textAppearanceSmall" /> + + \ No newline at end of file diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 11fe31a1..6355ce62 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -25,7 +25,7 @@ Dominio El dominio está bien formado Dominio no válido - Detalles del proveedor + Detalles del proveedor Utilizar sin registrarse usuario Por favor, introduce tu usuario diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 38e47f1d..22736245 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,7 +23,7 @@ Domain name It seems your URL is well formed It seems your URL is not well formed - Provider details + Provider details Use anonymously username Please enter your username diff --git a/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java b/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java index 1823d3e3..fc7c9ede 100644 --- a/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java +++ b/app/src/production/java/se/leap/bitmaskclient/NewProviderDialog.java @@ -16,14 +16,20 @@ */ package se.leap.bitmaskclient; -import butterknife.*; -import se.leap.bitmaskclient.ProviderListContent.ProviderItem; +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; +import android.widget.Toast; -import android.app.*; -import android.content.*; -import android.os.*; -import android.view.*; -import android.widget.*; +import butterknife.ButterKnife; +import butterknife.InjectView; /** * Implements the new custom provider dialog. @@ -38,23 +44,24 @@ public class NewProviderDialog extends DialogFragment { EditText url_input_field; public interface NewProviderDialogInterface { - public void showAndSelectProvider(String url_provider); + void showAndSelectProvider(String url_provider); } NewProviderDialogInterface interface_with_ConfigurationWizard; @Override - public void onAttach(Activity activity) { - super.onAttach(activity); + public void onAttach(Context context) { + super.onAttach(context); try { - interface_with_ConfigurationWizard = (NewProviderDialogInterface) activity; + interface_with_ConfigurationWizard = (NewProviderDialogInterface) context; } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + throw new ClassCastException(context.toString() + " must implement NoticeDialogListener"); } } @Override + @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); @@ -96,7 +103,6 @@ public class NewProviderDialog extends DialogFragment { } else { url_input_field.setText(""); Toast.makeText(getActivity().getApplicationContext(), R.string.not_valid_url_entered, Toast.LENGTH_LONG).show(); - ; } } diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java new file mode 100644 index 00000000..0c5b1957 --- /dev/null +++ b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailActivity.java @@ -0,0 +1,115 @@ +package se.leap.bitmaskclient; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; + +import butterknife.ButterKnife; +import butterknife.InjectView; + +public class ProviderDetailActivity extends Activity { + + final public static String TAG = "providerDetailActivity"; + private SharedPreferences preferences; + + @InjectView(R.id.provider_detail_domain) + TextView domain; + + @InjectView(R.id.provider_detail_name) + TextView name; + + @InjectView(R.id.provider_detail_description) + TextView description; + + @InjectView(R.id.provider_detail_options) + ListView options; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.provider_detail_fragment); + ButterKnife.inject(this); + + preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); + try { + JSONObject provider_json = new JSONObject(preferences.getString(Provider.KEY, "")); + domain.setText(provider_json.getString(Provider.DOMAIN)); + name.setText(provider_json.getJSONObject(Provider.NAME).getString("en")); + description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en")); + + setTitle(R.string.provider_details_title); + + ArrayList optionsList = new ArrayList<>(); + optionsList.add(getString(R.string.login_button)); + if (registration_allowed(provider_json)) { + optionsList.add(getString(R.string.signup_button)); + } + if (anon_allowed(provider_json)) { + optionsList.add(getString(R.string.use_anonymously_button)); + } + + options.setAdapter(new ArrayAdapter<>( + this, + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + optionsList.toArray(new String[optionsList.size()]) + )); + options.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String text = ((TextView) view).getText().toString(); + if (text.equals(getString(R.string.login_button))) { + Log.d(TAG, "login selected"); + } else if (text.equals(getString(R.string.signup_button))) { + Log.d(TAG, "signup selected"); + } else if (text.equals(getString(R.string.use_anonymously_button))) { + Intent intent = new Intent(getApplicationContext(), MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + } + }); + } catch (JSONException e) { + // TODO show error and return + } + } + + private boolean anon_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); + } catch (JSONException e) { + return false; + } + } + + private boolean registration_allowed(JSONObject provider_json) { + try { + JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); + return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION); + } catch (JSONException e) { + return false; + } + } + + @Override + public void onBackPressed() { + SharedPreferences.Editor editor = preferences.edit(); + editor.remove(Provider.KEY).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).apply(); + super.onBackPressed(); + } + +} diff --git a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java b/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java deleted file mode 100644 index c7224ede..00000000 --- a/app/src/production/java/se/leap/bitmaskclient/ProviderDetailFragment.java +++ /dev/null @@ -1,108 +0,0 @@ -package se.leap.bitmaskclient; - -import org.json.*; - -import android.app.*; -import android.content.*; -import android.os.*; -import android.view.*; -import android.widget.*; - -public class ProviderDetailFragment extends DialogFragment { - - final public static String TAG = "providerDetailFragment"; - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - try { - - LayoutInflater inflater = getActivity().getLayoutInflater(); - View provider_detail_view = inflater.inflate(R.layout.provider_detail_fragment, null); - - JSONObject provider_json = new JSONObject(getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, getActivity().MODE_PRIVATE).getString(Provider.KEY, "")); - - final TextView domain = (TextView) provider_detail_view.findViewById(R.id.provider_detail_domain); - domain.setText(provider_json.getString(Provider.DOMAIN)); - final TextView name = (TextView) provider_detail_view.findViewById(R.id.provider_detail_name); - name.setText(provider_json.getJSONObject(Provider.NAME).getString("en")); - final TextView description = (TextView) provider_detail_view.findViewById(R.id.provider_detail_description); - description.setText(provider_json.getJSONObject(Provider.DESCRIPTION).getString("en")); - - builder.setView(provider_detail_view); - builder.setTitle(R.string.provider_details_fragment_title); - - if (anon_allowed(provider_json)) { - builder.setPositiveButton(R.string.use_anonymously_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - interface_with_configuration_wizard.use_anonymously(); - } - }); - } - - if (registration_allowed(provider_json)) { - builder.setNegativeButton(R.string.signup_or_login_button, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - interface_with_configuration_wizard.login(); - } - }); - } - - return builder.create(); - } catch (JSONException e) { - return null; - } - } - - private boolean anon_allowed(JSONObject provider_json) { - try { - JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Constants.PROVIDER_ALLOW_ANONYMOUS) && service_description.getBoolean(Constants.PROVIDER_ALLOW_ANONYMOUS); - } catch (JSONException e) { - return false; - } - } - - private boolean registration_allowed(JSONObject provider_json) { - try { - JSONObject service_description = provider_json.getJSONObject(Provider.SERVICE); - return service_description.has(Provider.ALLOW_REGISTRATION) && service_description.getBoolean(Provider.ALLOW_REGISTRATION); - } catch (JSONException e) { - return false; - } - } - - @Override - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); - SharedPreferences.Editor editor = getActivity().getSharedPreferences(Constants.SHARED_PREFERENCES, Activity.MODE_PRIVATE).edit(); - editor.remove(Provider.KEY).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).commit(); - interface_with_configuration_wizard.cancelAndShowAllProviders(); - } - - public static DialogFragment newInstance() { - ProviderDetailFragment provider_detail_fragment = new ProviderDetailFragment(); - return provider_detail_fragment; - } - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - try { - interface_with_configuration_wizard = (ProviderDetailFragmentInterface) activity; - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() - + " must implement LogInDialogListener"); - } - } - - public interface ProviderDetailFragmentInterface { - public void login(); - - public void use_anonymously(); - - public void cancelAndShowAllProviders(); - } - - ProviderDetailFragmentInterface interface_with_configuration_wizard; -} -- cgit v1.2.3 From 8806e6ae477e0b20806851f5f8f3c0141a63ad9d Mon Sep 17 00:00:00 2001 From: Fup Duck Date: Tue, 9 Jan 2018 19:54:57 +0100 Subject: create LoginActivity and SignUpActivity --- .../leap/bitmaskclient/ProviderDetailActivity.java | 18 +-- app/src/main/AndroidManifest.xml | 19 +-- .../bitmaskclient/BaseConfigurationWizard.java | 3 +- .../se/leap/bitmaskclient/ButterKnifeActivity.java | 30 +++++ .../main/java/se/leap/bitmaskclient/Dashboard.java | 3 +- .../java/se/leap/bitmaskclient/LoginActivity.java | 29 +++++ .../ProviderCredentialsBaseActivity.java | 134 +++++++++++++++++++++ .../java/se/leap/bitmaskclient/SignupActivity.java | 66 ++++++++++ .../bitmaskclient/userstatus/SessionDialog.java | 6 +- .../userstatus/UserStatusFragment.java | 3 - app/src/main/res/layout/a_login.xml | 29 +++++ app/src/main/res/layout/a_signup.xml | 29 +++++ .../main/res/layout/provider_credentials_login.xml | 36 ++++++ .../res/layout/provider_credentials_signup.xml | 24 ++++ app/src/main/res/layout/provider_header.xml | 17 +++ app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 5 + app/src/main/res/values/themes.xml | 8 +- .../leap/bitmaskclient/ProviderDetailActivity.java | 3 +- 20 files changed, 438 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/se/leap/bitmaskclient/ButterKnifeActivity.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/LoginActivity.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java create mode 100644 app/src/main/java/se/leap/bitmaskclient/SignupActivity.java create mode 100644 app/src/main/res/layout/a_login.xml create mode 100644 app/src/main/res/layout/a_signup.xml create mode 100644 app/src/main/res/layout/provider_credentials_login.xml create mode 100644 app/src/main/res/layout/provider_credentials_signup.xml create mode 100644 app/src/main/res/layout/provider_header.xml diff --git a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java index c97daea6..363a90fe 100644 --- a/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java +++ b/app/src/insecure/java/se/leap/bitmaskclient/ProviderDetailActivity.java @@ -1,6 +1,5 @@ package se.leap.bitmaskclient; -import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; @@ -17,10 +16,9 @@ import org.json.JSONObject; import java.util.ArrayList; -import butterknife.ButterKnife; import butterknife.InjectView; -public class ProviderDetailActivity extends Activity { +public class ProviderDetailActivity extends ButterKnifeActivity { final public static String TAG = "providerDetailActivity"; private SharedPreferences preferences; @@ -41,7 +39,6 @@ public class ProviderDetailActivity extends Activity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.provider_detail_fragment); - ButterKnife.inject(this); preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE); try { @@ -71,15 +68,18 @@ public class ProviderDetailActivity extends Activity { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { String text = ((TextView) view).getText().toString(); + Intent intent; if (text.equals(getString(R.string.login_button))) { Log.d(TAG, "login selected"); + intent = new Intent(getApplicationContext(), LoginActivity.class); } else if (text.equals(getString(R.string.signup_button))) { Log.d(TAG, "signup selected"); - } else if (text.equals(getString(R.string.use_anonymously_button))) { - Intent intent = new Intent(getApplicationContext(), MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); - startActivity(intent); + intent = new Intent(getApplicationContext(), SignupActivity.class); + } else { + intent = new Intent(getApplicationContext(), MainActivity.class); } + intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); } }); } catch (JSONException e) { @@ -108,7 +108,7 @@ public class ProviderDetailActivity extends Activity { @Override public void onBackPressed() { SharedPreferences.Editor editor = preferences.edit(); - editor.remove(Provider.KEY).remove(ProviderItem.DANGER_ON).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).apply(); + editor.remove(Provider.KEY).remove(ProviderListContent.ProviderItem.DANGER_ON).remove(Constants.PROVIDER_ALLOW_ANONYMOUS).remove(Constants.PROVIDER_KEY).apply(); super.onBackPressed(); } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8407d76d..14ac77ef 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,7 +38,7 @@ android:icon="@drawable/icon" android:label="@string/app_name" android:logo="@drawable/icon" - android:theme="@style/AppTheme"> + android:theme="@style/BitmaskTheme"> @@ -71,12 +71,12 @@ android:theme="@android:style/Theme.Translucent.NoTitleBar" /> + android:label="@string/vpn_launch_title" /> + android:uiOptions="splitActionBarWhenNarrow" /> + + + @@ -97,6 +102,10 @@ android:name=".ProviderDetailActivity" android:label="@string/provider_details_title" /> + + + @@ -111,10 +120,6 @@ - - \ No newline at end of file diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 601615b6..9253cfe6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -69,7 +69,7 @@ import static android.view.View.VISIBLE; * @author cyberta */ -public abstract class BaseConfigurationWizard extends AppCompatActivity +public abstract class BaseConfigurationWizard extends ButterKnifeActivity implements NewProviderDialog.NewProviderDialogInterface, DownloadFailedDialog.DownloadFailedDialogInterface, ProviderAPIResultReceiver.Receiver { @InjectView(R.id.progressbar_configuration_wizard) protected ProgressBar mProgressBar; @@ -166,7 +166,6 @@ public abstract class BaseConfigurationWizard extends AppCompatActivity private void setUpInitialUI() { setContentView(R.layout.configuration_wizard_activity); - ButterKnife.inject(this); hideProgressBar(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/ButterKnifeActivity.java b/app/src/main/java/se/leap/bitmaskclient/ButterKnifeActivity.java new file mode 100644 index 00000000..41164463 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/ButterKnifeActivity.java @@ -0,0 +1,30 @@ +package se.leap.bitmaskclient; + +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +import butterknife.ButterKnife; + +/** + * Automatically inject with ButterKnife after calling setContentView + */ + +public abstract class ButterKnifeActivity extends AppCompatActivity { + + @Override + public void setContentView(View view) { + super.setContentView(view); + ButterKnife.inject(this); + } + + @Override + public void setContentView(int layoutResID) { + super.setContentView(layoutResID); + ButterKnife.inject(this); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 8c33a6cd..b36c8cc2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -57,7 +57,7 @@ import static se.leap.bitmaskclient.Constants.REQUEST_CODE_SWITCH_PROVIDER; * @author Sean Leonard * @author parmegv */ -public class Dashboard extends AppCompatActivity { +public class Dashboard extends ButterKnifeActivity { public static final String TAG = Dashboard.class.getSimpleName(); @@ -280,7 +280,6 @@ public class Dashboard extends AppCompatActivity { // just to start services and destroy them afterwards private void buildDashboard(boolean hideAndTurnOnEipOnBoot) { setContentView(R.layout.dashboard); - ButterKnife.inject(this); provider_name.setText(provider.getDomain()); diff --git a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java new file mode 100644 index 00000000..1b36d807 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java @@ -0,0 +1,29 @@ +package se.leap.bitmaskclient; + +import android.os.Bundle; +import android.support.annotation.Nullable; + +import butterknife.OnClick; + +/** + * Created by fupduck on 09.01.18. + */ + +public class LoginActivity extends ProviderCredentialsBaseActivity { + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.a_login); + + setProviderHeaderText("providerNAME"); + setProviderHeaderLogo(R.drawable.mask); + } + + @Override + @OnClick(R.id.button) + void handleButton() { + login(getUsername(), getPassword()); + } + +} diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java new file mode 100644 index 00000000..c61b078f --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java @@ -0,0 +1,134 @@ +package se.leap.bitmaskclient; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; +import android.support.annotation.StringRes; +import android.support.design.widget.TextInputEditText; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import butterknife.InjectView; +import butterknife.OnClick; +import se.leap.bitmaskclient.userstatus.SessionDialog; +import se.leap.bitmaskclient.userstatus.User; + +/** + * Created by fupduck on 09.01.18. + */ + +public abstract class ProviderCredentialsBaseActivity extends ButterKnifeActivity { + + protected ProviderAPIResultReceiver providerAPIResultReceiver; + + @InjectView(R.id.provider_header_logo) + ImageView providerHeaderLogo; + + @InjectView(R.id.provider_header_text) + TextView providerHeaderText; + + @InjectView(R.id.provider_credentials_username) + TextInputEditText providerCredentialsUsername; + + @InjectView(R.id.provider_credentials_password) + TextInputEditText providerCredentialsPassword; + + @InjectView(R.id.button) + Button providerCredentialsButton; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + providerAPIResultReceiver = new ProviderAPIResultReceiver(new Handler(), new ProviderCredentialsReceiver(this)); + + } + + @OnClick(R.id.button) + abstract void handleButton(); + + protected void setProviderHeaderLogo(@DrawableRes int providerHeaderLogo) { + this.providerHeaderLogo.setImageResource(providerHeaderLogo); + } + + protected void setProviderHeaderText(String providerHeaderText) { + this.providerHeaderText.setText(providerHeaderText); + } + + protected void setProviderHeaderText(@StringRes int providerHeaderText) { + this.providerHeaderText.setText(providerHeaderText); + } + + protected void setButtonText(@StringRes int buttonText) { + providerCredentialsButton.setText(buttonText); + } + + String getUsername() { + return providerCredentialsUsername.getText().toString(); + } + + String getPassword() { + return providerCredentialsPassword.getText().toString(); + } + + void login(String username, String password) { + User.setUserName(username); + Bundle parameters = bundlePassword(password); + ProviderAPICommand.execute(parameters, ProviderAPI.LOG_IN, providerAPIResultReceiver); + } + + public void signUp(String username, String password) { + User.setUserName(username); + Bundle parameters = bundlePassword(password); + ProviderAPICommand.execute(parameters, ProviderAPI.SIGN_UP, providerAPIResultReceiver); + } + protected Bundle bundlePassword(String password) { + Bundle parameters = new Bundle(); + if (!password.isEmpty()) + parameters.putString(SessionDialog.PASSWORD, password); + return parameters; + } + + public static class ProviderCredentialsReceiver implements ProviderAPIResultReceiver.Receiver{ + + private ProviderCredentialsBaseActivity activity; + + ProviderCredentialsReceiver(ProviderCredentialsBaseActivity activity) { + this.activity = activity; + } + + @Override + public void onReceiveResult(int resultCode, Bundle resultData) { + if (resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) { + String username = resultData.getString(SessionDialog.USERNAME); + String password = resultData.getString(SessionDialog.PASSWORD); + activity.login(username, password); + } else if (resultCode == ProviderAPI.FAILED_SIGNUP) { + //MainActivity.sessionDialog(resultData); + } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { + Intent intent = new Intent(activity, MainActivity.class); + activity.startActivity(intent); + } else if (resultCode == ProviderAPI.FAILED_LOGIN) { + //MainActivity.sessionDialog(resultData); +// TODO MOVE +// } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { +// if (switching_provider) activity.switchProvider(); +// } else if (resultCode == ProviderAPI.LOGOUT_FAILED) { +// activity.setResult(RESULT_CANCELED); +// } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { +// activity.eip_fragment.updateEipService(); +// activity.setResult(RESULT_OK); +// } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { +// activity.setResult(RESULT_CANCELED); +// } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) { +// activity.eip_fragment.updateEipService(); +// activity.setResult(RESULT_OK); +// } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE) { +// activity.setResult(RESULT_CANCELED); + } + } + } + +} diff --git a/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java b/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java new file mode 100644 index 00000000..f6344065 --- /dev/null +++ b/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java @@ -0,0 +1,66 @@ +package se.leap.bitmaskclient; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.design.widget.TextInputEditText; +import android.support.design.widget.TextInputLayout; +import android.text.Editable; +import android.text.TextWatcher; + +import butterknife.InjectView; +import butterknife.OnClick; + +/** + * Create an account with a provider + */ + +public class SignupActivity extends ProviderCredentialsBaseActivity { + + @InjectView(R.id.provider_credentials_password_verification) + TextInputEditText providerCredentialsPasswordVerification; + + @InjectView(R.id.provider_credentials_password_verification_layout) + TextInputLayout providerCredentialsPasswordVerificationLayout; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.a_signup); + + setProviderHeaderText("providerNAME"); + setProviderHeaderLogo(R.drawable.mask); + + setButtonText(R.string.signup_button); + + providerCredentialsPasswordVerification.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + if(getPassword().equals(getPasswordVerification())) { + providerCredentialsPasswordVerificationLayout.setError(null); + } else { + providerCredentialsPasswordVerificationLayout.setError(getString(R.string.password_mismatch)); + } + } + }); + } + + @Override + @OnClick(R.id.button) + void handleButton() { + if (getPassword().equals(getPasswordVerification())) { + signUp(getUsername(), getPassword()); + } + } + + private String getPasswordVerification() { + return providerCredentialsPasswordVerification.getText().toString(); + } +} diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java index 1256c619..d86da957 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java @@ -51,7 +51,7 @@ public class SessionDialog extends DialogFragment { final public static String USERNAME = "username"; final public static String PASSWORD = "password"; - public static enum ERRORS { + public enum ERRORS { USERNAME_MISSING, PASSWORD_INVALID_LENGTH, RISEUP_WARNING @@ -156,9 +156,9 @@ public class SessionDialog extends DialogFragment { * @author parmegv */ public interface SessionDialogInterface { - public void logIn(String username, String password); + void logIn(String username, String password); - public void signUp(String username, String password); + void signUp(String username, String password); } diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java index a6439a16..07c102e4 100644 --- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java @@ -2,7 +2,6 @@ package se.leap.bitmaskclient.userstatus; import android.content.Context; import android.os.Bundle; -import android.os.Handler; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; @@ -18,7 +17,6 @@ import java.util.Observer; import butterknife.ButterKnife; import butterknife.InjectView; import butterknife.OnClick; -import se.leap.bitmaskclient.Dashboard; import se.leap.bitmaskclient.MainActivity; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.ProviderAPI; @@ -74,7 +72,6 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia @Override public void onAttach(Context activity) { super.onAttach(activity); - providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), Dashboard.dashboardReceiver); } public void restoreSessionStatus(Bundle savedInstanceState) { diff --git a/app/src/main/res/layout/a_login.xml b/app/src/main/res/layout/a_login.xml new file mode 100644 index 00000000..5ecb807c --- /dev/null +++ b/app/src/main/res/layout/a_login.xml @@ -0,0 +1,29 @@ + + + + + + + + + +