Commit 1aae0391 authored by Roberta De Viti's avatar Roberta De Viti

test: null wakelock

parent 973d4953
...@@ -3,6 +3,7 @@ apply plugin: 'com.jfrog.bintray' ...@@ -3,6 +3,7 @@ apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
repositories { repositories {
google()
jcenter() jcenter()
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-feature android:name="android.hardware.bluetooth_le" /> <uses-feature android:name="android.hardware.bluetooth_le" />
<application android:name="android.support.multidex.MultiDexApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" <application android:name="android.support.multidex.MultiDexApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher"
...@@ -36,6 +37,9 @@ ...@@ -36,6 +37,9 @@
</activity> </activity>
<activity android:name="org.mpisws.testapp.googleauth.GoogleAuthActivity"/> <activity android:name="org.mpisws.testapp.googleauth.GoogleAuthActivity"/>
<receiver android:process=":remote" android:name=".Alarm"></receiver>
</application> </application>
</manifest> </manifest>
...@@ -23,8 +23,10 @@ import org.mpisws.encounters.EncounterBasedCommunication; ...@@ -23,8 +23,10 @@ import org.mpisws.encounters.EncounterBasedCommunication;
import org.mpisws.messaging.ReceivedMessageWrapper; import org.mpisws.messaging.ReceivedMessageWrapper;
import org.mpisws.testapp.googleauth.GoogleNativeAuthenticator; import org.mpisws.testapp.googleauth.GoogleNativeAuthenticator;
import org.mpisws.testapp.googleauth.GoogleToken; import org.mpisws.testapp.googleauth.GoogleToken;
import org.mpisws.testapp.simulator.Alarm;
import org.mpisws.testapp.simulator.SimulationClientBT; import org.mpisws.testapp.simulator.SimulationClientBT;
import org.mpisws.testapp.simulator.SimulationServerBT; import org.mpisws.testapp.simulator.SimulationServerBT;
import org.mpisws.testapp.simulator.NullWakelock;
import java.util.List; import java.util.List;
...@@ -56,6 +58,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -56,6 +58,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
findViewById(R.id.deleteAccount).setOnClickListener(this); findViewById(R.id.deleteAccount).setOnClickListener(this);
findViewById(R.id.testSendMessages).setOnClickListener(this); findViewById(R.id.testSendMessages).setOnClickListener(this);
findViewById(R.id.testReceiveMessages).setOnClickListener(this); findViewById(R.id.testReceiveMessages).setOnClickListener(this);
findViewById(R.id.nullWakelock).setOnClickListener(this);
findViewById(R.id.simulateEncounterFormationAndConfirmationClient).setOnClickListener(this); findViewById(R.id.simulateEncounterFormationAndConfirmationClient).setOnClickListener(this);
findViewById(R.id.simulateEncounterFormationAndConfirmationServer).setOnClickListener(this); findViewById(R.id.simulateEncounterFormationAndConfirmationServer).setOnClickListener(this);
findViewById(R.id.testEndToEndES).setOnClickListener(this); findViewById(R.id.testEndToEndES).setOnClickListener(this);
...@@ -92,6 +95,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -92,6 +95,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
/***************************** ES AND SDDR TESTS **********************/ /***************************** ES AND SDDR TESTS **********************/
case R.id.nullWakelock:
//if (!isSignedIn()) throw new SecurityException("Not signed in");
Log.d(TAG, "Starting null wakelock test!");
new Alarm().setAlarm(this);
break;
case R.id.simulateEncounterFormationAndConfirmationClient: case R.id.simulateEncounterFormationAndConfirmationClient:
if (!isSignedIn()) throw new SecurityException("Not signed in"); if (!isSignedIn()) throw new SecurityException("Not signed in");
new SimulationClientBT(this).startClient(); new SimulationClientBT(this).startClient();
......
package org.mpisws.testapp.simulator; package org.mpisws.testapp.simulator;
public class Alarm { import android.app.AlarmManager;
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;
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);
try {
long ts = System.currentTimeMillis();
long triggerAtMillis = (long) (ts + WAKE_INTERVAL);
am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, triggerAtMillis, pi);
} catch (NullPointerException e) {
Log.e(TAG, "BroadcastReceiver: onReceive() Exception" + System.currentTimeMillis() + e.getMessage());
}
}
public void setAlarm(Context context)
{
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);
} 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);
//}
} }
package org.mpisws.testapp.simulator; package org.mpisws.testapp.simulator;
public class NullWakelock { import android.app.Service;
} import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
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");
Alarm alarm = new Alarm();
public void onCreate()
{
Log.d(TAG, "onCreate(): " + System.currentTimeMillis());
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
Log.d(TAG, "onStartCommand(): " + System.currentTimeMillis());
alarm.setAlarm(this);
return START_STICKY;
}
@Override
public void onStart(Intent intent, int startId)
{
alarm.setAlarm(this);
}
@Override
public IBinder onBind(Intent intent)
{
return null;
}
}
\ No newline at end of file
...@@ -48,12 +48,20 @@ ...@@ -48,12 +48,20 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Messaging: Get unread messages" /> android:text="Messaging: Get unread messages" />
<Button
<Button
android:id="@+id/nullWakelock"
android:layout_width="224dp"
android:layout_height="wrap_content"
android:text="Test: Null Wakelock" />
<Button
android:id="@+id/simulateEncounterFormationAndConfirmationClient" android:id="@+id/simulateEncounterFormationAndConfirmationClient"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Simulate Encounters: Client" /> android:text="Simulate Encounters: Client" />
<Button
<Button
android:id="@+id/simulateEncounterFormationAndConfirmationServer" android:id="@+id/simulateEncounterFormationAndConfirmationServer"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
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