question

newuser-b32bc54c-3c90-43e9-a1cf-dc105476c7d3 avatar image

Crash in ADMMessageReceiver on Fire OS 7

We've recently been getting crash reports on the Fire TV Cube 2nd gen (Fire OS 7) when our app is in background. We're using a service called FireTVNotificationPushService that extends ADMMessageHandlerBase. It appears that starting on Android 8 background services are usually not allowed which I assume is what's causing this error.

The stack trace is as follows:


Caused by java.lang.IllegalStateException

Not allowed to start service Intent { act=com.amazon.device.messaging.intent.RECEIVE cat=[com.company.appname] flg=0x10 pkg=com.company.appname cmp=com.company.appname/.tv.notifications.FireTvNotificationPushService (has extras) }: app is in background uid UidRecord{e505199 u0a168 RCVR idle change:uncached procs:1 seq(0,0,0)}

android.app.ContextImpl.startServiceCommon (ContextImpl.java:1613)

android.app.ContextImpl.startService (ContextImpl.java:1568)

android.content.ContextWrapper.startService (ContextWrapper.java:664)

android.content.ContextWrapper.startService (ContextWrapper.java:664)

com.amazon.device.messaging.ADMMessageReceiver.onReceive (ADMMessageReceiver.java:118)

android.app.ActivityThread.handleReceiver (ActivityThread.java:3400)


fire tvamazon device messaging
10 |3000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kasten avatar image
Kasten answered

This seems like a bug with FireOS itself. Since we are seeing "com.amazon.device.messaging.ADMMessageReceiver.onReceive ADMMessageReceiver.java:118 " as the last non-Android method in the stack. It seems like FireOS hasn't updated to using a JobScheduler for ADM since switching to Android 9 as a base.

For reference there another thread open with this same crash

https://forums.developer.amazon.com/questions/218880/amazon-app-crashes-on-fire-hd-10-2019-on-receive-p.html


Also for reference there is a Github issue open about it in the OneSignal repo
https://github.com/OneSignal/OneSignal-Android-SDK/issues/890

10 |3000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

newuser-e664859f-4f70-40a9-a2ec-6f32b6535e85 avatar image
newuser-e664859f-4f70-40a9-a2ec-6f32b6535e85 answered

I solve it by custom service:


public static class CustomJobIntentService extends JobIntentService {
    static final String TAG 
    static final int JOB_ID = 101;
    static void enqueueWork(Context context, Intent work) {
        enqueueWork(context, CustomJobIntentService.class, JOB_ID, work);
    }

    protected void processIntent(Intent intent) {
        Bundle data = intent.getExtras();
        String action = intent.getAction();
        if(data == null) {
            return;
        }
        if(data.containsKey(ADMConstants.LowLevel.EXTRA_ERROR)) {
            // log error
        } else if(data.containsKey(ADMConstants.LowLevel.EXTRA_REGISTRATION_ID) && action.equals("com.amazon.device.messaging.intent.REGISTRATION")) {
            String registrationId = data.getString(ADMConstants.LowLevel.EXTRA_REGISTRATION_ID);
            // something like onPushTokenReceived(registrationId);
        } else if(data.containsKey(ADMConstants.LowLevel.EXTRA_UNREGISTERED)) {
            // log or whatever
        } else {
            // something like processPushNotification(intent.getExtras());
        }
    }

    @Override
    protected void onHandleWork(@NonNull Intent intent) {
        processIntent(intent);
    }
}
public static class MessageAlertReceiverAlt extends BroadcastReceiver {
   @Override
   public void onReceive(Context context, Intent intent) {
       CustomJobIntentService.enqueueWork(context, intent);
   }
}

in AndroidManifest.xml

<receiver android:name="com.myapp.MessageAlertReceiverAlt" android:permission="com.amazon.device.messaging.permission.SEND">

<service android:name="com.myapp.CustomJobIntentService" android:permission="android.permission.BIND_JOB_SERVICE" />
10 |3000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.