-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from DeployGate/jmatsu/feat/allow_opt_out_feat…
…ures Provide opt-out for crash reporting and device capture features
- Loading branch information
Showing
5 changed files
with
338 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 168 additions & 0 deletions
168
sdk/src/main/java/com/deploygate/sdk/DeployGateSdkConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package com.deploygate.sdk; | ||
|
||
import com.deploygate.sdk.internal.annotations.Experimental; | ||
|
||
public final class DeployGateSdkConfiguration { | ||
final CustomLogConfiguration customLogConfiguration; | ||
|
||
final boolean isDisabled; | ||
final boolean isEnabledOnNonDebuggableBuild; | ||
|
||
final String appOwnerName; | ||
|
||
final boolean isCrashReportingEnabled; | ||
|
||
|
||
final DeployGateCallback callback; | ||
|
||
final boolean isCaptureEnabled; | ||
|
||
private DeployGateSdkConfiguration( | ||
Builder builder | ||
) { | ||
this( | ||
builder.isDisabled, | ||
builder.customLogConfiguration, | ||
builder.isEnabledOnNonDebuggableBuild, | ||
builder.appOwnerName, | ||
builder.isCrashReportingEnabled, | ||
builder.isCaptureEnabled, | ||
builder.callback | ||
); | ||
} | ||
|
||
private DeployGateSdkConfiguration( | ||
boolean isDisabled, | ||
CustomLogConfiguration customLogConfiguration, | ||
boolean isEnabledOnNonDebuggableBuild, | ||
String appOwnerName, | ||
boolean isCrashReportingEnabled, | ||
boolean isCaptureEnabled, | ||
DeployGateCallback callback | ||
) { | ||
this.customLogConfiguration = customLogConfiguration; | ||
this.isDisabled = isDisabled; | ||
this.isEnabledOnNonDebuggableBuild = isEnabledOnNonDebuggableBuild; | ||
this.appOwnerName = appOwnerName; | ||
this.isCrashReportingEnabled = isCrashReportingEnabled; | ||
this.isCaptureEnabled = isCaptureEnabled; | ||
this.callback = callback; | ||
} | ||
|
||
public static final class Builder { | ||
private CustomLogConfiguration customLogConfiguration = new CustomLogConfiguration.Builder().build(); | ||
|
||
private boolean isDisabled = false; | ||
private boolean isEnabledOnNonDebuggableBuild = false; | ||
|
||
private String appOwnerName = null; | ||
|
||
private boolean isCrashReportingEnabled = true; | ||
|
||
private boolean isCaptureEnabled = true; | ||
|
||
private DeployGateCallback callback = null; | ||
|
||
public Builder() { | ||
} | ||
|
||
/** | ||
* Set a custom log configuration | ||
* | ||
* @param customLogConfiguration | ||
* a configuration object for custom logs like {@link DeployGate#logDebug(String)} | ||
* @see CustomLogConfiguration | ||
* @return self | ||
*/ | ||
@Experimental | ||
public Builder setCustomLogConfiguration(CustomLogConfiguration customLogConfiguration) { | ||
this.customLogConfiguration = customLogConfiguration; | ||
return this; | ||
} | ||
|
||
/** | ||
* Ensure the authority of this app to prevent casual redistribution via DeployGate. | ||
* | ||
* @param appOwnerName | ||
* A name of this app's owner on DeployGate. | ||
* @return self | ||
*/ | ||
public Builder setAppOwnerName(String appOwnerName) { | ||
this.appOwnerName = appOwnerName; | ||
return this; | ||
} | ||
|
||
/** | ||
* Disable all SDK features. | ||
* | ||
* @param disabled | ||
* Specify true if you would like to disable SDK completely. Defaults to false. | ||
* @return self | ||
*/ | ||
public Builder setDisabled(boolean disabled) { | ||
isDisabled = disabled; | ||
return this; | ||
} | ||
|
||
/** | ||
* Enable SDK even on non-debuggable builds. | ||
* | ||
* @param enabledOnNonDebuggableBuild | ||
* Specify true if you would like to enable SDK on non-debuggable builds. Defaults to false. | ||
* @return self | ||
*/ | ||
public Builder setEnabledOnNonDebuggableBuild(boolean enabledOnNonDebuggableBuild) { | ||
isEnabledOnNonDebuggableBuild = enabledOnNonDebuggableBuild; | ||
return this; | ||
} | ||
|
||
/** | ||
* Enable DeployGate Capture feature. | ||
* | ||
* @param captureEnabled | ||
* Specify true if you would like to use DeployGate Capture feature if available. Otherwise, false. Defaults to true. | ||
* @return self | ||
*/ | ||
@Experimental | ||
public Builder setCaptureEnabled(boolean captureEnabled) { | ||
isCaptureEnabled = captureEnabled; | ||
return this; | ||
} | ||
|
||
/** | ||
* Enable DeployGate Crash reporting feature. | ||
* | ||
* @param crashReportingEnabled | ||
* Specify true if you would like to use DeployGate Crash reporting feature. Otherwise, false. Defaults to true. | ||
* @return self | ||
*/ | ||
public Builder setCrashReportingEnabled(boolean crashReportingEnabled) { | ||
isCrashReportingEnabled = crashReportingEnabled; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set a callback of the communication events between DeployGate client app and this app. | ||
* | ||
* @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 | ||
*/ | ||
public Builder setCallback(DeployGateCallback callback) { | ||
this.callback = callback; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return a new sdk configuration. | ||
*/ | ||
public DeployGateSdkConfiguration build() { | ||
if (isDisabled) { | ||
// Create a new builder instance to release all references just in case. | ||
return new DeployGateSdkConfiguration(new Builder().setDisabled(true)); | ||
} else { | ||
return new DeployGateSdkConfiguration(this); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.