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

Commit cd93849c authored by Jacqueline Bronger's avatar Jacqueline Bronger Committed by Android (Google) Code Review
Browse files

Merge "Restrict auto-enter PiP on TV via permission" into main

parents 9e36d62b 82f413cc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -314,6 +314,7 @@ package android {
    field public static final String SYSTEM_ALERT_WINDOW = "android.permission.SYSTEM_ALERT_WINDOW";
    field public static final String TRANSMIT_IR = "android.permission.TRANSMIT_IR";
    field public static final String TURN_SCREEN_ON = "android.permission.TURN_SCREEN_ON";
    field @FlaggedApi("android.app.enable_tv_implicit_enter_pip_restriction") public static final String TV_IMPLICIT_ENTER_PIP = "android.permission.TV_IMPLICIT_ENTER_PIP";
    field public static final String UNINSTALL_SHORTCUT = "com.android.launcher.permission.UNINSTALL_SHORTCUT";
    field public static final String UPDATE_DEVICE_STATS = "android.permission.UPDATE_DEVICE_STATS";
    field public static final String UPDATE_PACKAGES_WITHOUT_USER_ACTION = "android.permission.UPDATE_PACKAGES_WITHOUT_USER_ACTION";
+22 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static com.android.sdksandbox.flags.Flags.sandboxActivitySdkBasedContext;

import static java.lang.Character.MIN_VALUE;

import android.Manifest;
import android.annotation.AnimRes;
import android.annotation.CallSuper;
import android.annotation.CallbackExecutor;
@@ -3193,6 +3194,16 @@ public class Activity extends ContextThemeWrapper
        return ActivityTaskManager.getMaxNumPictureInPictureActions(this);
    }

    private boolean isImplicitEnterPipProhibited() {
        PackageManager pm = getPackageManager();
        if (android.app.Flags.enableTvImplicitEnterPipRestriction()) {
            return pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK)
                    && pm.checkPermission(Manifest.permission.TV_IMPLICIT_ENTER_PIP,
                    getPackageName()) == PackageManager.PERMISSION_DENIED;
        }
        return false;
    }

    /**
     * @return Whether this device supports picture-in-picture.
     */
@@ -9192,6 +9203,8 @@ public class Activity extends ContextThemeWrapper
        }
        dispatchActivityPreResumed();

        mCanEnterPictureInPicture = true;

        mFragments.execPendingActions();

        mLastNonConfigurationInstances = null;
@@ -9243,6 +9256,11 @@ public class Activity extends ContextThemeWrapper
            Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "performPause:"
                    + mComponent.getClassName());
        }

        if (isImplicitEnterPipProhibited()) {
            mCanEnterPictureInPicture = false;
        }

        dispatchActivityPrePaused();
        mDoReportFullyDrawn = false;
        mFragments.dispatchPause();
@@ -9265,6 +9283,10 @@ public class Activity extends ContextThemeWrapper

    final void performUserLeaving() {
        onUserInteraction();

        if (isImplicitEnterPipProhibited()) {
            mCanEnterPictureInPicture = false;
        }
        onUserLeaveHint();
    }

+8 −0
Original line number Diff line number Diff line
@@ -8,3 +8,11 @@ flag {
    description: "Enables PiP UI state callback on entering"
    bug: "303718131"
}

flag {
    name: "enable_tv_implicit_enter_pip_restriction"
    is_exported: true
    namespace: "tv_system_ui"
    description: "Enables restrictions to PiP entry on TV for setAutoEnterEnabled and lifecycle methods"
    bug: "283115999"
}
+1 −0
Original line number Diff line number Diff line
@@ -158,6 +158,7 @@ android_app {
    flags_packages: [
        "android.app.appfunctions.flags-aconfig",
        "android.app.contextualsearch.flags-aconfig",
        "android.app.flags-aconfig",
        "android.appwidget.flags-aconfig",
        "android.content.pm.flags-aconfig",
        "android.provider.flags-aconfig",
+12 −0
Original line number Diff line number Diff line
@@ -4463,6 +4463,18 @@
                android:description="@string/permdesc_hideOverlayWindows"
                android:protectionLevel="normal" />

    <!-- Allows an app to enter Picture-in-Picture mode when the user is not explicitly requesting
        it. This includes using {@link PictureInPictureParams.Builder#setAutoEnterEnabled} as well
        as lifecycle methods such as {@link Activity#onUserLeaveHint} and {@link Activity#onPause}
        to enter PiP when the user leaves the app.
        This permission should only be used for certain PiP
        <a href="{@docRoot}training/tv/get-started/multitasking#usage-types">usage types</a>.
        @FlaggedApi(android.app.Flags.FLAG_ENABLE_TV_IMPLICIT_ENTER_PIP_RESTRICTION)
     -->
    <permission android:name="android.permission.TV_IMPLICIT_ENTER_PIP"
        android:protectionLevel="normal"
        android:featureFlag="android.app.enable_tv_implicit_enter_pip_restriction" />

    <!-- ================================== -->
    <!-- Permissions affecting the system wallpaper -->
    <!-- ================================== -->
Loading