Use Context#createPackageContext to work around Samsung's issue with small icons
The issue is related to the crashes http://crbug/829367 on Samsung (also, Lenovo
and Yulong) Marshmallow devices. Because of those crashes we prohibit setting
small notification icons as Bitmaps.
The icon coming from a web page shown in a TWA comes in a form of a Bitmap, so
we can't use that. A reasonable fallback would be to use the icon specified by
its resource id in meta-data for TWAService or by extending TWAService.
Unfortunately, there is a problem with that fallback as well. For M+ the small
icon has to be from the resources of the app whose context is passed to the
Notification.Builder constructor. Normally we would use the bitmap decoded (on
the client's side) from resource id. But then again, on Samsung M we can't set
that bitmap due to the crashes.
In this CL we create the context of client's app using Context#createForPackage,
pass that into NotificationBuilder, and that way we can use the icon id.
Since this approach is quite unusual and seems risky, it is used only in the
cases we're fixing, and protected by a feature flag.
Bug: 864786
Change-Id: Ia401f56b446e7dcc684697faea77ae2a3a402e67
Reviewed-on: https://chromium-review.googlesource.com/c/1228075
Commit-Queue: Pavel Shmakov <[email protected]>
Reviewed-by: Peter Conn <[email protected]>
Reviewed-by: Peter Beverloo <[email protected]>
Cr-Commit-Position: refs/heads/master@{#608516}
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index c54b83d..e1c9a4b 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -4520,6 +4520,14 @@
flag_descriptions::kEnableDiscoverAppDescription, kOsCrOS,
FEATURE_VALUE_TYPE(chromeos::features::kDiscoverApp)},
#endif // defined(OS_CHROMEOS)
+
+#if defined(OS_ANDROID)
+ {"allow-remote-context-for-notifications",
+ flag_descriptions::kAllowRemoteContextForNotificationsName,
+ flag_descriptions::kAllowRemoteContextForNotificationsDescription,
+ kOsAndroid,
+ FEATURE_VALUE_TYPE(chrome::android::kAllowRemoteContextForNotifications)},
+#endif // defined(OS_ANDROID)
};
class FlagsStateSingleton {