[android] Replaced WakefulReceiver to JobIntentService for GCM

This commit is contained in:
Dmitry Donskoy 2018-08-22 18:32:41 +03:00 committed by Aleksandr Zatsepin
parent 41260225e6
commit e300e80c54
3 changed files with 28 additions and 8 deletions

View file

@ -440,6 +440,13 @@
android:label="@string/subtittle_opt_out"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
<service
android:name="com.mapswithme.util.push.GcmRouterJobIntentService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false">
</service>
<receiver
android:name="com.mapswithme.maps.background.ConnectivityChangedReceiver"
android:enabled="true"

View file

@ -1,6 +1,5 @@
package com.mapswithme.util.push;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@ -8,14 +7,13 @@ import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.JobIntentService;
import android.text.TextUtils;
import com.google.android.gms.gcm.GcmListenerService;
import com.google.android.gms.gcm.GcmReceiver;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.util.log.Logger;
import com.mapswithme.util.log.LoggerFactory;
import com.pushwoosh.PushGcmIntentService;
import ru.mail.libnotify.api.NotificationFactory;
// It's temporary class, it may be deleted along with Pushwoosh sdk.
@ -39,7 +37,7 @@ public class GCMListenerRouterService extends GcmListenerService
String pwProjectId = getPWProjectId(getApplicationContext());
if (!TextUtils.isEmpty(pwProjectId) && pwProjectId.contains(from)) {
dispatchMessage(PushGcmIntentService.class.getName(), data);
dispatchMessage(data);
return;
}
@ -66,12 +64,11 @@ public class GCMListenerRouterService extends GcmListenerService
return null;
}
private void dispatchMessage(@NonNull String component, @NonNull Bundle data) {
private void dispatchMessage(@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);
int jobId = GcmRouterJobIntentService.class.hashCode();
JobIntentService.enqueueWork(this, GcmRouterJobIntentService.class, jobId, intent);
}
}

View file

@ -0,0 +1,16 @@
package com.mapswithme.util.push;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.app.JobIntentService;
import com.pushwoosh.internal.utils.NotificationRegistrarHelper;
public class GcmRouterJobIntentService extends JobIntentService
{
@Override
protected void onHandleWork(@NonNull Intent intent)
{
NotificationRegistrarHelper.handleMessage(intent.getExtras());
}
}