Check the permission of the callingUid instead of the calling package

Bug: 372671447
Test: atest
Flag: EXEMPT bug fix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e719575e92c1e6bd0b9088663e6c909bccf2b007)
Merged-In: Ib36c0a3ba482bcddd53c2c09409ea818e6f43cad
Change-Id: Ib36c0a3ba482bcddd53c2c09409ea818e6f43cad
This commit is contained in:
Fan Wu
2025-01-02 11:18:59 +08:00
committed by Cherrypicker Worker
parent e37a2247f1
commit 353cfc1b08

View File

@@ -20,6 +20,7 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import android.Manifest;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.Dialog;
import android.app.admin.DevicePolicyManager;
import android.app.settings.SettingsEnums;
@@ -33,6 +34,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.hardware.usb.IUsbManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
@@ -171,20 +173,19 @@ public abstract class AppInfoBase extends SettingsPreferenceFragment
if (!(activity instanceof SettingsActivity)) {
return false;
}
final String callingPackageName =
((SettingsActivity) activity).getInitialCallingPackage();
if (TextUtils.isEmpty(callingPackageName)) {
Log.w(TAG, "Not able to get calling package name for permission check");
try {
int callerUid = ActivityManager.getService().getLaunchedFromUid(
activity.getActivityToken());
if (ActivityManager.checkUidPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL,
callerUid) != PackageManager.PERMISSION_GRANTED) {
Log.w(TAG, "Uid " + callerUid + " does not have required permission "
+ Manifest.permission.INTERACT_ACROSS_USERS_FULL);
return false;
}
return true;
} catch (RemoteException e) {
return false;
}
if (mPm.checkPermission(Manifest.permission.INTERACT_ACROSS_USERS_FULL, callingPackageName)
!= PackageManager.PERMISSION_GRANTED) {
Log.w(TAG, "Package " + callingPackageName + " does not have required permission "
+ Manifest.permission.INTERACT_ACROSS_USERS_FULL);
return false;
}
return true;
}
protected void setIntentAndFinish(boolean appChanged) {