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

Commit 44387fbd authored by Matt Casey's avatar Matt Casey
Browse files

Announce private profile screenshot saving.

Extract announcement logic behind a flag (not much to extract, but it's
one less thing in the controller and now can be tested).

Test: atest com.android.systemui.screenshot
Flag: com.android.systemui.screenshot_private_profile_accessibility_announcement
Bug: 326941376
Change-Id: Iec464e4487e14a5a44298521e18d5b895eb27e90
parent c8b0817d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -522,6 +522,16 @@ flag {
    }
}

flag {
    name: "screenshot_private_profile_accessibility_announcement_fix"
    namespace: "systemui"
    description: "Modified a11y announcement for private space screenshots"
    bug: "326941376"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "screenshot_private_profile_behavior_fix"
    namespace: "systemui"
+2 −0
Original line number Diff line number Diff line
@@ -214,6 +214,8 @@
    <string name="screenshot_saving_title">Saving screenshot\u2026</string>
    <!-- Informs the user that a screenshot is being saved. [CHAR LIMIT=50] -->
    <string name="screenshot_saving_work_profile_title">Saving screenshot to work profile\u2026</string>
    <!-- Informs the user that a screenshot is being saved to the private profile. [CHAR LIMIT=100] -->
    <string name="screenshot_saving_private_profile">Saving screenshot to private</string>
    <!-- Notification title displayed when a screenshot is saved to the Gallery. [CHAR LIMIT=50] -->
    <string name="screenshot_saved_title">Screenshot saved</string>
    <!-- Notification title displayed when we fail to take a screenshot. [CHAR LIMIT=50] -->
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.screenshot

import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.screenshot.data.model.ProfileType
import com.android.systemui.screenshot.data.repository.ProfileTypeRepository
import com.android.systemui.screenshot.resources.Messages
import java.util.function.Consumer
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/** Logic for determining the announcement that a screenshot has been taken (for accessibility). */
class AnnouncementResolver
@Inject
constructor(
    private val messages: Messages,
    private val profileTypes: ProfileTypeRepository,
    @Application private val mainScope: CoroutineScope,
) {

    suspend fun getScreenshotAnnouncement(userId: Int): String =
        when (profileTypes.getProfileType(userId)) {
            ProfileType.PRIVATE -> messages.savingToPrivateProfileAnnouncement
            ProfileType.WORK -> messages.savingToWorkProfileAnnouncement
            else -> messages.savingScreenshotAnnouncement
        }

    fun getScreenshotAnnouncement(userId: Int, announceCallback: Consumer<String>) {
        mainScope.launch { announceCallback.accept(getScreenshotAnnouncement(userId)) }
    }
}
+17 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.screenshot;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.view.WindowManager.LayoutParams.TYPE_SCREENSHOT;

import static com.android.systemui.Flags.screenshotPrivateProfileAccessibilityAnnouncementFix;
import static com.android.systemui.Flags.screenshotShelfUi2;
import static com.android.systemui.screenshot.LogConfig.DEBUG_ANIM;
import static com.android.systemui.screenshot.LogConfig.DEBUG_CALLBACK;
@@ -217,6 +218,7 @@ public class ScreenshotController {
    private final AssistContentRequester mAssistContentRequester;

    private final MessageContainerController mMessageContainerController;
    private final AnnouncementResolver mAnnouncementResolver;
    private Bitmap mScreenBitmap;
    private SaveImageInBackgroundTask mSaveInBgTask;
    private boolean mScreenshotTakenInPortrait;
@@ -268,6 +270,7 @@ public class ScreenshotController {
            AssistContentRequester assistContentRequester,
            MessageContainerController messageContainerController,
            Provider<ScreenshotSoundController> screenshotSoundController,
            AnnouncementResolver announcementResolver,
            @Assisted Display display,
            @Assisted boolean showUIOnExternalDisplay
    ) {
@@ -297,6 +300,7 @@ public class ScreenshotController {
        mUserManager = userManager;
        mMessageContainerController = messageContainerController;
        mAssistContentRequester = assistContentRequester;
        mAnnouncementResolver = announcementResolver;

        mViewProxy = viewProxyFactory.getProxy(mContext, mDisplay.getDisplayId());

@@ -460,6 +464,13 @@ public class ScreenshotController {

    void prepareViewForNewScreenshot(@NonNull ScreenshotData screenshot, String oldPackageName) {
        withWindowAttached(() -> {
            if (screenshotPrivateProfileAccessibilityAnnouncementFix()) {
                mAnnouncementResolver.getScreenshotAnnouncement(
                        screenshot.getUserHandle().getIdentifier(),
                        announcement -> {
                            mViewProxy.announceForAccessibility(announcement);
                        });
            } else {
                if (mUserManager.isManagedProfile(screenshot.getUserHandle().getIdentifier())) {
                    mViewProxy.announceForAccessibility(mContext.getResources().getString(
                            R.string.screenshot_saving_work_profile_title));
@@ -467,6 +478,7 @@ public class ScreenshotController {
                    mViewProxy.announceForAccessibility(
                            mContext.getResources().getString(R.string.screenshot_saving_title));
                }
            }
        });

        mViewProxy.reset();
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.screenshot.resources

import android.content.Context
import androidx.annotation.OpenForTesting
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.res.R
import javax.inject.Inject

/** String values from resources, for easy injection. */
@OpenForTesting
@SysUISingleton
open class Messages @Inject constructor(private val context: Context) {
    open val savingScreenshotAnnouncement by lazy {
        requireNotNull(context.resources.getString(R.string.screenshot_saving_title))
    }

    open val savingToWorkProfileAnnouncement by lazy {
        requireNotNull(context.resources.getString(R.string.screenshot_saving_work_profile_title))
    }

    open val savingToPrivateProfileAnnouncement by lazy {
        requireNotNull(context.resources.getString(R.string.screenshot_saving_private_profile))
    }
}
Loading