From 6f71243c43d90ab08fa4ec81785ef1a09b5b9442 Mon Sep 17 00:00:00 2001 From: satsukies Date: Thu, 22 Aug 2024 19:07:39 +0900 Subject: [PATCH 1/9] feat: add callback interface to receive the Capture creation event --- .../java/com/deploygate/sdk/DeployGate.java | 52 +++++++++++++++++++ .../sdk/DeployGateCaptureCreateCallback.java | 21 ++++++++ .../sdk/DeployGateSdkConfiguration.java | 19 ++++++- .../java/com/deploygate/sdk/DeployGate.java | 6 +++ .../sdk/DeployGateCaptureCreateCallback.java | 21 ++++++++ .../sdk/DeployGateSdkConfiguration.java | 4 ++ 6 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 sdk/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java create mode 100644 sdkMock/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java index 924395d..05e2c4b 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java @@ -68,6 +68,7 @@ public class DeployGate { private final HashSet mInitializeCallbacks; private final HashSet mStatusChangeCallbacks; private final HashSet mUpdateAvailableCallbacks; + private final HashSet mCaptureCreateCallbacks; private final HashMap mPendingEvents; private final String mExpectedAuthor; private String mAuthor; @@ -328,6 +329,7 @@ private DeployGate( mInitializeCallbacks = new HashSet<>(); mStatusChangeCallbacks = new HashSet<>(); mUpdateAvailableCallbacks = new HashSet<>(); + mCaptureCreateCallbacks = new HashSet<>(); mPendingEvents = new HashMap<>(); mExpectedAuthor = sdkConfiguration.appOwnerName; @@ -345,6 +347,10 @@ private DeployGate( mUpdateAvailableCallbacks.add(sdkConfiguration.updateAvailableCallback); } + if (sdkConfiguration.captureCreateCallback != null) { + mCaptureCreateCallbacks.add(sdkConfiguration.captureCreateCallback); + } + mInitializedLatch = new CountDownLatch(1); ((Application) applicationContext).registerActivityLifecycleCallbacks(new VisibilityLifecycleCallbacks(mOnVisibilityChangeListener)); initService(true); @@ -941,6 +947,52 @@ private void unregisterUpdateAvailableCallbackInternal(DeployGateUpdateAvailable mUpdateAvailableCallbacks.remove(callback); } + /** + * Register a callback listener about the new capture is created. + * Don't forget to unregister the callback listener when it is no longer needed (e.g., on destroying an activity.) + * If the listener has already in the callback list, just ignored. + * + * @param callback callback listener + * @see #unregisterCaptureCreateCallback(DeployGateCaptureCreateCallback) + * @since 4.9.0 + */ + public static void registerCaptureCreateCallback(DeployGateCaptureCreateCallback callback) { + if (sInstance == null) { + return; + } + if (callback == null) { + return; + } + + sInstance.registerCaptureCaptureCallbackInternal(callback); + } + + private void registerCaptureCaptureCallbackInternal(DeployGateCaptureCreateCallback callback) { + mCaptureCreateCallbacks.add(callback); + } + + /** + * Unregister a callback listener. + * If the listener was not registered, just ignored. + * + * @param callback callback listener to be removed + * @since 4.9.0 + */ + public static void unregisterCaptureCreateCallback(DeployGateCaptureCreateCallback callback) { + if (sInstance == null) { + return; + } + if (callback == null) { + return; + } + + sInstance.unregisterCaptureCaptureCallbackInternal(callback); + } + + private void unregisterCaptureCaptureCallbackInternal(DeployGateCaptureCreateCallback callback) { + mCaptureCreateCallbacks.remove(callback); + } + /** * Register a DeployGate event callback listener. Don't forget to call * {@link #unregisterCallback(DeployGateCallback)} when the callback is no diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java b/sdk/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java new file mode 100644 index 0000000..319b1ec --- /dev/null +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java @@ -0,0 +1,21 @@ +package com.deploygate.sdk; + +/** + * A callback interface to receive the capture creation event. + * + * @since 4.9.0 + * @see DeployGate#registerCaptureCreateCallback(DeployGateCaptureCreateCallback) + */ +public interface DeployGateCaptureCreateCallback { + /** + * Callback to tell the new capture is successfully created. + * + * @param captureUrl URL of the created capture + * @param createdAtMillis Created time of the capture in milliseconds + * @since 4.9.0 + */ + public void onCaptureCreated( + String captureUrl, + long createdAtMillis + ); +} diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java b/sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java index 13d08c0..635e7f3 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java @@ -15,6 +15,7 @@ public final class DeployGateSdkConfiguration { final DeployGateInitializeCallback initializeCallback; final DeployGateStatusChangeCallback statusChangeCallback; final DeployGateUpdateAvailableCallback updateAvailableCallback; + final DeployGateCaptureCreateCallback captureCreateCallback; final boolean isCaptureEnabled; @@ -30,7 +31,8 @@ private DeployGateSdkConfiguration( builder.isCaptureEnabled, builder.initializeCallback, builder.statusChangeCallback, - builder.updateAvailableCallback + builder.updateAvailableCallback, + builder.captureCreateCallback ); } @@ -43,7 +45,8 @@ private DeployGateSdkConfiguration( boolean isCaptureEnabled, DeployGateInitializeCallback initializeCallback, DeployGateStatusChangeCallback statusChangeCallback, - DeployGateUpdateAvailableCallback updateAvailableCallback + DeployGateUpdateAvailableCallback updateAvailableCallback, + DeployGateCaptureCreateCallback captureCallback ) { this.customLogConfiguration = customLogConfiguration; this.isDisabled = isDisabled; @@ -54,6 +57,7 @@ private DeployGateSdkConfiguration( this.initializeCallback = initializeCallback; this.statusChangeCallback = statusChangeCallback; this.updateAvailableCallback = updateAvailableCallback; + this.captureCreateCallback = captureCallback; } public static final class Builder { @@ -71,6 +75,7 @@ public static final class Builder { private DeployGateInitializeCallback initializeCallback = null; private DeployGateStatusChangeCallback statusChangeCallback = null; private DeployGateUpdateAvailableCallback updateAvailableCallback = null; + private DeployGateCaptureCreateCallback captureCreateCallback = null; public Builder() { } @@ -184,6 +189,16 @@ public Builder setUpdateAvailableCallback(DeployGateUpdateAvailableCallback upda return this; } + /** + * + * @param captureCallback Set an instance of callback for the capture creation event. + * @return self + */ + public Builder setCaptureCreateCallback(DeployGateCaptureCreateCallback captureCallback) { + this.captureCreateCallback = captureCallback; + return this; + } + /** * @return a new sdk configuration. */ diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGate.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGate.java index e7d3593..d2ccc67 100644 --- a/sdkMock/src/main/java/com/deploygate/sdk/DeployGate.java +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGate.java @@ -89,6 +89,12 @@ public static void registerUpdateAvailableCallback(DeployGateUpdateAvailableCall public static void unregisterUpdateAvailableCallback(DeployGateUpdateAvailableCallback callback) { } + public static void registerCaptureCreateCallback(DeployGateCaptureCreateCallback callback) { + } + + public static void unregisterCaptureCreateCallback(DeployGateCaptureCreateCallback callback) { + } + @Deprecated public static void registerCallback( DeployGateCallback listener, diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java new file mode 100644 index 0000000..319b1ec --- /dev/null +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java @@ -0,0 +1,21 @@ +package com.deploygate.sdk; + +/** + * A callback interface to receive the capture creation event. + * + * @since 4.9.0 + * @see DeployGate#registerCaptureCreateCallback(DeployGateCaptureCreateCallback) + */ +public interface DeployGateCaptureCreateCallback { + /** + * Callback to tell the new capture is successfully created. + * + * @param captureUrl URL of the created capture + * @param createdAtMillis Created time of the capture in milliseconds + * @since 4.9.0 + */ + public void onCaptureCreated( + String captureUrl, + long createdAtMillis + ); +} diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java index b512e88..b265ff4 100644 --- a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java @@ -49,6 +49,10 @@ public Builder setUpdateAvailableCallback(DeployGateUpdateAvailableCallback upda return this; } + public Builder setCaptureCreateCallback(DeployGateCaptureCreateCallback captureCreateCallback) { + return this; + } + public DeployGateSdkConfiguration build() { return new DeployGateSdkConfiguration(); } From 980e85816faceb2a0a9b02e2fcc7daf580396b99 Mon Sep 17 00:00:00 2001 From: satsukies Date: Thu, 22 Aug 2024 19:27:31 +0900 Subject: [PATCH 2/9] feat: add callback interface to receive the Capture creation event --- .../java/com/deploygate/sdk/DeployGate.java | 8 ++++- .../sdk/DeployGateInterfaceTest.java | 25 +++++++++++++ ...ployGateSdkConfigurationInterfaceTest.java | 35 +++++++++++++++++++ .../sdk/DeployGateSdkConfigurationTest.java | 12 ++++++- .../com/deploygate/sdk/DeployGateTest.java | 26 ++++++++++++++ 5 files changed, 104 insertions(+), 2 deletions(-) diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java index 05e2c4b..2afa645 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java @@ -303,7 +303,6 @@ public void run() { for (DeployGateStatusChangeCallback callback : mStatusChangeCallbacks) { callback.onStatusChanged(false, false, null, false); } - } }); } @@ -1723,4 +1722,11 @@ static HashSet getStatusChangeCallbacks() { static HashSet getUpdateAvailableCallbacks() { return sInstance != null ? sInstance.mUpdateAvailableCallbacks : null; } + + /** + * Not a public API. This is only for testing. + */ + static HashSet getCaptureCreateCallbacks() { + return sInstance != null ? sInstance.mCaptureCreateCallbacks : null; + } } diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java index b4f3727..6ecb23e 100644 --- a/sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java @@ -29,6 +29,7 @@ public class DeployGateInterfaceTest { DeployGateInitializeCallback initializeCallback; DeployGateStatusChangeCallback statusChangeCallback; DeployGateUpdateAvailableCallback updateAvailableCallback; + DeployGateCaptureCreateCallback captureCreateCallback; @Before public void setUp() { @@ -77,6 +78,12 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) // no-op } }; + captureCreateCallback = new DeployGateCaptureCreateCallback() { + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + // no-op + } + }; DeployGate.clear(); } @@ -240,6 +247,15 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) // no-op } }); + + DeployGate.registerCaptureCreateCallback(null); + DeployGate.registerCaptureCreateCallback(captureCreateCallback); + DeployGate.registerCaptureCreateCallback(new DeployGateCaptureCreateCallback() { + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + // no-op + } + }); } @Test @@ -298,6 +314,15 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) } }); DeployGate.unregisterUpdateAvailableCallback(updateAvailableCallback); + + DeployGate.unregisterCaptureCreateCallback(null); + DeployGate.unregisterCaptureCreateCallback(new DeployGateCaptureCreateCallback() { + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + // no-op + } + }); + DeployGate.unregisterCaptureCreateCallback(captureCreateCallback); } @Test diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java index 4be2682..c0bae77 100644 --- a/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java @@ -24,6 +24,7 @@ public class DeployGateSdkConfigurationInterfaceTest { DeployGateInitializeCallback initializeCallback; DeployGateStatusChangeCallback statusChangeCallback; DeployGateUpdateAvailableCallback updateAvailableCallback; + DeployGateCaptureCreateCallback captureCreateCallback; @Before public void setUp() { @@ -46,6 +47,30 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) // no-op } }; + initializeCallback = new DeployGateInitializeCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + }; + statusChangeCallback = new DeployGateStatusChangeCallback() { + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + }; + updateAvailableCallback = new DeployGateUpdateAvailableCallback() { + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }; + captureCreateCallback = new DeployGateCaptureCreateCallback() { + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + // no-op + } + }; } @Test @@ -125,6 +150,16 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) // no-op } }); + + // setCaptureCreateCallback + builder.setCaptureCreateCallback(null); + builder.setCaptureCreateCallback(captureCreateCallback); + builder.setCaptureCreateCallback(new DeployGateCaptureCreateCallback() { + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + // no-op + } + }); } @Test diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java index 4e201e6..f89dfab 100644 --- a/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java @@ -15,6 +15,7 @@ public class DeployGateSdkConfigurationTest { DeployGateInitializeCallback initializeCallback; DeployGateStatusChangeCallback statusChangeCallback; DeployGateUpdateAvailableCallback updateAvailableCallback; + DeployGateCaptureCreateCallback captureCreateCallback; DeployGateCallback deployGateCallback; @Before @@ -38,6 +39,12 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) // no-op } }; + captureCreateCallback = new DeployGateCaptureCreateCallback() { + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + + } + }; deployGateCallback = new DeployGateCallback() { @Override public void onInitialized(boolean isServiceAvailable) { @@ -59,7 +66,6 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) @Test public void builder() { - DeployGateSdkConfiguration configuration = new DeployGateSdkConfiguration.Builder() .setAppOwnerName("owner") .setCaptureEnabled(true) @@ -70,6 +76,7 @@ public void builder() { .setInitializeCallback(initializeCallback) .setStatusChangeCallback(statusChangeCallback) .setUpdateAvailableCallback(updateAvailableCallback) + .setCaptureCreateCallback(captureCreateCallback) .build(); Truth.assertThat(configuration.appOwnerName).isEqualTo("owner"); @@ -81,6 +88,7 @@ public void builder() { Truth.assertThat(configuration.initializeCallback).isEqualTo(initializeCallback); Truth.assertThat(configuration.statusChangeCallback).isEqualTo(statusChangeCallback); Truth.assertThat(configuration.updateAvailableCallback).isEqualTo(updateAvailableCallback); + Truth.assertThat(configuration.captureCreateCallback).isEqualTo(captureCreateCallback); } @Test @@ -100,11 +108,13 @@ public void builder_setXXXCallback() { .setInitializeCallback(initializeCallback) .setStatusChangeCallback(statusChangeCallback) .setUpdateAvailableCallback(updateAvailableCallback) + .setCaptureCreateCallback(captureCreateCallback) .build(); Truth.assertThat(configurationWithFineGrainedCallbacks.initializeCallback).isEqualTo(initializeCallback); Truth.assertThat(configurationWithFineGrainedCallbacks.statusChangeCallback).isEqualTo(statusChangeCallback); Truth.assertThat(configurationWithFineGrainedCallbacks.updateAvailableCallback).isEqualTo(updateAvailableCallback); + Truth.assertThat(configurationWithFineGrainedCallbacks.captureCreateCallback).isEqualTo(captureCreateCallback); } @Test diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateTest.java index ee0dc61..11fdc7c 100644 --- a/sdk/src/test/java/com/deploygate/sdk/DeployGateTest.java +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateTest.java @@ -27,6 +27,7 @@ public class DeployGateTest { DeployGateInitializeCallback initializeCallback; DeployGateStatusChangeCallback statusChangeCallback; DeployGateUpdateAvailableCallback updateAvailableCallback; + DeployGateCaptureCreateCallback captureCreateCallback; @Before public void setUp() { @@ -66,6 +67,12 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) // no-op } }; + captureCreateCallback = new DeployGateCaptureCreateCallback() { + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + // no-op + } + }; DeployGate.install(app, configuration); } @@ -95,14 +102,22 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) // no-op } }; + DeployGateCaptureCreateCallback anotherCaptureCreateCallback = new DeployGateCaptureCreateCallback() { + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + // no-op + } + }; Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(0); Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(0); Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(0); + Truth.assertThat(DeployGate.getCaptureCreateCallbacks().size()).isEqualTo(0); DeployGate.registerInitializeCallback(initializeCallback); DeployGate.registerStatusChangeCallback(statusChangeCallback); DeployGate.registerUpdateAvailableCallback(updateAvailableCallback); + DeployGate.registerCaptureCreateCallback(captureCreateCallback); Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); Truth.assertThat(DeployGate.getInitializeCallbacks().contains(initializeCallback)).isTrue(); @@ -113,41 +128,52 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().contains(updateAvailableCallback)).isTrue(); Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().contains(anotherUpdateAvailableCallback)).isFalse(); + Truth.assertThat(DeployGate.getCaptureCreateCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getCaptureCreateCallbacks().contains(captureCreateCallback)).isTrue(); + Truth.assertThat(DeployGate.getCaptureCreateCallbacks().contains(anotherCaptureCreateCallback)).isFalse(); // Each callback already registered before, so DeployGate maybe ignore this operation. DeployGate.registerInitializeCallback(initializeCallback); DeployGate.registerStatusChangeCallback(statusChangeCallback); DeployGate.registerUpdateAvailableCallback(updateAvailableCallback); + DeployGate.registerCaptureCreateCallback(captureCreateCallback); Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getCaptureCreateCallbacks().size()).isEqualTo(1); // register another callbacks DeployGate.registerInitializeCallback(anotherInitializeCallback); DeployGate.registerStatusChangeCallback(anotherStatusChangeCallback); DeployGate.registerUpdateAvailableCallback(anotherUpdateAvailableCallback); + DeployGate.registerCaptureCreateCallback(anotherCaptureCreateCallback); Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(2); Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(2); Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(2); + Truth.assertThat(DeployGate.getCaptureCreateCallbacks().size()).isEqualTo(2); DeployGate.unregisterInitializeCallback(initializeCallback); DeployGate.unregisterStatusChangeCallback(statusChangeCallback); DeployGate.unregisterUpdateAvailableCallback(updateAvailableCallback); + DeployGate.unregisterCaptureCreateCallback(captureCreateCallback); Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getCaptureCreateCallbacks().size()).isEqualTo(1); // Each callback already unregistered before, so DeployGate maybe ignore this operation. DeployGate.unregisterInitializeCallback(initializeCallback); DeployGate.unregisterStatusChangeCallback(statusChangeCallback); DeployGate.unregisterUpdateAvailableCallback(updateAvailableCallback); + DeployGate.unregisterCaptureCreateCallback(captureCreateCallback); Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getCaptureCreateCallbacks().size()).isEqualTo(1); } @Test From 3c5e4a3d36368c9f3b7fdf569a4b7478570ce0c5 Mon Sep 17 00:00:00 2001 From: satsukies Date: Thu, 22 Aug 2024 19:27:47 +0900 Subject: [PATCH 3/9] feat: call interface method when receive event --- .../java/com/deploygate/sdk/DeployGate.java | 22 +++++++++++++++++++ .../deploygate/service/DeployGateEvent.java | 15 +++++++++++++ 2 files changed, 37 insertions(+) diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java index 2afa645..410b09a 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java @@ -165,6 +165,28 @@ public void onEvent( } catch (Throwable t) { Logger.w(t, "failed to report device states"); } + } else if(DeployGateEvent.ACTION_CAPTURE_CREATED.equals(action)) { + final String captureUrl = extras.getString(DeployGateEvent.EXTRA_CAPTURE_URL); + final long captureCreatedAt = extras.getLong(DeployGateEvent.EXTRA_CAPTURE_CREATED_AT, -1); + + if (TextUtils.isEmpty(captureUrl)) { + Logger.w("Capture ID is missing in the extra"); + return; + } + + if (captureCreatedAt < 0) { + Logger.w("Capture created at is missing in the extra"); + return; + } + + mHandler.post(new Runnable() { + @Override + public void run() { + for (DeployGateCaptureCreateCallback callback : mCaptureCreateCallbacks) { + callback.onCaptureCreated(captureUrl, captureCreatedAt); + } + } + }); } else { Logger.w("%s is not supported by this sdk version", action); } diff --git a/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java b/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java index ad77118..dac4aef 100644 --- a/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java +++ b/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java @@ -33,6 +33,11 @@ public interface DeployGateEvent { */ public static final String ACTION_COLLECT_DEVICE_STATES = "a.collect-device-states"; + /** + * @since 4.9.0 + */ + public static final String ACTION_CAPTURE_CREATED = "a.capture-created"; + public static final String EXTRA_AUTHOR = "author"; public static final String EXTRA_EXPECTED_AUTHOR = "expectedAuthor"; @@ -116,6 +121,16 @@ public interface DeployGateEvent { */ public static final String EXTRA_CAPTURE_ID = "e.capture-id"; + /** + * the url of the capture. + */ + public static final String EXTRA_CAPTURE_URL = "e.capture-url"; + + /** + * the created time of the capture. + */ + public static final String EXTRA_CAPTURE_CREATED_AT = "e.capture-created-at"; + /** * A event type for the app goes to foreground/background. */ From 91d9107f138f159e0de8d68f5d8eb9e0493b423c Mon Sep 17 00:00:00 2001 From: satsukies Date: Thu, 22 Aug 2024 21:53:05 +0900 Subject: [PATCH 4/9] chore: use new interface in sample app --- sample/src/main/java/com/deploygate/sample/App.java | 5 +++++ .../java/com/deploygate/sample/SampleActivity.java | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sample/src/main/java/com/deploygate/sample/App.java b/sample/src/main/java/com/deploygate/sample/App.java index b4fc254..6512b5f 100644 --- a/sample/src/main/java/com/deploygate/sample/App.java +++ b/sample/src/main/java/com/deploygate/sample/App.java @@ -66,6 +66,11 @@ public void onCreate() { Log.i(TAG, message); DeployGate.logInfo(message); }) + .setCaptureCreateCallback((captureUrl, createdAtMillis) -> { + String message = String.format(Locale.US, "onCaptureCreated(%s)", captureUrl); + Log.i(TAG, message); + DeployGate.logInfo(message); + }) .setEnabledOnNonDebuggableBuild(true) .build(); diff --git a/sample/src/main/java/com/deploygate/sample/SampleActivity.java b/sample/src/main/java/com/deploygate/sample/SampleActivity.java index dd10d67..5b1cdb3 100644 --- a/sample/src/main/java/com/deploygate/sample/SampleActivity.java +++ b/sample/src/main/java/com/deploygate/sample/SampleActivity.java @@ -16,11 +16,12 @@ import com.deploygate.sdk.CustomAttributes; import com.deploygate.sdk.DeployGate; +import com.deploygate.sdk.DeployGateCaptureCreateCallback; import com.deploygate.sdk.DeployGateInitializeCallback; import com.deploygate.sdk.DeployGateStatusChangeCallback; import com.deploygate.sdk.DeployGateUpdateAvailableCallback; -public class SampleActivity extends Activity implements DeployGateInitializeCallback, DeployGateStatusChangeCallback, DeployGateUpdateAvailableCallback { +public class SampleActivity extends Activity implements DeployGateInitializeCallback, DeployGateStatusChangeCallback, DeployGateUpdateAvailableCallback, DeployGateCaptureCreateCallback { private static final String TAG = "SampleActivity"; @@ -74,6 +75,7 @@ protected void onResume() { DeployGate.registerInitializeCallback(this); DeployGate.registerStatusChangeCallback(this); DeployGate.registerUpdateAvailableCallback(this); + DeployGate.registerCaptureCreateCallback(this); // finally, call refresh() method if you want to check the status immediately DeployGate.refresh(); @@ -87,6 +89,7 @@ protected void onPause() { DeployGate.unregisterInitializeCallback(this); DeployGate.unregisterStatusChangeCallback(this); DeployGate.unregisterUpdateAvailableCallback(this); + DeployGate.unregisterCaptureCreateCallback(this); } @@ -245,4 +248,10 @@ public void onUpdateAvailable( mTitleText.setText(getString(R.string.update_available, serial, versionName, versionCode, message)); mUpdateButton.setVisibility(View.VISIBLE); } + + @Override + public void onCaptureCreated(String captureUrl, long createdAtMillis) { + Log.d(TAG, "Capture created: url=" + captureUrl + ", created_at=" + createdAtMillis); + Toast.makeText(this, "onCaptureCreated: " + captureUrl, Toast.LENGTH_LONG).show(); + } } From 018f4d9f7e08ebe613bb963a758f1dd0b72f7537 Mon Sep 17 00:00:00 2001 From: satsukies Date: Fri, 23 Aug 2024 11:26:14 +0900 Subject: [PATCH 5/9] chore: define default value --- sdk/src/main/java/com/deploygate/sdk/DeployGate.java | 4 ++-- .../main/java/com/deploygate/service/DeployGateEvent.java | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java index 410b09a..bd846b0 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java @@ -167,14 +167,14 @@ public void onEvent( } } else if(DeployGateEvent.ACTION_CAPTURE_CREATED.equals(action)) { final String captureUrl = extras.getString(DeployGateEvent.EXTRA_CAPTURE_URL); - final long captureCreatedAt = extras.getLong(DeployGateEvent.EXTRA_CAPTURE_CREATED_AT, -1); + final long captureCreatedAt = extras.getLong(DeployGateEvent.EXTRA_CAPTURE_CREATED_AT, DeployGateEvent.DEFAULT_EXTRA_CAPTURE_CREATE_AT); if (TextUtils.isEmpty(captureUrl)) { Logger.w("Capture ID is missing in the extra"); return; } - if (captureCreatedAt < 0) { + if (captureCreatedAt == DeployGateEvent.DEFAULT_EXTRA_CAPTURE_CREATE_AT) { Logger.w("Capture created at is missing in the extra"); return; } diff --git a/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java b/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java index dac4aef..7424d3c 100644 --- a/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java +++ b/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java @@ -171,4 +171,9 @@ interface VisibilityType { int BACKGROUND = 0; int FOREGROUND = 1; } + + /** + * Not a public value. This is only for internal. + */ + static final Long DEFAULT_EXTRA_CAPTURE_CREATE_AT = -1L; } From ae6fd866f6b9557d5eeda4a25b5d64412f15bdbf Mon Sep 17 00:00:00 2001 From: satsukies Date: Fri, 23 Aug 2024 11:26:45 +0900 Subject: [PATCH 6/9] chore: update sample code --- .../src/main/java/com/deploygate/sample/SampleActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sample/src/main/java/com/deploygate/sample/SampleActivity.java b/sample/src/main/java/com/deploygate/sample/SampleActivity.java index 5b1cdb3..b7ca597 100644 --- a/sample/src/main/java/com/deploygate/sample/SampleActivity.java +++ b/sample/src/main/java/com/deploygate/sample/SampleActivity.java @@ -251,7 +251,9 @@ public void onUpdateAvailable( @Override public void onCaptureCreated(String captureUrl, long createdAtMillis) { - Log.d(TAG, "Capture created: url=" + captureUrl + ", created_at=" + createdAtMillis); - Toast.makeText(this, "onCaptureCreated: " + captureUrl, Toast.LENGTH_LONG).show(); + // will be called when the capture is created + String message = "onCaptureCreated: url=" + captureUrl + ", created_at=" + createdAtMillis; + Log.d(TAG, message); + Toast.makeText(this, "onCaptureCreated called", Toast.LENGTH_LONG).show(); } } From 00e9cbe6db70958adbef50c7e060ac76bf46ddfc Mon Sep 17 00:00:00 2001 From: satsukies Date: Fri, 23 Aug 2024 11:39:17 +0900 Subject: [PATCH 7/9] chore: update some comments --- .../com/deploygate/sdk/DeployGateCaptureCreateCallback.java | 4 ++-- .../com/deploygate/sdk/DeployGateSdkConfigurationTest.java | 2 +- .../com/deploygate/sdk/DeployGateCaptureCreateCallback.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java b/sdk/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java index 319b1ec..3e52ef0 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java @@ -2,9 +2,9 @@ /** * A callback interface to receive the capture creation event. - * + * * @since 4.9.0 - * @see DeployGate#registerCaptureCreateCallback(DeployGateCaptureCreateCallback) + * @see DeployGate#registerCaptureCreateCallback(DeployGateCaptureCreateCallback) */ public interface DeployGateCaptureCreateCallback { /** diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java index f89dfab..f3efb4c 100644 --- a/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java @@ -42,7 +42,7 @@ public void onUpdateAvailable(int revision, String versionName, int versionCode) captureCreateCallback = new DeployGateCaptureCreateCallback() { @Override public void onCaptureCreated(String captureUrl, long createdAtMillis) { - + // no-op } }; deployGateCallback = new DeployGateCallback() { diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java index 319b1ec..3e52ef0 100644 --- a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCaptureCreateCallback.java @@ -2,9 +2,9 @@ /** * A callback interface to receive the capture creation event. - * + * * @since 4.9.0 - * @see DeployGate#registerCaptureCreateCallback(DeployGateCaptureCreateCallback) + * @see DeployGate#registerCaptureCreateCallback(DeployGateCaptureCreateCallback) */ public interface DeployGateCaptureCreateCallback { /** From b0d2e182ac5a182500a8f67db76f7bfa820114f3 Mon Sep 17 00:00:00 2001 From: satsukies Date: Mon, 26 Aug 2024 12:57:55 +0900 Subject: [PATCH 8/9] fix: delete definition of default value --- .../main/java/com/deploygate/service/DeployGateEvent.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java b/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java index 7424d3c..dac4aef 100644 --- a/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java +++ b/sdk/src/main/java/com/deploygate/service/DeployGateEvent.java @@ -171,9 +171,4 @@ interface VisibilityType { int BACKGROUND = 0; int FOREGROUND = 1; } - - /** - * Not a public value. This is only for internal. - */ - static final Long DEFAULT_EXTRA_CAPTURE_CREATE_AT = -1L; } From 5500cc90b68639801cc7ca434ca7f911a7b3d204 Mon Sep 17 00:00:00 2001 From: satsukies Date: Mon, 26 Aug 2024 16:48:03 +0900 Subject: [PATCH 9/9] fix: build failure caused by using the undefined constant --- sdk/src/main/java/com/deploygate/sdk/DeployGate.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java index bd846b0..410b09a 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java @@ -167,14 +167,14 @@ public void onEvent( } } else if(DeployGateEvent.ACTION_CAPTURE_CREATED.equals(action)) { final String captureUrl = extras.getString(DeployGateEvent.EXTRA_CAPTURE_URL); - final long captureCreatedAt = extras.getLong(DeployGateEvent.EXTRA_CAPTURE_CREATED_AT, DeployGateEvent.DEFAULT_EXTRA_CAPTURE_CREATE_AT); + final long captureCreatedAt = extras.getLong(DeployGateEvent.EXTRA_CAPTURE_CREATED_AT, -1); if (TextUtils.isEmpty(captureUrl)) { Logger.w("Capture ID is missing in the extra"); return; } - if (captureCreatedAt == DeployGateEvent.DEFAULT_EXTRA_CAPTURE_CREATE_AT) { + if (captureCreatedAt < 0) { Logger.w("Capture created at is missing in the extra"); return; }