Skip to content

Commit

Permalink
Merge pull request #1 from beeguy1234/master
Browse files Browse the repository at this point in the history
tasker intent support
  • Loading branch information
jayy-ahn authored Nov 1, 2023
2 parents 890243f + a438855 commit f7ccdc3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<receiver android:name=".IntentBroadcastReceiver" android:exported="true">
<intent-filter>
<action android:name="app.intent.action.RESUME"/>
<action android:name="app.intent.action.START"/>
<action android:name="app.intent.action.STOP"/>
<action android:name="app.intent.action.PAUSE"/>
</intent-filter>
</receiver>
</application>

</manifest>
</manifest>
45 changes: 45 additions & 0 deletions app/src/main/java/org/jak_linux/dns66/IntentBroadcastReceiver
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.jak_linux.dns66;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.VpnService;
import android.os.Build;
import org.jak_linux.dns66.vpn.AdVpnService;
import org.jak_linux.dns66.vpn.Command;

public class IntentBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent receivedintent) {
int command = -1 ;
switch (receivedintent.getAction()){
case "app.intent.action.RESUME" :
command=Command.RESUME.ordinal();
break;
case "app.intent.action.START" :
Intent startintent = VpnService.prepare(context);
if (startintent != null) {
context.startActivity(startintent);
}
command=Command.START.ordinal();
break;
case "app.intent.action.STOP" :
command=Command.STOP.ordinal();
break;
case "app.intent.action.PAUSE" :
command=Command.PAUSE.ordinal();
break;
}
if (command!=-1) {
Intent intent = new Intent(context, AdVpnService.class);
intent.putExtra("COMMAND", command);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
}
else {
context.startService(intent);
}
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/org/jak_linux/dns66/vpn/AdVpnService.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ public void handleMessage(Message msg) {
@Override
public void run(int value) {
handler.sendMessage(handler.obtainMessage(VPN_MSG_STATUS_UPDATE, value, 0));
if (value==VPN_STATUS_RUNNING) {
Intent intent = new Intent();
intent.setAction("net.dinglish.android.tasker.DNS66_STATUS");
intent.putExtra("status","running");
sendBroadcast(intent);
}
else if (value==VPN_STATUS_STOPPED) {
Intent intent = new Intent();
intent.setAction("net.dinglish.android.tasker.DNS66_STATUS");
intent.putExtra("status","stopped");
sendBroadcast(intent);
}
}
});
private final BroadcastReceiver connectivityChangedReceiver = new BroadcastReceiver() {
Expand Down

0 comments on commit f7ccdc3

Please sign in to comment.