Skip to content

Commit

Permalink
Merge pull request #9 from deltaDNA/5.0.0
Browse files Browse the repository at this point in the history
5.0.0
  • Loading branch information
unity-thull authored Nov 5, 2021
2 parents b1d1006 + 91bec83 commit a850654
Show file tree
Hide file tree
Showing 23 changed files with 506 additions and 47 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## [5.0.0](https://github.com/deltaDNA/android-sdk/releases/tag/5.0.0)

## New
- **Breaking Change**: Provided APIs for checking if PIPL consent is required, and for registering a user's PIPL consent if so.
Note it is now a requirement to call the API to check for consent, and register any consents if necessary, before collect and engage
responses will be successfully sent to the deltaDNA service.

## [4.13.6](https://github.com/deltaDNA/android-sdk/releases/tag/4.13.6)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ allprojects {
```
在你APP的构建脚本
```groovy
compile 'com.deltadna.android:deltadna-sdk:4.13.6'
compile 'com.deltadna.android:deltadna-sdk:5.0.0'
```

## 初始化
Expand Down
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ allprojects {
In your app's build script:
```groovy
dependencies {
implementation 'com.deltadna.android:deltadna-sdk:4.13.6'
implementation 'com.deltadna.android:deltadna-sdk:5.0.0'
}
```
The Java source and target compatibility needs to be set to 1.8 in you app's build script:
Expand All @@ -68,6 +68,10 @@ The SDK needs to be initialised with the following parameters in an `Application
* `environmentKey`, a unique 32 character string assigned to your application. You will be assigned separate application keys for development and production builds of your game. You will need to change the environment key that you initialise the SDK with as you move from development and testing to production.
* `collectUrl`, this is the address of the server that will be collecting your events.
* `engageUrl`, this is the address of the server that will provide real-time A/B Testing and Targeting.

It is a requirement in versions 5.0.0 and above to check if a user is in a location where PIPL consent is required, and to provide that consent if so. This must
be done before the SDK will send any events or make any engage requests.

```java
public class MyApplication extends Application {

Expand All @@ -80,6 +84,22 @@ public class MyApplication extends Application {
"environmentKey",
"collectUrl",
"engageUrl"));

DDNA.instance().isPiplConsentRequired(new ConsentTracker.Callback() {
@Override
public void onSuccess(boolean requiresConsent) {
if (requiresConsent) {
// Put in a consent flow here to check that the user has given their consent, then update the booleans below to match.
DDNA.instance().setPiplConsent(true, true);
}
}

@Override
public void onFailure(Throwable exception) {
Log.e("EXAMPLE", "Failed to check for PIPL consent", exception);
// Try again later.
}
});
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.deltadna.android.sdk.example;

import android.app.Application;
import android.util.Log;

import com.deltadna.android.sdk.BuildConfig;
import com.deltadna.android.sdk.DDNA;
import com.deltadna.android.sdk.consent.ConsentTracker;

public class ExampleApplication extends Application {

Expand All @@ -39,5 +41,21 @@ public void onCreate() {
"http://collect3347ndrds.deltadna.net/collect/api",
"http://engage3347ndrds.deltadna.net")
.clientVersion(BuildConfig.VERSION_NAME));

DDNA.instance().isPiplConsentRequired(new ConsentTracker.Callback() {
@Override
public void onSuccess(boolean requiresConsent) {
if (requiresConsent) {
// In our example, we assume we have consent, but you should check to make sure this is the case!
DDNA.instance().setPiplConsent(true, true);
}
}

@Override
public void onFailure(Throwable exception) {
Log.e("EXAMPLE", "Failed to check for PIPL consent", exception);
// Try again later.
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.deltadna.android.sdk.example;

import android.app.Application;
import android.util.Log;

import com.deltadna.android.sdk.BuildConfig;
import com.deltadna.android.sdk.DDNA;
import com.deltadna.android.sdk.consent.ConsentTracker;

public class ExampleApplication extends Application {

Expand All @@ -39,5 +41,21 @@ public void onCreate() {
"http://collect3347ndrds.deltadna.net/collect/api",
"http://engage3347ndrds.deltadna.net")
.clientVersion(BuildConfig.VERSION_NAME));

DDNA.instance().isPiplConsentRequired(new ConsentTracker.Callback() {
@Override
public void onSuccess(boolean requiresConsent) {
if (requiresConsent) {
// In our example, we assume we have consent, but you should check to make sure this is the case!
DDNA.instance().setPiplConsent(true, true);
}
}

@Override
public void onFailure(Throwable exception) {
Log.e("EXAMPLE", "Failed to check for PIPL consent", exception);
// Try again later.
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.deltadna.android.sdk.notifications.example;

import android.app.Application;
import android.util.Log;

import com.deltadna.android.sdk.DDNA;
import com.deltadna.android.sdk.consent.ConsentTracker;

public class ExampleApplication extends Application {

Expand All @@ -31,5 +33,21 @@ public void onCreate() {
"07575004106474324897044893014183",
"http://collect3347ndrds.deltadna.net/collect/api",
"http://engage3347ndrds.deltadna.net"));

DDNA.instance().isPiplConsentRequired(new ConsentTracker.Callback() {
@Override
public void onSuccess(boolean requiresConsent) {
if (requiresConsent) {
// In our example, we assume we have consent, but you should check to make sure this is the case!
DDNA.instance().setPiplConsent(true, true);
}
}

@Override
public void onFailure(Throwable exception) {
Log.e("EXAMPLE", "Failed to check for PIPL consent", exception);
// Try again later.
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.deltadna.android.sdk.notifications.example;

import android.app.Application;
import android.util.Log;

import com.deltadna.android.sdk.DDNA;
import com.deltadna.android.sdk.consent.ConsentTracker;
import com.deltadna.android.sdk.notifications.DDNANotifications;

public class ExampleApplication extends Application {
Expand All @@ -32,6 +34,22 @@ public void onCreate() {
"07575004106474324897044893014183",
"http://collect3347ndrds.deltadna.net/collect/api",
"http://engage3347ndrds.deltadna.net"));

DDNA.instance().isPiplConsentRequired(new ConsentTracker.Callback() {
@Override
public void onSuccess(boolean requiresConsent) {
if (requiresConsent) {
// In our example, we assume we have consent, but you should check to make sure this is the case!
DDNA.instance().setPiplConsent(true, true);
}
}

@Override
public void onFailure(Throwable exception) {
Log.e("EXAMPLE", "Failed to check for PIPL consent", exception);
// Try again later.
}
});

// only needs to be called if targeting API 26 or higher
DDNANotifications.setReceiver(ExampleReceiver.class);
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=com.deltadna.android
VERSION_NAME=4.13.6
VERSION_NAME=5.0.0

POM_DESCRIPTION=deltaDNA SDK for Android
POM_URL=https://github.com/deltaDNA/android-sdk
Expand Down
4 changes: 2 additions & 2 deletions library-notifications/README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ allprojects {
```
在你APP的构建脚本
```groovy
compile 'com.deltadna.android:deltadna-sdk:4.13.6'
compile 'com.deltadna.android:deltadna-sdk-notifications:4.13.6'
compile 'com.deltadna.android:deltadna-sdk:5.0.0'
compile 'com.deltadna.android:deltadna-sdk-notifications:5.0.0'
```

## 整合
Expand Down
4 changes: 2 additions & 2 deletions library-notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ allprojects {
In your app's build script:
```groovy
dependencies {
implementation 'com.deltadna.android:deltadna-sdk:4.13.6'
implementation 'com.deltadna.android:deltadna-sdk-notifications:4.13.6'
implementation 'com.deltadna.android:deltadna-sdk:5.0.0'
implementation 'com.deltadna.android:deltadna-sdk-notifications:5.0.0'
}
```

Expand Down
57 changes: 56 additions & 1 deletion library/src/main/java/com/deltadna/android/sdk/DDNA.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
package com.deltadna.android.sdk;

import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import com.deltadna.android.sdk.consent.ConsentTracker;
import com.deltadna.android.sdk.consent.GeoIpNetworkClient;
import com.deltadna.android.sdk.exceptions.NotInitialisedException;
import com.deltadna.android.sdk.helpers.ClientInfo;
import com.deltadna.android.sdk.helpers.Preconditions;
Expand Down Expand Up @@ -131,6 +135,12 @@ public static synchronized DDNA instance() {
final Preferences preferences;
final NetworkManager network;
private final EngageFactory engageFactory;

/**
* INTERNAL USE ONLY. Do not access this property directly.
* Please use isPiplConsentRequired and setPiplConsent on the main DDNA instance to check for and provide consent.
*/
public final ConsentTracker consentTracker;

String sessionId = UUID.randomUUID().toString();

Expand All @@ -156,6 +166,10 @@ public static synchronized DDNA instance() {
engageUrl,
settings,
hashSecret);
consentTracker = new ConsentTracker(
application.getSharedPreferences("com.deltadna.android.sdk.prefs", Context.MODE_PRIVATE),
new GeoIpNetworkClient(network)
);
engageFactory = new EngageFactory(this);
}

Expand Down Expand Up @@ -409,7 +423,48 @@ public abstract <E extends Engagement> DDNA requestEngagement(
abstract ImageMessageStore getImageMessageStore();

abstract Map<String, Integer> getIso4217();


/**
* Checks if any PIPL user consents are required before sending data from the device.
* This method must be called before starting the SDK.
*
* The callback parameter will be true if consent needs to be checked, and false if either
* consent has previously been gathered, or if consent is not required in the user's current
* location.
*/
public void isPiplConsentRequired(ConsentTracker.Callback callback) {
consentTracker.isPiplConsentRequired(new ConsentTracker.Callback() {
@Override
public void onSuccess(boolean requiresConsent) {
if (!requiresConsent && instance != null && isStarted()) {
requestSessionConfiguration();
}
callback.onSuccess(requiresConsent);
}

@Override
public void onFailure(Throwable exception) {
callback.onFailure(exception);
}
});
}

/**
* Registers a user's consent (or lack of consent) to have their data used and / or exported
* under PIPL legislation. Call isPiplConsentRequired first to check if this method is needed
* or not.
*/
public void setPiplConsent(boolean consentForUse, boolean consentForExport) {
if (!consentForUse) {
forgetMe();
}
if (consentForUse && consentForExport && instance != null && isStarted()) {
// If we've already set up the SDK, refresh the SDK to allow relevant configurations to be fetched
requestSessionConfiguration();
}
consentTracker.setConsents(consentForUse, consentForExport);
}

/**
* Changes the session id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.text.TextUtils;

import com.deltadna.android.sdk.consent.ConsentTracker;
import com.deltadna.android.sdk.listeners.EngageListener;
import com.deltadna.android.sdk.listeners.EventListener;
import com.deltadna.android.sdk.listeners.internal.IEventListener;
Expand Down Expand Up @@ -183,7 +185,7 @@ public DDNA stopTrackingMe() {

return nonTracking;
}

@Override
ImageMessageStore getImageMessageStore() {
return getDelegate().getImageMessageStore();
Expand All @@ -195,7 +197,7 @@ Map<String, Integer> getIso4217() {
}

private DDNA getDelegate() {
if (preferences.isForgetMe() || preferences.isForgotten() || preferences.isStopTrackingMe()) {
if (preferences.isForgetMe() || preferences.isForgotten() || preferences.isStopTrackingMe() || DDNA.instance().consentTracker.isConsentDenied()) {
return nonTracking;
} else {
return tracking;
Expand Down
15 changes: 14 additions & 1 deletion library/src/main/java/com/deltadna/android/sdk/DDNAImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import com.deltadna.android.sdk.exceptions.NotStartedException;
import com.deltadna.android.sdk.exceptions.SessionConfigurationException;
import com.deltadna.android.sdk.helpers.ClientInfo;
Expand Down Expand Up @@ -90,6 +91,11 @@ public DDNA startSdk() {
@Override
public DDNA startSdk(@Nullable String userId) {
Log.d(TAG, "Starting SDK");

if (!consentTracker.hasCheckedForConsent()) {
Log.w(TAG, "In version 5.0.0 and above, it is a requirement to check if user consent is required before events will be sent. " +
"Events will not be sent until this check is performed and any required consents are provided.");
}

if (started) {
Log.w(TAG, "SDK already started");
Expand Down Expand Up @@ -243,6 +249,13 @@ public DDNA requestEngagement(String decisionPoint, EngageListener<Engagement> l
public <E extends Engagement> DDNA requestEngagement(E engagement, EngageListener<E> listener) {
Preconditions.checkArg(engagement != null, "engagement cannot be null");
Preconditions.checkArg(listener != null, "listener cannot be null");

if (!DDNA.instance().consentTracker.hasCheckedForConsent()) {
Log.w(TAG, "You need to check for user consent before making engagement requests.");
listener.onCompleted((E) engagement.setResponse(new Response<>(
200, false, new byte[] {}, new JSONObject(), null)));
return this;
}

if (!started) {
Log.w(TAG, "SDK has not been started, aborting engagement " + engagement);
Expand Down Expand Up @@ -389,7 +402,7 @@ public DDNA forgetMe() {
public DDNA stopTrackingMe() {
return stopSdk();
}

@Override
ImageMessageStore getImageMessageStore() {
return imageMessageStore;
Expand Down
Loading

0 comments on commit a850654

Please sign in to comment.