From ea5a59c354a834a413b58252cd5ccb869f498fed Mon Sep 17 00:00:00 2001 From: Himanshu Gupta Date: Fri, 12 May 2023 21:08:29 +0100 Subject: [PATCH] Fixing read from mUsersRedirectedToOwnerForMedia sparse array. ag/21547694 introduced some fixes in ContentProvider for clone profile. However, a new bug was also introduced due to incorrect index calculation. This CL fixes the same. Bug: 270350104 Test: atest AppCloningHostTest Change-Id: Iea3cc4b40194d809a62457899d7c4e96021692d7 --- core/java/android/content/ContentProvider.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java index 379a0111b58c0..2200af679531b 100644 --- a/core/java/android/content/ContentProvider.java +++ b/core/java/android/content/ContentProvider.java @@ -892,8 +892,9 @@ public abstract class ContentProvider implements ContentInterface, ComponentCall */ private boolean isContentRedirectionAllowedForUser(int incomingUserId) { if (MediaStore.AUTHORITY.equals(mAuthority)) { - if (mUsersRedirectedToOwnerForMedia.indexOfKey(incomingUserId) >= 0) { - return mUsersRedirectedToOwnerForMedia.valueAt(incomingUserId); + int incomingUserIdIndex = mUsersRedirectedToOwnerForMedia.indexOfKey(incomingUserId); + if (incomingUserIdIndex >= 0) { + return mUsersRedirectedToOwnerForMedia.valueAt(incomingUserIdIndex); } // Haven't seen this user yet, look it up