Skip to content

Commit

Permalink
Prevent try unregister after first success attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpassos committed Feb 6, 2015
1 parent fd0ad29 commit 4c17fd3
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class AeroGearGCMPushRegistrar implements PushRegistrar {
private static final String PROPERTY_ON_SERVER_EXPIRATION_TIME = "onServerExpirationTimeMs";
private static final String registryDeviceEndpoint = "/rest/registry/device";

private static final String DEVICE_ALREADY_UNREGISTERED = "Seems this device was already unregistered";

private final PushConfig config;
private URL deviceRegistryURL;

Expand Down Expand Up @@ -181,14 +183,26 @@ protected void onPostExecute(Exception result) {

}

/**
* Unregister device from Unified Push Server.
*
* if the device isn't registered onFailure will be called
*
* @param context Android application context
* @param callback a callback.
*/
@Override
public void unregister(final Context context, final Callback<Void> callback) {
new AsyncTask<Void, Void, Exception>() {
AsyncTask<Void, Void, Exception> execute = new AsyncTask<Void, Void, Exception>() {
@Override
protected Exception doInBackground(Void... params) {

try {

if ((config.getDeviceToken()) == null || (config.getDeviceToken().trim().equals(""))) {
throw new IllegalStateException(DEVICE_ALREADY_UNREGISTERED);
}

if (gcm == null) {
gcm = gcmProvider.get(context);
}
Expand Down

0 comments on commit 4c17fd3

Please sign in to comment.