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

Commit b416db5e authored by Chris Göllner's avatar Chris Göllner Committed by Android (Google) Code Review
Browse files

Merge changes from topic "pss-metrics-selector-displayed-finish" into main

* changes:
  [Media Projection] Fix LAST_ACTIVE_SESSION having the wrong timestamp
  [Media Projection] Finish server side logging of SELECTOR DISPLAYED
parents 3b58921a e41e441e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -206,4 +206,17 @@ interface IMediaProjectionManager {
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    oneway void notifyPermissionRequestDisplayed(int hostUid);

    /**
     * Notifies system server that the app selector was displayed.
     *
     * <p>Only used for emitting atoms.
     *
     * @param hostUid The uid of the process requesting consent to capture, may be an app or
     *                SystemUI.
     */
    @EnforcePermission("android.Manifest.permission.MANAGE_MEDIA_PROJECTION")
    @JavaPassthrough(annotation = "@android.annotation.RequiresPermission(android.Manifest"
            + ".permission.MANAGE_MEDIA_PROJECTION)")
    oneway void notifyAppSelectorDisplayed(int hostUid);
}
+13 −0
Original line number Diff line number Diff line
@@ -65,6 +65,19 @@ constructor(private val service: IMediaProjectionManager) {
        }
    }

    /**
     * Request to log that the app selector was displayed.
     *
     * @param hostUid The UID of the package that initiates MediaProjection.
     */
    fun notifyAppSelectorDisplayed(hostUid: Int) {
        try {
            service.notifyAppSelectorDisplayed(hostUid)
        } catch (e: RemoteException) {
            Log.e(TAG, "Error notifying server of app selector displayed", e)
        }
    }

    /**
     * Request to log that the permission request moved to the given state.
     *
+21 −1
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ class MediaProjectionAppSelectorActivity(
        component =
            componentFactory.create(
                hostUserHandle = hostUserHandle,
                hostUid = hostUid,
                callingPackage = callingPackage,
                view = this,
                resultHandler = this,
@@ -305,6 +306,17 @@ class MediaProjectionAppSelectorActivity(
                )
        }

    private val hostUid: Int
        get() {
            if (!intent.hasExtra(EXTRA_HOST_APP_UID)) {
                error(
                    "MediaProjectionAppSelectorActivity should be provided with " +
                        "$EXTRA_HOST_APP_UID extra"
                )
            }
            return intent.getIntExtra(EXTRA_HOST_APP_UID, /* defaultValue= */ -1)
        }

    companion object {
        const val TAG = "MediaProjectionAppSelectorActivity"

@@ -315,8 +327,16 @@ class MediaProjectionAppSelectorActivity(
         */
        const val EXTRA_CAPTURE_REGION_RESULT_RECEIVER = "capture_region_result_receiver"

        /** UID of the app that originally launched the media projection flow (host app user) */
        /**
         * User on the device that launched the media projection flow. (Primary, Secondary, Guest,
         * Work, etc)
         */
        const val EXTRA_HOST_APP_USER_HANDLE = "launched_from_user_handle"
        /**
         * The kernel user-ID that has been assigned to the app that originally launched the media
         * projection flow.
         */
        const val EXTRA_HOST_APP_UID = "launched_from_host_uid"
        const val KEY_CAPTURE_TARGET = "capture_region"

        /** Set up intent for the [ChooserActivity] */
+3 −0
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ import kotlinx.coroutines.SupervisorJob

@Qualifier @Retention(AnnotationRetention.BINARY) annotation class HostUserHandle

@Qualifier @Retention(AnnotationRetention.BINARY) annotation class HostUid

@Retention(AnnotationRetention.RUNTIME) @Scope annotation class MediaProjectionAppSelectorScope

@Module(
@@ -143,6 +145,7 @@ interface MediaProjectionAppSelectorComponent {
        /** Create a factory to inject the activity into the graph */
        fun create(
            @BindsInstance @HostUserHandle hostUserHandle: UserHandle,
            @BindsInstance @HostUid hostUid: Int,
            @BindsInstance @MediaProjectionAppSelector callingPackage: String?,
            @BindsInstance view: MediaProjectionAppSelectorView,
            @BindsInstance resultHandler: MediaProjectionAppSelectorResultHandler,
+2 −1
Original line number Diff line number Diff line
@@ -47,13 +47,14 @@ constructor(
    private val thumbnailLoader: RecentTaskThumbnailLoader,
    @MediaProjectionAppSelector private val isFirstStart: Boolean,
    private val logger: MediaProjectionMetricsLogger,
    @HostUid private val hostUid: Int,
) {

    fun init() {
        // Only log during the first start of the app selector.
        // Don't log when the app selector restarts due to a config change.
        if (isFirstStart) {
            logger.notifyPermissionProgress(STATE_APP_SELECTOR_DISPLAYED)
            logger.notifyAppSelectorDisplayed(hostUid)
        }

        scope.launch {
Loading