Skip to content

Commit

Permalink
VpnService: add partial_wake_lock
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Pashmfouroush <[email protected]>
  • Loading branch information
markpash committed May 18, 2024
1 parent 38c09a9 commit 6fce901
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/org/bepass/oblivion/OblivionVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.os.Message;
import android.os.Messenger;
import android.os.ParcelFileDescriptor;
import android.os.PowerManager;
import android.os.RemoteException;
import android.util.Log;

Expand Down Expand Up @@ -78,6 +79,7 @@ public void run() {
private ParcelFileDescriptor mInterface;
private String bindAddress;
private FileManager fileManager;
private static PowerManager.WakeLock wLock;
private ConnectionState lastKnownState = ConnectionState.DISCONNECTED;

public static synchronized void startVpnService(Context context) {
Expand Down Expand Up @@ -297,6 +299,11 @@ private void start() {
startForeground(1, notification, FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED);
}

if (wLock == null) {
wLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "oblivion:vpn");
wLock.setReferenceCounted(false);
}

executorService.execute(() -> {
bindAddress = getBindAddress();
Log.i(TAG, "Configuring VPN service");
Expand Down Expand Up @@ -368,6 +375,11 @@ public void onRevoke() {
e.printStackTrace();
}

if (wLock != null) {
wLock.release();
wLock = null;
}

if (mInterface != null) {
try {
mInterface.close();
Expand Down Expand Up @@ -407,7 +419,6 @@ private void setLastKnownState(ConnectionState lastKnownState) {
}

private String getNotificationText() {

boolean usePsiphon = fileManager.getBoolean("USERSETTING_psiphon");
boolean useWarp = fileManager.getBoolean("USERSETTING_gool");

Expand All @@ -417,7 +428,6 @@ private String getNotificationText() {
return "Warp in Warp";
}
return "Warp";

}

private void createNotification() {
Expand Down

0 comments on commit 6fce901

Please sign in to comment.