summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java13
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java45
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/LogWindowWrapper.java41
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java15
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java4
-rw-r--r--app/src/main/res/layout/eip_service_fragment.xml14
6 files changed, 70 insertions, 62 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index d5d06322..921bf95b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -285,8 +285,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
public void showLog() {
- Intent startLW = new Intent(getContext(), LogWindow.class);
- startActivity(startLW);
+ LogWindowWrapper log_window_wrapper = LogWindowWrapper.getInstance(getContext());
+ log_window_wrapper.showLog();
}
@Override
@@ -372,10 +372,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
protected void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) {
- if (eip_fragment != null && progressbar_message_resId != 0) {
- setStatusMessage(progressbar_message_resId);
- }
-
Intent command = prepareProviderAPICommand(parameters, providerApi_action);
startService(command);
}
@@ -449,11 +445,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
}
- private void setStatusMessage(int string_resId) {
- if (eip_fragment != null && eip_fragment.status_message != null)
- eip_fragment.status_message.setText(string_resId);
- }
-
public static Context getContext() {
return app;
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index bed61d24..c92ae3cd 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -20,7 +20,6 @@ import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
-import android.widget.*;
import org.jetbrains.annotations.*;
@@ -37,11 +36,9 @@ public class EipFragment extends Fragment implements Observer {
protected static final String IS_PENDING = TAG + ".is_pending";
protected static final String IS_CONNECTED = TAG + ".is_connected";
- protected static final String STATUS_MESSAGE = TAG + ".status_message";
public static final String START_ON_BOOT = "start on boot";
+ private static final String SHOWED_LOG = TAG + ".showed_log";
- @InjectView(R.id.status_message)
- TextView status_message;
@InjectView(R.id.vpn_Status_Image)
FabButton vpn_status_image;
@@ -83,8 +80,6 @@ public class EipFragment extends Fragment implements Observer {
eip_status.setConnecting();
else if (savedInstanceState.getBoolean(IS_CONNECTED))
eip_status.setConnectedOrDisconnected();
- else
- status_message.setText(savedInstanceState.getString(STATUS_MESSAGE));
}
@Override
@@ -98,7 +93,6 @@ public class EipFragment extends Fragment implements Observer {
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(IS_PENDING, eip_status.isConnecting());
outState.putBoolean(IS_CONNECTED, eip_status.isConnected());
- outState.putString(STATUS_MESSAGE, status_message.getText().toString());
super.onSaveInstanceState(outState);
}
@@ -109,6 +103,7 @@ public class EipFragment extends Fragment implements Observer {
@OnClick(R.id.vpn_Status_Image)
void handleIcon() {
+ LogWindowWrapper.getInstance(dashboard.getApplicationContext()).clearReason();
if (eip_status.isConnected() || eip_status.isConnecting())
handleSwitchOff();
else
@@ -174,8 +169,6 @@ public class EipFragment extends Fragment implements Observer {
public void startEipFromScratch() {
wants_to_connect = false;
eip_status.setConnecting();
- String status = dashboard.getString(R.string.eip_status_start_pending);
- status_message.setText(status);
saveStatus();
eipCommand(Constants.ACTION_START_EIP);
@@ -194,9 +187,6 @@ public class EipFragment extends Fragment implements Observer {
}
protected void stopEipIfPossible() {
- String message = dashboard.getString(R.string.eip_state_not_connected);
- status_message.setText(message);
-
eipCommand(Constants.ACTION_STOP_EIP);
}
@@ -251,29 +241,24 @@ public class EipFragment extends Fragment implements Observer {
}
private void handleNewState(EipStatus eip_status) {
- if (eip_status.wantsToDisconnect())
- setDisconnectedUI();
- else if (eip_status.isConnecting())
- setInProgressUI(eip_status);
- else if (eip_status.isConnected())
- setConnectedUI();
- else if (eip_status.isDisconnected() && !eip_status.isConnecting())
- setDisconnectedUI();
+ Context context = dashboard.getApplicationContext();
+ String error = eip_status.lastError(5, context);
+ LogWindowWrapper log_window = LogWindowWrapper.getInstance(context);
+
+ if (!error.isEmpty() && log_window != null && !log_window.reason().equalsIgnoreCase(error)) {
+ log_window.showLog();
+ log_window.showedBecauseOf(error);
+ VoidVpnService.stop();
+ }
+ adjustSwitch();
}
private void setConnectedUI() {
adjustSwitch();
- status_message.setText(dashboard.getString(R.string.eip_state_connected));
}
private void setDisconnectedUI() {
adjustSwitch();
- if (eip_status.errorInLast(5, dashboard.getApplicationContext())
- && !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))) {
- dashboard.showLog();
- VoidVpnService.stop();
- }
- status_message.setText(dashboard.getString(R.string.eip_state_not_connected));
}
private void adjustSwitch() {
@@ -292,16 +277,10 @@ public class EipFragment extends Fragment implements Observer {
}
private void setInProgressUI(EipStatus eip_status) {
- int localizedResId = eip_status.getLocalizedResId();
- String logmessage = eip_status.getLogMessage();
- String prefix = dashboard.getString(localizedResId);
-
- status_message.setText(prefix + " " + logmessage);
adjustSwitch();
}
private void updatingCertificateUI() {
- status_message.setText(getString(R.string.updating_certificate_message));
}
protected class EIPReceiver extends ResultReceiver {
diff --git a/app/src/main/java/se/leap/bitmaskclient/LogWindowWrapper.java b/app/src/main/java/se/leap/bitmaskclient/LogWindowWrapper.java
new file mode 100644
index 00000000..441eb28e
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/LogWindowWrapper.java
@@ -0,0 +1,41 @@
+package se.leap.bitmaskclient;
+
+import android.content.*;
+
+import de.blinkt.openvpn.activities.*;
+
+public class LogWindowWrapper {
+ private static LogWindowWrapper instance;
+
+ private static String TAG = LogWindowWrapper.class.getName();
+ private Context context;
+ private String reason = "";
+
+ public LogWindowWrapper(Context context) {
+ this.context = context;
+ }
+
+ public void showLog() {
+ Intent startLW = new Intent(context, LogWindow.class);
+ startLW.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(startLW);
+ }
+
+ public static LogWindowWrapper getInstance(Context context) {
+ if(instance == null)
+ instance = new LogWindowWrapper(context);
+ return instance;
+ }
+
+ public void clearReason() {
+ reason = "";
+ }
+
+ public void showedBecauseOf(String reason) {
+ this.reason = reason;
+ }
+
+ public String reason() {
+ return reason;
+ }
+}
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 b7f95277..356cf6b0 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
@@ -137,18 +137,25 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
}
public boolean errorInLast(int lines, Context context) {
- boolean result = false;
+ return !lastError(lines, context).isEmpty();
+ }
+
+ public String lastError(int lines, Context context) {
+ String error = "";
+
String[] error_keywords = {"error", "ERROR", "fatal", "FATAL"};
VpnStatus.LogItem[] log = VpnStatus.getlogbuffer();
String message = "";
for (int i = 1; i <= lines && log.length > i; i++) {
- message = log[log.length - i].getString(context);
+ VpnStatus.LogItem log_item = log[log.length - i];
+ message = log_item.getString(context);
for (int j = 0; j < error_keywords.length; j++)
if (message.contains(error_keywords[j]))
- result = true;
+ error = message;
}
- return result;
+
+ return error;
}
@Override
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 dac92fe2..cbf0fed2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -50,6 +50,10 @@ public class VoidVpnService extends VpnService {
closeFd();
}
+ public static boolean isRunning() throws NullPointerException {
+ return thread.isAlive() && fd != null;
+ }
+
private static void closeFd() {
try {
if (fd != null)
diff --git a/app/src/main/res/layout/eip_service_fragment.xml b/app/src/main/res/layout/eip_service_fragment.xml
index fea0093e..4ad8725d 100644
--- a/app/src/main/res/layout/eip_service_fragment.xml
+++ b/app/src/main/res/layout/eip_service_fragment.xml
@@ -15,20 +15,6 @@
android:text="@string/eip_service_label"
android:textAppearance="?android:attr/textAppearanceMedium" />
- <TextView
- android:id="@+id/status_message"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_below="@id/eipLabel"
- android:layout_centerVertical="true"
- android:paddingTop="5dp"
- android:paddingBottom="10dp"
- android:paddingLeft="10dp"
- android:paddingRight="10dp"
- android:clickable="true"
- android:text="@string/eip_state_not_connected" />
-
<view
android:id="@+id/vpn.Status.Image"
android:layout_width="@dimen/progress_button"