Added sms behaviour
This commit is contained in:
parent
7264554de3
commit
1ed6ad198b
7 changed files with 157 additions and 22 deletions
4
.idea/libraries/GraphView_3_1_2.xml
generated
4
.idea/libraries/GraphView_3_1_2.xml
generated
|
|
@ -4,8 +4,6 @@
|
|||
<root url="jar://$PROJECT_DIR$/app/libs/GraphView-3.1.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/app/libs/GraphView-master.zip!/GraphView-master/src/main/java" />
|
||||
</SOURCES>
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
Binary file not shown.
|
|
@ -8,8 +8,8 @@ android {
|
|||
applicationId "com.ericsson.uecontrol"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 19
|
||||
versionCode 10
|
||||
versionName "1.0.10"
|
||||
versionCode 11
|
||||
versionName "1.0.11"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@
|
|||
</activity>
|
||||
</application>
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
</manifest>
|
||||
|
|
|
|||
124
app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourSendSMS.java
Executable file
124
app/src/main/java/com/ericsson/uecontrol/core/behaviour/UeBehaviourSendSMS.java
Executable file
|
|
@ -0,0 +1,124 @@
|
|||
package com.ericsson.uecontrol.core.behaviour;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.telephony.SmsManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||
import com.ericsson.uecontrol.gui.MainActivity;
|
||||
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Created by ezivkoc on 2014-08-06.
|
||||
*/
|
||||
public class UeBehaviourSendSMS extends UeBehaviour{
|
||||
private static final Logger log = Logger.getLogger(UeBehaviourSendSMS.class);
|
||||
private static final String INTENT_ACTION_SENT = "SMS_SENT";
|
||||
private static final String INTENT_ACTION_DELIVERED = "SMS_DELIVERED";
|
||||
private static final int SLEEP_PERIOD = 200;
|
||||
|
||||
private static enum MessageStatus{
|
||||
UNKNOWN, MESSAGE_SENT, MESSAGE_DELIVERED, MESSAGE_SEND_ERROR, MESSAGE_CANCELED
|
||||
}
|
||||
|
||||
@Configurable("Phone Number")
|
||||
private String phoneNumber;
|
||||
@Configurable("Message Text")
|
||||
private String message;
|
||||
|
||||
private transient MessageStatus status;
|
||||
private transient Exception exception;
|
||||
|
||||
private transient BroadcastReceiver sentBroadcastReceiver = new BroadcastReceiver() {
|
||||
public void onReceive(Context arg0, Intent arg1) { setSendingStatus(getResultCode()); }};
|
||||
private transient BroadcastReceiver deliveryBroadcastReceiver = new BroadcastReceiver() {
|
||||
public void onReceive(Context arg0, Intent arg1) { setDeliveryStatus(getResultCode()); }};
|
||||
|
||||
@Override
|
||||
protected void execute() throws Exception {
|
||||
Context context = MainActivity.getContext();
|
||||
status = MessageStatus.UNKNOWN;
|
||||
exception = null;
|
||||
|
||||
// Register PendingIntents and BroadcastReceivers
|
||||
log.debug("Registering PendingIntents");
|
||||
PendingIntent sentPI = PendingIntent.getBroadcast(
|
||||
context, 0, new Intent(INTENT_ACTION_SENT), 0);
|
||||
PendingIntent deliveredPI = PendingIntent.getBroadcast(
|
||||
context, 0, new Intent(INTENT_ACTION_DELIVERED), 0);
|
||||
|
||||
context.registerReceiver(sentBroadcastReceiver, new IntentFilter(INTENT_ACTION_SENT));
|
||||
context.registerReceiver(deliveryBroadcastReceiver, new IntentFilter(INTENT_ACTION_DELIVERED));
|
||||
|
||||
// Send message
|
||||
log.debug("Sending message");
|
||||
SmsManager sms = SmsManager.getDefault();
|
||||
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
|
||||
this.setProgress(1/3);
|
||||
|
||||
// Wait for the message sending
|
||||
while(status != MessageStatus.MESSAGE_DELIVERED ||
|
||||
status != MessageStatus.MESSAGE_CANCELED){
|
||||
if(status == MessageStatus.MESSAGE_SENT)
|
||||
this.setProgress(2/3);
|
||||
Thread.sleep(SLEEP_PERIOD);
|
||||
}
|
||||
this.setProgress(3/3);
|
||||
|
||||
// Cleanup
|
||||
context.unregisterReceiver(sentBroadcastReceiver);
|
||||
context.unregisterReceiver(deliveryBroadcastReceiver);
|
||||
}
|
||||
|
||||
private void setSendingStatus(int code){
|
||||
switch (code) {
|
||||
case Activity.RESULT_OK:
|
||||
log.debug("Message sent");
|
||||
status = MessageStatus.MESSAGE_SENT;
|
||||
break;
|
||||
default:
|
||||
exception = new Exception("There was an error when sending the sms: "+getCodeString(code));
|
||||
}
|
||||
}
|
||||
private void setDeliveryStatus(int code){
|
||||
switch (code) {
|
||||
case Activity.RESULT_OK:
|
||||
log.debug("Message delivered");
|
||||
status = MessageStatus.MESSAGE_DELIVERED;
|
||||
break;
|
||||
case Activity.RESULT_CANCELED:
|
||||
log.debug("Message canceled");
|
||||
status = MessageStatus.MESSAGE_CANCELED;
|
||||
break;
|
||||
}
|
||||
}
|
||||
private String getCodeString(int code){
|
||||
switch (code) {
|
||||
case Activity.RESULT_CANCELED: return "RESULT_CANCELED";
|
||||
case Activity.RESULT_OK: return "RESULT_OK";
|
||||
case SmsManager.RESULT_ERROR_GENERIC_FAILURE: return "RESULT_ERROR_GENERIC_FAILURE";
|
||||
case SmsManager.RESULT_ERROR_NO_SERVICE: return "RESULT_ERROR_NO_SERVICE";
|
||||
case SmsManager.RESULT_ERROR_NULL_PDU: return "RESULT_ERROR_NULL_PDU";
|
||||
case SmsManager.RESULT_ERROR_RADIO_OFF: return "RESULT_ERROR_RADIO_OFF";
|
||||
}
|
||||
return "UNKNOWN_CODE("+code+")";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Send SMS";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Will send an SMS to: " + phoneNumber;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.ericsson.uecontrol.gui;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
|
|
@ -44,13 +45,15 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
private static UeControlExecutor currentExecutor;
|
||||
private static CSVWriter csvLogger;
|
||||
private static int uid;
|
||||
private static Context context;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// Get UID
|
||||
// Set static fields
|
||||
uid = getApplicationInfo().uid;
|
||||
context = this;
|
||||
|
||||
// Setup Debugging
|
||||
setupDebugLogging();
|
||||
|
|
@ -70,7 +73,10 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
try {
|
||||
log.debug("Reading saved state");
|
||||
currentExecutor.read(input.getAbsolutePath());
|
||||
}catch(Exception e){log.error(null, e);}
|
||||
}catch(Exception e){
|
||||
Toast.makeText(this, "Unable to load saved state", Toast.LENGTH_SHORT).show();
|
||||
log.error(null, e);
|
||||
}
|
||||
}
|
||||
else{
|
||||
log.debug("No saved state found, creating default behaviours");
|
||||
|
|
@ -167,20 +173,6 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public static UeControlExecutor getExecutor() {
|
||||
return currentExecutor;
|
||||
}
|
||||
|
||||
public static void logThroughput(double downThroughput, double upThroughput) {
|
||||
if(csvLogger == null || currentExecutor == null || currentExecutor.getRunningBehaviour() == null)
|
||||
return;
|
||||
|
||||
csvLogger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
|
||||
}
|
||||
public static int getUID(){
|
||||
return uid;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
|
|
@ -199,4 +191,23 @@ public class MainActivity extends FragmentActivity implements OnSharedPreference
|
|||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void logThroughput(double downThroughput, double upThroughput) {
|
||||
if(csvLogger == null || currentExecutor == null || currentExecutor.getRunningBehaviour() == null)
|
||||
return;
|
||||
|
||||
csvLogger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
|
||||
}
|
||||
|
||||
public static UeControlExecutor getExecutor() {
|
||||
return currentExecutor;
|
||||
}
|
||||
public static int getUID(){
|
||||
return uid;
|
||||
}
|
||||
public static Context getContext(){return context;}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
<string-array name="behaviours" >
|
||||
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourFileDownload</item>
|
||||
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourFtpDownload</item>
|
||||
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourSendSMS</item>
|
||||
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourSleep</item>
|
||||
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing</item>
|
||||
<item>com.ericsson.uecontrol.core.behaviour.UeBehaviourVideoStreaming</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue