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 sun.misc; 27 28 /** A repository of "shared secrets", which are a mechanism for 29 calling implementation-private methods in another package without 30 using reflection. A package-private class implements a public 31 interface and provides the ability to call package-private methods 32 within that package; the object implementing that interface is 33 provided through a third package to which access is restricted. 34 This framework avoids the primary disadvantage of using reflection 35 for this purpose, namely the loss of compile-time checking. */ 36 37 public class SharedSecrets { 38 // BEGIN Android-removed: Pruned unused access interfaces. 39 /* 40 private static final Unsafe unsafe = Unsafe.getUnsafe(); 41 private static JavaUtilJarAccess javaUtilJarAccess; 42 private static JavaLangAccess javaLangAccess; 43 private static JavaLangRefAccess javaLangRefAccess; 44 private static JavaIOAccess javaIOAccess; 45 private static JavaNetAccess javaNetAccess; 46 private static JavaNetHttpCookieAccess javaNetHttpCookieAccess; 47 private static JavaNioAccess javaNioAccess; 48 */ 49 // END Android-removed: Pruned unused access interfaces. 50 private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess; 51 // BEGIN Android-removed: Pruned unused access interfaces. 52 /* 53 private static JavaSecurityProtectionDomainAccess javaSecurityProtectionDomainAccess; 54 private static JavaSecurityAccess javaSecurityAccess; 55 private static JavaUtilZipFileAccess javaUtilZipFileAccess; 56 private static JavaAWTAccess javaAWTAccess; 57 private static JavaOISAccess javaOISAccess; 58 private static JavaObjectInputStreamAccess javaObjectInputStreamAccess; 59 60 public static JavaUtilJarAccess javaUtilJarAccess() { 61 if (javaUtilJarAccess == null) { 62 // Ensure JarFile is initialized; we know that that class 63 // provides the shared secret 64 unsafe.ensureClassInitialized(JarFile.class); 65 } 66 return javaUtilJarAccess; 67 } 68 69 public static void setJavaUtilJarAccess(JavaUtilJarAccess access) { 70 javaUtilJarAccess = access; 71 } 72 73 public static void setJavaLangAccess(JavaLangAccess jla) { 74 javaLangAccess = jla; 75 } 76 77 public static JavaLangAccess getJavaLangAccess() { 78 return javaLangAccess; 79 } 80 81 public static void setJavaLangRefAccess(JavaLangRefAccess jlra) { 82 javaLangRefAccess = jlra; 83 } 84 85 public static JavaLangRefAccess getJavaLangRefAccess() { 86 return javaLangRefAccess; 87 } 88 89 public static void setJavaNetAccess(JavaNetAccess jna) { 90 javaNetAccess = jna; 91 } 92 93 public static JavaNetAccess getJavaNetAccess() { 94 return javaNetAccess; 95 } 96 97 public static void setJavaNetHttpCookieAccess(JavaNetHttpCookieAccess a) { 98 javaNetHttpCookieAccess = a; 99 } 100 101 public static JavaNetHttpCookieAccess getJavaNetHttpCookieAccess() { 102 if (javaNetHttpCookieAccess == null) 103 unsafe.ensureClassInitialized(java.net.HttpCookie.class); 104 return javaNetHttpCookieAccess; 105 } 106 107 public static void setJavaNioAccess(JavaNioAccess jna) { 108 javaNioAccess = jna; 109 } 110 111 public static JavaNioAccess getJavaNioAccess() { 112 if (javaNioAccess == null) { 113 // Ensure java.nio.ByteOrder is initialized; we know that 114 // this class initializes java.nio.Bits that provides the 115 // shared secret. 116 unsafe.ensureClassInitialized(java.nio.ByteOrder.class); 117 } 118 return javaNioAccess; 119 } 120 121 public static void setJavaIOAccess(JavaIOAccess jia) { 122 javaIOAccess = jia; 123 } 124 125 public static JavaIOAccess getJavaIOAccess() { 126 if (javaIOAccess == null) { 127 unsafe.ensureClassInitialized(Console.class); 128 } 129 return javaIOAccess; 130 } 131 */ 132 // END Android-removed: Pruned unused access interfaces. 133 setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda)134 public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) { 135 javaIOFileDescriptorAccess = jiofda; 136 } 137 getJavaIOFileDescriptorAccess()138 public static JavaIOFileDescriptorAccess getJavaIOFileDescriptorAccess() { 139 // Android-changed: ensureClassInitialized isn't supported in Android. Use Class.forName. 140 // if (javaIOFileDescriptorAccess == null) 141 // unsafe.ensureClassInitialized(FileDescriptor.class); 142 if (javaIOFileDescriptorAccess == null) { 143 try { 144 Class.forName("java.io.FileDescriptor"); 145 } catch (ClassNotFoundException e) { 146 // Throw if FileDescriptor class is not found. Something wrong in runtime / libcore. 147 throw new RuntimeException(e); 148 } 149 } 150 return javaIOFileDescriptorAccess; 151 } 152 153 // BEGIN Android-removed: Pruned unused access interfaces. 154 /* 155 public static void setJavaOISAccess(JavaOISAccess access) { 156 javaOISAccess = access; 157 } 158 159 public static JavaOISAccess getJavaOISAccess() { 160 if (javaOISAccess == null) 161 unsafe.ensureClassInitialized(ObjectInputStream.class); 162 163 return javaOISAccess; 164 } 165 166 167 public static void setJavaSecurityProtectionDomainAccess 168 (JavaSecurityProtectionDomainAccess jspda) { 169 javaSecurityProtectionDomainAccess = jspda; 170 } 171 172 public static JavaSecurityProtectionDomainAccess 173 getJavaSecurityProtectionDomainAccess() { 174 if (javaSecurityProtectionDomainAccess == null) 175 unsafe.ensureClassInitialized(ProtectionDomain.class); 176 return javaSecurityProtectionDomainAccess; 177 } 178 179 public static void setJavaSecurityAccess(JavaSecurityAccess jsa) { 180 javaSecurityAccess = jsa; 181 } 182 183 public static JavaSecurityAccess getJavaSecurityAccess() { 184 if (javaSecurityAccess == null) { 185 unsafe.ensureClassInitialized(AccessController.class); 186 } 187 return javaSecurityAccess; 188 } 189 190 public static JavaUtilZipFileAccess getJavaUtilZipFileAccess() { 191 if (javaUtilZipFileAccess == null) 192 unsafe.ensureClassInitialized(java.util.zip.ZipFile.class); 193 return javaUtilZipFileAccess; 194 } 195 196 public static void setJavaUtilZipFileAccess(JavaUtilZipFileAccess access) { 197 javaUtilZipFileAccess = access; 198 } 199 200 public static void setJavaAWTAccess(JavaAWTAccess jaa) { 201 javaAWTAccess = jaa; 202 } 203 204 public static JavaAWTAccess getJavaAWTAccess() { 205 // this may return null in which case calling code needs to 206 // provision for. 207 if (javaAWTAccess == null) { 208 return null; 209 } 210 return javaAWTAccess; 211 } 212 213 public static JavaObjectInputStreamAccess getJavaObjectInputStreamAccess() { 214 if (javaObjectInputStreamAccess == null) { 215 unsafe.ensureClassInitialized(ObjectInputStream.class); 216 } 217 return javaObjectInputStreamAccess; 218 } 219 220 public static void setJavaObjectInputStreamAccess(JavaObjectInputStreamAccess access) { 221 javaObjectInputStreamAccess = access; 222 } 223 */ 224 // END Android-removed: Pruned unused access interfaces. 225 } 226