Skip to content

Commit

Permalink
Merge commit '40fedd019836381c472102183690b5a7dfe5517e' into sslavin-…
Browse files Browse the repository at this point in the history
…MM-1292

# Conflicts:
#	infobip-mobile-messaging-android-sdk/src/main/AndroidManifest.xml
  • Loading branch information
stanislavin committed Feb 22, 2017
2 parents 9bfdfb5 + 40fedd0 commit 5ed7d86
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This guide is designed to get you up and running with Mobile Messaging SDK integ
```groovy
dependencies {
...
compile ('org.infobip.mobile.messaging.api:infobip-mobile-messaging-android-sdk:1.3.28@aar') {
compile ('org.infobip.mobile.messaging.api:infobip-mobile-messaging-android-sdk:1.3.29@aar') {
transitive = true;
}
}
Expand Down
43 changes: 21 additions & 22 deletions infobip-mobile-messaging-android-demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.infobip.mobile.messaging.demo">
package="org.infobip.mobile.messaging.demo">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".InspectActivity"
android:label="@string/title_activity_inspect">
android:name=".InspectActivity"
android:label="@string/title_activity_inspect">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>

<receiver
android:name="org.infobip.mobile.messaging.demo.MobileMessagingBroadcastReceiver">
<receiver android:name="org.infobip.mobile.messaging.demo.MobileMessagingBroadcastReceiver">
<intent-filter>
<action android:name="org.infobip.mobile.messaging.REGISTRATION_ACQUIRED"/>
<action android:name="org.infobip.mobile.messaging.REGISTRATION_CREATED"/>
<action android:name="org.infobip.mobile.messaging.API_COMMUNICATION_ERROR"/>
<action android:name="org.infobip.mobile.messaging.API_PARAMETER_VALIDATION_ERROR"/>
<action android:name="org.infobip.mobile.messaging.REGISTRATION_ACQUIRED" />
<action android:name="org.infobip.mobile.messaging.REGISTRATION_CREATED" />
<action android:name="org.infobip.mobile.messaging.API_COMMUNICATION_ERROR" />
<action android:name="org.infobip.mobile.messaging.API_PARAMETER_VALIDATION_ERROR" />
</intent-filter>
</receiver>

Expand Down
34 changes: 20 additions & 14 deletions infobip-mobile-messaging-android-sdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.infobip.mobile.messaging">
package="org.infobip.mobile.messaging">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<uses-permission android:name=".permission.C2D_MESSAGE"/>
<permission android:name=".permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name=".permission.C2D_MESSAGE" />

<permission
android:name=".permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application>

<receiver
android:name="org.infobip.mobile.messaging.gcm.MobileMessagingGcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</receiver>

<service
android:name="org.infobip.mobile.messaging.gcm.MobileMessagingGcmIntentService"
android:exported="false">
</service>
android:exported="false" />
<service
android:name="org.infobip.mobile.messaging.gcm.MobileMessagingInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
<action android:name="com.google.android.gms.iid.InstanceID" />
<!-- Intent filter below is for pre-4.4 KitKat devices -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
</service>

Expand All @@ -39,11 +41,15 @@

<receiver android:name="org.infobip.mobile.messaging.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<receiver android:name="org.infobip.mobile.messaging.geo.GeofencingAlarmReceiver"/>
<receiver android:name="org.infobip.mobile.messaging.geo.GeofencingConsistencyReceiver">
<intent-filter>
<action android:name="android.location.PROVIDERS_CHANGED" />
</intent-filter>
</receiver>

<receiver android:name="org.infobip.mobile.messaging.notification.NotificationTapReceiver"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ void enablePushRegistration() {
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.PUSH_REGISTRATION_ENABLED, true);
registrationSynchronizer.updatePushRegistrationStatus(context, getRegistrationId(), true, getStats(), registrationAlignedExecutor);
if (isGeofencingActivated(context)) {
Geofencing.getInstance(context).activate();
Geofencing.getInstance(context).startGeoMonitoring();
}
}

void disablePushRegistration() {
PreferenceHelper.saveBoolean(context, MobileMessagingProperty.PUSH_REGISTRATION_ENABLED, false);
registrationSynchronizer.updatePushRegistrationStatus(context, getRegistrationId(), false, getStats(), registrationAlignedExecutor);
if (isGeofencingActivated(context)) {
Geofencing.getInstance(context).deactivate();
Geofencing.getInstance(context).stopGeoMonitoring();
}
}

Expand Down Expand Up @@ -422,21 +422,25 @@ public static boolean isGeofencingActivated(Context context) {
return PreferenceHelper.findBoolean(context, MobileMessagingProperty.GEOFENCING_ACTIVATED);
}

public void activateGeofencing() {
activateGeofencing(geofencing);
public void startGeoMonitoringIfNecessary() {
if (isGeofencingActivated(context) && isPushRegistrationEnabled()) {
if (geofencing == null) {
geofencing = Geofencing.getInstance(context);
}
geofencing.startGeoMonitoring();
}
}

void activateGeofencing(Geofencing geofencing) {
this.geofencing = geofencing;
setGeofencingActivated(context, geofencing != null);
if (geofencing == null) return;
geofencing.activate();
setGeofencingActivated(context, true);
geofencing.startGeoMonitoring();
}

void deactivateGeofencing() {
if (geofencing == null) return;
setGeofencingActivated(context, false);
geofencing.deactivate();
geofencing.stopGeoMonitoring();
this.geofencing = null;
}

Expand Down Expand Up @@ -660,7 +664,7 @@ public Builder withApplicationCode(String applicationCode) {
}

/**
* It will activate monitoring geo areas and notify when area is entered.
* It will start monitoring geo areas and notify device when area is entered.
*
* @param geofencing - handles monitored geo areas
* @return {@link Builder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ public final class MobileMessagingLogger {

public static final String TAG = "MobileMessaging";
private static Context context;
private static boolean isEnforced = false;

public static void init(Context context) {
MobileMessagingLogger.context = context;
}

public static void enforce() {
isEnforced = true;
}

public static void v(String tag, String msg) {
log(Log.VERBOSE, tag, msg, null);
}
Expand Down Expand Up @@ -95,7 +100,7 @@ public static void e(String msg, Throwable tr) {

private static void log(int logLevel, String tag, String msg, Throwable tr) {
boolean isDebuggable = (context != null && 0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
if (!isDebuggable) {
if (!isDebuggable && !isEnforced) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void saveMessage(Context context, Message message) {
messageStore.save(context, message);

if (MobileMessagingCore.hasGeo(message)) {
MobileMessagingCore.getInstance(context).activateGeofencing();
MobileMessagingCore.getInstance(context).startGeoMonitoringIfNecessary();
}
} catch (Exception e) {
MobileMessagingLogger.e(InternalSdkError.ERROR_SAVING_MESSAGE.get(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,20 @@ private void setLastNotificationTimeForArea(String messageId, String areaId, int
}

private void notifyAboutTransition(Context context, Geo geo, int geofenceTransition, Message message) {
saveMessage(message);
NotificationHandler.displayNotification(context, message);
sendGeoEventBroadcast(context, geofenceTransition, geo, message);
}

private void saveMessage(Message message) {
if (!MobileMessagingCore.getInstance(context).isMessageStoreEnabled()) {
return;
}

message.setSeenTimestamp(0);
MobileMessagingCore.getInstance(context).getMessageStore().save(context, message);
}

private void sendGeoEventBroadcast(Context context, int geofenceTransition, Geo geo, Message message) {
Event event = transitionBroadcasts.get(geofenceTransition);
if (event == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

public class GeofenceTransitionsIntentService extends IntentService {

final GeoAreasHandler geoAreasHandler = new GeoAreasHandler(this);

public GeofenceTransitionsIntentService() {
super(GeofenceTransitionsIntentService.class.getSimpleName());
}

@Override
protected void onHandleIntent(Intent intent) {
final GeoAreasHandler geoAreasHandler = new GeoAreasHandler(this);
geoAreasHandler.handleTransition(intent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public static void scheduleRefresh(Context context, Date when) {
}

AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, when.getTime(), PendingIntent.getBroadcast(context, 0, new Intent(context, GeofencingAlarmReceiver.class), 0));
Intent intent = new Intent(context, GeofencingConsistencyReceiver.class);
intent.setAction(GeofencingConsistencyReceiver.SCHEDULED_GEO_REFRESH_ACTION);
alarmManager.set(AlarmManager.RTC_WAKEUP, when.getTime(), PendingIntent.getBroadcast(context, 0, intent, 0));
}

@SuppressWarnings("WeakerAccess")
Expand Down Expand Up @@ -149,7 +151,7 @@ private static Date calculateNextCheckDateForGeo(Geo geo, Date oldCheckDate) {
}

@SuppressWarnings("MissingPermission")
public void activate() {
public void startGeoMonitoring() {

if (!PlayServicesSupport.isPlayServicesAvailable(context) ||
!MobileMessagingCore.isGeofencingActivated(context)) {
Expand Down Expand Up @@ -177,13 +179,12 @@ public void activate() {
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
MobileMessagingCore.setGeofencingActivated(context, status.isSuccess());
logGeofenceStatus(status, true);
}
});
}

public void deactivate() {
public void stopGeoMonitoring() {

if (!checkRequiredPermissions()) {
return;
Expand All @@ -198,7 +199,6 @@ public void deactivate() {
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
MobileMessagingCore.setGeofencingActivated(context, !status.isSuccess());
logGeofenceStatus(status, false);
}
});
Expand Down Expand Up @@ -275,7 +275,7 @@ private PendingIntent geofencePendingIntent() {
@Override
public void onConnected(@Nullable Bundle bundle) {
MobileMessagingLogger.d(TAG, "GoogleApiClient connected");
activate();
startGeoMonitoring();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import android.content.Intent;

/**
* @deprecated Use {@link GeofencingConsistencyReceiver} instead.
* @author sslavin
* @since 09/09/16.
*/
@Deprecated
public class GeofencingAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Geofencing.getInstance(context).activate();
Geofencing.getInstance(context).startGeoMonitoring();
}
}
Loading

0 comments on commit 5ed7d86

Please sign in to comment.