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

Commit ae6776a8 authored by Christine Franks's avatar Christine Franks Committed by Android (Google) Code Review
Browse files

Merge "Don't display QS security footer in demo mode" into oc-dr1-dev

parents e1132b4a 50971110
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -15,13 +15,16 @@
 */
package com.android.systemui.qs;

import android.app.ActivityManager;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.UserManager;
import android.provider.Settings;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
@@ -59,6 +62,8 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
    private final Handler mMainHandler;
    private final View mDivider;

    private final UserManager mUm;

    private AlertDialog mDialog;
    private QSTileHost mHost;
    protected H mHandler;
@@ -81,6 +86,7 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
        mSecurityController = Dependency.get(SecurityController.class);
        mHandler = new H(Dependency.get(Dependency.BG_LOOPER));
        mDivider = qsPanel == null ? null : qsPanel.getDivider();
        mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    }

    public void setHostEnvironment(QSTileHost host) {
@@ -128,6 +134,9 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic

    private void handleRefreshState() {
        final boolean isDeviceManaged = mSecurityController.isDeviceManaged();
        final UserInfo currentUser = mUm.getUserInfo(ActivityManager.getCurrentUser());
        final boolean isDemoDevice = UserManager.isDeviceInDemoMode(mContext) && currentUser != null
                && currentUser.isDemo();
        final boolean hasWorkProfile = mSecurityController.hasWorkProfile();
        final boolean hasCACerts = mSecurityController.hasCACertInCurrentUser();
        final boolean hasCACertsInWorkProfile = mSecurityController.hasCACertInWorkProfile();
@@ -137,7 +146,7 @@ public class QSSecurityFooter implements OnClickListener, DialogInterface.OnClic
        final CharSequence organizationName = mSecurityController.getDeviceOwnerOrganizationName();
        final CharSequence workProfileName = mSecurityController.getWorkProfileOrganizationName();
        // Update visibility of footer
        mIsVisible = isDeviceManaged || hasCACerts || hasCACertsInWorkProfile ||
        mIsVisible = (isDeviceManaged && !isDemoDevice) || hasCACerts || hasCACertsInWorkProfile ||
            vpnName != null || vpnNameWorkProfile != null;
        // Update the string
        mFooterTextContent = getFooterText(isDeviceManaged, hasWorkProfile,
+23 −0
Original line number Diff line number Diff line
@@ -16,12 +16,16 @@ package com.android.systemui.qs;

import static junit.framework.Assert.assertEquals;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.pm.UserInfo;
import android.os.Handler;
import android.os.Looper;
import android.os.UserManager;
import android.provider.Settings;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
import android.text.SpannableStringBuilder;
@@ -39,6 +43,7 @@ import android.testing.TestableImageView;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;

/*
 * Compile and run the whole SystemUI test suite:
@@ -63,6 +68,7 @@ public class QSSecurityFooterTest extends SysuiTestCase {
    private TestableImageView mFooterIcon;
    private QSSecurityFooter mFooter;
    private SecurityController mSecurityController = mock(SecurityController.class);
    private UserManager mUserManager;

    @Before
    public void setUp() {
@@ -72,6 +78,8 @@ public class QSSecurityFooterTest extends SysuiTestCase {
                new LayoutInflaterBuilder(mContext)
                        .replace("ImageView", TestableImageView.class)
                        .build());
        mUserManager = Mockito.mock(UserManager.class);
        mContext.addMockSystemService(Context.USER_SERVICE, mUserManager);
        Handler h = new Handler(Looper.getMainLooper());
        h.post(() -> mFooter = new QSSecurityFooter(null, mContext));
        waitForIdleSync(h);
@@ -122,6 +130,21 @@ public class QSSecurityFooterTest extends SysuiTestCase {
        assertEquals(-1, mFooterIcon.getLastImageResource());
    }

    @Test
    public void testManagedDemoMode() {
        when(mSecurityController.isDeviceManaged()).thenReturn(true);
        when(mSecurityController.getDeviceOwnerOrganizationName()).thenReturn(null);
        final UserInfo mockUserInfo = Mockito.mock(UserInfo.class);
        when(mockUserInfo.isDemo()).thenReturn(true);
        when(mUserManager.getUserInfo(anyInt())).thenReturn(mockUserInfo);
        Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_DEMO_MODE, 1);

        mFooter.refreshState();

        waitForIdleSync(mFooter.mHandler);
        assertEquals(View.GONE, mRootView.getVisibility());
    }

    @Test
    public void testNetworkLoggingEnabled() {
        when(mSecurityController.isDeviceManaged()).thenReturn(true);