Skip to content

Commit

Permalink
Catch possible crash in getUserBadgedIcon
Browse files Browse the repository at this point in the history
Happening on Google Pixel 4 XL, Android 8.1.0
  • Loading branch information
emanuele-f committed May 31, 2024
1 parent 0351e7b commit 308de20
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import androidx.annotation.Nullable;

import com.emanuelef.remote_capture.CaptureService;
import com.emanuelef.remote_capture.Log;
import com.emanuelef.remote_capture.interfaces.DrawableLoader;

import java.io.Serializable;
Expand All @@ -41,6 +42,8 @@ public class AppDescriptor implements Comparable<AppDescriptor>, Serializable {
private Drawable mIcon;
private final DrawableLoader mIconLoader;
private String mDescription;
private static final String TAG = "AppDescriptor";
private static boolean badgedIconFails = false;

// NULL for virtual apps
PackageManager mPm;
Expand Down Expand Up @@ -97,8 +100,18 @@ public String getName() {
// the badge is added below via getUserHandleForUid
mIcon = mPackageInfo.applicationInfo.loadUnbadgedIcon(mPm);

UserHandle handle = UserHandle.getUserHandleForUid(mUid);
mIcon = mPm.getUserBadgedIcon(mIcon, handle);
if (!badgedIconFails) {
try {
UserHandle handle = UserHandle.getUserHandleForUid(mUid);

// On some systems may throw "java.lang.SecurityException: You need MANAGE_USERS permission to:
// check if specified user a managed profile outside your profile group"
mIcon = mPm.getUserBadgedIcon(mIcon, handle);
} catch (SecurityException e) {
Log.w(TAG, "getUserBadgedIcon failed, using icons without badges: " + e.getMessage());
badgedIconFails = true;
}
}
} else
mIcon = mPackageInfo.applicationInfo.loadIcon(mPm);

Expand Down

0 comments on commit 308de20

Please sign in to comment.