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

Commit 2269f080 authored by Oli Lan's avatar Oli Lan Committed by Android (Google) Code Review
Browse files

Merge "Change clipboard access notification wording." into sc-dev

parents 44aae217 2d70047b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2815,6 +2815,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
@@ -555,6 +555,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
@@ -1054,27 +1054,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(
@@ -1085,4 +1074,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;
    }

}