The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* //device/libs/android_runtime/android_util_AssetManager.cpp |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "asset" |
| 19 | |
| 20 | #include <android_runtime/android_util_AssetManager.h> |
| 21 | |
Dan Albert | 46d8444 | 2014-11-18 16:07:51 -0800 | [diff] [blame] | 22 | #include <inttypes.h> |
| 23 | #include <linux/capability.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <stdio.h> |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | #include <sys/wait.h> |
Mårten Kongstad | 83ab0d7 | 2015-03-20 12:57:36 +0100 | [diff] [blame] | 27 | #include <sys/stat.h> |
Jakub Adamek | 1c15c63 | 2016-09-23 09:07:11 +0100 | [diff] [blame] | 28 | #include <sys/system_properties.h> |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 29 | |
Dan Albert | 46d8444 | 2014-11-18 16:07:51 -0800 | [diff] [blame] | 30 | #include <private/android_filesystem_config.h> // for AID_SYSTEM |
| 31 | |
Dan Albert | 3a091b7 | 2014-11-20 15:41:25 -0800 | [diff] [blame] | 32 | #include "androidfw/Asset.h" |
| 33 | #include "androidfw/AssetManager.h" |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 34 | #include "androidfw/AttributeResolution.h" |
Dan Albert | 3a091b7 | 2014-11-20 15:41:25 -0800 | [diff] [blame] | 35 | #include "androidfw/ResourceTypes.h" |
| 36 | #include "android_runtime/AndroidRuntime.h" |
| 37 | #include "android_util_Binder.h" |
| 38 | #include "core_jni_helpers.h" |
| 39 | #include "jni.h" |
Dan Albert | 46d8444 | 2014-11-18 16:07:51 -0800 | [diff] [blame] | 40 | #include "JNIHelp.h" |
| 41 | #include "ScopedStringChars.h" |
| 42 | #include "ScopedUtfChars.h" |
Dan Albert | 46d8444 | 2014-11-18 16:07:51 -0800 | [diff] [blame] | 43 | #include "utils/Log.h" |
| 44 | #include "utils/misc.h" |
Jakub Adamek | 1c15c63 | 2016-09-23 09:07:11 +0100 | [diff] [blame] | 45 | #include "utils/String8.h" |
Dan Albert | 46d8444 | 2014-11-18 16:07:51 -0800 | [diff] [blame] | 46 | |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 47 | extern "C" int capget(cap_user_header_t hdrp, cap_user_data_t datap); |
| 48 | extern "C" int capset(cap_user_header_t hdrp, const cap_user_data_t datap); |
| 49 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | |
| 51 | namespace android { |
| 52 | |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 53 | static const bool kThrowOnBadId = false; |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 54 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | // ---------------------------------------------------------------------------- |
| 56 | |
| 57 | static struct typedvalue_offsets_t |
| 58 | { |
| 59 | jfieldID mType; |
| 60 | jfieldID mData; |
| 61 | jfieldID mString; |
| 62 | jfieldID mAssetCookie; |
| 63 | jfieldID mResourceId; |
| 64 | jfieldID mChangingConfigurations; |
| 65 | jfieldID mDensity; |
| 66 | } gTypedValueOffsets; |
| 67 | |
| 68 | static struct assetfiledescriptor_offsets_t |
| 69 | { |
| 70 | jfieldID mFd; |
| 71 | jfieldID mStartOffset; |
| 72 | jfieldID mLength; |
| 73 | } gAssetFileDescriptorOffsets; |
| 74 | |
| 75 | static struct assetmanager_offsets_t |
| 76 | { |
| 77 | jfieldID mObject; |
| 78 | } gAssetManagerOffsets; |
| 79 | |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 80 | static struct sparsearray_offsets_t |
| 81 | { |
| 82 | jclass classObject; |
| 83 | jmethodID constructor; |
| 84 | jmethodID put; |
| 85 | } gSparseArrayOffsets; |
| 86 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 87 | static struct configuration_offsets_t |
| 88 | { |
| 89 | jclass classObject; |
| 90 | jmethodID constructor; |
| 91 | jfieldID mSmallestScreenWidthDpOffset; |
| 92 | jfieldID mScreenWidthDpOffset; |
| 93 | jfieldID mScreenHeightDpOffset; |
| 94 | } gConfigurationOffsets; |
| 95 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | jclass g_stringClass = NULL; |
| 97 | |
| 98 | // ---------------------------------------------------------------------------- |
| 99 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | static jint copyValue(JNIEnv* env, jobject outValue, const ResTable* table, |
| 101 | const Res_value& value, uint32_t ref, ssize_t block, |
| 102 | uint32_t typeSpecFlags, ResTable_config* config = NULL); |
| 103 | |
| 104 | jint copyValue(JNIEnv* env, jobject outValue, const ResTable* table, |
| 105 | const Res_value& value, uint32_t ref, ssize_t block, |
| 106 | uint32_t typeSpecFlags, ResTable_config* config) |
| 107 | { |
| 108 | env->SetIntField(outValue, gTypedValueOffsets.mType, value.dataType); |
| 109 | env->SetIntField(outValue, gTypedValueOffsets.mAssetCookie, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 110 | static_cast<jint>(table->getTableCookie(block))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | env->SetIntField(outValue, gTypedValueOffsets.mData, value.data); |
| 112 | env->SetObjectField(outValue, gTypedValueOffsets.mString, NULL); |
| 113 | env->SetIntField(outValue, gTypedValueOffsets.mResourceId, ref); |
| 114 | env->SetIntField(outValue, gTypedValueOffsets.mChangingConfigurations, |
| 115 | typeSpecFlags); |
| 116 | if (config != NULL) { |
| 117 | env->SetIntField(outValue, gTypedValueOffsets.mDensity, config->density); |
| 118 | } |
| 119 | return block; |
| 120 | } |
| 121 | |
Jaekyun Seok | 7de2f9c | 2017-03-02 12:45:10 +0900 | [diff] [blame] | 122 | // This is called by zygote (running as user root) as part of preloadResources. |
| 123 | static void verifySystemIdmaps() |
| 124 | { |
| 125 | pid_t pid; |
| 126 | char system_id[10]; |
| 127 | |
| 128 | snprintf(system_id, sizeof(system_id), "%d", AID_SYSTEM); |
| 129 | |
| 130 | switch (pid = fork()) { |
| 131 | case -1: |
| 132 | ALOGE("failed to fork for idmap: %s", strerror(errno)); |
| 133 | break; |
| 134 | case 0: // child |
| 135 | { |
| 136 | struct __user_cap_header_struct capheader; |
| 137 | struct __user_cap_data_struct capdata; |
| 138 | |
| 139 | memset(&capheader, 0, sizeof(capheader)); |
| 140 | memset(&capdata, 0, sizeof(capdata)); |
| 141 | |
| 142 | capheader.version = _LINUX_CAPABILITY_VERSION; |
| 143 | capheader.pid = 0; |
| 144 | |
| 145 | if (capget(&capheader, &capdata) != 0) { |
| 146 | ALOGE("capget: %s\n", strerror(errno)); |
| 147 | exit(1); |
| 148 | } |
| 149 | |
| 150 | capdata.effective = capdata.permitted; |
| 151 | if (capset(&capheader, &capdata) != 0) { |
| 152 | ALOGE("capset: %s\n", strerror(errno)); |
| 153 | exit(1); |
| 154 | } |
| 155 | |
| 156 | if (setgid(AID_SYSTEM) != 0) { |
| 157 | ALOGE("setgid: %s\n", strerror(errno)); |
| 158 | exit(1); |
| 159 | } |
| 160 | |
| 161 | if (setuid(AID_SYSTEM) != 0) { |
| 162 | ALOGE("setuid: %s\n", strerror(errno)); |
| 163 | exit(1); |
| 164 | } |
| 165 | |
| 166 | // Generic idmap parameters |
| 167 | const char* argv[8]; |
| 168 | int argc = 0; |
| 169 | struct stat st; |
| 170 | |
| 171 | memset(argv, NULL, sizeof(argv)); |
| 172 | argv[argc++] = AssetManager::IDMAP_BIN; |
| 173 | argv[argc++] = "--scan"; |
| 174 | argv[argc++] = AssetManager::TARGET_PACKAGE_NAME; |
| 175 | argv[argc++] = AssetManager::TARGET_APK_PATH; |
| 176 | argv[argc++] = AssetManager::IDMAP_DIR; |
| 177 | |
| 178 | // Directories to scan for overlays: if OVERLAY_THEME_DIR_PROPERTY is defined, |
| 179 | // use OVERLAY_DIR/<value of OVERLAY_THEME_DIR_PROPERTY> in addition to OVERLAY_DIR. |
| 180 | char subdir[PROP_VALUE_MAX]; |
| 181 | int len = __system_property_get(AssetManager::OVERLAY_THEME_DIR_PERSIST_PROPERTY, |
| 182 | subdir); |
| 183 | if (len == 0) { |
| 184 | len = __system_property_get(AssetManager::OVERLAY_THEME_DIR_PROPERTY, subdir); |
| 185 | } |
| 186 | if (len > 0) { |
| 187 | String8 overlayPath = String8(AssetManager::OVERLAY_DIR) + "/" + subdir; |
| 188 | if (stat(overlayPath.string(), &st) == 0) { |
| 189 | argv[argc++] = overlayPath.string(); |
| 190 | } |
| 191 | } |
| 192 | if (stat(AssetManager::OVERLAY_DIR, &st) == 0) { |
| 193 | argv[argc++] = AssetManager::OVERLAY_DIR; |
| 194 | } |
| 195 | |
| 196 | // Finally, invoke idmap (if any overlay directory exists) |
| 197 | if (argc > 5) { |
| 198 | execv(AssetManager::IDMAP_BIN, (char* const*)argv); |
| 199 | ALOGE("failed to execv for idmap: %s", strerror(errno)); |
| 200 | exit(1); // should never get here |
| 201 | } else { |
| 202 | exit(0); |
| 203 | } |
| 204 | } |
| 205 | break; |
| 206 | default: // parent |
| 207 | waitpid(pid, NULL, 0); |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | // ---------------------------------------------------------------------------- |
| 213 | |
| 214 | // this guy is exported to other jni routines |
| 215 | AssetManager* assetManagerForJavaObject(JNIEnv* env, jobject obj) |
| 216 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 217 | jlong amHandle = env->GetLongField(obj, gAssetManagerOffsets.mObject); |
| 218 | AssetManager* am = reinterpret_cast<AssetManager*>(amHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | if (am != NULL) { |
| 220 | return am; |
| 221 | } |
| 222 | jniThrowException(env, "java/lang/IllegalStateException", "AssetManager has been finalized!"); |
| 223 | return NULL; |
| 224 | } |
| 225 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 226 | static jlong android_content_AssetManager_openAsset(JNIEnv* env, jobject clazz, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | jstring fileName, jint mode) |
| 228 | { |
| 229 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 230 | if (am == NULL) { |
| 231 | return 0; |
| 232 | } |
| 233 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 234 | ALOGV("openAsset in %p (Java object %p)\n", am, clazz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 236 | ScopedUtfChars fileName8(env, fileName); |
| 237 | if (fileName8.c_str() == NULL) { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 238 | jniThrowException(env, "java/lang/IllegalArgumentException", "Empty file name"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | return -1; |
| 240 | } |
| 241 | |
| 242 | if (mode != Asset::ACCESS_UNKNOWN && mode != Asset::ACCESS_RANDOM |
| 243 | && mode != Asset::ACCESS_STREAMING && mode != Asset::ACCESS_BUFFER) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 244 | jniThrowException(env, "java/lang/IllegalArgumentException", "Bad access mode"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | return -1; |
| 246 | } |
| 247 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 248 | Asset* a = am->open(fileName8.c_str(), (Asset::AccessMode)mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | |
| 250 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 251 | jniThrowException(env, "java/io/FileNotFoundException", fileName8.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | return -1; |
| 253 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | |
| 255 | //printf("Created Asset Stream: %p\n", a); |
| 256 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 257 | return reinterpret_cast<jlong>(a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static jobject returnParcelFileDescriptor(JNIEnv* env, Asset* a, jlongArray outOffsets) |
| 261 | { |
Kenny Root | ddb76c4 | 2010-11-24 12:56:06 -0800 | [diff] [blame] | 262 | off64_t startOffset, length; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 263 | int fd = a->openFileDescriptor(&startOffset, &length); |
| 264 | delete a; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 265 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | if (fd < 0) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 267 | jniThrowException(env, "java/io/FileNotFoundException", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | "This file can not be opened as a file descriptor; it is probably compressed"); |
| 269 | return NULL; |
| 270 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | jlong* offsets = (jlong*)env->GetPrimitiveArrayCritical(outOffsets, 0); |
| 273 | if (offsets == NULL) { |
| 274 | close(fd); |
| 275 | return NULL; |
| 276 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | offsets[0] = startOffset; |
| 279 | offsets[1] = length; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | env->ReleasePrimitiveArrayCritical(outOffsets, offsets, 0); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 282 | |
Elliott Hughes | a3804cf | 2011-04-11 16:50:19 -0700 | [diff] [blame] | 283 | jobject fileDesc = jniCreateFileDescriptor(env, fd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | if (fileDesc == NULL) { |
| 285 | close(fd); |
| 286 | return NULL; |
| 287 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 288 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 289 | return newParcelFileDescriptor(env, fileDesc); |
| 290 | } |
| 291 | |
| 292 | static jobject android_content_AssetManager_openAssetFd(JNIEnv* env, jobject clazz, |
| 293 | jstring fileName, jlongArray outOffsets) |
| 294 | { |
| 295 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 296 | if (am == NULL) { |
| 297 | return NULL; |
| 298 | } |
| 299 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 300 | ALOGV("openAssetFd in %p (Java object %p)\n", am, clazz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 302 | ScopedUtfChars fileName8(env, fileName); |
| 303 | if (fileName8.c_str() == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | return NULL; |
| 305 | } |
| 306 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 307 | Asset* a = am->open(fileName8.c_str(), Asset::ACCESS_RANDOM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | |
| 309 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 310 | jniThrowException(env, "java/io/FileNotFoundException", fileName8.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | return NULL; |
| 312 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | |
| 314 | //printf("Created Asset Stream: %p\n", a); |
| 315 | |
| 316 | return returnParcelFileDescriptor(env, a, outOffsets); |
| 317 | } |
| 318 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 319 | static jlong android_content_AssetManager_openNonAssetNative(JNIEnv* env, jobject clazz, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | jint cookie, |
| 321 | jstring fileName, |
| 322 | jint mode) |
| 323 | { |
| 324 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 325 | if (am == NULL) { |
| 326 | return 0; |
| 327 | } |
| 328 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 329 | ALOGV("openNonAssetNative in %p (Java object %p)\n", am, clazz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 331 | ScopedUtfChars fileName8(env, fileName); |
| 332 | if (fileName8.c_str() == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | return -1; |
| 334 | } |
| 335 | |
| 336 | if (mode != Asset::ACCESS_UNKNOWN && mode != Asset::ACCESS_RANDOM |
| 337 | && mode != Asset::ACCESS_STREAMING && mode != Asset::ACCESS_BUFFER) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 338 | jniThrowException(env, "java/lang/IllegalArgumentException", "Bad access mode"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | return -1; |
| 340 | } |
| 341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 342 | Asset* a = cookie |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 343 | ? am->openNonAsset(static_cast<int32_t>(cookie), fileName8.c_str(), |
| 344 | (Asset::AccessMode)mode) |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 345 | : am->openNonAsset(fileName8.c_str(), (Asset::AccessMode)mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | |
| 347 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 348 | jniThrowException(env, "java/io/FileNotFoundException", fileName8.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 349 | return -1; |
| 350 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | |
| 352 | //printf("Created Asset Stream: %p\n", a); |
| 353 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 354 | return reinterpret_cast<jlong>(a); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static jobject android_content_AssetManager_openNonAssetFdNative(JNIEnv* env, jobject clazz, |
| 358 | jint cookie, |
| 359 | jstring fileName, |
| 360 | jlongArray outOffsets) |
| 361 | { |
| 362 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 363 | if (am == NULL) { |
| 364 | return NULL; |
| 365 | } |
| 366 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 367 | ALOGV("openNonAssetFd in %p (Java object %p)\n", am, clazz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 368 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 369 | ScopedUtfChars fileName8(env, fileName); |
| 370 | if (fileName8.c_str() == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | return NULL; |
| 372 | } |
| 373 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | Asset* a = cookie |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 375 | ? am->openNonAsset(static_cast<int32_t>(cookie), fileName8.c_str(), Asset::ACCESS_RANDOM) |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 376 | : am->openNonAsset(fileName8.c_str(), Asset::ACCESS_RANDOM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | |
| 378 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 379 | jniThrowException(env, "java/io/FileNotFoundException", fileName8.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | return NULL; |
| 381 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | |
| 383 | //printf("Created Asset Stream: %p\n", a); |
| 384 | |
| 385 | return returnParcelFileDescriptor(env, a, outOffsets); |
| 386 | } |
| 387 | |
| 388 | static jobjectArray android_content_AssetManager_list(JNIEnv* env, jobject clazz, |
| 389 | jstring fileName) |
| 390 | { |
| 391 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 392 | if (am == NULL) { |
| 393 | return NULL; |
| 394 | } |
| 395 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 396 | ScopedUtfChars fileName8(env, fileName); |
| 397 | if (fileName8.c_str() == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | return NULL; |
| 399 | } |
| 400 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 401 | AssetDir* dir = am->openDir(fileName8.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | |
| 403 | if (dir == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 404 | jniThrowException(env, "java/io/FileNotFoundException", fileName8.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | return NULL; |
| 406 | } |
| 407 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | size_t N = dir->getFileCount(); |
| 409 | |
| 410 | jobjectArray array = env->NewObjectArray(dir->getFileCount(), |
Vladimir Marko | aa5fe3d | 2013-06-17 12:46:22 +0100 | [diff] [blame] | 411 | g_stringClass, NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | if (array == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | delete dir; |
| 414 | return NULL; |
| 415 | } |
| 416 | |
| 417 | for (size_t i=0; i<N; i++) { |
| 418 | const String8& name = dir->getFileName(i); |
| 419 | jstring str = env->NewStringUTF(name.string()); |
| 420 | if (str == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | delete dir; |
| 422 | return NULL; |
| 423 | } |
| 424 | env->SetObjectArrayElement(array, i, str); |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 425 | env->DeleteLocalRef(str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | delete dir; |
| 429 | |
| 430 | return array; |
| 431 | } |
| 432 | |
| 433 | static void android_content_AssetManager_destroyAsset(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 434 | jlong assetHandle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 436 | Asset* a = reinterpret_cast<Asset*>(assetHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 437 | |
| 438 | //printf("Destroying Asset Stream: %p\n", a); |
| 439 | |
| 440 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 441 | jniThrowNullPointerException(env, "asset"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | return; |
| 443 | } |
| 444 | |
| 445 | delete a; |
| 446 | } |
| 447 | |
| 448 | static jint android_content_AssetManager_readAssetChar(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 449 | jlong assetHandle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 451 | Asset* a = reinterpret_cast<Asset*>(assetHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | |
| 453 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 454 | jniThrowNullPointerException(env, "asset"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | return -1; |
| 456 | } |
| 457 | |
| 458 | uint8_t b; |
| 459 | ssize_t res = a->read(&b, 1); |
| 460 | return res == 1 ? b : -1; |
| 461 | } |
| 462 | |
| 463 | static jint android_content_AssetManager_readAsset(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 464 | jlong assetHandle, jbyteArray bArray, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | jint off, jint len) |
| 466 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 467 | Asset* a = reinterpret_cast<Asset*>(assetHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | |
| 469 | if (a == NULL || bArray == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 470 | jniThrowNullPointerException(env, "asset"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | return -1; |
| 472 | } |
| 473 | |
| 474 | if (len == 0) { |
| 475 | return 0; |
| 476 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 477 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 478 | jsize bLen = env->GetArrayLength(bArray); |
| 479 | if (off < 0 || off >= bLen || len < 0 || len > bLen || (off+len) > bLen) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 480 | jniThrowException(env, "java/lang/IndexOutOfBoundsException", ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | return -1; |
| 482 | } |
| 483 | |
| 484 | jbyte* b = env->GetByteArrayElements(bArray, NULL); |
| 485 | ssize_t res = a->read(b+off, len); |
| 486 | env->ReleaseByteArrayElements(bArray, b, 0); |
| 487 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 488 | if (res > 0) return static_cast<jint>(res); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | |
| 490 | if (res < 0) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 491 | jniThrowException(env, "java/io/IOException", ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | } |
| 493 | return -1; |
| 494 | } |
| 495 | |
| 496 | static jlong android_content_AssetManager_seekAsset(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 497 | jlong assetHandle, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | jlong offset, jint whence) |
| 499 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 500 | Asset* a = reinterpret_cast<Asset*>(assetHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | |
| 502 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 503 | jniThrowNullPointerException(env, "asset"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | return -1; |
| 505 | } |
| 506 | |
| 507 | return a->seek( |
| 508 | offset, (whence > 0) ? SEEK_END : (whence < 0 ? SEEK_SET : SEEK_CUR)); |
| 509 | } |
| 510 | |
| 511 | static jlong android_content_AssetManager_getAssetLength(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 512 | jlong assetHandle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 514 | Asset* a = reinterpret_cast<Asset*>(assetHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | |
| 516 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 517 | jniThrowNullPointerException(env, "asset"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | return -1; |
| 519 | } |
| 520 | |
| 521 | return a->getLength(); |
| 522 | } |
| 523 | |
| 524 | static jlong android_content_AssetManager_getAssetRemainingLength(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 525 | jlong assetHandle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 527 | Asset* a = reinterpret_cast<Asset*>(assetHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | |
| 529 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 530 | jniThrowNullPointerException(env, "asset"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | return -1; |
| 532 | } |
| 533 | |
| 534 | return a->getRemainingLength(); |
| 535 | } |
| 536 | |
| 537 | static jint android_content_AssetManager_addAssetPath(JNIEnv* env, jobject clazz, |
Tao Bai | a6d7e3f | 2015-09-01 18:49:54 -0700 | [diff] [blame] | 538 | jstring path, jboolean appAsLib) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 540 | ScopedUtfChars path8(env, path); |
| 541 | if (path8.c_str() == NULL) { |
Glenn Kasten | 129e19c | 2012-01-10 17:57:36 -0800 | [diff] [blame] | 542 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 546 | if (am == NULL) { |
Glenn Kasten | 129e19c | 2012-01-10 17:57:36 -0800 | [diff] [blame] | 547 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 550 | int32_t cookie; |
Tao Bai | a6d7e3f | 2015-09-01 18:49:54 -0700 | [diff] [blame] | 551 | bool res = am->addAssetPath(String8(path8.c_str()), &cookie, appAsLib); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 552 | |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 553 | return (res) ? static_cast<jint>(cookie) : 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 556 | static jint android_content_AssetManager_addOverlayPath(JNIEnv* env, jobject clazz, |
| 557 | jstring idmapPath) |
| 558 | { |
| 559 | ScopedUtfChars idmapPath8(env, idmapPath); |
| 560 | if (idmapPath8.c_str() == NULL) { |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 565 | if (am == NULL) { |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | int32_t cookie; |
| 570 | bool res = am->addOverlayPath(String8(idmapPath8.c_str()), &cookie); |
| 571 | |
| 572 | return (res) ? (jint)cookie : 0; |
| 573 | } |
| 574 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 575 | static jboolean android_content_AssetManager_isUpToDate(JNIEnv* env, jobject clazz) |
| 576 | { |
| 577 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 578 | if (am == NULL) { |
| 579 | return JNI_TRUE; |
| 580 | } |
| 581 | return am->isUpToDate() ? JNI_TRUE : JNI_FALSE; |
| 582 | } |
| 583 | |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 584 | static jobjectArray getLocales(JNIEnv* env, jobject clazz, bool includeSystemLocales) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | { |
| 586 | Vector<String8> locales; |
| 587 | |
| 588 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 589 | if (am == NULL) { |
| 590 | return NULL; |
| 591 | } |
| 592 | |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 593 | am->getLocales(&locales, includeSystemLocales); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | |
| 595 | const int N = locales.size(); |
| 596 | |
| 597 | jobjectArray result = env->NewObjectArray(N, g_stringClass, NULL); |
| 598 | if (result == NULL) { |
| 599 | return NULL; |
| 600 | } |
| 601 | |
| 602 | for (int i=0; i<N; i++) { |
Gilles Debunne | 0db187a | 2010-08-27 11:51:34 -0700 | [diff] [blame] | 603 | jstring str = env->NewStringUTF(locales[i].string()); |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 604 | if (str == NULL) { |
| 605 | return NULL; |
| 606 | } |
| 607 | env->SetObjectArrayElement(result, i, str); |
| 608 | env->DeleteLocalRef(str); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | return result; |
| 612 | } |
| 613 | |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 614 | static jobjectArray android_content_AssetManager_getLocales(JNIEnv* env, jobject clazz) |
| 615 | { |
| 616 | return getLocales(env, clazz, true /* include system locales */); |
| 617 | } |
| 618 | |
| 619 | static jobjectArray android_content_AssetManager_getNonSystemLocales(JNIEnv* env, jobject clazz) |
| 620 | { |
| 621 | return getLocales(env, clazz, false /* don't include system locales */); |
| 622 | } |
| 623 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 624 | static jobject constructConfigurationObject(JNIEnv* env, const ResTable_config& config) { |
| 625 | jobject result = env->NewObject(gConfigurationOffsets.classObject, |
| 626 | gConfigurationOffsets.constructor); |
| 627 | if (result == NULL) { |
| 628 | return NULL; |
| 629 | } |
| 630 | |
| 631 | env->SetIntField(result, gConfigurationOffsets.mSmallestScreenWidthDpOffset, |
| 632 | config.smallestScreenWidthDp); |
| 633 | env->SetIntField(result, gConfigurationOffsets.mScreenWidthDpOffset, config.screenWidthDp); |
| 634 | env->SetIntField(result, gConfigurationOffsets.mScreenHeightDpOffset, config.screenHeightDp); |
| 635 | |
| 636 | return result; |
| 637 | } |
| 638 | |
| 639 | static jobjectArray getSizeConfigurationsInternal(JNIEnv* env, |
| 640 | const Vector<ResTable_config>& configs) { |
| 641 | const int N = configs.size(); |
| 642 | jobjectArray result = env->NewObjectArray(N, gConfigurationOffsets.classObject, NULL); |
| 643 | if (result == NULL) { |
| 644 | return NULL; |
| 645 | } |
| 646 | |
| 647 | for (int i=0; i<N; i++) { |
| 648 | jobject config = constructConfigurationObject(env, configs[i]); |
| 649 | if (config == NULL) { |
| 650 | env->DeleteLocalRef(result); |
| 651 | return NULL; |
| 652 | } |
| 653 | |
| 654 | env->SetObjectArrayElement(result, i, config); |
| 655 | env->DeleteLocalRef(config); |
| 656 | } |
| 657 | |
| 658 | return result; |
| 659 | } |
| 660 | |
| 661 | static jobjectArray android_content_AssetManager_getSizeConfigurations(JNIEnv* env, jobject clazz) { |
| 662 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 663 | if (am == NULL) { |
| 664 | return NULL; |
| 665 | } |
| 666 | |
| 667 | const ResTable& res(am->getResources()); |
| 668 | Vector<ResTable_config> configs; |
| 669 | res.getConfigurations(&configs, false /* ignoreMipmap */, true /* ignoreAndroidPackage */); |
| 670 | |
| 671 | return getSizeConfigurationsInternal(env, configs); |
| 672 | } |
| 673 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | static void android_content_AssetManager_setConfiguration(JNIEnv* env, jobject clazz, |
| 675 | jint mcc, jint mnc, |
| 676 | jstring locale, jint orientation, |
| 677 | jint touchscreen, jint density, |
| 678 | jint keyboard, jint keyboardHidden, |
| 679 | jint navigation, |
| 680 | jint screenWidth, jint screenHeight, |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 681 | jint smallestScreenWidthDp, |
Dianne Hackborn | 3fc982f | 2011-03-30 16:20:26 -0700 | [diff] [blame] | 682 | jint screenWidthDp, jint screenHeightDp, |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 683 | jint screenLayout, jint uiMode, |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 684 | jint colorMode, jint sdkVersion) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | { |
| 686 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 687 | if (am == NULL) { |
| 688 | return; |
| 689 | } |
| 690 | |
| 691 | ResTable_config config; |
| 692 | memset(&config, 0, sizeof(config)); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 693 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 694 | const char* locale8 = locale != NULL ? env->GetStringUTFChars(locale, NULL) : NULL; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 695 | |
Adam Lesinski | 2738c96 | 2015-05-14 14:25:36 -0700 | [diff] [blame] | 696 | // Constants duplicated from Java class android.content.res.Configuration. |
| 697 | static const jint kScreenLayoutRoundMask = 0x300; |
| 698 | static const jint kScreenLayoutRoundShift = 8; |
| 699 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | config.mcc = (uint16_t)mcc; |
| 701 | config.mnc = (uint16_t)mnc; |
| 702 | config.orientation = (uint8_t)orientation; |
| 703 | config.touchscreen = (uint8_t)touchscreen; |
| 704 | config.density = (uint16_t)density; |
| 705 | config.keyboard = (uint8_t)keyboard; |
Dianne Hackborn | c4db95c | 2009-07-21 17:46:02 -0700 | [diff] [blame] | 706 | config.inputFlags = (uint8_t)keyboardHidden; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 707 | config.navigation = (uint8_t)navigation; |
| 708 | config.screenWidth = (uint16_t)screenWidth; |
| 709 | config.screenHeight = (uint16_t)screenHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 710 | config.smallestScreenWidthDp = (uint16_t)smallestScreenWidthDp; |
Dianne Hackborn | 3fc982f | 2011-03-30 16:20:26 -0700 | [diff] [blame] | 711 | config.screenWidthDp = (uint16_t)screenWidthDp; |
| 712 | config.screenHeightDp = (uint16_t)screenHeightDp; |
Dianne Hackborn | 723738c | 2009-06-25 19:48:04 -0700 | [diff] [blame] | 713 | config.screenLayout = (uint8_t)screenLayout; |
Tobias Haamel | 27b28b3 | 2010-02-09 23:09:17 +0100 | [diff] [blame] | 714 | config.uiMode = (uint8_t)uiMode; |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 715 | config.colorMode = (uint8_t)colorMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 716 | config.sdkVersion = (uint16_t)sdkVersion; |
| 717 | config.minorVersion = 0; |
Adam Lesinski | 2738c96 | 2015-05-14 14:25:36 -0700 | [diff] [blame] | 718 | |
| 719 | // In Java, we use a 32bit integer for screenLayout, while we only use an 8bit integer |
| 720 | // in C++. We must extract the round qualifier out of the Java screenLayout and put it |
| 721 | // into screenLayout2. |
| 722 | config.screenLayout2 = |
| 723 | (uint8_t)((screenLayout & kScreenLayoutRoundMask) >> kScreenLayoutRoundShift); |
| 724 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 725 | am->setConfiguration(config, locale8); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 726 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 727 | if (locale != NULL) env->ReleaseStringUTFChars(locale, locale8); |
| 728 | } |
| 729 | |
| 730 | static jint android_content_AssetManager_getResourceIdentifier(JNIEnv* env, jobject clazz, |
| 731 | jstring name, |
| 732 | jstring defType, |
| 733 | jstring defPackage) |
| 734 | { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 735 | ScopedStringChars name16(env, name); |
| 736 | if (name16.get() == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 741 | if (am == NULL) { |
| 742 | return 0; |
| 743 | } |
| 744 | |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 745 | const char16_t* defType16 = reinterpret_cast<const char16_t*>(defType) |
| 746 | ? reinterpret_cast<const char16_t*>(env->GetStringChars(defType, NULL)) |
| 747 | : NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | jsize defTypeLen = defType |
| 749 | ? env->GetStringLength(defType) : 0; |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 750 | const char16_t* defPackage16 = reinterpret_cast<const char16_t*>(defPackage) |
| 751 | ? reinterpret_cast<const char16_t*>(env->GetStringChars(defPackage, |
| 752 | NULL)) |
| 753 | : NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 754 | jsize defPackageLen = defPackage |
| 755 | ? env->GetStringLength(defPackage) : 0; |
| 756 | |
| 757 | jint ident = am->getResources().identifierForName( |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 758 | reinterpret_cast<const char16_t*>(name16.get()), name16.size(), |
| 759 | defType16, defTypeLen, defPackage16, defPackageLen); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | |
| 761 | if (defPackage16) { |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 762 | env->ReleaseStringChars(defPackage, |
| 763 | reinterpret_cast<const jchar*>(defPackage16)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | } |
| 765 | if (defType16) { |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 766 | env->ReleaseStringChars(defType, |
| 767 | reinterpret_cast<const jchar*>(defType16)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | |
| 770 | return ident; |
| 771 | } |
| 772 | |
| 773 | static jstring android_content_AssetManager_getResourceName(JNIEnv* env, jobject clazz, |
| 774 | jint resid) |
| 775 | { |
| 776 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 777 | if (am == NULL) { |
| 778 | return NULL; |
| 779 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 780 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 781 | ResTable::resource_name name; |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 782 | if (!am->getResources().getResourceName(resid, true, &name)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 783 | return NULL; |
| 784 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 785 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | String16 str; |
| 787 | if (name.package != NULL) { |
| 788 | str.setTo(name.package, name.packageLen); |
| 789 | } |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 790 | if (name.type8 != NULL || name.type != NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 791 | if (str.size() > 0) { |
| 792 | char16_t div = ':'; |
| 793 | str.append(&div, 1); |
| 794 | } |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 795 | if (name.type8 != NULL) { |
| 796 | str.append(String16(name.type8, name.typeLen)); |
| 797 | } else { |
| 798 | str.append(name.type, name.typeLen); |
| 799 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | } |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 801 | if (name.name8 != NULL || name.name != NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | if (str.size() > 0) { |
| 803 | char16_t div = '/'; |
| 804 | str.append(&div, 1); |
| 805 | } |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 806 | if (name.name8 != NULL) { |
| 807 | str.append(String16(name.name8, name.nameLen)); |
| 808 | } else { |
| 809 | str.append(name.name, name.nameLen); |
| 810 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 812 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | return env->NewString((const jchar*)str.string(), str.size()); |
| 814 | } |
| 815 | |
| 816 | static jstring android_content_AssetManager_getResourcePackageName(JNIEnv* env, jobject clazz, |
| 817 | jint resid) |
| 818 | { |
| 819 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 820 | if (am == NULL) { |
| 821 | return NULL; |
| 822 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 823 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 824 | ResTable::resource_name name; |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 825 | if (!am->getResources().getResourceName(resid, true, &name)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | return NULL; |
| 827 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 828 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 829 | if (name.package != NULL) { |
| 830 | return env->NewString((const jchar*)name.package, name.packageLen); |
| 831 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 832 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | return NULL; |
| 834 | } |
| 835 | |
| 836 | static jstring android_content_AssetManager_getResourceTypeName(JNIEnv* env, jobject clazz, |
| 837 | jint resid) |
| 838 | { |
| 839 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 840 | if (am == NULL) { |
| 841 | return NULL; |
| 842 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 843 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | ResTable::resource_name name; |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 845 | if (!am->getResources().getResourceName(resid, true, &name)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | return NULL; |
| 847 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 848 | |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 849 | if (name.type8 != NULL) { |
| 850 | return env->NewStringUTF(name.type8); |
| 851 | } |
| 852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | if (name.type != NULL) { |
| 854 | return env->NewString((const jchar*)name.type, name.typeLen); |
| 855 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 856 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | return NULL; |
| 858 | } |
| 859 | |
| 860 | static jstring android_content_AssetManager_getResourceEntryName(JNIEnv* env, jobject clazz, |
| 861 | jint resid) |
| 862 | { |
| 863 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 864 | if (am == NULL) { |
| 865 | return NULL; |
| 866 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 868 | ResTable::resource_name name; |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 869 | if (!am->getResources().getResourceName(resid, true, &name)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | return NULL; |
| 871 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 872 | |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 873 | if (name.name8 != NULL) { |
| 874 | return env->NewStringUTF(name.name8); |
| 875 | } |
| 876 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | if (name.name != NULL) { |
| 878 | return env->NewString((const jchar*)name.name, name.nameLen); |
| 879 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 880 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 881 | return NULL; |
| 882 | } |
| 883 | |
| 884 | static jint android_content_AssetManager_loadResourceValue(JNIEnv* env, jobject clazz, |
| 885 | jint ident, |
Kenny Root | 55fc850 | 2010-10-28 14:47:01 -0700 | [diff] [blame] | 886 | jshort density, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 887 | jobject outValue, |
| 888 | jboolean resolve) |
| 889 | { |
Dianne Hackborn | 1f7d307 | 2013-02-11 17:03:32 -0800 | [diff] [blame] | 890 | if (outValue == NULL) { |
Dianne Hackborn | e5b50a6 | 2013-02-11 16:18:42 -0800 | [diff] [blame] | 891 | jniThrowNullPointerException(env, "outValue"); |
Dianne Hackborn | d45c68d | 2013-07-31 12:14:24 -0700 | [diff] [blame] | 892 | return 0; |
Dianne Hackborn | e5b50a6 | 2013-02-11 16:18:42 -0800 | [diff] [blame] | 893 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 895 | if (am == NULL) { |
| 896 | return 0; |
| 897 | } |
| 898 | const ResTable& res(am->getResources()); |
| 899 | |
| 900 | Res_value value; |
| 901 | ResTable_config config; |
| 902 | uint32_t typeSpecFlags; |
Kenny Root | 55fc850 | 2010-10-28 14:47:01 -0700 | [diff] [blame] | 903 | ssize_t block = res.getResource(ident, &value, false, density, &typeSpecFlags, &config); |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 904 | if (kThrowOnBadId) { |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 905 | if (block == BAD_INDEX) { |
| 906 | jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); |
| 907 | return 0; |
| 908 | } |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 909 | } |
| 910 | uint32_t ref = ident; |
| 911 | if (resolve) { |
| 912 | block = res.resolveReference(&value, block, &ref, &typeSpecFlags, &config); |
| 913 | if (kThrowOnBadId) { |
| 914 | if (block == BAD_INDEX) { |
| 915 | jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); |
| 916 | return 0; |
| 917 | } |
| 918 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | } |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 920 | if (block >= 0) { |
| 921 | return copyValue(env, outValue, &res, value, ref, block, typeSpecFlags, &config); |
| 922 | } |
| 923 | |
| 924 | return static_cast<jint>(block); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | static jint android_content_AssetManager_loadResourceBagValue(JNIEnv* env, jobject clazz, |
| 928 | jint ident, jint bagEntryId, |
| 929 | jobject outValue, jboolean resolve) |
| 930 | { |
| 931 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 932 | if (am == NULL) { |
| 933 | return 0; |
| 934 | } |
| 935 | const ResTable& res(am->getResources()); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 936 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | // Now lock down the resource object and start pulling stuff from it. |
| 938 | res.lock(); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | ssize_t block = -1; |
| 941 | Res_value value; |
| 942 | |
| 943 | const ResTable::bag_entry* entry = NULL; |
| 944 | uint32_t typeSpecFlags; |
| 945 | ssize_t entryCount = res.getBagLocked(ident, &entry, &typeSpecFlags); |
| 946 | |
| 947 | for (ssize_t i=0; i<entryCount; i++) { |
| 948 | if (((uint32_t)bagEntryId) == entry->map.name.ident) { |
| 949 | block = entry->stringBlock; |
| 950 | value = entry->map.value; |
| 951 | } |
| 952 | entry++; |
| 953 | } |
| 954 | |
| 955 | res.unlock(); |
| 956 | |
| 957 | if (block < 0) { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 958 | return static_cast<jint>(block); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | uint32_t ref = ident; |
| 962 | if (resolve) { |
| 963 | block = res.resolveReference(&value, block, &ref, &typeSpecFlags); |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 964 | if (kThrowOnBadId) { |
| 965 | if (block == BAD_INDEX) { |
| 966 | jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); |
| 967 | return 0; |
| 968 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 969 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | } |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 971 | if (block >= 0) { |
| 972 | return copyValue(env, outValue, &res, value, ref, block, typeSpecFlags); |
| 973 | } |
| 974 | |
| 975 | return static_cast<jint>(block); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | static jint android_content_AssetManager_getStringBlockCount(JNIEnv* env, jobject clazz) |
| 979 | { |
| 980 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 981 | if (am == NULL) { |
| 982 | return 0; |
| 983 | } |
| 984 | return am->getResources().getTableCount(); |
| 985 | } |
| 986 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 987 | static jlong android_content_AssetManager_getNativeStringBlock(JNIEnv* env, jobject clazz, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | jint block) |
| 989 | { |
| 990 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 991 | if (am == NULL) { |
| 992 | return 0; |
| 993 | } |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 994 | return reinterpret_cast<jlong>(am->getResources().getTableStringBlock(block)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | static jstring android_content_AssetManager_getCookieName(JNIEnv* env, jobject clazz, |
| 998 | jint cookie) |
| 999 | { |
| 1000 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1001 | if (am == NULL) { |
| 1002 | return NULL; |
| 1003 | } |
Narayan Kamath | 745d4ef | 2014-01-27 11:17:22 +0000 | [diff] [blame] | 1004 | String8 name(am->getAssetPath(static_cast<int32_t>(cookie))); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1005 | if (name.length() == 0) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1006 | jniThrowException(env, "java/lang/IndexOutOfBoundsException", "Empty cookie name"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | return NULL; |
| 1008 | } |
| 1009 | jstring str = env->NewStringUTF(name.string()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | return str; |
| 1011 | } |
| 1012 | |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1013 | static jobject android_content_AssetManager_getAssignedPackageIdentifiers(JNIEnv* env, jobject clazz) |
| 1014 | { |
| 1015 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1016 | if (am == NULL) { |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | const ResTable& res = am->getResources(); |
| 1021 | |
| 1022 | jobject sparseArray = env->NewObject(gSparseArrayOffsets.classObject, |
| 1023 | gSparseArrayOffsets.constructor); |
| 1024 | const size_t N = res.getBasePackageCount(); |
| 1025 | for (size_t i = 0; i < N; i++) { |
| 1026 | const String16 name = res.getBasePackageName(i); |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 1027 | env->CallVoidMethod( |
| 1028 | sparseArray, gSparseArrayOffsets.put, |
| 1029 | static_cast<jint>(res.getBasePackageId(i)), |
| 1030 | env->NewString(reinterpret_cast<const jchar*>(name.string()), |
| 1031 | name.size())); |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1032 | } |
| 1033 | return sparseArray; |
| 1034 | } |
| 1035 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1036 | static jlong android_content_AssetManager_newTheme(JNIEnv* env, jobject clazz) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | { |
| 1038 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1039 | if (am == NULL) { |
| 1040 | return 0; |
| 1041 | } |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1042 | return reinterpret_cast<jlong>(new ResTable::Theme(am->getResources())); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | static void android_content_AssetManager_deleteTheme(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1046 | jlong themeHandle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1048 | ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | delete theme; |
| 1050 | } |
| 1051 | |
| 1052 | static void android_content_AssetManager_applyThemeStyle(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1053 | jlong themeHandle, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | jint styleRes, |
| 1055 | jboolean force) |
| 1056 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1057 | ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | theme->applyStyle(styleRes, force ? true : false); |
| 1059 | } |
| 1060 | |
| 1061 | static void android_content_AssetManager_copyTheme(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1062 | jlong destHandle, jlong srcHandle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1063 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1064 | ResTable::Theme* dest = reinterpret_cast<ResTable::Theme*>(destHandle); |
| 1065 | ResTable::Theme* src = reinterpret_cast<ResTable::Theme*>(srcHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1066 | dest->setTo(*src); |
| 1067 | } |
| 1068 | |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 1069 | static void android_content_AssetManager_clearTheme(JNIEnv* env, jobject clazz, jlong themeHandle) |
| 1070 | { |
| 1071 | ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); |
| 1072 | theme->clear(); |
| 1073 | } |
| 1074 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1075 | static jint android_content_AssetManager_loadThemeAttributeValue( |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1076 | JNIEnv* env, jobject clazz, jlong themeHandle, jint ident, jobject outValue, jboolean resolve) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1078 | ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1079 | const ResTable& res(theme->getResTable()); |
| 1080 | |
| 1081 | Res_value value; |
| 1082 | // XXX value could be different in different configs! |
| 1083 | uint32_t typeSpecFlags = 0; |
| 1084 | ssize_t block = theme->getAttribute(ident, &value, &typeSpecFlags); |
| 1085 | uint32_t ref = 0; |
| 1086 | if (resolve) { |
| 1087 | block = res.resolveReference(&value, block, &ref, &typeSpecFlags); |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 1088 | if (kThrowOnBadId) { |
| 1089 | if (block == BAD_INDEX) { |
| 1090 | jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); |
| 1091 | return 0; |
| 1092 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1093 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1094 | } |
| 1095 | return block >= 0 ? copyValue(env, outValue, &res, value, ref, block, typeSpecFlags) : block; |
| 1096 | } |
| 1097 | |
Alan Viverette | c1d5279 | 2015-05-05 09:49:03 -0700 | [diff] [blame] | 1098 | static jint android_content_AssetManager_getThemeChangingConfigurations(JNIEnv* env, jobject clazz, |
| 1099 | jlong themeHandle) |
| 1100 | { |
| 1101 | ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); |
| 1102 | return theme->getChangingConfigurations(); |
| 1103 | } |
| 1104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | static void android_content_AssetManager_dumpTheme(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1106 | jlong themeHandle, jint pri, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | jstring tag, jstring prefix) |
| 1108 | { |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1109 | ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | const ResTable& res(theme->getResTable()); |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 1111 | (void)res; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1112 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | // XXX Need to use params. |
| 1114 | theme->dumpToLog(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | } |
| 1116 | |
Alan Viverette | 52b999f | 2014-03-24 18:00:26 -0700 | [diff] [blame] | 1117 | static jboolean android_content_AssetManager_resolveAttrs(JNIEnv* env, jobject clazz, |
| 1118 | jlong themeToken, |
| 1119 | jint defStyleAttr, |
| 1120 | jint defStyleRes, |
| 1121 | jintArray inValues, |
| 1122 | jintArray attrs, |
| 1123 | jintArray outValues, |
| 1124 | jintArray outIndices) |
| 1125 | { |
| 1126 | if (themeToken == 0) { |
| 1127 | jniThrowNullPointerException(env, "theme token"); |
| 1128 | return JNI_FALSE; |
| 1129 | } |
| 1130 | if (attrs == NULL) { |
| 1131 | jniThrowNullPointerException(env, "attrs"); |
| 1132 | return JNI_FALSE; |
| 1133 | } |
| 1134 | if (outValues == NULL) { |
| 1135 | jniThrowNullPointerException(env, "out values"); |
| 1136 | return JNI_FALSE; |
| 1137 | } |
| 1138 | |
Alan Viverette | 52b999f | 2014-03-24 18:00:26 -0700 | [diff] [blame] | 1139 | const jsize NI = env->GetArrayLength(attrs); |
| 1140 | const jsize NV = env->GetArrayLength(outValues); |
| 1141 | if (NV < (NI*STYLE_NUM_ENTRIES)) { |
| 1142 | jniThrowException(env, "java/lang/IndexOutOfBoundsException", "out values too small"); |
| 1143 | return JNI_FALSE; |
| 1144 | } |
| 1145 | |
| 1146 | jint* src = (jint*)env->GetPrimitiveArrayCritical(attrs, 0); |
| 1147 | if (src == NULL) { |
| 1148 | return JNI_FALSE; |
| 1149 | } |
| 1150 | |
| 1151 | jint* srcValues = (jint*)env->GetPrimitiveArrayCritical(inValues, 0); |
| 1152 | const jsize NSV = srcValues == NULL ? 0 : env->GetArrayLength(inValues); |
| 1153 | |
| 1154 | jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0); |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 1155 | if (baseDest == NULL) { |
Alan Viverette | 52b999f | 2014-03-24 18:00:26 -0700 | [diff] [blame] | 1156 | env->ReleasePrimitiveArrayCritical(attrs, src, 0); |
| 1157 | return JNI_FALSE; |
| 1158 | } |
| 1159 | |
| 1160 | jint* indices = NULL; |
Alan Viverette | 52b999f | 2014-03-24 18:00:26 -0700 | [diff] [blame] | 1161 | if (outIndices != NULL) { |
| 1162 | if (env->GetArrayLength(outIndices) > NI) { |
| 1163 | indices = (jint*)env->GetPrimitiveArrayCritical(outIndices, 0); |
| 1164 | } |
| 1165 | } |
| 1166 | |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 1167 | ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken); |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 1168 | bool result = ResolveAttrs(theme, defStyleAttr, defStyleRes, |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 1169 | (uint32_t*) srcValues, NSV, |
| 1170 | (uint32_t*) src, NI, |
| 1171 | (uint32_t*) baseDest, |
| 1172 | (uint32_t*) indices); |
Alan Viverette | 52b999f | 2014-03-24 18:00:26 -0700 | [diff] [blame] | 1173 | |
| 1174 | if (indices != NULL) { |
Alan Viverette | 52b999f | 2014-03-24 18:00:26 -0700 | [diff] [blame] | 1175 | env->ReleasePrimitiveArrayCritical(outIndices, indices, 0); |
| 1176 | } |
| 1177 | env->ReleasePrimitiveArrayCritical(outValues, baseDest, 0); |
| 1178 | env->ReleasePrimitiveArrayCritical(inValues, srcValues, 0); |
| 1179 | env->ReleasePrimitiveArrayCritical(attrs, src, 0); |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 1180 | return result ? JNI_TRUE : JNI_FALSE; |
Alan Viverette | 52b999f | 2014-03-24 18:00:26 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
John Reck | f32adf4 | 2016-11-23 10:39:40 -0800 | [diff] [blame] | 1183 | static void android_content_AssetManager_applyStyle(JNIEnv* env, jobject, jlong themeToken, |
| 1184 | jint defStyleAttr, jint defStyleRes, jlong xmlParserToken, jintArray attrsObj, jint length, |
| 1185 | jlong outValuesAddress, jlong outIndicesAddress) { |
| 1186 | jint* attrs = env->GetIntArrayElements(attrsObj, 0); |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 1187 | ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken); |
| 1188 | ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken); |
John Reck | f32adf4 | 2016-11-23 10:39:40 -0800 | [diff] [blame] | 1189 | uint32_t* outValues = reinterpret_cast<uint32_t*>(static_cast<uintptr_t>(outValuesAddress)); |
| 1190 | uint32_t* outIndices = reinterpret_cast<uint32_t*>(static_cast<uintptr_t>(outIndicesAddress)); |
| 1191 | ApplyStyle(theme, xmlParser, defStyleAttr, defStyleRes, |
| 1192 | reinterpret_cast<const uint32_t*>(attrs), length, outValues, outIndices); |
| 1193 | env->ReleaseIntArrayElements(attrsObj, attrs, JNI_ABORT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, jobject clazz, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1197 | jlong xmlParserToken, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1198 | jintArray attrs, |
| 1199 | jintArray outValues, |
| 1200 | jintArray outIndices) |
| 1201 | { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1202 | if (xmlParserToken == 0) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1203 | jniThrowNullPointerException(env, "xmlParserToken"); |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1204 | return JNI_FALSE; |
| 1205 | } |
| 1206 | if (attrs == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1207 | jniThrowNullPointerException(env, "attrs"); |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1208 | return JNI_FALSE; |
| 1209 | } |
| 1210 | if (outValues == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1211 | jniThrowNullPointerException(env, "out values"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | return JNI_FALSE; |
| 1213 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1216 | if (am == NULL) { |
| 1217 | return JNI_FALSE; |
| 1218 | } |
| 1219 | const ResTable& res(am->getResources()); |
| 1220 | ResXMLParser* xmlParser = (ResXMLParser*)xmlParserToken; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1221 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1222 | const jsize NI = env->GetArrayLength(attrs); |
| 1223 | const jsize NV = env->GetArrayLength(outValues); |
| 1224 | if (NV < (NI*STYLE_NUM_ENTRIES)) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1225 | jniThrowException(env, "java/lang/IndexOutOfBoundsException", "out values too small"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | return JNI_FALSE; |
| 1227 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1229 | jint* src = (jint*)env->GetPrimitiveArrayCritical(attrs, 0); |
| 1230 | if (src == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | return JNI_FALSE; |
| 1232 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1233 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1234 | jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0); |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 1235 | if (baseDest == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1236 | env->ReleasePrimitiveArrayCritical(attrs, src, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | return JNI_FALSE; |
| 1238 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1239 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | jint* indices = NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | if (outIndices != NULL) { |
| 1242 | if (env->GetArrayLength(outIndices) > NI) { |
| 1243 | indices = (jint*)env->GetPrimitiveArrayCritical(outIndices, 0); |
| 1244 | } |
| 1245 | } |
| 1246 | |
Adam Lesinski | 7a37b74 | 2016-10-12 14:05:55 -0700 | [diff] [blame] | 1247 | bool result = RetrieveAttributes(&res, xmlParser, |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 1248 | (uint32_t*) src, NI, |
| 1249 | (uint32_t*) baseDest, |
| 1250 | (uint32_t*) indices); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | if (indices != NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | env->ReleasePrimitiveArrayCritical(outIndices, indices, 0); |
| 1254 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | env->ReleasePrimitiveArrayCritical(outValues, baseDest, 0); |
| 1256 | env->ReleasePrimitiveArrayCritical(attrs, src, 0); |
Adam Lesinski | 4452e13 | 2016-10-12 07:47:28 -0700 | [diff] [blame] | 1257 | return result ? JNI_TRUE : JNI_FALSE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | static jint android_content_AssetManager_getArraySize(JNIEnv* env, jobject clazz, |
| 1261 | jint id) |
| 1262 | { |
| 1263 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1264 | if (am == NULL) { |
Olivier Bailly | d7c8672 | 2010-11-18 14:43:36 -0800 | [diff] [blame] | 1265 | return 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1266 | } |
| 1267 | const ResTable& res(am->getResources()); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1268 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | res.lock(); |
| 1270 | const ResTable::bag_entry* defStyleEnt = NULL; |
| 1271 | ssize_t bagOff = res.getBagLocked(id, &defStyleEnt); |
| 1272 | res.unlock(); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1273 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1274 | return static_cast<jint>(bagOff); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | static jint android_content_AssetManager_retrieveArray(JNIEnv* env, jobject clazz, |
| 1278 | jint id, |
| 1279 | jintArray outValues) |
| 1280 | { |
| 1281 | if (outValues == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1282 | jniThrowNullPointerException(env, "out values"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | return JNI_FALSE; |
| 1284 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1286 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1287 | if (am == NULL) { |
| 1288 | return JNI_FALSE; |
| 1289 | } |
| 1290 | const ResTable& res(am->getResources()); |
Dianne Hackborn | 0d22101 | 2009-07-29 15:41:19 -0700 | [diff] [blame] | 1291 | ResTable_config config; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1292 | Res_value value; |
| 1293 | ssize_t block; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | const jsize NV = env->GetArrayLength(outValues); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1296 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0); |
| 1298 | jint* dest = baseDest; |
| 1299 | if (dest == NULL) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1300 | jniThrowException(env, "java/lang/OutOfMemoryError", ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1301 | return JNI_FALSE; |
| 1302 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1303 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | // Now lock down the resource object and start pulling stuff from it. |
| 1305 | res.lock(); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | const ResTable::bag_entry* arrayEnt = NULL; |
| 1308 | uint32_t arrayTypeSetFlags = 0; |
| 1309 | ssize_t bagOff = res.getBagLocked(id, &arrayEnt, &arrayTypeSetFlags); |
| 1310 | const ResTable::bag_entry* endArrayEnt = arrayEnt + |
| 1311 | (bagOff >= 0 ? bagOff : 0); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1312 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1313 | int i = 0; |
| 1314 | uint32_t typeSetFlags; |
| 1315 | while (i < NV && arrayEnt < endArrayEnt) { |
| 1316 | block = arrayEnt->stringBlock; |
| 1317 | typeSetFlags = arrayTypeSetFlags; |
Dianne Hackborn | 0d22101 | 2009-07-29 15:41:19 -0700 | [diff] [blame] | 1318 | config.density = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | value = arrayEnt->map.value; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | uint32_t resid = 0; |
| 1322 | if (value.dataType != Res_value::TYPE_NULL) { |
| 1323 | // Take care of resolving the found resource to its final value. |
| 1324 | //printf("Resolving attribute reference\n"); |
Dianne Hackborn | 0d22101 | 2009-07-29 15:41:19 -0700 | [diff] [blame] | 1325 | ssize_t newBlock = res.resolveReference(&value, block, &resid, |
| 1326 | &typeSetFlags, &config); |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 1327 | if (kThrowOnBadId) { |
| 1328 | if (newBlock == BAD_INDEX) { |
| 1329 | jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); |
| 1330 | return JNI_FALSE; |
| 1331 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1332 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | if (newBlock >= 0) block = newBlock; |
| 1334 | } |
| 1335 | |
| 1336 | // Deal with the special @null value -- it turns back to TYPE_NULL. |
| 1337 | if (value.dataType == Res_value::TYPE_REFERENCE && value.data == 0) { |
| 1338 | value.dataType = Res_value::TYPE_NULL; |
Alan Viverette | f296940 | 2014-10-29 17:09:36 -0700 | [diff] [blame] | 1339 | value.data = Res_value::DATA_NULL_UNDEFINED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | //printf("Attribute 0x%08x: final type=0x%x, data=0x%08x\n", curIdent, value.dataType, value.data); |
| 1343 | |
| 1344 | // Write the final value back to Java. |
| 1345 | dest[STYLE_TYPE] = value.dataType; |
| 1346 | dest[STYLE_DATA] = value.data; |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1347 | dest[STYLE_ASSET_COOKIE] = reinterpret_cast<jint>(res.getTableCookie(block)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1348 | dest[STYLE_RESOURCE_ID] = resid; |
| 1349 | dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags; |
Dianne Hackborn | 0d22101 | 2009-07-29 15:41:19 -0700 | [diff] [blame] | 1350 | dest[STYLE_DENSITY] = config.density; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1351 | dest += STYLE_NUM_ENTRIES; |
| 1352 | i+= STYLE_NUM_ENTRIES; |
| 1353 | arrayEnt++; |
| 1354 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1355 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1356 | i /= STYLE_NUM_ENTRIES; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1357 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1358 | res.unlock(); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | env->ReleasePrimitiveArrayCritical(outValues, baseDest, 0); |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1362 | return i; |
| 1363 | } |
| 1364 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1365 | static jlong android_content_AssetManager_openXmlAssetNative(JNIEnv* env, jobject clazz, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | jint cookie, |
| 1367 | jstring fileName) |
| 1368 | { |
| 1369 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1370 | if (am == NULL) { |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1374 | ALOGV("openXmlAsset in %p (Java object %p)\n", am, clazz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1376 | ScopedUtfChars fileName8(env, fileName); |
| 1377 | if (fileName8.c_str() == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1378 | return 0; |
| 1379 | } |
| 1380 | |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1381 | int32_t assetCookie = static_cast<int32_t>(cookie); |
| 1382 | Asset* a = assetCookie |
| 1383 | ? am->openNonAsset(assetCookie, fileName8.c_str(), Asset::ACCESS_BUFFER) |
| 1384 | : am->openNonAsset(fileName8.c_str(), Asset::ACCESS_BUFFER, &assetCookie); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | |
| 1386 | if (a == NULL) { |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1387 | jniThrowException(env, "java/io/FileNotFoundException", fileName8.c_str()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | return 0; |
| 1389 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1390 | |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1391 | const DynamicRefTable* dynamicRefTable = |
| 1392 | am->getResources().getDynamicRefTableForCookie(assetCookie); |
| 1393 | ResXMLTree* block = new ResXMLTree(dynamicRefTable); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | status_t err = block->setTo(a->getBuffer(true), a->getLength(), true); |
| 1395 | a->close(); |
| 1396 | delete a; |
| 1397 | |
| 1398 | if (err != NO_ERROR) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1399 | jniThrowException(env, "java/io/FileNotFoundException", "Corrupt XML binary file"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1400 | return 0; |
| 1401 | } |
| 1402 | |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1403 | return reinterpret_cast<jlong>(block); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | static jintArray android_content_AssetManager_getArrayStringInfo(JNIEnv* env, jobject clazz, |
| 1407 | jint arrayResId) |
| 1408 | { |
| 1409 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1410 | if (am == NULL) { |
| 1411 | return NULL; |
| 1412 | } |
| 1413 | const ResTable& res(am->getResources()); |
| 1414 | |
| 1415 | const ResTable::bag_entry* startOfBag; |
| 1416 | const ssize_t N = res.lockBag(arrayResId, &startOfBag); |
| 1417 | if (N < 0) { |
| 1418 | return NULL; |
| 1419 | } |
| 1420 | |
| 1421 | jintArray array = env->NewIntArray(N * 2); |
| 1422 | if (array == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | res.unlockBag(startOfBag); |
| 1424 | return NULL; |
| 1425 | } |
| 1426 | |
| 1427 | Res_value value; |
| 1428 | const ResTable::bag_entry* bag = startOfBag; |
| 1429 | for (size_t i = 0, j = 0; ((ssize_t)i)<N; i++, bag++) { |
| 1430 | jint stringIndex = -1; |
| 1431 | jint stringBlock = 0; |
| 1432 | value = bag->map.value; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1433 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1434 | // Take care of resolving the found resource to its final value. |
| 1435 | stringBlock = res.resolveReference(&value, bag->stringBlock, NULL); |
| 1436 | if (value.dataType == Res_value::TYPE_STRING) { |
| 1437 | stringIndex = value.data; |
| 1438 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1439 | |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 1440 | if (kThrowOnBadId) { |
| 1441 | if (stringBlock == BAD_INDEX) { |
| 1442 | jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); |
| 1443 | return array; |
| 1444 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1445 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1447 | //todo: It might be faster to allocate a C array to contain |
| 1448 | // the blocknums and indices, put them in there and then |
| 1449 | // do just one SetIntArrayRegion() |
| 1450 | env->SetIntArrayRegion(array, j, 1, &stringBlock); |
| 1451 | env->SetIntArrayRegion(array, j + 1, 1, &stringIndex); |
| 1452 | j = j + 2; |
| 1453 | } |
| 1454 | res.unlockBag(startOfBag); |
| 1455 | return array; |
| 1456 | } |
| 1457 | |
| 1458 | static jobjectArray android_content_AssetManager_getArrayStringResource(JNIEnv* env, jobject clazz, |
| 1459 | jint arrayResId) |
| 1460 | { |
| 1461 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1462 | if (am == NULL) { |
| 1463 | return NULL; |
| 1464 | } |
| 1465 | const ResTable& res(am->getResources()); |
| 1466 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1467 | const ResTable::bag_entry* startOfBag; |
| 1468 | const ssize_t N = res.lockBag(arrayResId, &startOfBag); |
| 1469 | if (N < 0) { |
| 1470 | return NULL; |
| 1471 | } |
| 1472 | |
Vladimir Marko | aa5fe3d | 2013-06-17 12:46:22 +0100 | [diff] [blame] | 1473 | jobjectArray array = env->NewObjectArray(N, g_stringClass, NULL); |
Kenny Root | 485dd21 | 2010-05-06 16:06:48 -0700 | [diff] [blame] | 1474 | if (env->ExceptionCheck()) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1475 | res.unlockBag(startOfBag); |
| 1476 | return NULL; |
| 1477 | } |
| 1478 | |
| 1479 | Res_value value; |
| 1480 | const ResTable::bag_entry* bag = startOfBag; |
| 1481 | size_t strLen = 0; |
| 1482 | for (size_t i=0; ((ssize_t)i)<N; i++, bag++) { |
| 1483 | value = bag->map.value; |
| 1484 | jstring str = NULL; |
Kenny Root | 780d2a1 | 2010-02-22 22:36:26 -0800 | [diff] [blame] | 1485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | // Take care of resolving the found resource to its final value. |
| 1487 | ssize_t block = res.resolveReference(&value, bag->stringBlock, NULL); |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 1488 | if (kThrowOnBadId) { |
| 1489 | if (block == BAD_INDEX) { |
| 1490 | jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); |
| 1491 | return array; |
| 1492 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1493 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | if (value.dataType == Res_value::TYPE_STRING) { |
Kenny Root | 780d2a1 | 2010-02-22 22:36:26 -0800 | [diff] [blame] | 1495 | const ResStringPool* pool = res.getTableStringBlock(block); |
| 1496 | const char* str8 = pool->string8At(value.data, &strLen); |
| 1497 | if (str8 != NULL) { |
| 1498 | str = env->NewStringUTF(str8); |
| 1499 | } else { |
| 1500 | const char16_t* str16 = pool->stringAt(value.data, &strLen); |
Dan Albert | 6698749 | 2014-11-20 11:41:21 -0800 | [diff] [blame] | 1501 | str = env->NewString(reinterpret_cast<const jchar*>(str16), |
| 1502 | strLen); |
Kenny Root | 485dd21 | 2010-05-06 16:06:48 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | // If one of our NewString{UTF} calls failed due to memory, an |
| 1506 | // exception will be pending. |
| 1507 | if (env->ExceptionCheck()) { |
| 1508 | res.unlockBag(startOfBag); |
| 1509 | return NULL; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1510 | } |
Kenny Root | 780d2a1 | 2010-02-22 22:36:26 -0800 | [diff] [blame] | 1511 | |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1512 | env->SetObjectArrayElement(array, i, str); |
Kenny Root | 485dd21 | 2010-05-06 16:06:48 -0700 | [diff] [blame] | 1513 | |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1514 | // str is not NULL at that point, otherwise ExceptionCheck would have been true. |
| 1515 | // If we have a large amount of strings in our array, we might |
| 1516 | // overflow the local reference table of the VM. |
Kenny Root | 485dd21 | 2010-05-06 16:06:48 -0700 | [diff] [blame] | 1517 | env->DeleteLocalRef(str); |
| 1518 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | } |
| 1520 | res.unlockBag(startOfBag); |
| 1521 | return array; |
| 1522 | } |
| 1523 | |
| 1524 | static jintArray android_content_AssetManager_getArrayIntResource(JNIEnv* env, jobject clazz, |
| 1525 | jint arrayResId) |
| 1526 | { |
| 1527 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1528 | if (am == NULL) { |
| 1529 | return NULL; |
| 1530 | } |
| 1531 | const ResTable& res(am->getResources()); |
| 1532 | |
| 1533 | const ResTable::bag_entry* startOfBag; |
| 1534 | const ssize_t N = res.lockBag(arrayResId, &startOfBag); |
| 1535 | if (N < 0) { |
| 1536 | return NULL; |
| 1537 | } |
| 1538 | |
| 1539 | jintArray array = env->NewIntArray(N); |
| 1540 | if (array == NULL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1541 | res.unlockBag(startOfBag); |
| 1542 | return NULL; |
| 1543 | } |
| 1544 | |
| 1545 | Res_value value; |
| 1546 | const ResTable::bag_entry* bag = startOfBag; |
| 1547 | for (size_t i=0; ((ssize_t)i)<N; i++, bag++) { |
| 1548 | value = bag->map.value; |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1549 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1550 | // Take care of resolving the found resource to its final value. |
| 1551 | ssize_t block = res.resolveReference(&value, bag->stringBlock, NULL); |
Andreas Gampe | 0f0b491 | 2014-11-12 08:03:48 -0800 | [diff] [blame] | 1552 | if (kThrowOnBadId) { |
| 1553 | if (block == BAD_INDEX) { |
| 1554 | jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!"); |
| 1555 | return array; |
| 1556 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 1557 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1558 | if (value.dataType >= Res_value::TYPE_FIRST_INT |
| 1559 | && value.dataType <= Res_value::TYPE_LAST_INT) { |
| 1560 | int intVal = value.data; |
| 1561 | env->SetIntArrayRegion(array, i, 1, &intVal); |
| 1562 | } |
| 1563 | } |
| 1564 | res.unlockBag(startOfBag); |
| 1565 | return array; |
| 1566 | } |
| 1567 | |
Jon Miranda | 042ad63 | 2014-09-03 17:57:35 -0700 | [diff] [blame] | 1568 | static jintArray android_content_AssetManager_getStyleAttributes(JNIEnv* env, jobject clazz, |
| 1569 | jint styleId) |
| 1570 | { |
| 1571 | AssetManager* am = assetManagerForJavaObject(env, clazz); |
| 1572 | if (am == NULL) { |
| 1573 | return NULL; |
| 1574 | } |
| 1575 | const ResTable& res(am->getResources()); |
| 1576 | |
| 1577 | const ResTable::bag_entry* startOfBag; |
| 1578 | const ssize_t N = res.lockBag(styleId, &startOfBag); |
| 1579 | if (N < 0) { |
| 1580 | return NULL; |
| 1581 | } |
| 1582 | |
| 1583 | jintArray array = env->NewIntArray(N); |
| 1584 | if (array == NULL) { |
| 1585 | res.unlockBag(startOfBag); |
| 1586 | return NULL; |
| 1587 | } |
| 1588 | |
Jon Miranda | 042ad63 | 2014-09-03 17:57:35 -0700 | [diff] [blame] | 1589 | const ResTable::bag_entry* bag = startOfBag; |
| 1590 | for (size_t i=0; ((ssize_t)i)<N; i++, bag++) { |
| 1591 | int resourceId = bag->map.name.ident; |
| 1592 | env->SetIntArrayRegion(array, i, 1, &resourceId); |
| 1593 | } |
| 1594 | res.unlockBag(startOfBag); |
| 1595 | return array; |
| 1596 | } |
| 1597 | |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 1598 | static void android_content_AssetManager_init(JNIEnv* env, jobject clazz, jboolean isSystem) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | { |
Jaekyun Seok | 7de2f9c | 2017-03-02 12:45:10 +0900 | [diff] [blame] | 1600 | if (isSystem) { |
| 1601 | verifySystemIdmaps(); |
| 1602 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | AssetManager* am = new AssetManager(); |
| 1604 | if (am == NULL) { |
Gilles Debunne | 4d4040b | 2010-08-26 15:59:54 -0700 | [diff] [blame] | 1605 | jniThrowException(env, "java/lang/OutOfMemoryError", ""); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | return; |
| 1607 | } |
| 1608 | |
| 1609 | am->addDefaultAssets(); |
| 1610 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1611 | ALOGV("Created AssetManager %p for Java object %p\n", am, clazz); |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1612 | env->SetLongField(clazz, gAssetManagerOffsets.mObject, reinterpret_cast<jlong>(am)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1613 | } |
| 1614 | |
| 1615 | static void android_content_AssetManager_destroy(JNIEnv* env, jobject clazz) |
| 1616 | { |
| 1617 | AssetManager* am = (AssetManager*) |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1618 | (env->GetLongField(clazz, gAssetManagerOffsets.mObject)); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1619 | ALOGV("Destroying AssetManager %p for Java object %p\n", am, clazz); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1620 | if (am != NULL) { |
| 1621 | delete am; |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1622 | env->SetLongField(clazz, gAssetManagerOffsets.mObject, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | static jint android_content_AssetManager_getGlobalAssetCount(JNIEnv* env, jobject clazz) |
| 1627 | { |
| 1628 | return Asset::getGlobalCount(); |
| 1629 | } |
| 1630 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1631 | static jobject android_content_AssetManager_getAssetAllocations(JNIEnv* env, jobject clazz) |
| 1632 | { |
| 1633 | String8 alloc = Asset::getAssetAllocations(); |
| 1634 | if (alloc.length() <= 0) { |
| 1635 | return NULL; |
| 1636 | } |
Elliott Hughes | 69a017b | 2011-04-08 14:10:28 -0700 | [diff] [blame] | 1637 | |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1638 | jstring str = env->NewStringUTF(alloc.string()); |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1639 | return str; |
| 1640 | } |
| 1641 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1642 | static jint android_content_AssetManager_getGlobalAssetManagerCount(JNIEnv* env, jobject clazz) |
| 1643 | { |
| 1644 | return AssetManager::getGlobalCount(); |
| 1645 | } |
| 1646 | |
| 1647 | // ---------------------------------------------------------------------------- |
| 1648 | |
| 1649 | /* |
| 1650 | * JNI registration. |
| 1651 | */ |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 1652 | static const JNINativeMethod gAssetManagerMethods[] = { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1653 | /* name, signature, funcPtr */ |
| 1654 | |
| 1655 | // Basic asset stuff. |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1656 | { "openAsset", "(Ljava/lang/String;I)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | (void*) android_content_AssetManager_openAsset }, |
| 1658 | { "openAssetFd", "(Ljava/lang/String;[J)Landroid/os/ParcelFileDescriptor;", |
| 1659 | (void*) android_content_AssetManager_openAssetFd }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1660 | { "openNonAssetNative", "(ILjava/lang/String;I)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | (void*) android_content_AssetManager_openNonAssetNative }, |
| 1662 | { "openNonAssetFdNative", "(ILjava/lang/String;[J)Landroid/os/ParcelFileDescriptor;", |
| 1663 | (void*) android_content_AssetManager_openNonAssetFdNative }, |
| 1664 | { "list", "(Ljava/lang/String;)[Ljava/lang/String;", |
| 1665 | (void*) android_content_AssetManager_list }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1666 | { "destroyAsset", "(J)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1667 | (void*) android_content_AssetManager_destroyAsset }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1668 | { "readAssetChar", "(J)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1669 | (void*) android_content_AssetManager_readAssetChar }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1670 | { "readAsset", "(J[BII)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1671 | (void*) android_content_AssetManager_readAsset }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1672 | { "seekAsset", "(JJI)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1673 | (void*) android_content_AssetManager_seekAsset }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1674 | { "getAssetLength", "(J)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | (void*) android_content_AssetManager_getAssetLength }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1676 | { "getAssetRemainingLength", "(J)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | (void*) android_content_AssetManager_getAssetRemainingLength }, |
Tao Bai | a6d7e3f | 2015-09-01 18:49:54 -0700 | [diff] [blame] | 1678 | { "addAssetPathNative", "(Ljava/lang/String;Z)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1679 | (void*) android_content_AssetManager_addAssetPath }, |
Mårten Kongstad | 3011313 | 2014-11-07 10:52:17 +0100 | [diff] [blame] | 1680 | { "addOverlayPathNative", "(Ljava/lang/String;)I", |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 1681 | (void*) android_content_AssetManager_addOverlayPath }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1682 | { "isUpToDate", "()Z", |
| 1683 | (void*) android_content_AssetManager_isUpToDate }, |
| 1684 | |
| 1685 | // Resources. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | { "getLocales", "()[Ljava/lang/String;", |
| 1687 | (void*) android_content_AssetManager_getLocales }, |
Roozbeh Pournader | 1c686f2 | 2015-12-18 14:22:14 -0800 | [diff] [blame] | 1688 | { "getNonSystemLocales", "()[Ljava/lang/String;", |
| 1689 | (void*) android_content_AssetManager_getNonSystemLocales }, |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 1690 | { "getSizeConfigurations", "()[Landroid/content/res/Configuration;", |
| 1691 | (void*) android_content_AssetManager_getSizeConfigurations }, |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 1692 | { "setConfiguration", "(IILjava/lang/String;IIIIIIIIIIIIIII)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1693 | (void*) android_content_AssetManager_setConfiguration }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1694 | { "getResourceIdentifier","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | (void*) android_content_AssetManager_getResourceIdentifier }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1696 | { "getResourceName","(I)Ljava/lang/String;", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1697 | (void*) android_content_AssetManager_getResourceName }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1698 | { "getResourcePackageName","(I)Ljava/lang/String;", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | (void*) android_content_AssetManager_getResourcePackageName }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1700 | { "getResourceTypeName","(I)Ljava/lang/String;", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | (void*) android_content_AssetManager_getResourceTypeName }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1702 | { "getResourceEntryName","(I)Ljava/lang/String;", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1703 | (void*) android_content_AssetManager_getResourceEntryName }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1704 | { "loadResourceValue","(ISLandroid/util/TypedValue;Z)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | (void*) android_content_AssetManager_loadResourceValue }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1706 | { "loadResourceBagValue","(IILandroid/util/TypedValue;Z)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1707 | (void*) android_content_AssetManager_loadResourceBagValue }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1708 | { "getStringBlockCount","()I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1709 | (void*) android_content_AssetManager_getStringBlockCount }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1710 | { "getNativeStringBlock","(I)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | (void*) android_content_AssetManager_getNativeStringBlock }, |
| 1712 | { "getCookieName","(I)Ljava/lang/String;", |
| 1713 | (void*) android_content_AssetManager_getCookieName }, |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1714 | { "getAssignedPackageIdentifiers","()Landroid/util/SparseArray;", |
| 1715 | (void*) android_content_AssetManager_getAssignedPackageIdentifiers }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1716 | |
| 1717 | // Themes. |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1718 | { "newTheme", "()J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1719 | (void*) android_content_AssetManager_newTheme }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1720 | { "deleteTheme", "(J)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1721 | (void*) android_content_AssetManager_deleteTheme }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1722 | { "applyThemeStyle", "(JIZ)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | (void*) android_content_AssetManager_applyThemeStyle }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1724 | { "copyTheme", "(JJ)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1725 | (void*) android_content_AssetManager_copyTheme }, |
Alan Viverette | e54d245 | 2015-05-06 10:41:43 -0700 | [diff] [blame] | 1726 | { "clearTheme", "(J)V", |
| 1727 | (void*) android_content_AssetManager_clearTheme }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1728 | { "loadThemeAttributeValue", "(JILandroid/util/TypedValue;Z)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1729 | (void*) android_content_AssetManager_loadThemeAttributeValue }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1730 | { "getThemeChangingConfigurations", "(J)I", |
Alan Viverette | c1d5279 | 2015-05-05 09:49:03 -0700 | [diff] [blame] | 1731 | (void*) android_content_AssetManager_getThemeChangingConfigurations }, |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1732 | { "dumpTheme", "(JILjava/lang/String;Ljava/lang/String;)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | (void*) android_content_AssetManager_dumpTheme }, |
John Reck | f32adf4 | 2016-11-23 10:39:40 -0800 | [diff] [blame] | 1734 | { "applyStyle","(JIIJ[IIJJ)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | (void*) android_content_AssetManager_applyStyle }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1736 | { "resolveAttrs","(JII[I[I[I[I)Z", |
Alan Viverette | 607bd84 | 2014-09-12 12:36:35 -0700 | [diff] [blame] | 1737 | (void*) android_content_AssetManager_resolveAttrs }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1738 | { "retrieveAttributes","(J[I[I[I)Z", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | (void*) android_content_AssetManager_retrieveAttributes }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1740 | { "getArraySize","(I)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1741 | (void*) android_content_AssetManager_getArraySize }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1742 | { "retrieveArray","(I[I)I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | (void*) android_content_AssetManager_retrieveArray }, |
| 1744 | |
| 1745 | // XML files. |
Ashok Bhat | 896043d | 2014-01-17 16:02:38 +0000 | [diff] [blame] | 1746 | { "openXmlAssetNative", "(ILjava/lang/String;)J", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1747 | (void*) android_content_AssetManager_openXmlAssetNative }, |
| 1748 | |
| 1749 | // Arrays. |
| 1750 | { "getArrayStringResource","(I)[Ljava/lang/String;", |
| 1751 | (void*) android_content_AssetManager_getArrayStringResource }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1752 | { "getArrayStringInfo","(I)[I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | (void*) android_content_AssetManager_getArrayStringInfo }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1754 | { "getArrayIntResource","(I)[I", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1755 | (void*) android_content_AssetManager_getArrayIntResource }, |
John Reck | 3299522 | 2016-10-07 11:02:20 -0700 | [diff] [blame] | 1756 | { "getStyleAttributes","(I)[I", |
Jon Miranda | 042ad63 | 2014-09-03 17:57:35 -0700 | [diff] [blame] | 1757 | (void*) android_content_AssetManager_getStyleAttributes }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1758 | |
| 1759 | // Bookkeeping. |
Mårten Kongstad | 48d2232 | 2014-01-31 14:43:27 +0100 | [diff] [blame] | 1760 | { "init", "(Z)V", |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1761 | (void*) android_content_AssetManager_init }, |
| 1762 | { "destroy", "()V", |
| 1763 | (void*) android_content_AssetManager_destroy }, |
| 1764 | { "getGlobalAssetCount", "()I", |
| 1765 | (void*) android_content_AssetManager_getGlobalAssetCount }, |
Dianne Hackborn | 82e1ee9 | 2009-08-11 18:56:41 -0700 | [diff] [blame] | 1766 | { "getAssetAllocations", "()Ljava/lang/String;", |
| 1767 | (void*) android_content_AssetManager_getAssetAllocations }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1768 | { "getGlobalAssetManagerCount", "()I", |
Andreas Gampe | 3281261 | 2014-11-11 00:16:00 -0800 | [diff] [blame] | 1769 | (void*) android_content_AssetManager_getGlobalAssetManagerCount }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1770 | }; |
| 1771 | |
| 1772 | int register_android_content_AssetManager(JNIEnv* env) |
| 1773 | { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 1774 | jclass typedValue = FindClassOrDie(env, "android/util/TypedValue"); |
| 1775 | gTypedValueOffsets.mType = GetFieldIDOrDie(env, typedValue, "type", "I"); |
| 1776 | gTypedValueOffsets.mData = GetFieldIDOrDie(env, typedValue, "data", "I"); |
| 1777 | gTypedValueOffsets.mString = GetFieldIDOrDie(env, typedValue, "string", |
| 1778 | "Ljava/lang/CharSequence;"); |
| 1779 | gTypedValueOffsets.mAssetCookie = GetFieldIDOrDie(env, typedValue, "assetCookie", "I"); |
| 1780 | gTypedValueOffsets.mResourceId = GetFieldIDOrDie(env, typedValue, "resourceId", "I"); |
| 1781 | gTypedValueOffsets.mChangingConfigurations = GetFieldIDOrDie(env, typedValue, |
| 1782 | "changingConfigurations", "I"); |
| 1783 | gTypedValueOffsets.mDensity = GetFieldIDOrDie(env, typedValue, "density", "I"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 1785 | jclass assetFd = FindClassOrDie(env, "android/content/res/AssetFileDescriptor"); |
| 1786 | gAssetFileDescriptorOffsets.mFd = GetFieldIDOrDie(env, assetFd, "mFd", |
| 1787 | "Landroid/os/ParcelFileDescriptor;"); |
| 1788 | gAssetFileDescriptorOffsets.mStartOffset = GetFieldIDOrDie(env, assetFd, "mStartOffset", "J"); |
| 1789 | gAssetFileDescriptorOffsets.mLength = GetFieldIDOrDie(env, assetFd, "mLength", "J"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 1791 | jclass assetManager = FindClassOrDie(env, "android/content/res/AssetManager"); |
| 1792 | gAssetManagerOffsets.mObject = GetFieldIDOrDie(env, assetManager, "mObject", "J"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1793 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 1794 | jclass stringClass = FindClassOrDie(env, "java/lang/String"); |
| 1795 | g_stringClass = MakeGlobalRefOrDie(env, stringClass); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1796 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 1797 | jclass sparseArrayClass = FindClassOrDie(env, "android/util/SparseArray"); |
| 1798 | gSparseArrayOffsets.classObject = MakeGlobalRefOrDie(env, sparseArrayClass); |
| 1799 | gSparseArrayOffsets.constructor = GetMethodIDOrDie(env, gSparseArrayOffsets.classObject, |
| 1800 | "<init>", "()V"); |
| 1801 | gSparseArrayOffsets.put = GetMethodIDOrDie(env, gSparseArrayOffsets.classObject, "put", |
| 1802 | "(ILjava/lang/Object;)V"); |
Adam Lesinski | de898ff | 2014-01-29 18:20:45 -0800 | [diff] [blame] | 1803 | |
Filip Gruszczynski | 2349332 | 2015-07-29 17:02:59 -0700 | [diff] [blame] | 1804 | jclass configurationClass = FindClassOrDie(env, "android/content/res/Configuration"); |
| 1805 | gConfigurationOffsets.classObject = MakeGlobalRefOrDie(env, configurationClass); |
| 1806 | gConfigurationOffsets.constructor = GetMethodIDOrDie(env, configurationClass, |
| 1807 | "<init>", "()V"); |
| 1808 | gConfigurationOffsets.mSmallestScreenWidthDpOffset = GetFieldIDOrDie(env, configurationClass, |
| 1809 | "smallestScreenWidthDp", "I"); |
| 1810 | gConfigurationOffsets.mScreenWidthDpOffset = GetFieldIDOrDie(env, configurationClass, |
| 1811 | "screenWidthDp", "I"); |
| 1812 | gConfigurationOffsets.mScreenHeightDpOffset = GetFieldIDOrDie(env, configurationClass, |
| 1813 | "screenHeightDp", "I"); |
| 1814 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 1815 | return RegisterMethodsOrDie(env, "android/content/res/AssetManager", gAssetManagerMethods, |
| 1816 | NELEM(gAssetManagerMethods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | }; // namespace android |