Bug 650110 Update SUTAgent, whitespace refactor for fencp, ffxcp, watcher, r=ctalbert

This commit is contained in:
Bob Moss 2011-04-18 11:55:24 -07:00
Родитель 80e8072f92
Коммит 158f686929
15 изменённых файлов: 2627 добавлений и 2231 удалений

Просмотреть файл

@ -1,175 +1,211 @@
package org.mozilla.fencp;
import java.io.File;
import java.io.IOException;
import android.database.MatrixCursor;
public class DirCursor extends MatrixCursor {
public static final String _ID = "_id";
public static final String ISDIR = "isdir";
public static final String FILENAME = "filename";
public static final String LENGTH = "length";
public static final String TIMESTAMP = "ts";
public static final String WRITABLE = "writable";
static final String[] DEFCOLUMNS = new String[] {
_ID,
ISDIR,
FILENAME,
LENGTH,
TIMESTAMP,
WRITABLE
};
private String dirPath = null;
private String [] theColumns = null;
public DirCursor(String[] columnNames, String sPath) {
super((columnNames == null ? DEFCOLUMNS : columnNames));
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
dirPath = sPath;
doLoadCursor(dirPath);
}
public DirCursor(String[] columnNames, int initialCapacity, String sPath) {
super((columnNames == null ? DEFCOLUMNS : columnNames), initialCapacity);
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
dirPath = sPath;
doLoadCursor(dirPath);
}
private void doLoadCursor(String sDir) {
File dir = new File(sDir);
int nFiles = 0;
int nCols = theColumns.length;
int lcvFiles = 0;
int nCIndex = 0;
Object [] vals = new Object[nCols];
if (vals == null)
return;
if (dir.isDirectory()) {
try {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 1;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
try {
vals[nCIndex] = dir.getCanonicalPath();
} catch (IOException e) {
vals[nCIndex] = dir.getName();
}
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(WRITABLE);
if (nCIndex > -1)
vals[nCIndex] = (dir.canWrite() ? 1 : 0);
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
File [] files = dir.listFiles();
if (files != null) {
if ((nFiles = files.length) > 0) {
for (lcvFiles = 0; lcvFiles < nFiles; lcvFiles++) {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = lcvFiles;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = (files[lcvFiles].isDirectory() ? 1 : 0);
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = files[lcvFiles].getName();
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = (files[lcvFiles].isDirectory() ? -1 : files[lcvFiles].length());
try {
addRow(vals);
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
}
}
} else {
if (dir.isFile()) {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = dir.getName();
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = dir.length();
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1) {
vals[nCIndex] = dir.lastModified();
}
try {
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
else {
try {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = null;
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1)
vals[nCIndex] = 0;
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
}
}
}
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.fencp;
import java.io.File;
import java.io.IOException;
import android.database.MatrixCursor;
public class DirCursor extends MatrixCursor {
public static final String _ID = "_id";
public static final String ISDIR = "isdir";
public static final String FILENAME = "filename";
public static final String LENGTH = "length";
public static final String TIMESTAMP = "ts";
public static final String WRITABLE = "writable";
static final String[] DEFCOLUMNS = new String[] {
_ID,
ISDIR,
FILENAME,
LENGTH,
TIMESTAMP,
WRITABLE
};
private String dirPath = null;
private String [] theColumns = null;
public DirCursor(String[] columnNames, String sPath) {
super((columnNames == null ? DEFCOLUMNS : columnNames));
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
dirPath = sPath;
doLoadCursor(dirPath);
}
public DirCursor(String[] columnNames, int initialCapacity, String sPath) {
super((columnNames == null ? DEFCOLUMNS : columnNames), initialCapacity);
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
dirPath = sPath;
doLoadCursor(dirPath);
}
private void doLoadCursor(String sDir) {
File dir = new File(sDir);
int nFiles = 0;
int nCols = theColumns.length;
int lcvFiles = 0;
int nCIndex = 0;
Object [] vals = new Object[nCols];
if (vals == null)
return;
if (dir.isDirectory()) {
try {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 1;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
try {
vals[nCIndex] = dir.getCanonicalPath();
} catch (IOException e) {
vals[nCIndex] = dir.getName();
}
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(WRITABLE);
if (nCIndex > -1)
vals[nCIndex] = (dir.canWrite() ? 1 : 0);
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
File [] files = dir.listFiles();
if (files != null) {
if ((nFiles = files.length) > 0) {
for (lcvFiles = 0; lcvFiles < nFiles; lcvFiles++) {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = lcvFiles;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = (files[lcvFiles].isDirectory() ? 1 : 0);
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = files[lcvFiles].getName();
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = (files[lcvFiles].isDirectory() ? -1 : files[lcvFiles].length());
try {
addRow(vals);
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
}
}
} else {
if (dir.isFile()) {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = dir.getName();
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = dir.length();
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1) {
vals[nCIndex] = dir.lastModified();
}
try {
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
else {
try {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = null;
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1)
vals[nCIndex] = 0;
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
}
}
}

Просмотреть файл

@ -1,3 +1,39 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.fencp;
import android.app.Activity;

Просмотреть файл

@ -1,190 +1,226 @@
package org.mozilla.fencp;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
public class FenCPFP extends ContentProvider {
public static final String PROVIDER_NAME = "org.mozilla.fencp";
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/file");
public static final String _ID = "_id";
public static final String ISDIR = "isdir";
public static final String FILENAME = "filename";
public static final String LENGTH = "length";
public static final String CHUNK = "chunk";
static String[] dircolumns = new String[] {
_ID,
ISDIR,
FILENAME,
LENGTH
};
static String[] filecolumns = new String[] {
_ID,
CHUNK
};
private static final int DIR = 1;
private static final int FILE_NAME = 2;
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "dir", DIR);
uriMatcher.addURI(PROVIDER_NAME, "file", FILE_NAME);
}
public int PruneDir(String sTmpDir) {
int nRet = 0;
int nFiles = 0;
String sSubDir = null;
File dir = new File(sTmpDir);
if (dir.isDirectory()) {
File [] files = dir.listFiles();
if (files != null) {
if ((nFiles = files.length) > 0) {
for (int lcv = 0; lcv < nFiles; lcv++) {
if (files[lcv].isDirectory()) {
sSubDir = files[lcv].getAbsolutePath();
nRet += PruneDir(sSubDir);
}
else {
if (files[lcv].delete()) {
nRet++;
}
}
}
}
}
if (dir.delete()) {
nRet++;
}
if ((nFiles + 1) > nRet) {
nRet = -1;
}
}
return(nRet);
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int nFiles = 0;
switch (uriMatcher.match(uri)) {
case FILE_NAME:
File f = new File(selection);
if (f.delete())
nFiles = 1;
break;
case DIR:
nFiles = PruneDir(selection);
break;
default:
break;
}
return nFiles;
}
@Override
public String getType(Uri uri)
{
switch (uriMatcher.match(uri))
{
//---get directory---
case DIR:
return "vnd.android.cursor.dir/vnd.mozilla.dir ";
//---get a particular file---
case FILE_NAME:
return "vnd.android.cursor.item/vnd.mozilla.file ";
//---Unknown---
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Cursor retCursor = null;
switch(uriMatcher.match(uri)) {
case DIR:
retCursor = new DirCursor(projection, selection);
break;
case FILE_NAME:
retCursor = new FileCursor(projection, selection, selectionArgs);
break;
default:
break;
}
return (retCursor);
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int nRet = 0;
FileOutputStream dstFile = null;
switch(uriMatcher.match(uri)) {
case DIR:
File dir = new File(selection);
if (dir.mkdirs())
nRet = 1;
break;
case FILE_NAME:
try {
long lOffset = values.getAsLong("offset");
byte [] buf = values.getAsByteArray(CHUNK);
int nLength = values.getAsInteger(LENGTH);
if ((buf != null) && (nLength > 0)) {
File f = new File(selection);
dstFile = new FileOutputStream(f, (lOffset == 0 ? false : true));
dstFile.write(buf,0, nLength);
dstFile.flush();
dstFile.close();
nRet = nLength;
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
try {
dstFile.flush();
} catch (IOException e) {
}
try {
dstFile.close();
} catch (IOException e) {
}
}
break;
default:
break;
}
return nRet;
}
}
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.fencp;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
public class FenCPFP extends ContentProvider {
public static final String PROVIDER_NAME = "org.mozilla.fencp";
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/file");
public static final String _ID = "_id";
public static final String ISDIR = "isdir";
public static final String FILENAME = "filename";
public static final String LENGTH = "length";
public static final String CHUNK = "chunk";
static String[] dircolumns = new String[] {
_ID,
ISDIR,
FILENAME,
LENGTH
};
static String[] filecolumns = new String[] {
_ID,
CHUNK
};
private static final int DIR = 1;
private static final int FILE_NAME = 2;
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "dir", DIR);
uriMatcher.addURI(PROVIDER_NAME, "file", FILE_NAME);
}
public int PruneDir(String sTmpDir) {
int nRet = 0;
int nFiles = 0;
String sSubDir = null;
File dir = new File(sTmpDir);
if (dir.isDirectory()) {
File [] files = dir.listFiles();
if (files != null) {
if ((nFiles = files.length) > 0) {
for (int lcv = 0; lcv < nFiles; lcv++) {
if (files[lcv].isDirectory()) {
sSubDir = files[lcv].getAbsolutePath();
nRet += PruneDir(sSubDir);
}
else {
if (files[lcv].delete()) {
nRet++;
}
}
}
}
}
if (dir.delete()) {
nRet++;
}
if ((nFiles + 1) > nRet) {
nRet = -1;
}
}
return(nRet);
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int nFiles = 0;
switch (uriMatcher.match(uri)) {
case FILE_NAME:
File f = new File(selection);
if (f.delete())
nFiles = 1;
break;
case DIR:
nFiles = PruneDir(selection);
break;
default:
break;
}
return nFiles;
}
@Override
public String getType(Uri uri)
{
switch (uriMatcher.match(uri))
{
//---get directory---
case DIR:
return "vnd.android.cursor.dir/vnd.mozilla.dir ";
//---get a particular file---
case FILE_NAME:
return "vnd.android.cursor.item/vnd.mozilla.file ";
//---Unknown---
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Cursor retCursor = null;
switch(uriMatcher.match(uri)) {
case DIR:
retCursor = new DirCursor(projection, selection);
break;
case FILE_NAME:
retCursor = new FileCursor(projection, selection, selectionArgs);
break;
default:
break;
}
return (retCursor);
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int nRet = 0;
FileOutputStream dstFile = null;
switch(uriMatcher.match(uri)) {
case DIR:
File dir = new File(selection);
if (dir.mkdirs())
nRet = 1;
break;
case FILE_NAME:
try {
long lOffset = values.getAsLong("offset");
byte [] buf = values.getAsByteArray(CHUNK);
int nLength = values.getAsInteger(LENGTH);
if ((buf != null) && (nLength > 0)) {
File f = new File(selection);
dstFile = new FileOutputStream(f, (lOffset == 0 ? false : true));
dstFile.write(buf,0, nLength);
dstFile.flush();
dstFile.close();
nRet = nLength;
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
try {
dstFile.flush();
} catch (IOException e) {
}
try {
dstFile.close();
} catch (IOException e) {
}
}
break;
default:
break;
}
return nRet;
}
}

Просмотреть файл

@ -1,166 +1,202 @@
package org.mozilla.fencp;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.database.AbstractWindowedCursor;
import android.database.CursorWindow;
public class FileCursor extends AbstractWindowedCursor {
public static final String _ID = "_id";
public static final String CHUNK = "chunk";
public static final String LENGTH = "length";
static final String[] DEFCOLUMNS = new String[] {
_ID,
CHUNK,
LENGTH
};
private String filePath = null;
private String [] theColumns = null;
private static final int BUFSIZE = 4096;
private long lFileSize = 0;
private int nCount = 0;
private File theFile = null;
private byte [] theBuffer = null;
private long lOffset = 0;
private long lLength = -1;
public FileCursor(String[] columnNames, String sFilePath, String [] selectionArgs) {
super();
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
filePath = sFilePath;
nCount = -1;
if ((selectionArgs != null) && (selectionArgs.length > 0)) {
lOffset = Long.parseLong(selectionArgs[0]);
lLength = Long.parseLong(selectionArgs[1]);
}
if (filePath.length() > 0) {
theFile = new File(filePath);
if (theFile.exists() && theFile.canRead()) {
lFileSize = theFile.length();
// lLength == -1 return everything between lOffset and eof
// lLength == 0 return file length
// lLength > 0 return lLength bytes
if (lLength == -1) {
lFileSize = lFileSize - lOffset;
} else if (lLength == 0) {
// just return the file length
} else {
lFileSize = ((lLength <= (lFileSize - lOffset)) ? lLength : (lFileSize - lOffset));
}
if (lLength != 0) {
nCount = (int) (lFileSize / BUFSIZE);
if ((lFileSize % BUFSIZE) > 0)
nCount++;
} else {
nCount = 1;
}
mRowIdColumnIndex = 0;
}
}
}
public String getColumnName (int columnIndex) {
return theColumns[columnIndex];
}
@Override
public String[] getColumnNames() {
return theColumns;
}
@Override
public int getCount() {
return nCount;
}
@Override
public boolean onMove(int oldPosition, int newPosition) {
boolean bRet = true;
// get rid of old data
mWindow.clear();
bRet = mWindow.setNumColumns(theColumns.length);
fillWindow(newPosition, mWindow);
return bRet;
}
@Override
public void fillWindow (int pos, CursorWindow window) {
int nNumRows = window.getNumRows();
int nCIndex = 0;
window.setStartPosition(0);
if (pos > -1) {
if (nNumRows == 0) {
window.allocRow();
nNumRows = window.getNumRows();
}
if (nNumRows == 1) {
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1) {
window.putLong(lFileSize, 0, nCIndex);
}
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1) {
window.putLong((long)pos, 0, nCIndex);
}
nCIndex = getColumnIndex(CHUNK);
if (nCIndex > -1) {
if (lLength != 0) {
byte[] value = getABlob (pos, 1);
window.putBlob(value, 0, nCIndex);
}
}
}
window.setStartPosition(pos);
}
return;
}
public byte[] getABlob (int row, int column) {
int nRead = 0;
int nOffset = 0;
int nBufSize = 0;
if ((column == 1) && (theFile != null)) {
try {
FileInputStream fin = new FileInputStream(theFile);
nOffset = row * BUFSIZE;
if (row < (nCount - 1)) {
nBufSize = BUFSIZE;
} else {
nBufSize = (int) (lFileSize - nOffset);
}
theBuffer = new byte[nBufSize];
if (theBuffer != null) {
if (fin.skip(nOffset + lOffset) == (nOffset + lOffset)) {
if ((nRead = fin.read(theBuffer, 0, nBufSize)) != -1) {
if (nRead != nBufSize) {
return null;
}
}
}
}
fin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return theBuffer;
}
}
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.fencp;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.database.AbstractWindowedCursor;
import android.database.CursorWindow;
public class FileCursor extends AbstractWindowedCursor {
public static final String _ID = "_id";
public static final String CHUNK = "chunk";
public static final String LENGTH = "length";
static final String[] DEFCOLUMNS = new String[] {
_ID,
CHUNK,
LENGTH
};
private String filePath = null;
private String [] theColumns = null;
private static final int BUFSIZE = 4096;
private long lFileSize = 0;
private int nCount = 0;
private File theFile = null;
private byte [] theBuffer = null;
private long lOffset = 0;
private long lLength = -1;
public FileCursor(String[] columnNames, String sFilePath, String [] selectionArgs) {
super();
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
filePath = sFilePath;
nCount = -1;
if ((selectionArgs != null) && (selectionArgs.length > 0)) {
lOffset = Long.parseLong(selectionArgs[0]);
lLength = Long.parseLong(selectionArgs[1]);
}
if (filePath.length() > 0) {
theFile = new File(filePath);
if (theFile.exists() && theFile.canRead()) {
lFileSize = theFile.length();
// lLength == -1 return everything between lOffset and eof
// lLength == 0 return file length
// lLength > 0 return lLength bytes
if (lLength == -1) {
lFileSize = lFileSize - lOffset;
} else if (lLength == 0) {
// just return the file length
} else {
lFileSize = ((lLength <= (lFileSize - lOffset)) ? lLength : (lFileSize - lOffset));
}
if (lLength != 0) {
nCount = (int) (lFileSize / BUFSIZE);
if ((lFileSize % BUFSIZE) > 0)
nCount++;
} else {
nCount = 1;
}
mRowIdColumnIndex = 0;
}
}
}
public String getColumnName (int columnIndex) {
return theColumns[columnIndex];
}
@Override
public String[] getColumnNames() {
return theColumns;
}
@Override
public int getCount() {
return nCount;
}
@Override
public boolean onMove(int oldPosition, int newPosition) {
boolean bRet = true;
// get rid of old data
mWindow.clear();
bRet = mWindow.setNumColumns(theColumns.length);
fillWindow(newPosition, mWindow);
return bRet;
}
@Override
public void fillWindow (int pos, CursorWindow window) {
int nNumRows = window.getNumRows();
int nCIndex = 0;
window.setStartPosition(0);
if (pos > -1) {
if (nNumRows == 0) {
window.allocRow();
nNumRows = window.getNumRows();
}
if (nNumRows == 1) {
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1) {
window.putLong(lFileSize, 0, nCIndex);
}
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1) {
window.putLong((long)pos, 0, nCIndex);
}
nCIndex = getColumnIndex(CHUNK);
if (nCIndex > -1) {
if (lLength != 0) {
byte[] value = getABlob (pos, 1);
window.putBlob(value, 0, nCIndex);
}
}
}
window.setStartPosition(pos);
}
return;
}
public byte[] getABlob (int row, int column) {
int nRead = 0;
int nOffset = 0;
int nBufSize = 0;
if ((column == 1) && (theFile != null)) {
try {
FileInputStream fin = new FileInputStream(theFile);
nOffset = row * BUFSIZE;
if (row < (nCount - 1)) {
nBufSize = BUFSIZE;
} else {
nBufSize = (int) (lFileSize - nOffset);
}
theBuffer = new byte[nBufSize];
if (theBuffer != null) {
if (fin.skip(nOffset + lOffset) == (nOffset + lOffset)) {
if ((nRead = fin.read(theBuffer, 0, nBufSize)) != -1) {
if (nRead != nBufSize) {
return null;
}
}
}
}
fin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return theBuffer;
}
}

Просмотреть файл

@ -1,23 +1,23 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package org.mozilla.fencp;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package org.mozilla.fencp;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

Просмотреть файл

@ -1,175 +1,211 @@
package org.mozilla.ffxcp;
import java.io.File;
import java.io.IOException;
import android.database.MatrixCursor;
public class DirCursor extends MatrixCursor {
public static final String _ID = "_id";
public static final String ISDIR = "isdir";
public static final String FILENAME = "filename";
public static final String LENGTH = "length";
public static final String TIMESTAMP = "ts";
public static final String WRITABLE = "writable";
static final String[] DEFCOLUMNS = new String[] {
_ID,
ISDIR,
FILENAME,
LENGTH,
TIMESTAMP,
WRITABLE
};
private String dirPath = null;
private String [] theColumns = null;
public DirCursor(String[] columnNames, String sPath) {
super((columnNames == null ? DEFCOLUMNS : columnNames));
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
dirPath = sPath;
doLoadCursor(dirPath);
}
public DirCursor(String[] columnNames, int initialCapacity, String sPath) {
super((columnNames == null ? DEFCOLUMNS : columnNames), initialCapacity);
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
dirPath = sPath;
doLoadCursor(dirPath);
}
private void doLoadCursor(String sDir) {
File dir = new File(sDir);
int nFiles = 0;
int nCols = theColumns.length;
int lcvFiles = 0;
int nCIndex = 0;
Object [] vals = new Object[nCols];
if (vals == null)
return;
if (dir.isDirectory()) {
try {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 1;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
try {
vals[nCIndex] = dir.getCanonicalPath();
} catch (IOException e) {
vals[nCIndex] = dir.getName();
}
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(WRITABLE);
if (nCIndex > -1)
vals[nCIndex] = (dir.canWrite() ? 1 : 0);
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
File [] files = dir.listFiles();
if (files != null) {
if ((nFiles = files.length) > 0) {
for (lcvFiles = 0; lcvFiles < nFiles; lcvFiles++) {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = lcvFiles;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = (files[lcvFiles].isDirectory() ? 1 : 0);
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = files[lcvFiles].getName();
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = (files[lcvFiles].isDirectory() ? -1 : files[lcvFiles].length());
try {
addRow(vals);
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
}
}
} else {
if (dir.isFile()) {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = dir.getName();
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = dir.length();
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1) {
vals[nCIndex] = dir.lastModified();
}
try {
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
else {
try {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = null;
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1)
vals[nCIndex] = 0;
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
}
}
}
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.ffxcp;
import java.io.File;
import java.io.IOException;
import android.database.MatrixCursor;
public class DirCursor extends MatrixCursor {
public static final String _ID = "_id";
public static final String ISDIR = "isdir";
public static final String FILENAME = "filename";
public static final String LENGTH = "length";
public static final String TIMESTAMP = "ts";
public static final String WRITABLE = "writable";
static final String[] DEFCOLUMNS = new String[] {
_ID,
ISDIR,
FILENAME,
LENGTH,
TIMESTAMP,
WRITABLE
};
private String dirPath = null;
private String [] theColumns = null;
public DirCursor(String[] columnNames, String sPath) {
super((columnNames == null ? DEFCOLUMNS : columnNames));
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
dirPath = sPath;
doLoadCursor(dirPath);
}
public DirCursor(String[] columnNames, int initialCapacity, String sPath) {
super((columnNames == null ? DEFCOLUMNS : columnNames), initialCapacity);
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
dirPath = sPath;
doLoadCursor(dirPath);
}
private void doLoadCursor(String sDir) {
File dir = new File(sDir);
int nFiles = 0;
int nCols = theColumns.length;
int lcvFiles = 0;
int nCIndex = 0;
Object [] vals = new Object[nCols];
if (vals == null)
return;
if (dir.isDirectory()) {
try {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 1;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
try {
vals[nCIndex] = dir.getCanonicalPath();
} catch (IOException e) {
vals[nCIndex] = dir.getName();
}
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(WRITABLE);
if (nCIndex > -1)
vals[nCIndex] = (dir.canWrite() ? 1 : 0);
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
File [] files = dir.listFiles();
if (files != null) {
if ((nFiles = files.length) > 0) {
for (lcvFiles = 0; lcvFiles < nFiles; lcvFiles++) {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = lcvFiles;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = (files[lcvFiles].isDirectory() ? 1 : 0);
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = files[lcvFiles].getName();
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = (files[lcvFiles].isDirectory() ? -1 : files[lcvFiles].length());
try {
addRow(vals);
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
}
}
} else {
if (dir.isFile()) {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = dir.getName();
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = dir.length();
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1) {
vals[nCIndex] = dir.lastModified();
}
try {
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
else {
try {
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1)
vals[nCIndex] = -1;
nCIndex = getColumnIndex(ISDIR);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(FILENAME);
if (nCIndex > -1)
vals[nCIndex] = null;
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1)
vals[nCIndex] = 0;
nCIndex = getColumnIndex(TIMESTAMP);
if (nCIndex > -1)
vals[nCIndex] = 0;
addRow(vals);
}
catch (IllegalArgumentException iae) {
iae.printStackTrace();
}
}
}
}
}

Просмотреть файл

@ -1,190 +1,226 @@
package org.mozilla.ffxcp;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
public class FfxCPFP extends ContentProvider {
public static final String PROVIDER_NAME = "org.mozilla.ffxcp";
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/file");
public static final String _ID = "_id";
public static final String ISDIR = "isdir";
public static final String FILENAME = "filename";
public static final String LENGTH = "length";
public static final String CHUNK = "chunk";
static String[] dircolumns = new String[] {
_ID,
ISDIR,
FILENAME,
LENGTH
};
static String[] filecolumns = new String[] {
_ID,
CHUNK
};
private static final int DIR = 1;
private static final int FILE_NAME = 2;
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "dir", DIR);
uriMatcher.addURI(PROVIDER_NAME, "file", FILE_NAME);
}
public int PruneDir(String sTmpDir) {
int nRet = 0;
int nFiles = 0;
String sSubDir = null;
File dir = new File(sTmpDir);
if (dir.isDirectory()) {
File [] files = dir.listFiles();
if (files != null) {
if ((nFiles = files.length) > 0) {
for (int lcv = 0; lcv < nFiles; lcv++) {
if (files[lcv].isDirectory()) {
sSubDir = files[lcv].getAbsolutePath();
nRet += PruneDir(sSubDir);
}
else {
if (files[lcv].delete()) {
nRet++;
}
}
}
}
}
if (dir.delete()) {
nRet++;
}
if ((nFiles + 1) > nRet) {
nRet = -1;
}
}
return(nRet);
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int nFiles = 0;
switch (uriMatcher.match(uri)) {
case FILE_NAME:
File f = new File(selection);
if (f.delete())
nFiles = 1;
break;
case DIR:
nFiles = PruneDir(selection);
break;
default:
break;
}
return nFiles;
}
@Override
public String getType(Uri uri)
{
switch (uriMatcher.match(uri))
{
//---get directory---
case DIR:
return "vnd.android.cursor.dir/vnd.mozilla.dir ";
//---get a particular file---
case FILE_NAME:
return "vnd.android.cursor.item/vnd.mozilla.file ";
//---Unknown---
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Cursor retCursor = null;
switch(uriMatcher.match(uri)) {
case DIR:
retCursor = new DirCursor(projection, selection);
break;
case FILE_NAME:
retCursor = new FileCursor(projection, selection, selectionArgs);
break;
default:
break;
}
return (retCursor);
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int nRet = 0;
FileOutputStream dstFile = null;
switch(uriMatcher.match(uri)) {
case DIR:
File dir = new File(selection);
if (dir.mkdirs())
nRet = 1;
break;
case FILE_NAME:
try {
long lOffset = values.getAsLong("offset");
byte [] buf = values.getAsByteArray(CHUNK);
int nLength = values.getAsInteger(LENGTH);
if ((buf != null) && (nLength > 0)) {
File f = new File(selection);
dstFile = new FileOutputStream(f, (lOffset == 0 ? false : true));
dstFile.write(buf,0, nLength);
dstFile.flush();
dstFile.close();
nRet = nLength;
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
try {
dstFile.flush();
} catch (IOException e) {
}
try {
dstFile.close();
} catch (IOException e) {
}
}
break;
default:
break;
}
return nRet;
}
}
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.ffxcp;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
public class FfxCPFP extends ContentProvider {
public static final String PROVIDER_NAME = "org.mozilla.ffxcp";
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/file");
public static final String _ID = "_id";
public static final String ISDIR = "isdir";
public static final String FILENAME = "filename";
public static final String LENGTH = "length";
public static final String CHUNK = "chunk";
static String[] dircolumns = new String[] {
_ID,
ISDIR,
FILENAME,
LENGTH
};
static String[] filecolumns = new String[] {
_ID,
CHUNK
};
private static final int DIR = 1;
private static final int FILE_NAME = 2;
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "dir", DIR);
uriMatcher.addURI(PROVIDER_NAME, "file", FILE_NAME);
}
public int PruneDir(String sTmpDir) {
int nRet = 0;
int nFiles = 0;
String sSubDir = null;
File dir = new File(sTmpDir);
if (dir.isDirectory()) {
File [] files = dir.listFiles();
if (files != null) {
if ((nFiles = files.length) > 0) {
for (int lcv = 0; lcv < nFiles; lcv++) {
if (files[lcv].isDirectory()) {
sSubDir = files[lcv].getAbsolutePath();
nRet += PruneDir(sSubDir);
}
else {
if (files[lcv].delete()) {
nRet++;
}
}
}
}
}
if (dir.delete()) {
nRet++;
}
if ((nFiles + 1) > nRet) {
nRet = -1;
}
}
return(nRet);
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int nFiles = 0;
switch (uriMatcher.match(uri)) {
case FILE_NAME:
File f = new File(selection);
if (f.delete())
nFiles = 1;
break;
case DIR:
nFiles = PruneDir(selection);
break;
default:
break;
}
return nFiles;
}
@Override
public String getType(Uri uri)
{
switch (uriMatcher.match(uri))
{
//---get directory---
case DIR:
return "vnd.android.cursor.dir/vnd.mozilla.dir ";
//---get a particular file---
case FILE_NAME:
return "vnd.android.cursor.item/vnd.mozilla.file ";
//---Unknown---
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Cursor retCursor = null;
switch(uriMatcher.match(uri)) {
case DIR:
retCursor = new DirCursor(projection, selection);
break;
case FILE_NAME:
retCursor = new FileCursor(projection, selection, selectionArgs);
break;
default:
break;
}
return (retCursor);
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int nRet = 0;
FileOutputStream dstFile = null;
switch(uriMatcher.match(uri)) {
case DIR:
File dir = new File(selection);
if (dir.mkdirs())
nRet = 1;
break;
case FILE_NAME:
try {
long lOffset = values.getAsLong("offset");
byte [] buf = values.getAsByteArray(CHUNK);
int nLength = values.getAsInteger(LENGTH);
if ((buf != null) && (nLength > 0)) {
File f = new File(selection);
dstFile = new FileOutputStream(f, (lOffset == 0 ? false : true));
dstFile.write(buf,0, nLength);
dstFile.flush();
dstFile.close();
nRet = nLength;
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
try {
dstFile.flush();
} catch (IOException e) {
}
try {
dstFile.close();
} catch (IOException e) {
}
}
break;
default:
break;
}
return nRet;
}
}

Просмотреть файл

@ -1,167 +1,203 @@
package org.mozilla.ffxcp;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.database.AbstractWindowedCursor;
import android.database.CursorWindow;
public class FileCursor extends AbstractWindowedCursor {
public static final String _ID = "_id";
public static final String CHUNK = "chunk";
public static final String LENGTH = "length";
static final String[] DEFCOLUMNS = new String[] {
_ID,
CHUNK,
LENGTH
};
private String filePath = null;
private String [] theColumns = null;
private static final int BUFSIZE = 4096;
private long lFileSize = 0;
private int nCount = 0;
private File theFile = null;
private byte [] theBuffer = null;
private long lOffset = 0;
private long lLength = -1;
public FileCursor(String[] columnNames, String sFilePath, String [] selectionArgs) {
super();
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
filePath = sFilePath;
nCount = -1;
if ((selectionArgs != null) && (selectionArgs.length > 0)) {
lOffset = Long.parseLong(selectionArgs[0]);
lLength = Long.parseLong(selectionArgs[1]);
}
if (filePath.length() > 0) {
theFile = new File(filePath);
if (theFile.exists() && theFile.canRead()) {
lFileSize = theFile.length();
// lLength == -1 return everything between lOffset and eof
// lLength == 0 return file length
// lLength > 0 return lLength bytes
if (lLength == -1) {
lFileSize = lFileSize - lOffset;
} else if (lLength == 0) {
// just return the file length
} else {
lFileSize = ((lLength <= (lFileSize - lOffset)) ? lLength : (lFileSize - lOffset));
}
if (lLength != 0) {
nCount = (int) (lFileSize / BUFSIZE);
if ((lFileSize % BUFSIZE) > 0)
nCount++;
} else {
nCount = 1;
}
mRowIdColumnIndex = 0;
}
}
}
public String getColumnName (int columnIndex) {
return theColumns[columnIndex];
}
@Override
public String[] getColumnNames() {
return theColumns;
}
@Override
public int getCount() {
return nCount;
}
@Override
public boolean onMove(int oldPosition, int newPosition) {
boolean bRet = true;
// get rid of old data
mWindow.clear();
bRet = mWindow.setNumColumns(theColumns.length);
fillWindow(newPosition, mWindow);
return bRet;
}
@Override
public void fillWindow (int pos, CursorWindow window) {
int nNumRows = window.getNumRows();
int nCIndex = 0;
window.setStartPosition(0);
if (pos > -1) {
if (nNumRows == 0) {
window.allocRow();
nNumRows = window.getNumRows();
}
if (nNumRows == 1) {
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1) {
window.putLong(lFileSize, 0, nCIndex);
}
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1) {
window.putLong((long)pos, 0, nCIndex);
}
nCIndex = getColumnIndex(CHUNK);
if (nCIndex > -1) {
if (lLength != 0) {
byte[] value = getABlob (pos, 1);
window.putBlob(value, 0, nCIndex);
}
}
}
window.setStartPosition(pos);
}
return;
}
public byte[] getABlob (int row, int column) {
int nRead = 0;
int nOffset = 0;
int nBufSize = 0;
if ((column == 1) && (theFile != null)) {
try {
FileInputStream fin = new FileInputStream(theFile);
nOffset = row * BUFSIZE;
if (row < (nCount - 1)) {
nBufSize = BUFSIZE;
} else {
nBufSize = (int) (lFileSize - nOffset);
}
theBuffer = new byte[nBufSize];
if (theBuffer != null) {
if (fin.skip(nOffset + lOffset) == (nOffset + lOffset)) {
if ((nRead = fin.read(theBuffer, 0, nBufSize)) != -1) {
if (nRead != nBufSize) {
return null;
}
}
}
}
fin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return theBuffer;
}
}
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.ffxcp;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import android.database.AbstractWindowedCursor;
import android.database.CursorWindow;
public class FileCursor extends AbstractWindowedCursor {
public static final String _ID = "_id";
public static final String CHUNK = "chunk";
public static final String LENGTH = "length";
static final String[] DEFCOLUMNS = new String[] {
_ID,
CHUNK,
LENGTH
};
private String filePath = null;
private String [] theColumns = null;
private static final int BUFSIZE = 4096;
private long lFileSize = 0;
private int nCount = 0;
private File theFile = null;
private byte [] theBuffer = null;
private long lOffset = 0;
private long lLength = -1;
public FileCursor(String[] columnNames, String sFilePath, String [] selectionArgs) {
super();
theColumns = (columnNames == null ? DEFCOLUMNS : columnNames);
filePath = sFilePath;
nCount = -1;
if ((selectionArgs != null) && (selectionArgs.length > 0)) {
lOffset = Long.parseLong(selectionArgs[0]);
lLength = Long.parseLong(selectionArgs[1]);
}
if (filePath.length() > 0) {
theFile = new File(filePath);
if (theFile.exists() && theFile.canRead()) {
lFileSize = theFile.length();
// lLength == -1 return everything between lOffset and eof
// lLength == 0 return file length
// lLength > 0 return lLength bytes
if (lLength == -1) {
lFileSize = lFileSize - lOffset;
} else if (lLength == 0) {
// just return the file length
} else {
lFileSize = ((lLength <= (lFileSize - lOffset)) ? lLength : (lFileSize - lOffset));
}
if (lLength != 0) {
nCount = (int) (lFileSize / BUFSIZE);
if ((lFileSize % BUFSIZE) > 0)
nCount++;
} else {
nCount = 1;
}
mRowIdColumnIndex = 0;
}
}
}
public String getColumnName (int columnIndex) {
return theColumns[columnIndex];
}
@Override
public String[] getColumnNames() {
return theColumns;
}
@Override
public int getCount() {
return nCount;
}
@Override
public boolean onMove(int oldPosition, int newPosition) {
boolean bRet = true;
// get rid of old data
mWindow.clear();
bRet = mWindow.setNumColumns(theColumns.length);
fillWindow(newPosition, mWindow);
return bRet;
}
@Override
public void fillWindow (int pos, CursorWindow window) {
int nNumRows = window.getNumRows();
int nCIndex = 0;
window.setStartPosition(0);
if (pos > -1) {
if (nNumRows == 0) {
window.allocRow();
nNumRows = window.getNumRows();
}
if (nNumRows == 1) {
nCIndex = getColumnIndex(LENGTH);
if (nCIndex > -1) {
window.putLong(lFileSize, 0, nCIndex);
}
nCIndex = getColumnIndex(_ID);
if (nCIndex > -1) {
window.putLong((long)pos, 0, nCIndex);
}
nCIndex = getColumnIndex(CHUNK);
if (nCIndex > -1) {
if (lLength != 0) {
byte[] value = getABlob (pos, 1);
window.putBlob(value, 0, nCIndex);
}
}
}
window.setStartPosition(pos);
}
return;
}
public byte[] getABlob (int row, int column) {
int nRead = 0;
int nOffset = 0;
int nBufSize = 0;
if ((column == 1) && (theFile != null)) {
try {
FileInputStream fin = new FileInputStream(theFile);
nOffset = row * BUFSIZE;
if (row < (nCount - 1)) {
nBufSize = BUFSIZE;
} else {
nBufSize = (int) (lFileSize - nOffset);
}
theBuffer = new byte[nBufSize];
if (theBuffer != null) {
if (fin.skip(nOffset + lOffset) == (nOffset + lOffset)) {
if ((nRead = fin.read(theBuffer, 0, nBufSize)) != -1) {
if (nRead != nBufSize) {
return null;
}
}
}
}
fin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return theBuffer;
}
}

Просмотреть файл

@ -1,23 +1,23 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package org.mozilla.ffxcp;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package org.mozilla.ffxcp;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int icon=0x7f020000;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int hello=0x7f040000;
}
}

Просмотреть файл

@ -1,3 +1,39 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package org.mozilla.ffxcp;
import android.app.Activity;

Просмотреть файл

@ -1,25 +1,25 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.mozilla.watcher;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ateamlogo=0x7f020000;
public static final int icon=0x7f020001;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int foreground_service_started=0x7f040002;
public static final int hello=0x7f040000;
}
}
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.mozilla.watcher;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ateamlogo=0x7f020000;
public static final int icon=0x7f020001;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040001;
public static final int foreground_service_started=0x7f040002;
public static final int hello=0x7f040000;
}
}

Просмотреть файл

@ -1,164 +1,164 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package com.mozilla.watcher;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
public class RedirOutputThread extends Thread
{
OutputStream out;
InputStream sutErr;
InputStream sutOut;
Process pProc;
String strOutput;
public RedirOutputThread(Process pProc, OutputStream out)
{
if (pProc != null)
{
this.pProc = pProc;
sutErr = pProc.getErrorStream(); // Stderr
sutOut = pProc.getInputStream(); // Stdout
}
if (out != null)
this.out = out;
strOutput = "";
}
public void run()
{
boolean bStillRunning = true;
int nBytesOut = 0;
int nBytesErr = 0;
int nBytesRead = 0;
PrintWriter pOut = null;
byte[] buffer = new byte[1024];
if (out != null)
pOut = new PrintWriter(out);
else
bStillRunning = true;
while (bStillRunning)
{
try
{
if ((nBytesOut = sutOut.available()) > 0)
{
if (nBytesOut > buffer.length)
{
buffer = null;
System.gc();
buffer = new byte[nBytesOut];
}
nBytesRead = sutOut.read(buffer, 0, nBytesOut);
if (nBytesRead == -1)
bStillRunning = false;
else
{
String sRep = new String(buffer,0,nBytesRead).replace("\n", "\r\n");
if (pOut != null)
{
pOut.print(sRep);
pOut.flush();
}
else
strOutput += sRep;
}
}
if ((nBytesErr = sutErr.available()) > 0)
{
if (nBytesErr > buffer.length)
{
buffer = null;
System.gc();
buffer = new byte[nBytesErr];
}
nBytesRead = sutErr.read(buffer, 0, nBytesErr);
if (nBytesRead == -1)
bStillRunning = false;
else
{
String sRep = new String(buffer,0,nBytesRead).replace("\n", "\r\n");
if (pOut != null)
{
pOut.print(sRep);
pOut.flush();
}
else
strOutput += sRep;
}
}
bStillRunning = (IsProcRunning(pProc) || (sutOut.available() > 0) || (sutErr.available() > 0));
}
catch (IOException e)
{
// Toast.makeText(SUTAgentAndroid.me.getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
pProc.destroy();
buffer = null;
System.gc();
}
private boolean IsProcRunning(Process pProc)
{
boolean bRet = false;
@SuppressWarnings("unused")
int nExitCode = 0;
try
{
nExitCode = pProc.exitValue();
}
catch (IllegalThreadStateException z)
{
bRet = true;
}
return(bRet);
}
}
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package com.mozilla.watcher;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
public class RedirOutputThread extends Thread
{
OutputStream out;
InputStream sutErr;
InputStream sutOut;
Process pProc;
String strOutput;
public RedirOutputThread(Process pProc, OutputStream out)
{
if (pProc != null)
{
this.pProc = pProc;
sutErr = pProc.getErrorStream(); // Stderr
sutOut = pProc.getInputStream(); // Stdout
}
if (out != null)
this.out = out;
strOutput = "";
}
public void run()
{
boolean bStillRunning = true;
int nBytesOut = 0;
int nBytesErr = 0;
int nBytesRead = 0;
PrintWriter pOut = null;
byte[] buffer = new byte[1024];
if (out != null)
pOut = new PrintWriter(out);
else
bStillRunning = true;
while (bStillRunning)
{
try
{
if ((nBytesOut = sutOut.available()) > 0)
{
if (nBytesOut > buffer.length)
{
buffer = null;
System.gc();
buffer = new byte[nBytesOut];
}
nBytesRead = sutOut.read(buffer, 0, nBytesOut);
if (nBytesRead == -1)
bStillRunning = false;
else
{
String sRep = new String(buffer,0,nBytesRead).replace("\n", "\r\n");
if (pOut != null)
{
pOut.print(sRep);
pOut.flush();
}
else
strOutput += sRep;
}
}
if ((nBytesErr = sutErr.available()) > 0)
{
if (nBytesErr > buffer.length)
{
buffer = null;
System.gc();
buffer = new byte[nBytesErr];
}
nBytesRead = sutErr.read(buffer, 0, nBytesErr);
if (nBytesRead == -1)
bStillRunning = false;
else
{
String sRep = new String(buffer,0,nBytesRead).replace("\n", "\r\n");
if (pOut != null)
{
pOut.print(sRep);
pOut.flush();
}
else
strOutput += sRep;
}
}
bStillRunning = (IsProcRunning(pProc) || (sutOut.available() > 0) || (sutErr.available() > 0));
}
catch (IOException e)
{
// Toast.makeText(SUTAgentAndroid.me.getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
pProc.destroy();
buffer = null;
System.gc();
}
private boolean IsProcRunning(Process pProc)
{
boolean bRet = false;
@SuppressWarnings("unused")
int nExitCode = 0;
try
{
nExitCode = pProc.exitValue();
}
catch (IllegalThreadStateException z)
{
bRet = true;
}
return(bRet);
}
}

Просмотреть файл

@ -1,3 +1,39 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package com.mozilla.watcher;
import android.app.Activity;

Просмотреть файл

@ -1,19 +1,55 @@
package com.mozilla.watcher;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
// import android.os.Debug;
public class WatcherReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Debug.waitForDebugger();
Intent serviceIntent = new Intent();
serviceIntent.putExtra("command", "start");
serviceIntent.setAction("com.mozilla.watcher.LISTENER_SERVICE");
context.startService(serviceIntent);
}
}
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Android SUTAgent code.
*
* The Initial Developer of the Original Code is
* Bob Moss.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bob Moss <bmoss@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
package com.mozilla.watcher;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
// import android.os.Debug;
public class WatcherReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Debug.waitForDebugger();
Intent serviceIntent = new Intent();
serviceIntent.putExtra("command", "start");
serviceIntent.setAction("com.mozilla.watcher.LISTENER_SERVICE");
context.startService(serviceIntent);
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу