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

Commit 1b8f3b07 authored by Pranav Madapurmath's avatar Pranav Madapurmath Committed by Android (Google) Code Review
Browse files

Merge "Resolve cross account user icon validation." into main

parents 2a750a32 9a260d5e
Loading
Loading
Loading
Loading
+28 −6
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.UserHandle;
import android.os.UserHandle;
import android.util.Log;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;


@@ -40,6 +41,7 @@ public final class StatusHints implements Parcelable {
    private final CharSequence mLabel;
    private final CharSequence mLabel;
    private Icon mIcon;
    private Icon mIcon;
    private final Bundle mExtras;
    private final Bundle mExtras;
    private static final String TAG = StatusHints.class.getSimpleName();


    /**
    /**
     * @hide
     * @hide
@@ -150,17 +152,37 @@ public final class StatusHints implements Parcelable {
        // incompatible types.
        // incompatible types.
        if (icon != null && (icon.getType() == Icon.TYPE_URI
        if (icon != null && (icon.getType() == Icon.TYPE_URI
                || icon.getType() == Icon.TYPE_URI_ADAPTIVE_BITMAP)) {
                || icon.getType() == Icon.TYPE_URI_ADAPTIVE_BITMAP)) {
            String encodedUser = icon.getUri().getEncodedUserInfo();
            int callingUserId = callingUserHandle.getIdentifier();
            // If there is no encoded user, the URI is calling into the calling user space
            int requestingUserId = getUserIdFromAuthority(
            if (encodedUser != null) {
                    icon.getUri().getAuthority(), callingUserId);
                int userId = Integer.parseInt(encodedUser);
            if (callingUserId != requestingUserId) {
                // Do not try to save the icon if the user id isn't in the calling user space.
                return null;
                if (userId != callingUserHandle.getIdentifier()) return null;
            }
            }

        }
        }
        return icon;
        return icon;
    }
    }


    /**
     * Derives the user id from the authority or the default user id if none could be found.
     * @param auth
     * @param defaultUserId
     * @return The user id from the given authority.
     * @hide
     */
    public static int getUserIdFromAuthority(String auth, int defaultUserId) {
        if (auth == null) return defaultUserId;
        int end = auth.lastIndexOf('@');
        if (end == -1) return defaultUserId;
        String userIdString = auth.substring(0, end);
        try {
            return Integer.parseInt(userIdString);
        } catch (NumberFormatException e) {
            Log.w(TAG, "Error parsing userId." + e);
            return UserHandle.USER_NULL;
        }
    }

    @Override
    @Override
    public void writeToParcel(Parcel out, int flags) {
    public void writeToParcel(Parcel out, int flags) {
        out.writeCharSequence(mLabel);
        out.writeCharSequence(mLabel);