summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Tharp <dtharp@codeaurora.org>2015-05-20 15:25:07 -0700
committerWebTech Code Review <code-review@localhost>2015-05-21 10:47:36 -0700
commit3e2896f56b2e1893a9f559c1a64ef436da64e6fc (patch)
tree7b446884bd15ef24c66a52c14df9191b6d6deb63 /src
parent60aac81798fd01c8aaa8b9aeae554416d6ca14f0 (diff)
downloadandroid_packages_apps_Gello-3e2896f56b2e1893a9f559c1a64ef436da64e6fc.tar.gz
android_packages_apps_Gello-3e2896f56b2e1893a9f559c1a64ef436da64e6fc.tar.bz2
android_packages_apps_Gello-3e2896f56b2e1893a9f559c1a64ef436da64e6fc.zip
MDM Incognito Mode Restriction
Implements handling of MDM enforced restriction preventing the user from opening an incognito tab. When enforced by MDM, the Incognito button on the tabs screen is greyed out, and if tapped, presents a toast message informing the user that the setting is managed by the administrator. This commit includes basic unit tests. Change-Id: I26fcf10cc954f63c8e4489dbac9ff148e90b0c94
Diffstat (limited to 'src')
-rw-r--r--src/com/android/browser/NavScreen.java11
-rw-r--r--src/com/android/browser/mdm/IncognitoRestriction.java79
-rw-r--r--src/com/android/browser/mdm/tests/IncognitoRestrictionsTest.java115
3 files changed, 204 insertions, 1 deletions
diff --git a/src/com/android/browser/NavScreen.java b/src/com/android/browser/NavScreen.java
index 9e32f49c..76d0703f 100644
--- a/src/com/android/browser/NavScreen.java
+++ b/src/com/android/browser/NavScreen.java
@@ -33,8 +33,10 @@ import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.RelativeLayout;
+import android.widget.Toast;
import com.android.browser.NavTabScroller.OnRemoveListener;
+import com.android.browser.mdm.IncognitoRestriction;
import java.util.HashMap;
@@ -107,12 +109,15 @@ public class NavScreen extends RelativeLayout
mUiController.getTabControl().getTabPosition(mUi.getActiveTab()));
}
+
+
private void init() {
LayoutInflater.from(getContext()).inflate(R.layout.nav_screen, this);
setContentDescription(getContext().getResources().getString(
R.string.accessibility_transition_navscreen));
mToolbarLayout = findViewById(R.id.nav_toolbar_animate);
mNewIncognitoTab = (ImageButton) findViewById(R.id.newincognitotab);
+ IncognitoRestriction.getInstance().registerButton(mNewIncognitoTab);
mNewTab = (ImageButton) findViewById(R.id.newtab);
mMore = (ImageButton) findViewById(R.id.more);
mNewIncognitoTab.setOnClickListener(this);
@@ -144,7 +149,11 @@ public class NavScreen extends RelativeLayout
if (mNewTab == v) {
openNewTab();
} else if (mNewIncognitoTab == v) {
- openNewIncognitoTab();
+ if (IncognitoRestriction.getInstance().isEnabled()) {
+ Toast.makeText(getContext(), R.string.mdm_managed_alert, Toast.LENGTH_SHORT).show();
+ } else {
+ openNewIncognitoTab();
+ }
} else if (mMore == v) {
showPopupMenu();
}
diff --git a/src/com/android/browser/mdm/IncognitoRestriction.java b/src/com/android/browser/mdm/IncognitoRestriction.java
new file mode 100644
index 00000000..eb62cd3c
--- /dev/null
+++ b/src/com/android/browser/mdm/IncognitoRestriction.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+package com.android.browser.mdm;
+
+import android.os.Bundle;
+import android.widget.ImageButton;
+
+public class IncognitoRestriction extends Restriction {
+
+ private final static String TAG = "IncognitoRestriction";
+
+ public static final String INCOGNITO_RESTRICTION_ENABLED = "IncognitoRestrictionEnabled"; // boolean
+
+ private static IncognitoRestriction sInstance;
+ private ImageButton mIncogButton = null;
+
+ private IncognitoRestriction() {
+ super();
+ }
+
+ public static IncognitoRestriction getInstance() {
+ synchronized (IncognitoRestriction.class) {
+ if (sInstance == null) {
+ sInstance = new IncognitoRestriction();
+ }
+ }
+ return sInstance;
+ }
+
+ @Override
+ public void enforce(Bundle restrictions) {
+ enable(restrictions.getBoolean(INCOGNITO_RESTRICTION_ENABLED, false));
+ updateButton();
+ }
+
+ public void registerButton (ImageButton ib) {
+ mIncogButton = ib;
+ updateButton();
+ }
+
+ private void updateButton() {
+ if (null != mIncogButton) {
+ mIncogButton.setAlpha((float) (isEnabled() ? 0.5 : 1.0));
+ }
+ }
+
+ // For testing
+ public float getButtonAlpha() {
+ return mIncogButton != null ? mIncogButton.getAlpha() : (float) 1.0;
+ }
+}
diff --git a/src/com/android/browser/mdm/tests/IncognitoRestrictionsTest.java b/src/com/android/browser/mdm/tests/IncognitoRestrictionsTest.java
new file mode 100644
index 00000000..e58d64cd
--- /dev/null
+++ b/src/com/android/browser/mdm/tests/IncognitoRestrictionsTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+package com.android.browser.mdm.tests;
+
+import android.app.Instrumentation;
+import android.os.Bundle;
+import android.test.ActivityInstrumentationTestCase2;
+
+import com.android.browser.BrowserActivity;
+import com.android.browser.mdm.IncognitoRestriction;
+import com.android.browser.mdm.ManagedProfileManager;
+
+public class IncognitoRestrictionsTest extends ActivityInstrumentationTestCase2<BrowserActivity> {
+
+ private final static String TAG = "IncognitoRestrictionsTest";
+
+ private Instrumentation mInstrumentation;
+ private BrowserActivity mActivity;
+ private IncognitoRestriction mIncognitoRestriction;
+
+ public IncognitoRestrictionsTest() {
+ super(BrowserActivity.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mInstrumentation = getInstrumentation();
+ mActivity = getActivity();
+ mIncognitoRestriction = IncognitoRestriction.getInstance();
+ }
+
+ public void test_IncognitoRestriction() throws Throwable {
+ // Possible states
+ // enabled | button enabled
+ // ---------------------------------
+ // not set | Yes
+ // true | No
+ // false | Yes
+
+ clearIncognitoRestrictions();
+ assertFalse(mIncognitoRestriction.isEnabled());
+ assertEquals((float) 1.0, mIncognitoRestriction.getButtonAlpha());
+
+ setIncognitoRestrictions(true);
+ assertTrue(mIncognitoRestriction.isEnabled());
+ assertEquals((float) 0.5, mIncognitoRestriction.getButtonAlpha());
+
+ setIncognitoRestrictions(false);
+ assertFalse(mIncognitoRestriction.isEnabled());
+ assertEquals((float) 1.0, mIncognitoRestriction.getButtonAlpha());
+ }
+
+ /**
+ * Activate Incognito restriction
+ * @param clear if true, sends an empty bundle
+ * @param enabled Required. true or false
+ *
+ */
+ private void setIncognitoRestrictions(boolean clear, boolean enabled) {
+ final Bundle restrictions = new Bundle();
+
+ if (!clear) {
+ restrictions.putBoolean(IncognitoRestriction.INCOGNITO_RESTRICTION_ENABLED, enabled);
+ }
+
+ // Deliver restriction on UI thread
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ ManagedProfileManager.getInstance().setMdmRestrictions(restrictions);
+ }
+ });
+
+ // Wait to ensure restriction is set
+ mInstrumentation.waitForIdleSync();
+ }
+
+ private void clearIncognitoRestrictions() {
+ setIncognitoRestrictions(true, false);
+ }
+
+ private void setIncognitoRestrictions(boolean enabled) {
+ setIncognitoRestrictions(false, enabled);
+ }
+
+}