Skip to content

Commit a6e8772

Browse files
author
Oleksandr Mykhailenko
committed
[GAA-48] fixed notifications not being removed after logout
1 parent 566b7c7 commit a6e8772

6 files changed

Lines changed: 21 additions & 18 deletions

File tree

app/src/main/java/net/ivpn/client/common/session/SessionController.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class SessionController @Inject constructor(
157157
}
158158
if ((it.status == Responses.SESSION_NOT_FOUND)) {
159159
clearData()
160-
ViewModelCleaner()
161160
}
162161
}
163162
onUpdateError(null, errorResponse)

app/src/main/java/net/ivpn/client/common/utils/ComponentUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
along with the IVPN Android app. If not, see <https://www.gnu.org/licenses/>.
2323
*/
2424

25+
import android.app.NotificationManager;
2526
import android.content.Context;
2627
import android.util.Log;
2728

2829
import androidx.appcompat.app.AppCompatDelegate;
30+
import androidx.core.app.NotificationManagerCompat;
2931

3032
import net.ivpn.client.BuildConfig;
3133
import net.ivpn.client.IVPNApplication;
@@ -97,11 +99,13 @@ public void performBaseComponentsInit() {
9799
}
98100

99101
public void resetComponents() {
102+
networkController.finishAll();
100103
preference.removeAll();
101104
globalBehaviorController.finishAll();
102-
networkController.finishAll();
103105
updatesJobServiceUtil.clearUpdateJob(IVPNApplication.getApplication());
104106
updateHelper.skipUpdate();
107+
108+
NotificationManagerCompat.from(IVPNApplication.getApplication()).cancelAll();
105109
}
106110

107111
private void initProfile() {

app/src/main/java/net/ivpn/client/v2/killswitch/KillSwitchFragment.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ class KillSwitchFragment : Fragment(), KillSwitchViewModel.KillSwitchNavigator {
9090
}
9191
}
9292

93-
override fun onPause() {
94-
super.onPause()
95-
killSwitch.navigator = null
96-
}
93+
// override fun onPause() {
94+
// super.onPause()
95+
// killSwitch.navigator = null
96+
// }
9797

9898
private fun initToolbar() {
9999
val navController = findNavController()

app/src/main/java/net/ivpn/client/v2/network/NetworkViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ class NetworkViewModel @Inject internal constructor(
218218
}
219219

220220
override fun onNetworkSourceChanged(source: NetworkSource?) {
221-
Log.d("NetworkController", "onNetworkSourceChanged: source = $source")
221+
LOGGER.info("onNetworkSourceChanged: source = $source")
222222
if (source == null) {
223223
return
224224
}
225225
if (source == NetworkSource.WIFI) {
226-
Log.d("NetworkController", "onNetworkSourceChanged: ssid = " + source.ssid)
226+
LOGGER.info("NetworkController", "onNetworkSourceChanged: ssid = " + source.ssid)
227227
}
228228
networkSource.set(source)
229229
networkState.set(source.finalState)

app/src/main/java/net/ivpn/client/vpn/local/KillSwitchService.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
*/
2424

2525
import android.app.Notification;
26-
import android.app.NotificationManager;
2726
import android.app.PendingIntent;
28-
import android.content.Context;
2927
import android.content.Intent;
3028
import android.content.pm.PackageManager;
3129
import android.net.VpnService;
3230
import android.os.Build;
3331
import android.os.ParcelFileDescriptor;
32+
3433
import androidx.core.app.NotificationCompat;
34+
import androidx.core.app.NotificationManagerCompat;
3535
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
3636

3737
import net.ivpn.client.R;
@@ -51,7 +51,7 @@ public class KillSwitchService extends VpnService implements ServiceConstants {
5151
public static AtomicBoolean isRunning = new AtomicBoolean(false);
5252

5353
private ParcelFileDescriptor tun;
54-
private NotificationManager notificationManager;
54+
private NotificationManagerCompat notificationManager;
5555

5656
private int notificationId;
5757

@@ -65,7 +65,7 @@ public void onRevoke() {
6565
public void onCreate() {
6666
LOGGER.info("onCreate");
6767
super.onCreate();
68-
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
68+
notificationManager = NotificationManagerCompat.from(this);
6969
notificationId = ServiceConstants.KILL_SWITCH_CHANNEL.hashCode();
7070
}
7171

@@ -114,13 +114,12 @@ private int startKillSwitch() {
114114

115115
private int endService() {
116116
LOGGER.info("endService");
117-
notificationManager.cancelAll();
117+
notificationManager.cancel(notificationId);
118118
closeTun();
119119
stopForeground(true);
120120
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
121121
stopSelf(STOP_FOREGROUND_REMOVE);
122122
} else {
123-
notificationManager.cancel(notificationId);
124123
stopSelf();
125124
}
126125
return START_NOT_STICKY;

app/src/main/java/net/ivpn/client/vpn/local/WifiWatcherService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
import android.app.Notification;
26-
import android.app.NotificationManager;
2726
import android.app.PendingIntent;
2827
import android.app.Service;
2928
import android.content.BroadcastReceiver;
@@ -36,6 +35,7 @@
3635

3736
import androidx.annotation.Nullable;
3837
import androidx.core.app.NotificationCompat;
38+
import androidx.core.app.NotificationManagerCompat;
3939
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
4040

4141
import net.ivpn.client.IVPNApplication;
@@ -57,7 +57,7 @@ public class WifiWatcherService extends Service implements ServiceConstants {
5757
public static AtomicBoolean isRunning = new AtomicBoolean(false);
5858

5959
private WifiBroadcastReceiver receiver;
60-
private NotificationManager notificationManager;
60+
private NotificationManagerCompat notificationManager;
6161

6262
private int notificationId;
6363

@@ -74,7 +74,7 @@ public IBinder onBind(Intent intent) {
7474
public void onCreate() {
7575
LOGGER.info("onCreate");
7676
super.onCreate();
77-
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
77+
notificationManager = NotificationManagerCompat.from(this);
7878
notificationId = ServiceConstants.WIFI_WATCHER_CHANNEL.hashCode();
7979
}
8080

@@ -117,10 +117,11 @@ public void onDestroy() {
117117
private int endService() {
118118
LOGGER.info("endService");
119119
stopForeground(true);
120+
notificationManager.cancel(notificationId);
120121
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
121122
stopSelf(STOP_FOREGROUND_REMOVE);
122123
} else {
123-
notificationManager.cancel(notificationId);
124+
// notificationManager.cancel(notificationId);
124125
stopSelf();
125126
}
126127
return START_NOT_STICKY;

0 commit comments

Comments
 (0)