• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修訂aad3af0e0e24da9c18a3c5fbff5b501c6fdfd3ae (tree)
時間2016-07-20 18:01:00
作者jgu21 <jinghui.gu@inte...>
CommiterChih-Wei Huang

Log Message

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

Change Summary

差異

--- a/libnativebridge/native_bridge.cc
+++ b/libnativebridge/native_bridge.cc
@@ -109,6 +109,13 @@ static bool CharacterAllowed(char c, bool first) {
109109 }
110110 }
111111
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+
112119 // We only allow simple names for the library. It is supposed to be a file in
113120 // /system/lib or /vendor/lib. Only allow a small range of characters, that is
114121 // names consisting of [a-zA-Z0-9._-] and starting with [a-zA-Z].
@@ -162,8 +169,7 @@ static bool VersionCheck(const NativeBridgeCallbacks* cb) {
162169 static void CloseNativeBridge(bool with_error) {
163170 state = NativeBridgeState::kClosed;
164171 had_error |= with_error;
165- delete[] app_code_cache_dir;
166- app_code_cache_dir = nullptr;
172+ ReleaseAppCodeCacheDir();
167173 }
168174
169175 bool LoadNativeBridge(const char* nb_library_filename,
@@ -406,16 +412,16 @@ bool InitializeNativeBridge(JNIEnv* env, const char* instruction_set) {
406412 if (stat(app_code_cache_dir, &st) == -1) {
407413 if (errno == ENOENT) {
408414 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();
411417 }
412418 } 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();
415421 }
416422 } 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();
419425 }
420426
421427 // 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) {
424430 SetupEnvironment(callbacks, env, instruction_set);
425431 state = NativeBridgeState::kInitialized;
426432 // 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();
429434 } else {
430435 // Unload the library.
431436 dlclose(native_bridge_handle);
--- a/libnativebridge/tests/Android.mk
+++ b/libnativebridge/tests/Android.mk
@@ -9,6 +9,7 @@ include $(CLEAR_VARS)
99 test_src_files := \
1010 CodeCacheCreate_test.cpp \
1111 CodeCacheExists_test.cpp \
12+ CodeCacheStatFail_test.cpp \
1213 CompleteFlow_test.cpp \
1314 InvalidCharsNativeBridge_test.cpp \
1415 NativeBridge2Signal_test.cpp \
--- /dev/null
+++ b/libnativebridge/tests/CodeCacheStatFail_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
--- a/libnativebridge/tests/NativeBridgeTest.h
+++ b/libnativebridge/tests/NativeBridgeTest.h
@@ -24,6 +24,7 @@
2424
2525 constexpr const char* kNativeBridgeLibrary = "libnativebridge-dummy.so";
2626 constexpr const char* kCodeCache = "./code_cache";
27+constexpr const char* kCodeCacheStatFail = "./code_cache/temp";
2728
2829 namespace android {
2930