83
83
import android.os.Environment;
84
84
import android.os.StatFs;
85
85
import android.os.SystemClock;
86
import android.text.TextUtils;
86
87
import android.util.DisplayMetrics;
87
88
import android.util.Log;
88
89
import android.view.Surface;
105
106
String ffxProvider = "org.mozilla.ffxcp";
106
107
String fenProvider = "org.mozilla.fencp";
108
private final String prgVersion = "SUTAgentAndroid Version 1.08";
109
private final String prgVersion = "SUTAgentAndroid Version 1.09";
110
111
public enum Command
361
strReturn = UnInstallApp(Argv[1], cmdOut);
363
strReturn = sErrorPrefix + "Wrong number of arguments for inst command!";
361
strReturn = UnInstallApp(Argv[1], cmdOut, true);
363
strReturn = sErrorPrefix + "Wrong number of arguments for uninst command!";
368
strReturn = UnInstallApp(Argv[1], cmdOut, false);
370
strReturn = sErrorPrefix + "Wrong number of arguments for uninstall command!";
735
742
strReturn = Zip(Argv[1], (Argc == 3 ? Argv[2] : ""));
747
strReturn = ChmodDir(Argv[1]);
749
strReturn = sErrorPrefix + "Wrong number of arguments for chmod command!";
739
753
strReturn = PrintUsage();
1914
1927
if (dstFile != null) {
1915
1928
dstFile.flush();
1916
1929
dstFile.close();
1917
// set the new file's permissions to rwxrwxrwx, if possible
1918
Process pProc = Runtime.getRuntime().exec("chmod 777 "+sTmpFileName);
1919
RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
1923
} catch (InterruptedException e) {
1927
1932
if (lRead == lSize) {
2262
2267
File dir = new File(sTmpDir);
2264
2269
if (dir.mkdirs()) {
2265
// set the new dir's permissions to rwxrwxrwx, if possible
2267
Process pProc = Runtime.getRuntime().exec("chmod 777 "+sTmpDir);
2268
RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
2272
} catch (InterruptedException e) {
2274
} catch (IOException e) {
2275
e.printStackTrace();
2277
2270
sRet = sDir + " successfully created";
2381
2374
public String KillProcess(String sProcName, OutputStream out)
2384
String sCmd = "kill";
2386
2376
String sRet = sErrorPrefix + "Unable to kill " + sProcName + "\n";
2387
2377
ActivityManager aMgr = (ActivityManager) contextWrapper.getSystemService(Activity.ACTIVITY_SERVICE);
2388
2378
List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses();
2390
String strProcName = "";
2380
String sFoundProcName = "";
2392
2381
int nProcs = 0;
2382
boolean bFoundAppProcess = false;
2394
if (lProcesses != null)
2384
if (lProcesses != null)
2395
2385
nProcs = lProcesses.size();
2397
2387
for (lcv = 0; lcv < nProcs; lcv++)
2399
2389
if (lProcesses.get(lcv).processName.contains(sProcName))
2401
strProcName = lProcesses.get(lcv).processName;
2402
nPID = lProcesses.get(lcv).pid;
2403
sRet = sErrorPrefix + "Failed to kill " + nPID + " " + strProcName + "\n";
2391
sFoundProcName = lProcesses.get(lcv).processName;
2392
bFoundAppProcess = true;
2409
pProc = Runtime.getRuntime().exec(this.getSuArgs(sCmd));
2396
pProc = Runtime.getRuntime().exec(this.getSuArgs("kill " + lProcesses.get(lcv).pid));
2410
2397
RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
2411
2398
outThrd.start();
2412
2399
outThrd.join(15000);
2413
sTmp = outThrd.strOutput;
2400
String sTmp = outThrd.strOutput;
2414
2401
Log.e("KILLPROCESS", sTmp);
2415
if (outThrd.nExitCode == 0) {
2416
sRet = "Successfully killed " + nPID + " " + strProcName + "\n";
2420
sRet = sErrorPrefix + "Failed to kill " + nPID + " " + strProcName + "\n";
2423
2403
catch (IOException e)
2430
2410
e.printStackTrace();
2433
// Give the messages a chance to be processed
2437
catch (InterruptedException e)
2439
e.printStackTrace();
2415
if (bFoundAppProcess)
2447
sRet = "Successfully killed " + nPID + " " + strProcName + "\n";
2417
// Give the messages a chance to be processed
2421
catch (InterruptedException e)
2423
e.printStackTrace();
2426
sRet = "Successfully killed " + sProcName + "\n";
2448
2427
lProcesses = aMgr.getRunningAppProcesses();
2450
if (lProcesses != null)
2429
if (lProcesses != null)
2451
2430
nProcs = lProcesses.size();
2452
2431
for (lcv = 0; lcv < nProcs; lcv++)
2454
2433
if (lProcesses.get(lcv).processName.contains(sProcName))
2456
sRet = sErrorPrefix + "Unable to kill " + nPID + " " + strProcName + "\n";
2435
sRet = sErrorPrefix + "Unable to kill " + sProcName + " (couldn't kill " + sFoundProcName +")\n";
2469
2448
RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
2470
2449
outThrd.start();
2471
2450
outThrd.join(10000);
2472
sTmp = outThrd.strOutput;
2451
String sTmp = outThrd.strOutput;
2473
2452
StringTokenizer stokLines = new StringTokenizer(sTmp, "\n");
2474
2453
while(stokLines.hasMoreTokens())
3145
3124
return theArgs;
3148
public String UnInstallApp(String sApp, OutputStream out)
3127
public String UnInstallApp(String sApp, OutputStream out, boolean reboot)
3150
3129
String sRet = "";
3154
pProc = Runtime.getRuntime().exec(this.getSuArgs("pm uninstall " + sApp + ";reboot;exit"));
3133
if (reboot == true) {
3134
pProc = Runtime.getRuntime().exec(this.getSuArgs("pm uninstall " + sApp + ";reboot;exit"));
3136
pProc = Runtime.getRuntime().exec(this.getSuArgs("pm uninstall " + sApp + ";exit"));
3156
3139
RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
3157
3140
outThrd.start();
3676
public String ChmodDir(String sDir)
3680
String sSubDir = null;
3681
String sTmpDir = fixFileName(sDir);
3683
File dir = new File(sTmpDir);
3685
if (dir.isDirectory()) {
3686
sRet = "Changing permissions for " + sTmpDir;
3688
File [] files = dir.listFiles();
3689
if (files != null) {
3690
if ((nFiles = files.length) > 0) {
3691
for (int lcv = 0; lcv < nFiles; lcv++) {
3692
if (files[lcv].isDirectory()) {
3693
sSubDir = files[lcv].getAbsolutePath();
3694
sRet += "\n" + ChmodDir(sSubDir);
3697
// set the new file's permissions to rwxrwxrwx, if possible
3699
Process pProc = Runtime.getRuntime().exec("chmod 777 "+files[lcv]);
3700
RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
3703
sRet += "\n\tchmod " + files[lcv].getName() + " ok";
3704
} catch (InterruptedException e) {
3705
sRet += "\n\ttimeout waiting for chmod " + files[lcv].getName();
3706
} catch (IOException e) {
3707
sRet += "\n\tunable to chmod " + files[lcv].getName();
3713
sRet += "\n\t<empty>";
3717
// set the new directory's (or file's) permissions to rwxrwxrwx, if possible
3719
Process pProc = Runtime.getRuntime().exec("chmod 777 "+sTmpDir);
3720
RedirOutputThread outThrd = new RedirOutputThread(pProc, null);
3723
sRet += "\n\tchmod " + sTmpDir + " ok";
3724
} catch (InterruptedException e) {
3725
sRet += "\n\ttimeout waiting for chmod " + sTmpDir;
3726
} catch (IOException e) {
3727
sRet += "\n\tunable to chmod " + sTmpDir;
3695
3733
private String PrintUsage()
3726
3764
"mkdr directory - create directory\n" +
3727
3765
"dirw directory - tests whether the directory is writable\n" +
3728
3766
"isdir directory - test whether the directory exists\n" +
3767
"chmod directory|file - change permissions of directory and contents (or file) to 777\n" +
3729
3768
"stat processid - stat process\n" +
3730
3769
"dead processid - print whether the process is alive or hung\n" +
3731
3770
"mems - dump memory stats\n" +
3736
3775
"zip zipfile src - zip the source file/dir into zipfile\n" +
3737
3776
"rebt - reboot device\n" +
3738
3777
"inst /path/filename.apk - install the referenced apk file\n" +
3739
"uninst packagename - uninstall the referenced package\n" +
3778
"uninst packagename - uninstall the referenced package and reboot\n" +
3779
"uninstall packagename - uninstall the referenced package without a reboot\n" +
3740
3780
"updt pkgname pkgfile - unpdate the referenced package\n" +
3741
3781
"clok - the current device time expressed as the" +
3742
3782
" number of millisecs since epoch\n" +