New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 747959 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Aug 2017
Cc:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 1
Type: Bug



Sign in to add a comment

"Chrome has stopped" display after tapping "ADD" when adding shortcut to Home screen.

Reported by somcs...@gmail.com, Jul 24 2017

Issue description

Steps to reproduce the problem:
Pre Conditions : 
Google account added in DUT.
Steps:
Scenario 1:
1.	Launch Chrome for the first time.
2.	After Setup complete while page loading tap Settings-> Add to Home screen>Type something> ADD.

Scenario 2:
1.	Launch Chrome.
2.	Search something.
3.	Long tap any link in the list of search results.
4.	Tap “Open in new tab”.
5.	Open new tab that was created in step4.
6.	While page loading Settings-> Add to Home screen>Type something> ADD.

What is the expected behavior?
Crash should not occur.

What went wrong?
"Chrome has stopped" display.

Did this work before? N/A 

Chrome version: 59.0.3071.115  Channel: n/a
OS Version: 8.00
Flash Version: 

Root cause : 
07-12 12:33:57.391 12091 12091 W System.err: java.lang.IllegalArgumentException: Bitmap must not be null.
07-12 12:33:57.391  1174  1603 I hash_map_utils: key: 'incall_music' value: ''
07-12 12:33:57.391 12091 12091 W System.err:    at android.graphics.drawable.Icon.createWithBitmap(Icon.java:557)
07-12 12:33:57.391 12091 12091 W System.err:    at com.google.android.apps.chrome.webapps.ChromeShortcutManagerInternal.addShortcutToHomeScreen(ChromeShortcutManagerInternal.java:41)
07-12 12:33:57.391 12091 12091 W System.err:    at org.chromium.chrome.browser.ShortcutHelper$Delegate.addShortcutToHomescreen(ShortcutHelper.java:118)
07-12 12:33:57.391 12091 12091 W System.err:    at org.chromium.chrome.browser.ShortcutHelper.addShortcut(ShortcutHelper.java:221)
07-12 12:33:57.391 12091 12091 W System.err:    at org.chromium.chrome.browser.webapps.AddToHomescreenManager.nativeAddShortcut(Native Method)
07-12 12:33:57.391 12091 12091 W System.err:    at org.chromium.chrome.browser.webapps.AddToHomescreenManager.addShortcut(AddToHomescreenManager.java:68)
07-12 12:33:57.391 12091 12091 W System.err:    at org.chromium.chrome.browser.webapps.AddToHomescreenDialog$4.onClick(AddToHomescreenDialog.java:115)
07-12 12:33:57.391 12091 12091 W System.err:    at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:157)
07-12 12:33:57.391 12091 12091 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:105)
07-12 12:33:57.391 12091 12091 W System.err:    at android.os.Looper.loop(Looper.java:255)
07-12 12:33:57.391 12091 12091 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:6563)
07-12 12:33:57.391 12091 12091 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
07-12 12:33:57.391 12091 12091 W System.err:    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
07-12 12:33:57.391 12091 12091 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

In this case bitmap is null and it is throwing java.lang.IllegalArgumentException: Bitmap must not be null.

Searched in Google 
https://android.googlesource.com/platform/frameworks/base/+/6c6f142/graphics/java/android/graphics/drawable/Icon.java

/**
     * Create an Icon pointing to a bitmap in memory.
     * @param bits A valid {@link android.graphics.Bitmap} object
     */
    public static Icon createWithBitmap(Bitmap bits) {
        if (bits == null) {
            throw new IllegalArgumentException("Bitmap must not be null.");
        }
        final Icon rep = new Icon(TYPE_BITMAP);
        rep.mObj1 = bits;
        return rep;
    }

And this "createWithBitmap" is called by addShortcutWithShortcutManager

https://chromium.googlesource.com/chromium/src.git/+/1aa98d7cf548e42ef1a75828caa6d6831445172b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeShortcutManager.java

private void addShortcutWithShortcutManager(String title, Bitmap icon, Intent shortcutIntent) {
        String id = shortcutIntent.getStringExtra(ShortcutHelper.EXTRA_ID);
        Context context = ContextUtils.getApplicationContext();
-
-
-
  Method setIcon = builderClass.getMethod("setIcon", Icon.class);
  setIcon.invoke(shortcutBuilder, Icon.createWithBitmap(icon));

Icon.createWithBitmap(icon) -> icon parameter is null and it is passed by chrome. So it is Chrome issue.

and also we can confirm the behavior of bitmap is null in UI also.
 

Comment 1 by somcs...@gmail.com, Jul 25 2017

ocn.mp4
7.7 MB View Download

Comment 2 by somcs...@gmail.com, Jul 25 2017

bugreport-bullhead-OPP3.170518.006-2017-07-21-14-49-06.zip
2.3 MB Download

Comment 3 by somcs...@gmail.com, Jul 25 2017

I have attached the video and bugreport.
Issue is reproducing in Nexus 5x also.
Cc: aska...@chromium.org
Labels: triage-te
askatte@, can you take a look?
Cc: -aska...@chromium.org martiw@chromium.org
Components: UI>Browser>AppShortcuts
Labels: -triage-te -Arch-x86_64
Owner: dominickn@chromium.org
Status: Assigned (was: Unconfirmed)
I could repro this crash on Bullhead / Nexus 5X / 8.0. 

The bugreport says,
java.lang.IllegalArgumentException: Bitmap must not be null.
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at android.graphics.drawable.Icon.createWithBitmap(Icon.java:557)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at com.google.android.apps.chrome.webapps.ChromeShortcutManagerInternal.addShortcutToHomeScreen(ChromeShortcutManagerInternal.java:18)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at org.chromium.chrome.browser.ShortcutHelper$Delegate.addShortcutToHomescreen(ShortcutHelper.java:2)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at org.chromium.chrome.browser.ShortcutHelper.addShortcut(ShortcutHelper.java:16)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at org.chromium.chrome.browser.webapps.AddToHomescreenManager.nativeAddShortcut(Native Method)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at org.chromium.chrome.browser.webapps.AddToHomescreenManager.addShortcut(AddToHomescreenManager.java:7)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at org.chromium.chrome.browser.webapps.AddToHomescreenDialog$4.onClick(AddToHomescreenDialog.java:6)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:5)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at android.os.Handler.dispatchMessage(Handler.java:105)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at android.os.Looper.loop(Looper.java:164)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6541)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at java.lang.reflect.Method.invoke(Native Method)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
07-21 14:48:03.903 10059 28727 28727 W System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
07-21 14:48:03.904 10059 28727 28727 F chromium: [FATAL:jni_android.cc(243)] Please include Java exception stack in crash report

dominickn@ or martiw@ can you please take a look?

Comment 6 by martiw@google.com, Jul 27 2017

I could repro this crash on both Pixel and Nexus 6P on 8.0.
It is much easier to repro by following the steps of Scenario 2 and connecting GIN-2g wi-fi.

Comment 7 by martiw@google.com, Jul 27 2017

The root cause:
When trying to add shortcut but the Page is not loaded.
Chrome will try to add a shortcut with a NULL as icon at addShortcutWithShortcutManager() and cause the crash.

Possible solution:
- Should we disable "Add to Home Screen" in menu when the page is not loaded?
- Or should we prepare an "Empty icon" (like R.drawable.navigation_empty_icon) and use it when icon is NULL?

In Chrome 55 on Android 7.1.2., in the same situation,  no shortcut will be added.  (although there will be toast said "shortcut added", nothing happened indeed.)
Issue 749418 has been merged into this issue.
Labels: -Pri-2 M-61 ReleaseBlock-Stable Pri-1
Thanks for investigating Marti.

The icon should never end up null. If we fail to fetch an icon we should be generating one. I'm travelling and don't have an Android O device with me to investigate exactly what is going on here - if you have a chance, can you please put some LOG statements into add_to_homescreen_data_fetcher to work out what is going on when OnDataTimedout is being called?
Hi Dominick, when I reproduced the crash, in add_to_homescreen_data_fetcher:

- OnDataTimedout wasn't called.

- CreateLauncherIconInBackground was called (by CreateLauncherIconFromFaviconInBackground)

- primary_icon.getPixels()==nullptr at the end of CreateLauncherIconInBackground

Thanks for investigating. I've taken a look and figured out what is going wrong. It's a bit of a cascading series of failures:

1. icon generation relies on having |shortcut_info_.url| set to a non-null URL.
2. |shortcut_info_.url| is set based on content::WebContents::GetLastCommittedURL
3. |shortcut_info_.url| will be blank if add to homescreen is invoked *before* navigation commit

Hence, invoking add to homescreen before navigation commit means that icon generation fails and we get a null icon back.

I think the fix here is to disable add to homescreen prior to navigation commit as per the suggestion in c#7. I can prepare a CL for this.
Based on discussion with martiw@, we actually think falling back to the visible URL is the better way here:

1. last committed URL will be non-empty if we had previous navigations in the same tab
2. every thing else in the menu relies on the visible URL.
Project Member

Comment 13 by bugdroid1@chromium.org, Aug 10 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/e915a0344793b323a2fcb79216f9585912781dbe

commit e915a0344793b323a2fcb79216f9585912781dbe
Author: Dominick Ng <dominickn@chromium.org>
Date: Thu Aug 10 05:23:30 2017

Use the current visible URL for add to homescreen.

This addresses a bug where invoking add to homescreen prior to
navigation commit led to a null icon being generated for the page. This
causes either:

a) no shortcut to be added (pre Android O); or
b) a crash (Android O+)

The fix replaces the use of the last committed URL with the current
visible URL. This is arguably more correct since all other items in the
Chrome menu determine their enabled state based on the visible URL, not
the last committed URL.

BUG= 747959 

Change-Id: If1f431ca29f5948ee6f562e2db773d408218bde7
Reviewed-on: https://chromium-review.googlesource.com/604819
Commit-Queue: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#493263}
[modify] https://crrev.com/e915a0344793b323a2fcb79216f9585912781dbe/chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuPropertiesDelegate.java
[modify] https://crrev.com/e915a0344793b323a2fcb79216f9585912781dbe/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabAppMenuPropertiesDelegate.java
[modify] https://crrev.com/e915a0344793b323a2fcb79216f9585912781dbe/chrome/android/java/src/org/chromium/chrome/browser/webapps/AddToHomescreenManager.java
[modify] https://crrev.com/e915a0344793b323a2fcb79216f9585912781dbe/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/AddToHomescreenManagerTest.java
[modify] https://crrev.com/e915a0344793b323a2fcb79216f9585912781dbe/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc
[modify] https://crrev.com/e915a0344793b323a2fcb79216f9585912781dbe/chrome/browser/android/webapps/add_to_homescreen_data_fetcher_unittest.cc
[modify] https://crrev.com/e915a0344793b323a2fcb79216f9585912781dbe/chrome/browser/android/webapps/add_to_homescreen_manager.cc

Cc: aska...@chromium.org
askatte, can you check the fix in M62?
Verified fix in 62.0.3192.0 / Nexus 5X / OPR1.170623.011
Thanks!
Status: Fixed (was: Assigned)
Labels: Merge-TBD
[Auto-generated comment by a script] We noticed that this issue is targeted for M-61; it appears the fix may have landed after branch point, meaning a merge might be required. Please confirm if a merge is required here - if so add Merge-Request-61 label, otherwise remove Merge-TBD label. Thanks.
Labels: -Merge-TBD
This has been an issue for quite some time. I think we're okay not merging to 61 and waiting until 62.

Sign in to add a comment