Closed Bug 1491643 Opened 6 years ago Closed 6 years ago

Crash in java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.app.NotificationChannel.getId()' on a null object reference at org.mozilla.gecko.updater.Updater.startDownload(Updater.java)

Categories

(Firefox for Android Graveyard :: Download Manager, defect)

Unspecified
Android
defect
Not set
critical

Tracking

(firefox62 unaffected, firefox63 unaffected, firefox64 fixed)

RESOLVED FIXED
Firefox 64
Tracking Status
firefox62 --- unaffected
firefox63 --- unaffected
firefox64 --- fixed

People

(Reporter: jseward, Assigned: JanH)

References

Details

(Keywords: crash, regression)

Crash Data

Attachments

(1 file)

This bug was filed from the Socorro interface and is
report bp-d0bbdc3c-9c6a-4364-b0c7-da76f0180914.
=============================================================

This is the #3 topcrash in the Android nightly 20180913143243, with
8 crashes in 4 different installations.  I think I have the wrong
component, but I didn't see an "updater" component anywhere.

Java stack trace:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.app.NotificationChannel.getId()' on a null object reference
	at org.mozilla.gecko.updater.Updater.startDownload(Updater.java:281)
	at org.mozilla.gecko.updater.Updater.access$000(Updater.java:67)
	at org.mozilla.gecko.updater.Updater$1.run(Updater.java:168)
	at org.mozilla.gecko.permissions.PermissionBlock.executeRunnable(PermissionBlock.java:139)
	at org.mozilla.gecko.permissions.PermissionBlock.onPermissionsGranted(PermissionBlock.java:118)
	at org.mozilla.gecko.permissions.PermissionBlock.run(PermissionBlock.java:98)
	at org.mozilla.gecko.updater.Updater.startUpdate(Updater.java:165)
	at org.mozilla.gecko.updater.UpdatesCheckService.onHandleWork(UpdatesCheckService.java:14)
	at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:391)
	at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
	at android.os.AsyncTask$2.call(AsyncTask.java:333)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
	at java.lang.Thread.run(Thread.java:764)
Flags: needinfo?(nchen)
Problem 1: The crash happens for "getId()", so NotificationHelper.getInstance(context).getNotificationChannel(NotificationHelper.Channel.UPDATER) must have returned a null NotificationChannel. From reading through the framework sources, I had come away with the impression that querying an invalid notification channel from the NotificationManager would just return the system-created default channel, which cannot actually be used for displaying a notification if your target API is 26+, but at least is not null. Instead, it seems that we have to expect null values being returned there, too.

Problem 2a: Either the Updater runs even though it is supposed to be disabled. The visibility of the update button in about:firefox is only guarded on the MOZ_UPDATER define, so it would be one possible avenue for this. Empirically, a Nightly installed from the Play Store only shows "Update not available" after pressing the button, but I'm not entirely sure whether that is enforced from inside of our app (I think it isn't), or only through our update server and could possibly fail.

Problem 2b: Or else the Updater runs on a background thread, so maybe it manages to reach the point where it wants to start showing a notification faster than GeckoApplication can call NotificationHelper.getInstance(context).init()?
Assignee: nobody → jh+bugzilla
Problem 2b seems rather unlikely, since by my understanding GeckoApplication's onCreate() method should run first, thereby initialising our notification channels in the NotificationHelper, then the UpdaterService's onCreate() method next and only then could onHandleWork() for the respective UpdaterService sub-class be called (on a background thread as things stand).
Pretty sure `getNotificationChannel` does return null if you give it a nonexistent ID [1].

[1] http://androidxref.com/8.0.0_r4/xref/frameworks/base/services/core/java/com/android/server/notification/RankingHelper.java#645
Flags: needinfo?(nchen)
So far, we've generally opted for a policy of disabling the Updater when we've
been installed from the Play Store, not least because this is not allowed by the
Play Store's terms of service.

While other references to the Updater in the Android app UI are already
completely hidden in that case and we don't do any automatic checking for up-
dates either, the "Check for Updates" button on about:firefox is only hidden via
the MOZ_UPDATER build define and therefore still visible on all Nightly builds.
Since dynamically hiding it might be more involved, we just make sure that the
Updater simply aborts and returns NOT_AVAILABLE when an Update request has been
triggered from Gecko on a Play Store-installed build.

That way, we should be able to avoid all situations where the Updater might want
to display a notification, which of course doesn't work when the corresponding
notification channel hasn't been registered.
(In reply to Jim Chen [:jchen] [:darchons] from comment #4)
> Pretty sure `getNotificationChannel` does return null if you give it a
> nonexistent ID [1].
> 
> [1]
> http://androidxref.com/8.0.0_r4/xref/frameworks/base/services/core/java/com/
> android/server/notification/RankingHelper.java#645

Oh right, I misread that code originally. It only falls back to the DEFAULT_CHANNEL_ID if the channelId you pass in is already null. If it's not null but not registered, then you can indeed get back a null.
Comment on attachment 9009681 [details]
Bug 1491643 - Really disable updates when installed from the Play Store. r?jchen

Jim Chen [:jchen] [:darchons] has approved the revision.
Attachment #9009681 - Flags: review+
Pushed by mozilla@buttercookie.de:
https://hg.mozilla.org/integration/autoland/rev/5b265ae2ca23
Really disable updates when installed from the Play Store. r=jchen
https://hg.mozilla.org/mozilla-central/rev/5b265ae2ca23
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 64
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: