Skip to content

Commit

Permalink
Add Java function to retrieve the native library dir.
Browse files Browse the repository at this point in the history
Upstreaming the Change with change-id: I94aa26a6e421ec8310f351a410b9083d49eb90f4 made by Ben Murdoch (benm@google.com)

BUG=
TEST=


Review URL: https://chromiumcodereview.appspot.com/10663039

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145179 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
aurimas@chromium.org committed Jul 2, 2012
1 parent b3e35d2 commit 672898b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
15 changes: 15 additions & 0 deletions base/android/java/src/org/chromium/base/PathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.chromium.base;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Environment;

import org.chromium.base.CalledByNative;
Expand Down Expand Up @@ -41,4 +42,18 @@ public static String getDownloadsDirectory(Context appContext) {
return Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS).getPath();
}

/**
* @return the path to native libraries.
*/
@CalledByNative
public static String getNativeLibraryDirectory(Context appContext) {
ApplicationInfo ai = appContext.getApplicationInfo();
if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 ||
(ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
return ai.nativeLibraryDir;
}

return "/system/lib/";
}
}
7 changes: 7 additions & 0 deletions base/android/path_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ std::string GetDownloadsDirectory() {
return ConvertJavaStringToUTF8(path);
}

std::string GetNativeLibraryDirectory() {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jstring> path =
Java_PathUtils_getNativeLibraryDirectory(env, GetApplicationContext());
return ConvertJavaStringToUTF8(path);
}

bool RegisterPathUtils(JNIEnv* env) {
return RegisterNativesImpl(env);
}
Expand Down
4 changes: 4 additions & 0 deletions base/android/path_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ std::string GetCacheDirectory();
// Returns the path to the public downloads directory.
std::string GetDownloadsDirectory();

// Returns the path to the native JNI libraries via
// ApplicationInfo.nativeLibraryDir on the Java side.
std::string GetNativeLibraryDirectory();

bool RegisterPathUtils(JNIEnv* env);

} // namespace android
Expand Down
8 changes: 8 additions & 0 deletions base/android/path_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ TEST_F(PathUtilsTest, TestGetCacheDirectory) {
GetCacheDirectory().c_str());
}

TEST_F(PathUtilsTest, TestGetNativeLibraryDirectory) {
// The string comes from the Java side and depends on the APK
// we are running in. Assumes that we are packaged in
// org.chromium.native_test
EXPECT_STREQ("/data/data/org.chromium.native_test/lib",
GetNativeLibraryDirectory().c_str());
}

} // namespace android
} // namespace base
5 changes: 2 additions & 3 deletions base/base_paths_android.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -37,8 +37,7 @@ bool PathProviderAndroid(int key, FilePath* result) {
NOTIMPLEMENTED();
return false;
case base::DIR_MODULE: {
*result = FilePath(base::android::GetDataDirectory()).DirName()
.Append("lib");
*result = FilePath(base::android::GetNativeLibraryDirectory());
return true;
}
case base::DIR_SOURCE_ROOT:
Expand Down

0 comments on commit 672898b

Please sign in to comment.