Properly handle pending intent for multi-user

Use getActivityAsUser instead of getActivity to
handle pending intent for multi-user

Test: atest CtsCompanionDeviceManagerCoreTestCases
      atest CtsCompanionDeviceManagerUiAutomationTestCases
      atest CtsOsTestCases:CompanionDeviceManagerTest
Fix: 218790259, 218790145, 218790302
Change-Id: Id3cd06dfe53ba3b36b1fc06d2d942bd6d1c19a4a
This commit is contained in:
Evan Chen
2022-02-24 19:29:46 +00:00
parent 83fbe6e5cb
commit ec712b7a99

View File

@@ -50,6 +50,7 @@ import android.os.Handler;
import android.os.Parcel;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.UserHandle;
import android.util.PackageUtils;
import android.util.Slog;
@@ -201,8 +202,10 @@ class AssociationRequestsProcessor {
// requests at the same time.
// If the application already has a pending association request, that PendingIntent
// will be cancelled.
pendingIntent = PendingIntent.getActivity(mContext, /*requestCode */ packageUid, intent,
FLAG_ONE_SHOT | FLAG_CANCEL_CURRENT | FLAG_IMMUTABLE);
pendingIntent = PendingIntent.getActivityAsUser(
mContext, /*requestCode */ packageUid, intent,
FLAG_ONE_SHOT | FLAG_CANCEL_CURRENT | FLAG_IMMUTABLE,
/* options= */ null, UserHandle.CURRENT);
} finally {
Binder.restoreCallingIdentity(token);
}