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

Commit fddbb49c authored by Oli Lan's avatar Oli Lan
Browse files

Clear calling identity before retrieving app label for clipboard toast.

This fixes an issue where the source app in the clipboard access
toast was not displayed for apps targeting API 30+. This is because
the calling identity of the copying app was being used, resulting in
package visibility limitations being applied.

Bug: 182349975
Test: Manual, install app targeting API 30 and paste from another app.
Test: atest ClipboardManagerTest
Test: atest ManagedProfileCrossProfileTest#testCrossProfileCopyPaste
Change-Id: Icdd2d07a3e2855dba749dbbb3427fd3a8b217671
parent bc80405a
Loading
Loading
Loading
Loading
+28 −26
Original line number Diff line number Diff line
@@ -950,6 +950,7 @@ public class ClipboardService extends SystemService {
        }
        clipboard.mNotifiedUids.put(uid, true);

        Binder.withCleanCallingIdentity(() -> {
            // Retrieve the app label of the source of the clip data
            CharSequence sourceAppLabel = null;
            if (clipboard.mPrimaryClipPackage != null) {
@@ -969,15 +970,16 @@ public class ClipboardService extends SystemService {
                    message = getContext().getString(
                            R.string.pasted_from_app, callingAppLabel, sourceAppLabel);
                } else {
                message = getContext().getString(R.string.pasted_from_clipboard, callingAppLabel);
                    message = getContext().getString(
                            R.string.pasted_from_clipboard, callingAppLabel);
                }
                Slog.i(TAG, message);
            Binder.withCleanCallingIdentity(() ->
                    Toast.makeText(getContext(), UiThread.get().getLooper(), message,
                            Toast.LENGTH_SHORT)
                            .show());
                Toast.makeText(
                        getContext(), UiThread.get().getLooper(), message, Toast.LENGTH_SHORT)
                        .show();
            } catch (PackageManager.NameNotFoundException e) {
                // do nothing
            }
        });
    }
}