summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Christine Franks <christyfranks@google.com> 2017-07-18 18:12:31 -0700
committer Christine Franks <christyfranks@google.com> 2017-07-21 20:56:18 +0000
commit509711105d6514f93891c6cf29a028ec4b87f3d4 (patch)
treee73bc9a46f61db09e25dc173535b1663e47db6ba
parentcdcbbeccb76cd28daf8e18af7acc71f79ba0fc81 (diff)
Don't display QS security footer in demo mode
Bug: 63843869 Test: runtest systemui Change-Id: I50e408749262b33644c5c007cd1f78138e1d5c3b
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java11
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java23
2 files changed, 33 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
index 56fca1f14fba..3ce1465cfd8a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSSecurityFooter.java
@@ -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,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
index ebd266b87d6c..a8487b3eff4e 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSSecurityFooterTest.java
@@ -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);
@@ -123,6 +131,21 @@ public class QSSecurityFooterTest extends SysuiTestCase {
}
@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);
when(mSecurityController.isNetworkLoggingEnabled()).thenReturn(true);