MDM Edit Bookmark Restriction

When enabled through the MDM mechanism, Bookmark editing
operations are disabled:
- Edit and Delete pop-up menu options are disabled
- The 'Add Bookmark' and 'New Folder' buttons are greyed
  and if pressed a Toast message is displayed: 'Managed
  by your administrator'
- All existing bookmark items (except the MDM Managed
  tree if it is present) are overlaid with a lock icon
  (existing: ic_deco_secure).
- The 'Star' icon is greyed and if pressed results in
  the above Toast message

New files are the core implementation of the
EditBookmarksRestriction and the tests for it:
    EditBookmarksRestriction.java
    EditBookmarkRestrictionsTest.java

Note the has been some refactoring in BrowserBookmarksAdapter.java
to simplify the handling of bitmaps with regard to
overlay operations.  We now always set the bitmaps
with setImageBitmap() instead of sometimes using
setImageResource(). This simplifies the code considerably
but does result in a side effect: Folder icons look a bit
different now because they are translated and scaled the same
way as bookmark bitmaps. So instead of center-crop, they appear
as if they are scaled width-wise and top-aligned. Personally,
I like the look, but if its not acceptable, I'll adjust it as needed.

Change-Id: I966f84485873593ca70f2822cdace30a15464c44
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 99a40fe..2f8db52 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -98,6 +98,7 @@
 import com.android.browser.R;
 import com.android.browser.IntentHandler.UrlData;
 import com.android.browser.UI.ComboViews;
+import com.android.browser.mdm.EditBookmarksRestriction;
 import com.android.browser.mdm.IncognitoRestriction;
 import com.android.browser.mdm.URLFilterRestriction;
 import com.android.browser.mynavigation.AddMyNavigationPage;
@@ -1933,8 +1934,9 @@
         mUi.onPrepareOptionsMenu(menu);
 
         IncognitoRestriction.getInstance()
-                            .registerControl(menu.findItem(R.id.incognito_menu_id)
-                                                 .getIcon());
+                .registerControl(menu.findItem(R.id.incognito_menu_id).getIcon());
+        EditBookmarksRestriction.getInstance()
+                .registerControl(menu.findItem(R.id.bookmark_this_page_id).getIcon());
     }
 
     private void setMenuItemVisibility(Menu menu, int id,
@@ -2347,20 +2349,25 @@
 
     @Override
     public void bookmarkCurrentPage() {
-        WebView w = getCurrentTopWebView();
-        if (w == null)
-            return;
-        final Intent i = createBookmarkCurrentPageIntent(false);
-        createScreenshotAsync(
-            w, getDesiredThumbnailWidth(mActivity),
-            getDesiredThumbnailHeight(mActivity),
-            new ValueCallback<Bitmap>() {
-                @Override
-                    public void onReceiveValue(Bitmap bitmap) {
-                    mBookmarkBitmap = bitmap;
-                    mActivity.startActivity(i);
-                }
-            });
+        if(EditBookmarksRestriction.getInstance().isEnabled()) {
+            Toast.makeText(getContext(), R.string.mdm_managed_alert, Toast.LENGTH_SHORT).show();
+        }
+        else {
+            WebView w = getCurrentTopWebView();
+            if (w == null)
+                return;
+            final Intent i = createBookmarkCurrentPageIntent(false);
+            createScreenshotAsync(
+                    w, getDesiredThumbnailWidth(mActivity),
+                    getDesiredThumbnailHeight(mActivity),
+                    new ValueCallback<Bitmap>() {
+                        @Override
+                        public void onReceiveValue(Bitmap bitmap) {
+                            mBookmarkBitmap = bitmap;
+                            mActivity.startActivity(i);
+                        }
+                    });
+        }
     }
 
     private void goLive() {