Skip to content

Commit

Permalink
Allow start/stop tinc by external intent. Bump version to 0.9.9.
Browse files Browse the repository at this point in the history
Fixes #17.
  • Loading branch information
Vilbrekin committed Sep 9, 2014
1 parent a36f5a9 commit 3664313
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
14 changes: 10 additions & 4 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="org.poirsouille.tinc_gui"
android:versionCode="9"
android:versionName="0.9.8" >
android:versionCode="10"
android:versionName="0.9.9" >

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
Expand All @@ -22,7 +22,13 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".TincdService"></service>
<service android:name=".TincdService" android:exported="true" tools:ignore="ExportedService" >
<!-- Export START and STOP actions to allow interactions with apps such as Tasker -->
<intent-filter>
<action android:name="org.poirsouille.tinc_gui.TincdService.START"></action>
<action android:name="org.poirsouille.tinc_gui.TincdService.STOP"></action>
</intent-filter>
</service>
<activity android:name=".SettingsActivity"></activity>
<activity android:name=".SettingsActivityOld"></activity>
<activity android:name=".AboutActivity"></activity>
Expand Down
2 changes: 1 addition & 1 deletion src/org/poirsouille/tinc_gui/BootReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void onReceive(Context iContext, Intent iIntent)
{
Log.i(Tools.TAG, "Autostarting Tinc GUI service");
// Start tincd service
Intent intent = new Intent(iContext, TincdService.class);
Intent intent = new Intent(iContext, TincdService.class).setAction("org.poirsouille.tinc_gui.TincdService.START");
iContext.startService(intent);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/poirsouille/tinc_gui/TincActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void onClick(DialogInterface dialog, int id)
else
{
// Start tincd service
Intent intent = new Intent(this,TincdService.class);
Intent intent = new Intent(this,TincdService.class).setAction("org.poirsouille.tinc_gui.TincdService.START");
startService(intent);
}
}
Expand Down
29 changes: 24 additions & 5 deletions src/org/poirsouille/tinc_gui/TincdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import android.os.Binder;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.sax.StartElementListener;
import android.util.Log;

public class TincdService extends Service implements ICallback
Expand Down Expand Up @@ -357,16 +358,34 @@ public void toggleDebug()
_debug = !_debug;
}

/**
* Handle intent on startService call. Defines START & STOP actions to allow external applications to drive service.
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId)
public int onStartCommand(Intent iIntent, int flags, int startId)
{
// Because of the START_STICKY, the service might get restarted by the system after a kill, but with a null intent
if (intent != null)
if (iIntent != null)
{
startTinc();
Log.d(Tools.TAG, "Service started");
showNotification();
if (iIntent.getAction() == "org.poirsouille.tinc_gui.TincdService.START")
{
Log.i(Tools.TAG, "Received START intent for tincd service");
startTinc();
Log.d(Tools.TAG, "Service started");
showNotification();
}
else if (iIntent.getAction() == "org.poirsouille.tinc_gui.TincdService.STOP")
{
Log.i(Tools.TAG, "Received STOP intent for tincd service");
stopTincd();
}
else
{
Log.e(Tools.TAG, "Unkown intent action: " + iIntent.getAction());
return START_NOT_STICKY;
}
}

// We want this service to continue running until it is explicitly
// stopped, so return sticky.
return START_STICKY;
Expand Down

0 comments on commit 3664313

Please sign in to comment.