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

Commit 6b933cc5 authored by Matt Casey's avatar Matt Casey
Browse files

Allow work profile first run to include private space first run message

Reusing the work profile message template for now, iteration likely.

Forked the WorkProfileMessageController into ProfileMessageController,
generalized the logic a bit to support both Work and Private profiles.
Extracted the code that touched other parts of the system to make the
controller more testable. Aiming to keep the change to
MessageContainerController as minmimal as possible for now, with
basically all the changes behind the flag.

Bug: 324585817
Bug: 326941376
Test: atest ProfileMessageControllerTest MessageContainerControllerTest
Test: Manual testing with private/work/personal apps.
Flag: ACONFIG com.android.systemui.screenshot_private_profile TEAMFOOD

Change-Id: I80e0b9e72bbe8f11ea34d9f2e01dfc37769f7511
parent dc336859
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -461,10 +461,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>
    <!-- ComponentName for the file browsing app that the system would expect to be used for
         screenshots. The icon for this app will be shown to the user when informing them that a
         screenshot has been saved to a different profile (e.g. work profile). If blank, a default
         icon will be shown. -->
    <string name="config_screenshotFilesApp" translatable="false"></string>

    <!-- The component name of the screenshot editing activity that provides the App Clips flow.
         The App Clips flow includes taking a screenshot, showing user screenshot cropping activity
+2 −0
Original line number Diff line number Diff line
@@ -257,6 +257,8 @@
    <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">Saved in <xliff:g id="app" example="Files">%1$s</xliff:g> in the work profile</string>
    <!-- Notification displayed when a screenshot is saved in the private profile. [CHAR LIMIT=NONE] -->
    <string name="screenshot_private_profile_notification">Saved in <xliff:g id="app" example="Files">%1$s</xliff:g> in the private profile</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>
    <!-- A notice shown to the user to indicate that an app has detected the screenshot that the user has just taken. [CHAR LIMIT=75] -->
+51 −36
Original line number Diff line number Diff line
@@ -3,15 +3,19 @@ package com.android.systemui.screenshot
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.os.UserHandle
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
import android.view.ViewTreeObserver
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.constraintlayout.widget.Guideline
import com.android.systemui.Flags.screenshotPrivateProfileBehaviorFix
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.res.R
import com.android.systemui.screenshot.message.ProfileMessageController
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/**
 * MessageContainerController controls the display of content in the screenshot message container.
@@ -20,7 +24,9 @@ class MessageContainerController
@Inject
constructor(
    private val workProfileMessageController: WorkProfileMessageController,
    private val profileMessageController: ProfileMessageController,
    private val screenshotDetectionController: ScreenshotDetectionController,
    @Application private val mainScope: CoroutineScope,
) {
    private lateinit var container: ViewGroup
    private lateinit var guideline: Guideline
@@ -42,24 +48,32 @@ constructor(
        detectionNoticeView.visibility = View.GONE
    }

    // Minimal implementation for use when Flags.SCREENSHOT_METADATA isn't turned on.
    fun onScreenshotTaken(userHandle: UserHandle) {
        val workProfileData = workProfileMessageController.onScreenshotTaken(userHandle)
        if (workProfileData != null) {
    fun onScreenshotTaken(screenshot: ScreenshotData) {
        if (screenshotPrivateProfileBehaviorFix()) {
            mainScope.launch {
                val profileData = profileMessageController.onScreenshotTaken(screenshot.userHandle)
                var notifiedApps: List<CharSequence> =
                    screenshotDetectionController.maybeNotifyOfScreenshot(screenshot)

                // If profile first run needs to show, bias towards that, otherwise show screenshot
                // detection notification if needed.
                if (profileData != null) {
                    workProfileFirstRunView.visibility = View.VISIBLE
                    detectionNoticeView.visibility = View.GONE

            workProfileMessageController.populateView(
                workProfileFirstRunView,
                workProfileData,
                this::animateOutMessageContainer
            )
                    profileMessageController.bindView(workProfileFirstRunView, profileData) {
                        animateOutMessageContainer()
                    }
                    animateInMessageContainer()
                } else if (notifiedApps.isNotEmpty()) {
                    detectionNoticeView.visibility = View.VISIBLE
                    workProfileFirstRunView.visibility = View.GONE
                    screenshotDetectionController.populateView(detectionNoticeView, notifiedApps)
                    animateInMessageContainer()
                }
            }

    fun onScreenshotTaken(screenshot: ScreenshotData) {
        val workProfileData = workProfileMessageController.onScreenshotTaken(screenshot.userHandle)
        } else {
            val workProfileData =
                workProfileMessageController.onScreenshotTaken(screenshot.userHandle)
            var notifiedApps: List<CharSequence> =
                screenshotDetectionController.maybeNotifyOfScreenshot(screenshot)

@@ -81,6 +95,7 @@ constructor(
                animateInMessageContainer()
            }
        }
    }

    private fun animateInMessageContainer() {
        if (container.visibility == View.VISIBLE) return
+4 −5
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@ constructor(
        if (userManager.isManagedProfile(userHandle.identifier) && !messageAlreadyDismissed()) {
            var badgedIcon: Drawable? = null
            var label: CharSequence? = null
            val fileManager = fileManagerComponentName()
            val fileManager =
                fileManagerComponentName()
                    ?: return WorkProfileFirstRunData(defaultFileAppName(), null)
            try {
                val info = packageManager.getActivityInfo(fileManager, ComponentInfoFlags.of(0L))
@@ -103,9 +104,7 @@ constructor(
        context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE)

    private fun fileManagerComponentName() =
        ComponentName.unflattenFromString(
            context.getString(R.string.config_sceenshotWorkProfileFilesApp)
        )
        ComponentName.unflattenFromString(context.getString(R.string.config_screenshotFilesApp))

    private fun defaultFileAppName() = context.getString(R.string.screenshot_default_files_app_name)

+2 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.systemui.screenshot.TakeScreenshotExecutorImpl;
import com.android.systemui.screenshot.TakeScreenshotService;
import com.android.systemui.screenshot.appclips.AppClipsScreenshotHelperService;
import com.android.systemui.screenshot.appclips.AppClipsService;
import com.android.systemui.screenshot.message.MessageModule;
import com.android.systemui.screenshot.policy.ScreenshotPolicyModule;
import com.android.systemui.screenshot.proxy.SystemUiProxyModule;
import com.android.systemui.screenshot.ui.viewmodel.ScreenshotViewModel;
@@ -51,7 +52,7 @@ import dagger.multibindings.IntoMap;
/**
 * Defines injectable resources for Screenshots
 */
@Module(includes = {ScreenshotPolicyModule.class, SystemUiProxyModule.class})
@Module(includes = {ScreenshotPolicyModule.class, SystemUiProxyModule.class, MessageModule.class})
public abstract class ScreenshotModule {

    @Binds
Loading