diff options
Diffstat (limited to 'android/src')
7 files changed, 182 insertions, 1 deletions
diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java index b24dc0a22e..bb005118c5 100644 --- a/android/src/com/mapswithme/maps/MwmApplication.java +++ b/android/src/com/mapswithme/maps/MwmApplication.java @@ -41,6 +41,9 @@ import com.my.tracker.MyTracker; import com.my.tracker.MyTrackerParams; import com.pushwoosh.PushManager; import io.fabric.sdk.android.Fabric; +import ru.mail.libnotify.api.NotificationFactory; +import ru.mail.notify.core.api.BackgroundAwakeMode; +import ru.mail.notify.core.api.NetworkSyncMode; import java.util.List; @@ -165,6 +168,7 @@ public class MwmApplication extends Application private void initCoreIndependentSdks() { initCrashlytics(); + initLibnotify(); initPushWoosh(); initAppsFlyer(); initTracker(); @@ -333,6 +337,22 @@ public class MwmApplication extends Application } } + private void initLibnotify() + { + if (BuildConfig.DEBUG || BuildConfig.BUILD_TYPE.equals("beta")) + { + NotificationFactory.enableDebugMode(); + NotificationFactory.setLogReceiver(LoggerFactory.INSTANCE.createLibnotifyLogger()); + NotificationFactory.setUncaughtExceptionListener((thread, throwable) -> { + Logger l = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.THIRD_PARTY); + l.e("LIBNOTIFY", "Thread: " + thread, throwable); + }); + } + NotificationFactory.setNetworkSyncMode(NetworkSyncMode.WIFI_ONLY); + NotificationFactory.setBackgroundAwakeMode(BackgroundAwakeMode.DISABLED); + NotificationFactory.initialize(this); + } + private void initAppsFlyer() { // There is no necessary to use a conversion data listener for a while. diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index f52b8a3a4d..d8ce890d48 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -41,6 +41,7 @@ import com.mapswithme.util.UiUtils; import com.mapswithme.util.Utils; import com.mapswithme.util.concurrency.UiThread; import com.mapswithme.util.statistics.Statistics; +import ru.mail.libnotify.debug.NotifyDebugActivity; import java.util.ArrayList; import java.util.LinkedList; @@ -518,6 +519,12 @@ public class SearchFragment extends BaseMwmFragment return true; } + if (str.equals("?libnotifyId")) + { + startActivity(new Intent(getContext(), NotifyDebugActivity.class)); + return true; + } + return false; } diff --git a/android/src/com/mapswithme/util/log/LibnotifyLogReceiver.java b/android/src/com/mapswithme/util/log/LibnotifyLogReceiver.java new file mode 100644 index 0000000000..a5c3ad2a63 --- /dev/null +++ b/android/src/com/mapswithme/util/log/LibnotifyLogReceiver.java @@ -0,0 +1,45 @@ +package com.mapswithme.util.log; + +import ru.mail.notify.core.utils.LogReceiver; + +class LibnotifyLogReceiver implements LogReceiver +{ + private static final Logger LOGGER + = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.THIRD_PARTY); + private static final String TAG = "LIBNOTIFY_"; + @Override + public void v(String tag, String msg) + { + LOGGER.v(TAG + tag, msg); + } + + @Override + public void v(String tag, String msg, Throwable throwable) + { + LOGGER.v(TAG + tag, msg, throwable); + } + + @Override + public void e(String tag, String msg) + { + LOGGER.e(TAG + tag, msg); + } + + @Override + public void e(String tag, String msg, Throwable throwable) + { + LOGGER.e(tag, msg, throwable); + } + + @Override + public void d(String tag, String msg) + { + LOGGER.d(TAG + tag, msg); + } + + @Override + public void d(String tag, String msg, Throwable throwable) + { + LOGGER.d(TAG + tag, msg, throwable); + } +} diff --git a/android/src/com/mapswithme/util/log/LoggerFactory.java b/android/src/com/mapswithme/util/log/LoggerFactory.java index de130074f5..89782bf4b2 100644 --- a/android/src/com/mapswithme/util/log/LoggerFactory.java +++ b/android/src/com/mapswithme/util/log/LoggerFactory.java @@ -12,6 +12,7 @@ import com.mapswithme.maps.R; import com.mapswithme.util.StorageUtils; import net.jcip.annotations.GuardedBy; import net.jcip.annotations.ThreadSafe; +import ru.mail.notify.core.utils.LogReceiver; import java.io.File; import java.util.EnumMap; @@ -24,7 +25,7 @@ public class LoggerFactory public enum Type { MISC, LOCATION, TRAFFIC, GPS_TRACKING, TRACK_RECORDER, ROUTING, NETWORK, STORAGE, DOWNLOADER, - CORE + CORE, THIRD_PARTY } public interface OnZipCompletedListener @@ -135,6 +136,11 @@ public class LoggerFactory return mFileLoggerExecutor; } + @NonNull + public LogReceiver createLibnotifyLogger() + { + return new LibnotifyLogReceiver(); + } // Called from JNI. @SuppressWarnings("unused") private static void logCoreMessage(int level, String msg) diff --git a/android/src/com/mapswithme/util/push/GCMListenerRouterService.java b/android/src/com/mapswithme/util/push/GCMListenerRouterService.java new file mode 100644 index 0000000000..4bd025a03e --- /dev/null +++ b/android/src/com/mapswithme/util/push/GCMListenerRouterService.java @@ -0,0 +1,75 @@ +package com.mapswithme.util.push; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.text.TextUtils; + +import com.google.android.gms.gcm.GcmListenerService; +import com.google.android.gms.gcm.GcmReceiver; +import com.mapswithme.util.log.Logger; +import com.mapswithme.util.log.LoggerFactory; +import com.pushwoosh.GCMListenerService; +import ru.mail.libnotify.api.NotificationFactory; + +// It's temporary class, it may be deleted along with Pushwoosh sdk. +// The base of this code is taken from https://www.pushwoosh.com/docs/gcm-integration-legacy. +public class GCMListenerRouterService extends GcmListenerService +{ + private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.THIRD_PARTY); + private static final String TAG = GCMListenerRouterService.class.getSimpleName(); + @Override + public void onMessageReceived(@Nullable String from, @Nullable Bundle data) { + LOGGER.i(TAG, "Gcm router service received message: " + + (data != null ? data.toString() : "<null>") + " from: " + from); + + if (data == null || TextUtils.isEmpty(from)) + return; + + // Base GCM listener service removes this extra before calling onMessageReceived. + // Need to set it again to pass intent to another service. + data.putString("from", from); + + String pwProjectId = getPWProjectId(getApplicationContext()); + if (!TextUtils.isEmpty(pwProjectId) && pwProjectId.contains(from)) { + dispatchMessage(GCMListenerService.class.getName(), data); + return; + } + + NotificationFactory.deliverGcmMessageIntent(this, from, data); + } + + @Nullable + private static String getPWProjectId(@NonNull Context context) + { + PackageManager pMngr = context.getPackageManager(); + try + { + ApplicationInfo ai = pMngr.getApplicationInfo(context.getPackageName(), PackageManager + .GET_META_DATA); + Bundle metaData = ai.metaData; + if (metaData == null) + return null; + return metaData.getString("PW_PROJECT_ID"); + } + catch (PackageManager.NameNotFoundException e) + { + LOGGER.e(TAG, "Failed to get push woosh projectId: ", e); + } + return null; + } + + private void dispatchMessage(@NonNull String component, @NonNull Bundle data) { + Intent intent = new Intent(); + intent.putExtras(data); + intent.setAction("com.google.android.c2dm.intent.RECEIVE"); + intent.setComponent(new ComponentName(getPackageName(), component)); + + GcmReceiver.startWakefulService(getApplicationContext(), intent); + } +} diff --git a/android/src/com/mapswithme/util/push/GcmInstanceIDRouterListenerService.java b/android/src/com/mapswithme/util/push/GcmInstanceIDRouterListenerService.java new file mode 100644 index 0000000000..06658a2c5e --- /dev/null +++ b/android/src/com/mapswithme/util/push/GcmInstanceIDRouterListenerService.java @@ -0,0 +1,24 @@ +package com.mapswithme.util.push; + +import android.content.Intent; + +import com.google.android.gms.iid.InstanceIDListenerService; +import com.mapswithme.util.log.Logger; +import com.mapswithme.util.log.LoggerFactory; +import com.pushwoosh.GCMInstanceIDListenerService; +import ru.mail.libnotify.api.NotificationFactory; + +public class GcmInstanceIDRouterListenerService extends InstanceIDListenerService +{ + @Override + public void onTokenRefresh() + { + super.onTokenRefresh(); + Logger l = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.THIRD_PARTY); + l.i(GcmInstanceIDRouterListenerService.class.getSimpleName(), "onTokenRefresh()"); + Intent pwIntent = new Intent(this, GCMInstanceIDListenerService.class); + pwIntent.setAction("com.google.android.gms.iid.InstanceID"); + startService(pwIntent); + NotificationFactory.refreshGcmToken(this); + } +} diff --git a/android/src/com/mapswithme/util/statistics/PushwooshHelper.java b/android/src/com/mapswithme/util/statistics/PushwooshHelper.java index f72f033ee0..f59031d1a6 100644 --- a/android/src/com/mapswithme/util/statistics/PushwooshHelper.java +++ b/android/src/com/mapswithme/util/statistics/PushwooshHelper.java @@ -5,10 +5,12 @@ import android.os.AsyncTask; import android.os.Handler; import android.os.Looper; +import com.mapswithme.maps.MwmApplication; import com.mapswithme.util.log.Logger; import com.mapswithme.util.log.LoggerFactory; import com.pushwoosh.PushManager; import com.pushwoosh.SendPushTagsCallBack; +import ru.mail.libnotify.api.NotificationFactory; import java.lang.ref.WeakReference; import java.util.HashMap; @@ -53,6 +55,8 @@ public final class PushwooshHelper implements SendPushTagsCallBack private void sendTags(Map<String, Object> tags) { + //TODO: move notifylib code to another place when Pushwoosh is deleted. + NotificationFactory.get(MwmApplication.get()).collectEventBatch(tags); synchronized (mSyncObject) { if (!canSendTags()) |