system/corennnnn
修訂 | aad3af0e0e24da9c18a3c5fbff5b501c6fdfd3ae (tree) |
---|---|
時間 | 2016-07-20 18:01:00 |
作者 | jgu21 <jinghui.gu@inte...> |
Commiter | Chih-Wei Huang |
Allow native bridge to work without a code cache
In isolatedProcess, the app_code_cache_dir is not needed
for native bridge. This commit allows native bridge to work
without a code cache in isolatedProcess.
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-1596
Change-Id: I8580268d5ec6ca8d44e4500c3fafe10408e1e0d3
Signed-off-by: jgu21 <jinghui.gu@intel.com>
Reviewed-on: https://android.intel.com:443/406649
@@ -109,6 +109,13 @@ static bool CharacterAllowed(char c, bool first) { | ||
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | +static void ReleaseAppCodeCacheDir() { | |
113 | + if (app_code_cache_dir != nullptr) { | |
114 | + delete[] app_code_cache_dir; | |
115 | + app_code_cache_dir = nullptr; | |
116 | + } | |
117 | +} | |
118 | + | |
112 | 119 | // We only allow simple names for the library. It is supposed to be a file in |
113 | 120 | // /system/lib or /vendor/lib. Only allow a small range of characters, that is |
114 | 121 | // names consisting of [a-zA-Z0-9._-] and starting with [a-zA-Z]. |
@@ -162,8 +169,7 @@ static bool VersionCheck(const NativeBridgeCallbacks* cb) { | ||
162 | 169 | static void CloseNativeBridge(bool with_error) { |
163 | 170 | state = NativeBridgeState::kClosed; |
164 | 171 | had_error |= with_error; |
165 | - delete[] app_code_cache_dir; | |
166 | - app_code_cache_dir = nullptr; | |
172 | + ReleaseAppCodeCacheDir(); | |
167 | 173 | } |
168 | 174 | |
169 | 175 | bool LoadNativeBridge(const char* nb_library_filename, |
@@ -406,16 +412,16 @@ bool InitializeNativeBridge(JNIEnv* env, const char* instruction_set) { | ||
406 | 412 | if (stat(app_code_cache_dir, &st) == -1) { |
407 | 413 | if (errno == ENOENT) { |
408 | 414 | if (mkdir(app_code_cache_dir, S_IRWXU | S_IRWXG | S_IXOTH) == -1) { |
409 | - ALOGE("Cannot create code cache directory %s: %s.", app_code_cache_dir, strerror(errno)); | |
410 | - CloseNativeBridge(true); | |
415 | + ALOGW("Cannot create code cache directory %s: %s.", app_code_cache_dir, strerror(errno)); | |
416 | + ReleaseAppCodeCacheDir(); | |
411 | 417 | } |
412 | 418 | } else { |
413 | - ALOGE("Cannot stat code cache directory %s: %s.", app_code_cache_dir, strerror(errno)); | |
414 | - CloseNativeBridge(true); | |
419 | + ALOGW("Cannot stat code cache directory %s: %s.", app_code_cache_dir, strerror(errno)); | |
420 | + ReleaseAppCodeCacheDir(); | |
415 | 421 | } |
416 | 422 | } else if (!S_ISDIR(st.st_mode)) { |
417 | - ALOGE("Code cache is not a directory %s.", app_code_cache_dir); | |
418 | - CloseNativeBridge(true); | |
423 | + ALOGW("Code cache is not a directory %s.", app_code_cache_dir); | |
424 | + ReleaseAppCodeCacheDir(); | |
419 | 425 | } |
420 | 426 | |
421 | 427 | // If we're still PreInitialized (dind't fail the code cache checks) try to initialize. |
@@ -424,8 +430,7 @@ bool InitializeNativeBridge(JNIEnv* env, const char* instruction_set) { | ||
424 | 430 | SetupEnvironment(callbacks, env, instruction_set); |
425 | 431 | state = NativeBridgeState::kInitialized; |
426 | 432 | // We no longer need the code cache path, release the memory. |
427 | - delete[] app_code_cache_dir; | |
428 | - app_code_cache_dir = nullptr; | |
433 | + ReleaseAppCodeCacheDir(); | |
429 | 434 | } else { |
430 | 435 | // Unload the library. |
431 | 436 | dlclose(native_bridge_handle); |
@@ -9,6 +9,7 @@ include $(CLEAR_VARS) | ||
9 | 9 | test_src_files := \ |
10 | 10 | CodeCacheCreate_test.cpp \ |
11 | 11 | CodeCacheExists_test.cpp \ |
12 | + CodeCacheStatFail_test.cpp \ | |
12 | 13 | CompleteFlow_test.cpp \ |
13 | 14 | InvalidCharsNativeBridge_test.cpp \ |
14 | 15 | NativeBridge2Signal_test.cpp \ |
@@ -0,0 +1,51 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2014 The Android Open Source Project | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | +#include "NativeBridgeTest.h" | |
18 | + | |
19 | +#include <errno.h> | |
20 | +#include <sys/stat.h> | |
21 | +#include <unistd.h> | |
22 | +#include <fcntl.h> | |
23 | + | |
24 | +namespace android { | |
25 | + | |
26 | +// Tests that the bridge is initialized without errors if the code_cache is | |
27 | +// existed as a file. | |
28 | +TEST_F(NativeBridgeTest, CodeCacheStatFail) { | |
29 | + int fd = creat(kCodeCache, O_RDWR); | |
30 | + ASSERT_NE(-1, fd); | |
31 | + close(fd); | |
32 | + | |
33 | + struct stat st; | |
34 | + ASSERT_EQ(-1, stat(kCodeCacheStatFail, &st)); | |
35 | + ASSERT_EQ(ENOTDIR, errno); | |
36 | + | |
37 | + // Init | |
38 | + ASSERT_TRUE(LoadNativeBridge(kNativeBridgeLibrary, nullptr)); | |
39 | + ASSERT_TRUE(PreInitializeNativeBridge(kCodeCacheStatFail, "isa")); | |
40 | + ASSERT_TRUE(InitializeNativeBridge(nullptr, nullptr)); | |
41 | + ASSERT_TRUE(NativeBridgeAvailable()); | |
42 | + ASSERT_FALSE(NativeBridgeError()); | |
43 | + | |
44 | + // Clean up | |
45 | + UnloadNativeBridge(); | |
46 | + | |
47 | + ASSERT_FALSE(NativeBridgeError()); | |
48 | + unlink(kCodeCache); | |
49 | +} | |
50 | + | |
51 | +} // namespace android |
@@ -24,6 +24,7 @@ | ||
24 | 24 | |
25 | 25 | constexpr const char* kNativeBridgeLibrary = "libnativebridge-dummy.so"; |
26 | 26 | constexpr const char* kCodeCache = "./code_cache"; |
27 | +constexpr const char* kCodeCacheStatFail = "./code_cache/temp"; | |
27 | 28 | |
28 | 29 | namespace android { |
29 | 30 |