bumptech / bumptech/glide

AppWidgetTarget fails to update RemoteViews with maximum bitmap memory usage error

Open
#5,214 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

**Device/Android Version**:

Android 13

**Issue details / Repro steps / Use case background**:

Android has a limit on the maximum memory that a RemoteViews can use. Glide is not aware of that limit, which can cause loads to fail. The failure can appear random if certain images just so happen to exceed that limit. This seems like a usability issue with Android RemoteViews itself, but perhaps Glide can provide some relief, like trying to down-sample Bitmaps automatically to fit within the limit.

This issue is affecting Google Maps, specifically our Nearby traffic widget ([b/261379830](b/261379830), pigout@). As a workaround, Maps can:

1. downsample the Bitmap ourselves
2. then call Glide.load(Bitmap) instead of Glide.load(byte[]).

RemoteViews limit: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/services/appwidget/java/com/android/server/appwidget/AppWidgetServiceImpl.java;l=308;drc=731c7bb7b58d51e09a7b43e7adafa12363c87ee1

**Glide load line / `GlideModule` (if any) / list Adapter code (if any)**:
```kotlin

val appWidgetTarget =
AppWidgetTarget(context, R.id.view_id, remoteView, widgetId)

Glide.with(context)
.asBitmap()
.load(pngBytes.toByteArray())
.into(appWidgetTarget)

```

**Stack trace / LogCat**:
```ruby
ddl: Unexpected exception thrown by non-Glide code
at com.bumptech.glide.load.engine.EngineJob.callCallbackOnResourceReady(EngineJob:161)
at com.bumptech.glide.load.engine.EngineJob$CallResourceReady.run(EngineJob:428)
at com.bumptech.glide.load.engine.EngineJob$CallResourceReady.EngineJob$CallResourceReady$ar$run(EngineJob:0)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
Caused by: java.lang.IllegalArgumentException: RemoteViews for widget update exceeds maximum bitmap memory usage (used: 9437184, max: 6462720)
at android.os.Parcel.createExceptionOrNull(Parcel.java:3015)
at android.os.Parcel.createException(Parcel.java:2995)
at android.os.Parcel.readException(Parcel.java:2978)
at android.os.Parcel.readException(Parcel.java:2920)
at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetIds(IAppWidgetService.java:820)
at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:540)
at com.bumptech.glide.request.target.AppWidgetTarget.update(AppWidgetTarget:124)
at com.bumptech.glide.request.target.AppWidgetTarget.setBitmap(AppWidgetTarget:141)
at com.bumptech.glide.request.target.AppWidgetTarget.onResourceReady(AppWidgetTarget:131)
at com.bumptech.glide.request.target.AppWidgetTarget.onResourceReady(AppWidgetTarget:22)
at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest:669)
at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest:597)
at com.bumptech.glide.load.engine.EngineJob.callCallbackOnResourceReady(EngineJob:159)
at com.bumptech.glide.load.engine.EngineJob$CallResourceReady.run(EngineJob:428)
at com.bumptech.glide.load.engine.EngineJob$CallResourceReady.EngineJob$CallResourceReady$ar$run(EngineJob:0)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.appwidget.AppWidgetServiceImpl.updateAppWidgetInstanceLocked(AppWidgetServiceImpl.java:1872)
at com.android.server.appwidget.AppWidgetServiceImpl.updateAppWidgetIds(AppWidgetServiceImpl.java:1691)
at com.android.server.appwidget.AppWidgetServiceImpl.updateAppWidgetIds(AppWidgetServiceImpl.java:1434)
at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:399)
at android.os.Binder.execTransactInternal(Binder.java:1280)
```

Contributor guide

Open the contributing guide

Research direction

Start with AppWidgetTarget.update and setBitmap, which appear in the stack trace, and review how the provided RemoteViews is updated. Use the Android RemoteViews bitmap memory limit and the reproduction with pngBytes as the boundary conditions; done should define and verify behavior for images that exceed that limit.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.