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

Commit 7c20053c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix security exception when reading usb serial num"

parents 47d76622 d530d102
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -75,14 +75,21 @@ class UsbSerialReader extends IUsbSerialReader.Stub {
        if (uid != Process.SYSTEM_UID) {
            enforcePackageBelongsToUid(uid, packageName);

            int packageTargetSdkVersion;
            long token = Binder.clearCallingIdentity();
            try {
                PackageInfo pkg;
                try {
                    pkg = mContext.getPackageManager().getPackageInfo(packageName, 0);
                } catch (PackageManager.NameNotFoundException e) {
                    throw new RemoteException("package " + packageName + " cannot be found");
                }
                packageTargetSdkVersion = pkg.applicationInfo.targetSdkVersion;
            } finally {
                Binder.restoreCallingIdentity(token);
            }

            if (pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q) {
            if (packageTargetSdkVersion >= Build.VERSION_CODES.Q) {
                if (mContext.checkPermission(android.Manifest.permission.MANAGE_USB, pid, uid)
                        == PackageManager.PERMISSION_DENIED) {
                    UsbUserSettingsManager settings = mSettingsManager.getSettingsForUser(