diff --git a/sample/src/main/java/com/deploygate/sample/App.java b/sample/src/main/java/com/deploygate/sample/App.java index 6bc710c..b4fc254 100644 --- a/sample/src/main/java/com/deploygate/sample/App.java +++ b/sample/src/main/java/com/deploygate/sample/App.java @@ -7,7 +7,7 @@ import com.deploygate.sdk.CustomAttributes; import com.deploygate.sdk.DeployGate; -import com.deploygate.sdk.DeployGateCallback; +import com.deploygate.sdk.DeployGateSdkConfiguration; import java.util.Locale; @@ -27,12 +27,10 @@ public void onCreate() { // Note that you also need to edit your AndroidManifest.xml to activate customized initializer. // Refer the comment on stableReal/AndroidManifest.xml included in this sample. - DeployGate.install(this, new DeployGateCallback() { + DeployGateSdkConfiguration configuration = new DeployGateSdkConfiguration.Builder() // Please note that this callback is called iff you have removed the content provider. - // For those who wanna use the content provider, SDK provides DeployGate#registerCallback for your use-case. - - @Override - public void onInitialized(boolean isServiceAvailable) { + // For those who wanna use the content provider, SDK provides DeployGate#registerXXXCallback for your use-case. + .setInitializeCallback(isServiceAvailable -> { if (isServiceAvailable) { Log.i(TAG, "SDK is available"); DeployGate.logInfo("SDK is available"); @@ -44,49 +42,39 @@ public void onInitialized(boolean isServiceAvailable) { Log.i(TAG, "SDK is unavailable"); DeployGate.logInfo("SDK is unavailable"); // this fails silently } - } - - @Override - public void onStatusChanged( - boolean isManaged, - boolean isAuthorized, - String loginUsername, - boolean isStopped - ) { + }) + .setStatusChangeCallback((isManaged, isAuthorized, loginUsername, isStopped) -> { Bundle bundle = new Bundle(); bundle.putBoolean("isManaged", isManaged); bundle.putBoolean("isAuthorized", isAuthorized); bundle.putString("loginUsername", loginUsername); bundle.putBoolean("isStopped", isStopped); - String message = String.format(Locale.US, "onStatusChanged(%s)", bundle.toString()); + String message = String.format(Locale.US, "onStatusChanged(%s)", bundle); Log.i(TAG, message); DeployGate.logInfo(message); - } - - @Override - public void onUpdateAvailable( - int revision, - String versionName, - int versionCode - ) { + }) + .setUpdateAvailableCallback((revision, versionName, versionCode) -> { Bundle bundle = new Bundle(); bundle.putInt("revision", revision); bundle.putString("versionName", versionName); bundle.putInt("versionCode", versionCode); - String message = String.format(Locale.US, "onUpdateAvailable(%s)", bundle.toString()); + String message = String.format(Locale.US, "onUpdateAvailable(%s)", bundle); Log.i(TAG, message); DeployGate.logInfo(message); - } - }, true); + }) + .setEnabledOnNonDebuggableBuild(true) + .build(); + + DeployGate.install(this, configuration); // If you want to prevent the app distributed by someone else, specify your username on DeployGate - // as a second argument of DeployGate.install, like: + // with setAuthor method when creating DeployGate SdkConfiguration. like: // - // DeployGate.install(this, "YOURUSERNAME"); + // builder.setAuthor("YOURUSERNAME"); // // You can use DeployGate.isAuthorized() later to check the installation is valid or not. } diff --git a/sample/src/main/java/com/deploygate/sample/SampleActivity.java b/sample/src/main/java/com/deploygate/sample/SampleActivity.java index 639f2b0..dd10d67 100644 --- a/sample/src/main/java/com/deploygate/sample/SampleActivity.java +++ b/sample/src/main/java/com/deploygate/sample/SampleActivity.java @@ -16,9 +16,11 @@ import com.deploygate.sdk.CustomAttributes; import com.deploygate.sdk.DeployGate; -import com.deploygate.sdk.DeployGateCallback; +import com.deploygate.sdk.DeployGateInitializeCallback; +import com.deploygate.sdk.DeployGateStatusChangeCallback; +import com.deploygate.sdk.DeployGateUpdateAvailableCallback; -public class SampleActivity extends Activity implements DeployGateCallback { +public class SampleActivity extends Activity implements DeployGateInitializeCallback, DeployGateStatusChangeCallback, DeployGateUpdateAvailableCallback { private static final String TAG = "SampleActivity"; @@ -68,8 +70,13 @@ public void onCreate(Bundle savedInstanceState) { protected void onResume() { super.onResume(); - // register for callback, also request refreshing (second argument) - DeployGate.registerCallback(this, true); + // register for callbacks + DeployGate.registerInitializeCallback(this); + DeployGate.registerStatusChangeCallback(this); + DeployGate.registerUpdateAvailableCallback(this); + + // finally, call refresh() method if you want to check the status immediately + DeployGate.refresh(); } @Override @@ -77,7 +84,9 @@ protected void onPause() { super.onPause(); // unregister to stop callback - DeployGate.unregisterCallback(this); + DeployGate.unregisterInitializeCallback(this); + DeployGate.unregisterStatusChangeCallback(this); + DeployGate.unregisterUpdateAvailableCallback(this); } diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java index 79db2bd..924395d 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGate.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGate.java @@ -24,8 +24,6 @@ import com.deploygate.service.IDeployGateSdkService; import com.deploygate.service.IDeployGateSdkServiceCallback; -import org.json.JSONObject; - import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -67,7 +65,9 @@ public class DeployGate { private final Handler mHandler; private final ILogcatInstructionSerializer mLogcatInstructionSerializer; private final CustomLogInstructionSerializer mCustomLogInstructionSerializer; - private final HashSet mCallbacks; + private final HashSet mInitializeCallbacks; + private final HashSet mStatusChangeCallbacks; + private final HashSet mUpdateAvailableCallbacks; private final HashMap mPendingEvents; private final String mExpectedAuthor; private String mAuthor; @@ -194,8 +194,13 @@ private void onInitialized( mHandler.post(new Runnable() { @Override public void run() { - for (DeployGateCallback callback : mCallbacks) { + // call onInitialized on each callbacks + for (DeployGateInitializeCallback callback : mInitializeCallbacks) { callback.onInitialized(true); + } + + // after call onInitialized, then call onStatusChanged + for (DeployGateStatusChangeCallback callback : mStatusChangeCallbacks) { callback.onStatusChanged(isManaged, isAuthorized, loginUsername, isStopped); } } @@ -229,7 +234,7 @@ private void onUpdateArrived( mHandler.post(new Runnable() { @Override public void run() { - for (DeployGateCallback callback : mCallbacks) { + for (DeployGateUpdateAvailableCallback callback : mUpdateAvailableCallbacks) { callback.onUpdateAvailable(serial, versionName, versionCode); } } @@ -288,10 +293,16 @@ void callbackDeployGateUnavailable() { mHandler.post(new Runnable() { @Override public void run() { - for (DeployGateCallback callback : mCallbacks) { + // call onInitialized on each callbacks + for (DeployGateInitializeCallback callback : mInitializeCallbacks) { callback.onInitialized(false); + } + + // after call onInitialized, then call onStatusChanged + for (DeployGateStatusChangeCallback callback : mStatusChangeCallbacks) { callback.onStatusChanged(false, false, null, false); } + } }); } @@ -314,14 +325,24 @@ private DeployGate( mHandler = new Handler(); mLogcatInstructionSerializer = mHostApp.canUseLogcat ? new LogcatInstructionSerializer(mHostApp.packageName) : ILogcatInstructionSerializer.NULL_INSTANCE; mCustomLogInstructionSerializer = new CustomLogInstructionSerializer(mHostApp.packageName, sdkConfiguration.customLogConfiguration); - mCallbacks = new HashSet<>(); + mInitializeCallbacks = new HashSet<>(); + mStatusChangeCallbacks = new HashSet<>(); + mUpdateAvailableCallbacks = new HashSet<>(); mPendingEvents = new HashMap<>(); mExpectedAuthor = sdkConfiguration.appOwnerName; prepareBroadcastReceiver(); - if (sdkConfiguration.callback != null) { - mCallbacks.add(sdkConfiguration.callback); + if (sdkConfiguration.initializeCallback != null) { + mInitializeCallbacks.add(sdkConfiguration.initializeCallback); + } + + if (sdkConfiguration.statusChangeCallback != null) { + mStatusChangeCallbacks.add(sdkConfiguration.statusChangeCallback); + } + + if (sdkConfiguration.updateAvailableCallback != null) { + mUpdateAvailableCallbacks.add(sdkConfiguration.updateAvailableCallback); } mInitializedLatch = new CountDownLatch(1); @@ -782,6 +803,144 @@ private void refreshInternal() { } } + /** + * Register a callback listener about the DeployGate initialization event. + * Don't forget to call {@link #unregisterInitializeCallback(DeployGateInitializeCallback)} + * when the callback 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 + * @since 4.9.0 + */ + public static void registerInitializeCallback(DeployGateInitializeCallback callback) { + if (sInstance == null) { + return; + } + if (callback == null) { + return; + } + + sInstance.registerInitializeCallbackInternal(callback); + } + + private void registerInitializeCallbackInternal(DeployGateInitializeCallback callback) { + mInitializeCallbacks.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 unregisterInitializeCallback(DeployGateInitializeCallback callback) { + if (sInstance == null) { + return; + } + if (callback == null) { + return; + } + + sInstance.unregisterInitializeCallbackInternal(callback); + } + + private void unregisterInitializeCallbackInternal(DeployGateInitializeCallback callback) { + mInitializeCallbacks.remove(callback); + } + + /** + * Register a callback listener about the app status on DeployGate. + * Don't forget to call {@link #unregisterStatusChangeCallback(DeployGateStatusChangeCallback)} + * when the callback 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 + * @since 4.9.0 + */ + public static void registerStatusChangeCallback(DeployGateStatusChangeCallback callback) { + if (sInstance == null) { + return; + } + if (callback == null) { + return; + } + + sInstance.registerStatusChangeCallbackInternal(callback); + } + + private void registerStatusChangeCallbackInternal(DeployGateStatusChangeCallback callback) { + mStatusChangeCallbacks.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 unregisterStatusChangeCallback(DeployGateStatusChangeCallback callback) { + if (sInstance == null) { + return; + } + if (callback == null) { + return; + } + + sInstance.unregisterStatusChangeCallbackInternal(callback); + } + + private void unregisterStatusChangeCallbackInternal(DeployGateStatusChangeCallback callback) { + mStatusChangeCallbacks.remove(callback); + } + + /** + * Register a callback listener about the new version of the app is available. + * Don't forget to call {@link #unregisterUpdateAvailableCallback(DeployGateUpdateAvailableCallback)} + * when the callback 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 + * @since 4.9.0 + */ + public static void registerUpdateAvailableCallback(DeployGateUpdateAvailableCallback callback) { + if (sInstance == null) { + return; + } + if (callback == null) { + return; + } + + sInstance.registerUpdateAvailableCallbackInternal(callback); + } + + private void registerUpdateAvailableCallbackInternal(DeployGateUpdateAvailableCallback callback) { + mUpdateAvailableCallbacks.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 unregisterUpdateAvailableCallback(DeployGateUpdateAvailableCallback callback) { + if (sInstance == null) { + return; + } + if (callback == null) { + return; + } + + sInstance.unregisterUpdateAvailableCallbackInternal(callback); + } + + private void unregisterUpdateAvailableCallbackInternal(DeployGateUpdateAvailableCallback callback) { + mUpdateAvailableCallbacks.remove(callback); + } + /** * Register a DeployGate event callback listener. Don't forget to call * {@link #unregisterCallback(DeployGateCallback)} when the callback is no @@ -795,7 +954,12 @@ private void refreshInternal() { * true. * * @since r1 + * @deprecated since 4.9.0. Use each register method for separated callbacks instead. + * @see #registerInitializeCallback(DeployGateInitializeCallback) + * @see #registerStatusChangeCallback(DeployGateStatusChangeCallback) + * @see #registerUpdateAvailableCallback(DeployGateUpdateAvailableCallback) */ + @Deprecated public static void registerCallback( DeployGateCallback listener, boolean refreshImmediately @@ -814,7 +978,10 @@ private void registerCallbackInternal( DeployGateCallback listener, boolean callbackImmediately ) { - mCallbacks.add(listener); + mInitializeCallbacks.add(listener); + mStatusChangeCallbacks.add(listener); + mUpdateAvailableCallbacks.add(listener); + if (callbackImmediately) { refresh(); } @@ -828,8 +995,13 @@ private void registerCallbackInternal( * callback listener to be removed * * @since r1 + * @deprecated since 4.9.0. Use each unregister method for separated callbacks instead. + * @see #unregisterInitializeCallback(DeployGateInitializeCallback) + * @see #unregisterStatusChangeCallback(DeployGateStatusChangeCallback) + * @see #unregisterUpdateAvailableCallback(DeployGateUpdateAvailableCallback) */ - public static void unregisterCallback(DeployGateCallback listener) { + @Deprecated + public static void unregisterCallback(final DeployGateCallback listener) { if (sInstance == null) { return; } @@ -837,7 +1009,13 @@ public static void unregisterCallback(DeployGateCallback listener) { return; } - sInstance.mCallbacks.remove(listener); + sInstance.unregisterCallbackInternal(listener); + } + + private void unregisterCallbackInternal(DeployGateCallback listener) { + mInitializeCallbacks.remove(listener); + mStatusChangeCallbacks.remove(listener); + mUpdateAvailableCallbacks.remove(listener); } /** @@ -1472,4 +1650,25 @@ private static CustomAttributes getSdkDeviceStates() { return sSdkDeviceStates; } + + /** + * Not a public API. This is only for testing. + */ + static HashSet getInitializeCallbacks() { + return sInstance != null ? sInstance.mInitializeCallbacks : null; + } + + /** + * Not a public API. This is only for testing. + */ + static HashSet getStatusChangeCallbacks() { + return sInstance != null ? sInstance.mStatusChangeCallbacks : null; + } + + /** + * Not a public API. This is only for testing. + */ + static HashSet getUpdateAvailableCallbacks() { + return sInstance != null ? sInstance.mUpdateAvailableCallbacks : null; + } } diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGateCallback.java b/sdk/src/main/java/com/deploygate/sdk/DeployGateCallback.java index 8df3686..e54d6a8 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGateCallback.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGateCallback.java @@ -1,60 +1,14 @@ package com.deploygate.sdk; - /** - * A callback interface to receive DeployGate events. Implement this and pass to - * {@link DeployGate#registerCallback(DeployGateCallback, boolean)} to listen. + * A callback interface to receive DeployGate events. * * @author tnj + * @deprecated since 4.9.0. Use fine-grained callback interfaces for each purpose. + * @see com.deploygate.sdk.DeployGateInitializeCallback + * @see com.deploygate.sdk.DeployGateStatusChangeCallback + * @see com.deploygate.sdk.DeployGateUpdateAvailableCallback */ -public interface DeployGateCallback { - /** - * Callback to tell the finish of DeployGate service initialization - * procedure. - * - * @param isServiceAvailable - * true if DeployGate service is available on the - * device. - */ - public void onInitialized(boolean isServiceAvailable); - - /** - * Callback to tell the app status on the DeployGate has changed. This will - * also be called back just after {@link #onInitialized(boolean)}, - * {@link DeployGate#refresh()} and - * {@link DeployGate#registerCallback(DeployGateCallback, boolean)} with - * true in second argument. - * - * @param isManaged - * true if the app is known on DeployGate app - * @param isAuthorized - * true if the app is on current user's installed list - * @param loginUsername - * Current login username, returned only when - * isAuthorized is true. - * @param isStopped - * Reserved. - */ - public void onStatusChanged( - boolean isManaged, - boolean isAuthorized, - String loginUsername, - boolean isStopped - ); - - /** - * Callback to tell the new version is available. - * - * @param revision - * revision of new version - * @param versionName - * user-defined version name of new version - * @param versionCode - * user-defined version code of new version - */ - public void onUpdateAvailable( - int revision, - String versionName, - int versionCode - ); -} +@Deprecated +public interface DeployGateCallback extends DeployGateInitializeCallback, DeployGateStatusChangeCallback, DeployGateUpdateAvailableCallback { +} \ No newline at end of file diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGateInitializeCallback.java b/sdk/src/main/java/com/deploygate/sdk/DeployGateInitializeCallback.java new file mode 100644 index 0000000..9288a43 --- /dev/null +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGateInitializeCallback.java @@ -0,0 +1,18 @@ +package com.deploygate.sdk; + +/** + * A callback interface to receive DeployGate service initialization events. + * + * @since 4.9.0. + * @see DeployGate#registerInitializeCallback(DeployGateInitializeCallback) + */ +public interface DeployGateInitializeCallback { + /** + * Callback to tell the finish of DeployGate service initialization + * procedure. + * + * @param isServiceAvailable true if DeployGate service is available on the + * device. + */ + public void onInitialized(boolean isServiceAvailable); +} diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java b/sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java index 3250aed..13d08c0 100644 --- a/sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java @@ -12,8 +12,9 @@ public final class DeployGateSdkConfiguration { final boolean isCrashReportingEnabled; - - final DeployGateCallback callback; + final DeployGateInitializeCallback initializeCallback; + final DeployGateStatusChangeCallback statusChangeCallback; + final DeployGateUpdateAvailableCallback updateAvailableCallback; final boolean isCaptureEnabled; @@ -27,7 +28,9 @@ private DeployGateSdkConfiguration( builder.appOwnerName, builder.isCrashReportingEnabled, builder.isCaptureEnabled, - builder.callback + builder.initializeCallback, + builder.statusChangeCallback, + builder.updateAvailableCallback ); } @@ -38,7 +41,9 @@ private DeployGateSdkConfiguration( String appOwnerName, boolean isCrashReportingEnabled, boolean isCaptureEnabled, - DeployGateCallback callback + DeployGateInitializeCallback initializeCallback, + DeployGateStatusChangeCallback statusChangeCallback, + DeployGateUpdateAvailableCallback updateAvailableCallback ) { this.customLogConfiguration = customLogConfiguration; this.isDisabled = isDisabled; @@ -46,7 +51,9 @@ private DeployGateSdkConfiguration( this.appOwnerName = appOwnerName; this.isCrashReportingEnabled = isCrashReportingEnabled; this.isCaptureEnabled = isCaptureEnabled; - this.callback = callback; + this.initializeCallback = initializeCallback; + this.statusChangeCallback = statusChangeCallback; + this.updateAvailableCallback = updateAvailableCallback; } public static final class Builder { @@ -61,7 +68,9 @@ public static final class Builder { private boolean isCaptureEnabled = true; - private DeployGateCallback callback = null; + private DeployGateInitializeCallback initializeCallback = null; + private DeployGateStatusChangeCallback statusChangeCallback = null; + private DeployGateUpdateAvailableCallback updateAvailableCallback = null; public Builder() { } @@ -147,9 +156,31 @@ public Builder setCrashReportingEnabled(boolean crashReportingEnabled) { * @param callback * Set an instance of callback. The reference won't be released. Please use {@link DeployGate#registerCallback(DeployGateCallback, boolean)} for memory sensitive works. * @return self + * @deprecated since 4.9.0. Use each extended callback interfaces instead. + * @see #setInitializeCallback(DeployGateInitializeCallback) + * @see #setStatusChangeCallback(DeployGateStatusChangeCallback) + * @see #setUpdateAvailableCallback(DeployGateUpdateAvailableCallback) */ + @Deprecated public Builder setCallback(DeployGateCallback callback) { - this.callback = callback; + setInitializeCallback(callback); + setStatusChangeCallback(callback); + setUpdateAvailableCallback(callback); + return this; + } + + public Builder setInitializeCallback(DeployGateInitializeCallback initializeCallback) { + this.initializeCallback = initializeCallback; + return this; + } + + public Builder setStatusChangeCallback(DeployGateStatusChangeCallback statusChangeCallback) { + this.statusChangeCallback = statusChangeCallback; + return this; + } + + public Builder setUpdateAvailableCallback(DeployGateUpdateAvailableCallback updateAvailableCallback) { + this.updateAvailableCallback = updateAvailableCallback; return this; } diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGateStatusChangeCallback.java b/sdk/src/main/java/com/deploygate/sdk/DeployGateStatusChangeCallback.java new file mode 100644 index 0000000..e00822f --- /dev/null +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGateStatusChangeCallback.java @@ -0,0 +1,27 @@ +package com.deploygate.sdk; + +/** + * A callback interface to receive the app status on the DeployGate. + * + * @since 4.9.0. + * @see DeployGate#registerStatusChangeCallback(DeployGateStatusChangeCallback) + */ +public interface DeployGateStatusChangeCallback { + /** + * Callback to tell the app status on the DeployGate has changed. This will + * also be called back just after {@link DeployGateInitializeCallback#onInitialized(boolean)}, + * {@link DeployGate#refresh()}. + * + * @param isManaged true if the app is known on DeployGate app + * @param isAuthorized true if the app is on current user's installed list + * @param loginUsername Current login username, returned only when + * isAuthorized is true. + * @param isStopped Reserved. + */ + public void onStatusChanged( + boolean isManaged, + boolean isAuthorized, + String loginUsername, + boolean isStopped + ); +} diff --git a/sdk/src/main/java/com/deploygate/sdk/DeployGateUpdateAvailableCallback.java b/sdk/src/main/java/com/deploygate/sdk/DeployGateUpdateAvailableCallback.java new file mode 100644 index 0000000..96eaf4b --- /dev/null +++ b/sdk/src/main/java/com/deploygate/sdk/DeployGateUpdateAvailableCallback.java @@ -0,0 +1,22 @@ +package com.deploygate.sdk; + +/** + * A callback interface to receive the app update event. + * + * @since 4.9.0. + * @see DeployGate#registerUpdateAvailableCallback(DeployGateUpdateAvailableCallback) + */ +public interface DeployGateUpdateAvailableCallback { + /** + * Callback to tell the new version is available. + * + * @param revision revision of new version + * @param versionName user-defined version name of new version + * @param versionCode user-defined version code of new version + */ + public void onUpdateAvailable( + int revision, + String versionName, + int versionCode + ); +} diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java index 62684ee..b4f3727 100644 --- a/sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateInterfaceTest.java @@ -26,6 +26,9 @@ public class DeployGateInterfaceTest { Application app; DeployGateCallback callback; + DeployGateInitializeCallback initializeCallback; + DeployGateStatusChangeCallback statusChangeCallback; + DeployGateUpdateAvailableCallback updateAvailableCallback; @Before public void setUp() { @@ -56,6 +59,24 @@ public void onUpdateAvailable( } }; + 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 + } + }; DeployGate.clear(); } @@ -192,6 +213,33 @@ public void onUpdateAvailable( } }, false); + + DeployGate.registerInitializeCallback(null); + DeployGate.registerInitializeCallback(initializeCallback); + DeployGate.registerInitializeCallback(new DeployGateInitializeCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + }); + + DeployGate.registerStatusChangeCallback(null); + DeployGate.registerStatusChangeCallback(statusChangeCallback); + DeployGate.registerStatusChangeCallback(new DeployGateStatusChangeCallback() { + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + }); + + DeployGate.registerUpdateAvailableCallback(null); + DeployGate.registerUpdateAvailableCallback(updateAvailableCallback); + DeployGate.registerUpdateAvailableCallback(new DeployGateUpdateAvailableCallback() { + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }); } @Test @@ -200,7 +248,7 @@ public void unregisterCallback() { DeployGate.unregisterCallback(new DeployGateCallback() { @Override public void onInitialized(boolean isServiceAvailable) { - + // no-op } @Override @@ -210,7 +258,7 @@ public void onStatusChanged( String loginUsername, boolean isStopped ) { - + // no-op } @Override @@ -219,10 +267,37 @@ public void onUpdateAvailable( String versionName, int versionCode ) { - + // no-op } }); DeployGate.unregisterCallback(callback); + + DeployGate.unregisterInitializeCallback(null); + DeployGate.unregisterInitializeCallback(new DeployGateInitializeCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + }); + DeployGate.unregisterInitializeCallback(initializeCallback); + + DeployGate.unregisterStatusChangeCallback(null); + DeployGate.unregisterStatusChangeCallback(new DeployGateStatusChangeCallback() { + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + }); + DeployGate.unregisterStatusChangeCallback(statusChangeCallback); + + DeployGate.unregisterUpdateAvailableCallback(null); + DeployGate.unregisterUpdateAvailableCallback(new DeployGateUpdateAvailableCallback() { + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }); + DeployGate.unregisterUpdateAvailableCallback(updateAvailableCallback); } @Test diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java new file mode 100644 index 0000000..4be2682 --- /dev/null +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java @@ -0,0 +1,134 @@ +package com.deploygate.sdk; + +import androidx.annotation.NonNull; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.google.common.truth.Truth; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * This test class will make sure all *public* interfaces are defined as expected. + */ +@RunWith(AndroidJUnit4.class) +public class DeployGateSdkConfigurationInterfaceTest { + + @NonNull + DeployGateSdkConfiguration.Builder builder; + + CustomLogConfiguration customLogConfiguration; + String appOwnerName; + DeployGateCallback callback; + DeployGateInitializeCallback initializeCallback; + DeployGateStatusChangeCallback statusChangeCallback; + DeployGateUpdateAvailableCallback updateAvailableCallback; + + @Before + public void setUp() { + builder = new DeployGateSdkConfiguration.Builder(); + customLogConfiguration = new CustomLogConfiguration.Builder().build(); + appOwnerName = "owner"; + callback = new DeployGateCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }; + } + + @Test + public void builder__set_method() { + // setCustomLogConfiguration + builder.setCustomLogConfiguration(null); + builder.setCustomLogConfiguration(customLogConfiguration); + builder.setCustomLogConfiguration(new CustomLogConfiguration.Builder().build()); + + // setAppOwnerName + builder.setAppOwnerName(null); + builder.setAppOwnerName(appOwnerName); + builder.setAppOwnerName("owner"); + + // setDisabled + builder.setDisabled(true); + builder.setDisabled(false); + + // setEnabledOnNonDebuggableBuild + builder.setEnabledOnNonDebuggableBuild(true); + builder.setEnabledOnNonDebuggableBuild(false); + + // setCaptureEnabled + builder.setCaptureEnabled(true); + builder.setCaptureEnabled(false); + + // setCrashReportingEnabled + builder.setCrashReportingEnabled(true); + builder.setCrashReportingEnabled(false); + + // setCallback + builder.setCallback(null); + builder.setCallback(callback); + builder.setCallback(new DeployGateCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }); + + // setInitializeCallback + builder.setInitializeCallback(null); + builder.setInitializeCallback(initializeCallback); + builder.setInitializeCallback(new DeployGateInitializeCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + }); + + // setStatusChangeCallback + builder.setStatusChangeCallback(null); + builder.setStatusChangeCallback(statusChangeCallback); + builder.setStatusChangeCallback(new DeployGateStatusChangeCallback() { + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + }); + + // setUpdateAvailableCallback + builder.setUpdateAvailableCallback(null); + builder.setUpdateAvailableCallback(updateAvailableCallback); + builder.setUpdateAvailableCallback(new DeployGateUpdateAvailableCallback() { + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }); + } + + @Test + public void builder__build() { + Truth.assertThat(builder.build()).isNotNull(); + } +} diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java new file mode 100644 index 0000000..4e201e6 --- /dev/null +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationTest.java @@ -0,0 +1,157 @@ +package com.deploygate.sdk; + +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.google.common.truth.Truth; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class DeployGateSdkConfigurationTest { + + CustomLogConfiguration customLogConfiguration; + DeployGateInitializeCallback initializeCallback; + DeployGateStatusChangeCallback statusChangeCallback; + DeployGateUpdateAvailableCallback updateAvailableCallback; + DeployGateCallback deployGateCallback; + + @Before + public void setUp() { + customLogConfiguration = new CustomLogConfiguration.Builder().build(); + 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 + } + }; + deployGateCallback = new DeployGateCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }; + } + + + @Test + public void builder() { + + DeployGateSdkConfiguration configuration = new DeployGateSdkConfiguration.Builder() + .setAppOwnerName("owner") + .setCaptureEnabled(true) + .setCrashReportingEnabled(true) + .setCustomLogConfiguration(customLogConfiguration) + .setDisabled(false) + .setEnabledOnNonDebuggableBuild(true) + .setInitializeCallback(initializeCallback) + .setStatusChangeCallback(statusChangeCallback) + .setUpdateAvailableCallback(updateAvailableCallback) + .build(); + + Truth.assertThat(configuration.appOwnerName).isEqualTo("owner"); + Truth.assertThat(configuration.isCaptureEnabled).isTrue(); + Truth.assertThat(configuration.isCrashReportingEnabled).isTrue(); + Truth.assertThat(configuration.customLogConfiguration).isEqualTo(customLogConfiguration); + Truth.assertThat(configuration.isDisabled).isFalse(); + Truth.assertThat(configuration.isEnabledOnNonDebuggableBuild).isTrue(); + Truth.assertThat(configuration.initializeCallback).isEqualTo(initializeCallback); + Truth.assertThat(configuration.statusChangeCallback).isEqualTo(statusChangeCallback); + Truth.assertThat(configuration.updateAvailableCallback).isEqualTo(updateAvailableCallback); + } + + @Test + public void builder_setCallback() { + DeployGateSdkConfiguration configurationWithCallback = new DeployGateSdkConfiguration.Builder() + .setCallback(deployGateCallback) + .build(); + + Truth.assertThat(configurationWithCallback.initializeCallback).isEqualTo(deployGateCallback); + Truth.assertThat(configurationWithCallback.statusChangeCallback).isEqualTo(deployGateCallback); + Truth.assertThat(configurationWithCallback.updateAvailableCallback).isEqualTo(deployGateCallback); + } + + @Test + public void builder_setXXXCallback() { + DeployGateSdkConfiguration configurationWithFineGrainedCallbacks = new DeployGateSdkConfiguration.Builder() + .setInitializeCallback(initializeCallback) + .setStatusChangeCallback(statusChangeCallback) + .setUpdateAvailableCallback(updateAvailableCallback) + .build(); + + Truth.assertThat(configurationWithFineGrainedCallbacks.initializeCallback).isEqualTo(initializeCallback); + Truth.assertThat(configurationWithFineGrainedCallbacks.statusChangeCallback).isEqualTo(statusChangeCallback); + Truth.assertThat(configurationWithFineGrainedCallbacks.updateAvailableCallback).isEqualTo(updateAvailableCallback); + } + + @Test + public void builder_setCallbackAndOverride() { + DeployGateSdkConfiguration configurationOverrideByFineGrainedCallbacks = new DeployGateSdkConfiguration.Builder() + .setCallback(deployGateCallback) + .setInitializeCallback(initializeCallback) + .setStatusChangeCallback(statusChangeCallback) + .setUpdateAvailableCallback(updateAvailableCallback) + .build(); + + // the last value set will be used + Truth.assertThat(configurationOverrideByFineGrainedCallbacks.initializeCallback).isEqualTo(initializeCallback); + Truth.assertThat(configurationOverrideByFineGrainedCallbacks.statusChangeCallback).isEqualTo(statusChangeCallback); + Truth.assertThat(configurationOverrideByFineGrainedCallbacks.updateAvailableCallback).isEqualTo(updateAvailableCallback); + + DeployGateSdkConfiguration configurationOverrideByCallback = new DeployGateSdkConfiguration.Builder() + .setInitializeCallback(initializeCallback) + .setStatusChangeCallback(statusChangeCallback) + .setUpdateAvailableCallback(updateAvailableCallback) + .setCallback(deployGateCallback) + .build(); + + Truth.assertThat(configurationOverrideByCallback.initializeCallback).isEqualTo(deployGateCallback); + Truth.assertThat(configurationOverrideByCallback.statusChangeCallback).isEqualTo(deployGateCallback); + Truth.assertThat(configurationOverrideByCallback.updateAvailableCallback).isEqualTo(deployGateCallback); + + DeployGateSdkConfiguration configurationWithCallbackOverrideByNull = new DeployGateSdkConfiguration.Builder() + .setCallback(deployGateCallback) + .setInitializeCallback(null) + .setStatusChangeCallback(null) + .setUpdateAvailableCallback(null) + .build(); + + Truth.assertThat(configurationWithCallbackOverrideByNull.initializeCallback).isNull(); + Truth.assertThat(configurationWithCallbackOverrideByNull.statusChangeCallback).isNull(); + Truth.assertThat(configurationWithCallbackOverrideByNull.updateAvailableCallback).isNull(); + + DeployGateSdkConfiguration configurationWithFineGrainedCallbacksOverrideByNull = new DeployGateSdkConfiguration.Builder() + .setInitializeCallback(initializeCallback) + .setStatusChangeCallback(statusChangeCallback) + .setUpdateAvailableCallback(updateAvailableCallback) + .setCallback(null) + .build(); + + Truth.assertThat(configurationWithFineGrainedCallbacksOverrideByNull.initializeCallback).isNull(); + Truth.assertThat(configurationWithFineGrainedCallbacksOverrideByNull.statusChangeCallback).isNull(); + Truth.assertThat(configurationWithFineGrainedCallbacksOverrideByNull.updateAvailableCallback).isNull(); + } +} diff --git a/sdk/src/test/java/com/deploygate/sdk/DeployGateTest.java b/sdk/src/test/java/com/deploygate/sdk/DeployGateTest.java new file mode 100644 index 0000000..ee0dc61 --- /dev/null +++ b/sdk/src/test/java/com/deploygate/sdk/DeployGateTest.java @@ -0,0 +1,208 @@ +package com.deploygate.sdk; + +import static androidx.test.core.app.ApplicationProvider.getApplicationContext; + +import android.app.Application; + +import androidx.annotation.NonNull; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.google.common.truth.Truth; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class DeployGateTest { + + @NonNull + Application app; + + @NonNull + DeployGateSdkConfiguration configuration; + + DeployGateCallback callback; + DeployGateInitializeCallback initializeCallback; + DeployGateStatusChangeCallback statusChangeCallback; + DeployGateUpdateAvailableCallback updateAvailableCallback; + + @Before + public void setUp() { + app = getApplicationContext(); + configuration = new DeployGateSdkConfiguration.Builder().build(); + callback = new DeployGateCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + + @Override + 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 + } + }; + + DeployGate.install(app, configuration); + } + + @After + public void tearDown() { + DeployGate.clear(); + } + + @Test + public void register_fine_grained_callbacks() { + DeployGateInitializeCallback anotherInitializeCallback = new DeployGateInitializeCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + }; + DeployGateStatusChangeCallback anotherStatusChangeCallback = new DeployGateStatusChangeCallback() { + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + }; + DeployGateUpdateAvailableCallback anotherUpdateAvailableCallback = new DeployGateUpdateAvailableCallback() { + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }; + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(0); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(0); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(0); + + DeployGate.registerInitializeCallback(initializeCallback); + DeployGate.registerStatusChangeCallback(statusChangeCallback); + DeployGate.registerUpdateAvailableCallback(updateAvailableCallback); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getInitializeCallbacks().contains(initializeCallback)).isTrue(); + Truth.assertThat(DeployGate.getInitializeCallbacks().contains(anotherInitializeCallback)).isFalse(); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().contains(statusChangeCallback)).isTrue(); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().contains(anotherStatusChangeCallback)).isFalse(); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().contains(updateAvailableCallback)).isTrue(); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().contains(anotherUpdateAvailableCallback)).isFalse(); + + // Each callback already registered before, so DeployGate maybe ignore this operation. + DeployGate.registerInitializeCallback(initializeCallback); + DeployGate.registerStatusChangeCallback(statusChangeCallback); + DeployGate.registerUpdateAvailableCallback(updateAvailableCallback); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + + // register another callbacks + DeployGate.registerInitializeCallback(anotherInitializeCallback); + DeployGate.registerStatusChangeCallback(anotherStatusChangeCallback); + DeployGate.registerUpdateAvailableCallback(anotherUpdateAvailableCallback); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(2); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(2); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(2); + + DeployGate.unregisterInitializeCallback(initializeCallback); + DeployGate.unregisterStatusChangeCallback(statusChangeCallback); + DeployGate.unregisterUpdateAvailableCallback(updateAvailableCallback); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + + // Each callback already unregistered before, so DeployGate maybe ignore this operation. + DeployGate.unregisterInitializeCallback(initializeCallback); + DeployGate.unregisterStatusChangeCallback(statusChangeCallback); + DeployGate.unregisterUpdateAvailableCallback(updateAvailableCallback); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + } + + @Test + public void register_callback() { + DeployGateCallback anotherCallback = new DeployGateCallback() { + @Override + public void onInitialized(boolean isServiceAvailable) { + // no-op + } + + @Override + public void onStatusChanged(boolean isManaged, boolean isAuthorized, String loginUsername, boolean isStopped) { + // no-op + } + + @Override + public void onUpdateAvailable(int revision, String versionName, int versionCode) { + // no-op + } + }; + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(0); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(0); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(0); + + DeployGate.registerCallback(callback, false); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getInitializeCallbacks().contains(callback)).isTrue(); + Truth.assertThat(DeployGate.getInitializeCallbacks().contains(anotherCallback)).isFalse(); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().contains(callback)).isTrue(); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().contains(anotherCallback)).isFalse(); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().contains(callback)).isTrue(); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().contains(anotherCallback)).isFalse(); + + // callback already registered before, so DeployGate maybe ignore this operation. + DeployGate.registerCallback(callback, false); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + + // register another callback + DeployGate.registerCallback(anotherCallback, false); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(2); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(2); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(2); + + DeployGate.unregisterCallback(callback); + + Truth.assertThat(DeployGate.getInitializeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getStatusChangeCallbacks().size()).isEqualTo(1); + Truth.assertThat(DeployGate.getUpdateAvailableCallbacks().size()).isEqualTo(1); + } +} diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGate.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGate.java index 5d0b765..e7d3593 100644 --- a/sdkMock/src/main/java/com/deploygate/sdk/DeployGate.java +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGate.java @@ -71,13 +71,33 @@ public static void install( public static void refresh() { } + public static void registerInitializeCallback(DeployGateInitializeCallback callback) { + } + + public static void unregisterInitializeCallback(DeployGateInitializeCallback callback) { + } + + public static void registerStatusChangeCallback(DeployGateStatusChangeCallback callback) { + } + + public static void unregisterStatusChangeCallback(DeployGateStatusChangeCallback callback) { + } + + public static void registerUpdateAvailableCallback(DeployGateUpdateAvailableCallback callback) { + } + + public static void unregisterUpdateAvailableCallback(DeployGateUpdateAvailableCallback callback) { + } + + @Deprecated public static void registerCallback( DeployGateCallback listener, boolean refreshImmediately ) { } - public static void unregisterCallback(DeployGateCallback listener) { + @Deprecated + public static void unregisterCallback(final DeployGateCallback listener) { } public static boolean isInitialized() { diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCallback.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCallback.java index 8df3686..e54d6a8 100644 --- a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCallback.java +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateCallback.java @@ -1,60 +1,14 @@ package com.deploygate.sdk; - /** - * A callback interface to receive DeployGate events. Implement this and pass to - * {@link DeployGate#registerCallback(DeployGateCallback, boolean)} to listen. + * A callback interface to receive DeployGate events. * * @author tnj + * @deprecated since 4.9.0. Use fine-grained callback interfaces for each purpose. + * @see com.deploygate.sdk.DeployGateInitializeCallback + * @see com.deploygate.sdk.DeployGateStatusChangeCallback + * @see com.deploygate.sdk.DeployGateUpdateAvailableCallback */ -public interface DeployGateCallback { - /** - * Callback to tell the finish of DeployGate service initialization - * procedure. - * - * @param isServiceAvailable - * true if DeployGate service is available on the - * device. - */ - public void onInitialized(boolean isServiceAvailable); - - /** - * Callback to tell the app status on the DeployGate has changed. This will - * also be called back just after {@link #onInitialized(boolean)}, - * {@link DeployGate#refresh()} and - * {@link DeployGate#registerCallback(DeployGateCallback, boolean)} with - * true in second argument. - * - * @param isManaged - * true if the app is known on DeployGate app - * @param isAuthorized - * true if the app is on current user's installed list - * @param loginUsername - * Current login username, returned only when - * isAuthorized is true. - * @param isStopped - * Reserved. - */ - public void onStatusChanged( - boolean isManaged, - boolean isAuthorized, - String loginUsername, - boolean isStopped - ); - - /** - * Callback to tell the new version is available. - * - * @param revision - * revision of new version - * @param versionName - * user-defined version name of new version - * @param versionCode - * user-defined version code of new version - */ - public void onUpdateAvailable( - int revision, - String versionName, - int versionCode - ); -} +@Deprecated +public interface DeployGateCallback extends DeployGateInitializeCallback, DeployGateStatusChangeCallback, DeployGateUpdateAvailableCallback { +} \ No newline at end of file diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateInitializeCallback.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateInitializeCallback.java new file mode 100644 index 0000000..577ed6d --- /dev/null +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateInitializeCallback.java @@ -0,0 +1,18 @@ +package com.deploygate.sdk; + +/** + * A callback interface to receive DeployGate service initialization events. + * + * @since 4.9.0. + * @see DeployGate#registerInitializeCallback(DeployGateInitializeCallback) + */ +public interface DeployGateInitializeCallback { + /** + * Callback to tell the finish of DeployGate service initialization + * procedure. + * + * @param isServiceAvailable true if DeployGate service is available on the + * device. + */ + public void onInitialized(boolean isServiceAvailable); +} diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java index 56f17b1..b512e88 100644 --- a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java @@ -32,10 +32,23 @@ public Builder setCrashReportingEnabled(boolean crashReportingEnabled) { return this; } + @Deprecated public Builder setCallback(DeployGateCallback callback) { return this; } + public Builder setInitializeCallback(DeployGateInitializeCallback initializeCallback) { + return this; + } + + public Builder setStatusChangeCallback(DeployGateStatusChangeCallback statusChangeCallback) { + return this; + } + + public Builder setUpdateAvailableCallback(DeployGateUpdateAvailableCallback updateAvailableCallback) { + return this; + } + public DeployGateSdkConfiguration build() { return new DeployGateSdkConfiguration(); } diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateStatusChangeCallback.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateStatusChangeCallback.java new file mode 100644 index 0000000..6b82c33 --- /dev/null +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateStatusChangeCallback.java @@ -0,0 +1,27 @@ +package com.deploygate.sdk; + +/** + * A callback interface to receive the app status on the DeployGate. + * + * @since 4.9.0. + * @see DeployGate#registerStatusChangeCallback(DeployGateStatusChangeCallback) + */ +public interface DeployGateStatusChangeCallback { + /** + * Callback to tell the app status on the DeployGate has changed. This will + * also be called back just after {@link DeployGateInitializeCallback#onInitialized(boolean)}, + * {@link DeployGate#refresh()}. + * + * @param isManaged true if the app is known on DeployGate app + * @param isAuthorized true if the app is on current user's installed list + * @param loginUsername Current login username, returned only when + * isAuthorized is true. + * @param isStopped Reserved. + */ + public void onStatusChanged( + boolean isManaged, + boolean isAuthorized, + String loginUsername, + boolean isStopped + ); +} diff --git a/sdkMock/src/main/java/com/deploygate/sdk/DeployGateUpdateAvailableCallback.java b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateUpdateAvailableCallback.java new file mode 100644 index 0000000..96eaf4b --- /dev/null +++ b/sdkMock/src/main/java/com/deploygate/sdk/DeployGateUpdateAvailableCallback.java @@ -0,0 +1,22 @@ +package com.deploygate.sdk; + +/** + * A callback interface to receive the app update event. + * + * @since 4.9.0. + * @see DeployGate#registerUpdateAvailableCallback(DeployGateUpdateAvailableCallback) + */ +public interface DeployGateUpdateAvailableCallback { + /** + * Callback to tell the new version is available. + * + * @param revision revision of new version + * @param versionName user-defined version name of new version + * @param versionCode user-defined version code of new version + */ + public void onUpdateAvailable( + int revision, + String versionName, + int versionCode + ); +} diff --git a/sdkMock/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java b/sdkMock/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java new file mode 120000 index 0000000..3d343fc --- /dev/null +++ b/sdkMock/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java @@ -0,0 +1 @@ +../../../../../../../sdk/src/test/java/com/deploygate/sdk/DeployGateSdkConfigurationInterfaceTest.java \ No newline at end of file