Commit 541bda2c authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android Webapp] Catch IllegalStateException thrown by requestPinShorctcut()

According to the docs
(https://developer.android.com/reference/android/content/pm/ShortcutManager.html)
ShortcutManager#requestPinShortcut() throws an IllegalStateException if
"The caller doesn't have a foreground activity or a foreground service, or the
device is locked."

We create a home screen shortcut if WebAPK install fails. WebAPK installs time
out and fail out after 3 minutes. A user may be using a different app by the
time that the time out occurs.

This CL catches and ignores IllegalStateExceptions thrown by
ShortcutHelper#requestPinShortcut()

Bug=819725

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Iceab1a25a0d80b9869cfc523f091c3af8e590a76
Reviewed-on: https://chromium-review.googlesource.com/959751
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542813}
parent 4cc07b0d
......@@ -231,7 +231,13 @@ public class ShortcutHelper {
.setIcon(Icon.createWithBitmap(icon))
.setIntent(shortcutIntent)
.build();
sShortcutManager.requestPinShortcut(shortcutInfo, null);
try {
sShortcutManager.requestPinShortcut(shortcutInfo, null);
} catch (IllegalStateException e) {
Log.d(TAG,
"Could not create pinned shortcut: device is locked, or "
+ "activity is backgrounded.");
}
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment