summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-02-19 17:29:18 -0800
committerJeff Sharkey <jsharkey@android.com>2013-02-19 18:08:35 -0800
commitef946f3ae80556ab221265c0bf1c560683ea27f6 (patch)
tree1075b9a5a6f58c8a1333aac666124f40ba40fa1f
parent1a4f172df720edcc97ca86838910d3be557a5225 (diff)
downloadandroid_packages_apps_Terminal-ef946f3ae80556ab221265c0bf1c560683ea27f6.tar.gz
android_packages_apps_Terminal-ef946f3ae80556ab221265c0bf1c560683ea27f6.tar.bz2
android_packages_apps_Terminal-ef946f3ae80556ab221265c0bf1c560683ea27f6.zip
Initial code for Terminal app, with JNI glue.
Change-Id: I4b2ecb2eef9bef7a8236391d19a3708751a7c71d
-rw-r--r--Android.mk14
-rw-r--r--AndroidManifest.xml29
-rw-r--r--MODULE_LICENSE_APACHE20
-rw-r--r--jni/Android.mk22
-rw-r--r--jni/com_android_terminal_Terminal.cpp162
-rw-r--r--jni/jni_init.cpp38
-rw-r--r--res/values/strings.xml20
-rw-r--r--src/com/android/terminal/Terminal.java36
-rw-r--r--src/com/android/terminal/TerminalActivity.java33
9 files changed, 354 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..99f8214
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,14 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_JNI_SHARED_LIBRARIES := libjni_terminal
+
+LOCAL_PACKAGE_NAME := Terminal
+
+include $(BUILD_PACKAGE)
+
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
new file mode 100644
index 0000000..397c79f
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,29 @@
+<!-- Copyright (C) 2013 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.terminal">
+
+ <application android:label="@string/app_label">
+ <activity android:name=".TerminalActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+</manifest>
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/jni/Android.mk b/jni/Android.mk
new file mode 100644
index 0000000..0563efc
--- /dev/null
+++ b/jni/Android.mk
@@ -0,0 +1,22 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := \
+ jni_init.cpp \
+ com_android_terminal_Terminal.cpp
+
+LOCAL_C_INCLUDES += \
+ external/libvterm/include
+
+LOCAL_SHARED_LIBRARIES := \
+ libutils \
+ libnativehelper
+
+LOCAL_STATIC_LIBRARIES := \
+ libvterm
+
+LOCAL_MODULE := libjni_terminal
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/jni/com_android_terminal_Terminal.cpp b/jni/com_android_terminal_Terminal.cpp
new file mode 100644
index 0000000..ed84619
--- /dev/null
+++ b/jni/com_android_terminal_Terminal.cpp
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "Terminal"
+
+#include <utils/Log.h>
+#include "jni.h"
+#include "JNIHelp.h"
+
+#include <vterm.h>
+
+#include <string.h>
+
+namespace android {
+
+class Terminal;
+
+/*
+ * VTerm event handlers
+ */
+
+static int term_damage(VTermRect rect, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_damage");
+ return 1;
+}
+
+static int term_prescroll(VTermRect rect, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_prescroll");
+ return 1;
+}
+
+static int term_moverect(VTermRect dest, VTermRect src, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_moverect");
+ return 1;
+}
+
+static int term_movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_movecursor");
+ return 1;
+}
+
+static int term_settermprop(VTermProp prop, VTermValue *val, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_settermprop");
+ return 1;
+}
+
+static int term_setmousefunc(VTermMouseFunc func, void *data, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_setmousefunc");
+ return 1;
+}
+
+static int term_bell(void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_bell");
+ return 1;
+}
+
+static int term_resize(int rows, int cols, void *user) {
+ Terminal* term = reinterpret_cast<Terminal*>(user);
+ ALOGW("term_resize");
+ return 1;
+}
+
+static VTermScreenCallbacks cb = {
+ .damage = term_damage,
+ .prescroll = term_prescroll,
+ .moverect = term_moverect,
+ .movecursor = term_movecursor,
+ .settermprop = term_settermprop,
+ .setmousefunc = term_setmousefunc,
+ .bell = term_bell,
+ .resize = term_resize,
+};
+
+/*
+ * Terminal session
+ */
+
+class Terminal {
+public:
+ Terminal(int rows, int cols);
+ ~Terminal();
+
+ int getRows();
+
+private:
+ VTerm *mVt;
+ VTermScreen *mVts;
+
+ int mRows;
+ int mCols;
+};
+
+Terminal::Terminal(int rows, int cols) : mRows(rows), mCols(cols) {
+// pt->writefn = NULL;
+// pt->resizedfn = NULL;
+
+ /* Create VTerm */
+ mVt = vterm_new(rows, cols);
+ vterm_parser_set_utf8(mVt, 1);
+
+ /* Set up screen */
+ mVts = vterm_obtain_screen(mVt);
+ vterm_screen_enable_altscreen(mVts, 1);
+ vterm_screen_set_callbacks(mVts, &cb, this);
+ vterm_screen_set_damage_merge(mVts, VTERM_DAMAGE_SCROLL);
+
+ // TODO: finish setup and forkpty() here
+}
+
+Terminal::~Terminal() {
+ vterm_free(mVt);
+}
+
+int Terminal::getRows() {
+ return mRows;
+}
+
+/*
+ * JNI glue
+ */
+
+static jint com_android_terminal_Terminal_nativeInit(JNIEnv* env, jclass clazz,
+ jint rows, jint cols) {
+ return reinterpret_cast<jint>(new Terminal(rows, cols));
+}
+
+static jint com_android_terminal_Terminal_nativeGetRows(JNIEnv* env, jclass clazz, jint ptr) {
+ Terminal* term = reinterpret_cast<Terminal*>(ptr);
+ return term->getRows();
+}
+
+static JNINativeMethod gMethods[] = {
+ { "nativeInit", "(II)I", (void*)com_android_terminal_Terminal_nativeInit },
+ { "nativeGetRows", "(I)I", (void*)com_android_terminal_Terminal_nativeGetRows },
+};
+
+int register_com_android_terminal_Terminal(JNIEnv* env) {
+ return jniRegisterNativeMethods(env, "com/android/terminal/Terminal",
+ gMethods, NELEM(gMethods));
+}
+
+} /* namespace android */
diff --git a/jni/jni_init.cpp b/jni/jni_init.cpp
new file mode 100644
index 0000000..c4a262e
--- /dev/null
+++ b/jni/jni_init.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "Terminal"
+
+#include <utils/Log.h>
+#include "jni.h"
+
+namespace android {
+extern int register_com_android_terminal_Terminal(JNIEnv *env);
+}
+
+using namespace android;
+
+extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ JNIEnv *env;
+ if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
+ ALOGE("ERROR: GetEnv failed");
+ return -1;
+ }
+
+ register_com_android_terminal_Terminal(env);
+
+ return JNI_VERSION_1_6;
+}
diff --git a/res/values/strings.xml b/res/values/strings.xml
new file mode 100644
index 0000000..1aca939
--- /dev/null
+++ b/res/values/strings.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <!-- Title of the Terminal activity. -->
+ <string name="app_label">Terminal</string>
+</resources>
diff --git a/src/com/android/terminal/Terminal.java b/src/com/android/terminal/Terminal.java
new file mode 100644
index 0000000..8b1809c
--- /dev/null
+++ b/src/com/android/terminal/Terminal.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.terminal;
+
+public class Terminal {
+ static {
+ System.loadLibrary("jni_terminal");
+ }
+
+ private final int mNativePtr;
+
+ public Terminal() {
+ mNativePtr = nativeInit(25, 80);
+ }
+
+ public int getRows() {
+ return nativeGetRows(mNativePtr);
+ }
+
+ private static native int nativeInit(int rows, int cols);
+ private static native int nativeGetRows(int ptr);
+}
diff --git a/src/com/android/terminal/TerminalActivity.java b/src/com/android/terminal/TerminalActivity.java
new file mode 100644
index 0000000..0bb73ff
--- /dev/null
+++ b/src/com/android/terminal/TerminalActivity.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.terminal;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+
+public class TerminalActivity extends Activity {
+ private static final String TAG = "Terminal";
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Terminal t = new Terminal();
+ Log.d(TAG, "Rows: " + t.getRows());
+ }
+}