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

Commit 2d70047b authored by Oli Lan's avatar Oli Lan
Browse files

Change clipboard access notification wording.

This changes the wording of the clipboard access toast
notifications to: "<App> pasted text you copied" or
"<App> pasted content you copied".

A string is also included for the case "<App> pasted an
image you copied" - a future change may add support for that
case if needed.

Bug: 179469804
Test: manual, copy text and non-text and check notification is
correct.

Change-Id: I426c38c53316362bd8e79ec2b2ff40fa420ac071
parent 5f573843
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2802,6 +2802,15 @@
    <!-- Displayed to the user to inform them that an app has accessed clipboard data (pasted as in "copy and paste") [CHAR LIMIT=50] -->
    <string name="pasted_from_clipboard"><xliff:g id="pasting_app_name" example="Gmail">%1$s</xliff:g> pasted from clipboard</string>

    <!-- Displayed to the user to inform them that an app has accessed text from clipboard (pasted as in "copy and paste") [CHAR LIMIT=50] -->
    <string name="pasted_text"><xliff:g id="pasting_app_name" example="Gmail">%1$s</xliff:g> pasted text you copied</string>

    <!-- Displayed to the user to inform them that an app has accessed an image from clipboard (pasted as in "copy and paste") [CHAR LIMIT=50] -->
    <string name="pasted_image"><xliff:g id="pasting_app_name" example="Gmail">%1$s</xliff:g> pasted an image you copied</string>

    <!-- Displayed to the user to inform them that an app has accessed content from clipboard (pasted as in "copy and paste") [CHAR LIMIT=50] -->
    <string name="pasted_content"><xliff:g id="pasting_app_name" example="Gmail">%1$s</xliff:g> pasted content you copied</string>

    <!-- Menu item displayed at the end of a menu to allow users to see another page worth of menu items. This is shown on any app's menu as long as the app has too many items in the menu.-->
    <string name="more_item_label">More</string>
    <!-- Prepended to the shortcut for a menu item to indicate that the user should hold the MENU button together with the shortcut to invoke the item. For example, if the shortcut to open a new tab in browser is MENU and B together, then this would be prepended to the letter "B" -->
+3 −0
Original line number Diff line number Diff line
@@ -560,6 +560,9 @@
  <java-symbol type="string" name="paste_as_plain_text" />
  <java-symbol type="string" name="pasted_from_app" />
  <java-symbol type="string" name="pasted_from_clipboard" />
  <java-symbol type="string" name="pasted_text" />
  <java-symbol type="string" name="pasted_image" />
  <java-symbol type="string" name="pasted_content" />
  <java-symbol type="string" name="replace" />
  <java-symbol type="string" name="undo" />
  <java-symbol type="string" name="redo" />
+20 −14
Original line number Diff line number Diff line
@@ -1044,27 +1044,16 @@ 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) {
                try {
                    sourceAppLabel = mPm.getApplicationLabel(mPm.getApplicationInfoAsUser(
                            clipboard.mPrimaryClipPackage, 0, userId));
                } catch (PackageManager.NameNotFoundException e) {
                    // leave label as null
                }
            }

            try {
                CharSequence callingAppLabel = mPm.getApplicationLabel(
                        mPm.getApplicationInfoAsUser(callingPackage, 0, userId));
                String message;
                if (sourceAppLabel != null) {
                if (isText(clipboard.primaryClip)) {
                    message = getContext().getString(
                            R.string.pasted_from_app, callingAppLabel, sourceAppLabel);
                            R.string.pasted_text, callingAppLabel);
                } else {
                    message = getContext().getString(
                            R.string.pasted_from_clipboard, callingAppLabel);
                            R.string.pasted_content, callingAppLabel);
                }
                Slog.i(TAG, message);
                Toast.makeText(
@@ -1075,4 +1064,21 @@ public class ClipboardService extends SystemService {
            }
        });
    }

    /**
     * Returns true if the provided {@link ClipData} represents a single piece of text. That is, if
     * there is only on {@link ClipData.Item}, and that item contains a non-empty piece of text and
     * no URI or Intent. Note that HTML may be provided along with text so the presence of
     * HtmlText in the clip does not prevent this method returning true.
     */
    private static boolean isText(@NonNull ClipData data) {
        if (data.getItemCount() > 1) {
            return false;
        }
        ClipData.Item item = data.getItemAt(0);

        return !TextUtils.isEmpty(item.getText()) && item.getUri() == null
                && item.getIntent() == null;
    }

}