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

Commit 23b8d497 authored by Curtis Belmonte's avatar Curtis Belmonte
Browse files

Set secure window flag for AuthContainerView

Marks the window in which AuthContainerView is shown as secure in order
to prevent it from being screenshotted. This matches the behavior of
ConfirmDeviceCredentialActivity in Settings.

Test: atest AuthContainerViewTest
Test: Manual:
1. Use TestDPC to set up work profile
2. Set a PIN for the work profile in Settings > Security
3. Lock and unlock the device with non-work PIN
4. Launch a work app to be prompted for the work PIN
5. Attempt to take a screenshot

Before: Able to take a screenshot of the credential activity

After: Not able to take a screenshot

Fixes: 148000618
Change-Id: Ib1ac94915d28d8d88ec6a81292b69db396c419f9
parent b91132c6
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -583,11 +583,13 @@ public class AuthContainerView extends LinearLayout
     * @return
     */
    public static WindowManager.LayoutParams getLayoutParams(IBinder windowToken) {
        final int windowFlags = WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
                | WindowManager.LayoutParams.FLAG_SECURE;
        final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
                WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
                windowFlags,
                PixelFormat.TRANSLUCENT);
        lp.privateFlags |= WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;
        lp.setTitle("BiometricPrompt");
+10 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.content.Context;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Bundle;
import android.os.IBinder;
import android.os.UserManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
@@ -43,6 +44,7 @@ import android.testing.TestableLooper.RunWithLooper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ScrollView;
@@ -175,6 +177,14 @@ public class AuthContainerViewTest extends SysuiTestCase {
        assertEquals(Utils.CREDENTIAL_PATTERN, mAuthContainer.mCredentialView.mCredentialType);
    }

    @Test
    public void testLayoutParams_hasSecureWindowFlag() {
        final IBinder windowToken = mock(IBinder.class);
        final WindowManager.LayoutParams layoutParams =
                AuthContainerView.getLayoutParams(windowToken);
        assertTrue((layoutParams.flags & WindowManager.LayoutParams.FLAG_SECURE) != 0);
    }

    private void initializeContainer(int authenticators) {
        AuthContainerView.Config config = new AuthContainerView.Config();
        config.mContext = mContext;