Index: pjproject/trunk/pjsip-apps/src/pjsua/android/.classpath
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/.classpath	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/.classpath	(revision 4496)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
+	<classpathentry kind="output" path="bin/classes"/>
+</classpath>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/.project
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/.project	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/.project	(revision 4496)
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>pjsua</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+			<triggers>clean,full,incremental,</triggers>
+			<arguments>
+				<dictionary>
+					<key>?name?</key>
+					<value></value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.append_environment</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
+					<value>all</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.buildArguments</key>
+					<value></value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.buildCommand</key>
+					<value>make</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
+					<value>clean</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.contents</key>
+					<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
+					<value>false</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.enableFullBuild</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
+					<value>all</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.stopOnError</key>
+					<value>true</value>
+				</dictionary>
+				<dictionary>
+					<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
+					<value>true</value>
+				</dictionary>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+			<triggers>full,incremental,</triggers>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.cdt.core.cnature</nature>
+		<nature>org.eclipse.cdt.core.ccnature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+	</natures>
+</projectDescription>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/AndroidManifest.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/AndroidManifest.xml	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/AndroidManifest.xml	(revision 4496)
@@ -0,0 +1,45 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="org.pjsip.pjsua"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="15"
+        android:targetSdkVersion="15" />
+
+    <uses-permission android:name="android.permission.INTERNET" />
+    <uses-permission android:name="android.permission.RECORD_AUDIO" />
+    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
+    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
+    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
+    <uses-permission android:name="android.permission.VIBRATE" />
+    <uses-permission android:name="android.permission.READ_LOGS" />
+    <uses-permission android:name="android.permission.USE_SIP" />
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.CAMERA" />
+
+    <uses-feature
+        android:name="android.hardware.microphone"
+        android:required="true" />
+
+    <application
+        android:icon="@drawable/main_image"
+        android:label="@string/app_name"
+        android:theme="@android:style/Theme.DeviceDefault.NoActionBar" >
+        <activity
+            android:name=".MainActivity"
+            android:windowSoftInputMode="stateHidden"
+            android:label="@string/app_name" android:screenOrientation="portrait" android:theme="@android:style/Theme.NoTitleBar">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Android.mk
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Android.mk	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/jni/Android.mk	(revision 4496)
@@ -0,0 +1,61 @@
+# $id$
+
+LOCAL_PATH	:= $(call my-dir)
+include $(CLEAR_VARS)
+
+# Get PJ build settings
+include ../../../../build.mak
+include $(PJDIR)/build/common.mak
+
+# Path to SWIG
+MY_SWIG		:= swig
+
+#========================================================================
+# Choose console application to load
+#========================================================================
+
+# pjlib test
+#MY_MODULE :=  $(PJDIR)/pjlib/build/output/pjlib-test-$(TARGET_NAME)/*.o
+
+# pjlib-util test
+#MY_MODULE :=  $(PJDIR)/pjlib-util/build/output/pjlib-util-test-$(TARGET_NAME)/*.o
+
+# pjsip test
+#MY_MODULE :=  $(PJDIR)/pjsip/build/output/pjsip-test-$(TARGET_NAME)/*.o
+
+# pjnath test
+#MY_MODULE :=  $(PJDIR)/pjnath/build/output/pjnath-test-$(TARGET_NAME)/*.o
+
+# pjmedia test
+# Note: jbuf test requires Jbtest.dat, this jbuf test must be disabled (for now).
+#MY_MODULE :=  $(PJDIR)/pjmedia/build/output/pjmedia-test-$(TARGET_NAME)/*.o
+
+# pjsystest app (not supported yet)
+# Todo: this test requires some input and output files (log & WAV).
+#MY_MODULE := $(PJDIR)/pjsip-apps/build/output/pjsystest-$(TARGET_NAME)/*.o
+
+# pjsua app
+# Note: must set USE_GUI to zero in config_site.h
+MY_MODULE := $(PJDIR)/pjsip-apps/build/output/pjsua-$(TARGET_NAME)/*.o
+
+#========================================================================
+
+# Constants
+MY_JNI_WRAP	:= pjsua_wrap.cpp
+MY_JNI_DIR	:= jni
+
+# Android build settings
+LOCAL_MODULE    := libpjsua
+LOCAL_CFLAGS    := -Werror $(APP_CFLAGS) -frtti
+LOCAL_LDFLAGS   := $(APP_LDFLAGS)
+LOCAL_LDLIBS    := $(MY_MODULE) $(APP_LDLIBS)
+LOCAL_SRC_FILES := $(MY_JNI_WRAP) pjsua_app_callback.cpp
+
+# Invoke SWIG
+$(MY_JNI_DIR)/$(MY_JNI_WRAP):
+	@echo "Invoking SWIG..."
+	$(MY_SWIG) -c++ -o $(MY_JNI_DIR)/$(MY_JNI_WRAP) -package org.pjsip.pjsua -outdir src/org/pjsip/pjsua -java $(MY_JNI_DIR)/pjsua.i
+
+.PHONY: $(MY_JNI_DIR)/$(MY_JNI_WRAP)
+
+include $(BUILD_SHARED_LIBRARY)
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua.i
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua.i	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua.i	(revision 4496)
@@ -0,0 +1,29 @@
+%module (directors="1") pjsua
+
+%{
+#include "pjsua_app_callback.h"
+#include "../../pjsua_app.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+	int pjsuaStart();
+	void pjsuaDestroy();
+	int pjsuaRestart();
+	void setCallbackObject(PjsuaAppCallback* callback);	
+#ifdef __cplusplus
+}
+#endif
+%}
+
+int pjsuaStart();
+void pjsuaDestroy();
+int pjsuaRestart();
+
+/* turn on director wrapping PjsuaAppCallback */
+%feature("director") PjsuaAppCallback;
+
+%include "pjsua_app_callback.h"
+
+void setCallbackObject(PjsuaAppCallback* callback);
+
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp	(revision 4496)
@@ -0,0 +1,113 @@
+/* $Id: pjsua_app_callback.cpp $ */
+/* 
+ * Copyright (C) 2012-2012 Teluu Inc. (http://www.teluu.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+
+#include "pjsua_app_callback.h"
+#include "../../pjsua_app.h"
+#include "../../pjsua_app_config.h"
+
+#if defined(PJ_ANDROID) && PJ_ANDROID != 0
+
+static PjsuaAppCallback* registeredCallbackObject = NULL;
+static pjsua_app_cfg_t android_app_config;
+static int restart_argc;
+static char **restart_argv;
+
+extern const char *pjsua_app_def_argv[];
+
+#define THIS_FILE	"pjsua_app_callback.cpp"
+
+/** Callback wrapper **/
+void on_cli_started(pj_status_t status, const char *msg)
+{
+    char errmsg[PJ_ERR_MSG_SIZE];
+    if (registeredCallbackObject) {
+	if ((status != PJ_SUCCESS) && (!msg || !*msg)) {
+	    pj_strerror(status, errmsg, sizeof(errmsg));
+	    msg = errmsg;
+	}
+	registeredCallbackObject->onStarted(msg);
+    }
+}
+
+void on_cli_stopped(pj_bool_t restart, int argc, char **argv)
+{
+    if (restart) {
+	restart_argc = argc;
+	restart_argv = argv;
+    }
+
+    if (registeredCallbackObject) {
+	registeredCallbackObject->onStopped(restart);
+    }
+}
+
+static int initMain(int argc, char **argv)
+{
+    pj_status_t status;
+    android_app_config.argc = argc;
+    android_app_config.argv = argv;
+
+    status = pjsua_app_init(&android_app_config);
+    if (status == PJ_SUCCESS) {
+	status = pjsua_app_run(PJ_FALSE);
+    } else {
+	pjsua_app_destroy();
+    }
+
+    return status;
+}
+
+int pjsuaStart()
+{
+    pj_status_t status;
+
+    const char **argv = pjsua_app_def_argv;
+    int argc = pjsua_app_def_argc;
+
+    pj_bzero(&android_app_config, sizeof(android_app_config));
+
+    android_app_config.on_started = &on_cli_started;
+    android_app_config.on_stopped = &on_cli_stopped;
+
+    return initMain(argc, (char**)argv);
+}
+
+void pjsuaDestroy()
+{
+    pjsua_app_destroy();
+
+    /** This is on purpose **/
+    pjsua_app_destroy();
+}
+
+int pjsuaRestart()
+{
+    pj_status_t status;
+
+    pjsuaDestroy();
+
+    return initMain(restart_argc, restart_argv);
+}
+
+void setCallbackObject(PjsuaAppCallback* callback)
+{
+    registeredCallbackObject = callback;
+}
+
+#endif
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h	(revision 4496)
@@ -0,0 +1,36 @@
+/* $Id: pjsua_app_callback.h $ */
+/*
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef __PJSUA_APP_CALLBACK_H__
+#define __PJSUA_APP_CALLBACK_H__
+
+class PjsuaAppCallback {
+public:
+    virtual ~PjsuaAppCallback() {}
+    virtual void onStarted(const char *msg) {}
+    virtual void onStopped(int restart) {}
+};
+
+extern "C" {
+int pjsuaStart();
+void pjsuaDestroy();
+int pjsuaRestart();
+void setCallbackObject(PjsuaAppCallback* callback);
+}
+
+#endif /* __PJSUA_APP_CALLBACK_H__ */
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/lint.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/lint.xml	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/lint.xml	(revision 4496)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<lint>
+</lint>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/proguard-project.txt
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/proguard-project.txt	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/proguard-project.txt	(revision 4496)
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/project.properties
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/project.properties	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/project.properties	(revision 4496)
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-16
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/res/layout/activity_main.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/res/layout/activity_main.xml	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/res/layout/activity_main.xml	(revision 4496)
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical" >
+
+    <ImageView
+        android:id="@+id/imageApp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_above="@+id/textApp"
+        android:layout_centerHorizontal="true"
+        android:contentDescription="@string/app_name"
+        android:src="@drawable/main_image" />
+
+    <TextView
+        android:id="@+id/textApp"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_centerHorizontal="true"
+        android:layout_centerVertical="true"
+        android:text="@string/app_name"
+        android:textSize="40sp"
+        android:typeface="serif" />
+
+    <TextView
+        android:id="@+id/textStatus"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_centerHorizontal="true" 
+        android:textIsSelectable="false"/>
+
+</RelativeLayout>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/res/values-v11/styles.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/res/values-v11/styles.xml	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/res/values-v11/styles.xml	(revision 4496)
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Holo.Light" />
+
+</resources>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/res/values-v14/styles.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/res/values-v14/styles.xml	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/res/values-v14/styles.xml	(revision 4496)
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
+
+</resources>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/res/values/strings.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/res/values/strings.xml	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/res/values/strings.xml	(revision 4496)
@@ -0,0 +1,6 @@
+<resources>
+
+    <string name="app_name">pjsua</string>
+    <string name="title_activity_main">MainActivity</string>
+
+</resources>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/res/values/styles.xml
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/res/values/styles.xml	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/res/values/styles.xml	(revision 4496)
@@ -0,0 +1,5 @@
+<resources>
+
+    <style name="AppTheme" parent="android:Theme.Light" />
+
+</resources>
Index: pjproject/trunk/pjsip-apps/src/pjsua/android/src/org/pjsip/pjsua/MainActivity.java
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/android/src/org/pjsip/pjsua/MainActivity.java	(revision 4496)
+++ pjproject/trunk/pjsip-apps/src/pjsua/android/src/org/pjsip/pjsua/MainActivity.java	(revision 4496)
@@ -0,0 +1,242 @@
+/* $Id: MainActivity.java $ */
+/*
+ * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package org.pjsip.pjsua;
+
+import java.lang.ref.WeakReference;
+
+import android.app.Activity;
+import android.content.pm.ApplicationInfo;
+import android.os.Bundle;
+import android.util.Log;
+import android.os.Handler;
+import android.os.Message;
+import android.widget.TextView;
+
+class CONST {
+	public static final String LIB_FILENAME = "pjsua";
+	public static final String TAG = "pjsua";
+	public static final Boolean AUTOKILL_ON_FINISH = true;
+	public enum MSG_TYPE {
+		STR_DEBUG,
+		STR_INFO,
+		STR_ERROR,
+		CLI_STOP,
+		CLI_RESTART,
+		QUIT
+	};	
+}
+
+class LOG {
+	public static void DEBUG(Handler h, String str) {
+		Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_DEBUG.ordinal(), 
+									 str);
+		msg.sendToTarget();
+	}	
+	public static void INFO(Handler h, String str) {
+		Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_INFO.ordinal(), 
+									 str);
+		msg.sendToTarget();
+	}
+	public static void ERROR(Handler h, String str) {
+		Message msg = Message.obtain(h, CONST.MSG_TYPE.STR_ERROR.ordinal(), 
+									 str);
+		msg.sendToTarget();
+	}
+}
+
+public class MainActivity extends Activity {
+	private MyHandler ui_handler = new MyHandler(this);
+	private static MyCallback callback;
+	
+	private static class MyHandler extends Handler {
+		private final WeakReference<MainActivity> mTarget;
+		
+		public MyHandler(MainActivity target) {
+			mTarget = new WeakReference<MainActivity>(target); 
+		}
+		
+		@Override
+		public void handleMessage(Message m) {
+			MainActivity target = mTarget.get();
+			if (target == null)
+				return;
+			
+			if (m.what == CONST.MSG_TYPE.STR_DEBUG.ordinal()) {
+				Log.d(CONST.TAG, (String)m.obj);	
+			} else if (m.what == CONST.MSG_TYPE.STR_INFO.ordinal()) {
+				target.updateStatus((String)m.obj);
+				Log.i(CONST.TAG, (String)m.obj);				
+			} else if (m.what == CONST.MSG_TYPE.STR_ERROR.ordinal()) {
+				target.updateStatus((String)m.obj);
+				Log.e(CONST.TAG, (String)m.obj);
+			} else if (m.what == CONST.MSG_TYPE.CLI_STOP.ordinal()) {
+				pjsua.pjsuaDestroy();
+				LOG.INFO(this, "Telnet Unavailable");
+			} else if (m.what == CONST.MSG_TYPE.CLI_RESTART.ordinal()) {
+				int status = pjsua.pjsuaRestart();
+				if (status != 0) {
+					LOG.INFO(this, "Failed restarting telnet");
+				}
+			} else if (m.what == CONST.MSG_TYPE.QUIT.ordinal()) {
+				target.finish();
+				System.gc();
+				android.os.Process.killProcess(android.os.Process.myPid());
+			}
+		}
+    }
+	
+	/** Callback object **/
+	private static class MyCallback extends PjsuaAppCallback {
+		private WeakReference<Handler> ui_handler;
+		
+		public MyCallback(Handler in_ui_handler) {
+			set_ui_handler(in_ui_handler);			
+		}
+		
+		public void set_ui_handler(Handler in_ui_handler) {
+			ui_handler = new WeakReference<Handler>(in_ui_handler);
+		}		
+		
+		@Override
+	    public void onStarted(String msg) {
+			Handler ui = ui_handler.get();
+			LOG.INFO(ui, msg);			
+		}
+		
+		@Override
+	    public void onStopped(int restart) {
+			Handler ui = ui_handler.get();
+			/** Use timer to stopped/restart **/
+			if (restart != 0) {
+				LOG.INFO(ui, "Telnet Restarting");
+				Message msg = Message.obtain(ui, 
+										  CONST.MSG_TYPE.CLI_RESTART.ordinal());
+				ui.sendMessageDelayed(msg, 100);
+			} else {
+				LOG.INFO(ui, "Telnet Stopping");
+				Message msg = Message.obtain(ui, 
+											 CONST.MSG_TYPE.CLI_STOP.ordinal());
+				ui.sendMessageDelayed(msg, 100);
+			}
+		}
+	}
+	
+	private void updateStatus(String output) {
+        TextView tStatus = (TextView) findViewById(R.id.textStatus);
+        tStatus.setText(output);        
+	}
+    
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+    	LOG.DEBUG(ui_handler, "=== Activity::onCreate() ===");
+    	super.onCreate(savedInstanceState);
+    	
+    	init_view();
+
+    	init_lib();
+	}
+
+    @Override
+    protected void onStart() {
+    	LOG.DEBUG(ui_handler, "=== Activity::onStart() ===");
+    	super.onStart();
+    }
+    
+    @Override
+    protected void onRestart() {
+    	LOG.DEBUG(ui_handler, "=== Activity::onRestart() ===");
+    	super.onRestart();
+    }
+
+    @Override
+    protected void onResume() {
+    	LOG.DEBUG(ui_handler, "=== Activity::onResume() ===");
+    	super.onResume();
+    }
+
+    @Override
+    protected void onPause() {
+    	LOG.DEBUG(ui_handler, "=== Activity::onPause() ===");
+    	super.onPause();
+    }
+
+    @Override
+    protected void onStop() {
+    	LOG.DEBUG(ui_handler, "=== Activity::onStop() ===");
+    	super.onStop();
+    }
+
+    @Override
+    protected void onDestroy() {
+    	LOG.DEBUG(ui_handler, "=== Activity::onDestroy() ===");
+    	super.onDestroy();
+    }
+    
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+		super.onSaveInstanceState(outState);
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Bundle savedInstanceState) {
+		super.onRestoreInstanceState(savedInstanceState);
+    }
+    
+	private void init_view() {
+    	setContentView(R.layout.activity_main);
+	}
+	
+	private int init_lib() {        
+		LOG.INFO(ui_handler, "Loading module...");
+		try {
+			System.loadLibrary(CONST.LIB_FILENAME);
+		} catch (UnsatisfiedLinkError e) {
+			LOG.ERROR(ui_handler, "UnsatisfiedLinkError: " + e.getMessage());
+			return -1;
+		}
+		
+		// Wait for GDB to init
+		if ((getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) 
+		{
+			try {
+				Thread.sleep(5000);
+	        } catch (InterruptedException e) {
+	        	LOG.ERROR(ui_handler, "InterruptedException: " + 
+	        			  e.getMessage());
+	        }
+		}
+		
+		// Set callback object
+		if (callback == null)
+			callback = new MyCallback(ui_handler);
+		
+		pjsua.setCallbackObject(callback);
+
+		LOG.INFO(ui_handler, "Starting module..");
+
+		int rc = pjsua.pjsuaStart();
+        
+		if (rc != 0) {
+			LOG.INFO(ui_handler, "Failed starting telnet");
+		}
+		
+		return 0;
+	}
+}
