From c5919749ea7a54191a343f9c465bc714c661f916 Mon Sep 17 00:00:00 2001 From: Jon Spivack Date: Wed, 28 Apr 2021 11:43:34 -0700 Subject: [PATCH 1/9] Check screen context permissions for NIU Actions This checks for the ASSIST_STRUCTURE_ENABLED and ASSIST_SCREENSHOT_ENABLED permissions before sending NIU Actions Intents. If either permission is absent, the screenshot is not sent, and an error code is added to the Intent. Bug: 182010359 Test: Manual (toggled permissions and clicked NIU Actions buttons on Wembley device) Test: m -j RunLauncherGoGoogleRoboTests Change-Id: Icf0db739f5010862cc2bac496f5410665625f3be --- .../quickstep/TaskOverlayFactoryGo.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java index 350e0d1d97..79e50ef35b 100644 --- a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java +++ b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java @@ -21,14 +21,18 @@ import static com.android.quickstep.views.OverviewActionsView.DISABLED_ROTATED; import android.annotation.SuppressLint; import android.app.assist.AssistContent; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.graphics.Matrix; +import android.net.Uri; import android.os.SystemClock; +import android.provider.Settings; import android.text.TextUtils; import androidx.annotation.VisibleForTesting; +import com.android.launcher3.BuildConfig; import com.android.launcher3.R; import com.android.quickstep.util.AssistContentRequester; import com.android.quickstep.views.OverviewActionsView; @@ -45,7 +49,12 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { public static final String ACTION_SEARCH = "com.android.quickstep.ACTION_SEARCH"; public static final String ELAPSED_NANOS = "niu_actions_elapsed_realtime_nanos"; public static final String ACTIONS_URL = "niu_actions_app_url"; + public static final String ACTIONS_ERROR_CODE = "niu_actions_app_error_code"; + public static final int ERROR_PERMISSIONS = 1; private static final String TAG = "TaskOverlayFactoryGo"; + private static final String URI_AUTHORITY = + BuildConfig.APPLICATION_ID + ".overview.fileprovider"; + private static final String FAKE_FILEPATH = "shared_images/null.png"; // Empty constructor required for ResourceBasedOverride public TaskOverlayFactoryGo(Context context) {} @@ -64,6 +73,7 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { public static final class TaskOverlayGo extends TaskOverlay { private String mNIUPackageName; private String mWebUrl; + private boolean mAssistPermissionsEnabled; private TaskOverlayGo(TaskThumbnailView taskThumbnailView) { super(taskThumbnailView); @@ -87,6 +97,11 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { boolean isAllowedByPolicy = mThumbnailView.isRealSnapshot(); getActionsView().setCallbacks(new OverlayUICallbacksGoImpl(isAllowedByPolicy, task)); + checkPermissions(); + if (!mAssistPermissionsEnabled) { + return; + } + int taskId = task.key.id; AssistContentRequester contentRequester = new AssistContentRequester(mApplicationContext); @@ -112,7 +127,22 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { @VisibleForTesting public void sendNIUIntent(String actionType) { Intent intent = createNIUIntent(actionType); - mImageApi.shareAsDataWithExplicitIntent(/* crop */ null, intent); + // Only add and send the image if the appropriate permissions are held + if (mAssistPermissionsEnabled) { + mImageApi.shareAsDataWithExplicitIntent(/* crop */ null, intent); + } else { + intent.putExtra(ACTIONS_ERROR_CODE, ERROR_PERMISSIONS); + // The Intent recipient expects an image URI, and omitting one or using a + // completely invalid URI will cause the Intent parsing to crash. + // So we construct a URI for a nonexistent image. + Uri uri = new Uri.Builder() + .scheme(ContentResolver.SCHEME_CONTENT) + .authority(URI_AUTHORITY) + .path(FAKE_FILEPATH) + .build(); + intent.setData(uri); + mApplicationContext.startActivity(intent); + } } private Intent createNIUIntent(String actionType) { @@ -129,6 +159,19 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { return intent; } + /** + * Checks whether the Assistant has screen context permissions + */ + @VisibleForTesting + public void checkPermissions() { + ContentResolver contentResolver = mApplicationContext.getContentResolver(); + boolean structureEnabled = Settings.Secure.getInt(contentResolver, + Settings.Secure.ASSIST_STRUCTURE_ENABLED, 0) != 0; + boolean screenshotEnabled = Settings.Secure.getInt(contentResolver, + Settings.Secure.ASSIST_SCREENSHOT_ENABLED, 0) != 0; + mAssistPermissionsEnabled = structureEnabled && screenshotEnabled; + } + protected class OverlayUICallbacksGoImpl extends OverlayUICallbacksImpl implements OverlayUICallbacksGo { public OverlayUICallbacksGoImpl(boolean isAllowedByPolicy, Task task) { From a3a6f51b12b30591301efce0211c51bb47a8deaa Mon Sep 17 00:00:00 2001 From: Yogisha Dixit Date: Wed, 28 Apr 2021 13:45:37 +0100 Subject: [PATCH 2/9] Update drop target styling based for BC. Spec: https://docs.google.com/presentation/d/1UxdDh8EFhPbdRWRwzjbpgL-j02ew4Ew3eG3XBCeoYdo/edit#slide=id.vXfwHn8 Demo: https://drive.google.com/file/d/1ZIa3Dgo85vdVkfPm7aGJDyctZQR_c8Xx/view?usp=sharing Test: manual Bug: 184713740 Change-Id: I17dbbf1f7bbc40939cfc0fedb506a35f39ecc2e3 --- res/drawable/drop_target_frame.xml | 22 +++++++++++++++++++ res/drawable/drop_target_frame_hover.xml | 21 ++++++++++++++++++ res/drawable/ic_block_no_shadow.xml | 8 +++---- res/drawable/ic_remove_no_shadow.xml | 4 ++-- res/drawable/ic_uninstall_no_shadow.xml | 8 +++---- res/values/dimens.xml | 2 +- res/values/styles.xml | 7 ++---- .../android/launcher3/ButtonDropTarget.java | 9 ++++++++ .../android/launcher3/DeleteDropTarget.java | 2 +- .../launcher3/SecondaryDropTarget.java | 6 ++--- 10 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 res/drawable/drop_target_frame.xml create mode 100644 res/drawable/drop_target_frame_hover.xml diff --git a/res/drawable/drop_target_frame.xml b/res/drawable/drop_target_frame.xml new file mode 100644 index 0000000000..fa6dafd4fc --- /dev/null +++ b/res/drawable/drop_target_frame.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/res/drawable/drop_target_frame_hover.xml b/res/drawable/drop_target_frame_hover.xml new file mode 100644 index 0000000000..7d0e919331 --- /dev/null +++ b/res/drawable/drop_target_frame_hover.xml @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/res/drawable/ic_block_no_shadow.xml b/res/drawable/ic_block_no_shadow.xml index edeb4c63ec..be9aa07b38 100644 --- a/res/drawable/ic_block_no_shadow.xml +++ b/res/drawable/ic_block_no_shadow.xml @@ -14,10 +14,10 @@ limitations under the License. --> diff --git a/res/drawable/ic_uninstall_no_shadow.xml b/res/drawable/ic_uninstall_no_shadow.xml index 6aff102a2d..14cecacbea 100644 --- a/res/drawable/ic_uninstall_no_shadow.xml +++ b/res/drawable/ic_uninstall_no_shadow.xml @@ -14,10 +14,10 @@ limitations under the License. --> 14dp - 14sp + 20sp 2dp diff --git a/res/values/styles.xml b/res/values/styles.xml index 5ae4e3ffe0..97a576011a 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -258,14 +258,11 @@ 7.5dp 16dp 16dp - ?attr/workspaceTextColor + ?android:attr/textColorPrimary @dimen/drop_target_text_size true end - ?attr/workspaceShadowColor - 0.0 - 1.0 - 4.0 + @drawable/drop_target_frame