summaryrefslogtreecommitdiff
path: root/app/src/main/java/se
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2018-02-07 23:41:18 +0100
committercyBerta <cyberta@riseup.net>2018-02-07 23:41:18 +0100
commit4edff860bf3655db1ebdaa9f80265ff68dcb3c6a (patch)
tree75e775cd1ab6939067904d645ced6a6062771797 /app/src/main/java/se
parente33292227eeac35194f9217edd5a243c688cb560 (diff)
#8829 fixes notification handling after ui changes and fixes also memory leak #8838
Diffstat (limited to 'app/src/main/java/se')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java20
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/MainActivity.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/StartActivity.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java6
6 files changed, 41 insertions, 35 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index a4db5f84..78ec3fd2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -459,11 +459,11 @@ public class Dashboard extends ButterKnifeActivity {
String password = resultData.getString(SessionDialog.PASSWORD);
dashboard.user_status_fragment.logIn(username, password);
} else if (resultCode == ProviderAPI.FAILED_SIGNUP) {
- MainActivity.sessionDialog(resultData);
+ //MainActivity.sessionDialog(resultData);
} else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) {
Dashboard.downloadVpnCertificate();
} else if (resultCode == ProviderAPI.FAILED_LOGIN) {
- MainActivity.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/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 4027bc14..c0e2c21e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -53,6 +53,7 @@ import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
import se.leap.bitmaskclient.eip.VoidVpnService;
+import se.leap.bitmaskclient.userstatus.SessionDialog;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
@@ -73,10 +74,12 @@ import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
public class EipFragment extends Fragment implements Observer {
- public static String TAG = EipFragment.class.getSimpleName();
+ public final static String TAG = EipFragment.class.getSimpleName();
protected static final String IS_CONNECTED = TAG + ".is_connected";
public static final String START_EIP_ON_BOOT = "start on boot";
+ public static final String ASK_TO_CANCEL_VPN = "ask_to_cancel_vpn";
+
private SharedPreferences preferences;
@@ -121,6 +124,7 @@ public class EipFragment extends Fragment implements Observer {
};
+ @Override
public void onAttach(Context context) {
super.onAttach(context);
downloadEIPServiceConfig();
@@ -141,8 +145,12 @@ public class EipFragment extends Fragment implements Observer {
ButterKnife.inject(this, view);
Bundle arguments = getArguments();
- if (arguments != null && arguments.containsKey(START_EIP_ON_BOOT) && arguments.getBoolean(START_EIP_ON_BOOT)) {
- startEipFromScratch();
+ if (arguments != null) {
+ if (arguments.containsKey(START_EIP_ON_BOOT) && arguments.getBoolean(START_EIP_ON_BOOT)) {
+ startEipFromScratch();
+ } else if (arguments.containsKey(ASK_TO_CANCEL_VPN) && arguments.getBoolean(ASK_TO_CANCEL_VPN)) {
+ askToStopEIP();
+ }
}
return view;
}
@@ -205,8 +213,10 @@ public class EipFragment extends Fragment implements Observer {
startEipFromScratch();
else if (canLogInToStartEIP()) {
wantsToConnect = true;
- Bundle bundle = new Bundle();
- MainActivity.sessionDialog(bundle);
+ /*Bundle bundle = new Bundle();
+ seionDialogCallback.onSessionDialog(bundle);*/
+ Log.w(TAG, "TODO: implement login from here");
+ //FIXME: implement login from here
} else {
Log.d(TAG, "WHAT IS GOING ON HERE?!");
// TODO: implement a fallback: check if vpncertificate was not downloaded properly or give
diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
index 7629f0b7..186c2928 100644
--- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
@@ -15,12 +15,11 @@ import se.leap.bitmaskclient.userstatus.SessionDialog;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES;
+import static se.leap.bitmaskclient.EipFragment.ASK_TO_CANCEL_VPN;
public class MainActivity extends AppCompatActivity {
- private static Provider provider = new Provider();
- private static FragmentManagerEnhanced fragmentManager;
private SharedPreferences preferences;
public final static String ACTION_SHOW_VPN_FRAGMENT = "action_show_vpn_fragment";
@@ -40,7 +39,6 @@ public class MainActivity extends AppCompatActivity {
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
- fragmentManager = new FragmentManagerEnhanced(getSupportFragmentManager());
// Set up the drawer.
navigationDrawerFragment.setUp(
R.id.navigation_drawer,
@@ -49,15 +47,6 @@ public class MainActivity extends AppCompatActivity {
handleIntentAction(getIntent());
}
- 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();
- }
- }
-
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@@ -71,17 +60,21 @@ public class MainActivity extends AppCompatActivity {
}
Fragment fragment = null;
-
switch (intent.getAction()) {
case ACTION_SHOW_VPN_FRAGMENT:
fragment = new EipFragment();
+ if (intent.hasExtra(ASK_TO_CANCEL_VPN)) {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(ASK_TO_CANCEL_VPN, true);
+ fragment.setArguments(bundle);
+ }
break;
default:
break;
}
if (fragment != null) {
- fragmentManager.beginTransaction()
+ new FragmentManagerEnhanced(getSupportFragmentManager()).beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
@@ -100,5 +93,4 @@ public class MainActivity extends AppCompatActivity {
}
}
}
-
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
index f5991538..2d107c27 100644
--- a/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/StartActivity.java
@@ -15,6 +15,7 @@ import java.lang.annotation.RetentionPolicy;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.userstatus.User;
+import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static se.leap.bitmaskclient.Constants.APP_ACTION_CONFIGURE_ALWAYS_ON_PROFILE;
import static se.leap.bitmaskclient.Constants.PREFERENCES_APP_VERSION;
import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP;
@@ -187,6 +188,7 @@ public class StartActivity extends Activity {
private void showMainActivity() {
Intent intent = new Intent(this, MainActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(MainActivity.ACTION_SHOW_VPN_FRAGMENT);
startActivity(intent);
finish();
diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java b/app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java
index 5b089524..459f337b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/VpnNotificationManager.java
@@ -44,6 +44,8 @@ import static android.text.TextUtils.isEmpty;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_NONETWORK;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT;
import static se.leap.bitmaskclient.Constants.EIP_ACTION_STOP_BLOCKING_VPN;
+import static se.leap.bitmaskclient.EipFragment.ASK_TO_CANCEL_VPN;
+import static se.leap.bitmaskclient.MainActivity.ACTION_SHOW_VPN_FRAGMENT;
/**
* Created by cyberta on 14.01.18.
@@ -86,7 +88,7 @@ public class VpnNotificationManager {
VoidVpnService.NOTIFICATION_CHANNEL_NEWSTATUS_ID,
PRIORITY_MAX,
0,
- getDashboardIntent(),
+ getMainActivityIntent(),
actionBuilder.build());
}
@@ -122,7 +124,7 @@ public class VpnNotificationManager {
if (status == LEVEL_WAITING_FOR_USER_INPUT)
contentIntent = getUserInputIntent(msg);
else
- contentIntent = getDashboardIntent();
+ contentIntent = getMainActivityIntent();
int priority;
if (OpenVPNService.NOTIFICATION_CHANNEL_NEWSTATUS_ID.equals(notificationChannelNewstatusId)) {
@@ -254,11 +256,9 @@ public class VpnNotificationManager {
lastNotificationChannel = notificationChannelNewstatusId;
}
- private PendingIntent getDashboardIntent() {
- Intent startDashboard = new Intent(context, Dashboard.class);
- startDashboard.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
- Intent.FLAG_ACTIVITY_SINGLE_TOP);
- return PendingIntent.getActivity(context, 0, startDashboard, PendingIntent.FLAG_CANCEL_CURRENT);
+ private PendingIntent getMainActivityIntent() {
+ Intent startActivity = new Intent(context, StartActivity.class);
+ return PendingIntent.getActivity(context, 0, startActivity, PendingIntent.FLAG_CANCEL_CURRENT);
}
private PendingIntent getStopVoidVpnIntent() {
@@ -268,10 +268,10 @@ public class VpnNotificationManager {
}
private PendingIntent getDisconnectIntent() {
- Intent disconnectVPN = new Intent(context, Dashboard.class);
- disconnectVPN.setAction(Intent.ACTION_MAIN); //needs to be set that actual action can get triggered
- disconnectVPN.putExtra(Dashboard.ACTION_ASK_TO_CANCEL_VPN, true);
- disconnectVPN.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+ Intent disconnectVPN = new Intent(context, MainActivity.class);
+ disconnectVPN.setAction(ACTION_SHOW_VPN_FRAGMENT);
+ disconnectVPN.putExtra(ASK_TO_CANCEL_VPN, true);
+ disconnectVPN.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
return PendingIntent.getActivity(context, 0, disconnectVPN, PendingIntent.FLAG_CANCEL_CURRENT);
}
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 0f1d0cdb..4b8ce55d 100644
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
@@ -3,6 +3,7 @@ package se.leap.bitmaskclient.userstatus;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -26,7 +27,7 @@ import se.leap.bitmaskclient.R;
public class UserStatusFragment extends Fragment implements Observer, SessionDialog.SessionDialogInterface {
- public static String TAG = UserStatusFragment.class.getSimpleName();
+ public final static String TAG = UserStatusFragment.class.getSimpleName();
private ProviderAPIResultReceiver providerAPI_result_receiver;
@InjectView(R.id.user_status_username)
@@ -88,7 +89,8 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia
if(status.isLoggedIn())
logOut();
else if(status.isLoggedOut())
- MainActivity.sessionDialog(Bundle.EMPTY);
+ Log.w(TAG, "implement login from here?");
+ //MainActivity.sessionDialog(Bundle.EMPTY);
else if(status.inProgress())
cancelLoginOrSignup();
}