Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4eface65 authored by Ivan Chiang's avatar Ivan Chiang
Browse files

[PackageManager] Add @NonNull on ResolveInfo#loadLabel

Add @NonNull for the method and also add @NonNull on the
parameter (pm). If pm is null, it throws NPE in the original
behavior. We add the new null check will not change the original
behavior. It should be safe and backward-compatible.

Test: atest ResolveInfoTest
Bug: 271814726
Change-Id: Ic4ed1873488facaed29e62a50274b0a95a8baec1
parent 218dd2f0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13003,7 +13003,7 @@ package android.content.pm {
    method public final int getIconResource();
    method public boolean isCrossProfileIntentForwarderActivity();
    method public android.graphics.drawable.Drawable loadIcon(android.content.pm.PackageManager);
    method public CharSequence loadLabel(android.content.pm.PackageManager);
    method @NonNull public CharSequence loadLabel(@NonNull android.content.pm.PackageManager);
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.content.pm.ResolveInfo> CREATOR;
    field public android.content.pm.ActivityInfo activityInfo;
+10 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.content.pm;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
@@ -33,6 +34,7 @@ import android.util.Slog;

import java.text.Collator;
import java.util.Comparator;
import java.util.Objects;

/**
 * Information that is returned from resolving an intent
@@ -224,10 +226,17 @@ public class ResolveInfo implements Parcelable {
     * @return Returns a CharSequence containing the resolutions's label.  If the
     * item does not have a label, its name is returned.
     */
    public CharSequence loadLabel(PackageManager pm) {
    @NonNull
    public CharSequence loadLabel(@NonNull PackageManager pm) {
        if (nonLocalizedLabel != null) {
            return nonLocalizedLabel;
        }

        // In order to not change the original behavior. To add null check here to support backward
        // compatible. If nonLocalizedLabel is not null, we also return nonLocalizedLabel even if pm
        // is null.
        Objects.requireNonNull(pm);

        CharSequence label;
        if (resolvePackageName != null && labelRes != 0) {
            label = pm.getText(resolvePackageName, labelRes, null);