-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ndroi
committed
Oct 1, 2020
1 parent
ceb2e1a
commit cd170c7
Showing
8 changed files
with
131 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Easy163/app/src/main/java/org/ndroi/easy163/ui/EasyTileService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,93 @@ | ||
package org.ndroi.easy163.ui; | ||
|
||
import android.content.ComponentName; | ||
import android.content.Intent; | ||
import android.net.VpnService; | ||
import android.os.IBinder; | ||
import android.service.quicksettings.Tile; | ||
import android.service.quicksettings.TileService; | ||
import android.util.Log; | ||
import org.ndroi.easy163.vpn.LocalVPNService; | ||
import androidx.localbroadcastmanager.content.LocalBroadcastManager; | ||
|
||
public class EasyTileService extends TileService | ||
{ | ||
@Override | ||
public void onStartListening() | ||
{ | ||
super.onStartListening(); | ||
Log.d("EasyTileService", "onStartListening"); | ||
Tile tile = getQsTile(); | ||
if (tile == null) | ||
{ | ||
return; | ||
} | ||
if(LocalVPNService.getIsRunning()) | ||
{ | ||
tile.setState(Tile.STATE_ACTIVE); | ||
tile.updateTile(); | ||
}else | ||
{ | ||
tile.setState(Tile.STATE_INACTIVE); | ||
tile.updateTile(); | ||
} | ||
} | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) | ||
{ | ||
TileService.requestListeningState(this, new ComponentName(this, EasyTileService.class)); | ||
return super.onBind(intent); | ||
} | ||
|
||
@Override | ||
public void onClick() | ||
{ | ||
super.onClick(); | ||
Tile tile = getQsTile(); | ||
if (tile == null) | ||
{ | ||
return; | ||
} | ||
switch (tile.getState()) | ||
{ | ||
case Tile.STATE_ACTIVE: | ||
{ | ||
stopVPN(); | ||
tile.setState(Tile.STATE_INACTIVE); | ||
tile.updateTile(); | ||
break; | ||
} | ||
case Tile.STATE_INACTIVE: | ||
{ | ||
startVPN(); | ||
tile.setState(Tile.STATE_ACTIVE); | ||
tile.updateTile(); | ||
break; | ||
} | ||
default:break; | ||
} | ||
} | ||
|
||
private void startVPN() | ||
{ | ||
if (VpnService.prepare(this) == null) | ||
{ | ||
Intent intent = new Intent(this, LocalVPNService.class); | ||
startService(intent); | ||
} else | ||
{ | ||
Intent intent = new Intent(this, MainActivity.class); | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
startActivityAndCollapse(intent); | ||
} | ||
} | ||
|
||
private void stopVPN() | ||
{ | ||
Intent intent = new Intent("control"); | ||
intent.putExtra("cmd", "stop"); | ||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent); | ||
Log.d("stopVPN", "try to stopVPN"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters