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

Commit af211686 authored by Matt Casey's avatar Matt Casey
Browse files

Work profile first run updates

- Show until the user dismisses it.
- Fetch the app icon based upon config ComponentName.
- Fetch the app name based upon config.
- Extract relevant logic to WorkProfileMessageController
- Some no-op cleanups in SaveIMageInBackgroundTask to prevent sysui
  studio from complaining.

Flag: The calls into the new message controller are protected by
      SCREENSHOT_WORK_PROFILE_POLICY (in teamfood).
Bug: 254245929
Test: atest WorkProfileMessageControllerTest
Test: Manually testing dismissal and UI.
Change-Id: I943303992fdc2caeba76a06f88c1b91419d02be8
parent de157676
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -437,6 +437,11 @@
         This name is in the ComponentName flattened format (package/class)  -->
    <string name="config_screenshotEditor" translatable="false"></string>

    <!-- ComponentName for the file browsing app that the system would expect to be used in work
         profile. The icon for this app will be shown to the user when informing them that a
         screenshot has been saved to work profile. If blank, a default icon will be shown. -->
    <string name="config_sceenshotWorkProfileFilesApp" translatable="false"></string>

    <!-- Remote copy default activity.  Must handle REMOTE_COPY_ACTION intents.
     This name is in the ComponentName flattened format (package/class)  -->
    <string name="config_remoteCopyPackage" translatable="false"></string>
+3 −1
Original line number Diff line number Diff line
@@ -240,7 +240,9 @@
    <!-- Content description for the right boundary of the screenshot being cropped, with the current position as a percentage. [CHAR LIMIT=NONE] -->
    <string name="screenshot_right_boundary_pct">Right boundary <xliff:g id="percent" example="50">%1$d</xliff:g> percent</string>
    <!-- Notification displayed when a screenshot is saved in a work profile. [CHAR LIMIT=NONE] -->
    <string name="screenshot_work_profile_notification" translatable="false">Work screenshots are saved in the work <xliff:g id="app" example="Files">%1$s</xliff:g> app</string>
    <string name="screenshot_work_profile_notification">Work screenshots are saved in the <xliff:g id="app" example="Work Files">%1$s</xliff:g> app</string>
    <!-- Default name referring to the app on the device that lets the user browse stored files. [CHAR LIMIT=NONE] -->
    <string name="screenshot_default_files_app_name">Files</string>

    <!-- Notification title displayed for screen recording [CHAR LIMIT=50]-->
    <string name="screenrecord_name">Screen Recorder</string>
+8 −6
Original line number Diff line number Diff line
@@ -20,8 +20,7 @@ import static com.android.systemui.screenshot.LogConfig.DEBUG_ACTIONS;
import static com.android.systemui.screenshot.LogConfig.DEBUG_CALLBACK;
import static com.android.systemui.screenshot.LogConfig.DEBUG_STORAGE;
import static com.android.systemui.screenshot.LogConfig.logTag;
import static com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider.ScreenshotSmartActionType.QUICK_SHARE_ACTION;
import static com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider.ScreenshotSmartActionType.REGULAR_SMART_ACTIONS;
import static com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider.ScreenshotSmartActionType;

import android.app.ActivityTaskManager;
import android.app.Notification;
@@ -155,7 +154,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {

            CompletableFuture<List<Notification.Action>> smartActionsFuture =
                    mScreenshotSmartActions.getSmartActionsFuture(
                            mScreenshotId, uri, image, mSmartActionsProvider, REGULAR_SMART_ACTIONS,
                            mScreenshotId, uri, image, mSmartActionsProvider,
                            ScreenshotSmartActionType.REGULAR_SMART_ACTIONS,
                            smartActionsEnabled, user);
            List<Notification.Action> smartActions = new ArrayList<>();
            if (smartActionsEnabled) {
@@ -166,7 +166,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                smartActions.addAll(buildSmartActions(
                        mScreenshotSmartActions.getSmartActions(
                                mScreenshotId, smartActionsFuture, timeoutMs,
                                mSmartActionsProvider, REGULAR_SMART_ACTIONS),
                                mSmartActionsProvider,
                                ScreenshotSmartActionType.REGULAR_SMART_ACTIONS),
                        mContext));
            }

@@ -476,7 +477,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        CompletableFuture<List<Notification.Action>> quickShareActionsFuture =
                mScreenshotSmartActions.getSmartActionsFuture(
                        mScreenshotId, null, image, mSmartActionsProvider,
                        QUICK_SHARE_ACTION,
                        ScreenshotSmartActionType.QUICK_SHARE_ACTION,
                        true /* smartActionsEnabled */, user);
        int timeoutMs = DeviceConfig.getInt(
                DeviceConfig.NAMESPACE_SYSTEMUI,
@@ -485,7 +486,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        List<Notification.Action> quickShareActions =
                mScreenshotSmartActions.getSmartActions(
                        mScreenshotId, quickShareActionsFuture, timeoutMs,
                        mSmartActionsProvider, QUICK_SHARE_ACTION);
                        mSmartActionsProvider,
                        ScreenshotSmartActionType.QUICK_SHARE_ACTION);
        if (!quickShareActions.isEmpty()) {
            mQuickShareData.quickShareAction = quickShareActions.get(0);
            mParams.mQuickShareActionsReadyListener.onActionsReady(mQuickShareData);
+9 −9
Original line number Diff line number Diff line
@@ -280,6 +280,7 @@ public class ScreenshotController {
    private final TimeoutHandler mScreenshotHandler;
    private final ActionIntentExecutor mActionExecutor;
    private final UserManager mUserManager;
    private final WorkProfileMessageController mWorkProfileMessageController;

    private final OnBackInvokedCallback mOnBackInvokedCallback = () -> {
        if (DEBUG_INPUT) {
@@ -326,7 +327,8 @@ public class ScreenshotController {
            BroadcastSender broadcastSender,
            ScreenshotNotificationSmartActionsProvider screenshotNotificationSmartActionsProvider,
            ActionIntentExecutor actionExecutor,
            UserManager userManager
            UserManager userManager,
            WorkProfileMessageController workProfileMessageController
    ) {
        mScreenshotSmartActions = screenshotSmartActions;
        mNotificationsController = screenshotNotificationsController;
@@ -358,6 +360,7 @@ public class ScreenshotController {
        mFlags = flags;
        mActionExecutor = actionExecutor;
        mUserManager = userManager;
        mWorkProfileMessageController = workProfileMessageController;

        mAccessibilityManager = AccessibilityManager.getInstance(mContext);

@@ -679,7 +682,6 @@ public class ScreenshotController {
                        return true;
                    }
                });

        if (mFlags.isEnabled(SCREENSHOT_WORK_PROFILE_POLICY)) {
            mScreenshotView.badgeScreenshot(
                    mContext.getPackageManager().getUserBadgeForDensity(owner, 0));
@@ -1033,10 +1035,8 @@ public class ScreenshotController {

    private void doPostAnimation(ScreenshotController.SavedImageData imageData) {
        mScreenshotView.setChipIntents(imageData);
        if (mFlags.isEnabled(SCREENSHOT_WORK_PROFILE_POLICY)
                && mUserManager.isManagedProfile(imageData.owner.getIdentifier())) {
            // TODO: Read app from configuration
            mScreenshotView.showWorkProfileMessage("Files");
        if (mFlags.isEnabled(SCREENSHOT_WORK_PROFILE_POLICY)) {
            mWorkProfileMessageController.onScreenshotTaken(imageData.owner, mScreenshotView);
        }
    }

+14 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.Notification;
import android.app.PendingIntent;
@@ -100,7 +101,8 @@ import java.util.ArrayList;
 * Handles the visual elements and animations for the screenshot flow.
 */
public class ScreenshotView extends FrameLayout implements
        ViewTreeObserver.OnComputeInternalInsetsListener {
        ViewTreeObserver.OnComputeInternalInsetsListener,
        WorkProfileMessageController.WorkProfileMessageDisplay {

    interface ScreenshotViewCallback {
        void onUserInteraction();
@@ -351,13 +353,23 @@ public class ScreenshotView extends FrameLayout implements
     * been taken and which app can be used to view it.
     *
     * @param appName The name of the app to use to view screenshots
     * @param appIcon Optional icon for the relevant files app
     * @param onDismiss Runnable to be run when the user dismisses this message
     */
    void showWorkProfileMessage(String appName) {
    @Override
    public void showWorkProfileMessage(CharSequence appName, @Nullable Drawable appIcon,
            Runnable onDismiss) {
        if (appIcon != null) {
            // Replace the default icon if one is provided.
            ImageView imageView = mMessageContainer.findViewById(R.id.screenshot_message_icon);
            imageView.setImageDrawable(appIcon);
        }
        mMessageContent.setText(
                mContext.getString(R.string.screenshot_work_profile_notification, appName));
        mMessageContainer.setVisibility(VISIBLE);
        mMessageContainer.findViewById(R.id.message_dismiss_button).setOnClickListener((v) -> {
            mMessageContainer.setVisibility(View.GONE);
            onDismiss.run();
        });
    }

Loading