package com.lyonbros.securecache;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.util.Log;
import android.os.IBinder;
import android.R;

public class SecureCacheService extends Service
{
	public static final String CACHE_PERMISSION = "com.lyonbros.securecache.ACCESS_SECRETS";
	public static final String RECEIVE_CACHE = "com.lyonbros.securecache.RECEIVE_CACHE";
	private static final String TAG = "SecureCache";
	private static final int ONGOING_NOTIFICATION_ID = 1;
	private String cache;

	@Override
	public IBinder onBind(Intent intent)
	{
		return null;
	}

	@Override
	public void onCreate()
	{
		super.onCreate();
		Log.i(TAG, "SecureCacheService: created");
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startid)
	{
		if(intent == null) {
			return START_STICKY;
		}
		String action = intent.getStringExtra("action");
		if(action == null) {
			return START_STICKY;
		}
		Log.i(TAG, "SecureCacheService: action: "+action);
		if(action.equals("start")) {
			// hey, girl heyy
			respond("true");
		} else if(action.equals("set")) {
			String data = intent.getStringExtra("data");
			cache = data;
			respond("true");
		} else if(action.equals("wipe")) {
			cache = null;
			respond("true");
		} else if(action.equals("get")) {
			respond(cache);
		} else if(action.equals("stop")) {
			stopSelf();
			respond("true");
		}
		return START_STICKY;
	}

	@Override
	public void onDestroy()
	{
		super.onDestroy();
		Log.i(TAG, "SecureCacheService: destroyed");
	}

	private void respond(String msg)
	{
		Intent intent = new Intent(RECEIVE_CACHE);
		intent.putExtra("data", cache);
		intent.setPackage(getApplicationContext().getPackageName());
		sendBroadcast(intent, CACHE_PERMISSION);
	}
}


@@ -723,36 +723,16 @@
 i(TAG, %22
-SecureCacheService: 
 created%22
@@ -730,24 +730,24 @@
 %22created%22);%0A
+
 %09%7D%0A%0A%09@Overri
@@ -985,36 +985,16 @@
 i(TAG, %22
-SecureCacheService: 
 action: 
@@ -1056,16 +1056,40 @@
 rl heyy%0A
+%09%09%09Log.i(TAG, %22start%22);%0A
 %09%09%09respo
@@ -1184,16 +1184,62 @@
 data%22);%0A
+%09%09%09Log.i(TAG, %22set: %22+(data %7C%7C %22%22).length());%0A
 %09%09%09cache
@@ -1304,16 +1304,39 @@
 pe%22)) %7B%0A
+%09%09%09Log.i(TAG, %22wipe%22);%0A
 %09%09%09cache
@@ -1396,24 +1396,71 @@
 s(%22get%22)) %7B%0A
+%09%09%09Log.i(TAG, %22get: %22+(cache %7C%7C %22%22).length());%0A
 %09%09%09respond(c
@@ -1503,16 +1503,39 @@
 op%22)) %7B%0A
+%09%09%09Log.i(TAG, %22stop%22);%0A
 %09%09%09stopS
@@ -1648,24 +1648,24 @@
 nDestroy();%0A
+
 %09%09Log.i(TAG,
@@ -1670,28 +1670,8 @@
 G, %22
-SecureCacheService: 
 dest

update logging