Commit 147adcfa by Jamie Madill Committed by Commit Bot

Android: Call getExternalStorageDirectory natively.

This changes the call to base.test.util.UrlUtils to a native OS method. We may need to update this when Chromium starts running tests on "R". At that point we'll need a non-base mechanism to pass the right folder to ANGLE. This could be via env vars, debug properties, command-line arguments, or #defines. The prior implementation is left as commented-out code as a reminder to fix later. Also updates WARN() to std::cerr because WARN() was not showing up when testing. Bug: chromium:1097957 Change-Id: I4a84ea007341dbe7fe2184eac3aae0ddca44cc9c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2818240 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 5902753b
......@@ -9,6 +9,7 @@
#include "util/android/AndroidWindow.h"
#include <pthread.h>
#include <iostream>
#include "common/debug.h"
#include "util/android/third_party/android_native_app_glue.h"
......@@ -43,7 +44,7 @@ int SetScreenOrientation(struct android_app *app, int orientation)
JNIEnv *jni = GetJniEnv();
if (!jni)
{
WARN() << "Failed to get JNI env for screen rotation";
std::cerr << "Failed to get JNI env for screen rotation";
return JNI_ERR;
}
......@@ -196,83 +197,131 @@ std::string AndroidWindow::GetExternalStorageDirectory()
JNIEnv *jni = GetJniEnv();
if (!jni)
{
WARN() << "GetExternalStorageDirectory:: Failed to get JNI env";
std::cerr << "GetExternalStorageDirectory:: Failed to get JNI env";
return "";
}
// https://stackoverflow.com/questions/12841240/android-pass-parameter-to-native-activity
jclass clazz = jni->GetObjectClass(sApp->activity->clazz);
if (clazz == 0)
jclass classEnvironment = jni->FindClass("android/os/Environment");
if (classEnvironment == 0)
{
WARN() << "GetExternalStorageDirectory: Bad activity";
std::cerr << "GetExternalStorageDirectory: Failed to find Environment";
return "";
}
jmethodID giid = jni->GetMethodID(clazz, "getIntent", "()Landroid/content/Intent;");
if (giid == 0)
// public static File getExternalStorageDirectory ()
jmethodID methodIDgetExternalStorageDirectory =
jni->GetStaticMethodID(classEnvironment, "getExternalStorageDirectory", "()Ljava/io/File;");
if (methodIDgetExternalStorageDirectory == 0)
{
WARN() << "GetExternalStorageDirectory: Could not find getIntent";
std::cerr << "GetExternalStorageDirectory: Failed to get static method";
return "";
}
jobject intent = jni->CallObjectMethod(sApp->activity->clazz, giid);
if (intent == 0)
{
WARN() << "GetExternalStorageDirectory: Error calling getIntent";
return "";
}
jclass icl = jni->GetObjectClass(intent);
if (icl == 0)
{
WARN() << "GetExternalStorageDirectory: Error getting getIntent class";
return "";
}
jmethodID gseid =
jni->GetMethodID(icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
if (gseid == 0)
jobject objectFile =
jni->CallStaticObjectMethod(classEnvironment, methodIDgetExternalStorageDirectory);
jthrowable exception = jni->ExceptionOccurred();
if (exception != 0)
{
WARN() << "GetExternalStorageDirectory: Could not find getStringExtra";
jni->ExceptionDescribe();
jni->ExceptionClear();
std::cerr << "GetExternalStorageDirectory: Failed because of exception";
return "";
}
jstring stringPath = static_cast<jstring>(jni->CallObjectMethod(
intent, gseid, jni->NewStringUTF("org.chromium.base.test.util.UrlUtils.RootDirectory")));
if (stringPath != 0)
{
const char *path = jni->GetStringUTFChars(stringPath, nullptr);
return std::string(path) + "/chromium_tests_root";
}
jclass environment = jni->FindClass("org/chromium/base/test/util/UrlUtils");
if (environment == 0)
// Call method on File object to retrieve String object.
jclass classFile = jni->GetObjectClass(objectFile);
if (classEnvironment == 0)
{
WARN() << "GetExternalStorageDirectory: Failed to find Environment";
std::cerr << "GetExternalStorageDirectory: Failed to find object class";
return "";
}
jmethodID getDir =
jni->GetStaticMethodID(environment, "getIsolatedTestRoot", "()Ljava/lang/String;");
if (getDir == 0)
jmethodID methodIDgetAbsolutePath =
jni->GetMethodID(classFile, "getAbsolutePath", "()Ljava/lang/String;");
if (methodIDgetAbsolutePath == 0)
{
WARN() << "GetExternalStorageDirectory: Failed to get static method";
std::cerr << "GetExternalStorageDirectory: Failed to get method ID";
return "";
}
stringPath = static_cast<jstring>(jni->CallStaticObjectMethod(environment, getDir));
jthrowable exception = jni->ExceptionOccurred();
jstring stringPath =
static_cast<jstring>(jni->CallObjectMethod(objectFile, methodIDgetAbsolutePath));
// TODO(jmadill): Find how to pass the root test directory to ANGLE. http://crbug.com/1097957
// // https://stackoverflow.com/questions/12841240/android-pass-parameter-to-native-activity
// jclass clazz = jni->GetObjectClass(sApp->activity->clazz);
// if (clazz == 0)
// {
// std::cerr << "GetExternalStorageDirectory: Bad activity";
// return "";
// }
// jmethodID giid = jni->GetMethodID(clazz, "getIntent", "()Landroid/content/Intent;");
// if (giid == 0)
// {
// std::cerr << "GetExternalStorageDirectory: Could not find getIntent";
// return "";
// }
// jobject intent = jni->CallObjectMethod(sApp->activity->clazz, giid);
// if (intent == 0)
// {
// std::cerr << "GetExternalStorageDirectory: Error calling getIntent";
// return "";
// }
// jclass icl = jni->GetObjectClass(intent);
// if (icl == 0)
// {
// std::cerr << "GetExternalStorageDirectory: Error getting getIntent class";
// return "";
// }
// jmethodID gseid =
// jni->GetMethodID(icl, "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
// if (gseid == 0)
// {
// std::cerr << "GetExternalStorageDirectory: Could not find getStringExtra";
// return "";
// }
// jstring stringPath = static_cast<jstring>(jni->CallObjectMethod(
// intent, gseid, jni->NewStringUTF("org.chromium.base.test.util.UrlUtils.RootDirectory")));
// if (stringPath != 0)
// {
// const char *path = jni->GetStringUTFChars(stringPath, nullptr);
// return std::string(path) + "/chromium_tests_root";
// }
// jclass environment = jni->FindClass("org/chromium/base/test/util/UrlUtils");
// if (environment == 0)
// {
// std::cerr << "GetExternalStorageDirectory: Failed to find Environment";
// return "";
// }
// jmethodID getDir =
// jni->GetStaticMethodID(environment, "getIsolatedTestRoot", "()Ljava/lang/String;");
// if (getDir == 0)
// {
// std::cerr << "GetExternalStorageDirectory: Failed to get static method";
// return "";
// }
// stringPath = static_cast<jstring>(jni->CallStaticObjectMethod(environment, getDir));
exception = jni->ExceptionOccurred();
if (exception != 0)
{
jni->ExceptionDescribe();
jni->ExceptionClear();
WARN() << "GetExternalStorageDirectory: Failed because of exception";
std::cerr << "GetExternalStorageDirectory: Failed because of exception";
return "";
}
const char *path = jni->GetStringUTFChars(stringPath, nullptr);
return std::string(path);
return std::string(path) + "/chromium_tests_root";
}
// static
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment