From 96b2f39c3c276034e23de82fe184fef149ac6160 Mon Sep 17 00:00:00 2001 From: "Denny C. Ng" Date: Tue, 14 Apr 2015 11:39:39 +0800 Subject: [PATCH] update spice service add screen records --- .../java/edu/tsinghua/spice/SpiceService.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/twidere/src/main/java/edu/tsinghua/spice/SpiceService.java b/twidere/src/main/java/edu/tsinghua/spice/SpiceService.java index 72e24056b..6c80e4422 100644 --- a/twidere/src/main/java/edu/tsinghua/spice/SpiceService.java +++ b/twidere/src/main/java/edu/tsinghua/spice/SpiceService.java @@ -3,9 +3,13 @@ package edu.tsinghua.spice; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.os.IBinder; +import edu.tsinghua.spice.Utilies.NetworkStateUtil; import edu.tsinghua.spice.Utilies.SpiceProfilingUtil; /** @@ -30,6 +34,12 @@ public class SpiceService extends Service { SpiceProfilingUtil.log(this, "onCreate"); mAlarmManager = (AlarmManager) getSystemService(Service.ALARM_SERVICE); + IntentFilter mScreenOnFilter = new IntentFilter("android.intent.action.SCREEN_ON"); + SpiceService.this.registerReceiver(mScreenOReceiver, mScreenOnFilter); + + IntentFilter mScreenOffFilter = new IntentFilter("android.intent.action.SCREEN_OFF"); + SpiceService.this.registerReceiver(mScreenOReceiver, mScreenOffFilter); + // Upload Service final Intent uploadIntent = new Intent(SpiceUploadReceiver.ACTION_UPLOAD_PROFILE); mUploadIntent = PendingIntent.getBroadcast(this, 0, uploadIntent, 0); @@ -42,4 +52,19 @@ public class SpiceService extends Service { super.onDestroy(); } + private BroadcastReceiver mScreenOReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals("android.intent.action.SCREEN_ON")) { + SpiceProfilingUtil.profile(context,SpiceProfilingUtil.FILE_NAME_SCREEN, "SCREEN ON" + "," + NetworkStateUtil.getConnectedType(context)); + SpiceProfilingUtil.log(context, "SCREEN ON" + "," + NetworkStateUtil.getConnectedType(context)); + } else if (action.equals("android.intent.action.SCREEN_OFF")) { + SpiceProfilingUtil.profile(context,SpiceProfilingUtil.FILE_NAME_SCREEN, "SCREEN OFF" + "," + NetworkStateUtil.getConnectedType(context)); + SpiceProfilingUtil.log(context, "SCREEN OFF" + "," + NetworkStateUtil.getConnectedType(context)); + } + } + + }; + }