Consider unregistered if authorization fails.

This should only occur if another device has registered with the
same number, effectively making the current device unregistered.
This commit is contained in:
Moxie Marlinspike 2013-08-02 12:48:25 -07:00
parent 03ff55db97
commit cfb7b8fcba
3 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,9 @@
package org.whispersystems.textsecure.push;
import java.io.IOException;
public class AuthorizationFailedException extends IOException {
public AuthorizationFailedException(String s) {
super(s);
}
}

View File

@ -269,6 +269,10 @@ public class PushServiceSocket {
throw new RateLimitException("Rate limit exceeded: " + connection.getResponseCode());
}
if (connection.getResponseCode() == 403) {
throw new AuthorizationFailedException("Authorization failed!");
}
if (connection.getResponseCode() != 200) {
throw new IOException("Bad response: " + connection.getResponseCode() + " " + connection.getResponseMessage());
}

View File

@ -56,6 +56,7 @@ import org.thoughtcrime.securesms.util.MemoryCleaner;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Trimmer;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.textsecure.push.AuthorizationFailedException;
import org.whispersystems.textsecure.push.PushServiceSocket;
import java.io.IOException;
@ -358,8 +359,11 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
socket.unregisterGcmId();
GCMRegistrar.unregister(context);
return SUCCESS;
} catch (IOException e) {
Log.w("ApplicationPreferencesActivity", e);
} catch (AuthorizationFailedException afe) {
Log.w("ApplicationPreferencesActivity", afe);
return SUCCESS;
} catch (IOException ioe) {
Log.w("ApplicationPreferencesActivity", ioe);
return NETWORK_ERROR;
}
}