• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package jdk.internal.misc;
27 
28 import java.io.ObjectInputStream;
29 
30 /** A repository of "shared secrets", which are a mechanism for
31     calling implementation-private methods in another package without
32     using reflection. A package-private class implements a public
33     interface and provides the ability to call package-private methods
34     within that package; the object implementing that interface is
35     provided through a third package to which access is restricted.
36     This framework avoids the primary disadvantage of using reflection
37     for this purpose, namely the loss of compile-time checking. */
38 
39 public class SharedSecrets {
40     private static final Unsafe unsafe = Unsafe.getUnsafe();
41     // BEGIN Android-removed: Pruned unused access interfaces.
42     /*
43     private static JavaUtilJarAccess javaUtilJarAccess;
44     private static JavaLangAccess javaLangAccess;
45     private static JavaLangRefAccess javaLangRefAccess;
46     private static JavaIOAccess javaIOAccess;
47     private static JavaNetAccess javaNetAccess;
48     private static JavaNetHttpCookieAccess javaNetHttpCookieAccess;
49     private static JavaNioAccess javaNioAccess;
50     */
51     // END Android-removed: Pruned unused access interfaces.
52     private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess;
53     // BEGIN Android-removed: Pruned unused access interfaces.
54     /*
55     private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess;
56     private static JavaSecurityAccess javaSecurityAccess;
57     private static JavaUtilZipFileAccess javaUtilZipFileAccess;
58     private static JavaAWTAccess javaAWTAccess;
59     private static JavaOISAccess javaOISAccess;
60     private static JavaObjectInputStreamReadString javaObjectInputStreamReadString;
61     */
62     // END Android-removed: Pruned unused access interfaces.
63     private static JavaObjectInputStreamAccess javaObjectInputStreamAccess;
64     // BEGIN Android-removed: Pruned unused access interfaces.
65     /*
66     private static JavaSecuritySignatureAccess javaSecuritySignatureAccess;
67 
68     public static JavaUtilJarAccess javaUtilJarAccess() {
69         if (javaUtilJarAccess == null) {
70             // Ensure JarFile is initialized; we know that that class
71             // provides the shared secret
72             unsafe.ensureClassInitialized(JarFile.class);
73         }
74         return javaUtilJarAccess;
75     }
76 
77     public static void setJavaUtilJarAccess(JavaUtilJarAccess access) {
78         javaUtilJarAccess = access;
79     }
80 
81     public static void setJavaLangAccess(JavaLangAccess jla) {
82         javaLangAccess = jla;
83     }
84 
85     public static JavaLangAccess getJavaLangAccess() {
86         return javaLangAccess;
87     }
88 
89     public static void setJavaLangRefAccess(JavaLangRefAccess jlra) {
90         javaLangRefAccess = jlra;
91     }
92 
93     public static JavaLangRefAccess getJavaLangRefAccess() {
94         return javaLangRefAccess;
95     }
96 
97     public static void setJavaNetAccess(JavaNetAccess jna) {
98         javaNetAccess = jna;
99     }
100 
101     public static JavaNetAccess getJavaNetAccess() {
102         return javaNetAccess;
103     }
104 
105     public static void setJavaNetHttpCookieAccess(JavaNetHttpCookieAccess a) {
106         javaNetHttpCookieAccess = a;
107     }
108 
109     public static JavaNetHttpCookieAccess getJavaNetHttpCookieAccess() {
110         if (javaNetHttpCookieAccess == null)
111             unsafe.ensureClassInitialized(java.net.HttpCookie.class);
112         return javaNetHttpCookieAccess;
113     }
114 
115     public static void setJavaNioAccess(JavaNioAccess jna) {
116         javaNioAccess = jna;
117     }
118 
119     public static JavaNioAccess getJavaNioAccess() {
120         if (javaNioAccess == null) {
121             // Ensure java.nio.ByteOrder is initialized; we know that
122             // this class initializes java.nio.Bits that provides the
123             // shared secret.
124             unsafe.ensureClassInitialized(java.nio.ByteOrder.class);
125         }
126         return javaNioAccess;
127     }
128 
129     public static void setJavaIOAccess(JavaIOAccess jia) {
130         javaIOAccess = jia;
131     }
132 
133     public static JavaIOAccess getJavaIOAccess() {
134         if (javaIOAccess == null) {
135             unsafe.ensureClassInitialized(Console.class);
136         }
137         return javaIOAccess;
138     }
139     */
140     // END Android-removed: Pruned unused access interfaces.
141 
setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda)142     public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) {
143         javaIOFileDescriptorAccess = jiofda;
144     }
145 
getJavaIOFileDescriptorAccess()146     public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() {
147         // Android-changed: ensureClassInitialized isn't supported in Android. Use Class.forName.
148         // if (javaIOFileDescriptorAccess == null)
149         //     unsafe.ensureClassInitialized(FileDescriptor.class);
150         if (javaIOFileDescriptorAccess == null) {
151             try {
152                 Class.forName("java.io.FileDescriptor");
153             } catch (ClassNotFoundException e) {
154                 // Throw if FileDescriptor class is not found. Something wrong in runtime / libcore.
155                 throw new RuntimeException(e);
156             }
157         }
158         return javaIOFileDescriptorAccess;
159     }
160 
161     // BEGIN Android-removed: Pruned unused access interfaces.
162     /*
163     public static void setJavaOISAccess(JavaOISAccess access) {
164         javaOISAccess = access;
165     }
166 
167     public static JavaOISAccess getJavaOISAccess() {
168         if (javaOISAccess == null)
169             unsafe.ensureClassInitialized(ObjectInputStream.class);
170 
171         return javaOISAccess;
172     }
173 
174 
175     public static void setJavaSecurityProtectionDomainAccess
176         (JavaSecurityProtectionDomainAccess jspda) {
177             javaSecurityProtectionDomainAccess = jspda;
178     }
179 
180     public static JavaSecurityProtectionDomainAccess
181         getJavaSecurityProtectionDomainAccess() {
182             if (javaSecurityProtectionDomainAccess == null)
183                 unsafe.ensureClassInitialized(ProtectionDomain.class);
184             return javaSecurityProtectionDomainAccess;
185     }
186 
187     public static void setJavaSecurityAccess(JavaSecurityAccess jsa) {
188         javaSecurityAccess = jsa;
189     }
190 
191     public static JavaSecurityAccess getJavaSecurityAccess() {
192         if (javaSecurityAccess == null) {
193             unsafe.ensureClassInitialized(AccessController.class);
194         }
195         return javaSecurityAccess;
196     }
197 
198     public static JavaUtilZipFileAccess getJavaUtilZipFileAccess() {
199         if (javaUtilZipFileAccess == null)
200             unsafe.ensureClassInitialized(java.util.zip.ZipFile.class);
201         return javaUtilZipFileAccess;
202     }
203 
204     public static void setJavaUtilZipFileAccess(JavaUtilZipFileAccess access) {
205         javaUtilZipFileAccess = access;
206     }
207 
208     public static void setJavaAWTAccess(JavaAWTAccess jaa) {
209         javaAWTAccess = jaa;
210     }
211 
212     public static JavaAWTAccess getJavaAWTAccess() {
213         // this may return null in which case calling code needs to
214         // provision for.
215         if (javaAWTAccess == null) {
216             return null;
217         }
218         return javaAWTAccess;
219     }
220 
221     public static JavaObjectInputStreamReadString getJavaObjectInputStreamReadString() {
222         if (javaObjectInputStreamReadString == null) {
223             unsafe.ensureClassInitialized(ObjectInputStream.class);
224         }
225         return javaObjectInputStreamReadString;
226     }
227 
228     public static void setJavaObjectInputStreamReadString(JavaObjectInputStreamReadString access) {
229         javaObjectInputStreamReadString = access;
230     }
231     */
232     // END Android-removed: Pruned unused access interfaces.
233 
getJavaObjectInputStreamAccess()234     public static JavaObjectInputStreamAccess getJavaObjectInputStreamAccess() {
235         if (javaObjectInputStreamAccess == null) {
236             unsafe.ensureClassInitialized(ObjectInputStream.class);
237         }
238         return javaObjectInputStreamAccess;
239     }
240 
setJavaObjectInputStreamAccess(JavaObjectInputStreamAccess access)241     public static void setJavaObjectInputStreamAccess(JavaObjectInputStreamAccess access) {
242         javaObjectInputStreamAccess = access;
243     }
244 
245     // BEGIN Android-removed: Pruned unused access interfaces.
246     /*
247     public static void setJavaSecuritySignatureAccess(JavaSecuritySignatureAccess jssa) {
248         javaSecuritySignatureAccess = jssa;
249     }
250 
251     public static JavaSecuritySignatureAccess getJavaSecuritySignatureAccess() {
252         if (javaSecuritySignatureAccess == null) {
253             unsafe.ensureClassInitialized(Signature.class);
254         }
255         return javaSecuritySignatureAccess;
256     }
257     */
258     // END Android-removed: Pruned unused access interfaces.
259 }
260