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

Commit 2567782f authored by Chris Li's avatar Chris Li
Browse files

Only allow passing in calling pid/uid for SafeActivityOptions

Previously, the logic of querying pid/uid is hidden in the class, which
is not obvious without reading the JavaDoc.

Bug: 374638784
Test: running presubmit for refactor
Flag: EXEMPT refactor
Change-Id: I27984245c8640f50b68ffdba5f848687b36c71b5
parent a93bab0d
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -157,7 +157,8 @@ public class PendingIntentController {


            PendingIntentRecord.Key key = new PendingIntentRecord.Key(type, packageName, featureId,
            PendingIntentRecord.Key key = new PendingIntentRecord.Key(type, packageName, featureId,
                    token, resultWho, requestCode, intents, resolvedTypes, flags,
                    token, resultWho, requestCode, intents, resolvedTypes, flags,
                    new SafeActivityOptions(opts), userId);
                    new SafeActivityOptions(opts, Binder.getCallingPid(), Binder.getCallingUid()),
                    userId);
            WeakReference<PendingIntentRecord> ref;
            WeakReference<PendingIntentRecord> ref;
            ref = mIntentSenderRecords.get(key);
            ref = mIntentSenderRecords.get(key);
            PendingIntentRecord rec = ref != null ? ref.get() : null;
            PendingIntentRecord rec = ref != null ? ref.get() : null;
+2 −2
Original line number Original line Diff line number Diff line
@@ -533,9 +533,9 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
            // Extract options before clearing calling identity
            // Extract options before clearing calling identity
            mergedOptions = key.options;
            mergedOptions = key.options;
            if (mergedOptions == null) {
            if (mergedOptions == null) {
                mergedOptions = new SafeActivityOptions(opts);
                mergedOptions = new SafeActivityOptions(opts, callingPid, callingUid);
            } else {
            } else {
                mergedOptions.setCallerOptions(opts);
                mergedOptions.setCallerOptions(opts, callingPid, callingUid);
            }
            }


            if (mAllowlistDuration != null) {
            if (mAllowlistDuration != null) {
+4 −1
Original line number Original line Diff line number Diff line
@@ -886,7 +886,10 @@ class ActivityClientController extends IActivityClientController.Stub {


    @Override
    @Override
    public boolean convertToTranslucent(IBinder token, Bundle options) {
    public boolean convertToTranslucent(IBinder token, Bundle options) {
        final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(options);
        final int callingPid = Binder.getCallingPid();
        final int callingUid = Binder.getCallingUid();
        final SafeActivityOptions safeOptions = SafeActivityOptions.fromBundle(
                options, callingPid, callingUid);
        final long origId = Binder.clearCallingIdentity();
        final long origId = Binder.clearCallingIdentity();
        try {
        try {
            synchronized (mGlobalLock) {
            synchronized (mGlobalLock) {
+2 −1
Original line number Original line Diff line number Diff line
@@ -190,7 +190,8 @@ public class ActivityStartController {
                .setOutActivity(tmpOutRecord)
                .setOutActivity(tmpOutRecord)
                .setCallingUid(0)
                .setCallingUid(0)
                .setActivityInfo(aInfo)
                .setActivityInfo(aInfo)
                .setActivityOptions(options.toBundle())
                .setActivityOptions(options.toBundle(),
                        Binder.getCallingPid(), Binder.getCallingUid())
                .execute();
                .execute();
        mLastHomeActivityStartRecord = tmpOutRecord[0];
        mLastHomeActivityStartRecord = tmpOutRecord[0];
        if (rootHomeTask.mInResumeTopActivity) {
        if (rootHomeTask.mInResumeTopActivity) {
+2 −2
Original line number Original line Diff line number Diff line
@@ -3468,8 +3468,8 @@ class ActivityStarter {
        return this;
        return this;
    }
    }


    ActivityStarter setActivityOptions(Bundle bOptions) {
    ActivityStarter setActivityOptions(Bundle bOptions, int callingPid, int callingUid) {
        return setActivityOptions(SafeActivityOptions.fromBundle(bOptions));
        return setActivityOptions(SafeActivityOptions.fromBundle(bOptions, callingPid, callingUid));
    }
    }


    ActivityStarter setIgnoreTargetSecurity(boolean ignoreTargetSecurity) {
    ActivityStarter setIgnoreTargetSecurity(boolean ignoreTargetSecurity) {
Loading