update spice service

add screen records
This commit is contained in:
Denny C. Ng 2015-04-14 11:39:39 +08:00
parent 668e59f4f2
commit 96b2f39c3c
1 changed files with 25 additions and 0 deletions

View File

@ -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));
}
}
};
}