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

Commit 560aa579 authored by Hai Zhang's avatar Hai Zhang
Browse files

Pass EXTRA_CALLING_PACKAGE for legacy change default dialer/SMS intents.

So that RequestRoleActivity can always know the calling package. This
is required to keep supporting pre-Q apps calling with
startActivity().

Also fixed application info retrieval to be aware of multi-user.

Bug: 137054465
Test: manual
Change-Id: I686a97b543a0218837ee08291ef6fd9579a551d1
parent 0d2a5f94
Loading
Loading
Loading
Loading
+13 −8
Original line number Original line Diff line number Diff line
@@ -798,7 +798,7 @@ public final class PermissionPolicyService extends SystemService {
        @Override
        @Override
        public boolean checkStartActivity(@NonNull Intent intent, int callingUid,
        public boolean checkStartActivity(@NonNull Intent intent, int callingUid,
                @Nullable String callingPackage) {
                @Nullable String callingPackage) {
            if (callingPackage != null && isActionRemovedForCallingPackage(intent.getAction(),
            if (callingPackage != null && isActionRemovedForCallingPackage(intent, callingUid,
                    callingPackage)) {
                    callingPackage)) {
                Slog.w(LOG_TAG, "Action Removed: starting " + intent.toString() + " from "
                Slog.w(LOG_TAG, "Action Removed: starting " + intent.toString() + " from "
                        + callingPackage + " (uid=" + callingUid + ")");
                        + callingPackage + " (uid=" + callingUid + ")");
@@ -811,8 +811,9 @@ public final class PermissionPolicyService extends SystemService {
         * Check if the intent action is removed for the calling package (often based on target SDK
         * Check if the intent action is removed for the calling package (often based on target SDK
         * version). If the action is removed, we'll silently cancel the activity launch.
         * version). If the action is removed, we'll silently cancel the activity launch.
         */
         */
        private boolean isActionRemovedForCallingPackage(@Nullable String action,
        private boolean isActionRemovedForCallingPackage(@NonNull Intent intent, int callingUid,
                @NonNull String callingPackage) {
                @NonNull String callingPackage) {
            String action = intent.getAction();
            if (action == null) {
            if (action == null) {
                return false;
                return false;
            }
            }
@@ -821,15 +822,19 @@ public final class PermissionPolicyService extends SystemService {
                case Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT: {
                case Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT: {
                    ApplicationInfo applicationInfo;
                    ApplicationInfo applicationInfo;
                    try {
                    try {
                        applicationInfo = getContext().getPackageManager().getApplicationInfo(
                        applicationInfo = getContext().getPackageManager().getApplicationInfoAsUser(
                                callingPackage, 0);
                                callingPackage, 0, UserHandle.getUserId(callingUid));
                        if (applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q) {
                            // Applications targeting Q or higher should use
                            // RoleManager.createRequestRoleIntent() instead.
                            return true;
                        }
                    } catch (PackageManager.NameNotFoundException e) {
                    } catch (PackageManager.NameNotFoundException e) {
                        Slog.i(LOG_TAG, "Cannot find application info for " + callingPackage);
                        Slog.i(LOG_TAG, "Cannot find application info for " + callingPackage);
                        return false;
                    }
                    }
                    // Applications targeting Q should use RoleManager.createRequestRoleIntent()
                    // Make sure RequestRoleActivity can know the calling package if we allow it.
                    // instead.
                    intent.putExtra(Intent.EXTRA_CALLING_PACKAGE, callingPackage);
                    return applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q;
                    return false;
                }
                }
                default:
                default:
                    return false;
                    return false;