mirror of
https://github.com/schwabe/ics-openvpn.git
synced 2024-09-19 19:42:29 +02:00
Avoid replacing ongoing notification with "building config.." notification
This commit is contained in:
parent
b4b37f1531
commit
a067d0f480
@ -13,6 +13,7 @@ import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INP
|
||||
import static de.blinkt.openvpn.core.NetworkSpace.IpAddress;
|
||||
|
||||
import android.Manifest.permission;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
@ -39,6 +40,7 @@ import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.system.OsConstants;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
@ -113,7 +115,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
|
||||
private Thread mProcessThread = null;
|
||||
private VpnProfile mProfile;
|
||||
|
||||
|
||||
private DeviceStateReceiver mDeviceStateReceiver;
|
||||
private boolean mDisplayBytecount = false;
|
||||
private boolean mStarting = false;
|
||||
@ -537,10 +538,13 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
|
||||
|
||||
// Always show notification here to avoid problem with startForeground timeout
|
||||
VpnStatus.logInfo(R.string.building_configration);
|
||||
VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START);
|
||||
showNotification(VpnStatus.getLastCleanLogMessage(this),
|
||||
VpnStatus.getLastCleanLogMessage(this), NOTIFICATION_CHANNEL_NEWSTATUS_ID, 0, ConnectionStatus.LEVEL_START, null);
|
||||
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M || (!foregroundNotificationVisible())) {
|
||||
|
||||
VpnStatus.updateStateString("VPN_GENERATE_CONFIG", "", R.string.building_configration, ConnectionStatus.LEVEL_START);
|
||||
showNotification(VpnStatus.getLastCleanLogMessage(this),
|
||||
VpnStatus.getLastCleanLogMessage(this), NOTIFICATION_CHANNEL_NEWSTATUS_ID, 0, ConnectionStatus.LEVEL_START, null);
|
||||
}
|
||||
|
||||
/* start the OpenVPN process itself in a background thread */
|
||||
mCommandHandler.post(() -> startOpenVPN(intent, startId));
|
||||
@ -548,6 +552,14 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
private boolean foregroundNotificationVisible() {
|
||||
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
StatusBarNotification[] notifications = mNotificationManager.getActiveNotifications();
|
||||
/* Assume for simplicity that all our notifications are foreground */
|
||||
return notifications.length > 0;
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||
private void updateShortCutUsage(VpnProfile profile) {
|
||||
if (profile == null)
|
||||
@ -652,7 +664,7 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
|
||||
if (mProfile != null && mProfile == vp && (intent == null || noReplaceRequested))
|
||||
{
|
||||
/* we do not want to replace the running VPN */
|
||||
VpnStatus.logInfo("VPN already running. Ignoring request to start VPN");
|
||||
VpnStatus.logInfo(R.string.ignore_vpn_start_request, mProfile.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -510,4 +510,5 @@
|
||||
<string name="proxy_auth_username">Username</string>
|
||||
<string name="permission_requested">Permission to start a VPN connection is required</string>
|
||||
<string name="missing_vpn_permission_log">VPN Service is missing permission to connect a VPN. Requesting permission via notification.</string>
|
||||
<string name="ignore_vpn_start_request">VPN already running (%s). Ignoring request to start VPN.</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user