summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2010-07-02 18:52:01 -0700
committerDianne Hackborn <hackbod@google.com>2010-07-02 18:57:02 -0700
commit682674154e3fe88f6061245145f934f25f1a2eb8 (patch)
treea105ce9f0ae4d88732bfc8fb1a52d4474f17bc86 /core
parent8ecfb60a8e74dfcd51bbf3f236d5f414a4d5ac7d (diff)
downloadframeworks_base-682674154e3fe88f6061245145f934f25f1a2eb8.zip
frameworks_base-682674154e3fe88f6061245145f934f25f1a2eb8.tar.gz
frameworks_base-682674154e3fe88f6061245145f934f25f1a2eb8.tar.bz2
Add new native Looper API.
This allows us to avoid exposing the file descriptor of the event queue; instead, you attach an event queue to a looper. This will also should allow native apps to be written without the need for a separate thread, by attaching the event queue to the main thread's looper and scheduling their own messages there. Change-Id: I38489282635895ae2cbfacb88599c1b1cad9b239
Diffstat (limited to 'core')
-rw-r--r--core/java/android/app/NativeActivity.java11
-rw-r--r--core/jni/android_app_NativeActivity.cpp22
-rw-r--r--core/jni/android_os_MessageQueue.cpp6
3 files changed, 34 insertions, 5 deletions
diff --git a/core/java/android/app/NativeActivity.java b/core/java/android/app/NativeActivity.java
index 161161c..d72dda7 100644
--- a/core/java/android/app/NativeActivity.java
+++ b/core/java/android/app/NativeActivity.java
@@ -6,7 +6,9 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.PixelFormat;
+import android.os.Build;
import android.os.Bundle;
+import android.os.Environment;
import android.os.Looper;
import android.os.MessageQueue;
import android.view.InputChannel;
@@ -33,7 +35,8 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback,
private boolean mDestroyed;
- private native int loadNativeCode(String path, MessageQueue queue);
+ private native int loadNativeCode(String path, MessageQueue queue,
+ String internalDataPath, String externalDataPath, int sdkVersion);
private native void unloadNativeCode(int handle);
private native void onStartNative(int handle);
@@ -90,7 +93,11 @@ public class NativeActivity extends Activity implements SurfaceHolder.Callback,
throw new IllegalArgumentException("Unable to find native library: " + libname);
}
- mNativeHandle = loadNativeCode(path, Looper.myQueue());
+ mNativeHandle = loadNativeCode(path, Looper.myQueue(),
+ getFilesDir().toString(),
+ Environment.getExternalStorageAppFilesDirectory(ai.packageName).toString(),
+ Build.VERSION.SDK_INT);
+
if (mNativeHandle == 0) {
throw new IllegalArgumentException("Unable to load native library: " + path);
}
diff --git a/core/jni/android_app_NativeActivity.cpp b/core/jni/android_app_NativeActivity.cpp
index dab1dba..af61b80 100644
--- a/core/jni/android_app_NativeActivity.cpp
+++ b/core/jni/android_app_NativeActivity.cpp
@@ -166,6 +166,9 @@ struct NativeCode {
void* dlhandle;
ANativeActivity_createFunc* createActivityFunc;
+ String8 internalDataPath;
+ String8 externalDataPath;
+
sp<ANativeWindow> nativeWindow;
jobject inputChannel;
struct MyInputQueue* nativeInputQueue;
@@ -204,7 +207,8 @@ static bool mainWorkCallback(int fd, int events, void* data) {
// ------------------------------------------------------------------------
static jint
-loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jobject messageQueue)
+loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jobject messageQueue,
+ jstring internalDataDir, jstring externalDataDir, int sdkVersion)
{
const char* pathStr = env->GetStringUTFChars(path, NULL);
NativeCode* code = NULL;
@@ -247,6 +251,19 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jobject messageQ
}
code->activity.env = env;
code->activity.clazz = env->NewGlobalRef(clazz);
+
+ const char* dirStr = env->GetStringUTFChars(internalDataDir, NULL);
+ code->internalDataPath = dirStr;
+ code->activity.internalDataPath = code->internalDataPath.string();
+ env->ReleaseStringUTFChars(path, dirStr);
+
+ dirStr = env->GetStringUTFChars(externalDataDir, NULL);
+ code->externalDataPath = dirStr;
+ code->activity.externalDataPath = code->externalDataPath.string();
+ env->ReleaseStringUTFChars(path, dirStr);
+
+ code->activity.sdkVersion = sdkVersion;
+
code->createActivityFunc(&code->activity, NULL, 0);
}
@@ -420,7 +437,8 @@ onInputChannelDestroyed_native(JNIEnv* env, jobject clazz, jint handle, jobject
}
static const JNINativeMethod g_methods[] = {
- { "loadNativeCode", "(Ljava/lang/String;Landroid/os/MessageQueue;)I", (void*)loadNativeCode_native },
+ { "loadNativeCode", "(Ljava/lang/String;Landroid/os/MessageQueue;Ljava/lang/String;Ljava/lang/String;I)I",
+ (void*)loadNativeCode_native },
{ "unloadNativeCode", "(I)V", (void*)unloadNativeCode_native },
{ "onStartNative", "(I)V", (void*)onStart_native },
{ "onResumeNative", "(I)V", (void*)onResume_native },
diff --git a/core/jni/android_os_MessageQueue.cpp b/core/jni/android_os_MessageQueue.cpp
index 030d6c7..961f806 100644
--- a/core/jni/android_os_MessageQueue.cpp
+++ b/core/jni/android_os_MessageQueue.cpp
@@ -51,7 +51,11 @@ private:
// ----------------------------------------------------------------------------
NativeMessageQueue::NativeMessageQueue() {
- mPollLoop = new PollLoop();
+ mPollLoop = PollLoop::getForThread();
+ if (mPollLoop == NULL) {
+ mPollLoop = new PollLoop();
+ PollLoop::setForThread(mPollLoop);
+ }
}
NativeMessageQueue::~NativeMessageQueue() {