Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: broken tests
Browse files Browse the repository at this point in the history
ttypic committed Mar 20, 2024

Verified

This commit was signed with the committer’s verified signature.
sandhose Quentin Gliech
1 parent 53b4ae4 commit cc79da5
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -136,6 +136,11 @@ public class Options {
activationContext.setAbly(rest);
rest.setAndroidContext(context);

DebugOptions anonymousAblyOptions = new DebugOptions();
anonymousAblyOptions.httpListener = httpTracker;
AblyRest anonymousAbly = new AblyRest(anonymousAblyOptions);
activationContext.setAnonymousAbly(anonymousAbly);

adminRest = new AblyRest(options);
adminRest.auth.authorize(new Auth.TokenParams() {{
clientId = Auth.WILDCARD_CLIENTID;
21 changes: 21 additions & 0 deletions android/src/main/java/io/ably/lib/push/ActivationContext.java
Original file line number Diff line number Diff line change
@@ -4,13 +4,15 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import androidx.annotation.VisibleForTesting;
import com.google.firebase.messaging.FirebaseMessaging;

import java.util.WeakHashMap;

import io.ably.lib.rest.AblyRest;
import io.ably.lib.types.AblyException;
import io.ably.lib.types.Callback;
import io.ably.lib.types.ClientOptions;
import io.ably.lib.types.ErrorInfo;
import io.ably.lib.types.RegistrationToken;
import io.ably.lib.util.Log;
@@ -75,6 +77,24 @@ AblyRest getAbly() throws AblyException {
return (ably = new AblyRest(deviceIdentityToken));
}

@VisibleForTesting
public void setAnonymousAbly(AblyRest ably) {
this.anonymousAbly = ably;
}

/**
* @return AblyRest instance without any options including key or token auth. We use this instance to perform
* deregistration calls in push activation flow.
*/
AblyRest getAnonymousAbly() throws AblyException {
if (anonymousAbly == null) {
ClientOptions options = new ClientOptions();
options.authCallback = params -> null;
anonymousAbly = new AblyRest(options);
}
return anonymousAbly;
}

public boolean setClientId(String clientId, boolean propagateGotPushDeviceDetails) {
Log.v(TAG, "setClientId(): clientId=" + clientId + ", propagateGotPushDeviceDetails=" + propagateGotPushDeviceDetails);
boolean updated = !clientId.equals(this.clientId);
@@ -168,6 +188,7 @@ public static void setActivationContext(Context applicationContext, ActivationCo
}

protected AblyRest ably;
private AblyRest anonymousAbly;
protected String clientId;
protected ActivationStateMachine activationStateMachine;
protected LocalDevice localDevice;
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import io.ably.lib.rest.DeviceDetails;
import io.ably.lib.types.AblyException;
import io.ably.lib.types.Callback;
import io.ably.lib.types.ClientOptions;
import io.ably.lib.types.ErrorInfo;
import io.ably.lib.types.Param;
import io.ably.lib.types.RegistrationToken;
@@ -753,7 +752,7 @@ private void deregister() {
final AblyRest ably;
try {
// RSH3d2b: use `deviceIdentityToken` to perform request
ably = new AblyRest(new ClientOptions());
ably = activationContext.getAnonymousAbly();
} catch(AblyException ae) {
ErrorInfo reason = ae.errorInfo;
Log.e(TAG, "exception registering " + device.id + ": " + reason.toString());

0 comments on commit cc79da5

Please sign in to comment.