From 8a53bf0c88498059751693695775788874714fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 10 Mar 2015 11:44:00 +0100 Subject: Point to the log if an error occurrs while connecting --- app/src/main/java/se/leap/bitmaskclient/EipFragment.java | 6 +++++- app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java | 12 +++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 588b137b..3023442a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -262,7 +262,11 @@ public class EipFragment extends Fragment implements Observer { private void setDisconnectedUI(){ hideProgressBar(); adjustSwitch(); - status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); + String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); + if(last_log_message.contains("error") || last_log_message.contains("ERROR")) + status_message.setText("An error occurred." + "\n" + "Please take a look at the log, from the menu"); + else + status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java index c6735130..14158696 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -16,11 +16,12 @@ */ package se.leap.bitmaskclient.eip; -import android.util.Log; +import android.util.*; +import android.content.*; -import java.util.Observable; +import java.util.*; -import de.blinkt.openvpn.core.VpnStatus; +import de.blinkt.openvpn.core.*; public class EipStatus extends Observable implements VpnStatus.StateListener { public static String TAG = EipStatus.class.getSimpleName(); @@ -135,6 +136,11 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { EipStatus.level = level; } + public String getLastLogMessage(Context context) { + VpnStatus.LogItem[] log = VpnStatus.getlogbuffer(); + return log[log.length-1].getString(context); + } + @Override public String toString() { return "State: " + state + " Level: " + level.toString(); -- cgit v1.2.3 From 9732f263b3ea9af0c9610fa9b3f3010481a39e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 12 Mar 2015 11:47:28 +0100 Subject: Just show the log if an error occurred. --- .../main/java/se/leap/bitmaskclient/Dashboard.java | 19 ++++-- .../java/se/leap/bitmaskclient/EipFragment.java | 77 ++++++++++++---------- 2 files changed, 54 insertions(+), 42 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 4fe51939..04385ddd 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -249,16 +249,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn @Override public boolean onOptionsItemSelected(MenuItem item){ - Intent intent; switch (item.getItemId()){ case R.id.about_leap: - intent = new Intent(this, AboutActivity.class); - startActivity(intent); + showAbout(); return true; case R.id.log_window: - Intent startLW = new Intent(getAppContext(), LogWindow.class); - startLW.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - startActivity(startLW); + showLog(); return true; case R.id.switch_provider: switching_provider = true; @@ -279,6 +275,17 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn } } + public void showAbout() { + Intent intent = new Intent(this, AboutActivity.class); + startActivity(intent); + } + + public void showLog() { + Intent startLW = new Intent(getAppContext(), LogWindow.class); + //startLW.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(startLW); + } + @Override public void signUp(String username, String password) { Bundle parameters = bundleParameters(username, password); diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index 3023442a..680f21e1 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -1,32 +1,33 @@ +/** + * 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; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Fragment; -import android.content.DialogInterface; -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import android.os.ResultReceiver; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ProgressBar; -import android.widget.Switch; -import android.widget.TextView; - -import java.util.Observable; -import java.util.Observer; - -import butterknife.ButterKnife; -import butterknife.InjectView; -import butterknife.OnCheckedChanged; -import de.blinkt.openvpn.activities.DisconnectVPN; -import se.leap.bitmaskclient.eip.Constants; -import se.leap.bitmaskclient.eip.EIP; -import se.leap.bitmaskclient.eip.EipStatus; -import se.leap.bitmaskclient.eip.VoidVpnService; +import android.app.*; +import android.content.*; +import android.os.*; +import android.util.*; +import android.view.*; +import android.widget.*; + +import java.util.*; + +import butterknife.*; +import de.blinkt.openvpn.activities.*; +import se.leap.bitmaskclient.eip.*; public class EipFragment extends Fragment implements Observer { @@ -193,6 +194,10 @@ public class EipFragment extends Fragment implements Observer { private void stopEIP() { if(eip_status.isConnecting()) VoidVpnService.stop(); + disconnect(); + } + + private void disconnect() { Intent disconnect_vpn = new Intent(dashboard, DisconnectVPN.class); dashboard.startActivityForResult(disconnect_vpn, EIP.DISCONNECT); eip_status.setDisconnecting(); @@ -201,8 +206,8 @@ public class EipFragment extends Fragment implements Observer { protected void askToStopEIP() { hideProgressBar(); - String status = dashboard.getString(R.string.eip_state_not_connected); - status_message.setText(status); + String message = dashboard.getString(R.string.eip_state_not_connected); + status_message.setText(message); eipCommand(Constants.ACTION_STOP_EIP); } @@ -240,11 +245,10 @@ public class EipFragment extends Fragment implements Observer { } private void handleNewState(EipStatus eip_status) { - Log.d(TAG, "handleNewState: " + eip_status.toString()); if(eip_status.wantsToDisconnect()) setDisconnectedUI(); - else if(eip_status.isConnecting() || is_starting_to_connect) - setInProgressUI(eip_status); + else if(eip_status.isConnecting() || is_starting_to_connect) + setInProgressUI(eip_status); else if (eip_status.isConnected()) setConnectedUI(); else if (eip_status.isDisconnected() && !eip_status.isConnecting()) @@ -263,10 +267,11 @@ public class EipFragment extends Fragment implements Observer { hideProgressBar(); adjustSwitch(); String last_log_message = eip_status.getLastLogMessage(dashboard.getApplicationContext()); - if(last_log_message.contains("error") || last_log_message.contains("ERROR")) - status_message.setText("An error occurred." + "\n" + "Please take a look at the log, from the menu"); - else - status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); + if((last_log_message.contains("error") || last_log_message.contains("ERROR")) + && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){ + dashboard.showLog(); + } + status_message.setText(dashboard.getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { -- cgit v1.2.3