MDM Download Restriction support

This commit adds MDM management of the following if the restriction
is enabled via the MDM mechanism:
    1. The ability to download.
    2. The download directory under '/Phone Storage/', if
       downloading is permitted.

These restrictions are only effective on SWE provisioned in the
'Work' profile. Non-work-profile SWE will not be affected.

When the download capability has been restricted, clicking a download
link results in a Toast message (Managed by your administrator). A long-press
of the link still brings up a context menu, but the 'Save link as' menuitem
is disabled in this case.

If MDM sets the download directory, it is not setting the full path, just
the directory under '/Phone Storage'. The directory specified must include
a leading '/' i.e. '/NewDownloadDir'.

Change-Id: I13a44892a36925d6324b87f7655d79fb0776f8a9
diff --git a/src/com/android/browser/DownloadHandler.java b/src/com/android/browser/DownloadHandler.java
index 419e4b4..556b39f 100644
--- a/src/com/android/browser/DownloadHandler.java
+++ b/src/com/android/browser/DownloadHandler.java
@@ -38,6 +38,7 @@
 import android.widget.Toast;
 
 import com.android.browser.R;
+import com.android.browser.mdm.DownloadDirRestriction;
 import com.android.browser.platformsupport.WebAddress;
 import com.android.browser.reflect.ReflectHelper;
 
@@ -320,8 +321,14 @@
             new FetchUrlMimeType(activity, url, userAgent, referer,
                     privateBrowsing, filename).start();
         } else {
-            startDownloadSettings(activity, url, userAgent, contentDisposition, mimetype, referer,
-                    privateBrowsing, contentLength, filename);
+            if (DownloadDirRestriction.getInstance().downloadsAllowed()) {
+                startDownloadSettings(activity, url, userAgent, contentDisposition, mimetype, referer,
+                        privateBrowsing, contentLength, filename);
+            }
+            else {
+                Toast.makeText(activity, R.string.managed_by_your_administrator, Toast.LENGTH_SHORT)
+                .show();
+            }
         }
 
     }
@@ -599,7 +606,7 @@
             defaultStorage = getExternalStorageDirectory(context);
         }
 
-        defaultDownloadPath = defaultStorage + context.getString(R.string.download_default_path);
+        defaultDownloadPath = defaultStorage + DownloadDirRestriction.getInstance().getDownloadDirectory();
         Log.e(LOGTAG, "defaultStorage directory is : " + defaultDownloadPath);
         return defaultDownloadPath;
     }