Merge "Remove PackageManager.getResourcesForApplicationAsUser API"

This commit is contained in:
Felka Chang
2020-10-22 13:01:35 +00:00
committed by Android (Google) Code Review
3 changed files with 15 additions and 8 deletions

View File

@@ -630,7 +630,7 @@ public final class ShortcutInfo implements Parcelable {
* This will set {@link #FLAG_STRINGS_RESOLVED}.
*
* @param res {@link Resources} for the publisher. Must have been loaded with
* {@link PackageManager#getResourcesForApplicationAsUser}.
* {@link PackageManager#getResourcesForApplication(String)}.
*
* @hide
*/
@@ -752,7 +752,7 @@ public final class ShortcutInfo implements Parcelable {
* aforementioned method would do internally, but not documented, so doing here explicitly.)
*
* @param res {@link Resources} for the publisher. Must have been loaded with
* {@link PackageManager#getResourcesForApplicationAsUser}.
* {@link PackageManager#getResourcesForApplication(String)}.
*
* @hide
*/
@@ -782,7 +782,7 @@ public final class ShortcutInfo implements Parcelable {
* in the resource name fields.
*
* @param res {@link Resources} for the publisher. Must have been loaded with
* {@link PackageManager#getResourcesForApplicationAsUser}.
* {@link PackageManager#getResourcesForApplication(String)}.
*
* @hide
*/

View File

@@ -3907,10 +3907,11 @@ public class ShortcutService extends IShortcutService.Stub {
final long start = getStatStartTime();
final long token = injectClearCallingIdentity();
try {
return mContext.getPackageManager().getResourcesForApplicationAsUser(
packageName, userId);
return mContext.createContextAsUser(UserHandle.of(userId), /* flags */ 0)
.getPackageManager().getResourcesForApplication(packageName);
} catch (NameNotFoundException e) {
Slog.e(TAG, "Resources for package " + packageName + " not found");
Slog.e(TAG, "Resources of package " + packageName + " for user " + userId
+ " not found");
return null;
} finally {
injectRestoreCallingIdentity(token);

View File

@@ -176,6 +176,12 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
return null;
}
@Override
public Context createContextAsUser(UserHandle user, int flags) {
when(mMockPackageManager.getUserId()).thenReturn(user.getIdentifier());
return this;
}
@Override
public void unregisterReceiver(BroadcastReceiver receiver) {
// ignore.
@@ -939,7 +945,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
assertEquals(Process.SYSTEM_UID, mInjectedCallingUid);
final String packageName = (String) pmInvocation.getArguments()[0];
final int userId = (Integer) pmInvocation.getArguments()[1];
final int userId = mMockPackageManager.getUserId();
final Resources res = mock(Resources.class);
@@ -971,7 +977,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
return Integer.parseInt(entryName.substring(1)) + ressIdOffset;
}).when(res).getIdentifier(anyStringOrNull(), anyStringOrNull(), anyStringOrNull());
return res;
}).when(mMockPackageManager).getResourcesForApplicationAsUser(anyString(), anyInt());
}).when(mMockPackageManager).getResourcesForApplication(anyString());
}
protected static UserInfo withProfileGroupId(UserInfo in, int groupId) {