2011-03-25 06:43:04 -04:00
|
|
|
package hu.blint.ssldroid;
|
|
|
|
|
2011-10-19 05:44:43 -04:00
|
|
|
import hu.blint.ssldroid.db.SSLDroidDbAdapter;
|
2011-03-25 06:43:04 -04:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
2011-10-19 05:44:43 -04:00
|
|
|
import android.database.Cursor;
|
|
|
|
import android.util.Log;
|
2011-03-25 06:43:04 -04:00
|
|
|
|
2011-04-12 11:06:00 -04:00
|
|
|
public class BootStartupReceiver extends BroadcastReceiver {
|
2011-10-19 05:44:43 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-05-04 15:31:26 -04:00
|
|
|
@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");
|
2011-10-19 05:44:43 -04:00
|
|
|
if (!isStopped(context))
|
|
|
|
context.startService(i);
|
|
|
|
else
|
|
|
|
Log.w("SSLDroid", "Not starting service as directed by explicit stop");
|
2011-05-04 15:31:26 -04:00
|
|
|
}
|
|
|
|
}
|
2011-03-25 06:43:04 -04:00
|
|
|
}
|