1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.  Oracle designates this
9  * particular file as subject to the "Classpath" exception as provided
10  * by Oracle in the LICENSE file that accompanied this code.
11  *
12  * This code is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * version 2 for more details (a copy is included in the LICENSE file that
16  * accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License version
19  * 2 along with this work; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  * or visit www.oracle.com if you need additional information or have any
24  * questions.
25  */
26 
27 package java.lang;
28 
29 import java.security.*;
30 import java.io.FileDescriptor;
31 import java.net.InetAddress;
32 
33 // Android-changed: Stubbed the implementation.  Android doesn't support SecurityManager.
34 // SecurityManager can only check access by Java code, so it can be bypassed by using
35 // native code.  Applications should rely on Android permissions, process separation,
36 // other other methods for security purposes.
37 /**
38  * Legacy security code; do not use.
39  *
40  * <p>Security managers do <i>not</i> provide a secure environment for
41  * executing untrusted code and are unsupported on Android. Untrusted code
42  * cannot be safely isolated within a single VM on Android. Application
43  * developers can assume that there's no SecurityManager installed,
44  * i.e. {@link java.lang.System#getSecurityManager()} will return null.
45  */
46 public
47 class SecurityManager {
48 
49     /**
50      * @deprecated Use {@link #checkPermission} instead.
51      */
52     @Deprecated
53     protected boolean inCheck;
54 
55     /**
56      * @deprecated Use {@link #checkPermission} instead.
57      */
58     @Deprecated
getInCheck()59     public boolean getInCheck() {
60         return inCheck;
61     }
62 
SecurityManager()63     public SecurityManager() {
64 
65     }
66 
getClassContext()67     protected Class[] getClassContext() {
68         return null;
69     }
70 
71     /**
72      * @deprecated Use {@link #checkPermission} instead.
73      */
74     @Deprecated
currentClassLoader()75     protected ClassLoader currentClassLoader()
76     {
77         return null;
78     }
79 
80     /**
81      * @deprecated Use {@link #checkPermission} instead.
82      */
83     @Deprecated
currentLoadedClass()84     protected Class<?> currentLoadedClass() {
85         return null;
86     }
87 
88     /**
89      * @deprecated Use {@link #checkPermission} instead.
90      */
91     @Deprecated
classDepth(String name)92     protected int classDepth(String name) {
93         return -1;
94     }
95 
96     /**
97      * @deprecated Use {@link #checkPermission} instead.
98      */
99     @Deprecated
classLoaderDepth()100     protected int classLoaderDepth()
101     {
102         return -1;
103     }
104 
105     /**
106      * @deprecated Use {@link #checkPermission} instead.
107      */
108     @Deprecated
inClass(String name)109     protected boolean inClass(String name) {
110         return false;
111     }
112 
113     /**
114      * @deprecated Use {@link #checkPermission} instead.
115      */
116     @Deprecated
inClassLoader()117     protected boolean inClassLoader() {
118         return false;
119     }
120 
getSecurityContext()121     public Object getSecurityContext() {
122         return null;
123     }
124 
checkPermission(Permission perm)125     public void checkPermission(Permission perm) {
126 
127     }
128 
checkPermission(Permission perm, Object context)129     public void checkPermission(Permission perm, Object context) {
130 
131     }
132 
checkCreateClassLoader()133     public void checkCreateClassLoader() {
134 
135     }
136 
checkAccess(Thread t)137     public void checkAccess(Thread t) { }
138 
checkAccess(ThreadGroup g)139     public void checkAccess(ThreadGroup g) { }
140 
checkExit(int status)141     public void checkExit(int status) { }
142 
checkExec(String cmd)143     public void checkExec(String cmd) { }
144 
checkLink(String lib)145     public void checkLink(String lib) { }
146 
checkRead(FileDescriptor fd)147     public void checkRead(FileDescriptor fd) { }
148 
checkRead(String file)149     public void checkRead(String file) { }
150 
checkRead(String file, Object context)151     public void checkRead(String file, Object context) { }
152 
checkWrite(FileDescriptor fd)153     public void checkWrite(FileDescriptor fd) { }
154 
checkWrite(String file)155     public void checkWrite(String file) { }
156 
checkDelete(String file)157     public void checkDelete(String file) { }
158 
checkConnect(String host, int port)159     public void checkConnect(String host, int port) { }
160 
checkConnect(String host, int port, Object context)161     public void checkConnect(String host, int port, Object context) { }
162 
checkListen(int port)163     public void checkListen(int port) { }
164 
checkAccept(String host, int port)165     public void checkAccept(String host, int port) { }
166 
checkMulticast(InetAddress maddr)167     public void checkMulticast(InetAddress maddr) { }
168 
169     /**
170      * @deprecated use {@link #checkMulticast(java.net.InetAddress)} instead.
171      */
172     @Deprecated
checkMulticast(InetAddress maddr, byte ttl)173     public void checkMulticast(InetAddress maddr, byte ttl) { }
174 
checkPropertiesAccess()175     public void checkPropertiesAccess() { }
176 
checkPropertyAccess(String key)177     public void checkPropertyAccess(String key) { }
178 
checkTopLevelWindow(Object window)179     public boolean checkTopLevelWindow(Object window) {
180         return true;
181     }
182 
checkPrintJobAccess()183     public void checkPrintJobAccess() { }
184 
checkSystemClipboardAccess()185     public void checkSystemClipboardAccess() { }
186 
checkAwtEventQueueAccess()187     public void checkAwtEventQueueAccess() { }
188 
checkPackageAccess(String pkg)189     public void checkPackageAccess(String pkg) { }
190 
checkPackageDefinition(String pkg)191     public void checkPackageDefinition(String pkg) { }
192 
checkSetFactory()193     public void checkSetFactory() { }
194 
checkMemberAccess(Class<?> clazz, int which)195     public void checkMemberAccess(Class<?> clazz, int which) { }
196 
checkSecurityAccess(String target)197     public void checkSecurityAccess(String target) { }
198 
199     /**
200      * Returns the current thread's thread group.
201      */
getThreadGroup()202     public ThreadGroup getThreadGroup() {
203         return Thread.currentThread().getThreadGroup();
204     }
205 
206 }
207