Disable System.setSecurityManager.

We plan on removing SecurityManager checks, which are expensive and non-useful,
especially because Android doesn't use SecurityManager itself. As a first step,
let's ship a release where it's no longer possible to set a SecurityManager.

Bug: 1320501
Change-Id: I88664dbc1d8b087579d54003a1aaed7b3d8412be
diff --git a/libcore/luni-kernel/src/main/java/java/lang/System.java b/libcore/luni-kernel/src/main/java/java/lang/System.java
index aa78b1b..a238de7 100644
--- a/libcore/luni-kernel/src/main/java/java/lang/System.java
+++ b/libcore/luni-kernel/src/main/java/java/lang/System.java
@@ -89,11 +89,6 @@
     private static Properties systemProperties;
 
     /**
-     * The System default SecurityManager.
-     */
-    private static SecurityManager securityManager;
-
-    /**
      * Initialize all the slots in System on first use.
      */
     static {
@@ -496,13 +491,13 @@
     }
 
     /**
-     * Returns the active security manager.
+     * Returns null. Android does not use {@code SecurityManager}. This method
+     * is only provided for source compatibility.
      * 
-     * @return the system security manager object.
-     * @since Android 1.0
+     * @return null
      */
     public static SecurityManager getSecurityManager() {
-        return securityManager;
+        return null;
     }
 
     /**
@@ -603,13 +598,11 @@
     }
 
     /**
-     * <strong>Warning:</strong> security managers do <strong>not</strong>
-     * provide a secure environment for executing untrusted code. Untrusted code
-     * cannot be safely isolated within the Dalvik VM.
+     * Throws {@code UnsupportedOperationException}.
      *
-     * <p>Sets the active security manager. Note that once the security manager
-     * has been set, it can not be changed. Attempts to do that will cause a
-     * security exception.
+     * <p>Security managers do <i>not</i> provide a secure environment for
+     * executing untrusted code and are unsupported on Android. Untrusted code
+     * cannot be safely isolated within the Dalvik VM.
      *
      * @param sm
      *            the new security manager.
@@ -617,28 +610,11 @@
      *             if the security manager has already been set and if its
      *             checkPermission method does not allow to redefine the
      *             security manager.
-     * @since Android 1.0
      */
-    public static void setSecurityManager(final SecurityManager sm) {
-        if (securityManager != null) {
-            securityManager.checkPermission(new java.lang.RuntimePermission("setSecurityManager"));
-        }
-
+    public static void setSecurityManager(SecurityManager sm) {
         if (sm != null) {
-            // before the new manager assumed office, make a pass through
-            // the common operations and let it load needed classes (if any),
-            // to avoid infinite recursion later on
-            try {
-                sm.checkPermission(new SecurityPermission("getProperty.package.access"));
-            } catch (Exception ignore) {
-            }
-            try {
-                sm.checkPackageAccess("java.lang");
-            } catch (Exception ignore) {
-            }
+            throw new UnsupportedOperationException();
         }
-
-        securityManager = sm;
     }
 
     /**