diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7ba28fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,119 @@ +# Created by https://www.gitignore.io + +### Android ### +# Built application files +*.apk +*.ap_ + +# Files for the Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + + +### Eclipse ### +*.pydevproject +.metadata +.gradle +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + +# sbteclipse plugin +.target + +# TeXlipse plugin +.texlipse diff --git a/BaasioAndroid/.gitignore b/BaasioAndroid/.gitignore deleted file mode 100644 index b48c81f..0000000 --- a/BaasioAndroid/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -gen/* -bin/* \ No newline at end of file diff --git a/BaasioAndroid/AndroidManifest.xml b/BaasioAndroid/AndroidManifest.xml index 316535c..b355763 100644 --- a/BaasioAndroid/AndroidManifest.xml +++ b/BaasioAndroid/AndroidManifest.xml @@ -1,10 +1,31 @@ + - + + + + + + + + + + + + + + + + + + + + diff --git a/BaasioAndroid/build.gradle b/BaasioAndroid/build.gradle new file mode 100644 index 0000000..1844b29 --- /dev/null +++ b/BaasioAndroid/build.gradle @@ -0,0 +1,51 @@ +apply plugin: 'android-library' + +repositories { + mavenCentral() +} + +dependencies { + compile files('libs/gcm.jar') + compile 'com.android.support:support-v4:21.0.+' + compile 'org.codehaus.jackson:jackson-core-asl:1.9.+' + compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.+' + compile 'org.springframework.android:spring-android-rest-template:1.+' +} + +android { + compileSdkVersion 19 + buildToolsVersion "21.1.1" + + buildTypes { + release { + buildConfigField "boolean", "SDK_DEBUG", "false" + } + debug { + buildConfigField "boolean", "SDK_DEBUG", "true" + } + } + + sourceSets { + main { + manifest.srcFile 'AndroidManifest.xml' + java.srcDirs = ['src'] + resources.srcDirs = ['src'] + aidl.srcDirs = ['src'] + renderscript.srcDirs = ['src'] + res.srcDirs = ['res'] + assets.srcDirs = ['assets'] + } + + // Move the tests to tests/java, tests/res, etc... + instrumentTest.setRoot('tests') + + // Move the build types to build-types/ + // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... + // This moves them out of them default location under src//... which would + // conflict with src/ being used by the main source set. + // Adding new build types or product flavors should be accompanied + // by a similar customization. + debug.setRoot('build-types/debug') + release.setRoot('build-types/release') + } +} diff --git a/BaasioAndroid/src/com/kth/baasio/Baas.java b/BaasioAndroid/src/com/kth/baasio/Baas.java index 716ad2a..78da0c3 100644 --- a/BaasioAndroid/src/com/kth/baasio/Baas.java +++ b/BaasioAndroid/src/com/kth/baasio/Baas.java @@ -1,6 +1,10 @@ package com.kth.baasio; +import android.content.Context; +import android.content.Intent; +import android.os.Build; + import com.google.android.gcm.GCMRegistrar; import com.kth.baasio.callback.BaasioDeviceAsyncTask; import com.kth.baasio.callback.BaasioDeviceCallback; @@ -43,10 +47,6 @@ import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestTemplate; -import android.content.Context; -import android.content.Intent; -import android.os.Build; - import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; @@ -56,6 +56,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import javax.net.ssl.HttpsURLConnection; @@ -248,23 +249,39 @@ public void init(Context context, String baasioUrl, String baasioId, String appl * @param gcmSenderId GCM sender ID * @return GCM registration task */ - public BaasioDeviceAsyncTask setGcmEnabled(Context context, String tags, + public BaasioDeviceAsyncTask setGcmEnabled(Context context, List tags, BaasioDeviceCallback callback, String... gcmSenderId) { if (!ObjectUtils.isEmpty(gcmSenderId) && !ObjectUtils.isEmpty(gcmSenderId[0])) { this.gcmSenderId = gcmSenderId; gcmEnabled = true; - if (!ObjectUtils.isEmpty(tags)) { - return BaasioPush.registerWithTagsInBackground(context, tags, callback); - } else { - return BaasioPush.registerInBackground(context, callback); + if (tags != null) { + setGcmTags(tags); } } - return null; + return BaasioPush.registerInBackground(context, callback); } + public void setGcmTags(List tags) { + if (!Baas.io().isGcmEnabled()) { + LogUtils.LOGI(TAG, BaasioError.ERROR_GCM_DISABLED); + } + + for (String tag : tags) { + if (tag.length() > 36) { + throw new IllegalArgumentException(BaasioError.ERROR_GCM_TAG_LENGTH_EXCEED); + } + + Pattern pattern = Pattern.compile(BaasioPush.TAG_REGEXP); + if (!pattern.matcher(tag).matches()) { + throw new IllegalArgumentException(BaasioError.ERROR_GCM_TAG_PATTERN_MISS_MATCHED); + } + } + + BaasioPreferences.setNeedRegisteredTags(applicationContext, tags); + } /** * This method must be placed in Application.onDestroy() * diff --git a/BaasioAndroid/src/com/kth/baasio/entity/push/BaasioDevice.java b/BaasioAndroid/src/com/kth/baasio/entity/push/BaasioDevice.java index 143f69b..a21529f 100644 --- a/BaasioAndroid/src/com/kth/baasio/entity/push/BaasioDevice.java +++ b/BaasioAndroid/src/com/kth/baasio/entity/push/BaasioDevice.java @@ -1,8 +1,6 @@ package com.kth.baasio.entity.push; -import static org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_NULL; - import com.kth.baasio.entity.BaasioConnectableEntity; import com.kth.baasio.utils.JsonUtils; import com.kth.baasio.utils.ObjectUtils; @@ -12,20 +10,22 @@ import java.util.List; +import static org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_NULL; + public class BaasioDevice extends BaasioConnectableEntity { public final static String ENTITY_TYPE = "device"; public final static String PROPERTY_TOKEN = "token"; + public final static String PROPERTY_TAGS = "tags"; + public final static String PROPERTY_PLATFORM = "platform"; public final static String PLATFORM_TYPE_GCM = "G"; public final static String PLATFORM_TYPE_IOS = "I"; - private List tags; - public BaasioDevice() { super(); setType(ENTITY_TYPE); @@ -47,6 +47,7 @@ public List getPropertyNames() { List properties = super.getPropertyNames(); properties.add(PROPERTY_TOKEN); properties.add(PROPERTY_PLATFORM); + properties.add(PROPERTY_TAGS); return properties; } @@ -93,6 +94,7 @@ public void setPlatform(String platform) { */ @JsonSerialize(include = NON_NULL) public List getTags() { + List tags = JsonUtils.getStringArrayProperty(properties, PROPERTY_TAGS, List.class); if (ObjectUtils.isEmpty(tags)) { return null; } @@ -105,6 +107,6 @@ public List getTags() { * @param tags List of tags. */ public void setTags(List tags) { - this.tags = tags; + JsonUtils.setStringArrayProperty(properties, PROPERTY_TAGS, tags); } } diff --git a/BaasioAndroid/src/com/kth/baasio/entity/push/BaasioPush.java b/BaasioAndroid/src/com/kth/baasio/entity/push/BaasioPush.java index 9eee27d..8c93bf8 100644 --- a/BaasioAndroid/src/com/kth/baasio/entity/push/BaasioPush.java +++ b/BaasioAndroid/src/com/kth/baasio/entity/push/BaasioPush.java @@ -1,6 +1,9 @@ package com.kth.baasio.entity.push; +import android.content.Context; +import android.text.TextUtils; + import com.google.android.gcm.GCMRegistrar; import com.kth.baasio.Baas; import com.kth.baasio.BuildConfig; @@ -18,15 +21,11 @@ import org.springframework.http.HttpMethod; -import android.content.Context; -import android.text.TextUtils; - import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.Random; -import java.util.regex.Pattern; public class BaasioPush { @@ -44,37 +43,25 @@ enum REG_STATE { private static final Random sRandom = new Random(); - private static final String TAG_REGEXP = "^[a-zA-Z0-9-_]*$"; + public static final String TAG_REGEXP = "^[a-zA-Z0-9-_]*$"; - static List getTagList(String tagString) { - List result = new ArrayList(); - String[] tags = tagString.split("\\,"); - for (String tag : tags) { - tag = tag.toLowerCase(Locale.getDefault()).trim(); - if (!ObjectUtils.isEmpty(tag)) { - result.add(tag); - } - } - - return result; - } public BaasioPush() { } private static boolean needRegister(Context context, String signedInUsername, String regId, - String oldRegId, String newTags) { + String oldRegId, List newTags) { boolean bResult = true; if (GCMRegistrar.isRegisteredOnServer(context)) { String registeredUsername = BaasioPreferences.getRegisteredUserName(context); if (registeredUsername.equals(signedInUsername)) { - String curTags = BaasioPreferences.getRegisteredTags(context); + List curTags = BaasioPreferences.getRegisteredTags(context); - if (curTags.equals(newTags)) { + if (compareArrays(curTags, newTags)) { if (oldRegId.equals(regId)) { LogUtils.LOGV(TAG, "BaasioPush.register() called but already registered."); bResult = false; @@ -98,11 +85,28 @@ private static boolean needRegister(Context context, String signedInUsername, St return bResult; } - public static BaasioDevice register(Context context, String regId) throws BaasioException { + public synchronized static BaasioDevice register(Context context, String regId) throws BaasioException { if (!Baas.io().isGcmEnabled()) { throw new BaasioException(BaasioError.ERROR_GCM_DISABLED); } + BaasioPreferences.setRegisteredSenderId(context, Baas.io().getGcmSenderId()); + + return register(context); + } + + public synchronized static BaasioDevice register(Context context) throws BaasioException { + if (!Baas.io().isGcmEnabled()) { + throw new BaasioException(BaasioError.ERROR_GCM_DISABLED); + } + + String regId = GCMRegistrar.getRegistrationId(context); + + if (needRegisterSenderId(context, regId)) { + GCMRegistrar.register(context, Baas.io().getGcmSenderId()); + throw new BaasioException(BaasioError.ERROR_GCM_REGISTERING_SENDER_ID); + } + GCMRegistrar.checkDevice(context); if (BuildConfig.DEBUG) { GCMRegistrar.checkManifest(context); @@ -114,7 +118,7 @@ public static BaasioDevice register(Context context, String regId) throws Baasio signedInUsername = Baas.io().getSignedInUser().getUsername(); } - String newTags = BaasioPreferences.getNeedRegisteredTags(context); + List newTags = BaasioPreferences.getNeedRegisteredTags(context); String oldRegId = BaasioPreferences.getRegisteredRegId(context); if (!needRegister(context, signedInUsername, regId, oldRegId, newTags)) { @@ -136,11 +140,7 @@ public static BaasioDevice register(Context context, String regId) throws Baasio } device.setToken(regId); - - String tagString = BaasioPreferences.getNeedRegisteredTags(context); - List tags = getTagList(tagString); - - device.setTags(tags); + device.setTags(newTags); long backoff = BACKOFF_MILLIS + sRandom.nextInt(1000); REG_STATE eREG_STATE = REG_STATE.CREATE_DEVICE; @@ -202,18 +202,13 @@ public static BaasioDevice register(Context context, String regId) throws Baasio if (response != null) { BaasioDevice entity = response.getFirstEntity().toType(BaasioDevice.class); if (!ObjectUtils.isEmpty(entity)) { - BaasioPreferences - .setRegisteredSenderId(context, Baas.io().getGcmSenderId()); GCMRegistrar.setRegisteredOnServer(context, true); - BaasioPreferences.setRegisteredTags(context, tagString); BaasioPreferences.setRegisteredUserName(context, signedInUsername); - String newDeviceUuid = entity.getUuid().toString(); - - BaasioPreferences.setDeviceUuidForPush(context, newDeviceUuid); - - BaasioPreferences.setRegisteredRegId(context, regId); + BaasioPreferences.setRegisteredTags(context, entity.getTags()); + BaasioPreferences.setDeviceUuidForPush(context, entity.getUuid().toString()); + BaasioPreferences.setRegisteredRegId(context, entity.getToken()); return entity; } @@ -309,7 +304,11 @@ public static BaasioDevice register(Context context, String regId) throws Baasio return null; } - private static boolean compareArrays(String[] arr1, String[] arr2) { + static boolean compareArrays(String[] arr1, String[] arr2) { + if (ObjectUtils.isEmpty(arr1) && ObjectUtils.isEmpty(arr2)) { + return true; + } + if (ObjectUtils.isEmpty(arr1) || ObjectUtils.isEmpty(arr2)) { return false; } @@ -319,6 +318,20 @@ private static boolean compareArrays(String[] arr1, String[] arr2) { return Arrays.equals(arr1, arr2); } + static boolean compareArrays(List arr1, List arr2) { + if (ObjectUtils.isEmpty(arr1) && ObjectUtils.isEmpty(arr2)) { + return true; + } + + if (ObjectUtils.isEmpty(arr1) || ObjectUtils.isEmpty(arr2)) { + return false; + } + + Collections.sort(arr1); + Collections.sort(arr2); + return arr1.equals(arr2); + } + private static boolean needRegisterSenderId(Context context, String regId) { if (TextUtils.isEmpty(regId)) { LogUtils.LOGD(TAG, "RegId is empty. Need register Sender ID."); @@ -334,17 +347,8 @@ private static boolean needRegisterSenderId(Context context, String regId) { return false; } - /** - * Register device. If server is not available(HTTP status 5xx), it will - * retry 5 times. Executes asynchronously in background and the callbacks - * are called in the UI thread. - * - * @param context Context - * @param callback GCM registration result callback - * @return registration task - */ public static BaasioDeviceAsyncTask registerInBackground(final Context context, - final BaasioDeviceCallback callback) { + final BaasioDeviceCallback callback) { if (!Baas.io().isGcmEnabled()) { if (callback != null) { callback.onException(new BaasioException(BaasioError.ERROR_GCM_DISABLED)); @@ -352,62 +356,18 @@ public static BaasioDeviceAsyncTask registerInBackground(final Context context, return null; } - final String regId = GCMRegistrar.getRegistrationId(context); - - if (needRegisterSenderId(context, regId)) { - GCMRegistrar.register(context, Baas.io().getGcmSenderId()); - } else { - BaasioDeviceAsyncTask task = new BaasioDeviceAsyncTask(callback) { - @Override - public BaasioDevice doTask() throws BaasioException { - BaasioDevice device = register(context, regId); - if (ObjectUtils.isEmpty(device)) { - GCMRegistrar.unregister(context); - } - return device; + BaasioDeviceAsyncTask task = new BaasioDeviceAsyncTask(callback) { + @Override + public BaasioDevice doTask() throws BaasioException { + BaasioDevice device = register(context); + if (ObjectUtils.isEmpty(device)) { + GCMRegistrar.unregister(context); } - }; - task.execute(); - return task; - } - - return null; - } - - /** - * Register device with tags. If server is not available(HTTP status 5xx), - * it will retry 5 times. Executes asynchronously in background and the - * callbacks are called in the UI thread. - * - * @param context Context - * @param tags Tags. The max length of each tag is 36. - * @param callback GCM registration result callback - * @return registration task - */ - public static BaasioDeviceAsyncTask registerWithTagsInBackground(final Context context, - String tags, final BaasioDeviceCallback callback) { - if (!Baas.io().isGcmEnabled()) { - if (callback != null) { - callback.onException(new BaasioException(BaasioError.ERROR_GCM_DISABLED)); - } - return null; - } - - List tagList = getTagList(tags); - for (String tag : tagList) { - if (tag.length() > 36) { - throw new IllegalArgumentException(BaasioError.ERROR_GCM_TAG_LENGTH_EXCEED); - } - - Pattern pattern = Pattern.compile(TAG_REGEXP); - if (!pattern.matcher(tag).matches()) { - throw new IllegalArgumentException(BaasioError.ERROR_GCM_TAG_PATTERN_MISS_MATCHED); + return device; } - } - - BaasioPreferences.setNeedRegisteredTags(context, tags); - - return registerInBackground(context, callback); + }; + task.execute(); + return task; } /** @@ -416,10 +376,6 @@ public static BaasioDeviceAsyncTask registerWithTagsInBackground(final Context c * @param context Context */ public static BaasioResponse unregister(Context context) throws BaasioException { - if (!Baas.io().isGcmEnabled()) { - throw new BaasioException(BaasioError.ERROR_GCM_DISABLED); - } - if (!GCMRegistrar.isRegisteredOnServer(context)) { throw new BaasioException(BaasioError.ERROR_GCM_ALREADY_UNREGISTERED); } @@ -428,9 +384,9 @@ public static BaasioResponse unregister(Context context) throws BaasioException String oldRegId = BaasioPreferences.getRegisteredRegId(context); BaasioPreferences.setDeviceUuidForPush(context, ""); - BaasioPreferences.setNeedRegisteredTags(context, ""); + BaasioPreferences.setNeedRegisteredTags(context, new ArrayList()); BaasioPreferences.setRegisteredUserName(context, ""); - BaasioPreferences.setRegisteredTags(context, ""); + BaasioPreferences.setRegisteredTags(context, new ArrayList()); BaasioPreferences.setRegisteredRegId(context, ""); GCMRegistrar.setRegisteredOnServer(context, false); @@ -474,12 +430,6 @@ public static BaasioResponse unregister(Context context) throws BaasioException */ public static void unregisterInBackground(final Context context, final BaasioResponseCallback callback) { - if (!Baas.io().isGcmEnabled()) { - if (callback != null) { - callback.onException(new BaasioException(BaasioError.ERROR_GCM_DISABLED)); - } - return; - } (new BaasioAsyncTask(callback) { @Override diff --git a/BaasioAndroid/src/com/kth/baasio/entity/user/BaasioUser.java b/BaasioAndroid/src/com/kth/baasio/entity/user/BaasioUser.java index 8e31296..34fb767 100644 --- a/BaasioAndroid/src/com/kth/baasio/entity/user/BaasioUser.java +++ b/BaasioAndroid/src/com/kth/baasio/entity/user/BaasioUser.java @@ -1,7 +1,8 @@ package com.kth.baasio.entity.user; -import static org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_NULL; +import android.content.Context; +import android.net.Uri; import com.kth.baasio.Baas; import com.kth.baasio.callback.BaasioAsyncTask; @@ -26,13 +27,12 @@ import org.codehaus.jackson.map.annotate.JsonSerialize; import org.springframework.http.HttpMethod; -import android.content.Context; -import android.net.Uri; - import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_NULL; + public class BaasioUser extends BaasioConnectableEntity { private final static String TAG = LogUtils.makeLogTag(BaasioUser.class); @@ -469,7 +469,7 @@ public static BaasioUser signIn(Context context, String username, String passwor BaasioPreferences.setUserString(context, loggedInUser.toString()); BaasioPreferences.setAccessToken(context, accessToken); - BaasioPush.registerInBackground(context, null); + BaasioPush.register(context); return response.getUser(); } @@ -530,7 +530,7 @@ public static BaasioUser signInViaFacebook(Context context, String fb_access_tok BaasioPreferences.setUserString(context, loggedInUser.toString()); BaasioPreferences.setAccessToken(context, accessToken); - BaasioPush.registerInBackground(context, null); + BaasioPush.register(context); return response.getUser(); } @@ -588,7 +588,7 @@ public static BaasioUser signInViaKakaotalk(Context context, String kkt_access_t BaasioPreferences.setUserString(context, loggedInUser.toString()); BaasioPreferences.setAccessToken(context, accessToken); - BaasioPush.registerInBackground(context, null); + BaasioPush.register(context); return response.getUser(); } diff --git a/BaasioAndroid/src/com/kth/baasio/exception/BaasioError.java b/BaasioAndroid/src/com/kth/baasio/exception/BaasioError.java index 2632c9d..422c62e 100644 --- a/BaasioAndroid/src/com/kth/baasio/exception/BaasioError.java +++ b/BaasioAndroid/src/com/kth/baasio/exception/BaasioError.java @@ -58,6 +58,8 @@ public final class BaasioError { public static final String ERROR_GCM_DISABLED = "GCM is disabled."; + public static final String ERROR_GCM_REGISTERING_SENDER_ID = "Registering sender id. Wait for registering sender id."; + public static final String ERROR_GCM_ALREADY_REGISTERED = "GCM is already registered"; public static final String ERROR_GCM_ALREADY_UNREGISTERED = "GCM is already unregistered"; diff --git a/BaasioAndroid/src/com/kth/baasio/gcm/GCMBootReceiver.java b/BaasioAndroid/src/com/kth/baasio/gcm/GCMBootReceiver.java new file mode 100644 index 0000000..eb8cce1 --- /dev/null +++ b/BaasioAndroid/src/com/kth/baasio/gcm/GCMBootReceiver.java @@ -0,0 +1,24 @@ +package com.kth.baasio.gcm; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import com.google.android.gcm.GCMRegistrar; +import com.kth.baasio.Baas; +import com.kth.common.utils.LogUtils; + +/** + * Created by brad on 14. 12. 24.. + */ +public class GCMBootReceiver extends BroadcastReceiver{ + private static final String TAG = LogUtils.makeLogTag("GCM"); + + @Override + public void onReceive(Context context, Intent intent) { + if(Baas.io().isGcmEnabled()) { + LogUtils.LOGD(TAG, "GCMBootReceiver"); + GCMRegistrar.register(context.getApplicationContext(), Baas.io().getGcmSenderId()); + } + } +} diff --git a/BaasioAndroid/src/com/kth/baasio/gcm/GCMUpdateReceiver.java b/BaasioAndroid/src/com/kth/baasio/gcm/GCMUpdateReceiver.java new file mode 100644 index 0000000..8736960 --- /dev/null +++ b/BaasioAndroid/src/com/kth/baasio/gcm/GCMUpdateReceiver.java @@ -0,0 +1,27 @@ +package com.kth.baasio.gcm; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import com.google.android.gcm.GCMRegistrar; +import com.kth.baasio.Baas; +import com.kth.baasio.entity.push.BaasioPush; +import com.kth.common.utils.LogUtils; + +/** + * Created by brad on 14. 12. 24.. + */ +public class GCMUpdateReceiver extends BroadcastReceiver{ + private static final String TAG = LogUtils.makeLogTag("GCM"); + + @Override + public void onReceive(Context context, Intent intent) { + if(Baas.io().isGcmEnabled()) { + LogUtils.LOGD(TAG, "GCMUpdateReceiver"); + GCMRegistrar.register(context.getApplicationContext(), Baas.io().getGcmSenderId()); + } else { + BaasioPush.unregisterInBackground(context.getApplicationContext(), null); + } + } +} diff --git a/BaasioAndroid/src/com/kth/baasio/preferences/BaasioPreferences.java b/BaasioAndroid/src/com/kth/baasio/preferences/BaasioPreferences.java index 3bceb75..04ed281 100644 --- a/BaasioAndroid/src/com/kth/baasio/preferences/BaasioPreferences.java +++ b/BaasioAndroid/src/com/kth/baasio/preferences/BaasioPreferences.java @@ -1,16 +1,19 @@ package com.kth.baasio.preferences; +import android.content.Context; +import android.content.SharedPreferences; +import android.util.Base64; + import com.kth.baasio.exception.BaasioError; import com.kth.baasio.utils.JsonUtils; import com.kth.baasio.utils.ObjectUtils; import com.kth.common.PlatformSpecificImplementationFactory; import com.kth.common.preference.SharedPreferenceSaver; -import android.content.Context; -import android.content.SharedPreferences; -import android.util.Base64; - +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; import java.util.UUID; import javax.crypto.Cipher; @@ -167,20 +170,23 @@ public static String getRegisteredUserName(Context context) { return result; } - public static void setRegisteredTags(Context context, String string) { + public static void setRegisteredTags(Context context, List string) { + String tagString = getTagString(string); + SharedPreferences.Editor editor = getPreference(context).edit(); - editor.putString(SHARED_PREFERENCE_NAME_REGISTERED_TAGS_FOR_PUSH, string); + editor.putString(SHARED_PREFERENCE_NAME_REGISTERED_TAGS_FOR_PUSH, tagString); SharedPreferenceSaver saver = PlatformSpecificImplementationFactory .getSharedPreferenceSaver(context); saver.savePreferences(editor, false); } - public static String getRegisteredTags(Context context) { + public static List getRegisteredTags(Context context) { SharedPreferences prefs = getPreference(context); String result = prefs.getString(SHARED_PREFERENCE_NAME_REGISTERED_TAGS_FOR_PUSH, ""); - return result; + List tags = getTagList(result); + return tags; } public static void setRegisteredRegId(Context context, String string) { @@ -199,20 +205,23 @@ public static String getRegisteredRegId(Context context) { return result; } - public static void setNeedRegisteredTags(Context context, String string) { + public static void setNeedRegisteredTags(Context context, List string) { + String tagString = getTagString(string); + SharedPreferences.Editor editor = getPreference(context).edit(); - editor.putString(SHARED_PREFERENCE_NAME_NEED_REGISTER_TAGS_FOR_PUSH, string); + editor.putString(SHARED_PREFERENCE_NAME_NEED_REGISTER_TAGS_FOR_PUSH, tagString); SharedPreferenceSaver saver = PlatformSpecificImplementationFactory .getSharedPreferenceSaver(context); saver.savePreferences(editor, false); } - public static String getNeedRegisteredTags(Context context) { + public static List getNeedRegisteredTags(Context context) { SharedPreferences prefs = getPreference(context); String result = prefs.getString(SHARED_PREFERENCE_NAME_NEED_REGISTER_TAGS_FOR_PUSH, ""); - return result; + List tags = getTagList(result); + return tags; } private static final char[] SEKRIT = new String("baasio_eoqkrqktm!@").toCharArray(); @@ -248,4 +257,38 @@ protected static String decrypt(Context context, String uuid, String value) { throw new RuntimeException(e); } } + + protected static List getTagList(String tagString) { + List result = new ArrayList(); + + if(tagString != null) { + String[] tags = tagString.split("\\,"); + for (String tag : tags) { + tag = tag.toLowerCase(Locale.getDefault()).trim(); + if (!ObjectUtils.isEmpty(tag)) { + result.add(tag); + } + } + } + + return result; + } + + protected static String getTagString(List tagString) { + StringBuilder result = new StringBuilder(); + + if(tagString != null) { + for (String tag : tagString) { + tag = tag.toLowerCase(Locale.getDefault()).trim(); + if (!ObjectUtils.isEmpty(tag)) { + if (result.length() > 0) { + result.append(","); + } + result.append(tag); + } + } + } + + return result.toString(); + } } diff --git a/BaasioAndroid/src/com/kth/baasio/utils/JsonUtils.java b/BaasioAndroid/src/com/kth/baasio/utils/JsonUtils.java index 2783f9a..9328b74 100644 --- a/BaasioAndroid/src/com/kth/baasio/utils/JsonUtils.java +++ b/BaasioAndroid/src/com/kth/baasio/utils/JsonUtils.java @@ -8,9 +8,11 @@ import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.node.ArrayNode; import org.codehaus.jackson.node.JsonNodeFactory; import java.io.IOException; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -190,4 +192,25 @@ public static void setObjectProperty(Map properties, String na } } + public static > List getStringArrayProperty(Map properties, String name, Class c) { + JsonNode value = properties.get(name); + if (value != null) { + return fromJsonNode(value, c); + } + return null; + } + + public static > void setStringArrayProperty(Map properties, String name, T valueList) { + if (valueList == null) { + properties.remove(name); + } else { + ArrayNode node = JsonNodeFactory.instance.arrayNode(); + for(String value : valueList) { + node.add(JsonNodeFactory.instance.textNode((String) value)); + } + + properties.put(name, node); + } + } + } diff --git a/BaasioAndroid/src/com/kth/common/utils/LogUtils.java b/BaasioAndroid/src/com/kth/common/utils/LogUtils.java index f6608cf..73b31f1 100644 --- a/BaasioAndroid/src/com/kth/common/utils/LogUtils.java +++ b/BaasioAndroid/src/com/kth/common/utils/LogUtils.java @@ -16,13 +16,13 @@ package com.kth.common.utils; -import com.kth.baasio.BuildConfig; -import com.kth.baasio.utils.ObjectUtils; - import android.content.Context; import android.os.Environment; import android.util.Log; +import com.kth.baasio.BuildConfig; +import com.kth.baasio.utils.ObjectUtils; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -77,7 +77,7 @@ public static void LOGD(final String tag, String message, Throwable cause) { public static void LOGV(final String tag, String message) { // noinspection PointlessBooleanExpression,ConstantConditions - if (BuildConfig.DEBUG && Log.isLoggable(tag, Log.VERBOSE)) { + if (BuildConfig.SDK_DEBUG && Log.isLoggable(tag, Log.VERBOSE)) { Log.v(tag, message); appendLog(tag, message); @@ -86,7 +86,7 @@ public static void LOGV(final String tag, String message) { public static void LOGV(final String tag, String message, Throwable cause) { // noinspection PointlessBooleanExpression,ConstantConditions - if (BuildConfig.DEBUG && Log.isLoggable(tag, Log.VERBOSE)) { + if (BuildConfig.SDK_DEBUG && Log.isLoggable(tag, Log.VERBOSE)) { Log.v(tag, message, cause); appendLog(tag, message, cause); @@ -151,7 +151,7 @@ public static void appendLog(String tag, String text) { } public static void appendLog(String tag, String text, Throwable cause) { - if (!BuildConfig.DEBUG) { + if (!BuildConfig.SDK_DEBUG) { return; } diff --git a/BaasioAndroidUnitTest/.gitignore b/BaasioAndroidUnitTest/.gitignore deleted file mode 100644 index b48c81f..0000000 --- a/BaasioAndroidUnitTest/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -gen/* -bin/* \ No newline at end of file diff --git a/BaasioAndroidUnitTest/AndroidManifest.xml b/BaasioAndroidUnitTest/AndroidManifest.xml index c9ec8ca..597347c 100644 --- a/BaasioAndroidUnitTest/AndroidManifest.xml +++ b/BaasioAndroidUnitTest/AndroidManifest.xml @@ -1,5 +1,6 @@ - + @@ -39,10 +40,11 @@ services and handle them to the custom IntentService. The com.google.android.c2dm.permission.SEND permission is necessary - so only GCM services can send data messages for the app. + so only GCM services can send data messages for the app. + --> @@ -51,7 +53,13 @@ - + + + + + + + @@ -60,9 +68,10 @@ handle received messages. By default, it must be named .GCMIntentService, unless the - application uses a custom BroadcastReceiver that redefines its name. + application uses a custom BroadcastReceiver that redefines its name. + --> - + + // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... + // This moves them out of them default location under src//... which would + // conflict with src/ being used by the main source set. + // Adding new build types or product flavors should be accompanied + // by a similar customization. + debug.setRoot('build-types/debug') + release.setRoot('build-types/release') + } + + packagingOptions { + exclude 'META-INF/notice.txt' + exclude 'META-INF/license.txt' + exclude 'META-INF/ASL2.0' + exclude 'META-INF/LICENSE' + exclude 'META-INF/NOTICE' + } +} diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test000Auth.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test000Auth.java index d95f790..8049866 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test000Auth.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test000Auth.java @@ -1,6 +1,9 @@ package com.kth.baasio.test; +import android.os.AsyncTask; +import android.test.InstrumentationTestCase; + import com.kth.baasio.Baas; import com.kth.baasio.callback.BaasioCallback; import com.kth.baasio.callback.BaasioDeviceCallback; @@ -15,9 +18,8 @@ import com.kth.baasio.utils.ObjectUtils; import com.kth.common.utils.LogUtils; -import android.os.AsyncTask; -import android.test.InstrumentationTestCase; - +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; public class Test000Auth extends InstrumentationTestCase { @@ -46,8 +48,12 @@ public void test000Init() throws InterruptedException { BaasioConfig.BAASIO_ID, BaasioConfig.APPLICATION_ID); final CountDownLatch signal = new CountDownLatch(1); + + List tags = new ArrayList(); + tags.add(UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG); + mGCMRegisterTask = Baas.io().setGcmEnabled(getInstrumentation().getContext(), - UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG, new BaasioDeviceCallback() { + tags, new BaasioDeviceCallback() { @Override public void onException(BaasioException e) { diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test001Entity.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test001Entity.java index 991e8a6..2be3239 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test001Entity.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test001Entity.java @@ -1,6 +1,9 @@ package com.kth.baasio.test; +import android.os.AsyncTask; +import android.test.InstrumentationTestCase; + import com.kth.baasio.Baas; import com.kth.baasio.callback.BaasioCallback; import com.kth.baasio.callback.BaasioDeviceCallback; @@ -17,9 +20,6 @@ import com.kth.baasio.utils.ObjectUtils; import com.kth.common.utils.LogUtils; -import android.os.AsyncTask; -import android.test.InstrumentationTestCase; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -52,8 +52,12 @@ public void test000Init() throws InterruptedException { BaasioConfig.BAASIO_ID, BaasioConfig.APPLICATION_ID); final CountDownLatch signal = new CountDownLatch(1); + + List tags = new ArrayList(); + tags.add(UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG); + mGCMRegisterTask = Baas.io().setGcmEnabled(getInstrumentation().getContext(), - UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG, new BaasioDeviceCallback() { + tags, new BaasioDeviceCallback() { @Override public void onException(BaasioException e) { diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test002Group.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test002Group.java index e75d0ca..7a6865f 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test002Group.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test002Group.java @@ -1,6 +1,9 @@ package com.kth.baasio.test; +import android.os.AsyncTask; +import android.test.InstrumentationTestCase; + import com.kth.baasio.Baas; import com.kth.baasio.callback.BaasioCallback; import com.kth.baasio.callback.BaasioDeviceCallback; @@ -17,9 +20,7 @@ import com.kth.baasio.utils.ObjectUtils; import com.kth.common.utils.LogUtils; -import android.os.AsyncTask; -import android.test.InstrumentationTestCase; - +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -49,8 +50,12 @@ public void test000Init() throws InterruptedException { BaasioConfig.BAASIO_ID, BaasioConfig.APPLICATION_ID); final CountDownLatch signal = new CountDownLatch(1); + + List tags = new ArrayList(); + tags.add(UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG); + mGCMRegisterTask = Baas.io().setGcmEnabled(getInstrumentation().getContext(), - UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG, new BaasioDeviceCallback() { + tags, new BaasioDeviceCallback() { @Override public void onException(BaasioException e) { diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test003File.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test003File.java index a178db1..29bc60f 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test003File.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test003File.java @@ -1,6 +1,9 @@ package com.kth.baasio.test; +import android.os.AsyncTask; +import android.test.InstrumentationTestCase; + import com.kth.baasio.Baas; import com.kth.baasio.callback.BaasioCallback; import com.kth.baasio.callback.BaasioDeviceCallback; @@ -16,10 +19,9 @@ import com.kth.baasio.utils.ObjectUtils; import com.kth.common.utils.LogUtils; -import android.os.AsyncTask; -import android.test.InstrumentationTestCase; - import java.io.File; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; public class Test003File extends InstrumentationTestCase { @@ -48,8 +50,12 @@ public void test000Init() throws InterruptedException { BaasioConfig.BAASIO_ID, BaasioConfig.APPLICATION_ID); final CountDownLatch signal = new CountDownLatch(1); + + List tags = new ArrayList(); + tags.add(UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG); + mGCMRegisterTask = Baas.io().setGcmEnabled(getInstrumentation().getContext(), - UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG, new BaasioDeviceCallback() { + tags, new BaasioDeviceCallback() { @Override public void onException(BaasioException e) { diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test004Push.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test004Push.java index 9781727..860e8a5 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test004Push.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test004Push.java @@ -1,6 +1,9 @@ package com.kth.baasio.test; +import android.os.AsyncTask; +import android.test.InstrumentationTestCase; + import com.kth.baasio.Baas; import com.kth.baasio.callback.BaasioCallback; import com.kth.baasio.callback.BaasioDeviceCallback; @@ -17,9 +20,8 @@ import com.kth.baasio.utils.ObjectUtils; import com.kth.common.utils.LogUtils; -import android.os.AsyncTask; -import android.test.InstrumentationTestCase; - +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; public class Test004Push extends InstrumentationTestCase { @@ -46,8 +48,12 @@ public void test000Init() throws InterruptedException { BaasioConfig.BAASIO_ID, BaasioConfig.APPLICATION_ID); final CountDownLatch signal = new CountDownLatch(1); + + List tags = new ArrayList(); + tags.add(UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG); + mGCMRegisterTask = Baas.io().setGcmEnabled(getInstrumentation().getContext(), - UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG, new BaasioDeviceCallback() { + tags, new BaasioDeviceCallback() { @Override public void onException(BaasioException e) { diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test005HelpCenter.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test005HelpCenter.java index 28bc765..f123ce4 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test005HelpCenter.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test005HelpCenter.java @@ -1,6 +1,9 @@ package com.kth.baasio.test; +import android.os.AsyncTask; +import android.test.InstrumentationTestCase; + import com.kth.baasio.Baas; import com.kth.baasio.callback.BaasioCallback; import com.kth.baasio.callback.BaasioDeviceCallback; @@ -17,9 +20,7 @@ import com.kth.baasio.utils.ObjectUtils; import com.kth.common.utils.LogUtils; -import android.os.AsyncTask; -import android.test.InstrumentationTestCase; - +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -49,8 +50,12 @@ public void test000Init() throws InterruptedException { BaasioConfig.BAASIO_ID, BaasioConfig.APPLICATION_ID); final CountDownLatch signal = new CountDownLatch(1); + + List tags = new ArrayList(); + tags.add(UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG); + mGCMRegisterTask = Baas.io().setGcmEnabled(getInstrumentation().getContext(), - UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG, new BaasioDeviceCallback() { + tags, new BaasioDeviceCallback() { @Override public void onException(BaasioException e) { diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test006Push2.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test006Push2.java index 7ec1966..74f49d8 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test006Push2.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/Test006Push2.java @@ -1,6 +1,9 @@ package com.kth.baasio.test; +import android.os.AsyncTask; +import android.test.InstrumentationTestCase; + import com.kth.baasio.Baas; import com.kth.baasio.callback.BaasioCallback; import com.kth.baasio.callback.BaasioDeviceCallback; @@ -17,9 +20,8 @@ import com.kth.baasio.utils.ObjectUtils; import com.kth.common.utils.LogUtils; -import android.os.AsyncTask; -import android.test.InstrumentationTestCase; - +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; public class Test006Push2 extends InstrumentationTestCase { @@ -46,8 +48,12 @@ public void test000Init() throws InterruptedException { BaasioConfig.BAASIO_ID, BaasioConfig.APPLICATION_ID); final CountDownLatch signal = new CountDownLatch(1); + + List tags = new ArrayList(); + tags.add(UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG); + mGCMRegisterTask = Baas.io().setGcmEnabled(getInstrumentation().getContext(), - UnitTestConfig.PUSH_SHOULD_RECEIVE_TAG, new BaasioDeviceCallback() { + tags, new BaasioDeviceCallback() { @Override public void onException(BaasioException e) { diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/gcm/GCMIntentService.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/gcm/GCMIntentService.java index 7eb620b..e82e58b 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/gcm/GCMIntentService.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/gcm/GCMIntentService.java @@ -16,10 +16,12 @@ package com.kth.baasio.test.gcm; -import static com.kth.common.utils.LogUtils.LOGE; -import static com.kth.common.utils.LogUtils.LOGI; -import static com.kth.common.utils.LogUtils.LOGW; -import static com.kth.common.utils.LogUtils.makeLogTag; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.NotificationCompat; import com.google.android.gcm.GCMBaseIntentService; import com.kth.baasio.entity.push.BaasioPayload; @@ -35,22 +37,19 @@ import com.kth.baasio.utils.ObjectUtils; import com.kth.common.utils.LogUtils; -import android.app.Notification; -import android.app.NotificationManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.support.v4.app.NotificationCompat; - import java.util.Random; import java.util.UUID; +import static com.kth.common.utils.LogUtils.LOGE; +import static com.kth.common.utils.LogUtils.LOGI; +import static com.kth.common.utils.LogUtils.LOGW; + /** * {@link android.app.IntentService} responsible for handling GCM messages. */ public class GCMIntentService extends GCMBaseIntentService { - private static final String TAG = makeLogTag("GCM"); + private static final String TAG = LogUtils.makeLogTag("GCM"); private static final int TRIGGER_SYNC_MAX_JITTER_MILLIS = 3 * 60 * 1000; // 3 // minutes @@ -63,25 +62,23 @@ public GCMIntentService() { @Override protected void onRegistered(Context context, String regId) { - LOGI(TAG, "Device registered: regId=" + regId); + LogUtils.LOGI(TAG, "Device registered: regId=" + regId); try { BaasioPush.register(context, regId); } catch (BaasioException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LogUtils.LOGI(TAG, e.toString()); } } @Override protected void onUnregistered(Context context, String regId) { - LOGI(TAG, "Device unregistered"); + LogUtils.LOGI(TAG, "Device unregistered"); try { BaasioPush.unregister(context); } catch (BaasioException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + LogUtils.LOGI(TAG, e.toString()); } } @@ -89,7 +86,6 @@ protected void onUnregistered(Context context, String regId) { protected void onMessage(Context context, Intent intent) { String announcement = intent.getStringExtra("message"); if (announcement != null) { - // displayNotification(context, announcement); generateNotification(context, announcement); return; } @@ -163,13 +159,13 @@ private static void generateNotification(Context context, String message) { @Override public void onError(Context context, String errorId) { - LOGE(TAG, "Received error: " + errorId); + LogUtils.LOGE(TAG, "Received error: " + errorId); } @Override protected boolean onRecoverableError(Context context, String errorId) { // log message - LOGW(TAG, "Received recoverable error: " + errorId); + LogUtils.LOGW(TAG, "Received recoverable error: " + errorId); return super.onRecoverableError(context, errorId); } } diff --git a/BaasioAndroidUnitTest/src/com/kth/baasio/test/gcm/GCMRedirectedBroadcastReceiver.java b/BaasioAndroidUnitTest/src/com/kth/baasio/test/gcm/GCMRedirectedBroadcastReceiver.java index 78ce07c..b84d066 100644 --- a/BaasioAndroidUnitTest/src/com/kth/baasio/test/gcm/GCMRedirectedBroadcastReceiver.java +++ b/BaasioAndroidUnitTest/src/com/kth/baasio/test/gcm/GCMRedirectedBroadcastReceiver.java @@ -16,10 +16,11 @@ package com.kth.baasio.test.gcm; -import com.google.android.gcm.GCMBroadcastReceiver; - import android.content.Context; +import com.google.android.gcm.GCMBroadcastReceiver; +import com.kth.baasio.Baas; + /** * @author trevorjohns@google.com (Trevor Johns) */ @@ -32,6 +33,9 @@ public class GCMRedirectedBroadcastReceiver extends GCMBroadcastReceiver { */ @Override protected String getGCMIntentServiceClassName(Context context) { - return GCMIntentService.class.getCanonicalName(); + if(Baas.io().isGcmEnabled()) + return GCMIntentService.class.getCanonicalName(); + else + return null; } } diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..90153f8 --- /dev/null +++ b/build.gradle @@ -0,0 +1,9 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.0.0' + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..8c0fb64 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..8a33158 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Dec 17 09:52:36 KST 2014 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..c0b8ff4 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +include ':BaasioAndroid' +include ':BaasioAndroidUnitTest'