diff options
| author | 2023-10-23 18:30:21 +0000 | |
|---|---|---|
| committer | 2023-10-23 18:30:21 +0000 | |
| commit | ed5bd8cebdb237504e41f49ea3812c9bb17618e9 (patch) | |
| tree | ca377e887d72012ddd2205582fa0f62886cf33ba | |
| parent | 85f52d197c01929d17683807d8d6adbd9db4f717 (diff) | |
| parent | df3af7fdd097cdff925e5b86d501868a7f13ddc0 (diff) | |
Resize large app icons before adding them in a parcel am: df3af7fdd0
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2798385
Change-Id: I286f8ad80ffe7a79916abd66a8bd50e858a1f271
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java | 4 | ||||
| -rw-r--r-- | packages/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java | 16 |
2 files changed, 16 insertions, 4 deletions
diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java b/packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java index 97b807a76bb8..8cb25dc637d4 100644 --- a/packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java +++ b/packages/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java @@ -595,7 +595,7 @@ public class PackageInstallerActivity extends AlertActivity { CharSequence label = mPm.getApplicationLabel(mPkgInfo.applicationInfo); if (mLocalLOGV) Log.i(TAG, "creating snippet for " + label); mAppSnippet = new PackageUtil.AppSnippet(label, - mPm.getApplicationIcon(mPkgInfo.applicationInfo)); + mPm.getApplicationIcon(mPkgInfo.applicationInfo), getBaseContext()); } break; case ContentResolver.SCHEME_FILE: { @@ -633,7 +633,7 @@ public class PackageInstallerActivity extends AlertActivity { mPkgInfo = generateStubPackageInfo(info.getAppPackageName()); mAppSnippet = new PackageUtil.AppSnippet(info.getAppLabel(), info.getAppIcon() != null ? new BitmapDrawable(getResources(), info.getAppIcon()) - : getPackageManager().getDefaultActivityIcon()); + : getPackageManager().getDefaultActivityIcon(), getBaseContext()); return true; } diff --git a/packages/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java b/packages/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java index 6ab2def319cd..cf6af9588a78 100644 --- a/packages/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java +++ b/packages/PackageInstaller/src/com/android/packageinstaller/PackageUtil.java @@ -18,6 +18,7 @@ package com.android.packageinstaller; import android.app.Activity; +import android.app.ActivityManager; import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; @@ -123,15 +124,20 @@ public class PackageUtil { static final class AppSnippet implements Parcelable { @NonNull public CharSequence label; @Nullable public Drawable icon; - public AppSnippet(@NonNull CharSequence label, @Nullable Drawable icon) { + public int iconSize; + + public AppSnippet(@NonNull CharSequence label, @Nullable Drawable icon, Context context) { this.label = label; this.icon = icon; + final ActivityManager am = context.getSystemService(ActivityManager.class); + this.iconSize = am.getLauncherLargeIconSize(); } private AppSnippet(Parcel in) { label = in.readString(); Bitmap bmp = in.readParcelable(getClass().getClassLoader(), Bitmap.class); icon = new BitmapDrawable(Resources.getSystem(), bmp); + iconSize = in.readInt(); } @Override @@ -149,6 +155,7 @@ public class PackageUtil { dest.writeString(label.toString()); Bitmap bmp = getBitmapFromDrawable(icon); dest.writeParcelable(bmp, 0); + dest.writeInt(iconSize); } private Bitmap getBitmapFromDrawable(Drawable drawable) { @@ -162,6 +169,11 @@ public class PackageUtil { // bitmap held within drawable.draw(canvas); + // Scale it down if the icon is too large + if ((bmp.getWidth() > iconSize * 2) || (bmp.getHeight() > iconSize * 2)) { + bmp = Bitmap.createScaledBitmap(bmp, iconSize, iconSize, true); + } + return bmp; } @@ -218,7 +230,7 @@ public class PackageUtil { } catch (OutOfMemoryError e) { Log.i(LOG_TAG, "Could not load app icon", e); } - return new PackageUtil.AppSnippet(label, icon); + return new PackageUtil.AppSnippet(label, icon, pContext); } /** |