Merge "Enforce MANAGE_APP_PREDICTIONS on hasShareTargets"
This commit is contained in:
committed by
Android (Google) Code Review
commit
a984bb74b1
@@ -1717,6 +1717,7 @@ package android.content.pm {
|
||||
|
||||
public class ShortcutManager {
|
||||
method @NonNull public java.util.List<android.content.pm.ShortcutManager.ShareShortcutInfo> getShareTargets(@NonNull android.content.IntentFilter);
|
||||
method public boolean hasShareTargets(@NonNull String);
|
||||
}
|
||||
|
||||
public static final class ShortcutManager.ShareShortcutInfo implements android.os.Parcelable {
|
||||
|
||||
@@ -644,6 +644,7 @@ public class ShortcutManager {
|
||||
* @return True if the package has any share target definitions, False otherwise.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public boolean hasShareTargets(@NonNull String packageName) {
|
||||
try {
|
||||
return mService.hasShareTargets(mContext.getPackageName(), packageName,
|
||||
|
||||
@@ -2173,7 +2173,8 @@ public class ShortcutService extends IShortcutService.Stub {
|
||||
public boolean hasShareTargets(String packageName, String packageToCheck,
|
||||
@UserIdInt int userId) {
|
||||
verifyCaller(packageName, userId);
|
||||
enforceSystem();
|
||||
enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APP_PREDICTIONS,
|
||||
"hasShareTargets");
|
||||
|
||||
synchronized (mLock) {
|
||||
throwIfUserLockedL(userId);
|
||||
|
||||
@@ -6286,6 +6286,15 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
|
||||
mManager.getShareTargets(filter);
|
||||
}
|
||||
|
||||
public void testHasShareTargets_permission() {
|
||||
assertExpectException(SecurityException.class, "Missing permission", () ->
|
||||
mManager.hasShareTargets(CALLING_PACKAGE_1));
|
||||
|
||||
// Has permission, now it should pass.
|
||||
mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS);
|
||||
mManager.hasShareTargets(CALLING_PACKAGE_1);
|
||||
}
|
||||
|
||||
public void testDumpsys_crossProfile() {
|
||||
prepareCrossProfileDataSet();
|
||||
dumpsysOnLogcat("test1", /* force= */ true);
|
||||
|
||||
Reference in New Issue
Block a user