android: add shortcuts
Fixes tailscale/tailscale#16415 Signed-off-by: Mahyar Mirrashed <mah.mirr@gmail.com>pull/677/head
parent
e5a704f785
commit
5b881e475f
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
package com.tailscale.ipn;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity to disable the Tailscale VPN via app shortcut.
|
||||||
|
* Sends a broadcast to IPNReceiver and finishes immediately.
|
||||||
|
*/
|
||||||
|
public class DisableVpnShortcutActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
Intent broadcastIntent = new Intent(IPNReceiver.INTENT_DISCONNECT_VPN);
|
||||||
|
broadcastIntent.setClass(this, IPNReceiver.class);
|
||||||
|
sendBroadcast(broadcastIntent);
|
||||||
|
|
||||||
|
finish(); // Close the activity immediately
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
package com.tailscale.ipn;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activity to enable the Tailscale VPN via app shortcut.
|
||||||
|
* Sends a broadcast to IPNReceiver and finishes immediately.
|
||||||
|
*/
|
||||||
|
public class EnableVpnShortcutActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
Intent broadcastIntent = new Intent(IPNReceiver.INTENT_CONNECT_VPN);
|
||||||
|
broadcastIntent.setClass(this, IPNReceiver.class);
|
||||||
|
sendBroadcast(broadcastIntent);
|
||||||
|
|
||||||
|
finish(); // Close the activity immediately
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<shortcut
|
||||||
|
android:shortcutId="enable_vpn"
|
||||||
|
android:enabled="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:shortcutShortLabel="@string/shortcut_enable_vpn_short"
|
||||||
|
android:shortcutLongLabel="@string/shortcut_enable_vpn_long">
|
||||||
|
<intent
|
||||||
|
android:action="android.intent.action.VIEW"
|
||||||
|
android:targetPackage="com.tailscale.ipn"
|
||||||
|
android:targetClass="com.tailscale.ipn.EnableVpnShortcutActivity" />
|
||||||
|
</shortcut>
|
||||||
|
<shortcut
|
||||||
|
android:shortcutId="disable_vpn"
|
||||||
|
android:enabled="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:shortcutShortLabel="@string/shortcut_disable_vpn_short"
|
||||||
|
android:shortcutLongLabel="@string/shortcut_disable_vpn_long">
|
||||||
|
<intent
|
||||||
|
android:action="android.intent.action.VIEW"
|
||||||
|
android:targetPackage="com.tailscale.ipn"
|
||||||
|
android:targetClass="com.tailscale.ipn.DisableVpnShortcutActivity" />
|
||||||
|
</shortcut>
|
||||||
|
</shortcuts>
|
||||||
Loading…
Reference in New Issue