Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 11
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
Expand All @@ -25,7 +25,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.android.tools.build:gradle:2.3.2'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
Expand All @@ -17,23 +18,21 @@
*/
public class CommandManager {

private static final int MAX_RETRIES = 20;

DbQueue queue;
HttpHelper http;
Preferences preferences;
Object lockFlush;
final Object lockFlush;
boolean flushInProgress;
boolean flushMayNeedRestart;
AsyncTask<Void, Void, Void> flushTask;

public CommandManager(Context context, String target, String userAgent) {
public CommandManager(Context context, String target, String userAgent, Preferences preferences) {
queue = new DbQueue(context);
preferences = Preferences.get(context);
this.preferences = preferences;
http = new HttpHelper(target, userAgent);
lockFlush = new Object();

synchronized (lockFlush){
synchronized (lockFlush) {
flushInProgress = false;
flushMayNeedRestart = false;
}
Expand Down Expand Up @@ -75,8 +74,8 @@ public boolean executeBatch() {

StringBuilder logResult = new StringBuilder();
logResult.append("Batch executed, ")
.append(requests.size())
.append(" prepared, ");
.append(requests.size())
.append(" prepared, ");


if (data != null) {
Expand Down Expand Up @@ -105,17 +104,17 @@ public boolean executeBatch() {
}
}
logResult.append(successfulRequests.size())
.append(" succeeded, ")
.append(deleteRequests.size() - successfulRequests.size());
.append(" succeeded, ")
.append(deleteRequests.size() - successfulRequests.size());
} else {
Log.e(Contract.TAG, "Results are null");
logResult.append("0 succeeded, ")
.append(requests.size());
.append(requests.size());
}
} else {
Log.e(Contract.TAG, "Data is null");
logResult.append("0 succeeded, ")
.append(requests.size());
.append(requests.size());
}

logResult.append(" failed, rest was told to retry");
Expand Down Expand Up @@ -154,8 +153,8 @@ private void flushCommands(int maxRetries) {

synchronized (lockFlush) {
if (!flushMayNeedRestart) {
flushInProgress = false;
break;
flushInProgress = false;
break;
}
flushMayNeedRestart = false;
}
Expand Down Expand Up @@ -183,8 +182,8 @@ private int exponentialIncrease(int timeInMiliseconds)
int calculateDelay = timeInMiliseconds * 2;

return Contract.FLUSH_MAX_INTERVAL < calculateDelay
? Contract.FLUSH_MAX_INTERVAL
: calculateDelay;
? Contract.FLUSH_MAX_INTERVAL
: calculateDelay;
}

private JSONObject setCookieId(JSONObject command) {
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/com/infinario/android/infinariosdk/Contract.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.infinario.android.infinariosdk;

import android.app.AlarmManager;
import android.os.Build;

/**
* This file has been created by igi on 1/14/15.
*/
Expand All @@ -19,6 +16,11 @@ public class Contract {
public static final String VERSION = "1.1.4";
public static final String OS = "Android";

/**
* Preference files -> each Infinario instance has it's own preferences
*/
public static final String SHARED_PREF_FILES = "shared_preference_files";

/**
* Preferences details
*/
Expand Down Expand Up @@ -74,7 +76,8 @@ public class Contract {
public static final long FLUSH_DELAY = 10 * 1000;
public static final int FLUSH_COUNT = 50;
public static final boolean DEFAULT_AUTO_FLUSH = true;
public static int FLUSH_MIN_INTERVAL = 1000;
public static final java.lang.String PROJECT_PREFIX = "project_prefix";
public static int FLUSH_MIN_INTERVAL = 1000;
public static int FLUSH_MAX_INTERVAL = 3600000;

/**
Expand All @@ -97,13 +100,13 @@ public class Contract {
public static final String COLUMN_COMMAND = "command";
public static final String COLUMN_RETRIES = "retries";

public static final String DATABASE_NAME = "commands.db";
public static final String DATABASE_NAME_POSTFIX = "commands.db";
public static final int DATABASE_VERSION = 1;

// Database creation sql statement
public static final String DATABASE_CREATE = "create table "
+ TABLE_COMMANDS + "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_COMMAND
+ " text not null, " + COLUMN_RETRIES
+ " integer not null default 0);";
+ TABLE_COMMANDS + "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_COMMAND
+ " text not null, " + COLUMN_RETRIES
+ " integer not null default 0);";
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/
public class DbHelper extends SQLiteOpenHelper {

public DbHelper(Context context) {
super(context, Contract.DATABASE_NAME, null, Contract.DATABASE_VERSION);
public DbHelper(Context context, String dbName) {
super(context, dbName, null, Contract.DATABASE_VERSION);
}

@Override
Expand All @@ -22,10 +22,9 @@ public void onCreate(SQLiteDatabase database) {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(DbHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + Contract.TABLE_COMMANDS);
onCreate(db);
}

}
6 changes: 2 additions & 4 deletions src/main/java/com/infinario/android/infinariosdk/DbQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabaseLockedException;
import android.text.TextUtils;
import android.util.Log;

import org.json.JSONException;

Expand All @@ -24,8 +22,8 @@ public class DbQueue {
private Object lockAccess;
private int openCounter;

public DbQueue(Context context) {
dbHelper = new DbHelper(context);
public DbQueue(Context context, String dbName) {
dbHelper = new DbHelper(context, dbName);
lockAccess = new Object();
openCounter = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public GcmIntentService() {
protected void onHandleIntent(Intent intent) {
Infinario.handleGooglePushNotification(this, intent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import org.json.JSONException;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

Expand Down
Loading