# HG changeset patch # User Carl Byington # Date 1541705953 28800 # Node ID 807f7e4eaebe2f77f16defb0c22b5978a59a8484 # Parent 3a5df66c04802b06ff25936af0d670e72eba8e01 starting update to latest toolchain diff -r 3a5df66c0480 -r 807f7e4eaebe .classpath --- a/.classpath Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - - - - diff -r 3a5df66c0480 -r 807f7e4eaebe .project --- a/.project Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ - - - 510ConnectbotMonitor - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff -r 3a5df66c0480 -r 807f7e4eaebe AndroidManifest.xml --- a/AndroidManifest.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 3a5df66c0480 -r 807f7e4eaebe Makefile --- a/Makefile Fri May 01 12:34:17 2015 -0700 +++ b/Makefile Thu Nov 08 11:39:13 2018 -0800 @@ -1,13 +1,22 @@ #mc40 is "On Device Storage" #tc55 is "Internal Storage" -style=release -dest=/run/user/1000/gvfs/mtp*/*torage/Download -apk='bin/510ConnectbotMonitor-$(style).apk' +style:=release +dest:=/run/user/1000/gvfs/mtp*/*torage/Download +ver:=$(shell grep versionName app/src/main/AndroidManifest.xml | cut -d'"' -f2) +apk:='app/build/outputs/apk/510ConnectbotMonitor-$(ver).apk' +id:=$(shell hg id --id || echo 1) +da:=$(shell date +%Y-%m-%d) +version:=\ +\n\ +\n\ + 510ConnectbotMonitor $(ver) ($(id) $(da))\n\ +\n + ifeq ($(style),release) - debuggable=false + task:=assembleArmRelease else - debuggable=true + task:=assembleArmDebug endif all: @@ -15,10 +24,15 @@ make builder builder: - sed -i -e 's/android:debuggable=".*"/android:debuggable="$(debuggable)"/g' AndroidManifest.xml - rm -rf gen bin - android update project -p . -t android-16 - ant $(style) + rm -rf app/build/* + echo -e "$(version)" >app/src/main/res/values/version.xml + cat app/src/main/res/values/version.xml + ANDROID_HOME=/home/carl/Android/Sdk ANDROID_NDK_HOME=/home/carl/Android/Sdk/ndk-bundle ./gradlew $(task) + mv app/build/outputs/apk/arm/$(style)/app-arm-$(style).apk $(apk) + ls -al app/build/outputs/apk + +docs: + (cd xml; make) install: cp $(apk) $(dest) diff -r 3a5df66c0480 -r 807f7e4eaebe ant.properties --- a/ant.properties Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -# This file is used to override default values used by the Ant build system. -# -# This file must be checked in Version Control Systems, as it is -# integral to the build system of your project. - -# This file is only used by the Ant script. - -# You can use this to override default values such as -# 'source.dir' for the location of your java source folder and -# 'out.dir' for the location of your output folder. - -# You can also use it define how the release builds are signed by declaring -# the following properties: -# 'key.store' for the location of your keystore and -# 'key.alias' for the name of the key to use. -# The password will be asked during the build when you use the 'release' target. - -source.dir=src -out.dir=bin -key.store=510Connectbot.keystore -key.alias=510Connectbot diff -r 3a5df66c0480 -r 807f7e4eaebe app/build.gradle --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/build.gradle Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,89 @@ +task copyDebugLibTask(type: Copy) { + from 'build/intermediates/binaries/debug/arm/lib/armeabi' + into 'src/main/jniLibs/armeabi' +} +task copyReleaseLibTask(type: Copy) { + from 'build/intermediates/binaries/release/arm/lib/armeabi' + into 'src/main/jniLibs/armeabi' +} + +tasks.whenTaskAdded { task -> + if (task.name.contains("merge") && task.name.contains("JniLibFolders")) { + if (task.name.contains("ArmDebug")) { + task.dependsOn copyDebugLibTask + } + if (task.name.contains("ArmRelease")) { + task.dependsOn copyReleaseLibTask + } + } +} + + +apply plugin: 'com.android.application' + +android { + signingConfigs { + release { + print "\nNo Console\n" + def read = System.in.newReader().&readLine + print "\nkey store password" + storePassword = read() + print "\nkey alias password" + keyPassword = read() + print "\nDone\n" + storeFile = file("../510Connectbot.keystore") + storeType = "jks" + keyAlias = "510Connectbot" + } + } + compileSdkVersion = 16 + buildTypes { + release { + minifyEnabled = false + signingConfig = signingConfigs.release + ndk { + debuggable = false + abiFilters 'armeabi-v7a' + } + } + debug { + debuggable = true + ndk { + debuggable = true + abiFilters 'armeabi-v7a' + } + } + } + flavorDimensions "arch" + productFlavors { + arm { + dimension "arch" + } + x86 { + dimension "arch" + } + } + sourceSets { + main { + jni { + srcDir "Exec" + } + } + } + + defaultConfig { + applicationId = "com.five_ten_sg.connectbot" + minSdkVersion = 8 + targetSdkVersion = 15 + ndk { + moduleName = "com_google_ase_Exec" + } + } + + externalNativeBuild { + ndkBuild { + path "src/main/jni/Android.mk" + } + } + +} diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/AndroidManifest.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/AndroidManifest.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/java/com/five_ten_sg/connectbot/monitor/MonitorActivity.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/java/com/five_ten_sg/connectbot/monitor/MonitorActivity.java Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,106 @@ +package com.five_ten_sg.connectbot.monitor; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.net.Socket; + +import android.app.Activity; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.net.wifi.WifiManager.WifiLock; +import android.net.wifi.WifiManager; +import android.os.Binder; +import android.os.Bundle; +import android.os.Environment; +import android.os.Handler; +import android.os.IBinder; +import android.os.Message; +import android.os.PowerManager; +import android.util.Log; +import android.widget.TextView; + +public class MonitorActivity extends Activity { + public final static String TAG = "ConnectBot.MonitorActivity"; + + public static final int MESSAGE_CODE_PRINT = 6000; + private final int LINES = 20; + private String[] texts = new String[LINES]; + private int start = 0; + private int count = 0; + private TextView text = null; + private MonitorService bound = null; + private Handler handler = new Handler() { + @Override + public void handleMessage (Message msg) { + if (msg.what == MESSAGE_CODE_PRINT) { + printer((String)msg.obj); + } else { + super.handleMessage(msg); + } + } + }; + private ServiceConnection connection = new ServiceConnection() { + public void onServiceConnected(ComponentName className, IBinder service) { + Log.i(TAG, "onServiceConnected()"); + bound = ((MonitorService.MonitorBinder)service).getService(); + bound.handler = handler; + } + public void onServiceDisconnected(ComponentName className) { + Log.i(TAG, "onServiceDisconnected()"); + bound = null; + } + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + text = (TextView) findViewById(R.id.text2); + printer(getString(R.string.copyright)); + String external_dir = Environment.getExternalStorageDirectory().getAbsolutePath(); + printer(""); + printer(String.format("External directory is %s", external_dir)); + printer(""); + Log.i(TAG, "binding to monitor service"); + Intent intent = new Intent ("com.five_ten_sg.connectbot.monitor.MonitorService"); + bindService(intent, connection, Context.BIND_AUTO_CREATE); + } + + private void printer(String msg) { + if (count < LINES) count++; + else start = (start+1) % LINES; + texts[(start+count-1) % LINES] = msg + "\n"; + String c = ""; + for (int i=0; i clients = new ConcurrentHashMap(); + public static int currentConnection = -1; + + private boolean speech = false; + private TextToSpeech talker = null; + private BlockingQueue talkerQueue = null; + public Handler handler = null; + private ServerSocket serverSocket; + private Thread serverThread = null; + private WifiManager.WifiLock wifiLock; + private PowerManager.WakeLock wakeLock; + final private IBinder binder = new MonitorBinder(); + + + public class MonitorBinder extends Binder { + public MonitorService getService() { + return MonitorService.this; + } + } + + @Override + public void onInit(int status) { + if (status == TextToSpeech.SUCCESS) { + talker.setLanguage(Locale.US); + speech = true; + } + } + + @Override + public void onCreate() { + WifiManager wMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); + wifiLock = wMgr.createWifiLock(WifiManager.WIFI_MODE_FULL, "MyWifiLock"); + wifiLock.acquire(); + + PowerManager pMgr = (PowerManager) getSystemService(Context.POWER_SERVICE); + wakeLock = pMgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); + wakeLock.acquire(); + + talker = new TextToSpeech(this, this); + this.serverThread = new Thread(new ServerThread()); + this.serverThread.start(); + } + + @Override + public IBinder onBind(Intent intent) { + startService(new Intent(this, MonitorService.class)); + return binder; + } + + public void printer(String msg) { + if (handler != null) handler.sendMessage(handler.obtainMessage(MonitorActivity.MESSAGE_CODE_PRINT, msg)); + } + + public synchronized void setCurrentConnection(int connection) { + currentConnection = connection; + } + + public synchronized int nextConnection() { + int c = 1; + while (clients.get(c) != null) c++; + return c; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Log.i(TAG, "service onStartCommand()"); + return START_STICKY; + } + + @Override + public void onDestroy() { + try { + Log.i(TAG, "service onDestroy()"); + teCloseAll(); + talker.stop(); + talker.shutdown(); + wifiLock.release(); + wakeLock.release(); + serverSocket.close(); + } catch (IOException e) { + Log.e(TAG, "exception in onDestroy()", e); + } + super.onDestroy(); + } + + class ServerThread extends Thread { + public void run() { + Socket socket = null; + int connection = 0; + try { + serverSocket = new ServerSocket(MONITORPORT); + } catch (IOException e) { + Log.e(TAG, "exception in ServerThread.run(), cannot create listening socket", e); + return; + } + while (true) { + try{ + socket = serverSocket.accept(); + connection = nextConnection(); + CommunicationThread commThread = new CommunicationThread(connection, socket); + clients.put(connection, commThread); + commThread.start(); + } catch (IOException e) { + Log.e(TAG, "exception in ServerThread.run(), listening socket closed", e); + break; + } + } + } + } + + class triple { + private int l, c; + private char[] b; + public triple(int l, int c, char[] b) { + this.l = l; + this.c = c; + this.b = b; + } + } + + class CommunicationThread extends Thread { + public int thread_id; + public int connection; + private String initString = null; + private Socket client_socket; + private InputStream client_in; + private OutputStream client_out; + private boolean is_closing = false; + private Integer getfields_outstanding = 0; + private BlockingQueue value_queue = new ArrayBlockingQueue(1); + private BlockingQueue packet_queue = new ArrayBlockingQueue(10000); + + public CommunicationThread(int handle, Socket socket) { + connection = handle; + client_socket = socket; + try { + client_in = client_socket.getInputStream(); + client_out = client_socket.getOutputStream(); + } catch (IOException e) { + Log.e(TAG, "exception in CommunicationThread() constructor, cannot get socket streams", e); + } + } + + public synchronized void abandon() { + value_queue.offer(new triple(0, 0, new char[0])); + } + + public void speak(byte [] msg, boolean flush, boolean synchronous) { + if (speech) { + String smsg = bytesToString(msg); + if (synchronous) { + HashMap myHashParms = new HashMap(); + myHashParms.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, String.format("connection %d", connection)); + talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, myHashParms); + try { + String x = talkerQueue.take(); // wait for completion + } catch (InterruptedException e) { + Log.e(TAG, "exception in cm.speak()", e); + } + } + else { + talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null); + } + } + } + + public String bytesToString(byte[] b) { + char[] c = new char[b.length]; + int bp = 0; + for(int i = 0; i < c.length; i++) { + byte b1 = 0; + byte b2 = b[bp++]; + c[i] = (char) (((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); + } + return new String(c); + } + + public char[] bytesToChars(byte[] b, int len) { + char[] c = new char[len >> 1]; + int bp = 0; + for(int i = 0; i < c.length; i++) { + byte b1 = b[bp++]; + byte b2 = b[bp++]; + c[i] = (char) (((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); + } + return c; + } + + public byte[] charsToBytes(char[] c) { + byte[] b = new byte[c.length << 1]; + int bp = 0; + for (int i=0; i> 8); + b[bp++] = (byte) (c[i] & 0x00ff); + } + return b; + } + + void cleanup(char[] buf) { + int i; + for (i=0; i + + + + + + \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/res/menu/main.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/res/menu/main.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/res/values-sw600dp/dimens.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/res/values-sw600dp/dimens.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/res/values-sw720dp-land/dimens.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/res/values-sw720dp-land/dimens.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,9 @@ + + + + 128dp + + \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/res/values-v11/styles.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/res/values-v11/styles.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/res/values-v14/styles.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/res/values-v14/styles.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/res/values/dimens.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/res/values/dimens.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/res/values/strings.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/res/values/strings.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,7 @@ + + + 510 Connectbot Monitor + Maintains socket connection between 510 Connectbot terminal emulator and the monitoring application. + Settings + Copyright © 2014 by 510 Software Group. Released under the GPLv3 or later. Full source code at http://www.five-ten-sg.com/510ConnectbotMonitor/ + diff -r 3a5df66c0480 -r 807f7e4eaebe app/src/main/res/values/styles.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/src/main/res/values/styles.xml Thu Nov 08 11:39:13 2018 -0800 @@ -0,0 +1,20 @@ + + + + + + + + + \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe build.xml --- a/build.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - diff -r 3a5df66c0480 -r 807f7e4eaebe proguard-project.txt --- a/proguard-project.txt Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -# 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 *; -#} diff -r 3a5df66c0480 -r 807f7e4eaebe project.properties --- a/project.properties Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -# 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. -# - -# Project target. -target=android-16 diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-hdpi/icon.png Binary file res/drawable-hdpi/icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-hdpi/notification_icon.png Binary file res/drawable-hdpi/notification_icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-ldpi/icon.png Binary file res/drawable-ldpi/icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-ldpi/notification_icon.png Binary file res/drawable-ldpi/notification_icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-mdpi/icon.png Binary file res/drawable-mdpi/icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-mdpi/notification_icon.png Binary file res/drawable-mdpi/notification_icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-xhdpi/icon.png Binary file res/drawable-xhdpi/icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-xhdpi/notification_icon.png Binary file res/drawable-xhdpi/notification_icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-xxhdpi/icon.png Binary file res/drawable-xxhdpi/icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-xxhdpi/notification_icon.png Binary file res/drawable-xxhdpi/notification_icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-xxxhdpi/icon.png Binary file res/drawable-xxxhdpi/icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/drawable-xxxhdpi/notification_icon.png Binary file res/drawable-xxxhdpi/notification_icon.png has changed diff -r 3a5df66c0480 -r 807f7e4eaebe res/layout/main.xml --- a/res/layout/main.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ - - - - - - - \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe res/menu/main.xml --- a/res/menu/main.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ - - - - - \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe res/values-sw600dp/dimens.xml --- a/res/values-sw600dp/dimens.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe res/values-sw720dp-land/dimens.xml --- a/res/values-sw720dp-land/dimens.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ - - - - 128dp - - \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe res/values-v11/styles.xml --- a/res/values-v11/styles.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe res/values-v14/styles.xml --- a/res/values-v14/styles.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe res/values/dimens.xml --- a/res/values/dimens.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ - - - - 16dp - 16dp - - \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe res/values/strings.xml --- a/res/values/strings.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ - - - 510 Connectbot Monitor - Maintains socket connection between 510 Connectbot terminal emulator and the monitoring application. - Settings - Copyright © 2014 by 510 Software Group. Released under the GPLv3 or later. Full source code at http://www.five-ten-sg.com/510ConnectbotMonitor/ - diff -r 3a5df66c0480 -r 807f7e4eaebe res/values/styles.xml --- a/res/values/styles.xml Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - - - - - - - - - \ No newline at end of file diff -r 3a5df66c0480 -r 807f7e4eaebe src/com/five_ten_sg/connectbot/monitor/MonitorActivity.java --- a/src/com/five_ten_sg/connectbot/monitor/MonitorActivity.java Fri May 01 12:34:17 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -package com.five_ten_sg.connectbot.monitor; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.ServerSocket; -import java.net.Socket; - -import android.app.Activity; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.net.wifi.WifiManager.WifiLock; -import android.net.wifi.WifiManager; -import android.os.Binder; -import android.os.Bundle; -import android.os.Environment; -import android.os.Handler; -import android.os.IBinder; -import android.os.Message; -import android.os.PowerManager; -import android.util.Log; -import android.widget.TextView; - -public class MonitorActivity extends Activity { - public final static String TAG = "ConnectBot.MonitorActivity"; - - public static final int MESSAGE_CODE_PRINT = 6000; - private final int LINES = 20; - private String[] texts = new String[LINES]; - private int start = 0; - private int count = 0; - private TextView text = null; - private MonitorService bound = null; - private Handler handler = new Handler() { - @Override - public void handleMessage (Message msg) { - if (msg.what == MESSAGE_CODE_PRINT) { - printer((String)msg.obj); - } else { - super.handleMessage(msg); - } - } - }; - private ServiceConnection connection = new ServiceConnection() { - public void onServiceConnected(ComponentName className, IBinder service) { - Log.i(TAG, "onServiceConnected()"); - bound = ((MonitorService.MonitorBinder)service).getService(); - bound.handler = handler; - } - public void onServiceDisconnected(ComponentName className) { - Log.i(TAG, "onServiceDisconnected()"); - bound = null; - } - }; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - text = (TextView) findViewById(R.id.text2); - printer(getString(R.string.copyright)); - String external_dir = Environment.getExternalStorageDirectory().getAbsolutePath(); - printer(""); - printer(String.format("External directory is %s", external_dir)); - printer(""); - Log.i(TAG, "binding to monitor service"); - Intent intent = new Intent ("com.five_ten_sg.connectbot.monitor.MonitorService"); - bindService(intent, connection, Context.BIND_AUTO_CREATE); - } - - private void printer(String msg) { - if (count < LINES) count++; - else start = (start+1) % LINES; - texts[(start+count-1) % LINES] = msg + "\n"; - String c = ""; - for (int i=0; i clients = new ConcurrentHashMap(); - public static int currentConnection = -1; - - private boolean speech = false; - private TextToSpeech talker = null; - private BlockingQueue talkerQueue = null; - public Handler handler = null; - private ServerSocket serverSocket; - private Thread serverThread = null; - private WifiManager.WifiLock wifiLock; - private PowerManager.WakeLock wakeLock; - final private IBinder binder = new MonitorBinder(); - - - public class MonitorBinder extends Binder { - public MonitorService getService() { - return MonitorService.this; - } - } - - @Override - public void onInit(int status) { - if (status == TextToSpeech.SUCCESS) { - talker.setLanguage(Locale.US); - speech = true; - } - } - - @Override - public void onCreate() { - WifiManager wMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); - wifiLock = wMgr.createWifiLock(WifiManager.WIFI_MODE_FULL, "MyWifiLock"); - wifiLock.acquire(); - - PowerManager pMgr = (PowerManager) getSystemService(Context.POWER_SERVICE); - wakeLock = pMgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); - wakeLock.acquire(); - - talker = new TextToSpeech(this, this); - this.serverThread = new Thread(new ServerThread()); - this.serverThread.start(); - } - - @Override - public IBinder onBind(Intent intent) { - startService(new Intent(this, MonitorService.class)); - return binder; - } - - public void printer(String msg) { - if (handler != null) handler.sendMessage(handler.obtainMessage(MonitorActivity.MESSAGE_CODE_PRINT, msg)); - } - - public synchronized void setCurrentConnection(int connection) { - currentConnection = connection; - } - - public synchronized int nextConnection() { - int c = 1; - while (clients.get(c) != null) c++; - return c; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - Log.i(TAG, "service onStartCommand()"); - return START_STICKY; - } - - @Override - public void onDestroy() { - try { - Log.i(TAG, "service onDestroy()"); - teCloseAll(); - talker.stop(); - talker.shutdown(); - wifiLock.release(); - wakeLock.release(); - serverSocket.close(); - } catch (IOException e) { - Log.e(TAG, "exception in onDestroy()", e); - } - super.onDestroy(); - } - - class ServerThread extends Thread { - public void run() { - Socket socket = null; - int connection = 0; - try { - serverSocket = new ServerSocket(MONITORPORT); - } catch (IOException e) { - Log.e(TAG, "exception in ServerThread.run(), cannot create listening socket", e); - return; - } - while (true) { - try{ - socket = serverSocket.accept(); - connection = nextConnection(); - CommunicationThread commThread = new CommunicationThread(connection, socket); - clients.put(connection, commThread); - commThread.start(); - } catch (IOException e) { - Log.e(TAG, "exception in ServerThread.run(), listening socket closed", e); - break; - } - } - } - } - - class triple { - private int l, c; - private char[] b; - public triple(int l, int c, char[] b) { - this.l = l; - this.c = c; - this.b = b; - } - } - - class CommunicationThread extends Thread { - public int thread_id; - public int connection; - private String initString = null; - private Socket client_socket; - private InputStream client_in; - private OutputStream client_out; - private boolean is_closing = false; - private Integer getfields_outstanding = 0; - private BlockingQueue value_queue = new ArrayBlockingQueue(1); - private BlockingQueue packet_queue = new ArrayBlockingQueue(10000); - - public CommunicationThread(int handle, Socket socket) { - connection = handle; - client_socket = socket; - try { - client_in = client_socket.getInputStream(); - client_out = client_socket.getOutputStream(); - } catch (IOException e) { - Log.e(TAG, "exception in CommunicationThread() constructor, cannot get socket streams", e); - } - } - - public synchronized void abandon() { - value_queue.offer(new triple(0, 0, new char[0])); - } - - public void speak(byte [] msg, boolean flush, boolean synchronous) { - if (speech) { - String smsg = bytesToString(msg); - if (synchronous) { - HashMap myHashParms = new HashMap(); - myHashParms.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, String.format("connection %d", connection)); - talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, myHashParms); - try { - String x = talkerQueue.take(); // wait for completion - } catch (InterruptedException e) { - Log.e(TAG, "exception in cm.speak()", e); - } - } - else { - talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null); - } - } - } - - public String bytesToString(byte[] b) { - char[] c = new char[b.length]; - int bp = 0; - for(int i = 0; i < c.length; i++) { - byte b1 = 0; - byte b2 = b[bp++]; - c[i] = (char) (((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); - } - return new String(c); - } - - public char[] bytesToChars(byte[] b, int len) { - char[] c = new char[len >> 1]; - int bp = 0; - for(int i = 0; i < c.length; i++) { - byte b1 = b[bp++]; - byte b2 = b[bp++]; - c[i] = (char) (((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); - } - return c; - } - - public byte[] charsToBytes(char[] c) { - byte[] b = new byte[c.length << 1]; - int bp = 0; - for (int i=0; i> 8); - b[bp++] = (byte) (c[i] & 0x00ff); - } - return b; - } - - void cleanup(char[] buf) { - int i; - for (i=0; i