1
0
mirror of https://github.com/moparisthebest/SSLDroid synced 2024-11-23 09:22:16 -05:00
SSLDroid/src/hu/blint/ssldroid/BootStartupReceiver.java
Balint Kovacs 8e3cd92b69 Implemented explicit stop feature - stops the service until it is
started manually

Signed-off-by: Balint Kovacs <blint@blint.hu>
2011-10-19 11:44:43 +02:00

44 lines
1.3 KiB
Java

package hu.blint.ssldroid;
import hu.blint.ssldroid.db.SSLDroidDbAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;
public class BootStartupReceiver extends BroadcastReceiver {
private boolean isStopped(Context context){
Boolean stopped = false;
SSLDroidDbAdapter dbHelper;
dbHelper = new SSLDroidDbAdapter(context);
dbHelper.open();
Cursor cursor = dbHelper.getStopStatus();
int tunnelcount = cursor.getCount();
Log.d("SSLDroid", "Tunnelcount: "+tunnelcount);
//don't start if the stop status field is available
if (tunnelcount != 0){
stopped = true;
}
cursor.close();
dbHelper.close();
return stopped;
}
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent();
i.setAction("hu.blint.ssldroid.SSLDroid");
if (!isStopped(context))
context.startService(i);
else
Log.w("SSLDroid", "Not starting service as directed by explicit stop");
}
}
}