diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 154f4b57..5d5ee5cd 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -230,6 +230,13 @@
+
+
+
+
+
+
+
diff --git a/src/com/prey/activities/AddDeviceToAccountActivity.java b/src/com/prey/activities/AddDeviceToAccountActivity.java
index 087a0c11..f5563ec9 100644
--- a/src/com/prey/activities/AddDeviceToAccountActivity.java
+++ b/src/com/prey/activities/AddDeviceToAccountActivity.java
@@ -12,14 +12,15 @@
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.Service;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.net.Uri;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
@@ -32,22 +33,21 @@
import android.widget.TextView;
import android.widget.Toast;
-import com.prey.PreyAccountData;
import com.prey.PreyConfig;
import com.prey.PreyLogger;
import com.prey.R;
-import com.prey.exceptions.NoMoreDevicesAllowedException;
-import com.prey.exceptions.PreyException;
-import com.prey.net.PreyWebServices;
+import com.prey.services.AddDeviceToAccountService;
import com.prey.util.KeyboardStatusDetector;
import com.prey.util.KeyboardVisibilityListener;
public class AddDeviceToAccountActivity extends SetupActivity {
+ public static final String ADDDEVICE_FILTER = "AddDeviceToAccountActivity_receiver";
private static final int NO_MORE_DEVICES_WARNING = 0;
private static final int ERROR = 3;
private String error = null;
private boolean noMoreDeviceError = false;
+ private AddDeviceToAccountReceiver receiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -87,6 +87,8 @@ public void onVisibilityChanged(boolean keyboardVisible) {
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.layout.add_device);
InputMethodManager im = (InputMethodManager) getSystemService(Service.INPUT_METHOD_SERVICE);
+ receiver = new AddDeviceToAccountReceiver();
+ registerReceiver(receiver, new IntentFilter(ADDDEVICE_FILTER));
Button ok = (Button) findViewById(R.id.add_device_btn_ok);
ok.setOnClickListener(new View.OnClickListener() {
@@ -104,7 +106,11 @@ public void onClick(View v) {
if(password.length()<6||password.length()>32){
Toast.makeText(ctx, ctx.getString(R.string.error_password_out_of_range,6,32), Toast.LENGTH_LONG).show();
}else{
- new AddDeviceToAccount().execute(email, password, getDeviceType(ctx));
+ Intent addDevice = new Intent(AddDeviceToAccountActivity.this, AddDeviceToAccountService.class);
+ receiver.showProgressDialog();
+ String[] params = { email, password, getDeviceType(ctx) };
+ addDevice.putExtra("params", params);
+ AddDeviceToAccountActivity.this.startService(addDevice);
}
}
}
@@ -146,6 +152,13 @@ public void onClick(View v) {
}
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (receiver != null)
+ unregisterReceiver(receiver);
+ }
+
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@@ -213,12 +226,11 @@ public void onClick(DialogInterface dialog, int id) {
}
}
- private class AddDeviceToAccount extends AsyncTask {
+ private class AddDeviceToAccountReceiver extends BroadcastReceiver {
ProgressDialog progressDialog = null;
- @Override
- protected void onPreExecute() {
+ public void showProgressDialog() {
progressDialog = new ProgressDialog(AddDeviceToAccountActivity.this);
progressDialog.setMessage(AddDeviceToAccountActivity.this.getText(R.string.set_old_user_loading).toString());
progressDialog.setIndeterminate(true);
@@ -227,30 +239,12 @@ protected void onPreExecute() {
}
@Override
- protected Void doInBackground(String... data) {
- try {
- noMoreDeviceError = false;
- error = null;
- PreyAccountData accountData = PreyWebServices.getInstance().registerNewDeviceToAccount(AddDeviceToAccountActivity.this, data[0], data[1], data[2]);
- getPreyConfig().saveAccount(accountData);
-
- } catch (PreyException e) {
- error = e.getMessage();
- try {
- NoMoreDevicesAllowedException noMoreDevices = (NoMoreDevicesAllowedException) e;
- noMoreDeviceError = true;
-
- } catch (ClassCastException e1) {
- noMoreDeviceError = false;
- }
- }
- return null;
- }
-
- @Override
- protected void onPostExecute(Void unused) {
+ public void onReceive(Context receiverContext, Intent receiverIntent) {
+ error = receiverIntent.getStringExtra("error");
+ noMoreDeviceError = receiverIntent.getBooleanExtra("noMoreDeviceError", false);
try {
- progressDialog.dismiss();
+ if (progressDialog != null)
+ progressDialog.dismiss();
} catch (Exception e) {
}
if (noMoreDeviceError)
@@ -264,7 +258,7 @@ protected void onPostExecute(Void unused) {
Intent intent = new Intent(AddDeviceToAccountActivity.this, PermissionInformationActivity.class);
intent.putExtras(bundle);
startActivity(intent);
- finish();
+ AddDeviceToAccountActivity.this.finish();
} else
showDialog(ERROR);
}
diff --git a/src/com/prey/activities/CreateAccountActivity.java b/src/com/prey/activities/CreateAccountActivity.java
index 7e1f4ba1..ea1630bf 100644
--- a/src/com/prey/activities/CreateAccountActivity.java
+++ b/src/com/prey/activities/CreateAccountActivity.java
@@ -9,17 +9,16 @@
import java.util.Locale;
import android.app.AlertDialog;
-
-import com.prey.R;
import android.app.Dialog;
import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Typeface;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
@@ -31,19 +30,21 @@
import android.widget.TextView;
import android.widget.Toast;
-import com.prey.PreyAccountData;
import com.prey.PreyLogger;
-import com.prey.exceptions.PreyException;
-import com.prey.net.PreyWebServices;
+import com.prey.R;
+import com.prey.services.CreateAccountService;
import com.prey.util.KeyboardStatusDetector;
import com.prey.util.KeyboardVisibilityListener;
public class CreateAccountActivity extends SetupActivity {
+ public static final String CREATEACCOUNT_FILTER = "CreateAccountReceiver_receiver";
+
private static final int ERROR = 1;
private String password = null;
private String name = null;
private String email = null;
private String error = null;
+ private CreateAccountReceiver receiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -80,6 +81,8 @@ public void onVisibilityChanged(boolean keyboardVisible) {
}
});
+ receiver = new CreateAccountReceiver();
+ this.registerReceiver(receiver, new IntentFilter(CREATEACCOUNT_FILTER));
Button ok = (Button) findViewById(R.id.new_account_btn_ok);
ok.setOnClickListener(new View.OnClickListener() {
@@ -97,7 +100,11 @@ public void onClick(View v) {
if(password.length()<6||password.length()>32){
Toast.makeText(ctx, ctx.getString(R.string.error_password_out_of_range,6,32), Toast.LENGTH_LONG).show();
}else{
- new CreateAccount().execute(name, email, password);
+ Intent createAccount = new Intent(CreateAccountActivity.this, CreateAccountService.class);
+ receiver.showProgressDialog();
+ String[] params = { name, email, password };
+ createAccount.putExtra("params", params);
+ CreateAccountActivity.this.startService(createAccount);
}
}
}
@@ -143,18 +150,24 @@ public void onClick(View v) {
}
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (receiver != null)
+ unregisterReceiver(receiver);
+ }
+
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
- private class CreateAccount extends AsyncTask {
+ private class CreateAccountReceiver extends BroadcastReceiver {
ProgressDialog progressDialog = null;
- @Override
- protected void onPreExecute() {
+ public void showProgressDialog() {
progressDialog = new ProgressDialog(CreateAccountActivity.this);
progressDialog.setMessage(CreateAccountActivity.this.getText(R.string.creating_account_please_wait).toString());
progressDialog.setIndeterminate(true);
@@ -163,21 +176,11 @@ protected void onPreExecute() {
}
@Override
- protected Void doInBackground(String... data) {
+ public void onReceive(Context receiverContext, Intent receiverIntent) {
+ error = receiverIntent.getStringExtra("error");
try {
- PreyAccountData accountData = PreyWebServices.getInstance().registerNewAccount(CreateAccountActivity.this, data[0], data[1], data[2], getDeviceType());
- PreyLogger.d("Response creating account: " + accountData.toString());
- getPreyConfig().saveAccount(accountData);
- } catch (PreyException e) {
- error = e.getMessage();
- }
- return null;
- }
-
- @Override
- protected void onPostExecute(Void unused) {
- try {
- progressDialog.dismiss();
+ if (progressDialog != null)
+ progressDialog.dismiss();
} catch (Exception e) {
}
if (error == null) {
@@ -187,7 +190,7 @@ protected void onPostExecute(Void unused) {
Intent intent = new Intent(CreateAccountActivity.this, PermissionInformationActivity.class);
intent.putExtras(bundle);
startActivity(intent);
- finish();
+ CreateAccountActivity.this.finish();
} else
showDialog(ERROR);
}
diff --git a/src/com/prey/activities/PasswordActivity.java b/src/com/prey/activities/PasswordActivity.java
index 8e59600e..5f983187 100644
--- a/src/com/prey/activities/PasswordActivity.java
+++ b/src/com/prey/activities/PasswordActivity.java
@@ -7,27 +7,41 @@
package com.prey.activities;
import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.graphics.Typeface;
-import android.net.Uri;
-import android.os.AsyncTask;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
-import com.prey.events.Event;
-import com.prey.events.manager.EventManagerRunner;
-import com.prey.exceptions.PreyException;
-import com.prey.net.PreyWebServices;
-import com.prey.PreyConfig;
import com.prey.PreyStatus;
import com.prey.R;
+import com.prey.events.Event;
+import com.prey.events.manager.EventManagerRunner;
+import com.prey.services.CheckPasswordService;
public class PasswordActivity extends PreyActivity {
-
+
+ public static final String CHECKPWD_FILTER = "PasswordActivity_receiver";
int wrongPasswordIntents = 0;
+ private CheckPasswordReceiver receiver;
+
+ @Override
+ protected void onCreate(android.os.Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ receiver = new CheckPasswordReceiver();
+ registerReceiver(receiver, new IntentFilter(CHECKPWD_FILTER));
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ if (receiver != null)
+ unregisterReceiver(receiver);
+ }
protected void bindPasswordControls() {
Button checkPasswordOkButton = (Button) findViewById(R.id.password_btn_login);
@@ -43,7 +57,11 @@ public void onClick(View v) {
if(passwordtyped.length()<6||passwordtyped.length()>32){
Toast.makeText(ctx, ctx.getString(R.string.error_password_out_of_range,6,32), Toast.LENGTH_LONG).show();
}else{
- new CheckPassword().execute(passwordtyped);
+ Intent checkPwd = new Intent(PasswordActivity.this, CheckPasswordService.class);
+ receiver.showProgressDialog();
+ String[] params = { passwordtyped };
+ checkPwd.putExtra("params", params);
+ PasswordActivity.this.startService(checkPwd);
}
}
@@ -92,16 +110,14 @@ public void onClick(View v) {
((TextView) findViewById(R.id.login_h2_text)).setText(h2);*/
}
- protected class CheckPassword extends AsyncTask {
+ protected class CheckPasswordReceiver extends BroadcastReceiver {
ProgressDialog progressDialog = null;
boolean isPasswordOk = false;
- boolean keepAsking = true;
String error = null;
- @Override
- protected void onPreExecute() {
+ public void showProgressDialog() {
try{
progressDialog = new ProgressDialog(PasswordActivity.this);
progressDialog.setMessage(PasswordActivity.this.getText(R.string.password_checking_dialog).toString());
@@ -114,23 +130,11 @@ protected void onPreExecute() {
}
@Override
- protected Void doInBackground(String... password) {
- try {
- String email = getPreyConfig().getEmail();
- isPasswordOk = PreyWebServices.getInstance().checkPassword(PasswordActivity.this, email, password[0]);
- //if (isPasswordOk)
- //PreyConfig.getPreyConfig(CheckPasswordActivity.this).setPassword(password[0]);
-
- } catch (PreyException e) {
- error = e.getMessage();
- }
- return null;
- }
-
- @Override
- protected void onPostExecute(Void unused) {
+ public void onReceive(Context receiverContext, Intent receiverIntent) {
+ error = receiverIntent.getStringExtra("error");
+ isPasswordOk = receiverIntent.getBooleanExtra("isPasswordOk", false);
try{
- if (progressDialog.isShowing()){
+ if (progressDialog != null && progressDialog.isShowing()){
progressDialog.dismiss();
}
}catch(Exception e){
@@ -145,8 +149,8 @@ else if (!isPasswordOk) {
wrongPasswordIntents++;
if (wrongPasswordIntents == 3) {
Toast.makeText(PasswordActivity.this, R.string.password_intents_exceed, Toast.LENGTH_LONG).show();
- setResult(RESULT_CANCELED);
- finish();
+ PasswordActivity.this.setResult(RESULT_CANCELED);
+ PasswordActivity.this.finish();
} else {
Toast.makeText(PasswordActivity.this, R.string.password_wrong, Toast.LENGTH_SHORT).show();
}
diff --git a/src/com/prey/activities/SMSContactActivity.java b/src/com/prey/activities/SMSContactActivity.java
index d3d8a4c0..673f692d 100644
--- a/src/com/prey/activities/SMSContactActivity.java
+++ b/src/com/prey/activities/SMSContactActivity.java
@@ -7,17 +7,19 @@
package com.prey.activities;
import android.app.AlertDialog;
+import android.app.IntentService;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.net.Uri;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.view.View;
import android.widget.Button;
-import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@@ -31,8 +33,10 @@
import com.prey.R;
public class SMSContactActivity extends PreyActivity {
+ public static final String LOADCONTACT_FILTER = "SMSContactActivity_receiver";
private static final int PICK_CONTACT_REQUEST = 0;
ContactAccessor contactAccesor = new ContactAccessor();
+ private BroadcastReceiver receiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -60,6 +64,22 @@ public void onClick(View v) {
}
});
+ receiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context receiverContext, Intent receiverIntent) {
+ ContactInfo result = (ContactInfo) receiverIntent.getSerializableExtra("contact");
+ bindView(result);
+ showContactNowAlert();
+ }
+ };
+ registerReceiver(receiver, new IntentFilter(LOADCONTACT_FILTER));
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (receiver != null)
+ unregisterReceiver(receiver);
}
@Override
@@ -126,20 +146,11 @@ private void loadContactInfo(Uri contactUri) {
* up the UI thread while waiting for the query to come back, we might
* get an "Application Not Responding" dialog.
*/
- AsyncTask task = new AsyncTask() {
-
- @Override
- protected ContactInfo doInBackground(Uri... uris) {
- return contactAccesor.loadContact(getContentResolver(), uris[0]);
- }
-
- @Override
- protected void onPostExecute(ContactInfo result) {
- bindView(result);
- showContactNowAlert();
- }
- };
- task.execute(contactUri);
+ Intent loadContact = new Intent(this, LoadContactService.class);
+ loadContact.putExtra("contactAccesor", contactAccesor);
+ Uri[] uris = { contactUri };
+ loadContact.putExtra("uris", uris);
+ this.startService(loadContact);
}
protected void bindView(ContactInfo contactInfo) {
@@ -174,3 +185,18 @@ private void fillScreenInfo(String name, String number, Bitmap photo){
}
}
+
+class LoadContactService extends IntentService {
+ public LoadContactService() {
+ super("LoadContactService");
+ }
+
+ public void onHandleIntent(Intent intent) {
+ ContactAccessor contactAccesor = (ContactAccessor) intent.getSerializableExtra("contactAccesor");
+ Uri[] uris = (Uri[]) intent.getParcelableArrayExtra("uris");
+ Intent resultIntent = new Intent(SMSContactActivity.LOADCONTACT_FILTER);
+ resultIntent.putExtra("contact", contactAccesor.loadContact(getContentResolver(), uris[0]));
+ sendBroadcast(resultIntent);
+ return;
+ }
+}
diff --git a/src/com/prey/activities/WelcomeBatchActivity.java b/src/com/prey/activities/WelcomeBatchActivity.java
index 7e5f674e..bf2fc165 100644
--- a/src/com/prey/activities/WelcomeBatchActivity.java
+++ b/src/com/prey/activities/WelcomeBatchActivity.java
@@ -7,21 +7,24 @@
package com.prey.activities;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
-import android.os.AsyncTask;
import android.os.Bundle;
-
-import com.prey.PreyAccountData;
+
import com.prey.PreyConfig;
import com.prey.PreyScheduled;
import com.prey.R;
-import com.prey.exceptions.PreyException;
-import com.prey.net.PreyWebServices;
+import com.prey.services.AddDeviceToApiKeyBatch;
public class WelcomeBatchActivity extends PreyActivity {
+ public static final String KEYBATCHRECEIVER_FILTER = "WelcomeBatchActivity_RECEIVER";
+
private String error = null;
+ private AddDeviceToApiKeyBatchReceiver receiver;
@Override
public void onConfigurationChanged(Configuration newConfig) {
@@ -39,31 +42,28 @@ protected void onCreate(Bundle savedInstanceState) {
}
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (receiver != null) {
+ unregisterReceiver(receiver);
+ }
+ }
private void installBatch() {
- new AddDeviceToApiKeyBatch().execute(getPreyConfig().getApiKeyBatch(),getPreyConfig().getEmailBatch(), getDeviceType());
+ receiver = new AddDeviceToApiKeyBatchReceiver();
+ this.registerReceiver(receiver, new IntentFilter(KEYBATCHRECEIVER_FILTER));
+ Intent addToKeyBatch = new Intent(this, AddDeviceToApiKeyBatch.class);
+ String[] params = { getPreyConfig().getApiKeyBatch(),
+ getPreyConfig().getEmailBatch(), getDeviceType() };
+ addToKeyBatch.putExtra("params", params);
+ this.startService(addToKeyBatch);
}
- private class AddDeviceToApiKeyBatch extends AsyncTask {
- @Override
- protected void onPreExecute() {
-
- }
-
- @Override
- protected Void doInBackground(String... data) {
- try {
- error = null;
- PreyAccountData accountData =PreyWebServices.getInstance().registerNewDeviceWithApiKeyEmail(WelcomeBatchActivity.this, data[0], data[1], data[2]);
- getPreyConfig().saveAccount(accountData);
- } catch (PreyException e) {
- error = e.getMessage();
- }
- return null;
- }
-
+ private class AddDeviceToApiKeyBatchReceiver extends BroadcastReceiver {
@Override
- protected void onPostExecute(Void unused) {
+ public void onReceive(Context receiverContext, Intent receiverIntent) {
+ error = receiverIntent.getStringExtra("error");
if (error == null) {
String message = getString(R.string.device_added_congratulations_text);
Bundle bundle = new Bundle();
@@ -76,7 +76,7 @@ protected void onPostExecute(Void unused) {
if (PreyConfig.getPreyConfig(WelcomeBatchActivity.this).isScheduled()) {
PreyScheduled.getInstance(WelcomeBatchActivity.this);
}
- finish();
+ WelcomeBatchActivity.this.finish();
}
}
}
diff --git a/src/com/prey/contacts/ContactAccessor.java b/src/com/prey/contacts/ContactAccessor.java
index eea91de3..90a30ec3 100644
--- a/src/com/prey/contacts/ContactAccessor.java
+++ b/src/com/prey/contacts/ContactAccessor.java
@@ -36,7 +36,7 @@
* social status updates (see {@link android.provider.ContactsContract.StatusUpdates}).
*
*/
-public class ContactAccessor {
+public class ContactAccessor implements java.io.Serializable {
public Intent getPickContactIntent() {
return new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
diff --git a/src/com/prey/contacts/ContactInfo.java b/src/com/prey/contacts/ContactInfo.java
index 24d95222..f81add44 100644
--- a/src/com/prey/contacts/ContactInfo.java
+++ b/src/com/prey/contacts/ContactInfo.java
@@ -11,7 +11,7 @@
/**
* A model object containing contact data.
*/
-public class ContactInfo {
+public class ContactInfo implements java.io.Serializable {
private String mDisplayName;
private String mPhoneNumber;
diff --git a/src/com/prey/preferences/DetachDevicePreferences.java b/src/com/prey/preferences/DetachDevicePreferences.java
index 599b975f..b9f662f9 100644
--- a/src/com/prey/preferences/DetachDevicePreferences.java
+++ b/src/com/prey/preferences/DetachDevicePreferences.java
@@ -7,22 +7,24 @@
package com.prey.preferences;
import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.os.AsyncTask;
+import android.content.IntentFilter;
import android.os.Bundle;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.widget.Toast;
-import com.prey.PreyConfig;
-import com.prey.activities.LoginActivity;
-import com.prey.exceptions.PreyException;
-import com.prey.net.PreyWebServices;
import com.prey.R;
+import com.prey.activities.LoginActivity;
+import com.prey.services.DetachDeviceService;
public class DetachDevicePreferences extends DialogPreference {
+ public static final String DETACHDEVICE_FILTER = "DetachDevicePreferences_RECEIVER";
+
Context ctx = null;
+ private DetachDeviceReceiver receiver;
public DetachDevicePreferences(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -38,17 +40,28 @@ public DetachDevicePreferences(Context context, AttributeSet attrs, int defStyle
public void onClick(DialogInterface dialog, int which) {
super.onClick(dialog, which);
if (which == DialogInterface.BUTTON_POSITIVE) {
- new DetachDevice().execute();
+ receiver = new DetachDeviceReceiver();
+ ctx.registerReceiver(receiver, new IntentFilter(DETACHDEVICE_FILTER));
+ Intent detachDevice = new Intent(ctx, DetachDeviceService.class);
+ receiver.showProgressDialog();
+ ctx.startService(detachDevice);
+ }
+ }
+
+ @Override
+ public void onActivityDestroy() {
+ super.onActivityDestroy();
+ if (receiver != null) {
+ ctx.unregisterReceiver(receiver);
}
}
- public class DetachDevice extends AsyncTask {
+ public class DetachDeviceReceiver extends BroadcastReceiver {
private String error = null;
ProgressDialog progressDialog = null;
- @Override
- protected void onPreExecute() {
+ public void showProgressDialog() {
progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage(getContext().getText(R.string.preferences_detach_dettaching_message).toString());
progressDialog.setIndeterminate(true);
@@ -57,23 +70,11 @@ protected void onPreExecute() {
}
@Override
- protected Void doInBackground(Void... unused) {
- try {
- PreyConfig.getPreyConfig(getContext()).unregisterC2dm(false);
- PreyConfig.getPreyConfig(getContext()).setSecurityPrivilegesAlreadyPrompted(false);
- PreyWebServices.getInstance().deleteDevice(ctx);
- PreyConfig.getPreyConfig(getContext()).wipeData();
-
- } catch (PreyException e) {
- e.printStackTrace();
- error = e.getMessage();
+ public void onReceive(Context receiverContext, Intent receiverIntent) {
+ error = receiverIntent.getStringExtra("error");
+ if (progressDialog != null) {
+ progressDialog.dismiss();
}
- return null;
- }
-
- @Override
- protected void onPostExecute(Void unused) {
- progressDialog.dismiss();
if (error != null) {
Toast.makeText(getContext(), error, Toast.LENGTH_LONG).show();
showDialog(new Bundle());
diff --git a/src/com/prey/preferences/RevokedPasswordPreferences.java b/src/com/prey/preferences/RevokedPasswordPreferences.java
index 32cb8839..49f1de58 100644
--- a/src/com/prey/preferences/RevokedPasswordPreferences.java
+++ b/src/com/prey/preferences/RevokedPasswordPreferences.java
@@ -8,20 +8,25 @@
import android.app.ProgressDialog;
+import android.content.BroadcastReceiver;
import android.content.Context;
-import android.os.AsyncTask;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.preference.EditTextPreference;
import android.util.AttributeSet;
import com.prey.PreyConfig;
import com.prey.PreyLogger;
import com.prey.R;
+import com.prey.services.RevokedPasswordPhraseService;
public class RevokedPasswordPreferences extends EditTextPreference {
-
+ public static final String REVOKEDPWD_FILTER = "RevokedPasswordPreferences_receiver";
+
Context ctx = null;
private String error = null;
+ private RevokedPasswordPhraseReceiver receiver;
public RevokedPasswordPreferences(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
@@ -45,25 +50,31 @@ protected void onDialogClosed(boolean positiveResult) {
PreyConfig preyConfig = PreyConfig.getPreyConfig(ctx);
if (positiveResult){
PreyLogger.d("Activation phrase changed to:" + getText());
- new RevokedPasswordPhraseTask(ctx).execute(getText());
+ receiver = new RevokedPasswordPhraseReceiver();
+ ctx.registerReceiver(receiver, new IntentFilter(REVOKEDPWD_FILTER));
+ receiver.showProgressDialog();
+ Intent revokedPwdPhrase = new Intent(ctx, RevokedPasswordPhraseService.class);
+ revokedPwdPhrase.putExtra("param", getText());
+ ctx.startService(revokedPwdPhrase);
}
else{
preyConfig.setRevokedPassword(false, "");
}
}
-
-
- private class RevokedPasswordPhraseTask extends AsyncTask {
- ProgressDialog progressDialog = null;
- private Context context = null;
-
- public RevokedPasswordPhraseTask(Context context){
- this.context = context;
+ @Override
+ public void onActivityDestroy() {
+ super.onActivityDestroy();
+ if (receiver != null) {
+ ctx.unregisterReceiver(receiver);
}
+ }
+
+ private class RevokedPasswordPhraseReceiver extends BroadcastReceiver {
+
+ ProgressDialog progressDialog = null;
- @Override
- protected void onPreExecute() {
+ public void showProgressDialog() {
progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage(getContext().getText(R.string.preferences_admin_device_setting_uninstallation_password).toString());
@@ -73,22 +84,11 @@ protected void onPreExecute() {
}
@Override
- protected Void doInBackground(String... data) {
- try {
- PreyConfig preyConfig = PreyConfig.getPreyConfig(context);
- PreyLogger.d("password [" + getText()+"]");
- preyConfig.setRevokedPassword(true, getText());
-
- //PreyWebServices.getInstance().updateActivationPhrase(getContext(), getText());
- } catch (Exception e) {
- error = e.getMessage();
+ public void onReceive(Context receiverContext, Intent receiverIntent) {
+ error = receiverIntent.getStringExtra("error");
+ if (progressDialog != null) {
+ progressDialog.dismiss();
}
- return null;
- }
-
- @Override
- protected void onPostExecute(Void unused) {
- progressDialog.dismiss();
}
}
diff --git a/src/com/prey/services/AddDeviceToAccountService.java b/src/com/prey/services/AddDeviceToAccountService.java
new file mode 100644
index 00000000..82efffdf
--- /dev/null
+++ b/src/com/prey/services/AddDeviceToAccountService.java
@@ -0,0 +1,48 @@
+package com.prey.services;
+
+import android.app.IntentService;
+import android.content.Intent;
+
+import com.prey.PreyAccountData;
+import com.prey.PreyConfig;
+import com.prey.activities.AddDeviceToAccountActivity;
+import com.prey.exceptions.NoMoreDevicesAllowedException;
+import com.prey.exceptions.PreyException;
+import com.prey.net.PreyWebServices;
+
+public class AddDeviceToAccountService extends IntentService {
+ String error;
+ boolean noMoreDeviceError;
+
+ public AddDeviceToAccountService() {
+ super("AddDeviceToAccountService");
+ }
+
+ public void onHandleIntent(Intent intent) {
+ String[] data = intent.getStringArrayExtra("params");
+ try {
+ noMoreDeviceError = false;
+ error = null;
+ PreyAccountData accountData = PreyWebServices.getInstance()
+ .registerNewDeviceToAccount(this, data[0], data[1], data[2]);
+ getPreyConfig().saveAccount(accountData);
+ } catch (PreyException e) {
+ error = e.getMessage();
+ try {
+ NoMoreDevicesAllowedException noMoreDevices = (NoMoreDevicesAllowedException) e;
+ noMoreDeviceError = true;
+ } catch (ClassCastException e1) {
+ noMoreDeviceError = false;
+ }
+ }
+ Intent resultIntent = new Intent(AddDeviceToAccountActivity.ADDDEVICE_FILTER);
+ resultIntent.putExtra("error", error);
+ resultIntent.putExtra("noMoreDeviceError", noMoreDeviceError);
+ sendBroadcast(resultIntent);
+ return;
+ }
+
+ private PreyConfig getPreyConfig() {
+ return PreyConfig.getPreyConfig(this);
+ }
+}
diff --git a/src/com/prey/services/AddDeviceToApiKeyBatch.java b/src/com/prey/services/AddDeviceToApiKeyBatch.java
new file mode 100644
index 00000000..1150f97c
--- /dev/null
+++ b/src/com/prey/services/AddDeviceToApiKeyBatch.java
@@ -0,0 +1,39 @@
+package com.prey.services;
+
+import android.app.IntentService;
+import android.content.Intent;
+
+import com.prey.PreyAccountData;
+import com.prey.PreyConfig;
+import com.prey.activities.WelcomeBatchActivity;
+import com.prey.exceptions.PreyException;
+import com.prey.net.PreyWebServices;
+
+public class AddDeviceToApiKeyBatch extends IntentService {
+ private String error;
+
+ public AddDeviceToApiKeyBatch() {
+ super("AddDeviceToApiKeyBatch");
+ }
+
+ public void onHandleIntent(Intent intent) {
+ String[] data = intent.getStringArrayExtra("params");
+ try {
+ error = null;
+ PreyAccountData accountData = PreyWebServices.getInstance()
+ .registerNewDeviceWithApiKeyEmail(this, data[0], data[1],
+ data[2]);
+ getPreyConfig().saveAccount(accountData);
+ } catch (PreyException e) {
+ error = e.getMessage();
+ }
+ Intent resultIntent = new Intent(WelcomeBatchActivity.KEYBATCHRECEIVER_FILTER);
+ resultIntent.putExtra("error", error);
+ sendBroadcast(resultIntent);
+ return;
+ }
+
+ private PreyConfig getPreyConfig() {
+ return PreyConfig.getPreyConfig(this);
+ }
+}
diff --git a/src/com/prey/services/CheckPasswordService.java b/src/com/prey/services/CheckPasswordService.java
new file mode 100644
index 00000000..1154eb95
--- /dev/null
+++ b/src/com/prey/services/CheckPasswordService.java
@@ -0,0 +1,37 @@
+package com.prey.services;
+
+import android.app.IntentService;
+import android.content.Intent;
+
+import com.prey.PreyConfig;
+import com.prey.activities.PasswordActivity;
+import com.prey.exceptions.PreyException;
+import com.prey.net.PreyWebServices;
+
+public class CheckPasswordService extends IntentService {
+ boolean isPasswordOk;
+ String error;
+
+ public CheckPasswordService() {
+ super("CheckPasswordService");
+ }
+
+ public void onHandleIntent(Intent intent) {
+ String[] password = intent.getStringArrayExtra("params");
+ try {
+ String email = getPreyConfig().getEmail();
+ isPasswordOk = PreyWebServices.getInstance().checkPassword(this, email, password[0]);
+ } catch (PreyException e) {
+ error = e.getMessage();
+ }
+ Intent resultIntent = new Intent(PasswordActivity.CHECKPWD_FILTER);
+ resultIntent.putExtra("error", error);
+ resultIntent.putExtra("isPasswordOk", isPasswordOk);
+ sendBroadcast(resultIntent);
+ return;
+ }
+
+ private PreyConfig getPreyConfig() {
+ return PreyConfig.getPreyConfig(this);
+ }
+}
diff --git a/src/com/prey/services/CreateAccountService.java b/src/com/prey/services/CreateAccountService.java
new file mode 100644
index 00000000..4e76fa6f
--- /dev/null
+++ b/src/com/prey/services/CreateAccountService.java
@@ -0,0 +1,44 @@
+package com.prey.services;
+
+import android.app.IntentService;
+import android.content.Intent;
+
+import com.prey.PreyAccountData;
+import com.prey.PreyConfig;
+import com.prey.PreyLogger;
+import com.prey.PreyUtils;
+import com.prey.activities.CreateAccountActivity;
+import com.prey.exceptions.PreyException;
+import com.prey.net.PreyWebServices;
+
+public class CreateAccountService extends IntentService {
+ String error;
+
+ public CreateAccountService() {
+ super("CreateAccountService");
+ }
+
+ public void onHandleIntent(Intent intent) {
+ String[] data = intent.getStringArrayExtra("params");
+ try {
+ PreyAccountData accountData = PreyWebServices.getInstance()
+ .registerNewAccount(this, data[0], data[1], data[2], getDeviceType());
+ PreyLogger.d("Response creating account: " + accountData.toString());
+ getPreyConfig().saveAccount(accountData);
+ } catch (PreyException e) {
+ error = e.getMessage();
+ }
+ Intent resultIntent = new Intent(CreateAccountActivity.CREATEACCOUNT_FILTER);
+ resultIntent.putExtra("error", error);
+ sendBroadcast(resultIntent);
+ return;
+ }
+
+ private String getDeviceType() {
+ return PreyUtils.getDeviceType(this);
+ }
+
+ private PreyConfig getPreyConfig() {
+ return PreyConfig.getPreyConfig(this);
+ }
+}
diff --git a/src/com/prey/services/DetachDeviceService.java b/src/com/prey/services/DetachDeviceService.java
new file mode 100644
index 00000000..b71d00a8
--- /dev/null
+++ b/src/com/prey/services/DetachDeviceService.java
@@ -0,0 +1,33 @@
+package com.prey.services;
+
+import android.app.IntentService;
+import android.content.Intent;
+
+import com.prey.PreyConfig;
+import com.prey.exceptions.PreyException;
+import com.prey.net.PreyWebServices;
+import com.prey.preferences.DetachDevicePreferences;
+
+public class DetachDeviceService extends IntentService {
+ private String error;
+
+ public DetachDeviceService() {
+ super("DetachDeviceService");
+ }
+
+ public void onHandleIntent(Intent intent) {
+ try {
+ PreyConfig.getPreyConfig(this).unregisterC2dm(false);
+ PreyConfig.getPreyConfig(this).setSecurityPrivilegesAlreadyPrompted(false);
+ PreyWebServices.getInstance().deleteDevice(this);
+ PreyConfig.getPreyConfig(this).wipeData();
+ } catch (PreyException e) {
+ e.printStackTrace();
+ error = e.getMessage();
+ }
+ Intent resultIntent = new Intent(DetachDevicePreferences.DETACHDEVICE_FILTER);
+ resultIntent.putExtra("error", error);
+ sendBroadcast(resultIntent);
+ return;
+ }
+}
diff --git a/src/com/prey/services/RevokedPasswordPhraseService.java b/src/com/prey/services/RevokedPasswordPhraseService.java
new file mode 100644
index 00000000..3cbe9dc1
--- /dev/null
+++ b/src/com/prey/services/RevokedPasswordPhraseService.java
@@ -0,0 +1,30 @@
+package com.prey.services;
+
+import android.app.IntentService;
+import android.content.Intent;
+
+import com.prey.PreyConfig;
+import com.prey.PreyLogger;
+import com.prey.preferences.RevokedPasswordPreferences;
+
+public class RevokedPasswordPhraseService extends IntentService {
+ String error;
+
+ public RevokedPasswordPhraseService() {
+ super("RevokedPasswordPhraseService");
+ }
+
+ public void onHandleIntent(Intent intent) {
+ String data = intent.getStringExtra("param");
+ try {
+ PreyConfig preyConfig = PreyConfig.getPreyConfig(this);
+ PreyLogger.d("password [" + data + "]");
+ preyConfig.setRevokedPassword(true, data);
+ } catch (Exception e) {
+ error = e.getMessage();
+ }
+ Intent resultIntent = new Intent(RevokedPasswordPreferences.REVOKEDPWD_FILTER);
+ resultIntent.putExtra("error", error);
+ sendBroadcast(resultIntent);
+ }
+}