Don't show clipboard actions for the source app
If the user copies a link from (say) chrome, we don't want to show an action to open the link back in chrome. This change suppresses actions where the target package is the same as the source package. Bug: 216658864 Test: manual Change-Id: I4f2ee7ac30b2e54c702e3c9149f77eb5dd5d6243
This commit is contained in:
@@ -301,6 +301,7 @@
|
||||
|
||||
<!-- For clipboard overlay -->
|
||||
<uses-permission android:name="android.permission.READ_CLIPBOARD_IN_BACKGROUND" />
|
||||
<uses-permission android:name="android.permission.SET_CLIP_SOURCE" />
|
||||
|
||||
<protected-broadcast android:name="com.android.settingslib.action.REGISTER_SLICE_RECEIVER" />
|
||||
<protected-broadcast android:name="com.android.settingslib.action.UNREGISTER_SLICE_RECEIVER" />
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<com.android.systemui.clipboardoverlay.DraggableConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:theme="@style/Screenshot"
|
||||
android:alpha="0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@@ -50,7 +51,8 @@
|
||||
<LinearLayout
|
||||
android:id="@+id/actions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true">
|
||||
<include layout="@layout/screenshot_action_chip"
|
||||
android:id="@+id/remote_copy_chip"/>
|
||||
<include layout="@layout/screenshot_action_chip"
|
||||
@@ -64,7 +66,7 @@
|
||||
android:layout_marginStart="@dimen/overlay_offset_x"
|
||||
android:layout_marginBottom="@dimen/overlay_offset_y"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="@id/actions_container_background"
|
||||
android:elevation="@dimen/overlay_preview_elevation"
|
||||
app:layout_constraintEnd_toEndOf="@id/clipboard_preview_end"
|
||||
app:layout_constraintTop_toTopOf="@id/clipboard_preview_top"
|
||||
|
||||
@@ -63,7 +63,8 @@ public class ClipboardListener extends CoreStartable
|
||||
mClipboardOverlayController =
|
||||
new ClipboardOverlayController(mContext, new TimeoutHandler(mContext));
|
||||
}
|
||||
mClipboardOverlayController.setClipData(mClipboardManager.getPrimaryClip());
|
||||
mClipboardOverlayController.setClipData(
|
||||
mClipboardManager.getPrimaryClip(), mClipboardManager.getPrimaryClipSource());
|
||||
mClipboardOverlayController.setOnSessionCompleteListener(() -> {
|
||||
// Session is complete, free memory until it's needed again.
|
||||
mClipboardOverlayController = null;
|
||||
|
||||
@@ -182,6 +182,7 @@ public class ClipboardOverlayController {
|
||||
withWindowAttached(() -> {
|
||||
mWindow.setContentView(mView);
|
||||
updateInsets(mWindowManager.getCurrentWindowMetrics().getWindowInsets());
|
||||
mView.requestLayout();
|
||||
mView.post(this::animateIn);
|
||||
});
|
||||
|
||||
@@ -213,7 +214,7 @@ public class ClipboardOverlayController {
|
||||
mContext.sendBroadcast(new Intent(COPY_OVERLAY_ACTION), SELF_PERMISSION);
|
||||
}
|
||||
|
||||
void setClipData(ClipData clipData) {
|
||||
void setClipData(ClipData clipData, String clipSource) {
|
||||
reset();
|
||||
if (clipData == null || clipData.getItemCount() == 0) {
|
||||
showTextPreview(mContext.getResources().getString(
|
||||
@@ -221,7 +222,7 @@ public class ClipboardOverlayController {
|
||||
} else if (!TextUtils.isEmpty(clipData.getItemAt(0).getText())) {
|
||||
ClipData.Item item = clipData.getItemAt(0);
|
||||
if (item.getTextLinks() != null) {
|
||||
AsyncTask.execute(() -> classifyText(clipData.getItemAt(0)));
|
||||
AsyncTask.execute(() -> classifyText(clipData.getItemAt(0), clipSource));
|
||||
}
|
||||
showEditableText(item.getText());
|
||||
} else if (clipData.getItemAt(0).getUri() != null) {
|
||||
@@ -238,7 +239,7 @@ public class ClipboardOverlayController {
|
||||
mOnSessionCompleteListener = runnable;
|
||||
}
|
||||
|
||||
private void classifyText(ClipData.Item item) {
|
||||
private void classifyText(ClipData.Item item, String source) {
|
||||
ArrayList<RemoteAction> actions = new ArrayList<>();
|
||||
for (TextLinks.TextLink link : item.getTextLinks().getLinks()) {
|
||||
TextClassification classification = mTextClassifier.classifyText(
|
||||
@@ -246,14 +247,14 @@ public class ClipboardOverlayController {
|
||||
actions.addAll(classification.getActions());
|
||||
}
|
||||
mView.post(() -> {
|
||||
for (ScreenshotActionChip chip : mActionChips) {
|
||||
mActionContainer.removeView(chip);
|
||||
}
|
||||
mActionChips.clear();
|
||||
resetActionChips();
|
||||
for (RemoteAction action : actions) {
|
||||
ScreenshotActionChip chip = constructActionChip(action);
|
||||
mActionContainer.addView(chip);
|
||||
mActionChips.add(chip);
|
||||
Intent targetIntent = action.getActionIntent().getIntent();
|
||||
if (!TextUtils.equals(source, targetIntent.getComponent().getPackageName())) {
|
||||
ScreenshotActionChip chip = constructActionChip(action);
|
||||
mActionContainer.addView(chip);
|
||||
mActionChips.add(chip);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -451,13 +452,17 @@ public class ClipboardOverlayController {
|
||||
}
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
mView.setTranslationX(0);
|
||||
mView.setAlpha(0);
|
||||
private void resetActionChips() {
|
||||
for (ScreenshotActionChip chip : mActionChips) {
|
||||
mActionContainer.removeView(chip);
|
||||
}
|
||||
mActionChips.clear();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
mView.setTranslationX(0);
|
||||
mView.setAlpha(0);
|
||||
resetActionChips();
|
||||
mTimeoutHandler.cancelTimeout();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user