Clipboard Support, added test mode for debugging purposes

This commit is contained in:
José Pereira 2010-12-25 15:33:52 +00:00
parent 160c4b7447
commit 0d977f4689
38 changed files with 143 additions and 138 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.onaips.vnc" android:versionName="0.98 will now use only busybox, if you don't have it, it will ask for it. I'm going to merge donate and free versions in time." android:versionCode="50">
package="org.onaips.vnc" android:versionName="0.991" android:versionCode="52">
<uses-sdk android:minSdkVersion="3" />
<application android:debuggable="false" android:icon="@drawable/icon"
android:label="droid VNC server" android:name="MainApplication">
@ -19,6 +19,7 @@
<activity android:name="com.mobclix.android.sdk.MobclixBrowserActivity" />
<service android:name="StartAtBootService">
<intent-filter>
<action android:name="org.onaips.vnc.StartAtBootService"></action>
@ -34,14 +35,8 @@
</intent-filter>
</receiver>
<receiver android:name=".DaemonCommunication">
<intent-filter>
<action android:name="org.onaips.vnc.intent.action.DaemonCommunication.ClientConnected" />
<action android:name="org.onaips.vnc.intent.action.DaemonCommunication.ClientDisconnected" />
</intent-filter>
</receiver>
</application>
<service android:name="avncservice"></service>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"></uses-permission>
@ -51,5 +46,6 @@
<uses-permission android:name="android.permission.GET_TASKS"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
</manifest>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,9 +13,10 @@ public final class R {
public static final int rotation_values=0x7f070000;
public static final int scale_strings=0x7f070003;
public static final int scale_values=0x7f070002;
public static final int sleep_strings=0x7f070004;
public static final int startonboot_strings=0x7f070005;
public static final int startonboot_values=0x7f070006;
public static final int sleep_strings=0x7f070005;
public static final int startonboot_strings=0x7f070006;
public static final int startonboot_values=0x7f070007;
public static final int test_mode_strings=0x7f070004;
}
public static final class attr {
/** <p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",

Binary file not shown.

View File

@ -27,6 +27,13 @@
<item>30</item>
<item>20</item>
</string-array>
<string-array name="test_mode_strings">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
<string-array name="sleep_strings">
<item>On</item>
<item>Off</item>

View File

@ -11,5 +11,7 @@
<CheckBoxPreference android:key="screenturnoff" android:title="Don't let screen turn off" android:defaultValue="false"></CheckBoxPreference>
<CheckBoxPreference android:key="notifyclient" android:title="Notify when client connects" android:summary="Show notification on status bar" android:defaultValue="true"></CheckBoxPreference>
<CheckBoxPreference android:key="hidead" android:defaultValue="false" android:title="Disable Bottom Ad" android:summary="Select this if you don't want to view the ad."></CheckBoxPreference>
<ListPreference android:title="Screen Test Mode" android:summary="DANGEROUS: enable this to fix screen issues" android:key="testmode" android:entries="@array/test_mode_strings" android:entryValues="@array/test_mode_strings"></ListPreference>
</PreferenceScreen>

View File

@ -1,48 +0,0 @@
package org.onaips.vnc;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.util.Log;
public class DaemonCommunication extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.v("VNC","daemoncom" + action);
Intent i=null;
if (action.equalsIgnoreCase("org.onaips.vnc.intent.action.DaemonCommunication.ClientConnected"))
{
i = new Intent("org.onaips.vnc.CLIENTCONNECTED");
i.putExtra("clientip", intent.getStringExtra("clientip"));
}
else if (action.equalsIgnoreCase("org.onaips.vnc.intent.action.DaemonCommunication.ClientDisconnected"))
{
i = new Intent("org.onaips.vnc.CLIENTDISCONNECTED");
}
context.sendOrderedBroadcast(i, null, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int result = getResultCode();
if (result != Activity.RESULT_CANCELED) {
Log.d("VNC", "Activity caught the broadcast, result "+result);
return; // Activity caught it
}
Log.d("VNC", "Activity did not catch the broadcast");
}
}, null, Activity.RESULT_CANCELED, null, null);
}
}

View File

@ -23,9 +23,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Array;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Timer;
@ -59,6 +61,8 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.net.NetworkInfo;
import android.net.Uri;
import android.net.NetworkInfo.DetailedState;
@ -66,8 +70,10 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.text.ClipboardManager;
import android.text.Html;
import android.util.Log;
import android.view.Menu;
@ -90,7 +96,9 @@ public class MainActivity extends Activity
private static final int MENU_SENDLOG = 3;
private static final int MENU_CHANGELOG = 4;
private static final int APP_ID = 123;
private static final String changelog="- [Fix] Start/stop server now handled by busybox, it will ask if you don't have it (please report if you still have the issue) - Sorry for that";
private static final String changelog="- [Add] Clipboard text support!";
public static String SOCKET_ADDRESS = "org.onaips.vnc.localsocket";
private PowerManager.WakeLock wakeLock = null;
private Timer watchdogTimer=null;
@ -105,7 +113,6 @@ public class MainActivity extends Activity
{
super.onDestroy();
unregisterReceiver(mReceiver);
unregisterReceiver(activityReceiver);
}
@ -161,8 +168,9 @@ public class MainActivity extends Activity
// register wifi event receiver
registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
registerReceiver(activityReceiver, new IntentFilter("org.onaips.vnc.CLIENTCONNECTED"));
registerReceiver(activityReceiver, new IntentFilter("org.onaips.vnc.CLIENTDISCONNECTED"));
SocketListener s=new SocketListener();
s.start();
setStateLabels(isAndroidServerRunning());
@ -258,10 +266,6 @@ public class MainActivity extends Activity
return version;
}
public boolean free_version()
{
return getPackageName().equals("org.onaips.vnc");
}
public void showInitialScreen(boolean forceShow)
{
@ -282,8 +286,7 @@ public class MainActivity extends Activity
startDialog.setMessage(Html.fromHtml(changelog));
startDialog.setIcon(R.drawable.icon);
if (free_version())
{
startDialog.setButton(AlertDialog.BUTTON1,"OK", new DialogInterface.OnClickListener() {
@Override
@ -292,19 +295,17 @@ public class MainActivity extends Activity
}
});
startDialog.setButton2("Donate Version", new DialogInterface.OnClickListener() {
startDialog.setButton2("Donate", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=org.onaips.vnc_donate"));
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=org.onaips.donate"));
startActivity(myIntent);
}
});
startDialog.show();
}
else
startDialog.show();
}
@ -431,13 +432,13 @@ public class MainActivity extends Activity
}
else
{
writeCommand(os, "killall androidvncserver");
writeCommand(os, "killall -KILL androidvncserver");
if (findExecutableOnPath("killall")==null)
{
showTextOnScreen("I couldn't find the killall executable, please install busybox or i can't stop server");
Log.v("VNC","I couldn't find the killall executable, please install busybox or i can't stop server");
}
writeCommand(os, "killall androidvncserver");
writeCommand(os, "killall -KILL androidvncserver");
}
writeCommand(os, "exit");
@ -497,9 +498,10 @@ public class MainActivity extends Activity
if (!scaling.equals("0"))
scaling_string="-s " + scaling;
String donate=free_version()?"":" -d ";
String port=preferences.getString("port", "5901");
String tm=preferences.getString("testmode", "0");
String testmode="-t " + tm;
try
{
int port1=Integer.parseInt(port);
@ -516,10 +518,10 @@ public class MainActivity extends Activity
OutputStream os = sh.getOutputStream();
writeCommand(os, "chmod 777 " + getFilesDir().getAbsolutePath() + "/androidvncserver");
writeCommand(os,getFilesDir().getAbsolutePath() + "/androidvncserver "+ password_check + " " + rotation + " " + scaling_string + " " + port_string + donate);
writeCommand(os,getFilesDir().getAbsolutePath() + "/androidvncserver "+ password_check + " " + rotation + " " + scaling_string + " " + port_string +" " + testmode);
//dont show password on logcat
Log.v("VNC","Starting " + getFilesDir().getAbsolutePath() + "/androidvncserver " + " " + rotation + " " + scaling_string + " " + port_string + donate);
Log.v("VNC","Starting " + getFilesDir().getAbsolutePath() + "/androidvncserver " + " " + rotation + " " + scaling_string + " " + port_string + " " + testmode);
} catch (IOException e) {
@ -789,17 +791,14 @@ public class MainActivity extends Activity
}
};
public BroadcastReceiver activityReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context1, Intent intent) {
if (intent.getAction().equalsIgnoreCase("org.onaips.vnc.CLIENTCONNECTED") && (preferences.getBoolean("notifyclient", true)))
{
public void showClientConnected(String c)
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = intent.getStringExtra("clientip") + " connected to VNC server";
CharSequence tickerText = c + " connected to VNC server";
long when = System.currentTimeMillis();
@ -807,13 +806,12 @@ public class MainActivity extends Activity
Context context = getApplicationContext();
CharSequence contentTitle = "Droid VNC Server";
CharSequence contentText = "Client Connected from " + intent.getStringExtra("clientip");
CharSequence contentText = "Client Connected from " + c;
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(context1, 0, notificationIntent, 0);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(APP_ID, notification);
//lets see if we should keep screen on
@ -824,7 +822,8 @@ public class MainActivity extends Activity
wakeLock.acquire();
}
}
else if (intent.getAction().equalsIgnoreCase("org.onaips.vnc.CLIENTDISCONNECTED"))
void showClientDisconnected()
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
@ -834,8 +833,54 @@ public class MainActivity extends Activity
wakeLock.release();
}
class SocketListener extends Thread {
@Override
public void run() {
try {
LocalServerSocket server = new LocalServerSocket(SOCKET_ADDRESS);
while (true) {
LocalSocket receiver = server.accept();
if (receiver != null) {
InputStream input = receiver.getInputStream();
int readed = input.read();
StringBuffer bytes=new StringBuffer(2048);
while (readed != -1) {
bytes.append((char) readed);
readed = input.read();
}
//showTextOnScreen(bytes.toString());
Log.v("VNC",bytes.substring(0, 6));
if (bytes.substring(0, 6).equals("~CLIP|"))
{
bytes.delete(0, 6);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(bytes.toString());
}
else if (preferences.getBoolean("notifyclient", true))
{
if (bytes.substring(0, 11).equals("~CONNECTED|"))
{
bytes.delete(0, 11);
showClientConnected(bytes.toString());
}
else if (bytes.substring(0, 14).equals("~DISCONNECTED|"))
{
showClientDisconnected();
}
}
}
}
} catch (IOException e) {
Log.e(getClass().getName(), e.getMessage());
}
}
}
};
private static File findExecutableOnPath(String executableName)
{

View File

@ -60,6 +60,8 @@ public class MainApplication extends Application {
OutputStream os = sh.getOutputStream();
writeCommand(os, "killall androidvncserver");
writeCommand(os, "killall -KILL androidvncserver");
//chmod 777 SHOULD exist
writeCommand(os, "chmod 777 " + getFilesDir().getAbsolutePath() + "/androidvncserver");
os.close();