merge commit a=backout
authorClint Talbert <ctalbert@mozilla.com>
Thu, 16 Dec 2010 16:53:31 -0800
changeset 59428 51795db981f2dc408a244fc75b748c94519bc765
parent 59426 2020888cd34f6378fea834425c9524a9d7a47357 (current diff)
parent 59427 ba9da51f5129fa1cc904387591cae0df48e563a6 (diff)
child 59429 c6c33df76468e285a7eb0bc322fd778478dd8349
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersbackout
milestone2.0b9pre
merge commit a=backout
build/mobile/sutagent/android/DoCommand.java
build/mobile/sutagent/android/SUTAgentAndroid.java
--- a/build/mobile/sutagent/android/ASMozStub.java
+++ b/build/mobile/sutagent/android/ASMozStub.java
@@ -110,12 +110,13 @@ public class ASMozStub extends android.a
 		Toast.makeText(this, "Listener Service destroyed...", Toast.LENGTH_LONG).show();
 		
 		System.exit(0);
 		}
 	
 	public void SendToDataChannel(String strToSend)
 		{
 		if (runDataThrd.isAlive())
+			{
 			runDataThrd.SendToDataChannel(strToSend);
+			}
 		}
-	
 }
--- a/build/mobile/sutagent/android/DoCommand.java
+++ b/build/mobile/sutagent/android/DoCommand.java
@@ -46,24 +46,26 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.PrintWriter;
+import java.lang.reflect.Field;
 import java.net.Socket;
 import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.TimeZone;
 import java.util.Timer;
 import java.util.zip.Adler32;
@@ -81,54 +83,54 @@ import org.apache.commons.net.ftp.FTPRep
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.DefaultHttpClient;
 
 import com.mozilla.SUTAgentAndroid.SUTAgentAndroid;
+
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.AlarmManager;
 import android.content.ActivityNotFoundException;
-import android.content.ComponentName;
 import android.content.Context;
 import android.content.ContextWrapper;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
-import android.content.pm.ServiceInfo;
 import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Configuration;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Debug;
 import android.os.Environment;
 import android.os.StatFs;
 import android.os.SystemClock;
+import android.provider.Settings;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.WindowManager;
 
 public class DoCommand {
 	
 	String lineSep = System.getProperty("line.separator");
 	Process	pProc;
 	OutputStream sutIn;
 	InputStream	sutErr;
 	InputStream	sutOut;
 	AlertLooperThread alrt = null;
 	ContextWrapper	contextWrapper = null;
 	
 	String	currentDir = "/";
 	String	sErrorPrefix = "##AGENT-WARNING## ";
-	boolean bTraceOn = false;
 	
-	private final String prgVersion = "SUTAgentAndroid Version 0.94";
+	private final String prgVersion = "SUTAgentAndroid Version 0.87";
 	
 	public enum Command
 		{
 		RUN ("run"),
 		EXEC ("exec"),
 		ENVRUN ("envrun"),
 		KILL ("kill"),
 		PS ("ps"),
@@ -149,22 +151,20 @@ public class DoCommand {
 		CP ("cp"),
 		TIME ("time"),
 		HASH ("hash"),
 		CD ("cd"),
 		CAT ("cat"),
 		CWD ("cwd"),
 		MV ("mv"),
 		PUSH ("push"),
-		PULL ("pull"),
 		RM ("rm"),
 		PRUNE ("rmdr"),
 		MKDR ("mkdr"),
 		DIRWRITABLE ("dirw"),
-		ISDIR ("isdir"),
 		DEAD ("dead"),
 		MEMS ("mems"),
 		LS ("ls"),
 		TMPD ("tmpd"),
 		PING ("ping"),
 		REBT ("rebt"),
 		UNZP ("unzp"),
 		ZIP ("zip"),
@@ -174,18 +174,16 @@ public class DoCommand {
 		EXIT ("exit"),
 		HELP ("help"),
 		FTPG ("ftpg"),
 		FTPP ("ftpp"),
 		INST ("inst"),
 		UPDT ("updt"),
 		UNINST ("uninst"),
 		TEST ("test"),
-		DBG ("dbg"),
-		TRACE ("trace"),
 		VER ("ver"),
 		TZGET ("tzget"),
 		TZSET ("tzset"),
 		UNKNOWN ("unknown");
 		
 		private final String theCmd;
 		
 		Command(String theCmd) { this.theCmd = theCmd; }
@@ -206,41 +204,31 @@ public class DoCommand {
 			return (retCmd);
 			}
 		}
 	
 	public DoCommand(ContextWrapper service)
 		{
 		this.contextWrapper = service;
 		}
-
+	
 	public String processCommand(String theCmdLine, PrintWriter out, BufferedInputStream in, OutputStream cmdOut)
 		{
 		String 	strReturn = "";
 		Command	cCmd = null;
 		Command cSubCmd = null;
 		
-		if (bTraceOn)
-			((ASMozStub)this.contextWrapper).SendToDataChannel(theCmdLine);
-		
 		String [] Argv = parseCmdLine2(theCmdLine);
 		
 		int Argc = Argv.length;
 		
 		cCmd = Command.getCmd(Argv[0]);
 		
 		switch(cCmd)
 			{
-			case TRACE:
-				if (Argc == 2)
-					bTraceOn = (Argv[1].equalsIgnoreCase("on") ? true : false);
-				else
-					strReturn = sErrorPrefix + "Wrong number of arguments for trace command!";
-				break;
-				
 			case VER:
 				strReturn = prgVersion;
 				break;
 				
 			case CLOK:
 				strReturn = GetClok();
 				break;
 				
@@ -251,17 +239,17 @@ public class DoCommand {
 			case TZSET:
 				if (Argc == 2)
 					strReturn = SetTimeZone(Argv[1]);
 				else
 					strReturn = sErrorPrefix + "Wrong number of arguments for settz command!";
 				break;
 				
 			case UPDT:
-				strReturn = StrtUpdtOMatic(Argv[1], Argv[2], (Argc > 3 ? Argv[3] : null), (Argc > 4 ? Argv[4] : null));
+				strReturn = StartUpdateOMatic(Argv[1], Argv[2]);
 				break;
 			
 			case SETTIME:
 				strReturn = SetSystemTime(Argv[1], Argv[2], cmdOut);
 				break;
 			
 			case CWD:
 				try {
@@ -286,45 +274,31 @@ public class DoCommand {
 				
 			case GETAPPROOT:
 				if (Argc == 2)
 					strReturn = GetAppRoot(Argv[1]);
 				else
 					strReturn = sErrorPrefix + "Wrong number of arguments for getapproot command!";
 				break;
 				
-			case ISDIR:
-				if (Argc == 2)
-					strReturn = isDirectory(Argv[1]);
-				else
-					strReturn = sErrorPrefix + "Wrong number of arguments for isdir command!";
-				break;
-				
 			case TESTROOT:
 				strReturn = GetTestRoot();
 				break;
 				
 			case DEAD:
 				if (Argc == 2)
 					strReturn = (IsProcessDead(Argv[1]) ? (Argv[1] + " is hung or unresponsive") : (Argv[1] + " is ok"));
 				else
 					strReturn = sErrorPrefix + "Wrong number of arguments for dead command!";
 				break;
 				
 			case PS:
 				strReturn = GetProcessInfo();
 				break;
 				
-			case PULL:
-				if (Argc == 2)
-					strReturn = Pull(Argv[1], cmdOut);
-				else
-					strReturn = sErrorPrefix + "Wrong number of arguments for pull command!";
-				break;
-				
 			case PUSH:
 				if (Argc == 3)
 					{
 					long lArg = 0;
 				    try
 				    	{
 				        lArg = Long.parseLong(Argv[2].trim());
 				        System.out.println("long l = " + lArg);
@@ -504,17 +478,17 @@ public class DoCommand {
 				else
 					strReturn = sErrorPrefix + "Wrong number of arguments for mkdr command!";
 				break;
 				
 			case RM:
 				if (Argc == 2)
 					strReturn = RemoveFile(Argv[1]);
 				else
-					strReturn = sErrorPrefix + "Wrong number of arguments for rm command!";
+					strReturn = sErrorPrefix + "Wrong number of arguments for mkdr command!";
 				break;
 				
 			case MV:
 				if (Argc == 3)
 					strReturn = Move(Argv[1], Argv[2]);
 				else
 					strReturn = sErrorPrefix + "Wrong number of arguments for mv command!";
 				break;
@@ -526,25 +500,193 @@ public class DoCommand {
 					strReturn = sErrorPrefix + "Wrong number of arguments for cp command!";
 				break;
 				
 			case QUIT:
 			case EXIT:
 				strReturn = Argv[0];
 				break;
 				
-			case DBG:
-		        Debug.waitForDebugger();
-		        strReturn = "waitForDebugger on";
+			case TEST:
+//				boolean bRet = false;
+/*				
+				Configuration userConfig = new Configuration();
+				Settings.System.getConfiguration( contextWrapper.getContentResolver(), userConfig );
+				Calendar cal = Calendar.getInstance( userConfig.locale);
+				TimeZone ctz = cal.getTimeZone();
+				String sctzLongName = ctz.getDisplayName();
+				String pstzName = TimeZone.getDefault().getDisplayName();
+*/
+				String sTimeZoneName = GetTimeZone();
+				
+				TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
+				TimeZone tz2 = TimeZone.getTimeZone("GMT-08:00");
+				int	nOffset = (-8 * 3600000);
+				String [] zoneNames = TimeZone.getAvailableIDs(nOffset);
+				int nNumMatches = zoneNames.length;
+				TimeZone.setDefault(tz);
+				
+				String sOldTZ = System.setProperty("persist.sys.timezone", "America/Los_Angeles");
+				
+/*				
+				byte[] buffer = new byte [4096];
+				int	nRead = 0;
+				long lTotalRead = 0;
+
+				Context ctx = SUTAgentAndroid.me.getApplicationContext();
+
+				FTPClient ftp = new FTPClient();
+				try 
+					{
+					String strRet = "";
+					int	reply = 0;
+					FileOutputStream outStream = null;
+					
+					ftp.connect("ftp.mozilla.org");
+					strRet = ftp.getReplyString();
+					reply = ftp.getReplyCode();
+					
+				    if(!FTPReply.isPositiveCompletion(reply))
+				    	{
+				        ftp.disconnect();
+				        System.err.println("FTP server refused connection.");
+				        System.exit(1);
+				        }
+				    // transfer files
+				    
+				    ftp.login("anonymous", "b@t.com");
+					strRet = ftp.getReplyString();
+					reply = ftp.getReplyCode();
+					
+				    if(!FTPReply.isPositiveCompletion(reply))
+				    	{
+				        ftp.disconnect();
+				        System.err.println("FTP server refused connection.");
+				        System.exit(1);
+				        }
+				    
+				    ftp.enterLocalPassiveMode();
+				    
+				    if (ftp.setFileType(FTP.BINARY_FILE_TYPE))
+				    	{
+				    	File root = Environment.getExternalStorageDirectory();
+				    	if (root.canWrite())
+				    		{
+				    		File outFile = new File(root, "firefox-3.6b4.cab");
+				    		outStream = new FileOutputStream(outFile);
+				    		}
+				    	else
+				    		outStream = ctx.openFileOutput("firefox-3.6b4.cab", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
+//				    	outStream = new FileOutputStream("/sdcard/firefox-3.6b4.cab");
+				    	InputStream ftpIn = ftp.retrieveFileStream("pub/mozilla.org/firefox/releases/3.6b4/wince-arm/en-US/firefox-3.6b4.cab");
+						while ((nRead = ftpIn.read(buffer)) != -1)
+							{
+							lTotalRead += nRead;
+							outStream.write(buffer, 0, nRead);
+							strRet = "\r" + lTotalRead + " bytes received";
+							cmdOut.write(strRet.getBytes());
+							cmdOut.flush();
+							}
+						
+						ftpIn.close();
+						boolean bRet = ftp.completePendingCommand();
+						outStream.flush();
+
+				    	/*				    	
+				    	if (ftp.retrieveFile("pub/mozilla.org/firefox/releases/3.6b4/wince-arm/en-US/firefox-3.6b4.cab", outStream))
+				    		{
+				    		outStream.flush();
+				    		}
+				    	 * /				    		
+			    		outStream.close();
+						strRet = ftp.getReplyString();
+						reply = ftp.getReplyCode();
+				    	}
+					strRet = ftp.getReplyString();
+					reply = ftp.getReplyCode();
+				    ftp.logout();
+				    
+				    strReturn = "\r\n" + strRet; 
+					}
+				catch (SocketException e)
+					{
+					// TODO Auto-generated catch block
+					strReturn = e.getMessage();
+					e.printStackTrace();
+					}
+				catch (IOException e)
+					{
+					// TODO Auto-generated catch block
+					strReturn = e.getMessage();
+					e.printStackTrace();
+					}
+*/				
+//				strReturn = InstallApplication();
+//				strReturn = InstallApp(Argv[1], cmdOut);
+				
+//				strReturn = UninstallApplication();
+//				String sPingCheck = SendPing("www.mozilla.org",null);
+//				if (sPingCheck.contains("3 received"))
+//					strReturn = sPingCheck;
+//				RunReboot(cmdOut);
+/*
+				try 
+					{
+					FileOutputStream outFile = ctx.openFileOutput("test.txt", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
+					OutputStreamWriter outS = new OutputStreamWriter(outFile);
+					outS.write("Hello world 1" + lineSep);
+					outS.write("Hello world 2" + lineSep);
+					outS.write("Hello world 3" + lineSep);
+					outS.write("Hello world 4" + lineSep);
+					outS.flush();
+					outS.close();
+					
+					String [] files = ctx.fileList();
+					File aFile   = ctx.getFilesDir();
+					String aPath = aFile.getCanonicalPath();
+					String hold = aFile.getName();
+					
+					strReturn = PrintDir(aPath);
+					strReturn += "\r\n";
+					
+					String src = aPath + "/test.txt";
+					String dst = aPath + "/test2.txt";
+					strReturn += CopyFile(src, dst);
+					strReturn += "\r\n";
+					
+					strReturn += PrintDir(aPath);
+					strReturn += "\r\n";
+					
+					dst = aPath + "/test3.txt";
+					strReturn += Move(src, dst);
+					strReturn += "\r\n";
+					
+					strReturn += PrintDir(aPath);
+					strReturn += "\r\n";
+
+					src = aPath + "/test2.txt";
+					strReturn += RemoveFile(src);
+					strReturn += "\r\n";
+					strReturn += RemoveFile(dst);
+					strReturn += "\r\n";
+					strReturn += PrintDir(aPath);
+					}
+				catch (FileNotFoundException e)
+					{
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+					} 
+				catch (IOException e) 
+					{
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+					}
+*/
 				break;
 				
-			case TEST:
-				break;
-				
-			case EXEC:
 			case ENVRUN:
 				if (Argc >= 2)
 					{
 					String [] theArgs = new String [Argc - 1];
 			
 					for (int lcv = 1; lcv < Argc; lcv++)
 						{
 						theArgs[lcv - 1] = Argv[lcv];
@@ -553,39 +695,42 @@ public class DoCommand {
 					strReturn = StartPrg2(theArgs, cmdOut);
 					}
 				else
 					{
 					strReturn = sErrorPrefix + "Wrong number of arguments for " + Argv[0] + " command!";
 					}
 				break;
 				
+			case EXEC:
 			case RUN:
 				if (Argc >= 2)
 					{
 					String [] theArgs = new String [Argc - 1];
 				
 					for (int lcv = 1; lcv < Argc; lcv++)
 						{
 						theArgs[lcv - 1] = Argv[lcv];
 						}
 				
 					if (Argv[1].contains("/") || Argv[1].contains("\\") || !Argv[1].contains("."))
 						strReturn = StartPrg(theArgs, cmdOut);
 					else
-						strReturn = StartJavaPrg(theArgs, null);
+						strReturn = StartJavaPrg(theArgs);
 					}
 				else
 					{
 					strReturn = sErrorPrefix + "Wrong number of arguments for " + Argv[0] + " command!";
 					}
 				break;
 
 			case KILL:
 				if (Argc == 2)
+//					strReturn = NewKillProc(Argv[1], Argv[2], cmdOut);
+//					strReturn = NewKillProc(Argv[1], cmdOut);
 					strReturn = KillProcess(Argv[1], cmdOut);
 				else
 					strReturn = sErrorPrefix + "Wrong number of arguments for kill command!";
 				break;
 				
 			case DISK:
 				strReturn = GetDiskInfo((Argc == 2 ? Argv[1] : "/"));
 				break;
@@ -920,28 +1065,31 @@ public class DoCommand {
 					{
 					nStart = 0;
 					nEnd++;
 					}
 				}
 			else // no quote so find the next space
 				{
 				nEnd = workingString.indexOf(' ', nStart);
-				
 				// there isn't one of those
 				if (nEnd == -1)
 					nEnd = nLength;	// Just grab the rest of the cmdline
 				}
 			
 			// get the substring
 			workingString2 = workingString.substring(nStart, nEnd);
 			
 			// add it to the list
 			lst.add(new String(workingString2));
 			
+			// if we are dealing with a quote
+//			if (nStart > 0)
+//				nEnd++; //  point past the end one
+			
 			// jump past the substring and trim it
 			workingString = (workingString.substring(nEnd)).trim();
 			}
 		
 		int nItems = lst.size();
 		
 		String [] theArgs = new String [nItems];
 		
@@ -1200,17 +1348,17 @@ public class DoCommand {
 			sRet = GetTmpDir();			
 			}
 		
 		return(sRet);
 		}
 	
 	public String GetAppRoot(String AppName)
 		{
-		String sRet = sErrorPrefix + " internal error [no context]";
+		String sRet = "";
 		Context ctx = contextWrapper.getApplicationContext();
 		
 		if (ctx != null)
 			{
 			try {
 				Context appCtx = ctx.createPackageContext(AppName, 0);
 				ContextWrapper appCtxW = new ContextWrapper(appCtx);
 				sRet = appCtxW.getPackageResourcePath();
@@ -1221,79 +1369,33 @@ public class DoCommand {
 				}
 			catch (NameNotFoundException e)
 				{
 				e.printStackTrace();
 				}
 			}
 		return(sRet);
 		}
-	
-	public String isDirectory(String sDir)
-		{
-		String	sRet = sErrorPrefix + sDir + " does not exist";
-		String	tmpDir	= fixFileName(sDir);
-		String [] theArgs = new String [3];
-		
-		theArgs[0] = "su";
-		theArgs[1] = "-c";
-		theArgs[2] = "ls -l " + sDir;
-		
-		File tmpFile = new java.io.File(tmpDir);
-		
-		if (tmpFile.exists())
-			{
-			sRet = (tmpFile.isDirectory() ? "TRUE" : "FALSE");
-			}
-		else
-			{
-			try 
-				{
-				pProc = Runtime.getRuntime().exec(theArgs);
-				RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
-				outThrd.start();
-				outThrd.join(5000);
-				sRet = outThrd.strOutput;
-				if (!sRet.contains("No such file or directory") && sRet.startsWith("l"))
-					sRet = "FALSE";
-				}
-			catch (IOException e) 
-				{
-				sRet = e.getMessage();
-				e.printStackTrace();
-				} 
-			catch (InterruptedException e)
-				{
-				e.printStackTrace();
-				}
-			}
-		
-		return(sRet);
-		}
 
 	public String changeDir(String newDir)
 		{
 		String	tmpDir	= fixFileName(newDir);
 		String	sRet = sErrorPrefix + "Couldn't change directory to " + tmpDir;
 		
 		File tmpFile = new java.io.File(tmpDir);
 		
 		if (tmpFile.exists())
 			{
 			try {
-				if (tmpFile.isDirectory())
-					{
-					currentDir = tmpFile.getCanonicalPath();
-					sRet = "";
-					}
-				else
-					sRet = sErrorPrefix + tmpDir + " is not a valid directory";
+				currentDir = tmpFile.getCanonicalPath();
+				sRet = "";
 				}
 			catch (IOException e)
 				{
+				// TODO Auto-generated catch block
 				e.printStackTrace();
 				}
 			}
 		
 		return(sRet);
 		}
 	
 	static final String HEXES = "0123456789abcdef";
@@ -1659,78 +1761,35 @@ public class DoCommand {
 			strRet = ftp.getReplyString();
 			reply = ftp.getReplyCode();
 			sRet += "\n" + strRet;
 			e.printStackTrace();
 			}
 		return (sRet);
 	}
 	
-	public String Pull(String fileName, OutputStream out)
-		{
-		String	sTmpFileName = fixFileName(fileName);
-		String	sRet = sErrorPrefix + "Could not read the file " + sTmpFileName;
-		byte[]	buffer = new byte [4096];
-		int		nRead = 0;
-	
-		try {
-			File f = new File(sTmpFileName);
-			long lFileLength = f.length();
-			FileInputStream fin = new FileInputStream(f);
-			if (lFileLength == 0)
-				{
-				while ((nRead = fin.read(buffer)) != -1)
-					{
-					lFileLength += nRead;
-					}
-				fin.close();
-				fin = new FileInputStream(f);
-				}
-			
-			String sTmp = sTmpFileName + "," + lFileLength + "\n";
-			out.write(sTmp.getBytes());
-			while ((nRead = fin.read(buffer)) != -1)
-				{
-				out.write(buffer,0,nRead);
-				}
-			fin.close();
-			out.flush();
-			sRet = "";
-			}
-		catch (FileNotFoundException e)
-			{
-			sRet = sErrorPrefix + sTmpFileName + ",-1\nNo such file or directory";
-			} 
-		catch (IOException e) 
-			{
-			sRet = e.toString();
-			}
-		return (sRet);
-		}
-
 	public String Cat(String fileName, OutputStream out)
 		{
 		String	sTmpFileName = fixFileName(fileName);
 		String	sRet = sErrorPrefix + "Could not read the file " + sTmpFileName;
 		byte[]	buffer = new byte [4096];
 		int		nRead = 0;
 		
 		try {
 			FileInputStream fin = new FileInputStream(sTmpFileName);
 			while ((nRead = fin.read(buffer)) != -1)
 				{
 				out.write(buffer,0,nRead);
 				}
-			fin.close();
 			out.flush();
 			sRet = "";
 			}
 		catch (FileNotFoundException e)
 			{
-			sRet = sErrorPrefix + sTmpFileName + " No such file or directory";
+			sRet = e.toString();
 			} 
 		catch (IOException e) 
 			{
 			sRet = e.toString();
 			}
 		return (sRet);
 		}
 	
@@ -1931,66 +1990,16 @@ public class DoCommand {
 		ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE);
 		ActivityManager.MemoryInfo outInfo = new ActivityManager.MemoryInfo();
 		aMgr.getMemoryInfo(outInfo);
 		long lMem = outInfo.availMem;
 
 		return (lMem);
 		}
 	
-	public String UpdateCallBack(String sFileName)
-		{
-		String sRet = sErrorPrefix + "No file specified";
-		String sIP = "";
-		String sPort = "";
-		int nEnd = 0;
-		int nStart = 0;
-		
-		if ((sFileName == null) || (sFileName.length() == 0))
-			return(sRet);
-			
-		Context ctx = contextWrapper.getApplicationContext();
-		try {
-			FileInputStream fis = ctx.openFileInput(sFileName);
-			int nBytes = fis.available();
-			if (nBytes > 0)
-				{
-				byte [] buffer = new byte [nBytes + 1];
-				int nRead = fis.read(buffer, 0, nBytes);
-				fis.close();
-				ctx.deleteFile(sFileName);
-				if (nRead > 0)
-					{
-					String sBuffer = new String(buffer);
-					nEnd = sBuffer.indexOf(',');
-					if (nEnd > 0)
-						{
-						sIP = (sBuffer.substring(0, nEnd)).trim();
-						nStart = nEnd + 1;
-						nEnd = sBuffer.indexOf('\r', nStart);
-						if (nEnd > 0)
-							{
-							sPort = (sBuffer.substring(nStart, nEnd)).trim();
-							sRet = RegisterTheDevice(sIP, sPort, sBuffer.substring(nEnd + 1));
-							}
-						}
-					}
-				}
-			} 
-		catch (FileNotFoundException e)
-			{
-			sRet = sErrorPrefix + "Nothing to do";
-			} 
-		catch (IOException e)
-			{
-			sRet = sErrorPrefix + "Couldn't send info to " + sIP + ":" + sPort;
-			}
-		return(sRet);
-		}
-	
 	public String RegisterTheDevice(String sSrvr, String sPort, String sData)
 		{
 		String sRet = "";
 		String line = "";
 		
 		if (sSrvr != null && sPort != null && sData != null)
 			{
 			try
@@ -2001,30 +2010,23 @@ public class DoCommand {
 				BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
 				out.println(sData);
 				if ( out.checkError() == false )
 					{
 					socket.setSoTimeout(30000);
 					while (socket.isInputShutdown() == false)
 						{
 						line = in.readLine();
-						
-						if (line != null)
+						line = line.toLowerCase();
+						if ((line == null) || (line.contains("ok")))
 							{
-							line = line.toLowerCase();
 							sRet += line;
-							// ok means we're done
-							if (line.contains("ok"))
-								break;
-							}
-						else
-							{
-							// end of stream reached
 							break;
 							}
+						sRet += line;
 						}
 					}
 				out.close();
 				in.close();
 				socket.close();
 				}
 			catch(NumberFormatException e)
 				{
@@ -2060,16 +2062,18 @@ public class DoCommand {
 				{
 			    ByteArrayOutputStream ostream = new ByteArrayOutputStream();
 			    response.getEntity().writeTo(ostream);
 			    Log.e("HTTP CLIENT", ostream.toString());
 				}
 			else
 				{
 			    InputStream content = response.getEntity().getContent();
+//			    int nAvailable = content.available();
+//			    byte [] data = new byte [nAvailable];
 			    byte [] data = new byte [2048];
 			    int nRead = content.read(data);
 			    sRet = new String(data, 0, nRead);
 			    content.close(); // this will also close the connection
 				}
 			}
 		catch (IllegalArgumentException e)
 			{
@@ -2264,16 +2268,17 @@ public class DoCommand {
 			}
 		catch (IOException e) 
 			{
 			sRet = e.getMessage();
 			e.printStackTrace();
 			} 
 		catch (InterruptedException e)
 			{
+			// TODO Auto-generated catch block
 			e.printStackTrace();
 			}
 
 		return(sRet);
 		}
 	
 	public String SendPing(String sIPAddr, OutputStream out)
 		{
@@ -2371,18 +2376,17 @@ public class DoCommand {
 				while ((sLine = in.readLine()) != null)
 					{
 					if (sLine.toLowerCase().contains(sComp))
 						{
 						String [] temp = null;
 						temp = sLine.split("=");
 						if (temp != null)
 							{
-							if (temp.length > 1)
-								sRet = temp[1].trim();
+							sRet = temp[1].trim();
 							}
 						break;
 						}
 					}
 				}
 			in.close();
 			}
 		catch (FileNotFoundException e)
@@ -2449,106 +2453,118 @@ public class DoCommand {
 			}
 		catch (IOException e) 
 			{
 			sRet = e.getMessage();
 			e.printStackTrace();
 			} 
 		catch (InterruptedException e)
 			{
+			// TODO Auto-generated catch block
 			e.printStackTrace();
 			}
 		
 		return (sRet);
 	}
 	
 	public String InstallApp(String sApp, OutputStream out)
 		{
 		String sRet = "";
 		String [] theArgs = new String [3];
 		File	srcFile = new File(sApp);
+//		boolean bDone = false;
+//		int		nExitCode;
 
 		theArgs[0] = "su";
 		theArgs[1] = "-c";
 		theArgs[2] = "mv " + GetTmpDir() + "/" + srcFile.getName() + " /data/local/tmp/" + srcFile.getName() + ";exit";
+//		theArgs[2] += ";chmod 666 /data/local/tmp/" + srcFile.getName();
+//		theArgs[2] += ";pm install /data/local/tmp/" + srcFile.getName() + " Cleanup";
+//		theArgs[2] += ";done;exit";
 		
 		sRet = CopyFile(sApp, GetTmpDir() + "/" + srcFile.getName());
 		try {
 			out.write(sRet.getBytes());
 			out.flush();
-			}
-		catch (IOException e1)
-			{
+		} catch (IOException e1) {
+			// TODO Auto-generated catch block
 			e1.printStackTrace();
-			}
+		}
+//		CopyFile(sApp, GetTmpDir() + "/" + srcFile.getName());
 
 		try 
 			{
 			pProc = Runtime.getRuntime().exec(theArgs);
 			
 			RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
 			outThrd.start();
 			outThrd.join(90000);
 			int nRet = pProc.exitValue();
+//			boolean bRet = outThrd.isAlive();
 			sRet = "\nmove complete [" + nRet + "]";
 			try 
 				{
 				out.write(sRet.getBytes());
 				out.flush();
 				}
 			catch (IOException e1)
 				{
+				// TODO Auto-generated catch block
 				e1.printStackTrace();
 				}
 			
 			theArgs[2] = "chmod 666 /data/local/tmp/" + srcFile.getName() + ";exit";
 			pProc = Runtime.getRuntime().exec(theArgs);
 			RedirOutputThread outThrd2 = new RedirOutputThread(pProc, out);
 			outThrd2.start();
 			outThrd2.join(10000);
 			int nRet2 = pProc.exitValue();
+//			bRet = outThrd2.isAlive();
 			sRet = "\npermission change complete [" + nRet2 + "]\n";
 			try {
 				out.write(sRet.getBytes());
 				out.flush();
 				}
 			catch (IOException e1)
 				{
+				// TODO Auto-generated catch block
 				e1.printStackTrace();
 				}
 			
 			theArgs[2] = "pm install /data/local/tmp/" + srcFile.getName() + " Cleanup" + ";exit";
 			pProc = Runtime.getRuntime().exec(theArgs);
 			RedirOutputThread outThrd3 = new RedirOutputThread(pProc, out);
 			outThrd3.start();
 			outThrd3.join(60000);
 			int nRet3 = pProc.exitValue();
 			sRet = "\ninstallation complete [" + nRet3 + "]";
 			try {
 				out.write(sRet.getBytes());
 				out.flush();
 				}
 			catch (IOException e1)
 				{
+				// TODO Auto-generated catch block
 				e1.printStackTrace();
 				}
 			
 			theArgs[2] = "rm /data/local/tmp/" + srcFile.getName() + ";exit";
 			pProc = Runtime.getRuntime().exec(theArgs);
 			RedirOutputThread outThrd4 = new RedirOutputThread(pProc, out);
 			outThrd4.start();
 			outThrd4.join(60000);
 			int nRet4 = pProc.exitValue();
 			sRet = "\ntmp file removed [" + nRet4 + "]";
 			try {
 				out.write(sRet.getBytes());
 				out.flush();
 				}
 			catch (IOException e1)
 				{
+				// TODO Auto-generated catch block
 				e1.printStackTrace();
 				}
 			sRet = "\nSuccess";
 			}
 		catch (IOException e) 
 			{
 			sRet = e.getMessage();
 			e.printStackTrace();
@@ -2557,104 +2573,73 @@ public class DoCommand {
 			{
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 			}
 
 		return (sRet);
 		}
 
-	public String StrtUpdtOMatic(String sPkgName, String sPkgFileName, String sCallBackIP, String sCallBackPort)
+	public String StartUpdateOMatic(String sPkgName, String sPkgFileName)
 		{
 		String sRet = "";
-		
+	
 		Context ctx = contextWrapper.getApplicationContext();
 		PackageManager pm = ctx.getPackageManager();
 
 		Intent prgIntent = new Intent();
-		prgIntent.setPackage("com.mozilla.watcher");
-		
+		prgIntent.setPackage("com.mozilla.UpdateOMatic");
+		prgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
 		try {
-			PackageInfo pi = pm.getPackageInfo("com.mozilla.watcher", PackageManager.GET_SERVICES | PackageManager.GET_INTENT_FILTERS);
-			ServiceInfo [] si = pi.services;
-			for (int i = 0; i < si.length; i++)
+			PackageInfo pi = pm.getPackageInfo("com.mozilla.UpdateOMatic", PackageManager.GET_ACTIVITIES | PackageManager.GET_INTENT_FILTERS);
+			ActivityInfo [] ai = pi.activities;
+			for (int i = 0; i < ai.length; i++)
 				{
-				ServiceInfo s = si[i];
-				if (s.name.length() > 0)
+				ActivityInfo a = ai[i];
+				if (a.name.length() > 0)
 					{
-					prgIntent.setClassName(s.packageName, s.name);
+					prgIntent.setClassName(a.packageName, a.name);
 					break;
 					}
 				}
 			}
 		catch (NameNotFoundException e)
 			{
 			e.printStackTrace();
-			sRet = sErrorPrefix + "watcher is not properly installed";
-			return(sRet);
 			}
 		
-		prgIntent.putExtra("command", "updt");
 		prgIntent.putExtra("pkgName", sPkgName);
-		prgIntent.putExtra("pkgFile", sPkgFileName);
-		
+		prgIntent.putExtra("pkgFileName", sPkgFileName);
+
 		try 
 			{
-			if ((sCallBackIP != null) && (sCallBackPort != null) && 
-					(sCallBackIP.length() > 0) && (sCallBackPort.length() > 0))
-				{
-				FileOutputStream fos = ctx.openFileOutput("update.info", Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
-				String sBuffer = sCallBackIP + "," + sCallBackPort + "\rupdate started " + sPkgName + " " + sPkgFileName + "\r";
-				fos.write(sBuffer.getBytes());
-				fos.flush();
-				fos.close();
-				fos = null;
-				prgIntent.putExtra("outFile", ctx.getFilesDir() + "/update.info");
-				}
-			
-			ComponentName cn = contextWrapper.startService(prgIntent);
-			if (cn != null)
-				sRet = "exit";
-			else
-				sRet = sErrorPrefix + "Unable to use watcher service";
+			contextWrapper.startActivity(prgIntent);
+			sRet = "exit";
 			}
 		catch(ActivityNotFoundException anf)
 			{
 			anf.printStackTrace();
 			} 
-		catch (FileNotFoundException e)
-			{
-			e.printStackTrace();
-			}
-		catch (IOException e)
-			{
-			e.printStackTrace();
-			}
-
+	
 		ctx = null;
-		
 		return (sRet);
 		}
 
-	public String StartJavaPrg(String [] sArgs, Intent preIntent)
+	public String StartJavaPrg(String [] sArgs)
 		{
 		String sRet = "";
 		String sArgList = "";
 		String sUrl = "";
-//		String sRedirFileName = "";
-		Intent prgIntent = null;
+		String sRedirFileName = "";
 		
 		Context ctx = contextWrapper.getApplicationContext();
 		PackageManager pm = ctx.getPackageManager();
 
-		if (preIntent == null)
-			prgIntent = new Intent();
-		else
-			prgIntent = preIntent;
-		
+		Intent prgIntent = new Intent();
 		prgIntent.setPackage(sArgs[0]);
 		prgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
 		try {
 			PackageInfo pi = pm.getPackageInfo(sArgs[0], PackageManager.GET_ACTIVITIES | PackageManager.GET_INTENT_FILTERS);
 			ActivityInfo [] ai = pi.activities;
 			for (int i = 0; i < ai.length; i++)
 				{
@@ -2668,41 +2653,35 @@ public class DoCommand {
 			}
 		catch (NameNotFoundException e)
 			{
 			e.printStackTrace();
 			}
 		
 		if (sArgs.length > 1)
 			{
-			if (sArgs[0].contains("android.browser"))
+//			if (sArgs[0].contains("android.browser"))
 				prgIntent.setAction(Intent.ACTION_VIEW);
-			else
-				prgIntent.setAction(Intent.ACTION_MAIN);
 			
 			if (sArgs[0].contains("fennec"))
 				{
 				sArgList = "";
 				sUrl = "";
 				
 				for (int lcv = 1; lcv < sArgs.length; lcv++)
 					{
 					if (sArgs[lcv].contains("://"))
-						{
-						prgIntent.setAction(Intent.ACTION_VIEW);
 						sUrl = sArgs[lcv];
-						}
 					else
 						{
 						if (sArgs[lcv].equals(">"))
 							{
 							lcv++;
 							if (lcv < sArgs.length)
-								lcv++;
-//								sRedirFileName = sArgs[lcv++];
+								sRedirFileName = sArgs[lcv++];
 							}
 						else
 							sArgList += " " + sArgs[lcv];
 						}
 					}
 				
 				if (sArgList.length() > 0)
 					prgIntent.putExtra("args", sArgList.trim());
@@ -2714,19 +2693,17 @@ public class DoCommand {
 				{
 				for (int lcv = 1; lcv < sArgs.length; lcv++)
 					sArgList += " " + sArgs[lcv];
 				
 				prgIntent.setData(Uri.parse(sArgList.trim()));
 				}
 			}
 		else
-			{
-			prgIntent.setAction(Intent.ACTION_MAIN);
-			}
+			prgIntent.setData(Uri.parse("about:blank"));
 
 		try 
 			{
 			contextWrapper.startActivity(prgIntent);
 			}
 		catch(ActivityNotFoundException anf)
 			{
 			anf.printStackTrace();
@@ -2756,36 +2733,46 @@ public class DoCommand {
 		catch (InterruptedException e)
 			{
 			e.printStackTrace();
 			sRet = "Timed out!";
 			}
 
 		return (sRet);
 		}
+/*	
+	@SuppressWarnings("unchecked")
+	public static void set(String key, String value) throws Exception
+		{
+	    Class[] classes = Collections.class.getDeclaredClasses();
+	    Map env = System.getenv();
+	    for(Class cl : classes)
+	    	{
+	        if("java.util.Collections$UnmodifiableMap".equals(cl.getName()))
+	        	{
+	            Field field = cl.getDeclaredField("m");
+	            field.setAccessible(true);
+	            Object obj = field.get(env);
+	            Map<String, String> map = (Map<String, String>) obj;
+	            map.put(key, value);
+	        	}
+	    	}
+		}
 
+*/	
 	public String StartPrg2(String [] progArray, OutputStream out)
 		{
 		String sRet = "";
 		
 		int	nArraySize = 0;
 		int	nArgs = progArray.length - 1; // 1st arg is the environment string
 		int	lcv	= 0;
 		int	temp = 0;
 
 		String sEnvString = progArray[0];
-		
-		if (!sEnvString.contains("="))
-			{
-			if (sEnvString.contains("/") || sEnvString.contains("\\") || !sEnvString.contains("."))
-				sRet = StartPrg(progArray, out);
-			else
-				sRet = StartJavaPrg(progArray, null);
-			return(sRet);
-			}
 
 		// Set up command line args stripping off the environment string
 		String [] theArgs = new String [nArgs];
 		for (lcv = 0; lcv < nArgs; lcv++)
 			{
 			theArgs[lcv] = progArray[lcv + 1];
 			}
 		
@@ -2844,36 +2831,24 @@ public class DoCommand {
 	        	else
 	        		envArray[i++] = entry.getKey() + "=" + entry.getValue();
 	        	}
 	        
 			for (Map.Entry<String, String> entry : newEnv.entrySet())
 				{
         		envArray[i++] = entry.getKey() + "=" + entry.getValue();
 				}
-			
-			if (theArgs[0].contains("/") || theArgs[0].contains("\\") || !theArgs[0].contains("."))
-				{
-				pProc = Runtime.getRuntime().exec(theArgs, envArray);
+	        
+			pProc = Runtime.getRuntime().exec(theArgs, envArray);
 
-				RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
-				outThrd.start();
-				outThrd.join(10000);
-				int nRetCode = pProc.exitValue();
-				sRet = "return code [" + nRetCode + "]";
-				}
-			else
-				{
-				Intent preIntent = new Intent();
-				for (lcv = 0; lcv < envArray.length; lcv++)
-					{
-					preIntent.putExtra("env" + lcv, envArray[lcv]);
-					}
-				sRet = StartJavaPrg(theArgs, preIntent);
-				}
+			RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
+			outThrd.start();
+			outThrd.join(10000);
+			int nRetCode = pProc.exitValue();
+			sRet = "return code [" + nRetCode + "]";
 			}
 		catch(UnsupportedOperationException e)
 			{
 			if (e != null)
 				e.printStackTrace();
 			}
 		catch(ClassCastException e)
 			{
@@ -2897,69 +2872,95 @@ public class DoCommand {
 		catch (InterruptedException e)
 			{
 			e.printStackTrace();
 			sRet = "Timed out!";
 			}
 
 		return (sRet);
 		}
+/*	
+	public String InstallApplication()
+		{
+		String sRet = "";
+		String sFileName = Environment.getExternalStorageDirectory() + "/org.mozilla.fennec.apk";
+		
+		Intent instIntent = new Intent();
+		
+		instIntent.setAction(android.content.Intent.ACTION_VIEW);
+		instIntent.setDataAndType(Uri.fromFile(new File(sFileName)), "application/vnd.android.package-archive");
+//		instIntent.setDataAndType(Uri.parse("file:///sdcard/org.mozilla.fennec.apk"), "application/vnd.android.package-archive");
+		SUTAgentAndroid.me.startActivity(instIntent);
+		
+//		Instrumentation inst = new Instrumentation();
+//		inst.sendKeyDownUpSync(KeyEvent.KEYCODE_SOFT_LEFT);
+		
+		return(sRet);
+		}
 
+	public String UninstallApplication()
+		{
+		String sRet = "";
+		Uri		pkgURI = Uri.parse("package:" + "org.mozilla.fennec");
+	
+		Intent unInstIntent = new Intent(Intent.ACTION_DELETE, pkgURI);
+	
+		SUTAgentAndroid.me.startActivity(unInstIntent);
+
+		return(sRet);
+		}
+*/
 	private String PrintUsage()
 		{
 		String sRet = 
-			"run [cmdline]                - start program no wait\n" +
-			"exec [env pairs] [cmdline]   - start program no wait optionally pass env\n" +
-			"                               key=value pairs (comma separated)\n" +
+			"run [executable] [args]      - start program no wait\n" +
+			"exec [executable] [args]     - start program wait\n" +
+			"fire [executable] [args]     - start program no wait\n" +
+			"envrun [env pairs] [cmdline] - start program no wait\n" +
 			"kill [program name]          - kill program no path\n" +
 			"killall                      - kill all processes started\n" +
 			"ps                           - list of running processes\n" +
 			"info                         - list of device info\n" +
 			"        [os]                 - os version for device\n" +
 			"        [id]                 - unique identifier for device\n" +
 			"        [uptime]             - uptime for device\n" +
-			"        [systime]            - current system time\n" +
+			"        [systime]            - current system time on device\n" +
 			"        [screen]             - width, height and bits per pixel for device\n" +
-			"        [memory]             - physical, free, available, storage memory\n" +
-			"                               for device\n" +
+			"        [memory]             - physical, free, available, storage memory for device\n" +
 			"        [processes]          - list of running processes see 'ps'\n" +
 			"deadman timeout              - set the duration for the deadman timer\n" +
 			"alrt [on/off]                - start or stop sysalert behavior\n" +
 			"disk [arg]                   - prints disk space info\n" +
-			"cp file1 file2               - copy file1 to file2\n" +
-			"time file                    - timestamp for file\n" +
-			"hash file                    - generate hash for file\n" +
-			"cd directory                 - change cwd\n" +
-			"cat file                     - cat file\n" +
-			"cwd                          - display cwd\n" +
-			"mv file1 file2               - move file1 to file2\n" +
+			"cp file1 file2               - copy file1 to file2 on device\n" +
+			"time file                    - timestamp for file on device\n" +
+			"hash file                    - generate hash for file on device\n" +
+			"cd directory                 - change cwd on device\n" +
+			"cat file                     - cat file on device\n" +
+			"cwd                          - display cwd on device\n" +
+			"mv file1 file2               - move file1 to file2 on device\n" +
 			"push filename                - push file to device\n" +
-			"rm file                      - delete file\n" +
-			"rmdr directory               - delete directory even if not empty\n" +
-			"mkdr directory               - create directory\n" +
-			"dirw directory               - tests whether the directory is writable\n" +
-			"isdir directory              - test whether the directory exists\n" +
-			"stat processid               - stat process\n" +
-			"dead processid               - print whether the process is alive or hung\n" +
-			"mems                         - dump memory stats\n" +
-			"ls                           - print directory\n" +
-			"tmpd                         - print temp directory\n" +
+			"rm file                      - delete file on device\n" +
+			"rmdr directory               - delete directory on device even if not empty\n" +
+			"mkdr directory               - create directory on device\n" +
+			"dirw directory               - tests whether the directory is writable on the device\n" +
+			"stat processid               - stat process on device\n" +
+			"dead processid               - print whether the process is alive or hung on device\n" +
+			"mems                         - dump memory stats on device\n" +
+			"ls                           - print directory on device\n" +
+			"tmpd                         - print temp directory on device\n" +
 			"ping [hostname/ipaddr]       - ping a network device\n" +
 			"unzp zipfile destdir         - unzip the zipfile into the destination dir\n" +
 			"zip zipfile src              - zip the source file/dir into zipfile\n" +
 			"rebt                         - reboot device\n" +
 			"inst /path/filename.apk      - install the referenced apk file\n" +
 			"uninst packagename           - uninstall the referenced package\n" +
 			"updt pkgname pkgfile         - unpdate the referenced package\n" +
-			"clok                         - the current device time expressed as the" +
-			"                               number of millisecs since epoch\n" +
-			"settime date time            - sets the device date and time\n" +
-			"                               (YYYY/MM/DD HH:MM:SS)\n" +
-			"tzset timezone               - sets the device timezone format is\n" +
-			"                               GMTxhh:mm x = +/- or a recognized Olsen string\n" +
+			"clok                         - the current device time expressed as the number of millisecs since epoch\n" +
+			"settime date time            - sets the device date and time (YYYY/MM/DD HH:MM:SS)\n" +
+			"tzset timezone               - sets the device timezone format is GMTxhh:mm x = +/- or a recognized Olsen string\n" +
 			"tzget                        - returns the current timezone set on the device\n" +
 			"rebt                         - reboot device\n" +
 			"quit                         - disconnect SUTAgent\n" +
 			"exit                         - close SUTAgent\n" +
 			"ver                          - SUTAgent version\n" +
 			"help                         - you're reading it";
 		return (sRet);
 		}
--- a/build/mobile/sutagent/android/SUTAgentAndroid.java
+++ b/build/mobile/sutagent/android/SUTAgentAndroid.java
@@ -40,30 +40,28 @@ package com.mozilla.SUTAgentAndroid;
 import java.io.File;
 import java.io.PrintWriter;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
 import java.net.SocketException;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Timer;
-
 import com.mozilla.SUTAgentAndroid.service.ASMozStub;
 import com.mozilla.SUTAgentAndroid.service.DoCommand;
-import com.mozilla.watcher.*;
 
+// import dalvik.system.VMRuntime;
 import android.app.Activity;
 import android.app.KeyguardManager;
 import android.bluetooth.BluetoothAdapter;
 import android.content.BroadcastReceiver;
+// import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.pm.ActivityInfo;
-import android.content.res.Configuration;
 import android.net.Uri;
 import android.net.wifi.SupplicantState;
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WifiManager.WifiLock;
 import android.os.BatteryManager;
 import android.os.Bundle;
@@ -80,16 +78,17 @@ import android.widget.TextView;
 import android.widget.Toast;
 
 public class SUTAgentAndroid extends Activity 
 	{
 	public static final int START_PRG = 1959;
 	MenuItem mExitMenuItem;
 	Timer timer = null;
 	
+//	public static SUTAgentAndroid me = null;
     public static String sUniqueID = null;
     public static String sLocalIPAddr = null;
     public static String sACStatus = null;
     public static String sPowerStatus = null;
     public static int	nChargeLevel = 0;
     public static int	nBatteryTemp = 0;
     
 	String lineSep = System.getProperty("line.separator");
@@ -101,17 +100,18 @@ public class SUTAgentAndroid extends Act
     private static String HardwareID = "";
     private static String Pool = "";
     private static String sRegString = "";
     
     private WifiLock wl = null;
     private PowerManager.WakeLock pwl = null;
     
     private BroadcastReceiver battReceiver = null;
-    
+//    private ComponentName service = null;
+
 	public boolean onCreateOptionsMenu(Menu menu)
 		{
 		mExitMenuItem = menu.add("Exit");
 		mExitMenuItem.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
 		return super.onCreateOptionsMenu(menu);
 		}
 
 	public boolean onMenuItemSelected(int featureId, MenuItem item)
@@ -128,19 +128,24 @@ public class SUTAgentAndroid extends Act
 		return(RegSvrIPAddr);
 		}
     
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState)
     	{
         super.onCreate(savedInstanceState);
-        
         setContentView(R.layout.main);
 
+//        Debug.waitForDebugger();
+
+//        long lHeapSize = VMRuntime.getRuntime().getMinimumHeapSize();
+//        lHeapSize = 16000000;
+//        VMRuntime.getRuntime().setMinimumHeapSize(lHeapSize);
+        
         // Keep phone from locking or remove lock on screen
         KeyguardManager km = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
         if (km != null)
         	{
         	KeyguardManager.KeyguardLock kl = km.newKeyguardLock("SUTAgent");
         	if (kl != null)
         		kl.disableKeyguard();
         	}
@@ -149,18 +154,16 @@ public class SUTAgentAndroid extends Act
         PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
         if (pm != null)
         	{
         	pwl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "SUTAgent");
         	if (pwl != null)
         		pwl.acquire();
         	}
         
-        fixScreenOrientation();
-        
         DoCommand dc = new DoCommand(getApplication());
         
         // Get configuration settings from "ini" file
         File dir = getFilesDir();
         File iniFile = new File(dir, "SUTAgent.ini");
         String sIniFile = iniFile.getAbsolutePath();
         
         SUTAgentAndroid.RegSvrIPAddr = dc.GetIniData("Registration Server", "IPAddr", sIniFile);
@@ -168,16 +171,18 @@ public class SUTAgentAndroid extends Act
         SUTAgentAndroid.HardwareID = dc.GetIniData("Registration Server", "HARDWARE", sIniFile);
         SUTAgentAndroid.Pool = dc.GetIniData("Registration Server", "POOL", sIniFile);
 
         TextView  tv = (TextView) this.findViewById(R.id.Textview01);
 
         if (getLocalIpAddress() == null)
         	setUpNetwork(sIniFile);
         
+//        me = this;
+        
         WifiInfo wifi;
         WifiManager wifiMan = (WifiManager)getSystemService(Context.WIFI_SERVICE);
         String macAddress = "Unknown";
         if (wifiMan != null) 
         	{
 			wifi = wifiMan.getConnectionInfo();
 			if (wifi != null)
 				{
@@ -185,17 +190,17 @@ public class SUTAgentAndroid extends Act
 				if (macAddress != null)
 					sUniqueID = macAddress;
 				}
         	}
         
         if (sUniqueID == null)
         	{
         	BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
-        	if ((ba != null) && (ba.isEnabled() != true))
+        	if (ba.isEnabled() != true)
         		{
         		ba.enable();
         		while(ba.getState() != BluetoothAdapter.STATE_ON)
         			{
 					try {
 						Thread.sleep(1000);
 						}
         			catch (InterruptedException e)
@@ -215,21 +220,18 @@ public class SUTAgentAndroid extends Act
         			catch (InterruptedException e)
     					{
         				e.printStackTrace();
     					}
     				}
         		}
         	else
         		{
-        		if (ba != null)
-        			{
-        			sUniqueID = ba.getAddress();
-        			sUniqueID.toLowerCase();
-        			}
+        		sUniqueID = ba.getAddress();
+        		sUniqueID.toLowerCase();
         		}
         	}
 
         if (sUniqueID == null)
         	{
         	TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
         	if (mTelephonyMgr != null)
         		{
@@ -266,33 +268,24 @@ public class SUTAgentAndroid extends Act
         sRegString += "&SCRNHEIGHT=" + xy[1];
         sRegString += "&BPP=8";
         sRegString += "&MEMORY=" + dc.GetMemoryConfig();
         sRegString += "&HARDWARE=" + HardwareID;
         sRegString += "&POOL=" + Pool;
         
         String sTemp = Uri.encode(sRegString,"=&");
         sRegString = "register " + sTemp;
-/*        
-		Intent svcIntent = new Intent();
-		svcIntent.setClassName("com.mozilla.watcher", "com.mozilla.watcher.WatcherService");
-    	boolean bRet = bindService(svcIntent, mConn, Context.BIND_AUTO_CREATE);
-*/        
+        
         if (!bNetworkingStarted)
         	{
         	Thread thread = new Thread(null, doStartService, "StartServiceBkgnd");
         	thread.start();
+//        	ToDoListening(1,300,dc);
         	bNetworkingStarted = true;
-        	
-        	// If we are returning from an update let'em know we're back
-//        	Debug.waitForDebugger();
-        	String sRegRet = dc.UpdateCallBack("update.info");
-        	
-        	sRegRet = "";
-        	
+        	String sRegRet = "";
         	if (RegSvrIPAddr.length() > 0)
         		{
         		sRegRet = dc.RegisterTheDevice(RegSvrIPAddr, RegSvrIPPort, sRegString);
         		if (sRegRet.contains("ok"))
         			{
         			sConfig += "Registered with testserver" + lineSep;
         			sConfig += "\tIPAddress: " + RegSvrIPAddr + lineSep;
         			if (RegSvrIPPort.length() > 0)
@@ -310,60 +303,18 @@ public class SUTAgentAndroid extends Act
         monitorBatteryState();
         
         final Button goButton = (Button) findViewById(R.id.Button01);
         goButton.setOnClickListener(new OnClickListener() {
             public void onClick(View v) {
     			finish();
                 }
         	});
-/*            	
-        
-        final Button runButton = (Button) findViewById(R.id.Button03);
-        runButton.setOnClickListener(new OnClickListener() {
-            public void onClick(View v) {
-            	String sRet = "";
-        		if (mService != null)
-					{
-        			try
-    					{
-        				int nRet = mService.UpdateApplication("com.mozilla.test", "/sdcard/foo.apk", "/update.info", 0);
-        				if (nRet == 1)
-        					sRet = "Success";
-    					}
-        			catch (RemoteException e)
-						{
-        				e.printStackTrace();
-        				e.printStackTrace();
-						}
-//        			unbindService(mConn);
-					}
-            	}
-        	});
-        
-        final Button testButton = (Button) findViewById(R.id.Button02);
-        testButton.setOnClickListener(new OnClickListener() {
-            public void onClick(View v) {
-            	String sRet = "";
-        		Intent svcIntent = new Intent();
-        		svcIntent.setClassName("com.mozilla.watcher", "com.mozilla.watcher.WatcherService");
-
-            	boolean bRet = bindService(svcIntent, mConn, Context.BIND_AUTO_CREATE);
-           		int nRet = sRet.length();
-            	}
-        	});
-*/            	
         }
     
-    public void fixScreenOrientation()
-    	{
-    	setRequestedOrientation((getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) ?
-    							ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);    	
-    	}
-    
     protected void onActivityResult(int requestCode, int resultCode, Intent data)
     	{
         if (requestCode == START_PRG)
         	{
            	Toast.makeText(getApplication().getApplicationContext(), "SUTAgent startprg finished ...", Toast.LENGTH_LONG).show();
         	}
     	}
     
@@ -373,18 +324,16 @@ public class SUTAgentAndroid extends Act
 		super.onDestroy();
     	if (isFinishing())
     		{
     		Intent listenerSvc = new Intent(this, ASMozStub.class);
     		listenerSvc.setAction("com.mozilla.SUTAgentAndroid.service.LISTENER_SERVICE");
     		stopService(listenerSvc);
     		bNetworkingStarted = false;
     		
-//			unbindService(mConn);
-    		
 			unregisterReceiver(battReceiver);
 	        KeyguardManager km = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
 	        if (km != null)
 	        	{
 	        	KeyguardManager.KeyguardLock kl = km.newKeyguardLock("SUTAgent");
 	        	if (kl != null)
 	        		kl.reenableKeyguard();
 	        	}
@@ -668,18 +617,111 @@ public class SUTAgentAndroid extends Act
     
     private Runnable doStartService = new Runnable()
     	{
     	public void run()
     		{
 			Intent listenerService = new Intent();
 			listenerService.setAction("com.mozilla.SUTAgentAndroid.service.LISTENER_SERVICE");
 			startService(listenerService);
+//			service = startService(listenerService);
     		}
     	};
+/*
+    class ToDoListener extends TimerTask 
+    	{
+    	boolean 	bFirstRun = true;
+    	DoCommand	dc = null;
+    	
+    	ToDoListener() {}
+    	
+    	ToDoListener(DoCommand dc)
+    		{
+    		this.dc = dc;
+    		}
+    	
+		public void run ()
+			{
+			if (bFirstRun == true)
+				{
+				Intent listenerService = new Intent();
+				listenerService.setAction("com.mozilla.SUTAgentAndroid.service.LISTENER_SERVICE");
+				service = startService(listenerService);
+				bFirstRun = false;
+				}
+			else
+				{
+				if (dc != null)
+					{
+					String sRet = this.dc.SendPing("www.mozilla.org", null);
+					if (sRet.contains("3 received"))
+						this.dc.StopAlert();
+					else
+						this.dc.StartAlert();
+					sRet = null;
+					System.gc();
+					}
+				}
+			}
+		}
+	
+	public void ToDoListening(int delay, int interval, DoCommand dc)
+		{
+		if (timer == null)
+			timer = new Timer();
+//		timer.scheduleAtFixedRate(new ToDoListener(dc), delay * 1000, interval * 1000);
+//		timer.schedule(new ToDoListener(dc), delay * 1000);
+		timer.schedule(new ToDoListener(), delay * 1000);
+		}
+
+	class DoHeartBeat extends TimerTask
+		{
+    	PrintWriter out;
+	
+    	DoHeartBeat(PrintWriter out)
+			{
+    		this.out = out;
+			}
+	
+    	public void run ()
+			{
+    		String sRet = "";
+    		
+    		Calendar cal = Calendar.getInstance();
+    		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss");
+    		sRet = sdf.format(cal.getTime());
+    		sRet += " Thump thump - " + sUniqueID + "\r\n";
+
+    		out.write(sRet);
+    		out.flush();
+			}
+		}
+
+	public void StartHeartBeat(PrintWriter out)
+		{
+		// start the heartbeat
+		this.dataOut = out;
+		if (timer == null)
+			timer = new Timer();
+		timer.scheduleAtFixedRate(new DoHeartBeat(dataOut), 0, 60000);
+		}
+	
+	public void StopHeartBeat()
+		{
+		// stop the heartbeat
+		this.dataOut = null;
+		if (timer != null)
+			{
+			timer.cancel();
+			timer.purge();
+			timer = null;
+			System.gc();
+			}
+		}
+*/	
 	
     public String getLocalIpAddress()
 		{
 		try
     		{
 			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) 
         		{
 				NetworkInterface intf = en.nextElement();
@@ -694,29 +736,9 @@ public class SUTAgentAndroid extends Act
         		}
     		} 
 		catch (SocketException ex)
     		{
 			Toast.makeText(getApplication().getApplicationContext(), ex.toString(), Toast.LENGTH_LONG).show();
     		}
 		return null;
 		}
-/*    
-    private ServiceConnection mConn = new ServiceConnection() {
-        public void onServiceConnected(ComponentName className, IBinder service) {
-            // This is called when the connection with the service has been
-            // established, giving us the service object we can use to
-            // interact with the service.  We are communicating with our
-            // service through an IDL interface, so get a client-side
-            // representation of that from the raw service object.
-        	Debug.waitForDebugger();
-            mService = IWatcherService.Stub.asInterface(service);
-        }
-
-        public void onServiceDisconnected(ComponentName className) {
-            // This is called when the connection with the service has been
-            // unexpectedly disconnected -- that is, its process crashed.
-        	Debug.waitForDebugger();
-            mService = null;
-        }
-    };
-*/	
-}
+}
\ No newline at end of file
--- a/build/mobile/sutagent/android/res/layout/main.xml
+++ b/build/mobile/sutagent/android/res/layout/main.xml
@@ -9,11 +9,9 @@
     android:layout_height="wrap_content" 
     android:id="@+id/Textview01"/>
 
 
 
 
 <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:text="Exit"></Button>
 
-
-
 </LinearLayout>