Commit 46228fda authored by Roberta De Viti's avatar Roberta De Viti

test: null wakelock, fix service in manifest

parent 1aae0391
......@@ -38,7 +38,11 @@
<activity android:name="org.mpisws.testapp.googleauth.GoogleAuthActivity"/>
<receiver android:process=":remote" android:name=".Alarm"></receiver>
<receiver android:process=":remote" android:name=".simulator.Alarm"></receiver>
<service
android:name=".simulator.NullWakelock"
android:enabled="true" >
</service>
</application>
......
......@@ -97,8 +97,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
/***************************** ES AND SDDR TESTS **********************/
case R.id.nullWakelock:
//if (!isSignedIn()) throw new SecurityException("Not signed in");
startService(new Intent(MainActivity.this, NullWakelock.class));
Log.d(TAG, "Starting null wakelock test!");
new Alarm().setAlarm(this);
break;
case R.id.simulateEncounterFormationAndConfirmationClient:
if (!isSignedIn()) throw new SecurityException("Not signed in");
......
......@@ -5,35 +5,23 @@ import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.util.Log;
import android.widget.Toast;
import java.io.IOException;
public class Alarm extends BroadcastReceiver {
public static final long WAKE_INTERVAL = (long) 10;
public static final long WAKE_INTERVAL = (long) (15*60000);
private static final String TAG = Alarm.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent)
{
//PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "testapp:blah");
//wl.acquire();
// Put here YOUR code.
//Toast.makeText(context, "Alarm !!!!!!!!!!", Toast.LENGTH_LONG).show(); // For example
//wl.release();
Log.d(TAG, "BroadcastReceiver: onReceive(): " + System.currentTimeMillis());
AlarmManager am =(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
long ts = System.currentTimeMillis();
long triggerAtMillis = (long) (ts + WAKE_INTERVAL);
try {
long ts = System.currentTimeMillis();
long triggerAtMillis = (long) (ts + WAKE_INTERVAL);
am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtMillis, pi);
Log.d(TAG, "BroadcastReceiver: onReceive(): " + ts + "->" + triggerAtMillis);
} catch (NullPointerException e) {
Log.e(TAG, "BroadcastReceiver: onReceive() Exception" + System.currentTimeMillis() + e.getMessage());
}
......@@ -44,22 +32,14 @@ public class Alarm extends BroadcastReceiver {
AlarmManager am =(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
//am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi); // Millisec * Second * Minute
long ts = System.currentTimeMillis();
long triggerAtMillis = (long) (ts + WAKE_INTERVAL);
Log.d(TAG, "BroadcastReceiver: setAlarm(): " + ts + "->" + triggerAtMillis);
try {
am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtMillis, pi);
Log.d(TAG, "BroadcastReceiver: setAlarm(): " + ts + "->" + triggerAtMillis);
} catch (NullPointerException e) {
Log.e(TAG, "BroadcastReceiver: setAlarm() Exception" + System.currentTimeMillis() + e.getMessage());
}
}
//public void cancelAlarm(Context context)
//{
// Intent intent = new Intent(context, Alarm.class);
// PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
// AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
// alarmManager.cancel(sender);
//}
}
......@@ -13,7 +13,7 @@ import java.util.UUID;
public class NullWakelock extends Service {
private static final String TAG = Alarm.class.getSimpleName();
private static final UUID MY_UUID = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
//private static final UUID MY_UUID = UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
Alarm alarm = new Alarm();
public void onCreate()
......
......@@ -51,7 +51,7 @@
<Button
android:id="@+id/nullWakelock"
android:layout_width="224dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test: Null Wakelock" />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment