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
diff --git a/src/com/android/browser/NavScreen.java b/src/com/android/browser/NavScreen.java
index 9e32f49..76d0703 100644
--- a/src/com/android/browser/NavScreen.java
+++ b/src/com/android/browser/NavScreen.java
@@ -33,8 +33,10 @@
 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 @@
                 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 @@
         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();
         }