Skip to content

Commit

Permalink
Merge pull request #22 from unity/release-branch-4.13.4
Browse files Browse the repository at this point in the history
Update DDSDK to 4.13.4

- Fixed a bug where changing the OS language could crash the app.
- Improved handling of database exceptions.
  • Loading branch information
GBurslem authored and GitHub Enterprise committed Feb 16, 2021
2 parents d00b007 + c835380 commit 2781fdc
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 57 deletions.
21 changes: 21 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Git Attributes

# ------------------------------------------------------------------------------
# Line Endings

* text=auto

# Source Files
*.java eol=lf
*.kt eol=lf

*.txt eol=lf
*.md eol=lf

# Batch Files
*.sh text eol=lf
*.{bat,[bB][aA][tT]} text eol=crlf
*.{cmd,[cC][mM][dD]} text eol=crlf

# Other files
*.gradle text eol=lf
11 changes: 11 additions & 0 deletions .yamato/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tests:
name: Test deltaDNA Android SDK
agent:
type: Unity::VM::osx
image: mobile/android-macos-execution:latest
flavor: i1.medium
triggers:
cancel_old_ci: true
expression: pull_request.target EQ "develop" OR pull_request.target EQ "master"
commands:
- ./gradlew clean build -i
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

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

### Fixed
- Fixed a bug where changing the OS language could crash the app.
- Improved handling of database exceptions.

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

### 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.3'
compile 'com.deltadna.android:deltadna-sdk:4.13.4'
```

## 初始化
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ allprojects {
In your app's build script:
```groovy
dependencies {
implementation 'com.deltadna.android:deltadna-sdk:4.13.3'
implementation 'com.deltadna.android:deltadna-sdk:4.13.4'
}
```
The Java source and target compatibility needs to be set to 1.8 in you app's build script:
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.3
VERSION_NAME=4.13.4

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.3'
compile 'com.deltadna.android:deltadna-sdk-notifications:4.13.3'
compile 'com.deltadna.android:deltadna-sdk:4.13.4'
compile 'com.deltadna.android:deltadna-sdk-notifications:4.13.4'
```

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

Expand Down
54 changes: 24 additions & 30 deletions library/src/main/java/com/deltadna/android/sdk/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.AsyncTask;
import android.provider.BaseColumns;
Expand All @@ -42,7 +44,7 @@ final class DatabaseHelper extends SQLiteOpenHelper {
}

@Override
public void onCreate(SQLiteDatabase db) {
public void onCreate(SQLiteDatabase db) throws SQLException {
db.execSQL("CREATE TABLE " + Events.TABLE + "("
+ Events.Column.ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ Events.Column.TIME + " INTEGER NOT NULL, "
Expand Down Expand Up @@ -83,11 +85,7 @@ public void onCreate(SQLiteDatabase db) {
}

@Override
public void onUpgrade(
SQLiteDatabase db,
int oldVersion,
int newVersion) {

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) throws SQLException {
Log.d(TAG, String.format(
Locale.ENGLISH,
"Upgrading %s from version %d to %d",
Expand Down Expand Up @@ -158,7 +156,7 @@ long getEventsSize() {
}
}

Cursor getEventRows() {
Cursor getEventRows() throws SQLiteException {
return getReadableDatabase().rawQuery(
String.format(
Locale.US,
Expand All @@ -182,7 +180,7 @@ boolean insertEventRow(
Location location,
String name,
@Nullable String hash,
long size) {
long size) throws SQLiteException {
final ContentValues values = new ContentValues(5);
values.put(Events.Column.TIME.toString(), time);
values.put(Events.Column.LOCATION.toString(), location.name());
Expand All @@ -194,19 +192,19 @@ boolean insertEventRow(
!= -1);
}

boolean removeEventRow(long id) {
boolean removeEventRow(long id) throws SQLiteException {
return (getWritableDatabase().delete(
Events.TABLE,
Events.Column.ID + " = ?",
new String[]{Long.toString(id)})
== 1);
}

void removeEventRows() {
void removeEventRows() throws SQLiteException {
getWritableDatabase().delete(Events.TABLE, null, null);
}

Cursor getEngagement(String decisionPoint, String flavour) {
Cursor getEngagement(String decisionPoint, String flavour) throws SQLiteException {
return getReadableDatabase().query(
Engagements.TABLE,
Engagements.Column.all(),
Expand Down Expand Up @@ -239,26 +237,26 @@ boolean insertEngagementRow(
public class InsertEngagementAsyncTask extends AsyncTask<ContentValues, Void, Void>{

@Override
protected Void doInBackground(ContentValues... contentValues) {
protected Void doInBackground(ContentValues... contentValues) throws SQLiteException {
ContentValues value = contentValues[0];
getWritableDatabase().insert(Engagements.TABLE, null, value);
return null;
}
}

boolean removeEngagementRow(long id) {
boolean removeEngagementRow(long id) throws SQLiteException {
return (getWritableDatabase().delete(
Engagements.TABLE,
Engagements.Column.ID + " = ?",
new String[]{Long.toString(id)})
== 1);
}

void removeEngagementRows() {
void removeEngagementRows() throws SQLiteException {
getWritableDatabase().delete(Engagements.TABLE, null, null);
}

Cursor getImageMessages() {
Cursor getImageMessages() throws SQLiteException {
return getReadableDatabase().query(
ImageMessages.TABLE,
ImageMessages.Column.all(),
Expand All @@ -269,7 +267,7 @@ Cursor getImageMessages() {
null);
}

Cursor getImageMessage(String url) {
Cursor getImageMessage(String url) throws SQLiteException {
final String other;
if (url.startsWith("http://")) {
other = "https" + url.substring("http".length(), url.length());
Expand All @@ -293,15 +291,15 @@ Cursor getImageMessage(String url) {
null);
}

boolean removeImageMessage(long id) {
boolean removeImageMessage(long id) throws SQLiteException {
return (getWritableDatabase().delete(
ImageMessages.TABLE,
ImageMessages.Column.ID + " = ?",
new String[]{Long.toString(id)})
== 1);
}

void removeImageMessageRows() {
void removeImageMessageRows() throws SQLiteException {
getWritableDatabase().delete(ImageMessages.TABLE, null, null);
}

Expand All @@ -310,7 +308,7 @@ boolean insertImageMessage(
Location location,
String name,
long size,
Date downloaded) {
Date downloaded) throws SQLiteException {
final ContentValues values = new ContentValues(4);
values.put(ImageMessages.Column.URL.toString(), url);
values.put(ImageMessages.Column.LOCATION.toString(), location.name());
Expand All @@ -323,7 +321,7 @@ boolean insertImageMessage(
}

@Nullable
JSONObject getAction(long campaignId) {
JSONObject getAction(long campaignId) throws SQLiteException {
try (final Cursor cursor = getReadableDatabase().query(
Actions.TABLE,
Actions.Column.all(),
Expand Down Expand Up @@ -371,30 +369,27 @@ boolean insertActionRow(
return true;
}


public class InsertActionRowAsyncTask extends AsyncTask<ContentValues, Void, Void>{

@Override
protected Void doInBackground(ContentValues... values) {

protected Void doInBackground(ContentValues... values) throws SQLiteException {
getWritableDatabase().insert(Actions.TABLE, null, values[0]);
return null;
}
}

boolean removeActionRow(long campaignId) {
boolean removeActionRow(long campaignId) throws SQLiteException {
return (getWritableDatabase().delete(
Actions.TABLE,
Actions.Column.CAMPAIGN_ID + " = ?",
new String[]{Long.toString(campaignId)})
== 1);
}

void removeActionRows() {
void removeActionRows() throws SQLiteException {
getWritableDatabase().delete(Actions.TABLE, null, null);
}

long getETCExecutionCount(long variantId) {
long getETCExecutionCount(long variantId) throws SQLiteException {
long executions = 0;
try (
final Cursor cursor = getReadableDatabase().query(
Expand All @@ -413,8 +408,7 @@ long getETCExecutionCount(long variantId) {
return executions;
}


void recordETCExecution(long campaignId) {
void recordETCExecution(long campaignId) throws SQLiteException {
long etcExecutionCount = getETCExecutionCount(campaignId);
SQLiteDatabase database = this.getWritableDatabase();
if (etcExecutionCount == 0) {
Expand All @@ -431,7 +425,7 @@ void recordETCExecution(long campaignId) {

}

void clearETCExecutions() {
void clearETCExecutions() throws SQLiteException {
getWritableDatabase().delete(ETCExecutions.TABLE, null, null);
}

Expand Down
11 changes: 10 additions & 1 deletion library/src/main/java/com/deltadna/android/sdk/EventStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.content.*;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.os.AsyncTask;
import androidx.annotation.Nullable;
import android.util.Log;
Expand Down Expand Up @@ -316,7 +317,15 @@ protected Void doInBackground(Void... params) {
}
}

if (!db.insertEventRow(time, location, name, hash, file.length())) {
boolean dbInsertSucceeded;
try {
dbInsertSucceeded = db.insertEventRow(time, location, name, hash, file.length());
} catch (SQLiteException e) {
Log.e(TAG, "An error occurred when trying to insert event row into the database", e);
dbInsertSucceeded = false;
}

if (!dbInsertSucceeded) {
Log.w(TAG, "Failed inserting " + new String(content));
//noinspection ResultOfMethodCallIgnored
file.delete();
Expand Down
28 changes: 15 additions & 13 deletions library/src/main/java/com/deltadna/android/sdk/EventTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.database.sqlite.SQLiteException;
import android.util.Log;
import com.deltadna.android.sdk.triggers.ExecutionCountTriggerCondition;
import com.deltadna.android.sdk.triggers.ExecutionRepeatTriggerCondition;
Expand Down Expand Up @@ -227,18 +229,18 @@ boolean evaluate(Event event) {
}
}




if (stack.isEmpty() || (boolean) stack.pop()) {



// Default to true if no conditions exist
boolean anyCanExecute = campaignTriggerConditions.size() == 0;

// Only one condition needs to be true to flip conditions to true
etcMetricStore.recordETCExecution(variantId);
try {
etcMetricStore.recordETCExecution(variantId);
} catch (SQLiteException e) {
Log.e(TAG, "Failed to record the ETC execution", e);
return false;
}

for (TriggerCondition condition : campaignTriggerConditions){
if ( condition.canExecute() ) anyCanExecute = true;
}
Expand Down Expand Up @@ -494,8 +496,8 @@ boolean fromCompare(int value) throws InvalidOperation {
@Override
boolean evaluate(String left, String right) throws InvalidOperation {
return CONTAINS.evaluate(
left.toLowerCase(Locale.getDefault()),
right.toLowerCase(Locale.getDefault()));
left.toLowerCase(Locale.ENGLISH),
right.toLowerCase(Locale.ENGLISH));
}
},
STARTS_WITH("starts with") {
Expand All @@ -518,8 +520,8 @@ boolean fromCompare(int value) throws InvalidOperation {
@Override
boolean evaluate(String left, String right) throws InvalidOperation {
return STARTS_WITH.evaluate(
left.toLowerCase(Locale.getDefault()),
right.toLowerCase(Locale.getDefault()));
left.toLowerCase(Locale.ENGLISH),
right.toLowerCase(Locale.ENGLISH));
}
},
ENDS_WITH("ends with") {
Expand All @@ -542,8 +544,8 @@ boolean fromCompare(int value) throws InvalidOperation {
@Override
boolean evaluate(String left, String right) throws InvalidOperation {
return ENDS_WITH.evaluate(
left.toLowerCase(Locale.getDefault()),
right.toLowerCase(Locale.getDefault()));
left.toLowerCase(Locale.ENGLISH),
right.toLowerCase(Locale.ENGLISH));
}
};

Expand Down
Loading

0 comments on commit 2781fdc

Please sign in to comment.