merge m-c to devtools
20
Makefile.in
|
@ -88,11 +88,6 @@ DIST_GARBAGE = config.cache config.log config.status config-defs.h \
|
|||
netwerk/necko-config.h xpcom/xpcom-config.h xpcom/xpcom-private.h \
|
||||
$(topsrcdir)/.mozconfig.mk $(topsrcdir)/.mozconfig.out
|
||||
|
||||
ifdef WINCE
|
||||
check::
|
||||
$(PYTHON) $(topsrcdir)/build/mobile/devicemanager-utils.py copy $(DIST)/bin
|
||||
endif
|
||||
|
||||
default alldep all:: $(topsrcdir)/configure config.status
|
||||
$(RM) -r $(DIST)/sdk
|
||||
$(RM) -r $(DIST)/include
|
||||
|
@ -195,21 +190,6 @@ endif
|
|||
mv $(SYMBOL_INDEX_NAME).tmp $(SYMBOL_INDEX_NAME)
|
||||
cd $(DIST)/crashreporter-symbols && \
|
||||
zip -r9D "../$(PKG_PATH)$(SYMBOL_ARCHIVE_BASENAME).zip" . -i "*.sym" -i "*.txt"
|
||||
else
|
||||
ifdef WINCE
|
||||
ifdef SYMBOLSTORE_PATH
|
||||
echo building symbol store with symstore.exe
|
||||
$(RM) -r $(DIST)/symbols
|
||||
$(RM) "$(DIST)/$(SYMBOL_ARCHIVE_BASENAME).zip"
|
||||
$(NSINSTALL) -D $(DIST)/symbols
|
||||
$(SYMBOLSTORE_PATH) add -r -f "$(subst /,\,$(shell pwd -W))\*.PDB" \
|
||||
-s $(DIST)/symbols/ -t "$(MOZ_PKG_APPNAME)" -v "$(MOZ_PKG_VERSION)"
|
||||
echo packing symbols
|
||||
$(NSINSTALL) -D $(DIST)/$(PKG_PATH)
|
||||
cd $(DIST)/symbols && \
|
||||
zip -r9D "../$(PKG_PATH)$(SYMBOL_ARCHIVE_BASENAME).zip" .
|
||||
endif # SYMBOLSTORE_PATH
|
||||
endif # WINCE
|
||||
endif # MOZ_CRASHREPORTER
|
||||
|
||||
uploadsymbols:
|
||||
|
|
|
@ -466,7 +466,7 @@ nsFontSizeTextAttr::Format(const nscoord& aValue, nsAString& aFormattedValue)
|
|||
//
|
||||
// XXX todo: consider sharing this code with layout module? (bug 474621)
|
||||
float px =
|
||||
NSAppUnitsToFloatPixels(aValue, nsIDeviceContext::AppUnitsPerCSSPixel());
|
||||
NSAppUnitsToFloatPixels(aValue, nsDeviceContext::AppUnitsPerCSSPixel());
|
||||
// Each pt is 4/3 of a CSS pixel.
|
||||
int pts = NS_lround(px*3/4);
|
||||
|
||||
|
|
|
@ -337,7 +337,7 @@ private:
|
|||
*/
|
||||
nscoord GetFontSize(nsIFrame *aFrame);
|
||||
|
||||
nsIDeviceContext *mDC;
|
||||
nsDeviceContext *mDC;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ nsHyperTextAccessible::GetPosAndText(PRInt32& aStartOffset, PRInt32& aEndOffset,
|
|||
*aEndFrame = nsnull;
|
||||
}
|
||||
if (aBoundsRect) {
|
||||
aBoundsRect->Empty();
|
||||
aBoundsRect->SetEmpty();
|
||||
}
|
||||
if (aStartAcc)
|
||||
*aStartAcc = nsnull;
|
||||
|
|
|
@ -75,17 +75,6 @@ probes/Makefile
|
|||
extensions/Makefile
|
||||
"
|
||||
|
||||
if [ "$WINCE" ]; then
|
||||
add_makefiles "
|
||||
build/wince/tools/Makefile
|
||||
build/wince/shunt/Makefile
|
||||
build/wince/shunt/include/windows.h
|
||||
build/wince/shunt/include/ymath.h
|
||||
build/wince/shunt/include/stdlib.h
|
||||
build/wince/shunt/include/sys/Makefile
|
||||
"
|
||||
fi
|
||||
|
||||
if [ "$MOZ_MEMORY" -a "$LIBXUL_SDK" = "" ]; then
|
||||
add_makefiles "
|
||||
memory/jemalloc/Makefile
|
||||
|
|
|
@ -87,7 +87,9 @@
|
|||
}
|
||||
|
||||
#updateDeck > hbox > label:not([class="text-link"]) {
|
||||
%ifdef MOZ_OFFICIAL_BRANDING
|
||||
color: #909090;
|
||||
%endif
|
||||
font-style:italic;
|
||||
}
|
||||
|
||||
|
|
|
@ -3296,16 +3296,15 @@ const BrowserSearch = {
|
|||
win.BrowserSearch.webSearch();
|
||||
} else {
|
||||
// If there are no open browser windows, open a new one
|
||||
|
||||
// This needs to be in a timeout so that we don't end up refocused
|
||||
// in the url bar
|
||||
function webSearchCallback() {
|
||||
setTimeout(BrowserSearch.webSearch, 0);
|
||||
function observer(subject, topic, data) {
|
||||
if (subject == win) {
|
||||
BrowserSearch.webSearch();
|
||||
Services.obs.removeObserver(observer, "browser-delayed-startup-finished");
|
||||
}
|
||||
}
|
||||
|
||||
win = window.openDialog("chrome://browser/content/", "_blank",
|
||||
"chrome,all,dialog=no", "about:blank");
|
||||
win.addEventListener("load", webSearchCallback, false);
|
||||
Services.obs.addObserver(observer, "browser-delayed-startup-finished", false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -261,6 +261,14 @@ BrowserGlue.prototype = {
|
|||
else if (data == "force-ui-migration") {
|
||||
this._migrateUI();
|
||||
}
|
||||
else if (data == "force-distribution-customization") {
|
||||
this._distributionCustomizer.applyPrefDefaults();
|
||||
this._distributionCustomizer.applyCustomizations();
|
||||
// To apply distribution bookmarks use "places-init-complete".
|
||||
}
|
||||
else if (data == "force-places-init") {
|
||||
this._initPlaces();
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -84,11 +84,11 @@ function searchHistory(aInput)
|
|||
case "visited":
|
||||
resultType = NHQO.RESULTS_AS_URI;
|
||||
sortingMode = NHQO.SORT_BY_VISITCOUNT_DESCENDING;
|
||||
break;
|
||||
break;
|
||||
case "lastvisited":
|
||||
resultType = NHQO.RESULTS_AS_URI;
|
||||
sortingMode = NHQO.SORT_BY_DATE_DESCENDING;
|
||||
break;
|
||||
break;
|
||||
case "dayandsite":
|
||||
resultType = NHQO.RESULTS_AS_DATE_SITE_QUERY;
|
||||
break;
|
||||
|
@ -105,7 +105,7 @@ function searchHistory(aInput)
|
|||
if (aInput) {
|
||||
query.searchTerms = aInput;
|
||||
if (gHistoryGrouping != "visited" && gHistoryGrouping != "lastvisited") {
|
||||
sortingMode = NHQO.SORT_BY_TITLE_ASCENDING;
|
||||
sortingMode = NHQO.SORT_BY_FRECENCY_DESCENDING;
|
||||
resultType = NHQO.RESULTS_AS_URI;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,62 +1,20 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/* ***** 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 Places Unit Test code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Marco Bonardo <mak77@bonardo.net>
|
||||
*
|
||||
* 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 ***** */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Tests that nsBrowserGlue does not overwrite bookmarks imported from the
|
||||
* migrators. They usually run before nsBrowserGlue, so if we find any
|
||||
* bookmark on init, we should not try to import.
|
||||
* Tests that nsBrowserGlue correctly imports bookmarks from distribution.ini.
|
||||
*/
|
||||
|
||||
const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
|
||||
const PREF_BMPROCESSED = "distribution.516444.bookmarksProcessed";
|
||||
const PREF_DISTRIBUTION_ID = "distribution.id";
|
||||
|
||||
const TOPIC_FINAL_UI_STARTUP = "final-ui-startup";
|
||||
const TOPICDATA_DISTRIBUTION_CUSTOMIZATION = "force-distribution-customization";
|
||||
const TOPIC_CUSTOMIZATION_COMPLETE = "distribution-customization-complete";
|
||||
const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
|
||||
|
||||
function run_test() {
|
||||
// This is needed but we still have to investigate the reason, could just be
|
||||
// we try to act too late in the game, moving our shutdown earlier will help.
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
// TODO: re-enable when bug 523936 is fixed.
|
||||
return;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
do_test_pending();
|
||||
|
||||
// Copy distribution.ini file to our app dir.
|
||||
|
@ -68,82 +26,67 @@ function run_test() {
|
|||
iniFile.remove(false);
|
||||
print("distribution.ini already exists, did some test forget to cleanup?");
|
||||
}
|
||||
|
||||
let testDistributionFile = gTestDir.clone();
|
||||
testDistributionFile.append("distribution.ini");
|
||||
testDistributionFile.copyTo(distroDir, "distribution.ini");
|
||||
do_check_true(testDistributionFile.exists());
|
||||
|
||||
// Disable Smart Bookmarks creation.
|
||||
let ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
// Avoid migrateUI, we are just simulating a partial startup.
|
||||
ps.setIntPref("browser.migration.version", 4);
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
|
||||
// Initialize Places through the History Service.
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
// Check a new database has been created.
|
||||
// nsBrowserGlue will use databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
|
||||
// Initialize Places through the History Service and check that a new
|
||||
// database has been created.
|
||||
do_check_eq(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
|
||||
// Initialize nsBrowserGlue.
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIBrowserGlue);
|
||||
// Force distribution.
|
||||
Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIObserver).observe(null,
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_DISTRIBUTION_CUSTOMIZATION);
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
let observer = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(this, PlacesUtils.TOPIC_INIT_COMPLETE);
|
||||
|
||||
// Simulate browser startup.
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
TOPIC_FINAL_UI_STARTUP,
|
||||
null);
|
||||
// Test will continue on customization complete notification.
|
||||
let cObserver = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
os.removeObserver(this, TOPIC_CUSTOMIZATION_COMPLETE);
|
||||
do_execute_soon(continue_test);
|
||||
}
|
||||
}
|
||||
os.addObserver(cObserver, TOPIC_CUSTOMIZATION_COMPLETE, false);
|
||||
}
|
||||
}
|
||||
os.addObserver(observer, PlacesUtils.TOPIC_INIT_COMPLETE, false);
|
||||
// Test will continue on customization complete notification.
|
||||
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee,
|
||||
TOPIC_CUSTOMIZATION_COMPLETE,
|
||||
false);
|
||||
do_execute_soon(onCustomizationComplete);
|
||||
}, TOPIC_CUSTOMIZATION_COMPLETE, false);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
dump_table("moz_bookmarks");
|
||||
|
||||
function onCustomizationComplete()
|
||||
{
|
||||
// Check the custom bookmarks exist on menu.
|
||||
let menuItemId = bs.getIdForItemAt(bs.bookmarksMenuFolder, 0);
|
||||
let menuItemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0);
|
||||
do_check_neq(menuItemId, -1);
|
||||
do_check_eq(bs.getItemTitle(menuItemId), "Menu Link Before");
|
||||
menuItemId = bs.getIdForItemAt(bs.bookmarksMenuFolder, 1 + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId),
|
||||
"Menu Link Before");
|
||||
menuItemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
||||
1 + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
do_check_neq(menuItemId, -1);
|
||||
do_check_eq(bs.getItemTitle(menuItemId), "Menu Link After");
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId),
|
||||
"Menu Link After");
|
||||
|
||||
// Check the custom bookmarks exist on toolbar.
|
||||
let toolbarItemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
let toolbarItemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_neq(toolbarItemId, -1);
|
||||
do_check_eq(bs.getItemTitle(toolbarItemId), "Toolbar Link Before");
|
||||
toolbarItemId = bs.getIdForItemAt(bs.toolbarFolder, 1 + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId),
|
||||
"Toolbar Link Before");
|
||||
toolbarItemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
1 + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_neq(toolbarItemId, -1);
|
||||
do_check_eq(bs.getItemTitle(toolbarItemId), "Toolbar Link After");
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId),
|
||||
"Toolbar Link After");
|
||||
|
||||
// Check the bmprocessed pref has been created.
|
||||
let ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
do_check_true(ps.getBoolPref(PREF_BMPROCESSED));
|
||||
do_check_true(Services.prefs.getBoolPref(PREF_BMPROCESSED));
|
||||
|
||||
// Check distribution prefs have been created.
|
||||
do_check_eq(ps.getCharPref(PREF_DISTRIBUTION_ID), "516444");
|
||||
do_check_eq(Services.prefs.getCharPref(PREF_DISTRIBUTION_ID), "516444");
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
|
|
|
@ -1,40 +1,5 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/* ***** 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 Places Unit Test code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Marco Bonardo <mak77@bonardo.net>
|
||||
*
|
||||
* 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 ***** */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Tests that nsBrowserGlue does not overwrite bookmarks imported from the
|
||||
|
@ -42,39 +7,13 @@
|
|||
* bookmark on init, we should not try to import.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onBeforeItemRemoved: function(id) {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
// Create our bookmarks.html copying bookmarks.glue.html to the profile
|
||||
// folder. It will be ignored.
|
||||
// folder. It should be ignored.
|
||||
create_bookmarks_html("bookmarks.glue.html");
|
||||
|
||||
// Remove current database file.
|
||||
|
@ -85,35 +24,61 @@ function run_test() {
|
|||
do_check_false(db.exists());
|
||||
}
|
||||
|
||||
// Initialize Places through the History Service.
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
// Check a new database has been created.
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
|
||||
// Initialize Places through the History Service and check that a new
|
||||
// database has been created.
|
||||
do_check_eq(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
|
||||
// A migrator would run before nsBrowserGlue, so we mimic that behavior
|
||||
// adding a bookmark.
|
||||
bs.insertBookmark(bs.bookmarksMenuFolder, uri("http://mozilla.org/"),
|
||||
bs.DEFAULT_INDEX, "migrated");
|
||||
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder, uri("http://mozilla.org/"),
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "migrated");
|
||||
|
||||
// Initialize nsBrowserGlue.
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIBrowserGlue);
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
// Check if the currently finished batch created the smart bookmarks.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (PlacesUtils.annotations
|
||||
.itemHasAnnotation(itemId, "Places/SmartBookmark")) {
|
||||
do_execute_soon(onSmartBookmarksCreation);
|
||||
}
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onBeforeItemRemoved: function(id) {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
// The test will continue once import has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
PlacesUtils.bookmarks.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
|
||||
function continue_test() {
|
||||
function onSmartBookmarksCreation() {
|
||||
// Check the created bookmarks still exist.
|
||||
let itemId = bs.getIdForItemAt(bs.bookmarksMenuFolder, SMART_BOOKMARKS_ON_MENU);
|
||||
do_check_eq(bs.getItemTitle(itemId), "migrated");
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
||||
SMART_BOOKMARKS_ON_MENU);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "migrated");
|
||||
|
||||
// Check that we have not imported any new bookmark.
|
||||
do_check_eq(bs.getIdForItemAt(bs.bookmarksMenuFolder, SMART_BOOKMARKS_ON_MENU + 1), -1);
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_MENU), -1);
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
||||
SMART_BOOKMARKS_ON_MENU + 1)
|
||||
do_check_eq(itemId, -1);
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_MENU)
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
remove_bookmarks_html();
|
||||
|
||||
|
|
|
@ -1,287 +1,265 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/* ***** 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 Places Unit Test code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Marco Bonardo <mak77@bonardo.net>
|
||||
*
|
||||
* 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 ***** */
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Tests that nsBrowserGlue is correctly interpreting the preferences settable
|
||||
* by the user or by other components.
|
||||
*/
|
||||
|
||||
/** Bug 539067
|
||||
* Test is disabled due to random failures and timeouts, see run_test.
|
||||
* This is commented out to avoid leaks.
|
||||
// Initialize browserGlue.
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIBrowserGlue);
|
||||
*/
|
||||
|
||||
// Initialize Places through Bookmarks Service.
|
||||
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
||||
getService(Ci.nsINavBookmarksService);
|
||||
|
||||
// Get other services.
|
||||
let ps = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
let os = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
|
||||
const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML";
|
||||
const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks";
|
||||
const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
|
||||
const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML";
|
||||
|
||||
let tests = [];
|
||||
//------------------------------------------------------------------------------
|
||||
const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
|
||||
const TOPICDATA_FORCE_PLACES_INIT = "force-places-init";
|
||||
|
||||
tests.push({
|
||||
description: "Import from bookmarks.html if importBookmarksHTML is true.",
|
||||
exec: function() {
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIBrowserGlue);
|
||||
|
||||
let gTests = [
|
||||
|
||||
// This test must be the first one.
|
||||
function test_checkPreferences() {
|
||||
// Initialize Places through the History Service and check that a new
|
||||
// database has been created.
|
||||
do_check_eq(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
|
||||
// Wait for Places init notification.
|
||||
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee,
|
||||
PlacesUtils.TOPIC_INIT_COMPLETE);
|
||||
do_execute_soon(function () {
|
||||
// Ensure preferences status.
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
|
||||
|
||||
try {
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
do_throw("importBookmarksHTML pref should not exist");
|
||||
}
|
||||
catch(ex) {}
|
||||
|
||||
try {
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
do_throw("importBookmarksHTML pref should not exist");
|
||||
}
|
||||
catch(ex) {}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
}, PlacesUtils.TOPIC_INIT_COMPLETE, false);
|
||||
},
|
||||
|
||||
function test_import()
|
||||
{
|
||||
do_log_info("Import from bookmarks.html if importBookmarksHTML is true.");
|
||||
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
// Force nsBrowserGlue::_initPlaces().
|
||||
print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
PlacesUtils.TOPIC_INIT_COMPLETE,
|
||||
null);
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
|
||||
// Check bookmarks.html has been imported, and a smart bookmark has been
|
||||
// created.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||
itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example");
|
||||
// Check preferences have been reverted.
|
||||
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
run_next_test();
|
||||
},
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function test_import_noSmartBookmarks()
|
||||
{
|
||||
do_log_info("import from bookmarks.html, but don't create smart bookmarks \
|
||||
if they are disabled");
|
||||
|
||||
tests.push({
|
||||
description: "import from bookmarks.html, but don't create smart bookmarks if they are disabled",
|
||||
exec: function() {
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
// Force nsBrowserGlue::_initPlaces().
|
||||
print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
PlacesUtils.TOPIC_INIT_COMPLETE,
|
||||
null);
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example");
|
||||
// Check preferences have been reverted.
|
||||
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
run_next_test();
|
||||
},
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function test_import_autoExport_updatedSmartBookmarks()
|
||||
{
|
||||
do_log_info("Import from bookmarks.html, but don't create smart bookmarks \
|
||||
if autoExportHTML is true and they are at latest version");
|
||||
|
||||
tests.push({
|
||||
description: "Import from bookmarks.html, but don't create smart bookmarks if autoExportHTML is true and they are at latest version",
|
||||
exec: function() {
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999);
|
||||
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999);
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
// Force nsBrowserGlue::_initPlaces()
|
||||
print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
PlacesUtils.TOPIC_INIT_COMPLETE,
|
||||
null);
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example");
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
// Check preferences have been reverted.
|
||||
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
run_next_test();
|
||||
},
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function test_import_autoExport_oldSmartBookmarks()
|
||||
{
|
||||
do_log_info("Import from bookmarks.html, and create smart bookmarks if \
|
||||
autoExportHTML is true and they are not at latest version.");
|
||||
|
||||
tests.push({
|
||||
description: "Import from bookmarks.html, and create smart bookmarks if autoExportHTML is true and they are not at latest version.",
|
||||
exec: function() {
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
ps.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
// Force nsBrowserGlue::_initPlaces()
|
||||
print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
PlacesUtils.TOPIC_INIT_COMPLETE,
|
||||
null);
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example");
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
// Check preferences have been reverted.
|
||||
ps.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
run_next_test();
|
||||
},
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
tests.push({
|
||||
description: "restore from default bookmarks.html if restore_default_bookmarks is true.",
|
||||
exec: function() {
|
||||
function test_restore()
|
||||
{
|
||||
do_log_info("restore from default bookmarks.html if \
|
||||
restore_default_bookmarks is true.");
|
||||
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
ps.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||
Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||
|
||||
// Force nsBrowserGlue::_initPlaces()
|
||||
print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
PlacesUtils.TOPIC_INIT_COMPLETE,
|
||||
null);
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
|
||||
// Check bookmarks.html has been restored.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + 1);
|
||||
do_check_true(itemId > 0);
|
||||
// Check preferences have been reverted.
|
||||
do_check_false(ps.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
run_next_test();
|
||||
},
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
function test_restore_import()
|
||||
{
|
||||
do_log_info("setting both importBookmarksHTML and \
|
||||
restore_default_bookmarks should restore defaults.");
|
||||
|
||||
tests.push({
|
||||
description: "setting both importBookmarksHTML and restore_default_bookmarks should restore defaults.",
|
||||
exec: function() {
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
do_check_eq(bs.getIdForItemAt(bs.toolbarFolder, 0), -1);
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
ps.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
ps.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||
|
||||
// Force nsBrowserGlue::_initPlaces()
|
||||
print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
PlacesUtils.TOPIC_INIT_COMPLETE,
|
||||
null);
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
|
||||
// Check bookmarks.html has been restored.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR + 1);
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + 1);
|
||||
do_check_true(itemId > 0);
|
||||
// Check preferences have been reverted.
|
||||
do_check_false(ps.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
do_test_finished();
|
||||
run_next_test();
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
];
|
||||
|
||||
function finish_test() {
|
||||
// Clean up database from all bookmarks.
|
||||
do_register_cleanup(function () {
|
||||
remove_all_bookmarks();
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
});
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
var testIndex = 0;
|
||||
function next_test() {
|
||||
// Clean up database from all bookmarks.
|
||||
remove_all_bookmarks();
|
||||
// nsBrowserGlue stops observing topics after first notification,
|
||||
// so we add back the observer to test additional runs.
|
||||
os.addObserver(bg.QueryInterface(Ci.nsIObserver),
|
||||
PlacesUtils.TOPIC_INIT_COMPLETE, false);
|
||||
os.addObserver(bg.QueryInterface(Ci.nsIObserver),
|
||||
PlacesUtils.TOPIC_DATABASE_LOCKED, false);
|
||||
// Execute next test.
|
||||
let test = tests.shift();
|
||||
print("\nTEST " + (++testIndex) + ": " + test.description);
|
||||
test.exec();
|
||||
}
|
||||
function run_test() {
|
||||
// Bug 539067: disabled due to random failures and timeouts.
|
||||
return;
|
||||
|
||||
do_test_pending();
|
||||
// Enqueue test, so it will consume the default places-init-complete
|
||||
// notification created at Places init.
|
||||
do_timeout(0, start_tests);
|
||||
}
|
||||
|
||||
function start_tests() {
|
||||
// Clean up database from all bookmarks.
|
||||
remove_all_bookmarks();
|
||||
|
||||
// Ensure preferences status.
|
||||
do_check_false(ps.getBoolPref(PREF_AUTO_EXPORT_HTML));
|
||||
try {
|
||||
do_check_false(ps.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
do_throw("importBookmarksHTML pref should not exist");
|
||||
}
|
||||
catch(ex) {}
|
||||
do_check_false(ps.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// Create our bookmarks.html from bookmarks.glue.html.
|
||||
create_bookmarks_html("bookmarks.glue.html");
|
||||
// Create our JSON backup from bookmarks.glue.json.
|
||||
create_JSON_backup("bookmarks.glue.json");
|
||||
// Kick-off tests.
|
||||
next_test();
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ include $(DEPTH)/config/autoconf.mk
|
|||
|
||||
MODULE = build
|
||||
|
||||
ifeq (,$(filter WINCE WINNT OS2,$(OS_ARCH)))
|
||||
ifeq (,$(filter WINNT OS2,$(OS_ARCH)))
|
||||
DIRS = unix
|
||||
endif
|
||||
|
||||
|
@ -53,26 +53,14 @@ ifeq (WINNT,$(OS_ARCH))
|
|||
DIRS = win32
|
||||
endif
|
||||
|
||||
ifdef WINCE
|
||||
# We need jemalloc built before the shunt
|
||||
ifdef MOZ_MEMORY
|
||||
DIRS += wince/tools \
|
||||
$(DEPTH)/memory/jemalloc \
|
||||
wince/shunt \
|
||||
$(DEPTH)/memory/mozalloc \
|
||||
$(NULL)
|
||||
else
|
||||
DIRS += wince/tools \
|
||||
wince/shunt \
|
||||
$(DEPTH)/memory/mozalloc \
|
||||
$(NULL)
|
||||
endif
|
||||
endif
|
||||
|
||||
DIRS += pgo
|
||||
|
||||
ifeq (Android,$(OS_TARGET))
|
||||
DIRS += mobile/sutagent/android
|
||||
DIRS += mobile/sutagent/android \
|
||||
mobile/sutagent/android/watcher \
|
||||
mobile/sutagent/android/ffxcp \
|
||||
mobile/sutagent/android/fencp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
# finds the location of the browser and puts it in the variable $(browser_path)
|
||||
|
||||
ifneq (,$(filter OS2 WINCE WINNT,$(OS_ARCH)))
|
||||
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
|
||||
PROGRAM = $(MOZ_APP_NAME)$(BIN_SUFFIX)
|
||||
else
|
||||
PROGRAM = $(MOZ_APP_NAME)-bin$(BIN_SUFFIX)
|
||||
|
|
|
@ -1,122 +1,215 @@
|
|||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Timer;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
// import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ASMozStub extends android.app.Service {
|
||||
|
||||
private ServerSocket cmdChnl = null;
|
||||
private ServerSocket dataChnl = null;
|
||||
private Handler handler = new Handler();
|
||||
RunCmdThread runCmdThrd = null;
|
||||
RunDataThread runDataThrd = null;
|
||||
Thread monitor = null;
|
||||
Timer timer = null;
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Toast.makeText(this, "Listener Service created...", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public void onStart(Intent intent, int startId) {
|
||||
super.onStart(intent, startId);
|
||||
|
||||
try {
|
||||
cmdChnl = new ServerSocket(20701);
|
||||
runCmdThrd = new RunCmdThread(cmdChnl, this, handler);
|
||||
runCmdThrd.start();
|
||||
Toast.makeText(this, "Command channel port 20701 ...", Toast.LENGTH_LONG).show();
|
||||
|
||||
dataChnl = new ServerSocket(20700);
|
||||
runDataThrd = new RunDataThread(dataChnl, this);
|
||||
runDataThrd.start();
|
||||
Toast.makeText(this, "Data channel port 20700 ...", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Toast.makeText(getApplication().getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
if (runCmdThrd.isAlive())
|
||||
{
|
||||
runCmdThrd.StopListening();
|
||||
}
|
||||
|
||||
if (runDataThrd.isAlive())
|
||||
{
|
||||
runDataThrd.StopListening();
|
||||
}
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(1959);
|
||||
|
||||
Toast.makeText(this, "Listener Service destroyed...", Toast.LENGTH_LONG).show();
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void SendToDataChannel(String strToSend)
|
||||
{
|
||||
if (runDataThrd.isAlive())
|
||||
{
|
||||
runDataThrd.SendToDataChannel(strToSend);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Timer;
|
||||
|
||||
import com.mozilla.SUTAgentAndroid.R;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ASMozStub extends android.app.Service {
|
||||
|
||||
private ServerSocket cmdChnl = null;
|
||||
private ServerSocket dataChnl = null;
|
||||
private Handler handler = new Handler();
|
||||
RunCmdThread runCmdThrd = null;
|
||||
RunDataThread runDataThrd = null;
|
||||
Thread monitor = null;
|
||||
Timer timer = null;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final Class[] mStartForegroundSignature = new Class[] {
|
||||
int.class, Notification.class};
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final Class[] mStopForegroundSignature = new Class[] {
|
||||
boolean.class};
|
||||
|
||||
private NotificationManager mNM;
|
||||
private Method mStartForeground;
|
||||
private Method mStopForeground;
|
||||
private Object[] mStartForegroundArgs = new Object[2];
|
||||
private Object[] mStopForegroundArgs = new Object[1];
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
try {
|
||||
mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature);
|
||||
mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature);
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
// Running on an older platform.
|
||||
mStartForeground = mStopForeground = null;
|
||||
}
|
||||
|
||||
doToast("Listener Service created...");
|
||||
}
|
||||
|
||||
public void onStart(Intent intent, int startId) {
|
||||
super.onStart(intent, startId);
|
||||
|
||||
try {
|
||||
cmdChnl = new ServerSocket(20701);
|
||||
runCmdThrd = new RunCmdThread(cmdChnl, this, handler);
|
||||
runCmdThrd.start();
|
||||
doToast("Command channel port 20701 ...");
|
||||
|
||||
dataChnl = new ServerSocket(20700);
|
||||
runDataThrd = new RunDataThread(dataChnl, this);
|
||||
runDataThrd.start();
|
||||
doToast("Data channel port 20700 ...");
|
||||
|
||||
Notification notification = new Notification();
|
||||
startForegroundCompat(R.string.foreground_service_started, notification);
|
||||
}
|
||||
catch (Exception e) {
|
||||
doToast(e.toString());
|
||||
// Toast.makeText(getApplication().getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
|
||||
if (runCmdThrd.isAlive())
|
||||
{
|
||||
runCmdThrd.StopListening();
|
||||
}
|
||||
|
||||
if (runDataThrd.isAlive())
|
||||
{
|
||||
runDataThrd.StopListening();
|
||||
}
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(1959);
|
||||
|
||||
stopForegroundCompat(R.string.foreground_service_started);
|
||||
|
||||
doToast("Listener Service destroyed...");
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void SendToDataChannel(String strToSend)
|
||||
{
|
||||
if (runDataThrd.isAlive())
|
||||
runDataThrd.SendToDataChannel(strToSend);
|
||||
}
|
||||
|
||||
public void doToast(String sMsg) {
|
||||
Toast toast = Toast.makeText(this, sMsg, Toast.LENGTH_LONG);
|
||||
toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 100);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a wrapper around the new startForeground method, using the older
|
||||
* APIs if it is not available.
|
||||
*/
|
||||
void startForegroundCompat(int id, Notification notification) {
|
||||
// If we have the new startForeground API, then use it.
|
||||
if (mStartForeground != null) {
|
||||
mStartForegroundArgs[0] = Integer.valueOf(id);
|
||||
mStartForegroundArgs[1] = notification;
|
||||
try {
|
||||
mStartForeground.invoke(this, mStartForegroundArgs);
|
||||
} catch (InvocationTargetException e) {
|
||||
// Should not happen.
|
||||
Log.w("ScreenOnWidget", "Unable to invoke startForeground", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
// Should not happen.
|
||||
Log.w("ScreenOnWidget", "Unable to invoke startForeground", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back on the old API.
|
||||
setForeground(true);
|
||||
mNM.notify(id, notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a wrapper around the new stopForeground method, using the older
|
||||
* APIs if it is not available.
|
||||
*/
|
||||
void stopForegroundCompat(int id) {
|
||||
// If we have the new stopForeground API, then use it.
|
||||
if (mStopForeground != null) {
|
||||
mStopForegroundArgs[0] = Boolean.TRUE;
|
||||
try {
|
||||
mStopForeground.invoke(this, mStopForegroundArgs);
|
||||
} catch (InvocationTargetException e) {
|
||||
// Should not happen.
|
||||
Log.w("ScreenOnWidget", "Unable to invoke stopForeground", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
// Should not happen.
|
||||
Log.w("ScreenOnWidget", "Unable to invoke stopForeground", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back on the old API. Note to cancel BEFORE changing the
|
||||
// foreground state, since we could be killed at that point.
|
||||
mNM.cancel(id);
|
||||
setForeground(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,96 +1,96 @@
|
|||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.util.Timer;
|
||||
|
||||
import android.content.ContextWrapper;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
class AlertLooperThread extends Thread
|
||||
{
|
||||
public Handler mHandler;
|
||||
private Looper looper = null;
|
||||
private DoAlert da = null;
|
||||
private Timer alertTimer = null;
|
||||
private ContextWrapper contextWrapper = null;
|
||||
|
||||
AlertLooperThread(ContextWrapper ctxW)
|
||||
{
|
||||
this.contextWrapper = ctxW;
|
||||
}
|
||||
|
||||
public Timer getAlertTimer()
|
||||
{
|
||||
return alertTimer;
|
||||
}
|
||||
|
||||
public void term()
|
||||
{
|
||||
if (da != null)
|
||||
da.term();
|
||||
}
|
||||
|
||||
public void quit()
|
||||
{
|
||||
if (looper != null)
|
||||
looper.quit();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
Looper.prepare();
|
||||
|
||||
looper = Looper.myLooper();
|
||||
|
||||
mHandler = new Handler()
|
||||
{
|
||||
public void handleMessage(Message msg)
|
||||
{
|
||||
// process incoming messages here
|
||||
}
|
||||
};
|
||||
|
||||
alertTimer = new Timer();
|
||||
da = new DoAlert(contextWrapper);
|
||||
alertTimer.scheduleAtFixedRate(da, 0, 5000);
|
||||
Looper.loop();
|
||||
}
|
||||
}
|
||||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.util.Timer;
|
||||
|
||||
import android.content.ContextWrapper;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
|
||||
class AlertLooperThread extends Thread
|
||||
{
|
||||
public Handler mHandler;
|
||||
private Looper looper = null;
|
||||
private DoAlert da = null;
|
||||
private Timer alertTimer = null;
|
||||
private ContextWrapper contextWrapper = null;
|
||||
|
||||
AlertLooperThread(ContextWrapper ctxW)
|
||||
{
|
||||
this.contextWrapper = ctxW;
|
||||
}
|
||||
|
||||
public Timer getAlertTimer()
|
||||
{
|
||||
return alertTimer;
|
||||
}
|
||||
|
||||
public void term()
|
||||
{
|
||||
if (da != null)
|
||||
da.term();
|
||||
}
|
||||
|
||||
public void quit()
|
||||
{
|
||||
if (looper != null)
|
||||
looper.quit();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
Looper.prepare();
|
||||
|
||||
looper = Looper.myLooper();
|
||||
|
||||
mHandler = new Handler()
|
||||
{
|
||||
public void handleMessage(Message msg)
|
||||
{
|
||||
// process incoming messages here
|
||||
}
|
||||
};
|
||||
|
||||
alertTimer = new Timer();
|
||||
da = new DoAlert(contextWrapper);
|
||||
alertTimer.scheduleAtFixedRate(da, 0, 5000);
|
||||
Looper.loop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mozilla.SUTAgentAndroid"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" android:sharedUserId="org.mozilla.sharedID">
|
||||
android:versionCode="1" android:versionName="1.01">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
|
||||
<activity android:name=".SUTAgentAndroid"
|
||||
android:screenOrientation="nosensor"
|
||||
|
@ -23,8 +22,7 @@
|
|||
<action android:name="com.mozilla.SUTAgentAndroid.service.LISTENER_SERVICE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
</application>
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="8"/>
|
||||
|
||||
|
@ -43,29 +41,17 @@
|
|||
<uses-permission android:name="android.permission.DEVICE_POWER"></uses-permission>
|
||||
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_SETTINGS"></uses-permission>
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.INSTALL_PACKAGES"></uses-permission>
|
||||
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.STATUS_BAR"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.SET_TIME"></uses-permission>
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.SET_TIME_ZONE"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"></uses-permission>
|
||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"></uses-permission>
|
||||
|
||||
</manifest>
|
|
@ -1,199 +1,199 @@
|
|||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
// import com.mozilla.SUTAgentAndroid.DoCommand;
|
||||
|
||||
public class CmdWorkerThread extends Thread
|
||||
{
|
||||
private RunCmdThread theParent = null;
|
||||
private Socket socket = null;
|
||||
private String prompt = null;
|
||||
boolean bListening = true;
|
||||
|
||||
public CmdWorkerThread(RunCmdThread theParent, Socket workerSocket)
|
||||
{
|
||||
super("CmdWorkerThread");
|
||||
this.theParent = theParent;
|
||||
this.socket = workerSocket;
|
||||
byte pr [] = new byte [3];
|
||||
pr[0] = '$';
|
||||
pr[1] = '>';
|
||||
pr[2] = 0;
|
||||
prompt = new String(pr,0,3);
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
|
||||
private String readLine(BufferedInputStream in)
|
||||
{
|
||||
String sRet = "";
|
||||
int nByte = 0;
|
||||
char cChar = 0;
|
||||
|
||||
try
|
||||
{
|
||||
nByte = in.read();
|
||||
while (nByte != -1)
|
||||
{
|
||||
cChar = ((char)(nByte & 0xFF));
|
||||
if ((cChar != '\r') && (cChar != '\n'))
|
||||
sRet += cChar;
|
||||
else
|
||||
break;
|
||||
nByte = in.read();
|
||||
}
|
||||
|
||||
if ((in.available() > 0) && (cChar != '\n'))
|
||||
{
|
||||
in.mark(1024);
|
||||
nByte = in.read();
|
||||
|
||||
if (nByte != -1)
|
||||
{
|
||||
cChar = ((char)(nByte & 0xFF));
|
||||
if (cChar != '\n')
|
||||
{
|
||||
in.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (sRet.length() == 0)
|
||||
sRet = null;
|
||||
|
||||
return(sRet);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
OutputStream cmdOut = socket.getOutputStream();
|
||||
InputStream cmdIn = socket.getInputStream();
|
||||
PrintWriter out = new PrintWriter(cmdOut, true);
|
||||
BufferedInputStream in = new BufferedInputStream(cmdIn);
|
||||
String inputLine, outputLine;
|
||||
DoCommand dc = new DoCommand(theParent.svc);
|
||||
|
||||
int nAvail = cmdIn.available();
|
||||
cmdIn.skip(nAvail);
|
||||
|
||||
out.print(prompt);
|
||||
out.flush();
|
||||
|
||||
while (bListening)
|
||||
{
|
||||
if (!(in.available() > 0))
|
||||
{
|
||||
socket.setSoTimeout(500);
|
||||
try {
|
||||
int nRead = cmdIn.read();
|
||||
if (nRead == -1)
|
||||
{
|
||||
bListening = false;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputLine = ((char)nRead) + "";
|
||||
socket.setSoTimeout(120000);
|
||||
}
|
||||
}
|
||||
catch(SocketTimeoutException toe)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
inputLine = "";
|
||||
|
||||
if ((inputLine += readLine(in)) != null)
|
||||
{
|
||||
outputLine = dc.processCommand(inputLine, out, in, cmdOut);
|
||||
if (outputLine.length() > 0)
|
||||
{
|
||||
out.print(outputLine + "\n" + prompt);
|
||||
}
|
||||
else
|
||||
out.print(prompt);
|
||||
out.flush();
|
||||
if (outputLine.equals("exit"))
|
||||
{
|
||||
theParent.StopListening();
|
||||
bListening = false;
|
||||
}
|
||||
if (outputLine.equals("quit"))
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
outputLine = null;
|
||||
System.gc();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
out.close();
|
||||
out = null;
|
||||
in.close();
|
||||
in = null;
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.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 com.mozilla.SUTAgentAndroid.service;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
|
||||
// import com.mozilla.SUTAgentAndroid.DoCommand;
|
||||
|
||||
public class CmdWorkerThread extends Thread
|
||||
{
|
||||
private RunCmdThread theParent = null;
|
||||
private Socket socket = null;
|
||||
private String prompt = null;
|
||||
boolean bListening = true;
|
||||
|
||||
public CmdWorkerThread(RunCmdThread theParent, Socket workerSocket)
|
||||
{
|
||||
super("CmdWorkerThread");
|
||||
this.theParent = theParent;
|
||||
this.socket = workerSocket;
|
||||
byte pr [] = new byte [3];
|
||||
pr[0] = '$';
|
||||
pr[1] = '>';
|
||||
pr[2] = 0;
|
||||
prompt = new String(pr,0,3);
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
|
||||
private String readLine(BufferedInputStream in)
|
||||
{
|
||||
String sRet = "";
|
||||
int nByte = 0;
|
||||
char cChar = 0;
|
||||
|
||||
try
|
||||
{
|
||||
nByte = in.read();
|
||||
while (nByte != -1)
|
||||
{
|
||||
cChar = ((char)(nByte & 0xFF));
|
||||
if ((cChar != '\r') && (cChar != '\n'))
|
||||
sRet += cChar;
|
||||
else
|
||||
break;
|
||||
nByte = in.read();
|
||||
}
|
||||
|
||||
if ((in.available() > 0) && (cChar != '\n'))
|
||||
{
|
||||
in.mark(1024);
|
||||
nByte = in.read();
|
||||
|
||||
if (nByte != -1)
|
||||
{
|
||||
cChar = ((char)(nByte & 0xFF));
|
||||
if (cChar != '\n')
|
||||
{
|
||||
in.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (sRet.length() == 0)
|
||||
sRet = null;
|
||||
|
||||
return(sRet);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
OutputStream cmdOut = socket.getOutputStream();
|
||||
InputStream cmdIn = socket.getInputStream();
|
||||
PrintWriter out = new PrintWriter(cmdOut, true);
|
||||
BufferedInputStream in = new BufferedInputStream(cmdIn);
|
||||
String inputLine, outputLine;
|
||||
DoCommand dc = new DoCommand(theParent.svc);
|
||||
|
||||
int nAvail = cmdIn.available();
|
||||
cmdIn.skip(nAvail);
|
||||
|
||||
out.print(prompt);
|
||||
out.flush();
|
||||
|
||||
while (bListening)
|
||||
{
|
||||
if (!(in.available() > 0))
|
||||
{
|
||||
socket.setSoTimeout(500);
|
||||
try {
|
||||
int nRead = cmdIn.read();
|
||||
if (nRead == -1)
|
||||
{
|
||||
bListening = false;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputLine = ((char)nRead) + "";
|
||||
socket.setSoTimeout(120000);
|
||||
}
|
||||
}
|
||||
catch(SocketTimeoutException toe)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
inputLine = "";
|
||||
|
||||
if ((inputLine += readLine(in)) != null)
|
||||
{
|
||||
outputLine = dc.processCommand(inputLine, out, in, cmdOut);
|
||||
if (outputLine.length() > 0)
|
||||
{
|
||||
out.print(outputLine + "\n" + prompt);
|
||||
}
|
||||
else
|
||||
out.print(prompt);
|
||||
out.flush();
|
||||
if (outputLine.equals("exit"))
|
||||
{
|
||||
theParent.StopListening();
|
||||
bListening = false;
|
||||
}
|
||||
if (outputLine.equals("quit"))
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
outputLine = null;
|
||||
System.gc();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
out.close();
|
||||
out = null;
|
||||
in.close();
|
||||
in = null;
|
||||
socket.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,237 +1,237 @@
|
|||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
// import com.mozilla.SUTAgentAndroid.DoCommand;
|
||||
import com.mozilla.SUTAgentAndroid.SUTAgentAndroid;
|
||||
|
||||
public class DataWorkerThread extends Thread
|
||||
{
|
||||
private RunDataThread theParent = null;
|
||||
private Socket socket = null;
|
||||
boolean bListening = true;
|
||||
PrintWriter out = null;
|
||||
SimpleDateFormat sdf = null;
|
||||
|
||||
public DataWorkerThread(RunDataThread theParent, Socket workerSocket)
|
||||
{
|
||||
super("DataWorkerThread");
|
||||
this.theParent = theParent;
|
||||
this.socket = workerSocket;
|
||||
this.sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss");
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
|
||||
public void SendString(String strToSend)
|
||||
{
|
||||
if (this.out != null)
|
||||
{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String strOut = sdf.format(cal.getTime());
|
||||
strOut += " " + strToSend + "\r\n";
|
||||
|
||||
out.write(strOut);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
private String readLine(BufferedInputStream in)
|
||||
{
|
||||
String sRet = "";
|
||||
int nByte = 0;
|
||||
char cChar = 0;
|
||||
|
||||
try
|
||||
{
|
||||
nByte = in.read();
|
||||
while (nByte != -1)
|
||||
{
|
||||
cChar = ((char)(nByte & 0xFF));
|
||||
if ((cChar != '\r') && (cChar != '\n'))
|
||||
sRet += cChar;
|
||||
else
|
||||
break;
|
||||
nByte = in.read();
|
||||
}
|
||||
|
||||
if (in.available() > 0)
|
||||
{
|
||||
in.mark(1024);
|
||||
nByte = in.read();
|
||||
|
||||
while (nByte != -1)
|
||||
{
|
||||
cChar = ((char)(nByte & 0xFF));
|
||||
if ((cChar == '\r') || (cChar == '\n'))
|
||||
{
|
||||
if (in.available() > 0)
|
||||
{
|
||||
in.mark(1024);
|
||||
nByte = in.read();
|
||||
}
|
||||
else
|
||||
nByte = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
in.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (sRet.length() == 0)
|
||||
sRet = null;
|
||||
|
||||
return(sRet);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
String sRet = "";
|
||||
long lEndTime = System.currentTimeMillis() + 60000;
|
||||
|
||||
try {
|
||||
while(bListening)
|
||||
{
|
||||
OutputStream cmdOut = socket.getOutputStream();
|
||||
InputStream cmdIn = socket.getInputStream();
|
||||
this.out = new PrintWriter(cmdOut, true);
|
||||
BufferedInputStream in = new BufferedInputStream(cmdIn);
|
||||
String inputLine, outputLine;
|
||||
DoCommand dc = new DoCommand(theParent.svc);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
sRet = sdf.format(cal.getTime());
|
||||
sRet += " trace output";
|
||||
|
||||
out.println(sRet);
|
||||
out.flush();
|
||||
int nAvail = cmdIn.available();
|
||||
cmdIn.skip(nAvail);
|
||||
|
||||
while (bListening)
|
||||
{
|
||||
if (System.currentTimeMillis() > lEndTime)
|
||||
{
|
||||
cal = Calendar.getInstance();
|
||||
sRet = sdf.format(cal.getTime());
|
||||
sRet += " Thump thump - " + SUTAgentAndroid.sUniqueID + "\r\n";
|
||||
|
||||
out.write(sRet);
|
||||
out.flush();
|
||||
|
||||
lEndTime = System.currentTimeMillis() + 60000;
|
||||
}
|
||||
|
||||
if (!(in.available() > 0))
|
||||
{
|
||||
socket.setSoTimeout(500);
|
||||
try {
|
||||
int nRead = cmdIn.read();
|
||||
if (nRead == -1)
|
||||
{
|
||||
bListening = false;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
inputLine = (char)nRead + "";
|
||||
}
|
||||
catch(SocketTimeoutException toe)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
inputLine = "";
|
||||
|
||||
if ((inputLine += readLine(in)) != null)
|
||||
{
|
||||
outputLine = dc.processCommand(inputLine, out, in, cmdOut);
|
||||
out.print(outputLine + "\n");
|
||||
out.flush();
|
||||
if (outputLine.equals("exit"))
|
||||
{
|
||||
theParent.StopListening();
|
||||
bListening = false;
|
||||
}
|
||||
if (outputLine.equals("quit"))
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
outputLine = null;
|
||||
System.gc();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
out.close();
|
||||
out = null;
|
||||
in.close();
|
||||
in = null;
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.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 com.mozilla.SUTAgentAndroid.service;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
// import com.mozilla.SUTAgentAndroid.DoCommand;
|
||||
import com.mozilla.SUTAgentAndroid.SUTAgentAndroid;
|
||||
|
||||
public class DataWorkerThread extends Thread
|
||||
{
|
||||
private RunDataThread theParent = null;
|
||||
private Socket socket = null;
|
||||
boolean bListening = true;
|
||||
PrintWriter out = null;
|
||||
SimpleDateFormat sdf = null;
|
||||
|
||||
public DataWorkerThread(RunDataThread theParent, Socket workerSocket)
|
||||
{
|
||||
super("DataWorkerThread");
|
||||
this.theParent = theParent;
|
||||
this.socket = workerSocket;
|
||||
this.sdf = new SimpleDateFormat("yyyyMMdd-HH:mm:ss");
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
|
||||
public void SendString(String strToSend)
|
||||
{
|
||||
if (this.out != null)
|
||||
{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String strOut = sdf.format(cal.getTime());
|
||||
strOut += " " + strToSend + "\r\n";
|
||||
|
||||
out.write(strOut);
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
private String readLine(BufferedInputStream in)
|
||||
{
|
||||
String sRet = "";
|
||||
int nByte = 0;
|
||||
char cChar = 0;
|
||||
|
||||
try
|
||||
{
|
||||
nByte = in.read();
|
||||
while (nByte != -1)
|
||||
{
|
||||
cChar = ((char)(nByte & 0xFF));
|
||||
if ((cChar != '\r') && (cChar != '\n'))
|
||||
sRet += cChar;
|
||||
else
|
||||
break;
|
||||
nByte = in.read();
|
||||
}
|
||||
|
||||
if (in.available() > 0)
|
||||
{
|
||||
in.mark(1024);
|
||||
nByte = in.read();
|
||||
|
||||
while (nByte != -1)
|
||||
{
|
||||
cChar = ((char)(nByte & 0xFF));
|
||||
if ((cChar == '\r') || (cChar == '\n'))
|
||||
{
|
||||
if (in.available() > 0)
|
||||
{
|
||||
in.mark(1024);
|
||||
nByte = in.read();
|
||||
}
|
||||
else
|
||||
nByte = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
in.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (sRet.length() == 0)
|
||||
sRet = null;
|
||||
|
||||
return(sRet);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
String sRet = "";
|
||||
long lEndTime = System.currentTimeMillis() + 60000;
|
||||
|
||||
try {
|
||||
while(bListening)
|
||||
{
|
||||
OutputStream cmdOut = socket.getOutputStream();
|
||||
InputStream cmdIn = socket.getInputStream();
|
||||
this.out = new PrintWriter(cmdOut, true);
|
||||
BufferedInputStream in = new BufferedInputStream(cmdIn);
|
||||
String inputLine, outputLine;
|
||||
DoCommand dc = new DoCommand(theParent.svc);
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
sRet = sdf.format(cal.getTime());
|
||||
sRet += " trace output";
|
||||
|
||||
out.println(sRet);
|
||||
out.flush();
|
||||
int nAvail = cmdIn.available();
|
||||
cmdIn.skip(nAvail);
|
||||
|
||||
while (bListening)
|
||||
{
|
||||
if (System.currentTimeMillis() > lEndTime)
|
||||
{
|
||||
cal = Calendar.getInstance();
|
||||
sRet = sdf.format(cal.getTime());
|
||||
sRet += " Thump thump - " + SUTAgentAndroid.sUniqueID + "\r\n";
|
||||
|
||||
out.write(sRet);
|
||||
out.flush();
|
||||
|
||||
lEndTime = System.currentTimeMillis() + 60000;
|
||||
}
|
||||
|
||||
if (!(in.available() > 0))
|
||||
{
|
||||
socket.setSoTimeout(500);
|
||||
try {
|
||||
int nRead = cmdIn.read();
|
||||
if (nRead == -1)
|
||||
{
|
||||
bListening = false;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
inputLine = (char)nRead + "";
|
||||
}
|
||||
catch(SocketTimeoutException toe)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
inputLine = "";
|
||||
|
||||
if ((inputLine += readLine(in)) != null)
|
||||
{
|
||||
outputLine = dc.processCommand(inputLine, out, in, cmdOut);
|
||||
out.print(outputLine + "\n");
|
||||
out.flush();
|
||||
if (outputLine.equals("exit"))
|
||||
{
|
||||
theParent.StopListening();
|
||||
bListening = false;
|
||||
}
|
||||
if (outputLine.equals("quit"))
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
outputLine = null;
|
||||
System.gc();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
out.close();
|
||||
out = null;
|
||||
in.close();
|
||||
in = null;
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,81 +1,81 @@
|
|||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
class DoAlert extends TimerTask
|
||||
{
|
||||
int lcv = 0;
|
||||
Toast toast = null;
|
||||
Ringtone rt = null;
|
||||
|
||||
DoAlert(ContextWrapper contextWrapper)
|
||||
{
|
||||
Context ctx = contextWrapper.getApplicationContext();
|
||||
this.toast = Toast.makeText(ctx, "Help me!", Toast.LENGTH_LONG);
|
||||
rt = RingtoneManager.getRingtone(ctx, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
|
||||
}
|
||||
|
||||
public void term()
|
||||
{
|
||||
if (rt != null)
|
||||
{
|
||||
if (rt.isPlaying())
|
||||
rt.stop();
|
||||
}
|
||||
|
||||
if (toast != null)
|
||||
toast.cancel();
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
String sText =(((lcv++ % 2) == 0) ? "Help me!" : "I've fallen down!" );
|
||||
toast.setText(sText);
|
||||
toast.show();
|
||||
if (rt != null)
|
||||
rt.play();
|
||||
}
|
||||
}
|
||||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
class DoAlert extends TimerTask
|
||||
{
|
||||
int lcv = 0;
|
||||
Toast toast = null;
|
||||
Ringtone rt = null;
|
||||
|
||||
DoAlert(ContextWrapper contextWrapper)
|
||||
{
|
||||
Context ctx = contextWrapper.getApplicationContext();
|
||||
this.toast = Toast.makeText(ctx, "Help me!", Toast.LENGTH_LONG);
|
||||
rt = RingtoneManager.getRingtone(ctx, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));
|
||||
}
|
||||
|
||||
public void term()
|
||||
{
|
||||
if (rt != null)
|
||||
{
|
||||
if (rt.isPlaying())
|
||||
rt.stop();
|
||||
}
|
||||
|
||||
if (toast != null)
|
||||
toast.cancel();
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
String sText =(((lcv++ % 2) == 0) ? "Help me!" : "I've fallen down!" );
|
||||
toast.setText(sText);
|
||||
toast.show();
|
||||
if (rt != null)
|
||||
rt.play();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ JAVAFILES = \
|
|||
DataWorkerThread.java \
|
||||
DoAlert.java \
|
||||
DoCommand.java \
|
||||
NtpMessage.java \
|
||||
Power.java \
|
||||
RedirOutputThread.java \
|
||||
RunCmdThread.java \
|
||||
|
|
|
@ -0,0 +1,468 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* This class represents a NTP message, as specified in RFC 2030. The message
|
||||
* format is compatible with all versions of NTP and SNTP.
|
||||
*
|
||||
* This class does not support the optional authentication protocol, and
|
||||
* ignores the key ID and message digest fields.
|
||||
*
|
||||
* For convenience, this class exposes message values as native Java types, not
|
||||
* the NTP-specified data formats. For example, timestamps are
|
||||
* stored as doubles (as opposed to the NTP unsigned 64-bit fixed point
|
||||
* format).
|
||||
*
|
||||
* However, the contructor NtpMessage(byte[]) and the method toByteArray()
|
||||
* allow the import and export of the raw NTP message format.
|
||||
*
|
||||
*
|
||||
* Usage example
|
||||
*
|
||||
* // Send message
|
||||
* DatagramSocket socket = new DatagramSocket();
|
||||
* InetAddress address = InetAddress.getByName("ntp.cais.rnp.br");
|
||||
* byte[] buf = new NtpMessage().toByteArray();
|
||||
* DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 123);
|
||||
* socket.send(packet);
|
||||
*
|
||||
* // Get response
|
||||
* socket.receive(packet);
|
||||
* System.out.println(msg.toString());
|
||||
*
|
||||
*
|
||||
* This code is copyright (c) Adam Buckley 2004
|
||||
*
|
||||
* Contributor(s):
|
||||
* Bob Moss <bmoss@mozilla.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version. A HTML version of the GNU General Public License can be
|
||||
* seen at http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
*
|
||||
* Comments for member variables are taken from RFC2030 by David Mills,
|
||||
* University of Delaware.
|
||||
*
|
||||
* Number format conversion code in NtpMessage(byte[] array) and toByteArray()
|
||||
* inspired by http://www.pps.jussieu.fr/~jch/enseignement/reseaux/
|
||||
* NTPMessage.java which is copyright (c) 2003 by Juliusz Chroboczek
|
||||
*
|
||||
* @author Adam Buckley
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package com.mozilla.SUTAgentAndroid;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class NtpMessage
|
||||
{
|
||||
/**
|
||||
* This is a two-bit code warning of an impending leap second to be
|
||||
* inserted/deleted in the last minute of the current day. It's values
|
||||
* may be as follows:
|
||||
*
|
||||
* Value Meaning
|
||||
* ----- -------
|
||||
* 0 no warning
|
||||
* 1 last minute has 61 seconds
|
||||
* 2 last minute has 59 seconds)
|
||||
* 3 alarm condition (clock not synchronized)
|
||||
*/
|
||||
public byte leapIndicator = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This value indicates the NTP/SNTP version number. The version number
|
||||
* is 3 for Version 3 (IPv4 only) and 4 for Version 4 (IPv4, IPv6 and OSI).
|
||||
* If necessary to distinguish between IPv4, IPv6 and OSI, the
|
||||
* encapsulating context must be inspected.
|
||||
*/
|
||||
public byte version = 3;
|
||||
|
||||
|
||||
/**
|
||||
* This value indicates the mode, with values defined as follows:
|
||||
*
|
||||
* Mode Meaning
|
||||
* ---- -------
|
||||
* 0 reserved
|
||||
* 1 symmetric active
|
||||
* 2 symmetric passive
|
||||
* 3 client
|
||||
* 4 server
|
||||
* 5 broadcast
|
||||
* 6 reserved for NTP control message
|
||||
* 7 reserved for private use
|
||||
*
|
||||
* In unicast and anycast modes, the client sets this field to 3 (client)
|
||||
* in the request and the server sets it to 4 (server) in the reply. In
|
||||
* multicast mode, the server sets this field to 5 (broadcast).
|
||||
*/
|
||||
public byte mode = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This value indicates the stratum level of the local clock, with values
|
||||
* defined as follows:
|
||||
*
|
||||
* Stratum Meaning
|
||||
* ----------------------------------------------
|
||||
* 0 unspecified or unavailable
|
||||
* 1 primary reference (e.g., radio clock)
|
||||
* 2-15 secondary reference (via NTP or SNTP)
|
||||
* 16-255 reserved
|
||||
*/
|
||||
public short stratum = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This value indicates the maximum interval between successive messages,
|
||||
* in seconds to the nearest power of two. The values that can appear in
|
||||
* this field presently range from 4 (16 s) to 14 (16284 s); however, most
|
||||
* applications use only the sub-range 6 (64 s) to 10 (1024 s).
|
||||
*/
|
||||
public byte pollInterval = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This value indicates the precision of the local clock, in seconds to
|
||||
* the nearest power of two. The values that normally appear in this field
|
||||
* range from -6 for mains-frequency clocks to -20 for microsecond clocks
|
||||
* found in some workstations.
|
||||
*/
|
||||
public byte precision = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This value indicates the total roundtrip delay to the primary reference
|
||||
* source, in seconds. Note that this variable can take on both positive
|
||||
* and negative values, depending on the relative time and frequency
|
||||
* offsets. The values that normally appear in this field range from
|
||||
* negative values of a few milliseconds to positive values of several
|
||||
* hundred milliseconds.
|
||||
*/
|
||||
public double rootDelay = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This value indicates the nominal error relative to the primary reference
|
||||
* source, in seconds. The values that normally appear in this field
|
||||
* range from 0 to several hundred milliseconds.
|
||||
*/
|
||||
public double rootDispersion = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This is a 4-byte array identifying the particular reference source.
|
||||
* In the case of NTP Version 3 or Version 4 stratum-0 (unspecified) or
|
||||
* stratum-1 (primary) servers, this is a four-character ASCII string, left
|
||||
* justified and zero padded to 32 bits. In NTP Version 3 secondary
|
||||
* servers, this is the 32-bit IPv4 address of the reference source. In NTP
|
||||
* Version 4 secondary servers, this is the low order 32 bits of the latest
|
||||
* transmit timestamp of the reference source. NTP primary (stratum 1)
|
||||
* servers should set this field to a code identifying the external
|
||||
* reference source according to the following list. If the external
|
||||
* reference is one of those listed, the associated code should be used.
|
||||
* Codes for sources not listed can be contrived as appropriate.
|
||||
*
|
||||
* Code External Reference Source
|
||||
* ---- -------------------------
|
||||
* LOCL uncalibrated local clock used as a primary reference for
|
||||
* a subnet without external means of synchronization
|
||||
* PPS atomic clock or other pulse-per-second source
|
||||
* individually calibrated to national standards
|
||||
* ACTS NIST dialup modem service
|
||||
* USNO USNO modem service
|
||||
* PTB PTB (Germany) modem service
|
||||
* TDF Allouis (France) Radio 164 kHz
|
||||
* DCF Mainflingen (Germany) Radio 77.5 kHz
|
||||
* MSF Rugby (UK) Radio 60 kHz
|
||||
* WWV Ft. Collins (US) Radio 2.5, 5, 10, 15, 20 MHz
|
||||
* WWVB Boulder (US) Radio 60 kHz
|
||||
* WWVH Kaui Hawaii (US) Radio 2.5, 5, 10, 15 MHz
|
||||
* CHU Ottawa (Canada) Radio 3330, 7335, 14670 kHz
|
||||
* LORC LORAN-C radionavigation system
|
||||
* OMEG OMEGA radionavigation system
|
||||
* GPS Global Positioning Service
|
||||
* GOES Geostationary Orbit Environment Satellite
|
||||
*/
|
||||
public byte[] referenceIdentifier = {0, 0, 0, 0};
|
||||
|
||||
|
||||
/**
|
||||
* This is the time at which the local clock was last set or corrected, in
|
||||
* seconds since 00:00 1-Jan-1900.
|
||||
*/
|
||||
public double referenceTimestamp = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This is the time at which the request departed the client for the
|
||||
* server, in seconds since 00:00 1-Jan-1900.
|
||||
*/
|
||||
public double originateTimestamp = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This is the time at which the request arrived at the server, in seconds
|
||||
* since 00:00 1-Jan-1900.
|
||||
*/
|
||||
public double receiveTimestamp = 0;
|
||||
|
||||
|
||||
/**
|
||||
* This is the time at which the reply departed the server for the client,
|
||||
* in seconds since 00:00 1-Jan-1900.
|
||||
*/
|
||||
public double transmitTimestamp = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new NtpMessage from an array of bytes.
|
||||
*/
|
||||
public NtpMessage(byte[] array)
|
||||
{
|
||||
// See the packet format diagram in RFC 2030 for details
|
||||
leapIndicator = (byte) ((array[0] >> 6) & 0x3);
|
||||
version = (byte) ((array[0] >> 3) & 0x7);
|
||||
mode = (byte) (array[0] & 0x7);
|
||||
stratum = unsignedByteToShort(array[1]);
|
||||
pollInterval = array[2];
|
||||
precision = array[3];
|
||||
|
||||
rootDelay = (array[4] * 256.0) +
|
||||
unsignedByteToShort(array[5]) +
|
||||
(unsignedByteToShort(array[6]) / 256.0) +
|
||||
(unsignedByteToShort(array[7]) / 65536.0);
|
||||
|
||||
rootDispersion = (unsignedByteToShort(array[8]) * 256.0) +
|
||||
unsignedByteToShort(array[9]) +
|
||||
(unsignedByteToShort(array[10]) / 256.0) +
|
||||
(unsignedByteToShort(array[11]) / 65536.0);
|
||||
|
||||
referenceIdentifier[0] = array[12];
|
||||
referenceIdentifier[1] = array[13];
|
||||
referenceIdentifier[2] = array[14];
|
||||
referenceIdentifier[3] = array[15];
|
||||
|
||||
referenceTimestamp = decodeTimestamp(array, 16);
|
||||
originateTimestamp = decodeTimestamp(array, 24);
|
||||
receiveTimestamp = decodeTimestamp(array, 32);
|
||||
transmitTimestamp = decodeTimestamp(array, 40);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new NtpMessage in client -> server mode, and sets the
|
||||
* transmit timestamp to the current time.
|
||||
*/
|
||||
public NtpMessage()
|
||||
{
|
||||
// Note that all the other member variables are already set with
|
||||
// appropriate default values.
|
||||
this.mode = 3;
|
||||
this.transmitTimestamp = (System.currentTimeMillis()/1000.0) + 2208988800.0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This method constructs the data bytes of a raw NTP packet.
|
||||
*/
|
||||
public byte[] toByteArray()
|
||||
{
|
||||
// All bytes are automatically set to 0
|
||||
byte[] p = new byte[48];
|
||||
|
||||
p[0] = (byte) (leapIndicator << 6 | version << 3 | mode);
|
||||
p[1] = (byte) stratum;
|
||||
p[2] = (byte) pollInterval;
|
||||
p[3] = (byte) precision;
|
||||
|
||||
// root delay is a signed 16.16-bit FP, in Java an int is 32-bits
|
||||
int l = (int) (rootDelay * 65536.0);
|
||||
p[4] = (byte) ((l >> 24) & 0xFF);
|
||||
p[5] = (byte) ((l >> 16) & 0xFF);
|
||||
p[6] = (byte) ((l >> 8) & 0xFF);
|
||||
p[7] = (byte) (l & 0xFF);
|
||||
|
||||
// root dispersion is an unsigned 16.16-bit FP, in Java there are no
|
||||
// unsigned primitive types, so we use a long which is 64-bits
|
||||
long ul = (long) (rootDispersion * 65536.0);
|
||||
p[8] = (byte) ((ul >> 24) & 0xFF);
|
||||
p[9] = (byte) ((ul >> 16) & 0xFF);
|
||||
p[10] = (byte) ((ul >> 8) & 0xFF);
|
||||
p[11] = (byte) (ul & 0xFF);
|
||||
|
||||
p[12] = referenceIdentifier[0];
|
||||
p[13] = referenceIdentifier[1];
|
||||
p[14] = referenceIdentifier[2];
|
||||
p[15] = referenceIdentifier[3];
|
||||
|
||||
encodeTimestamp(p, 16, referenceTimestamp);
|
||||
encodeTimestamp(p, 24, originateTimestamp);
|
||||
encodeTimestamp(p, 32, receiveTimestamp);
|
||||
encodeTimestamp(p, 40, transmitTimestamp);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string representation of a NtpMessage
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
String precisionStr =
|
||||
new DecimalFormat("0.#E0").format(Math.pow(2, precision));
|
||||
|
||||
return "Leap indicator: " + leapIndicator + "\n" +
|
||||
"Version: " + version + "\n" +
|
||||
"Mode: " + mode + "\n" +
|
||||
"Stratum: " + stratum + "\n" +
|
||||
"Poll: " + pollInterval + "\n" +
|
||||
"Precision: " + precision + " (" + precisionStr + " seconds)\n" +
|
||||
"Root delay: " + new DecimalFormat("0.00").format(rootDelay*1000) + " ms\n" +
|
||||
"Root dispersion: " + new DecimalFormat("0.00").format(rootDispersion*1000) + " ms\n" +
|
||||
"Reference identifier: " + referenceIdentifierToString(referenceIdentifier, stratum, version) + "\n" +
|
||||
"Reference timestamp: " + timestampToString(referenceTimestamp) + "\n" +
|
||||
"Originate timestamp: " + timestampToString(originateTimestamp) + "\n" +
|
||||
"Receive timestamp: " + timestampToString(receiveTimestamp) + "\n" +
|
||||
"Transmit timestamp: " + timestampToString(transmitTimestamp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Converts an unsigned byte to a short. By default, Java assumes that
|
||||
* a byte is signed.
|
||||
*/
|
||||
public static short unsignedByteToShort(byte b)
|
||||
{
|
||||
if((b & 0x80)==0x80) return (short) (128 + (b & 0x7f));
|
||||
else return (short) b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Will read 8 bytes of a message beginning at <code>pointer</code>
|
||||
* and return it as a double, according to the NTP 64-bit timestamp
|
||||
* format.
|
||||
*/
|
||||
public static double decodeTimestamp(byte[] array, int pointer)
|
||||
{
|
||||
double r = 0.0;
|
||||
|
||||
for(int i=0; i<8; i++)
|
||||
{
|
||||
r += unsignedByteToShort(array[pointer+i]) * Math.pow(2, (3-i)*8);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Encodes a timestamp in the specified position in the message
|
||||
*/
|
||||
public static void encodeTimestamp(byte[] array, int pointer, double timestamp)
|
||||
{
|
||||
// Converts a double into a 64-bit fixed point
|
||||
for(int i=0; i<8; i++)
|
||||
{
|
||||
// 2^24, 2^16, 2^8, .. 2^-32
|
||||
double base = Math.pow(2, (3-i)*8);
|
||||
|
||||
// Capture byte value
|
||||
array[pointer+i] = (byte) (timestamp / base);
|
||||
|
||||
// Subtract captured value from remaining total
|
||||
timestamp = timestamp - (double) (unsignedByteToShort(array[pointer+i]) * base);
|
||||
}
|
||||
|
||||
// From RFC 2030: It is advisable to fill the non-significant
|
||||
// low order bits of the timestamp with a random, unbiased
|
||||
// bitstring, both to avoid systematic roundoff errors and as
|
||||
// a means of loop detection and replay detection.
|
||||
array[7] = (byte) (Math.random()*255.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a timestamp (number of seconds since 00:00 1-Jan-1900) as a
|
||||
* formatted date/time string.
|
||||
*/
|
||||
public static String timestampToString(double timestamp)
|
||||
{
|
||||
if(timestamp==0) return "0";
|
||||
|
||||
// timestamp is relative to 1900, utc is used by Java and is relative
|
||||
// to 1970
|
||||
double utc = timestamp - (2208988800.0);
|
||||
|
||||
// milliseconds
|
||||
long ms = (long) (utc * 1000.0);
|
||||
|
||||
// date/time
|
||||
String date = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").format(new Date(ms));
|
||||
|
||||
// fraction
|
||||
double fraction = timestamp - ((long) timestamp);
|
||||
String fractionSting = new DecimalFormat(".000000").format(fraction);
|
||||
|
||||
return date + fractionSting;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a string representation of a reference identifier according
|
||||
* to the rules set out in RFC 2030.
|
||||
*/
|
||||
public static String referenceIdentifierToString(byte[] ref, short stratum, byte version)
|
||||
{
|
||||
// From the RFC 2030:
|
||||
// In the case of NTP Version 3 or Version 4 stratum-0 (unspecified)
|
||||
// or stratum-1 (primary) servers, this is a four-character ASCII
|
||||
// string, left justified and zero padded to 32 bits.
|
||||
if(stratum==0 || stratum==1)
|
||||
{
|
||||
return new String(ref);
|
||||
}
|
||||
|
||||
// In NTP Version 3 secondary servers, this is the 32-bit IPv4
|
||||
// address of the reference source.
|
||||
else if(version==3)
|
||||
{
|
||||
return unsignedByteToShort(ref[0]) + "." +
|
||||
unsignedByteToShort(ref[1]) + "." +
|
||||
unsignedByteToShort(ref[2]) + "." +
|
||||
unsignedByteToShort(ref[3]);
|
||||
}
|
||||
|
||||
// In NTP Version 4 secondary servers, this is the low order 32 bits
|
||||
// of the latest transmit timestamp of the reference source.
|
||||
else if(version==4)
|
||||
{
|
||||
return "" + ((unsignedByteToShort(ref[0]) / 256.0) +
|
||||
(unsignedByteToShort(ref[1]) / 65536.0) +
|
||||
(unsignedByteToShort(ref[2]) / 16777216.0) +
|
||||
(unsignedByteToShort(ref[3]) / 4294967296.0));
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -1,102 +1,102 @@
|
|||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.os;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Class that provides access to some of the power management functions.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public class Power
|
||||
{
|
||||
// can't instantiate this class
|
||||
private Power()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Wake lock that ensures that the CPU is running. The screen might
|
||||
* not be on.
|
||||
*/
|
||||
public static final int PARTIAL_WAKE_LOCK = 1;
|
||||
|
||||
/**
|
||||
* Wake lock that ensures that the screen is on.
|
||||
*/
|
||||
public static final int FULL_WAKE_LOCK = 2;
|
||||
|
||||
public static native void acquireWakeLock(int lock, String id);
|
||||
public static native void releaseWakeLock(String id);
|
||||
|
||||
/**
|
||||
* Brightness value for fully off
|
||||
*/
|
||||
public static final int BRIGHTNESS_OFF = 0;
|
||||
|
||||
/**
|
||||
* Brightness value for dim backlight
|
||||
*/
|
||||
public static final int BRIGHTNESS_DIM = 20;
|
||||
|
||||
/**
|
||||
* Brightness value for fully on
|
||||
*/
|
||||
public static final int BRIGHTNESS_ON = 255;
|
||||
|
||||
/**
|
||||
* Brightness value to use when battery is low
|
||||
*/
|
||||
public static final int BRIGHTNESS_LOW_BATTERY = 10;
|
||||
|
||||
/**
|
||||
* Threshold for BRIGHTNESS_LOW_BATTERY (percentage)
|
||||
* Screen will stay dim if battery level is <= LOW_BATTERY_THRESHOLD
|
||||
*/
|
||||
public static final int LOW_BATTERY_THRESHOLD = 10;
|
||||
|
||||
/**
|
||||
* Turn the screen on or off
|
||||
*
|
||||
* @param on Whether you want the screen on or off
|
||||
*/
|
||||
public static native int setScreenState(boolean on);
|
||||
|
||||
public static native int setLastUserActivityTimeout(long ms);
|
||||
|
||||
/**
|
||||
* Turn the device off.
|
||||
*
|
||||
* This method is considered deprecated in favor of
|
||||
* {@link android.policy.ShutdownThread.shutdownAfterDisablingRadio()}.
|
||||
*
|
||||
* @deprecated
|
||||
* @hide
|
||||
*/
|
||||
@Deprecated
|
||||
public static native void shutdown();
|
||||
|
||||
/**
|
||||
* Reboot the device.
|
||||
* @param reason code to pass to the kernel (e.g. "recovery"), or null.
|
||||
*
|
||||
* @throws IOException if reboot fails for some reason (eg, lack of
|
||||
* permission)
|
||||
*/
|
||||
public static native void reboot(String reason) throws IOException;
|
||||
}
|
||||
/*
|
||||
* Copyright (C) 2007 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.os;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Class that provides access to some of the power management functions.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public class Power
|
||||
{
|
||||
// can't instantiate this class
|
||||
private Power()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Wake lock that ensures that the CPU is running. The screen might
|
||||
* not be on.
|
||||
*/
|
||||
public static final int PARTIAL_WAKE_LOCK = 1;
|
||||
|
||||
/**
|
||||
* Wake lock that ensures that the screen is on.
|
||||
*/
|
||||
public static final int FULL_WAKE_LOCK = 2;
|
||||
|
||||
public static native void acquireWakeLock(int lock, String id);
|
||||
public static native void releaseWakeLock(String id);
|
||||
|
||||
/**
|
||||
* Brightness value for fully off
|
||||
*/
|
||||
public static final int BRIGHTNESS_OFF = 0;
|
||||
|
||||
/**
|
||||
* Brightness value for dim backlight
|
||||
*/
|
||||
public static final int BRIGHTNESS_DIM = 20;
|
||||
|
||||
/**
|
||||
* Brightness value for fully on
|
||||
*/
|
||||
public static final int BRIGHTNESS_ON = 255;
|
||||
|
||||
/**
|
||||
* Brightness value to use when battery is low
|
||||
*/
|
||||
public static final int BRIGHTNESS_LOW_BATTERY = 10;
|
||||
|
||||
/**
|
||||
* Threshold for BRIGHTNESS_LOW_BATTERY (percentage)
|
||||
* Screen will stay dim if battery level is <= LOW_BATTERY_THRESHOLD
|
||||
*/
|
||||
public static final int LOW_BATTERY_THRESHOLD = 10;
|
||||
|
||||
/**
|
||||
* Turn the screen on or off
|
||||
*
|
||||
* @param on Whether you want the screen on or off
|
||||
*/
|
||||
public static native int setScreenState(boolean on);
|
||||
|
||||
public static native int setLastUserActivityTimeout(long ms);
|
||||
|
||||
/**
|
||||
* Turn the device off.
|
||||
*
|
||||
* This method is considered deprecated in favor of
|
||||
* {@link android.policy.ShutdownThread.shutdownAfterDisablingRadio()}.
|
||||
*
|
||||
* @deprecated
|
||||
* @hide
|
||||
*/
|
||||
@Deprecated
|
||||
public static native void shutdown();
|
||||
|
||||
/**
|
||||
* Reboot the device.
|
||||
* @param reason code to pass to the kernel (e.g. "recovery"), or null.
|
||||
*
|
||||
* @throws IOException if reboot fails for some reason (eg, lack of
|
||||
* permission)
|
||||
*/
|
||||
public static native void reboot(String reason) throws IOException;
|
||||
}
|
||||
|
|
|
@ -1,32 +1,33 @@
|
|||
/* 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.SUTAgentAndroid;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int ateamlogo=0x7f020000;
|
||||
public static final int ic_stat_first=0x7f020001;
|
||||
public static final int ic_stat_neterror=0x7f020002;
|
||||
public static final int ic_stat_second=0x7f020003;
|
||||
public static final int ic_stat_warning=0x7f020004;
|
||||
public static final int icon=0x7f020005;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int Button01=0x7f050001;
|
||||
public static final int Textview01=0x7f050000;
|
||||
}
|
||||
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 com.mozilla.SUTAgentAndroid;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int ateamlogo=0x7f020000;
|
||||
public static final int ic_stat_first=0x7f020001;
|
||||
public static final int ic_stat_neterror=0x7f020002;
|
||||
public static final int ic_stat_second=0x7f020003;
|
||||
public static final int ic_stat_warning=0x7f020004;
|
||||
public static final int icon=0x7f020005;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int Button01=0x7f050001;
|
||||
public static final int Textview01=0x7f050000;
|
||||
}
|
||||
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,163 @@
|
|||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
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.SUTAgentAndroid.service;
|
||||
|
||||
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;
|
||||
int nExitCode = -1;
|
||||
|
||||
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)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
pProc.destroy();
|
||||
buffer = null;
|
||||
System.gc();
|
||||
}
|
||||
|
||||
private boolean IsProcRunning(Process pProc)
|
||||
{
|
||||
boolean bRet = false;
|
||||
|
||||
try
|
||||
{
|
||||
nExitCode = pProc.exitValue();
|
||||
}
|
||||
catch (IllegalThreadStateException z)
|
||||
{
|
||||
nExitCode = -1;
|
||||
bRet = true;
|
||||
}
|
||||
|
||||
return(bRet);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,318 +1,318 @@
|
|||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.mozilla.SUTAgentAndroid.R;
|
||||
import com.mozilla.SUTAgentAndroid.SUTAgentAndroid;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
|
||||
public class RunCmdThread extends Thread
|
||||
{
|
||||
private ServerSocket SvrSocket = null;
|
||||
private Socket socket = null;
|
||||
private Handler handler = null;
|
||||
boolean bListening = true;
|
||||
boolean bNetError = false;
|
||||
List<CmdWorkerThread> theWorkers = new ArrayList<CmdWorkerThread>();
|
||||
android.app.Service svc = null;
|
||||
|
||||
public RunCmdThread(ServerSocket socket, android.app.Service service, Handler handler)
|
||||
{
|
||||
super("RunCmdThread");
|
||||
this.SvrSocket = socket;
|
||||
this.svc = service;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
int nIterations = 0;
|
||||
|
||||
SvrSocket.setSoTimeout(5000);
|
||||
while (bListening)
|
||||
{
|
||||
try
|
||||
{
|
||||
socket = SvrSocket.accept();
|
||||
CmdWorkerThread theWorker = new CmdWorkerThread(this, socket);
|
||||
theWorker.start();
|
||||
theWorkers.add(theWorker);
|
||||
}
|
||||
catch (SocketTimeoutException toe)
|
||||
{
|
||||
if (++nIterations > 60)
|
||||
{
|
||||
nIterations = 0;
|
||||
String sRet = SendPing("www.mozilla.org");
|
||||
if (sRet.contains("3 received"))
|
||||
handler.post(new doCancelNotification());
|
||||
else
|
||||
handler.post(new doSendNotification("SUTAgent - Network Connectivity Error", sRet));
|
||||
sRet = null;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int nNumWorkers = theWorkers.size();
|
||||
for (int lcv = 0; lcv < nNumWorkers; lcv++)
|
||||
{
|
||||
if (theWorkers.get(lcv).isAlive())
|
||||
{
|
||||
theWorkers.get(lcv).StopListening();
|
||||
while(theWorkers.get(lcv).isAlive())
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
theWorkers.clear();
|
||||
|
||||
SvrSocket.close();
|
||||
|
||||
svc.stopSelf();
|
||||
|
||||
// SUTAgentAndroid.me.finish();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private String SendPing(String sIPAddr)
|
||||
{
|
||||
Process pProc;
|
||||
String sRet = "";
|
||||
String [] theArgs = new String [4];
|
||||
boolean bStillRunning = true;
|
||||
int nBytesOut = 0;
|
||||
int nBytesErr = 0;
|
||||
int nBytesRead = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
theArgs[0] = "ping";
|
||||
theArgs[1] = "-c";
|
||||
theArgs[2] = "3";
|
||||
theArgs[3] = sIPAddr;
|
||||
|
||||
try
|
||||
{
|
||||
pProc = Runtime.getRuntime().exec(theArgs);
|
||||
|
||||
InputStream sutOut = pProc.getInputStream();
|
||||
InputStream sutErr = pProc.getErrorStream();
|
||||
|
||||
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");
|
||||
sRet += sRep;
|
||||
sRep = null;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
sRet += sRep;
|
||||
sRep = null;
|
||||
}
|
||||
}
|
||||
|
||||
bStillRunning = (IsProcRunning(pProc) || (sutOut.available() > 0) || (sutErr.available() > 0));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if ((bStillRunning == true) && (nBytesErr == 0) && (nBytesOut == 0))
|
||||
{
|
||||
try {
|
||||
sleep(2000);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pProc.destroy();
|
||||
pProc = null;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
sRet = e.getMessage();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return (sRet);
|
||||
}
|
||||
|
||||
private boolean IsProcRunning(Process pProc)
|
||||
{
|
||||
boolean bRet = false;
|
||||
@SuppressWarnings("unused")
|
||||
int nExitCode = 0;
|
||||
|
||||
try
|
||||
{
|
||||
nExitCode = pProc.exitValue();
|
||||
}
|
||||
catch (IllegalThreadStateException z)
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return(bRet);
|
||||
}
|
||||
|
||||
private void SendNotification(String tickerText, String expandedText)
|
||||
{
|
||||
NotificationManager notificationManager = (NotificationManager)svc.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
// int icon = android.R.drawable.stat_notify_more;
|
||||
// int icon = R.drawable.ic_stat_first;
|
||||
// int icon = R.drawable.ic_stat_second;
|
||||
// int icon = R.drawable.ic_stat_neterror;
|
||||
int icon = R.drawable.ateamlogo;
|
||||
long when = System.currentTimeMillis();
|
||||
|
||||
Notification notification = new Notification(icon, tickerText, when);
|
||||
|
||||
notification.flags |= (Notification.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL);
|
||||
notification.defaults |= Notification.DEFAULT_SOUND;
|
||||
notification.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
notification.defaults |= Notification.DEFAULT_LIGHTS;
|
||||
|
||||
Context context = svc.getApplicationContext();
|
||||
|
||||
// Intent to launch an activity when the extended text is clicked
|
||||
Intent intent2 = new Intent(svc, SUTAgentAndroid.class);
|
||||
PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent2, 0);
|
||||
|
||||
notification.setLatestEventInfo(context, tickerText, expandedText, launchIntent);
|
||||
|
||||
notificationManager.notify(1959, notification);
|
||||
}
|
||||
|
||||
private void CancelNotification()
|
||||
{
|
||||
NotificationManager notificationManager = (NotificationManager)svc.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(1959);
|
||||
}
|
||||
|
||||
class doCancelNotification implements Runnable
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
CancelNotification();
|
||||
}
|
||||
};
|
||||
|
||||
class doSendNotification implements Runnable
|
||||
{
|
||||
private String sTitle = "";
|
||||
private String sBText = "";
|
||||
|
||||
doSendNotification(String sTitle, String sBodyText)
|
||||
{
|
||||
this.sTitle = sTitle;
|
||||
this.sBText = sBodyText;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
SendNotification(sTitle, sBText);
|
||||
}
|
||||
};
|
||||
}
|
||||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.mozilla.SUTAgentAndroid.R;
|
||||
import com.mozilla.SUTAgentAndroid.SUTAgentAndroid;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
|
||||
public class RunCmdThread extends Thread
|
||||
{
|
||||
private ServerSocket SvrSocket = null;
|
||||
private Socket socket = null;
|
||||
private Handler handler = null;
|
||||
boolean bListening = true;
|
||||
boolean bNetError = false;
|
||||
List<CmdWorkerThread> theWorkers = new ArrayList<CmdWorkerThread>();
|
||||
android.app.Service svc = null;
|
||||
|
||||
public RunCmdThread(ServerSocket socket, android.app.Service service, Handler handler)
|
||||
{
|
||||
super("RunCmdThread");
|
||||
this.SvrSocket = socket;
|
||||
this.svc = service;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
int nIterations = 0;
|
||||
|
||||
SvrSocket.setSoTimeout(5000);
|
||||
while (bListening)
|
||||
{
|
||||
try
|
||||
{
|
||||
socket = SvrSocket.accept();
|
||||
CmdWorkerThread theWorker = new CmdWorkerThread(this, socket);
|
||||
theWorker.start();
|
||||
theWorkers.add(theWorker);
|
||||
}
|
||||
catch (SocketTimeoutException toe)
|
||||
{
|
||||
if (++nIterations > 60)
|
||||
{
|
||||
nIterations = 0;
|
||||
String sRet = SendPing("www.mozilla.org");
|
||||
if (sRet.contains("3 received"))
|
||||
handler.post(new doCancelNotification());
|
||||
else
|
||||
handler.post(new doSendNotification("SUTAgent - Network Connectivity Error", sRet));
|
||||
sRet = null;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int nNumWorkers = theWorkers.size();
|
||||
for (int lcv = 0; lcv < nNumWorkers; lcv++)
|
||||
{
|
||||
if (theWorkers.get(lcv).isAlive())
|
||||
{
|
||||
theWorkers.get(lcv).StopListening();
|
||||
while(theWorkers.get(lcv).isAlive())
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
theWorkers.clear();
|
||||
|
||||
SvrSocket.close();
|
||||
|
||||
svc.stopSelf();
|
||||
|
||||
// SUTAgentAndroid.me.finish();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private String SendPing(String sIPAddr)
|
||||
{
|
||||
Process pProc;
|
||||
String sRet = "";
|
||||
String [] theArgs = new String [4];
|
||||
boolean bStillRunning = true;
|
||||
int nBytesOut = 0;
|
||||
int nBytesErr = 0;
|
||||
int nBytesRead = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
theArgs[0] = "ping";
|
||||
theArgs[1] = "-c";
|
||||
theArgs[2] = "3";
|
||||
theArgs[3] = sIPAddr;
|
||||
|
||||
try
|
||||
{
|
||||
pProc = Runtime.getRuntime().exec(theArgs);
|
||||
|
||||
InputStream sutOut = pProc.getInputStream();
|
||||
InputStream sutErr = pProc.getErrorStream();
|
||||
|
||||
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");
|
||||
sRet += sRep;
|
||||
sRep = null;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
sRet += sRep;
|
||||
sRep = null;
|
||||
}
|
||||
}
|
||||
|
||||
bStillRunning = (IsProcRunning(pProc) || (sutOut.available() > 0) || (sutErr.available() > 0));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if ((bStillRunning == true) && (nBytesErr == 0) && (nBytesOut == 0))
|
||||
{
|
||||
try {
|
||||
sleep(2000);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pProc.destroy();
|
||||
pProc = null;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
sRet = e.getMessage();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return (sRet);
|
||||
}
|
||||
|
||||
private boolean IsProcRunning(Process pProc)
|
||||
{
|
||||
boolean bRet = false;
|
||||
@SuppressWarnings("unused")
|
||||
int nExitCode = 0;
|
||||
|
||||
try
|
||||
{
|
||||
nExitCode = pProc.exitValue();
|
||||
}
|
||||
catch (IllegalThreadStateException z)
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return(bRet);
|
||||
}
|
||||
|
||||
private void SendNotification(String tickerText, String expandedText)
|
||||
{
|
||||
NotificationManager notificationManager = (NotificationManager)svc.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
// int icon = android.R.drawable.stat_notify_more;
|
||||
// int icon = R.drawable.ic_stat_first;
|
||||
// int icon = R.drawable.ic_stat_second;
|
||||
// int icon = R.drawable.ic_stat_neterror;
|
||||
int icon = R.drawable.ateamlogo;
|
||||
long when = System.currentTimeMillis();
|
||||
|
||||
Notification notification = new Notification(icon, tickerText, when);
|
||||
|
||||
notification.flags |= (Notification.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL);
|
||||
notification.defaults |= Notification.DEFAULT_SOUND;
|
||||
notification.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
notification.defaults |= Notification.DEFAULT_LIGHTS;
|
||||
|
||||
Context context = svc.getApplicationContext();
|
||||
|
||||
// Intent to launch an activity when the extended text is clicked
|
||||
Intent intent2 = new Intent(svc, SUTAgentAndroid.class);
|
||||
PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent2, 0);
|
||||
|
||||
notification.setLatestEventInfo(context, tickerText, expandedText, launchIntent);
|
||||
|
||||
notificationManager.notify(1959, notification);
|
||||
}
|
||||
|
||||
private void CancelNotification()
|
||||
{
|
||||
NotificationManager notificationManager = (NotificationManager)svc.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(1959);
|
||||
}
|
||||
|
||||
class doCancelNotification implements Runnable
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
CancelNotification();
|
||||
}
|
||||
};
|
||||
|
||||
class doSendNotification implements Runnable
|
||||
{
|
||||
private String sTitle = "";
|
||||
private String sBText = "";
|
||||
|
||||
doSendNotification(String sTitle, String sBodyText)
|
||||
{
|
||||
this.sTitle = sTitle;
|
||||
this.sBText = sBodyText;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
SendNotification(sTitle, sBText);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,125 +1,125 @@
|
|||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
|
||||
public class RunDataThread extends Thread
|
||||
{
|
||||
Timer heartBeatTimer;
|
||||
|
||||
private ServerSocket SvrSocket = null;
|
||||
private Socket socket = null;
|
||||
boolean bListening = true;
|
||||
List<DataWorkerThread> theWorkers = new ArrayList<DataWorkerThread>();
|
||||
android.app.Service svc = null;
|
||||
|
||||
public RunDataThread(ServerSocket socket, android.app.Service service)
|
||||
{
|
||||
super("RunDataThread");
|
||||
this.SvrSocket = socket;
|
||||
this.svc = service;
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
|
||||
public void SendToDataChannel(String strToSend)
|
||||
{
|
||||
int nNumWorkers = theWorkers.size();
|
||||
for (int lcv = 0; lcv < nNumWorkers; lcv++)
|
||||
{
|
||||
if (theWorkers.get(lcv).isAlive())
|
||||
{
|
||||
theWorkers.get(lcv).SendString(strToSend);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
SvrSocket.setSoTimeout(5000);
|
||||
while (bListening)
|
||||
{
|
||||
try
|
||||
{
|
||||
socket = SvrSocket.accept();
|
||||
DataWorkerThread theWorker = new DataWorkerThread(this, socket);
|
||||
theWorker.start();
|
||||
theWorkers.add(theWorker);
|
||||
}
|
||||
catch (SocketTimeoutException toe)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int nNumWorkers = theWorkers.size();
|
||||
for (int lcv = 0; lcv < nNumWorkers; lcv++)
|
||||
{
|
||||
if (theWorkers.get(lcv).isAlive())
|
||||
{
|
||||
theWorkers.get(lcv).StopListening();
|
||||
while(theWorkers.get(lcv).isAlive())
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
theWorkers.clear();
|
||||
|
||||
SvrSocket.close();
|
||||
|
||||
svc.stopSelf();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// Toast.makeText(SUTAgentAndroid.me.getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* ***** 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.SUTAgentAndroid.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
|
||||
public class RunDataThread extends Thread
|
||||
{
|
||||
Timer heartBeatTimer;
|
||||
|
||||
private ServerSocket SvrSocket = null;
|
||||
private Socket socket = null;
|
||||
boolean bListening = true;
|
||||
List<DataWorkerThread> theWorkers = new ArrayList<DataWorkerThread>();
|
||||
android.app.Service svc = null;
|
||||
|
||||
public RunDataThread(ServerSocket socket, android.app.Service service)
|
||||
{
|
||||
super("RunDataThread");
|
||||
this.SvrSocket = socket;
|
||||
this.svc = service;
|
||||
}
|
||||
|
||||
public void StopListening()
|
||||
{
|
||||
bListening = false;
|
||||
}
|
||||
|
||||
public void SendToDataChannel(String strToSend)
|
||||
{
|
||||
int nNumWorkers = theWorkers.size();
|
||||
for (int lcv = 0; lcv < nNumWorkers; lcv++)
|
||||
{
|
||||
if (theWorkers.get(lcv).isAlive())
|
||||
{
|
||||
theWorkers.get(lcv).SendString(strToSend);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
SvrSocket.setSoTimeout(5000);
|
||||
while (bListening)
|
||||
{
|
||||
try
|
||||
{
|
||||
socket = SvrSocket.accept();
|
||||
DataWorkerThread theWorker = new DataWorkerThread(this, socket);
|
||||
theWorker.start();
|
||||
theWorkers.add(theWorker);
|
||||
}
|
||||
catch (SocketTimeoutException toe)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int nNumWorkers = theWorkers.size();
|
||||
for (int lcv = 0; lcv < nNumWorkers; lcv++)
|
||||
{
|
||||
if (theWorkers.get(lcv).isAlive())
|
||||
{
|
||||
theWorkers.get(lcv).StopListening();
|
||||
while(theWorkers.get(lcv).isAlive())
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
theWorkers.clear();
|
||||
|
||||
SvrSocket.close();
|
||||
|
||||
svc.stopSelf();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// Toast.makeText(SUTAgentAndroid.me.getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,53 +1,53 @@
|
|||
/* ***** 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.SUTAgentAndroid;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class SUTStartupIntentReceiver extends BroadcastReceiver
|
||||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
Intent mySUTAgentIntent = new Intent(context, SUTAgentAndroid.class);
|
||||
mySUTAgentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(mySUTAgentIntent);
|
||||
}
|
||||
}
|
||||
/* ***** 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.SUTAgentAndroid;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class SUTStartupIntentReceiver extends BroadcastReceiver
|
||||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
Intent mySUTAgentIntent = new Intent(context, SUTAgentAndroid.class);
|
||||
mySUTAgentIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(mySUTAgentIntent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.mozilla.fencp"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" android:sharedUserId="org.mozilla.fennec.sharedID">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
|
||||
<activity android:label="@string/app_name" android:name="FenCP">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider android:name="FenCPFP"
|
||||
android:enabled="true"
|
||||
android:authorities="org.mozilla.fencp"
|
||||
android:exported="true">
|
||||
</provider>
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="6" />
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,211 @@
|
|||
/* ***** 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,15 +11,15 @@
|
|||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is MOZCE Lib.
|
||||
* The Original Code is Android SUTAgent code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* 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):
|
||||
* John Wolfe <wolfe@lobo.us>
|
||||
* 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
|
||||
|
@ -34,17 +34,16 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package org.mozilla.fencp;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
#ifndef MOZCE_WINDOWS_H
|
||||
#define MOZCE_WINDOWS_H
|
||||
|
||||
// This is to work around the inconistancy of GetProcAddress between
|
||||
// windows desktop and wince, see bug 464190
|
||||
|
||||
#include "@WINCE_SDK_DIR@/Include/Armv4i/windows.h"
|
||||
#ifdef GetProcAddress
|
||||
#undef GetProcAddress
|
||||
#endif
|
||||
#define GetProcAddress GetProcAddressA
|
||||
#endif
|
||||
public class FenCP extends Activity {
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
/* ***** 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,202 @@
|
|||
/* ***** 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
# ***** 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 the Android sutagent for testing.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Mozilla Foundation
|
||||
# Portions created by the Initial Developer are Copyright (C) 2010
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Clint Talbert <ctalbert@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 *****
|
||||
|
||||
DEPTH = ../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = FenCP
|
||||
|
||||
JAVAFILES = \
|
||||
DirCursor.java \
|
||||
FenCP.java \
|
||||
FenCPFP.java \
|
||||
FileCursor.java \
|
||||
R.java \
|
||||
$(NULL)
|
||||
|
||||
RES_FILES = \
|
||||
res/drawable-hdpi/icon.png \
|
||||
res/drawable-ldpi/icon.png \
|
||||
res/drawable-mdpi/icon.png \
|
||||
res/layout/main.xml \
|
||||
res/values/strings.xml \
|
||||
$(NULL)
|
||||
|
||||
GARBAGE += \
|
||||
AndroidManifest.xml \
|
||||
classes.dex \
|
||||
FenCP.apk \
|
||||
$(NULL)
|
||||
|
||||
GARBAGE_DIRS += res classes network-libs
|
||||
|
||||
JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# include Android specific java flags - using these instead of what's in rules.mk
|
||||
include $(topsrcdir)/config/android-common.mk
|
||||
|
||||
tools:: FenCP.apk
|
||||
|
||||
classes.dex: $(JAVAFILES)
|
||||
$(NSINSTALL) -D classes
|
||||
$(JAVAC) $(JAVAC_FLAGS) -d classes $(addprefix $(srcdir)/,$(JAVAFILES))
|
||||
$(DX) --dex --output=$@ classes
|
||||
|
||||
FenCP.ap_: $(srcdir)/AndroidManifest.xml
|
||||
$(AAPT) package -f -M $(srcdir)/AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -S res -F $@
|
||||
|
||||
FenCP-unsigned-unaligned.apk: FenCP.ap_ classes.dex
|
||||
$(APKBUILDER) $@ -v $(APKBUILDER_FLAGS) -z FenCP.ap_ -f classes.dex
|
||||
|
||||
FenCP-unaligned.apk: FenCP-unsigned-unaligned.apk
|
||||
cp FenCP-unsigned-unaligned.apk $@
|
||||
ifdef JARSIGNER
|
||||
$(JARSIGNER) $@
|
||||
endif
|
||||
|
||||
FenCP.apk: FenCP-unaligned.apk
|
||||
$(ZIPALIGN) -f -v 4 FenCP-unaligned.apk $@
|
||||
|
||||
export::
|
||||
$(NSINSTALL) -D res
|
||||
@(cd $(srcdir)/res && tar $(TAR_CREATE_FLAGS) - *) | (cd $(DEPTH)/build/mobile/sutagent/android/fencp/res && tar -xf -)
|
||||
|
|
@ -0,0 +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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-6
|
После Ширина: | Высота: | Размер: 4.0 KiB |
После Ширина: | Высота: | Размер: 1.7 KiB |
После Ширина: | Высота: | Размер: 2.5 KiB |
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hello"
|
||||
/>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="hello">Hello World, FennecCP!</string>
|
||||
<string name="app_name">FennecCP</string>
|
||||
</resources>
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.mozilla.ffxcp"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" android:sharedUserId="org.mozilla.firefox.sharedID">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
|
||||
<activity android:label="@string/app_name" android:name="ffxcp">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider android:name="FfxCPFP"
|
||||
android:enabled="true"
|
||||
android:authorities="org.mozilla.ffxcp"
|
||||
android:exported="true">
|
||||
</provider>
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="6" />
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,211 @@
|
|||
/* ***** 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,226 @@
|
|||
/* ***** 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
/* ***** 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
# ***** 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 the Android sutagent for testing.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Mozilla Foundation
|
||||
# Portions created by the Initial Developer are Copyright (C) 2010
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Clint Talbert <ctalbert@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 *****
|
||||
|
||||
DEPTH = ../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = FfxCP
|
||||
|
||||
JAVAFILES = \
|
||||
DirCursor.java \
|
||||
ffxcp.java \
|
||||
FfxCPFP.java \
|
||||
FileCursor.java \
|
||||
R.java \
|
||||
$(NULL)
|
||||
|
||||
RES_FILES = \
|
||||
res/drawable-hdpi/icon.png \
|
||||
res/drawable-ldpi/icon.png \
|
||||
res/drawable-mdpi/icon.png \
|
||||
res/layout/main.xml \
|
||||
res/values/strings.xml \
|
||||
$(NULL)
|
||||
|
||||
GARBAGE += \
|
||||
AndroidManifest.xml \
|
||||
classes.dex \
|
||||
FfxCP.apk \
|
||||
$(NULL)
|
||||
|
||||
GARBAGE_DIRS += res classes network-libs
|
||||
|
||||
JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# include Android specific java flags - using these instead of what's in rules.mk
|
||||
include $(topsrcdir)/config/android-common.mk
|
||||
|
||||
tools:: FfxCP.apk
|
||||
|
||||
classes.dex: $(JAVAFILES)
|
||||
$(NSINSTALL) -D classes
|
||||
$(JAVAC) $(JAVAC_FLAGS) -d classes $(addprefix $(srcdir)/,$(JAVAFILES))
|
||||
$(DX) --dex --output=$@ classes
|
||||
|
||||
FfxCP.ap_: $(srcdir)/AndroidManifest.xml
|
||||
$(AAPT) package -f -M $(srcdir)/AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -S res -F $@
|
||||
|
||||
FfxCP-unsigned-unaligned.apk: FfxCP.ap_ classes.dex
|
||||
$(APKBUILDER) $@ -v $(APKBUILDER_FLAGS) -z FfxCP.ap_ -f classes.dex
|
||||
|
||||
FfxCP-unaligned.apk: FfxCP-unsigned-unaligned.apk
|
||||
cp FfxCP-unsigned-unaligned.apk $@
|
||||
ifdef JARSIGNER
|
||||
$(JARSIGNER) $@
|
||||
endif
|
||||
|
||||
FfxCP.apk: FfxCP-unaligned.apk
|
||||
$(ZIPALIGN) -f -v 4 FfxCP-unaligned.apk $@
|
||||
|
||||
export::
|
||||
$(NSINSTALL) -D res
|
||||
@(cd $(srcdir)/res && tar $(TAR_CREATE_FLAGS) - *) | (cd $(DEPTH)/build/mobile/sutagent/android/ffxcp/res && tar -xf -)
|
||||
|
|
@ -0,0 +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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-6
|
|
@ -11,15 +11,15 @@
|
|||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is MOZCE Lib.
|
||||
* The Original Code is Android SUTAgent code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* 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):
|
||||
* John Wolfe <wolfe@lobo.us>
|
||||
* 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
|
||||
|
@ -34,19 +34,16 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package org.mozilla.ffxcp;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
#ifndef MOZCE_YMATH_H
|
||||
#define MOZCE_YMATH_H
|
||||
|
||||
// This is to work around _FNan not being defined on wince, see bug 464180
|
||||
|
||||
#include "@WINCE_SDK_DIR@/Include/Armv4i/ymath.h"
|
||||
#define _FMAX ((1 << (15 - _FOFF)) - 1)
|
||||
#define _FOFF 7
|
||||
#define _FSIGN 0x8000
|
||||
#define INIT(w0) {w0, 0}
|
||||
static const _Dconst _FNanWinCE = {INIT((_FMAX << _FOFF)
|
||||
| (1 << (_FOFF - 1)))};
|
||||
#define _FNan _FNanWinCE
|
||||
#endif
|
||||
public class ffxcp extends Activity {
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
}
|
||||
}
|
После Ширина: | Высота: | Размер: 4.0 KiB |
После Ширина: | Высота: | Размер: 1.7 KiB |
После Ширина: | Высота: | Размер: 2.5 KiB |
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hello"
|
||||
/>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="hello">Hello World, firefoxcp!</string>
|
||||
<string name="app_name">FirefoxCP</string>
|
||||
</resources>
|
|
@ -14,4 +14,6 @@
|
|||
|
||||
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="true" android:text="Exit"></Button>
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -3,4 +3,8 @@
|
|||
|
||||
<string name="hello">Hello World, SUTAgentAndroid!</string>
|
||||
<string name="app_name">SUTAgentAndroid</string>
|
||||
|
||||
|
||||
<string name="foreground_service_started">Foreground Service Started (ASMozStub)</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mozilla.watcher"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".WatcherMain"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<receiver android:name=".WatcherReceiver">
|
||||
<intent-filter>
|
||||
<action android:value="android.intent.action.BOOT_COMPLETED" android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
<category android:value="android.intent.category.HOME" android:name="android.intent.category.HOME"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service android:name="WatcherService">
|
||||
<intent-filter>
|
||||
<action android:name="com.mozilla.watcher.LISTENER_SERVICE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="5" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* This file is auto-generated. DO NOT MODIFY.
|
||||
* Original file: C:\\Users\\Bob\\workspace\\Watcher\\src\\com\\mozilla\\watcher\\IWatcherService.aidl
|
||||
*/
|
||||
package com.mozilla.watcher;
|
||||
public interface IWatcherService extends android.os.IInterface
|
||||
{
|
||||
/** Local-side IPC implementation stub class. */
|
||||
public static abstract class Stub extends android.os.Binder implements com.mozilla.watcher.IWatcherService
|
||||
{
|
||||
private static final java.lang.String DESCRIPTOR = "com.mozilla.watcher.IWatcherService";
|
||||
/** Construct the stub at attach it to the interface. */
|
||||
public Stub()
|
||||
{
|
||||
this.attachInterface(this, DESCRIPTOR);
|
||||
}
|
||||
/**
|
||||
* Cast an IBinder object into an com.mozilla.watcher.IWatcherService interface,
|
||||
* generating a proxy if needed.
|
||||
*/
|
||||
public static com.mozilla.watcher.IWatcherService asInterface(android.os.IBinder obj)
|
||||
{
|
||||
if ((obj==null)) {
|
||||
return null;
|
||||
}
|
||||
android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
|
||||
if (((iin!=null)&&(iin instanceof com.mozilla.watcher.IWatcherService))) {
|
||||
return ((com.mozilla.watcher.IWatcherService)iin);
|
||||
}
|
||||
return new com.mozilla.watcher.IWatcherService.Stub.Proxy(obj);
|
||||
}
|
||||
public android.os.IBinder asBinder()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
@Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case INTERFACE_TRANSACTION:
|
||||
{
|
||||
reply.writeString(DESCRIPTOR);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_UpdateApplication:
|
||||
{
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
java.lang.String _arg0;
|
||||
_arg0 = data.readString();
|
||||
java.lang.String _arg1;
|
||||
_arg1 = data.readString();
|
||||
java.lang.String _arg2;
|
||||
_arg2 = data.readString();
|
||||
int _arg3;
|
||||
_arg3 = data.readInt();
|
||||
int _result = this.UpdateApplication(_arg0, _arg1, _arg2, _arg3);
|
||||
reply.writeNoException();
|
||||
reply.writeInt(_result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onTransact(code, data, reply, flags);
|
||||
}
|
||||
private static class Proxy implements com.mozilla.watcher.IWatcherService
|
||||
{
|
||||
private android.os.IBinder mRemote;
|
||||
Proxy(android.os.IBinder remote)
|
||||
{
|
||||
mRemote = remote;
|
||||
}
|
||||
public android.os.IBinder asBinder()
|
||||
{
|
||||
return mRemote;
|
||||
}
|
||||
public java.lang.String getInterfaceDescriptor()
|
||||
{
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
public int UpdateApplication(java.lang.String sPkgName, java.lang.String sPkgFileName, java.lang.String sOutFile, int bReboot) throws android.os.RemoteException
|
||||
{
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
int _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeString(sPkgName);
|
||||
_data.writeString(sPkgFileName);
|
||||
_data.writeString(sOutFile);
|
||||
_data.writeInt(bReboot);
|
||||
mRemote.transact(Stub.TRANSACTION_UpdateApplication, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = _reply.readInt();
|
||||
}
|
||||
finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
}
|
||||
static final int TRANSACTION_UpdateApplication = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
|
||||
}
|
||||
public int UpdateApplication(java.lang.String sPkgName, java.lang.String sPkgFileName, java.lang.String sOutFile, int bReboot) throws android.os.RemoteException;
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
# ***** 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 the Android sutagent for testing.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Mozilla Foundation
|
||||
# Portions created by the Initial Developer are Copyright (C) 2010
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Clint Talbert <ctalbert@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 *****
|
||||
|
||||
DEPTH = ../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = Watcher
|
||||
|
||||
JAVAFILES = \
|
||||
IWatcherService.java \
|
||||
RedirOutputThread.java \
|
||||
R.java \
|
||||
WatcherMain.java \
|
||||
WatcherReceiver.java \
|
||||
WatcherService.java \
|
||||
$(NULL)
|
||||
|
||||
RES_FILES = \
|
||||
res/drawable-hdpi/icon.png \
|
||||
res/drawable-hdpi/ateamlogo.png \
|
||||
res/drawable-ldpi/icon.png \
|
||||
res/drawable-ldpi/ateamlogo.png \
|
||||
res/drawable-mdpi/icon.png \
|
||||
res/drawable-mdpi/ateamlogo.png \
|
||||
res/layout/main.xml \
|
||||
res/values/strings.xml \
|
||||
$(NULL)
|
||||
|
||||
GARBAGE += \
|
||||
AndroidManifest.xml \
|
||||
classes.dex \
|
||||
Watcher.apk \
|
||||
$(NULL)
|
||||
|
||||
GARBAGE_DIRS += res classes network-libs
|
||||
|
||||
JAVA_CLASSPATH = $(ANDROID_SDK)/android.jar
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# include Android specific java flags - using these instead of what's in rules.mk
|
||||
include $(topsrcdir)/config/android-common.mk
|
||||
|
||||
tools:: Watcher.apk
|
||||
|
||||
classes.dex: $(JAVAFILES)
|
||||
$(NSINSTALL) -D classes
|
||||
$(JAVAC) $(JAVAC_FLAGS) -d classes $(addprefix $(srcdir)/,$(JAVAFILES))
|
||||
$(DX) --dex --output=$@ classes
|
||||
|
||||
Watcher.ap_: $(srcdir)/AndroidManifest.xml
|
||||
$(AAPT) package -f -M $(srcdir)/AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -S res -F $@
|
||||
|
||||
Watcher-unsigned-unaligned.apk: Watcher.ap_ classes.dex
|
||||
$(APKBUILDER) $@ -v $(APKBUILDER_FLAGS) -z Watcher.ap_ -f classes.dex
|
||||
|
||||
Watcher-unaligned.apk: Watcher-unsigned-unaligned.apk
|
||||
cp Watcher-unsigned-unaligned.apk $@
|
||||
ifdef JARSIGNER
|
||||
$(JARSIGNER) $@
|
||||
endif
|
||||
|
||||
Watcher.apk: Watcher-unaligned.apk
|
||||
$(ZIPALIGN) -f -v 4 Watcher-unaligned.apk $@
|
||||
|
||||
export::
|
||||
$(NSINSTALL) -D res
|
||||
@(cd $(srcdir)/res && tar $(TAR_CREATE_FLAGS) - *) | (cd $(DEPTH)/build/mobile/sutagent/android/watcher/res && tar -xf -)
|
||||
|
|
@ -0,0 +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;
|
||||
}
|
||||
}
|
|
@ -0,0 +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);
|
||||
}
|
||||
}
|
|
@ -11,15 +11,15 @@
|
|||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is MOZCE Lib.
|
||||
* The Original Code is Android SUTAgent code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* 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):
|
||||
* Robert Strong <robert.bugzilla@gmail.com>
|
||||
* 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
|
||||
|
@ -34,30 +34,16 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package com.mozilla.watcher;
|
||||
|
||||
/* environment.h and environment.cpp are also included by app update */
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
#ifndef MOZCE_ENVIRONMENT_H
|
||||
#define MOZCE_ENVIRONMENT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Environment stuff */
|
||||
char* getenv(const char* inName);
|
||||
int putenv(const char *a);
|
||||
char SetEnvironmentVariableW(const wchar_t * name, const wchar_t * value );
|
||||
char GetEnvironmentVariableW(const wchar_t * lpName, wchar_t* lpBuffer, unsigned long nSize);
|
||||
|
||||
unsigned int ExpandEnvironmentStringsW(const wchar_t* lpSrc,
|
||||
wchar_t* lpDst,
|
||||
unsigned int nSize);
|
||||
|
||||
wchar_t* mozce_GetEnvironmentCL();
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif //MOZCE_ENVIRONMENT_H
|
||||
public class WatcherMain extends Activity {
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -12,17 +11,15 @@
|
|||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
* The Original Code is Android SUTAgent code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* Bob Moss.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Nisheeth Ranjan <nisheeth@netscape.com> (original author)
|
||||
* Peter Van der Beken <peterv@netscape.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -37,21 +34,22 @@
|
|||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package com.mozilla.watcher;
|
||||
|
||||
#include "nsISupports.idl"
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
// import android.os.Debug;
|
||||
|
||||
interface nsIDOMNode;
|
||||
interface nsIDOMDocument;
|
||||
public class WatcherReceiver extends BroadcastReceiver {
|
||||
|
||||
/**
|
||||
* @deprecated Use nsIXSLTProcessor instead!!
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
|
||||
[deprecated, scriptable, uuid(3fbff728-2d20-11d3-aef3-00108300ff91)]
|
||||
interface nsIXSLTProcessorObsolete : nsISupports
|
||||
{
|
||||
void transformDocument(in nsIDOMNode aSourceDOM,
|
||||
in nsIDOMNode aStyleDOM,
|
||||
in nsIDOMDocument aOutputDOC,
|
||||
in nsISupports aObserver);
|
||||
};
|
||||
}
|
|
@ -0,0 +1,948 @@
|
|||
/* ***** 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.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.KeyguardManager;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.ActivityNotFoundException;
|
||||
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.PackageManager.NameNotFoundException;
|
||||
import android.os.IBinder;
|
||||
import android.os.PowerManager;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class WatcherService extends Service
|
||||
{
|
||||
String sErrorPrefix = "##Installer Error## ";
|
||||
String currentDir = "/";
|
||||
String sPingTarget = "";
|
||||
long lDelay = 60000;
|
||||
long lPeriod = 300000;
|
||||
int nMaxStrikes = 3;
|
||||
Process pProc;
|
||||
Context myContext = null;
|
||||
Timer myTimer = null;
|
||||
private PowerManager.WakeLock pwl = null;
|
||||
public static final int NOTIFICATION_ID = 1964;
|
||||
boolean bInstalling = false;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final Class[] mStartForegroundSignature = new Class[] {
|
||||
int.class, Notification.class};
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final Class[] mStopForegroundSignature = new Class[] {
|
||||
boolean.class};
|
||||
|
||||
private NotificationManager mNM;
|
||||
private Method mStartForeground;
|
||||
private Method mStopForeground;
|
||||
private Object[] mStartForegroundArgs = new Object[2];
|
||||
private Object[] mStopForegroundArgs = new Object[1];
|
||||
|
||||
|
||||
private IWatcherService.Stub stub = new IWatcherService.Stub() {
|
||||
public int UpdateApplication(String sAppName, String sFileName, String sOutFile, int bReboot) throws RemoteException
|
||||
{
|
||||
return UpdtApp(sAppName, sFileName, sOutFile, bReboot);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent arg0) {
|
||||
return stub;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
|
||||
myContext = this;
|
||||
|
||||
getKeyGuardAndWakeLock();
|
||||
|
||||
File dir = getFilesDir();
|
||||
File iniFile = new File(dir, "watcher.ini");
|
||||
String sIniFile = iniFile.getAbsolutePath();
|
||||
String sHold = "";
|
||||
|
||||
this.sPingTarget = GetIniData("watcher", "PingTarget", sIniFile, "www.mozilla.org");
|
||||
sHold = GetIniData("watcher", "delay", sIniFile, "60000");
|
||||
this.lDelay = Long.parseLong(sHold.trim());
|
||||
sHold = GetIniData("watcher", "period", sIniFile,"300000");
|
||||
this.lPeriod = Long.parseLong(sHold.trim());
|
||||
sHold = GetIniData("watcher", "strikes", sIniFile,"3");
|
||||
this.nMaxStrikes = Integer.parseInt(sHold.trim());
|
||||
|
||||
doToast("WatcherService created");
|
||||
}
|
||||
|
||||
public String GetIniData(String sSection, String sKey, String sFile, String sDefault)
|
||||
{
|
||||
String sRet = sDefault;
|
||||
String sComp = "";
|
||||
String sLine = "";
|
||||
boolean bFound = false;
|
||||
BufferedReader in = null;
|
||||
String sTmpFileName = fixFileName(sFile);
|
||||
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(sTmpFileName));
|
||||
sComp = "[" + sSection + "]";
|
||||
while ((sLine = in.readLine()) != null)
|
||||
{
|
||||
if (sLine.equalsIgnoreCase(sComp))
|
||||
{
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bFound)
|
||||
{
|
||||
sComp = (sKey + " =").toLowerCase();
|
||||
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();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
sComp = e.toString();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
sComp = e.toString();
|
||||
}
|
||||
return (sRet);
|
||||
}
|
||||
|
||||
private void handleCommand(Intent intent)
|
||||
{
|
||||
String sCmd = intent.getStringExtra("command");
|
||||
|
||||
// Debug.waitForDebugger();
|
||||
|
||||
if (sCmd != null)
|
||||
{
|
||||
if (sCmd.equalsIgnoreCase("updt"))
|
||||
{
|
||||
String sPkgName = intent.getStringExtra("pkgName");
|
||||
String sPkgFile = intent.getStringExtra("pkgFile");
|
||||
String sOutFile = intent.getStringExtra("outFile");
|
||||
boolean bReboot = intent.getBooleanExtra("reboot", true);
|
||||
int nReboot = bReboot ? 1 : 0;
|
||||
SendNotification("WatcherService updating " + sPkgName + " using file " + sPkgFile, "WatcherService updating " + sPkgName + " using file " + sPkgFile);
|
||||
|
||||
UpdateApplication worker = new UpdateApplication(sPkgName, sPkgFile, sOutFile, nReboot);
|
||||
}
|
||||
else if (sCmd.equalsIgnoreCase("start"))
|
||||
{
|
||||
doToast("WatcherService started");
|
||||
myTimer = new Timer();
|
||||
myTimer.scheduleAtFixedRate(new MyTime(), lDelay, lPeriod);
|
||||
}
|
||||
else
|
||||
{
|
||||
doToast("WatcherService unknown command");
|
||||
}
|
||||
}
|
||||
else
|
||||
doToast("WatcherService created");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
handleCommand(intent);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
handleCommand(intent);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
doToast("WatcherService destroyed");
|
||||
if (pwl != null)
|
||||
pwl.release();
|
||||
stopForegroundCompat(R.string.foreground_service_started);
|
||||
}
|
||||
|
||||
protected void getKeyGuardAndWakeLock()
|
||||
{
|
||||
// Fire off a thread to do some work that we shouldn't do directly in the UI thread
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
// Keep phone from locking or remove lock on screen
|
||||
KeyguardManager km = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
|
||||
if (km != null)
|
||||
{
|
||||
KeyguardManager.KeyguardLock kl = km.newKeyguardLock("watcher");
|
||||
if (kl != null)
|
||||
kl.disableKeyguard();
|
||||
}
|
||||
|
||||
// No sleeping on the job
|
||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
if (pm != null)
|
||||
{
|
||||
pwl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "watcher");
|
||||
if (pwl != null)
|
||||
pwl.acquire();
|
||||
}
|
||||
|
||||
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
try {
|
||||
mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature);
|
||||
mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature);
|
||||
}
|
||||
catch (NoSuchMethodException e)
|
||||
{
|
||||
// Running on an older platform.
|
||||
mStartForeground = mStopForeground = null;
|
||||
}
|
||||
Notification notification = new Notification();
|
||||
startForegroundCompat(R.string.foreground_service_started, notification);
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a wrapper around the new startForeground method, using the older
|
||||
* APIs if it is not available.
|
||||
*/
|
||||
void startForegroundCompat(int id, Notification notification) {
|
||||
// If we have the new startForeground API, then use it.
|
||||
if (mStartForeground != null) {
|
||||
mStartForegroundArgs[0] = Integer.valueOf(id);
|
||||
mStartForegroundArgs[1] = notification;
|
||||
try {
|
||||
mStartForeground.invoke(this, mStartForegroundArgs);
|
||||
} catch (InvocationTargetException e) {
|
||||
// Should not happen.
|
||||
Log.w("ApiDemos", "Unable to invoke startForeground", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
// Should not happen.
|
||||
Log.w("ApiDemos", "Unable to invoke startForeground", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back on the old API.
|
||||
setForeground(true);
|
||||
mNM.notify(id, notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a wrapper around the new stopForeground method, using the older
|
||||
* APIs if it is not available.
|
||||
*/
|
||||
void stopForegroundCompat(int id) {
|
||||
// If we have the new stopForeground API, then use it.
|
||||
if (mStopForeground != null) {
|
||||
mStopForegroundArgs[0] = Boolean.TRUE;
|
||||
try {
|
||||
mStopForeground.invoke(this, mStopForegroundArgs);
|
||||
} catch (InvocationTargetException e) {
|
||||
// Should not happen.
|
||||
Log.w("ApiDemos", "Unable to invoke stopForeground", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
// Should not happen.
|
||||
Log.w("ApiDemos", "Unable to invoke stopForeground", e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back on the old API. Note to cancel BEFORE changing the
|
||||
// foreground state, since we could be killed at that point.
|
||||
mNM.cancel(id);
|
||||
setForeground(false);
|
||||
}
|
||||
|
||||
public void doToast(String sMsg)
|
||||
{
|
||||
Toast toast = Toast.makeText(this, sMsg, Toast.LENGTH_LONG);
|
||||
toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 100);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
public void CheckMem() {
|
||||
System.gc();
|
||||
long lFreeMemory = Runtime.getRuntime().freeMemory();
|
||||
long lTotMemory = Runtime.getRuntime().totalMemory();
|
||||
long lMaxMemory = Runtime.getRuntime().maxMemory();
|
||||
|
||||
SendNotification("Memory Check", "Free: " + lFreeMemory + "Total: " + lTotMemory + "Max: " + lMaxMemory);
|
||||
}
|
||||
|
||||
public int UpdtApp(String sPkgName, String sPkgFileName, String sOutFile, int bReboot)
|
||||
{
|
||||
int nRet = 1;
|
||||
int lcv = 0;
|
||||
String sRet = "";
|
||||
|
||||
// Debug.waitForDebugger();
|
||||
|
||||
FileOutputStream f = null;
|
||||
|
||||
try {
|
||||
SendNotification("Killing " + sPkgName, "Step 1: Kill " + sPkgName + " if running");
|
||||
while (!IsProcessDead(sPkgName) && (lcv < 5)) {
|
||||
if (KillProcess(sPkgName, null).startsWith("Successfully"))
|
||||
break;
|
||||
else
|
||||
lcv++;
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
|
||||
CheckMem();
|
||||
|
||||
if ((sOutFile != null) && (sOutFile.length() > 0)) {
|
||||
File outFile = new File(sOutFile);
|
||||
if (outFile.exists() && outFile.canWrite()) {
|
||||
f = new FileOutputStream(outFile, true);
|
||||
} else {
|
||||
SendNotification("File not found or cannot write to " + sOutFile, "File not found or cannot write to " + sOutFile);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
SendNotification("File not found " + sOutFile, "Couldn't open " + sOutFile + " " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
SendNotification("Security excepetion for " + sOutFile, "Exception message " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if ((sPkgName != null) && (sPkgName.length() > 0))
|
||||
{
|
||||
SendNotification("Uninstalling " + sPkgName, "Step 2: Uninstall " + sPkgName);
|
||||
sRet = UnInstallApp(sPkgName, null);
|
||||
CheckMem();
|
||||
if ((sRet.length() > 0) && (f != null))
|
||||
{
|
||||
try {
|
||||
f.write(sRet.getBytes());
|
||||
f.flush();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((sPkgFileName != null) && (sPkgFileName.length() > 0))
|
||||
{
|
||||
SendNotification("Installing " + sPkgFileName, "Step 3: Install " + sPkgFileName);
|
||||
sRet = InstallApp(sPkgFileName, null);
|
||||
SendNotification("Installed " + sPkgFileName, "" + sRet);
|
||||
CheckMem();
|
||||
if ((sRet.length() > 0) && (f != null))
|
||||
{
|
||||
try {
|
||||
f.write(sRet.getBytes());
|
||||
f.flush();
|
||||
f.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bReboot > 0)
|
||||
RunReboot(null);
|
||||
|
||||
return(nRet);
|
||||
}
|
||||
|
||||
public boolean GetProcessInfo(String sProcName)
|
||||
{
|
||||
boolean bRet = false;
|
||||
ActivityManager aMgr = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE);
|
||||
List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses();
|
||||
int nProcs = lProcesses.size();
|
||||
int lcv = 0;
|
||||
String strProcName = "";
|
||||
|
||||
for (lcv = 0; lcv < nProcs; lcv++)
|
||||
{
|
||||
strProcName = lProcesses.get(lcv).processName;
|
||||
if (strProcName.contains(sProcName))
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
}
|
||||
|
||||
return (bRet);
|
||||
}
|
||||
|
||||
public String RunReboot(OutputStream out)
|
||||
{
|
||||
String sRet = "";
|
||||
String [] theArgs = new String [3];
|
||||
|
||||
theArgs[0] = "su";
|
||||
theArgs[1] = "-c";
|
||||
theArgs[2] = "reboot";
|
||||
|
||||
try
|
||||
{
|
||||
pProc = Runtime.getRuntime().exec(theArgs);
|
||||
RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
|
||||
outThrd.start();
|
||||
outThrd.join(10000);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
sRet = e.getMessage();
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return (sRet);
|
||||
}
|
||||
|
||||
public String KillProcess(String sProcName, OutputStream out)
|
||||
{
|
||||
String [] theArgs = new String [3];
|
||||
|
||||
theArgs[0] = "su";
|
||||
theArgs[1] = "-c";
|
||||
theArgs[2] = "kill";
|
||||
|
||||
String sRet = sErrorPrefix + "Unable to kill " + sProcName + "\n";
|
||||
ActivityManager aMgr = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
|
||||
List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses();
|
||||
int lcv = 0;
|
||||
String strProcName = "";
|
||||
int nPID = 0;
|
||||
|
||||
for (lcv = 0; lcv < lProcesses.size(); lcv++)
|
||||
{
|
||||
if (lProcesses.get(lcv).processName.contains(sProcName))
|
||||
{
|
||||
strProcName = lProcesses.get(lcv).processName;
|
||||
nPID = lProcesses.get(lcv).pid;
|
||||
sRet = sErrorPrefix + "Failed to kill " + nPID + " " + strProcName + "\n";
|
||||
|
||||
theArgs[2] += " " + nPID;
|
||||
|
||||
try
|
||||
{
|
||||
pProc = Runtime.getRuntime().exec(theArgs);
|
||||
RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
|
||||
outThrd.start();
|
||||
outThrd.join(5000);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
sRet = e.getMessage();
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Give the messages a chance to be processed
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nPID > 0)
|
||||
{
|
||||
sRet = "Successfully killed " + nPID + " " + strProcName + "\n";
|
||||
lProcesses = aMgr.getRunningAppProcesses();
|
||||
for (lcv = 0; lcv < lProcesses.size(); lcv++)
|
||||
{
|
||||
if (lProcesses.get(lcv).processName.contains(sProcName))
|
||||
{
|
||||
sRet = sErrorPrefix + "Unable to kill " + nPID + " " + strProcName + "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (sRet);
|
||||
}
|
||||
|
||||
public String GetAppRoot(String AppName)
|
||||
{
|
||||
String sRet = sErrorPrefix + " internal error [no context]";
|
||||
Context ctx = getApplicationContext();
|
||||
|
||||
if (ctx != null)
|
||||
{
|
||||
try {
|
||||
Context appCtx = ctx.createPackageContext(AppName, 0);
|
||||
ContextWrapper appCtxW = new ContextWrapper(appCtx);
|
||||
sRet = appCtxW.getPackageResourcePath();
|
||||
appCtxW = null;
|
||||
appCtx = null;
|
||||
ctx = null;
|
||||
System.gc();
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return(sRet);
|
||||
}
|
||||
|
||||
public boolean IsProcessDead(String sProcName)
|
||||
{
|
||||
boolean bRet = true;
|
||||
ActivityManager aMgr = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
|
||||
List <ActivityManager.RunningAppProcessInfo> lProcesses = aMgr.getRunningAppProcesses(); // .getProcessesInErrorState();
|
||||
int lcv = 0;
|
||||
|
||||
if (lProcesses != null)
|
||||
{
|
||||
for (lcv = 0; lcv < lProcesses.size(); lcv++)
|
||||
{
|
||||
if (lProcesses.get(lcv).processName.contentEquals(sProcName))
|
||||
{
|
||||
bRet = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (bRet);
|
||||
}
|
||||
|
||||
public String fixFileName(String fileName)
|
||||
{
|
||||
String sRet = "";
|
||||
String sTmpFileName = "";
|
||||
|
||||
sRet = fileName.replace('\\', '/');
|
||||
|
||||
if (sRet.startsWith("/"))
|
||||
sTmpFileName = sRet;
|
||||
else
|
||||
sTmpFileName = currentDir + "/" + sRet;
|
||||
|
||||
sRet = sTmpFileName.replace('\\', '/');
|
||||
sTmpFileName = sRet;
|
||||
sRet = sTmpFileName.replace("//", "/");
|
||||
|
||||
return(sRet);
|
||||
}
|
||||
|
||||
public String GetTmpDir()
|
||||
{
|
||||
String sRet = "";
|
||||
Context ctx = getApplicationContext();
|
||||
File dir = ctx.getFilesDir();
|
||||
ctx = null;
|
||||
try {
|
||||
sRet = dir.getCanonicalPath();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return(sRet);
|
||||
}
|
||||
|
||||
public String UnInstallApp(String sApp, OutputStream out)
|
||||
{
|
||||
String sRet = "";
|
||||
String [] theArgs = new String [3];
|
||||
|
||||
theArgs[0] = "su";
|
||||
theArgs[1] = "-c";
|
||||
theArgs[2] = "pm uninstall " + sApp + ";exit";
|
||||
|
||||
try
|
||||
{
|
||||
pProc = Runtime.getRuntime().exec(theArgs);
|
||||
|
||||
RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
|
||||
outThrd.start();
|
||||
outThrd.join(60000);
|
||||
int nRet = pProc.exitValue();
|
||||
sRet = "\nuninst complete [" + nRet + "]";
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
sRet = e.getMessage();
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return (sRet);
|
||||
}
|
||||
|
||||
public String InstallApp(String sApp, OutputStream out)
|
||||
{
|
||||
String sRet = "";
|
||||
String sHold = "";
|
||||
String [] theArgs = new String [3];
|
||||
|
||||
theArgs[0] = "su";
|
||||
theArgs[1] = "-c";
|
||||
theArgs[2] = "pm install " + sApp + ";exit";
|
||||
|
||||
try
|
||||
{
|
||||
pProc = Runtime.getRuntime().exec(theArgs);
|
||||
|
||||
RedirOutputThread outThrd = new RedirOutputThread(pProc, out);
|
||||
outThrd.start();
|
||||
outThrd.join(180000);
|
||||
int nRet = pProc.exitValue();
|
||||
sRet += "\ninstall complete [" + nRet + "]";
|
||||
sHold = outThrd.strOutput;
|
||||
sRet += "\nSuccess";
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
sRet = e.getMessage();
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return (sRet);
|
||||
}
|
||||
|
||||
private String SendPing(String sIPAddr)
|
||||
{
|
||||
Process pProc;
|
||||
String sRet = "";
|
||||
String [] theArgs = new String [4];
|
||||
boolean bStillRunning = true;
|
||||
int nBytesOut = 0;
|
||||
int nBytesErr = 0;
|
||||
int nBytesRead = 0;
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
theArgs[0] = "ping";
|
||||
theArgs[1] = "-c";
|
||||
theArgs[2] = "3";
|
||||
theArgs[3] = sIPAddr;
|
||||
|
||||
try
|
||||
{
|
||||
pProc = Runtime.getRuntime().exec(theArgs);
|
||||
|
||||
InputStream sutOut = pProc.getInputStream();
|
||||
InputStream sutErr = pProc.getErrorStream();
|
||||
|
||||
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");
|
||||
sRet += sRep;
|
||||
sRep = null;
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
sRet += sRep;
|
||||
sRep = null;
|
||||
}
|
||||
}
|
||||
|
||||
bStillRunning = (IsProcRunning(pProc) || (sutOut.available() > 0) || (sutErr.available() > 0));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if ((bStillRunning == true) && (nBytesErr == 0) && (nBytesOut == 0))
|
||||
{
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pProc.destroy();
|
||||
pProc = null;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
sRet = e.getMessage();
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return (sRet);
|
||||
}
|
||||
|
||||
private boolean IsProcRunning(Process pProc)
|
||||
{
|
||||
boolean bRet = false;
|
||||
@SuppressWarnings("unused")
|
||||
int nExitCode = 0;
|
||||
|
||||
try
|
||||
{
|
||||
nExitCode = pProc.exitValue();
|
||||
}
|
||||
catch (IllegalThreadStateException z)
|
||||
{
|
||||
bRet = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return(bRet);
|
||||
}
|
||||
|
||||
private class UpdateApplication implements Runnable {
|
||||
Thread runner;
|
||||
String msPkgName = "";
|
||||
String msPkgFileName = "";
|
||||
String msOutFile = "";
|
||||
int mbReboot = 0;
|
||||
|
||||
public UpdateApplication(String sPkgName, String sPkgFileName, String sOutFile, int bReboot) {
|
||||
runner = new Thread(this);
|
||||
msPkgName = sPkgName;
|
||||
msPkgFileName = sPkgFileName;
|
||||
msOutFile = sOutFile;
|
||||
mbReboot = bReboot;
|
||||
runner.start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
bInstalling = true;
|
||||
UpdtApp(msPkgName, msPkgFileName, msOutFile, mbReboot);
|
||||
bInstalling = false;
|
||||
}
|
||||
}
|
||||
|
||||
private class MyTime extends TimerTask
|
||||
{
|
||||
int nStrikes = 0;
|
||||
|
||||
public MyTime()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (bInstalling)
|
||||
return;
|
||||
|
||||
// See if the network is up, if not after three failures reboot
|
||||
String sRet = SendPing(sPingTarget);
|
||||
if (!sRet.contains("3 received"))
|
||||
{
|
||||
if (nMaxStrikes > 0)
|
||||
{
|
||||
if (++nStrikes >= nMaxStrikes)
|
||||
RunReboot(null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nStrikes = 0;
|
||||
}
|
||||
sRet = null;
|
||||
|
||||
String sProgramName = "com.mozilla.SUTAgentAndroid";
|
||||
PackageManager pm = myContext.getPackageManager();
|
||||
|
||||
// Debug.waitForDebugger();
|
||||
|
||||
if (!GetProcessInfo(sProgramName))
|
||||
{
|
||||
Intent agentIntent = new Intent();
|
||||
agentIntent.setPackage(sProgramName);
|
||||
agentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
agentIntent.setAction(Intent.ACTION_MAIN);
|
||||
try {
|
||||
PackageInfo pi = pm.getPackageInfo(sProgramName, PackageManager.GET_ACTIVITIES | PackageManager.GET_INTENT_FILTERS);
|
||||
ActivityInfo [] ai = pi.activities;
|
||||
for (int i = 0; i < ai.length; i++)
|
||||
{
|
||||
ActivityInfo a = ai[i];
|
||||
if (a.name.length() > 0)
|
||||
{
|
||||
agentIntent.setClassName(a.packageName, a.name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
try
|
||||
{
|
||||
myContext.startActivity(agentIntent);
|
||||
}
|
||||
catch(ActivityNotFoundException anf)
|
||||
{
|
||||
anf.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SendNotification(String tickerText, String expandedText) {
|
||||
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
int icon = R.drawable.ateamlogo;
|
||||
long when = System.currentTimeMillis();
|
||||
|
||||
Notification notification = new Notification(icon, tickerText, when);
|
||||
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
notification.defaults |= Notification.DEFAULT_SOUND;
|
||||
// notification.defaults |= Notification.DEFAULT_VIBRATE;
|
||||
notification.defaults |= Notification.DEFAULT_LIGHTS;
|
||||
|
||||
Context context = getApplicationContext();
|
||||
|
||||
// Intent to launch an activity when the extended text is clicked
|
||||
Intent intent = new Intent(this, WatcherService.class);
|
||||
PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
|
||||
notification.setLatestEventInfo(context, tickerText, expandedText, launchIntent);
|
||||
|
||||
notificationManager.notify(NOTIFICATION_ID, notification);
|
||||
}
|
||||
|
||||
private void CancelNotification() {
|
||||
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(NOTIFICATION_ID);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-5
|
После Ширина: | Высота: | Размер: 1.5 KiB |
После Ширина: | Высота: | Размер: 4.0 KiB |
После Ширина: | Высота: | Размер: 1.5 KiB |
После Ширина: | Высота: | Размер: 1.7 KiB |
После Ширина: | Высота: | Размер: 1.5 KiB |
После Ширина: | Высота: | Размер: 2.5 KiB |
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/hello"
|
||||
/>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="hello">Hello World, WatcherMain!</string>
|
||||
<string name="app_name">watcher</string>
|
||||
<string name="foreground_service_started">Foreground Service Started</string>
|
||||
|
||||
</resources>
|
|
@ -1,456 +0,0 @@
|
|||
# ***** 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 Mozilla build system.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Mozilla Foundation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2007
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# John Wolfe <wolfe@lobo.us>
|
||||
# Vladimir Vukicevic <vladimir@pobox.com>
|
||||
# Alex Pakhotin <alexp@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 *****
|
||||
################################################################
|
||||
#
|
||||
# make_wince_cab.py --- Given a directory, walk it and make an
|
||||
# installer based upon the contents of that directory
|
||||
#
|
||||
# Usage:
|
||||
# python make_wince_cab.py [-setupdll] [-s] [-faststart] [CABWIZ_PATH] SOURCE_DIR PROGRAM_NAME CAB_FINAL_NAME
|
||||
#
|
||||
# Walk through the relative directory SOURCE_DIR, parsing filenames
|
||||
# Checks for duplicate filenames and renames where needed
|
||||
# Then builds a WinMobile INF file based upon results
|
||||
#
|
||||
# Each directory in SOURCE_DIR may have a file named
|
||||
# 'install-exceptions', which lists files in SOURCE_DIR that
|
||||
# need not be placed into an installation CAB file. The
|
||||
# 'install-exceptions' file itself is always ignored.
|
||||
#
|
||||
# Blank lines and '#' comments in the 'install-exceptions' file are
|
||||
# ignored.
|
||||
#
|
||||
# ARGS:
|
||||
# -setupdll - Make a small additional CAB including Setup.dll.
|
||||
# This is to add Fennec to the system list of installed applications
|
||||
# available in Settings - System - Remove Programs.
|
||||
#
|
||||
# -s - Don't pass /compress to cabwiz (generate CAB compatible with Windows CE)
|
||||
#
|
||||
# -faststart - Add FastStart shortcut
|
||||
#
|
||||
# CABWIZ_PATH - If specified, will use this cabwiz.exe executable. Otherwise, will attempt
|
||||
# to find one using $VSINSTALLDIR.
|
||||
#
|
||||
# SOURCE_DIR - sub-directory which contains the target program
|
||||
# NOTE: It is assumed that the application name is SOURCE_DIR.exe
|
||||
# EXAMPLE: source_dir=fennec, there should be a fennec/fennec.exe application
|
||||
#
|
||||
# PROGRAM_NAME - Name of the program to place inside the INF file
|
||||
#
|
||||
# CAB_FINAL_NAME - actual final name for the produced CAB file
|
||||
#
|
||||
# EXAMPLE OF COMMAND LINE:
|
||||
# python make_wince_cab.py /c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/SmartDevices/SDK/SDKTools/cabwiz.exe dist/fennec Fennec fennec-0.11.en-US.wince-arm.cab
|
||||
#
|
||||
# NOTE: In our example, "fennec" is the directory [source_name]
|
||||
# "fennec.exe" is the application [$(source_name).exe], and
|
||||
# "Fennec" is the shortcut name [program_name]
|
||||
################################################################
|
||||
|
||||
import sys
|
||||
import os
|
||||
from os.path import join
|
||||
from subprocess import call, STDOUT
|
||||
import fnmatch
|
||||
import string
|
||||
import shutil
|
||||
|
||||
CompressFlag = "/compress"
|
||||
FaststartFlag = 0
|
||||
MakeSetupDllCab = 0
|
||||
|
||||
class FileEntry:
|
||||
def __init__(self, dirpath, dircount, filename, filecount, actual_filename):
|
||||
self.dirpath = dirpath
|
||||
self.dircount = dircount
|
||||
self.filename = filename
|
||||
self.filecount = filecount
|
||||
self.actual_filename = actual_filename
|
||||
|
||||
|
||||
class DirEntry:
|
||||
def __init__(self, dirpath, dircount, filecount):
|
||||
self.dirpath = dirpath
|
||||
self.dircount = dircount
|
||||
self.filecount = filecount
|
||||
|
||||
# Ignore detritus left lying around by editing tools.
|
||||
ignored_patterns = ['*~', '.#*', '#*#', '*.orig', '*.rej']
|
||||
|
||||
file_entry_count = 0
|
||||
file_entries = []
|
||||
|
||||
fcount = 0
|
||||
fnames = {}
|
||||
|
||||
directories = {}
|
||||
files_in_directory = []
|
||||
|
||||
# Return the contents of FILENAME, a 'install-exceptions' file, as
|
||||
# a dictionary whose keys are exactly the list of filenames, along
|
||||
# with the basename of FILENAME itself. If FILENAME does not exist,
|
||||
# return the empty dictionary.
|
||||
def read_exceptions(filename):
|
||||
exceptions = set()
|
||||
if os.path.exists(filename):
|
||||
f = file(filename)
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and line[0] != '#':
|
||||
exceptions.add(line)
|
||||
exceptions.add( os.path.basename(filename) )
|
||||
f.close()
|
||||
return exceptions
|
||||
|
||||
|
||||
# Sorts two items based first upon directory count (index of
|
||||
# directory in list of directories), then upon filename. A way of
|
||||
# getting a list sorted into directories, and then alphabetically by
|
||||
# filename within each directory.
|
||||
def sort_dircount_then_filename(item1, item2):
|
||||
# First Compare dirpaths
|
||||
if item1.dircount != item2.dircount:
|
||||
return cmp(item1.dircount, item2.dircount)
|
||||
|
||||
# Next compare filenames
|
||||
next_result = cmp(item1.filename, item2.filename)
|
||||
if next_result != 0:
|
||||
return next_result
|
||||
|
||||
# Lastly, compare filecounts
|
||||
return cmp(item1.filecount, item2.filecount)
|
||||
|
||||
|
||||
def handle_duplicate_filename(dirpath, filename, filecount):
|
||||
if filecount == 1:
|
||||
return filename
|
||||
file_parts = os.path.splitext(filename)
|
||||
new_filename = "%s_%d%s" % (file_parts[0], filecount, file_parts[1])
|
||||
old_relative_filename = join(dirpath, filename)
|
||||
new_relative_filename = join(dirpath, new_filename)
|
||||
shutil.copyfile(old_relative_filename, new_relative_filename)
|
||||
return new_filename
|
||||
|
||||
def add_new_entry(dirpath, dircount, filename, filecount):
|
||||
global file_entries
|
||||
global file_entry_count
|
||||
actual_filename = handle_duplicate_filename(dirpath, filename, filecount)
|
||||
file_entries.append( FileEntry(dirpath, dircount, filename, filecount, actual_filename) )
|
||||
file_entry_count += 1
|
||||
|
||||
|
||||
def walk_tree(start_dir, ignore):
|
||||
global fcount
|
||||
global fnames
|
||||
global directories
|
||||
global files_in_directory
|
||||
|
||||
dircount = 0;
|
||||
files_in_directory = [0]
|
||||
|
||||
for (dirpath, dirnames, filenames) in os.walk(start_dir):
|
||||
exceptions = read_exceptions(join(dirpath, 'install-exceptions'))
|
||||
|
||||
dircount += 1
|
||||
directories[dirpath] = DirEntry(dirpath, dircount, len(filenames))
|
||||
|
||||
if len(filenames) < 1:
|
||||
print "WARNING: No files in directory [%s]" % dirpath
|
||||
|
||||
for filename in filenames:
|
||||
if len(exceptions) > 0 and filename in exceptions:
|
||||
continue
|
||||
if any(fnmatch.fnmatch(filename, p) for p in ignore):
|
||||
continue
|
||||
filecount = 1
|
||||
if filename in fnames:
|
||||
filecount = fnames[filename] + 1
|
||||
fnames[filename] = filecount
|
||||
|
||||
add_new_entry(dirpath, dircount, filename, filecount)
|
||||
|
||||
|
||||
def output_inf_file_header(f, program_name):
|
||||
f.write("""; Duplicated Filenames ==> One of the two files
|
||||
; needs renaming before packaging up the CAB
|
||||
;
|
||||
; Technique: Rename the second directory's file to XXXX_1 prior to starting the CABWIZ,
|
||||
; then take care of the name in the File.xxxxx section
|
||||
|
||||
[Version]
|
||||
Signature = "$Windows NT$" ; required as-is
|
||||
Provider = "Mozilla" ; maximum of 30 characters, full app name will be \"<Provider> <AppName>\"
|
||||
CESignature = "$Windows CE$" ; required as-is
|
||||
|
||||
[CEStrings]
|
||||
AppName = "%s" ; maximum of 40 characters, full app name will be \"<Provider> <AppName>\"\n""" % program_name)
|
||||
|
||||
f.write("InstallDir = %CE1%\\%AppName% ; Program Files\Fennec\n\n")
|
||||
|
||||
|
||||
def output_sourcedisksnames_section(f, dirs):
|
||||
f.write("[SourceDisksNames] ; directory that holds the application's files\n")
|
||||
for dir in dirs:
|
||||
f.write("""%d = , "%s",,%s\n""" % (directories[dir].dircount, dir, dir))
|
||||
f.write(" \n")
|
||||
|
||||
|
||||
def output_sourcedisksfiles_section(f):
|
||||
f.write("[SourceDisksFiles] ; list of files to be included in .cab\n")
|
||||
for entry in sorted(file_entries, sort_dircount_then_filename):
|
||||
f.write("%s=%d\n" % (entry.actual_filename, entry.dircount))
|
||||
f.write("\n")
|
||||
|
||||
|
||||
def output_defaultinstall_section(f, dirs):
|
||||
copyfileslist = ""
|
||||
copyfilesrawlist=[]
|
||||
for dir in dirs:
|
||||
if directories[dir].filecount < 1:
|
||||
continue
|
||||
copyfilesrawlist.append( "Files.%s" % '.'.join( dir.split('\\') ) )
|
||||
prefix = ", "
|
||||
copyfileslist = ','.join(copyfilesrawlist)
|
||||
|
||||
f.write("""[DefaultInstall] ; operations to be completed during install
|
||||
CopyFiles = %s
|
||||
AddReg = RegData
|
||||
CEShortcuts = Shortcuts
|
||||
\n""" % copyfileslist)
|
||||
|
||||
|
||||
def output_destinationdirs_section(f, dirs):
|
||||
f.write("[DestinationDirs] ; default destination directories for each operation section\n")
|
||||
for dir in dirs:
|
||||
dir_split = dir.split('\\')
|
||||
mod_dir_string = '.'.join(dir_split)
|
||||
if len(dir_split) > 1:
|
||||
dir_minus_top_level = '\\'.join(dir_split[1:])
|
||||
else:
|
||||
dir_minus_top_level = ""
|
||||
if dir_minus_top_level:
|
||||
dir_minus_top_level = "\\%s" % dir_minus_top_level
|
||||
if directories[dir].filecount < 1:
|
||||
f.write(";Files.%s = 0, %%InstallDir%%%s ; NO FILES IN THIS DIRECTORY\n" % (mod_dir_string, dir_minus_top_level))
|
||||
else:
|
||||
f.write("Files.%s = 0, %%InstallDir%%%s\n" % (mod_dir_string, dir_minus_top_level))
|
||||
f.write("Shortcuts = 0, %CE11% ; \Windows\Start Menu\Programs\n\n")
|
||||
|
||||
|
||||
def output_directory_sections(f, dirs):
|
||||
for dir in dirs:
|
||||
if directories[dir].filecount < 1:
|
||||
f.write(";[Files.%s]\n;===NO FILES===\n" % '.'.join( dir.split('\\') ))
|
||||
else:
|
||||
f.write("[Files.%s]\n" % '.'.join( dir.split('\\') ))
|
||||
for entry in file_entries:
|
||||
if entry.dirpath == dir:
|
||||
f.write("\"%s\",%s\n" % (entry.filename, entry.actual_filename))
|
||||
f.write("\n")
|
||||
|
||||
|
||||
def output_registry_section(f):
|
||||
f.write("""[RegData] ; registry key list
|
||||
HKCU,Software\%AppName%,MajorVersion,0x00010001,1
|
||||
HKCU,Software\%AppName%,MinorVersion,0x00010001,0
|
||||
\n""")
|
||||
|
||||
|
||||
def output_shortcuts_section(f, app_name):
|
||||
f.write("[Shortcuts]\n")
|
||||
f.write("%%AppName%%,0,%s,%%CE11%%\n" % app_name)
|
||||
if FaststartFlag:
|
||||
f.write("%%AppName%%faststart,0,%sfaststart.exe,%%CE4%%\n" % os.path.splitext(app_name)[0]);
|
||||
|
||||
|
||||
def output_inf_file(program_name, app_name):
|
||||
global files_in_directory
|
||||
inf_name = "%s.inf" % program_name
|
||||
f = open(inf_name, 'w')
|
||||
output_inf_file_header(f, program_name)
|
||||
dirs = sorted(directories)
|
||||
output_sourcedisksnames_section(f, dirs)
|
||||
output_sourcedisksfiles_section(f)
|
||||
output_defaultinstall_section(f, dirs)
|
||||
output_destinationdirs_section(f, dirs)
|
||||
output_directory_sections(f, dirs)
|
||||
output_registry_section(f)
|
||||
output_shortcuts_section(f, app_name)
|
||||
f.close()
|
||||
|
||||
|
||||
|
||||
def output_setup_dll_inf_file(source_dir, program_name, app_name):
|
||||
inf_name = "%s.inf" % program_name
|
||||
f = open(inf_name, 'w')
|
||||
|
||||
f.write("""; Additional CAB to create Fennec entry in the installed programs list
|
||||
|
||||
[Version]
|
||||
Signature = "$Windows NT$" ; required as-is
|
||||
Provider = "Mozilla" ; maximum of 30 characters, full app name will be \"<Provider> <AppName>\"
|
||||
CESignature = "$Windows CE$" ; required as-is
|
||||
|
||||
[CEStrings]
|
||||
AppName = "%s" ; maximum of 40 characters, full app name will be \"<Provider> <AppName>\"\n""" % program_name)
|
||||
|
||||
f.write("InstallDir = %CE1%\\%AppName% ; Program Files\Fennec\n\n")
|
||||
|
||||
f.write("[SourceDisksNames] ; directory that holds the application's files\n")
|
||||
f.write('1 = , "%s",,%s\n\n' % (source_dir, source_dir))
|
||||
|
||||
f.write("[SourceDisksFiles] ; list of files to be included in .cab\n")
|
||||
f.write("Setup.dll = 1\n\n")
|
||||
|
||||
f.write("""[DefaultInstall] ; operations to be completed during install
|
||||
CopyFiles = Files.%s
|
||||
AddReg = RegData
|
||||
CESetupDLL = "Setup.dll"
|
||||
\n""" % program_name)
|
||||
|
||||
f.write("[DestinationDirs] ; default destination directories for each operation section\n")
|
||||
f.write("Files.%s = 0, %%InstallDir%%\n\n" % program_name)
|
||||
|
||||
f.write("""[Files.%s]
|
||||
;No files to copy
|
||||
|
||||
[RegData]
|
||||
;No registry entries
|
||||
""" % program_name)
|
||||
|
||||
f.close()
|
||||
|
||||
|
||||
def make_cab_file(cabwiz_path, program_name, cab_final_name):
|
||||
make_cab_command = "\"%s\" %s %s.inf" % (cabwiz_path, CompressFlag, program_name)
|
||||
print "INFORMATION: Executing command to make %s CAB file (only works on BASH)" % program_name
|
||||
print " [%s]" % make_cab_command
|
||||
sys.stdout.flush()
|
||||
|
||||
success = call([cabwiz_path, "%s.inf" % program_name, CompressFlag],
|
||||
stdout=open("NUL:","w"), stderr=STDOUT)
|
||||
|
||||
if not os.path.isfile("%s.CAB" % program_name):
|
||||
print """***************************************************************************
|
||||
ERROR: CAB FILE NOT CREATED.
|
||||
You can try running the command by hand:
|
||||
%s
|
||||
----
|
||||
NOTE: If you see an error like this:
|
||||
Error: File XXXXXXXXXX.inf contains DirIDs, which are not supported
|
||||
--
|
||||
this may mean that your PYTHON is outputting Windows files WITHOUT CR-LF
|
||||
line endings. Please verify that your INF file has CR-LF line endings.
|
||||
***************************************************************************""" % make_cab_command
|
||||
sys.exit(2)
|
||||
|
||||
print "INFORMATION: Executing command to move %s.CAB to %s" % (program_name, cab_final_name)
|
||||
sys.stdout.flush()
|
||||
shutil.move("%s.CAB" % program_name, cab_final_name)
|
||||
|
||||
|
||||
def purge_copied_files():
|
||||
for entry in file_entries:
|
||||
if entry.filename != entry.actual_filename:
|
||||
new_relative_filename = join(entry.dirpath, entry.actual_filename)
|
||||
os.remove(new_relative_filename)
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv
|
||||
if len(args) < 4 or len(args) > 7:
|
||||
print >> sys.stderr, "Usage: %s [-setupdll] [-s] [-faststart] [CABWIZ_PATH] SOURCE_DIR PROGRAM_NAME CAB_FINAL_NAME" % args[0]
|
||||
print >> sys.stderr, "Example: %s /c/Program\ Files/Microsoft\ Visual\ Studio\ 9.0/ fennec Fennec fennec-0.11.en-US.wince-arm.cab" % args[0]
|
||||
sys.exit(1)
|
||||
|
||||
args = args[1:]
|
||||
|
||||
if args[0] == "-setupdll":
|
||||
global MakeSetupDllCab
|
||||
MakeSetupDllCab = 1
|
||||
args = args[1:]
|
||||
|
||||
if args[0] == "-s":
|
||||
global CompressFlag
|
||||
CompressFlag = ""
|
||||
args = args[1:]
|
||||
|
||||
if args[0] == "-faststart":
|
||||
global FaststartFlag
|
||||
FaststartFlag = 1
|
||||
args = args[1:]
|
||||
|
||||
cabwiz_path = None
|
||||
if len(args) == 4:
|
||||
cabwiz_path = args[0]
|
||||
args = args[1:]
|
||||
else:
|
||||
if "VSINSTALLDIR" in os.environ:
|
||||
cabwiz_path = os.path.join(os.environ["VSINSTALLDIR"], "SmartDevices", "SDK", "SDKTools", "cabwiz.exe")
|
||||
|
||||
source_dir = args[0]
|
||||
program_name = args[1]
|
||||
app_name = "%s.exe" % source_dir
|
||||
cab_final_name = args[2]
|
||||
|
||||
if cabwiz_path is None or not os.path.isfile(cabwiz_path):
|
||||
print """***************************************************************************
|
||||
ERROR: CABWIZ_PATH is not a valid file, or cabwiz couldn't be found!
|
||||
EXITING...
|
||||
***************************************************************************"""
|
||||
sys.exit(2)
|
||||
|
||||
if MakeSetupDllCab:
|
||||
output_setup_dll_inf_file(source_dir, program_name, app_name)
|
||||
sys.stdout.flush()
|
||||
make_cab_file(cabwiz_path, program_name, cab_final_name)
|
||||
os.remove("%s/setup.dll" % source_dir)
|
||||
else:
|
||||
walk_tree(source_dir, ignored_patterns)
|
||||
sys.stdout.flush()
|
||||
output_inf_file(program_name, app_name)
|
||||
sys.stdout.flush()
|
||||
make_cab_file(cabwiz_path, program_name, cab_final_name)
|
||||
purge_copied_files()
|
||||
|
||||
|
||||
# run main if run directly
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,103 +0,0 @@
|
|||
# ***** 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 Mozilla core build scripts.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Brad Lassey <blassey@mozilla.com>
|
||||
#
|
||||
# Portions created by the Initial Developer are Copyright (C) 2008
|
||||
# the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# 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 *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
MODULE = shunt
|
||||
|
||||
TOPSRCDIR = $(topsrcdir)
|
||||
OBJDIR = $(DEPTH)
|
||||
|
||||
export NO_SHUNT = 1
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = mozce_shunt
|
||||
LIBRARY_NAME = mozce_shunt
|
||||
FORCE_SHARED_LIB= 1
|
||||
DIST_INSTALL = 1
|
||||
|
||||
EXPORTS_NAMESPACES = mozce_shunt
|
||||
EXPORTS_mozce_shunt = \
|
||||
include/windows.h \
|
||||
include/ymath.h \
|
||||
include/stdlib.h \
|
||||
include/direct.h \
|
||||
include/errno.h \
|
||||
include/fcntl.h \
|
||||
include/io.h \
|
||||
include/mbstring.h \
|
||||
include/environment.h \
|
||||
include/mozce_shunt.h \
|
||||
include/process.h \
|
||||
include/signal.h \
|
||||
$(NULL)
|
||||
|
||||
DIRS += include/sys
|
||||
|
||||
ifdef MOZ_MEMORY
|
||||
CFLAGS += -DMOZ_MEMORY
|
||||
CXXFLAGS += -DMOZ_MEMORY
|
||||
EXPORTS_mozce_shunt += $(topsrcdir)/memory/jemalloc/jemalloc.h
|
||||
|
||||
# We have to include the obj file directly, because we want to export
|
||||
# some of its symbols through our def file
|
||||
EXTRA_LIBS += $(OBJDIR)/memory/jemalloc/jemalloc.obj
|
||||
endif
|
||||
|
||||
DEFFILE = mozce_shunt.def
|
||||
|
||||
OS_LIBS = $(call EXPAND_LIBNAME, libcmt)
|
||||
|
||||
CPPSRCS = \
|
||||
shunt.cpp \
|
||||
environment.cpp \
|
||||
time.cpp \
|
||||
memory.cpp \
|
||||
$(NULL)
|
||||
|
||||
DEFINES += -DMOZCE_SHUNT_EXPORTS -DIN_SHUNT
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
mozce_shunt.def: mozce_shunt.def.in
|
||||
$(PYTHON) $(topsrcdir)/config/Preprocessor.py $(DEFINES) $(ACDEFINES) $^ > $@
|
||||
|
||||
.NOTPARALLEL:
|
||||
|
|
@ -1,336 +0,0 @@
|
|||
/* -*- Mode: C; c-basic-offset: 2; tab-width: 4; indent-tabs-mode: nil; -*- */
|
||||
/* ***** 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 MOZCE Lib.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Wolfe <wolfe@lobo.us>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
/* environment.h and environment.cpp are also included by app update */
|
||||
|
||||
// WINCE_SKIP_SHUNT_INCLUDE is used by app update to prevent including of
|
||||
// mozce_shunt.h when it includes environment.cpp
|
||||
#ifndef WINCE_SKIP_SHUNT_INCLUDE
|
||||
#include "include/mozce_shunt.h"
|
||||
#endif
|
||||
#include "include/environment.h"
|
||||
#include "time_conversions.h"
|
||||
#include <stdlib.h>
|
||||
#include "Windows.h"
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Environment Variable Stuff
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct env_entry env_entry;
|
||||
|
||||
#define ENV_IS_STATIC 0
|
||||
#define ENV_FREE_KEY 1
|
||||
#define ENV_FREE_BOTH 2
|
||||
|
||||
struct env_entry {
|
||||
char *key;
|
||||
char *value;
|
||||
int flag;
|
||||
env_entry *next;
|
||||
};
|
||||
|
||||
static bool env_ready = false;
|
||||
static env_entry *env_head = NULL;
|
||||
|
||||
static env_entry *
|
||||
env_find_key(const char *key)
|
||||
{
|
||||
env_entry *entry = env_head;
|
||||
while (entry) {
|
||||
if (strcmp(entry->key, key) == 0)
|
||||
return entry;
|
||||
|
||||
entry = entry->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
putenv_internal(char *key, char *value, int flag)
|
||||
{
|
||||
env_entry *entry = env_find_key(key);
|
||||
if (entry) {
|
||||
// get rid of old key/value; if flag is set, then
|
||||
// they're static strings and we don't touch them
|
||||
if (entry->flag == ENV_FREE_BOTH)
|
||||
free (entry->value);
|
||||
if (entry->flag == ENV_FREE_KEY)
|
||||
free (entry->key);
|
||||
} else {
|
||||
entry = new env_entry;
|
||||
entry->next = env_head;
|
||||
env_head = entry;
|
||||
}
|
||||
|
||||
entry->key = key;
|
||||
entry->value = value;
|
||||
entry->flag = flag;
|
||||
}
|
||||
|
||||
static void
|
||||
init_initial_env() {
|
||||
env_ready = true;
|
||||
|
||||
putenv_internal("NSS_DEFAULT_DB_TYPE", "sql", ENV_IS_STATIC);
|
||||
putenv_internal("NSPR_FD_CACHE_SIZE_LOW", "10", ENV_IS_STATIC);
|
||||
putenv_internal("NSPR_FD_CACHE_SIZE_HIGH", "30", ENV_IS_STATIC);
|
||||
putenv_internal("XRE_PROFILE_NAME", "default", ENV_IS_STATIC);
|
||||
putenv_internal("tmp", "/Temp", ENV_IS_STATIC);
|
||||
}
|
||||
|
||||
void
|
||||
putenv_copy(const char *k, const char *v)
|
||||
{
|
||||
if (!env_ready)
|
||||
init_initial_env();
|
||||
|
||||
putenv_internal(strdup(k), strdup(v), ENV_FREE_BOTH);
|
||||
}
|
||||
|
||||
int
|
||||
putenv(const char *envstr)
|
||||
{
|
||||
if (!env_ready)
|
||||
init_initial_env();
|
||||
|
||||
char *key = strdup(envstr);
|
||||
char *value = strchr(key, '=');
|
||||
if (!value) {
|
||||
free(key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*value++ = '\0';
|
||||
|
||||
putenv_internal(key, value, ENV_FREE_KEY);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
getenv(const char* name)
|
||||
{
|
||||
if (!env_ready)
|
||||
init_initial_env();
|
||||
|
||||
env_entry *entry = env_find_key(name);
|
||||
if (entry && entry->value[0] != 0) {
|
||||
return entry->value;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char
|
||||
GetEnvironmentVariableW(const WCHAR* lpName,
|
||||
WCHAR* lpBuffer,
|
||||
unsigned long nSize)
|
||||
{
|
||||
char key[256];
|
||||
int rv = WideCharToMultiByte(CP_ACP, 0, lpName, -1, key, 255, NULL, NULL);
|
||||
if (rv <= 0)
|
||||
return 0;
|
||||
|
||||
key[rv] = 0;
|
||||
|
||||
char* val = getenv(key);
|
||||
|
||||
if (!val)
|
||||
return 0;
|
||||
|
||||
// strlen(val)+1, let MBTWC convert the nul byte for us
|
||||
return MultiByteToWideChar(CP_ACP, 0, val, strlen(val)+1, lpBuffer, nSize);
|
||||
}
|
||||
|
||||
char
|
||||
SetEnvironmentVariableW(const WCHAR* name,
|
||||
const WCHAR* value)
|
||||
{
|
||||
char key[256];
|
||||
char val[256];
|
||||
int rv;
|
||||
|
||||
rv = WideCharToMultiByte(CP_ACP, 0, name, -1, key, 255, NULL, NULL);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
|
||||
key[rv] = 0;
|
||||
|
||||
rv = WideCharToMultiByte(CP_ACP, 0, value, -1, val, 255, NULL, NULL);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
|
||||
val[rv] = 0;
|
||||
|
||||
putenv_copy(key, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned int ExpandEnvironmentStringsW(const WCHAR* lpSrc,
|
||||
WCHAR* lpDst,
|
||||
unsigned int nSize)
|
||||
{
|
||||
if ( NULL == lpDst )
|
||||
return 0;
|
||||
|
||||
unsigned int size = 0;
|
||||
unsigned int index = 0;
|
||||
unsigned int origLen = wcslen(lpSrc);
|
||||
|
||||
const WCHAR *pIn = lpSrc;
|
||||
WCHAR *pOut = lpDst;
|
||||
|
||||
while ( index < origLen ) {
|
||||
|
||||
if (*pIn != L'%') { // Regular char, copy over
|
||||
if ( size++ < nSize ) *pOut = *pIn, pOut++;
|
||||
index++, pIn++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Have a starting '%' - look for matching '%'
|
||||
int envlen = 0;
|
||||
const WCHAR *pTmp = pIn + 1;
|
||||
while ( *pTmp != L'%' && *pTmp != L' ' ) {
|
||||
envlen++, pTmp++;
|
||||
if ( origLen < index + envlen ) { // Ran past end of original
|
||||
while ( envlen-- ) {
|
||||
if ( size++ < nSize ) *pOut = *pIn, pOut++;
|
||||
index++, pIn++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( *pTmp == L' ' ) { // Need to append through space
|
||||
while ( envlen-- ) {
|
||||
if ( size++ < nSize ) *pOut = *pIn, pOut++;
|
||||
index++, pIn++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
pIn++; // Move past original %
|
||||
if ( 0 == envlen ) { // Encountered a "%%" - mapping to "%"
|
||||
if ( size++ < nSize ) *pOut = *pIn, pOut++;
|
||||
index += 2, pIn++;
|
||||
} else {
|
||||
// Encountered a "%something%" - mapping "something"
|
||||
char key[256];
|
||||
int k = WideCharToMultiByte(CP_ACP, 0, pIn, envlen, key, 255, NULL, NULL);
|
||||
key[k] = 0;
|
||||
char *pC = getenv(key);
|
||||
if ( NULL != pC ) {
|
||||
int n = MultiByteToWideChar( CP_ACP, 0, pC, -1, pOut, nSize - size );
|
||||
if ( n > 0 ) {
|
||||
size += n - 1; // Account for trailing zero
|
||||
pOut += n - 1;
|
||||
}
|
||||
}
|
||||
index += envlen + 2;
|
||||
pIn = ++pTmp;
|
||||
}
|
||||
}
|
||||
|
||||
if ( size < nSize ) lpDst[size] = 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
WCHAR *
|
||||
mozce_GetEnvironmentCL()
|
||||
{
|
||||
env_entry *entry = env_head;
|
||||
int len = 0;
|
||||
while (entry) {
|
||||
if (entry->flag == ENV_IS_STATIC) {
|
||||
entry = entry->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
len += strlen(entry->key);
|
||||
len += strlen(entry->value);
|
||||
|
||||
// for each env var, 11 chars of " --environ:", 3 chars of '"="', and a null at the end
|
||||
len += 11 + 3 + 1;
|
||||
|
||||
entry = entry->next;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
return wcsdup(L"");
|
||||
}
|
||||
|
||||
wchar_t *env = (wchar_t*) malloc(sizeof(wchar_t) * (len+1));
|
||||
if (!env)
|
||||
return NULL;
|
||||
|
||||
entry = env_head;
|
||||
|
||||
int pos = 0;
|
||||
while (entry) {
|
||||
if (entry->flag == ENV_IS_STATIC) {
|
||||
entry = entry->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strchr(entry->key, '"') || strchr(entry->value, '"')) {
|
||||
// argh, we don't have a good way of encoding the ", so let's just
|
||||
// ignore this var for now
|
||||
RETAILMSG(1, (L"Skipping environment variable with quote marks in key or value! %S -> %s\r\n", entry->key, entry->value));
|
||||
entry = entry->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
wcscpy (env+pos, L" --environ:\"");
|
||||
pos += 12;
|
||||
pos += MultiByteToWideChar(CP_ACP, 0, entry->key, strlen(entry->key), env+pos, len-pos);
|
||||
env[pos++] = '=';
|
||||
pos += MultiByteToWideChar(CP_ACP, 0, entry->value, strlen(entry->value), env+pos, len-pos);
|
||||
env[pos++] = '\"';
|
||||
|
||||
entry = entry->next;
|
||||
}
|
||||
|
||||
env[pos] = '\0';
|
||||
|
||||
return env;
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* Input/output error */
|
||||
#define ENXIO 6 /* Device not configured */
|
||||
#define E2BIG 7 /* Argument list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file descriptor */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EDEADLK 11 /* Resource deadlock avoided */
|
||||
#define ENOMEM 12 /* Cannot allocate memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#define EBUSY 16 /* Device busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* Operation not supported by device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* Too many open files in system */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Inappropriate ioctl for device */
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
#define EDOM 33 /* Numerical argument out of domain */
|
||||
#define ERANGE 34 /* Result too large */
|
||||
#define EAGAIN 35 /* Resource temporarily unavailable */
|
||||
#define ENOTEMPTY 39 /* Directory not empty */
|
||||
|
||||
|
|
@ -1,240 +0,0 @@
|
|||
/* ***** 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 MOZCE Lib.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Wolfe <wolfe@lobo.us>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef MOZCE_SHUNT_H
|
||||
#define MOZCE_SHUNT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _WCHAR_T_DEFINED
|
||||
typedef unsigned short wchar_t;
|
||||
#define _WCHAR_T_DEFINED
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} //extern "C"
|
||||
#endif
|
||||
|
||||
#include "environment.h"
|
||||
|
||||
#ifdef MOZ_MEMORY
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
// define these so we don't include <new> from either VC or
|
||||
// the CE5 SDK
|
||||
#define _NEW_
|
||||
#define _INC_NEW
|
||||
|
||||
#ifndef __NOTHROW_T_DEFINED
|
||||
#define __NOTHROW_T_DEFINED
|
||||
namespace std {
|
||||
struct nothrow_t {};
|
||||
extern const nothrow_t nothrow;
|
||||
struct bad_alloc {};
|
||||
};
|
||||
#endif
|
||||
|
||||
// grab malloc and free prototypes
|
||||
#include "jemalloc.h"
|
||||
|
||||
// mozalloc.h defines "normal" infallible operator new, but not
|
||||
// std::nothrow operator new, so we define that below. This is inline
|
||||
// and exported from the shunt.
|
||||
inline void *operator new(size_t size, const std::nothrow_t&) throw() {
|
||||
return malloc(size);
|
||||
}
|
||||
inline void *operator new[](size_t size, const std::nothrow_t&) throw() {
|
||||
return malloc(size);
|
||||
}
|
||||
inline void operator delete(void* ptr, const std::nothrow_t&) throw() {
|
||||
free(ptr);
|
||||
}
|
||||
inline void operator delete[](void* ptr, const std::nothrow_t&) throw() {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
// Placement new. Just inline, not exported (which doesn't work for
|
||||
// some reason, but it's a noop in any case)
|
||||
inline void *operator new(size_t, void *p) {
|
||||
return p;
|
||||
}
|
||||
inline void *operator new[](size_t, void *p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifndef IN_SHUNT
|
||||
// for Gecko, include infallible mozalloc allocators. elsewhere, define
|
||||
// operator new() normally.
|
||||
// NB: this include guard needs to be kept in sync with the one in nscore.h
|
||||
#if defined(_MOZILLA_CONFIG_H_) && !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
|
||||
# include "mozilla/mozalloc.h"
|
||||
#else
|
||||
|
||||
inline void* operator new(size_t size) throw() {
|
||||
return malloc(size);
|
||||
}
|
||||
inline void* operator new[](size_t size) throw() {
|
||||
return malloc(size);
|
||||
}
|
||||
inline void operator delete(void* ptr) throw() {
|
||||
free(ptr);
|
||||
}
|
||||
inline void operator delete[](void* ptr) throw() {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
#endif // if defined(_MOZILLA_CONFIG_H_)
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#undef _strdup
|
||||
#undef strdup
|
||||
#undef _strndup
|
||||
#undef strndup
|
||||
#undef _wcsdup
|
||||
#undef wcsdup
|
||||
#undef _wcsndup
|
||||
#undef wcsndup
|
||||
|
||||
char * __cdecl
|
||||
_strdup(const char*);
|
||||
|
||||
wchar_t * __cdecl
|
||||
_wcsdup(const wchar_t *);
|
||||
|
||||
char * __cdecl
|
||||
_strndup(const char *, unsigned int);
|
||||
|
||||
wchar_t * __cdecl
|
||||
_wcsndup(const wchar_t *, unsigned int);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} //extern "C"
|
||||
#endif
|
||||
|
||||
#endif // ifdef MOZ_MEMORY
|
||||
|
||||
#define strdup _strdup
|
||||
#define strndup _strndup
|
||||
#define wcsdup _wcsdup
|
||||
#define wcsndup _wcsndup
|
||||
|
||||
|
||||
#define strcmpi _stricmp
|
||||
#define stricmp _stricmp
|
||||
#define wgetcwd _wgetcwd
|
||||
#define vsnprintf _vsnprintf
|
||||
|
||||
#define SHGetSpecialFolderPathW SHGetSpecialFolderPath
|
||||
#define SHGetPathFromIDListW SHGetPathFromIDList
|
||||
#define FONTENUMPROCW FONTENUMPROC
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* errno and family */
|
||||
extern int errno;
|
||||
char* strerror(int);
|
||||
|
||||
/* abort */
|
||||
void abort(void);
|
||||
|
||||
/* Environment stuff */
|
||||
char* getenv(const char* inName);
|
||||
int putenv(const char *a);
|
||||
char SetEnvironmentVariableW(const wchar_t * name, const wchar_t * value );
|
||||
char GetEnvironmentVariableW(const wchar_t * lpName, wchar_t* lpBuffer, unsigned long nSize);
|
||||
|
||||
unsigned int ExpandEnvironmentStringsW(const wchar_t* lpSrc,
|
||||
wchar_t* lpDst,
|
||||
unsigned int nSize);
|
||||
|
||||
/* File system stuff */
|
||||
wchar_t * _wgetcwd(wchar_t* dir, unsigned long size);
|
||||
wchar_t *_wfullpath(wchar_t *absPath, const wchar_t *relPath, unsigned long maxLength );
|
||||
int _unlink(const char *filename );
|
||||
int _wchdir(const wchar_t* path);
|
||||
|
||||
/* The time stuff should be defined here, but it can't be because it
|
||||
is already defined in time.h.
|
||||
|
||||
size_t strftime(char *, size_t, const char *, const struct tm *)
|
||||
struct tm* localtime(const time_t* inTimeT)
|
||||
struct tm* mozce_gmtime_r(const time_t* inTimeT, struct tm* outRetval)
|
||||
struct tm* gmtime(const time_t* inTimeT)
|
||||
time_t mktime(struct tm* inTM)
|
||||
time_t time(time_t *)
|
||||
clock_t clock()
|
||||
|
||||
*/
|
||||
|
||||
struct tm;
|
||||
|
||||
#ifndef _TIME_T_DEFINED
|
||||
typedef long time_t;
|
||||
#define _TIME_T_DEFINED
|
||||
#endif
|
||||
|
||||
struct tm* gmtime_r(const time_t* inTimeT, struct tm* outRetval);
|
||||
struct tm* localtime_r(const time_t* inTimeT, struct tm* outRetval);
|
||||
|
||||
/* Locale Stuff */
|
||||
|
||||
/* The locale stuff should be defined here, but it can't be because it
|
||||
is already defined in locale.h.
|
||||
|
||||
struct lconv * localeconv(void)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
wchar_t* mozce_GetEnvironmentCL();
|
||||
|
||||
/* square root of 1/2, missing from math.h */
|
||||
#define M_SQRT1_2 0.707106781186547524401
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif //MOZCE_SHUNT_H
|
|
@ -1,3 +0,0 @@
|
|||
|
||||
#define _beginthreadex(security, stack_size, start_proc, arg, flags, pid) \
|
||||
CreateThread(security, stack_size ? stack_size : 65536L,(LPTHREAD_START_ROUTINE) start_proc, arg, flags | STACK_SIZE_PARAM_IS_A_RESERVATION, pid)
|
|
@ -1,88 +0,0 @@
|
|||
/* ***** 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 MOZCE Lib.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Brad Lassey <blassey@mozilla.com>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
|
||||
#ifndef MOZCE_STDLIB_H
|
||||
#define MOZCE_STDLIB_H
|
||||
#ifdef MOZ_MEMORY
|
||||
|
||||
#undef strdup
|
||||
#undef _strdup
|
||||
#undef wcsdup
|
||||
#undef _wcsdup
|
||||
#undef strndup
|
||||
#undef _strndup
|
||||
#undef wcsndup
|
||||
#undef _wcsndup
|
||||
|
||||
#define free orig_free
|
||||
#define malloc orig_malloc
|
||||
#define calloc orig_calloc
|
||||
#define realloc orig_realloc
|
||||
#define _wcsdup orig_wcsdup
|
||||
#define _strdup orig_strup
|
||||
|
||||
#endif
|
||||
|
||||
#include "@WINCE_SDK_DIR@/Include/Armv4i/stdlib.h"
|
||||
|
||||
#ifdef MOZ_MEMORY
|
||||
|
||||
#undef free
|
||||
#undef malloc
|
||||
#undef calloc
|
||||
#undef realloc
|
||||
|
||||
#undef strdup
|
||||
#undef _strdup
|
||||
#undef wcsdup
|
||||
#undef _wcsdup
|
||||
#undef strndup
|
||||
#undef _strndup
|
||||
#undef wcsndup
|
||||
#undef _wcsndup
|
||||
|
||||
#define strdup _strdup
|
||||
#define strndup _strndup
|
||||
#define wcsdup _wcsdup
|
||||
#define wcsndup _wcsndup
|
||||
|
||||
/* now include jemalloc.h to get the real malloc, free, etc. */
|
||||
#include "jemalloc.h"
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,49 +0,0 @@
|
|||
# ***** 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 Mozilla core build scripts.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Brad Lassey <blassey@mozilla.com>
|
||||
#
|
||||
# Portions created by the Initial Developer are Copyright (C) 2008
|
||||
# the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# 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 *****
|
||||
|
||||
DEPTH = ../../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
export:: $(srcdir)/stat.h $(srcdir)/types.h
|
||||
$(INSTALL) $^ $(DIST)/include/mozce_shunt/sys
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/* -*- Mode: C; c-basic-offset: 2; tab-width: 4; indent-tabs-mode: nil; -*- */
|
||||
/* ***** 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 MOZCE Lib.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Wolfe <wolfe@lobo.us>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#include "include/mozce_shunt.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef MOZ_MEMORY
|
||||
|
||||
// declare the nothrow object
|
||||
const std::nothrow_t std::nothrow;
|
||||
|
||||
char*
|
||||
_strndup(const char *src, size_t len) {
|
||||
char* dst = (char*)malloc(len + 1);
|
||||
if(dst)
|
||||
strncpy(dst, src, len + 1);
|
||||
return dst;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
_strdup(const char *src) {
|
||||
size_t len = strlen(src);
|
||||
return _strndup(src, len );
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
_wcsndup(const wchar_t *src, size_t len) {
|
||||
wchar_t* dst = (wchar_t*)malloc(sizeof(wchar_t) * (len + 1));
|
||||
if(dst)
|
||||
wcsncpy(dst, src, len + 1);
|
||||
return dst;
|
||||
}
|
||||
|
||||
wchar_t *
|
||||
_wcsdup(const wchar_t *src) {
|
||||
size_t len = wcslen(src);
|
||||
return _wcsndup(src, len);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
LIBRARY mozce_shunt.dll
|
||||
EXPORTS
|
||||
ExpandEnvironmentStringsW
|
||||
GetEnvironmentVariableW
|
||||
SetEnvironmentVariableW
|
||||
_unlink
|
||||
_wfullpath
|
||||
_wgetcwd
|
||||
_wchdir
|
||||
abort
|
||||
clock
|
||||
errno
|
||||
gmtime
|
||||
gmtime_r
|
||||
localeconv
|
||||
localtime
|
||||
localtime_r
|
||||
mktime
|
||||
mozce_GetEnvironmentCL
|
||||
putenv
|
||||
getenv
|
||||
strerror
|
||||
strftime
|
||||
time
|
||||
|
||||
#ifdef MOZ_MEMORY
|
||||
;; std::nothrow object
|
||||
?nothrow@std@@3Unothrow_t@1@B
|
||||
;; operator new
|
||||
??2@YAPAXI@Z
|
||||
;; operator new nothrow
|
||||
??2@YAPAXIABUnothrow_t@std@@@Z
|
||||
;; operator delete
|
||||
??3@YAXPAX@Z
|
||||
;; operator new[]
|
||||
??_U@YAPAXI@Z
|
||||
;; operator new[] nothrow
|
||||
??_U@YAPAXIABUnothrow_t@std@@@Z
|
||||
;; operator delete[]
|
||||
??_V@YAXPAX@Z
|
||||
malloc
|
||||
valloc
|
||||
calloc
|
||||
realloc
|
||||
free
|
||||
posix_memalign
|
||||
memalign
|
||||
malloc_usable_size
|
||||
jemalloc_stats
|
||||
_strdup
|
||||
_wcsdup
|
||||
_strndup
|
||||
_wcsndup
|
||||
#endif
|
|
@ -1,271 +0,0 @@
|
|||
/* -*- Mode: C; c-basic-offset: 2; tab-width: 4; indent-tabs-mode: nil; -*- */
|
||||
/* ***** 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 MOZCE Lib.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Wolfe <wolfe@lobo.us>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
|
||||
#include "include/mozce_shunt.h"
|
||||
#include "time_conversions.h"
|
||||
#include <stdlib.h>
|
||||
#include "Windows.h"
|
||||
|
||||
// from environment.cpp
|
||||
void putenv_copy(const char *k, const char *v);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// special folder stuff
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct MOZCE_SHUNT_SPECIAL_FOLDER_INFO
|
||||
{
|
||||
int nFolder;
|
||||
char *folderEnvName;
|
||||
} MozceShuntSpecialFolderInfo;
|
||||
|
||||
// TAKEN DIRECTLY FROM MICROSOFT SHELLAPI.H HEADER FILE
|
||||
// supported SHGetSpecialFolderPath nFolder ids
|
||||
#define CSIDL_DESKTOP 0x0000
|
||||
#define CSIDL_PROGRAMS 0x0002 // \Windows\Start Menu\Programs
|
||||
#define CSIDL_PERSONAL 0x0005
|
||||
#define CSIDL_WINDOWS 0x0024 // \Windows
|
||||
#define CSIDL_PROGRAM_FILES 0x0026 // \Program Files
|
||||
|
||||
#define CSIDL_APPDATA 0x001A // NOT IN SHELLAPI.H header file
|
||||
#define CSIDL_PROFILE 0x0028 // NOT IN SHELLAPI.H header file
|
||||
|
||||
MozceShuntSpecialFolderInfo mozceSpecialFoldersToEnvVars[] = {
|
||||
{ CSIDL_APPDATA, "APPDATA" },
|
||||
{ CSIDL_PROGRAM_FILES, "ProgramFiles" },
|
||||
{ CSIDL_WINDOWS, "windir" },
|
||||
|
||||
// { CSIDL_PROFILE, "HOMEPATH" }, // No return on WinMobile 6 Pro
|
||||
// { CSIDL_PROFILE, "USERPROFILE" }, // No return on WinMobile 6 Pro
|
||||
// { int, "ALLUSERSPROFILE" }, // Only one profile on WinCE
|
||||
// { int, "CommonProgramFiles" },
|
||||
// { int, "COMPUTERNAME" },
|
||||
// { int, "HOMEDRIVE" },
|
||||
// { int, "SystemDrive" },
|
||||
// { int, "SystemRoot" },
|
||||
// { int, "TEMP" },
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static void InitializeSpecialFolderEnvVars()
|
||||
{
|
||||
MozceShuntSpecialFolderInfo *p = mozceSpecialFoldersToEnvVars;
|
||||
while ( p && p->nFolder && p->folderEnvName ) {
|
||||
WCHAR wPath[MAX_PATH];
|
||||
char cPath[MAX_PATH];
|
||||
if ( SHGetSpecialFolderPath(NULL, wPath, p->nFolder, FALSE) )
|
||||
if ( 0 != WideCharToMultiByte(CP_ACP, 0, wPath, -1, cPath, MAX_PATH, 0, 0) )
|
||||
putenv_copy(p->folderEnvName, cPath);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// errno
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
char* strerror(int inErrno)
|
||||
{
|
||||
return "Unknown Error";
|
||||
}
|
||||
|
||||
int errno = 0;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// File System Stuff
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
wchar_t * _wgetcwd(wchar_t * dir, unsigned long size)
|
||||
{
|
||||
wchar_t tmp[MAX_PATH] = {0};
|
||||
GetEnvironmentVariableW(L"CWD", tmp, size);
|
||||
if (tmp && tmp[0]) {
|
||||
if (wcslen(tmp) > size)
|
||||
return 0;
|
||||
if (!dir) {
|
||||
dir = (wchar_t*)malloc(sizeof(wchar_t) * (wcslen(tmp) + 2));
|
||||
if (!dir)
|
||||
return 0;
|
||||
}
|
||||
wcscpy(dir, tmp);
|
||||
} else {
|
||||
unsigned long i;
|
||||
if (!dir) {
|
||||
dir = (wchar_t*)malloc(sizeof(wchar_t) * (MAX_PATH + 1));
|
||||
if (!dir)
|
||||
return 0;
|
||||
}
|
||||
if (!GetModuleFileNameW(GetModuleHandle (NULL), dir, MAX_PATH))
|
||||
return 0;
|
||||
for (i = wcslen(dir); i && dir[i] != '\\'; i--) {}
|
||||
dir[i + 1] = '\0';
|
||||
SetEnvironmentVariableW(L"CWD", dir);
|
||||
}
|
||||
size_t len = wcslen(dir);
|
||||
if (dir[len - 1] != '\\' && (len + 2) < size) {
|
||||
dir[len] = '\\';
|
||||
dir[len + 1] = '\0';
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
wchar_t *_wfullpath( wchar_t *absPath, const wchar_t *relPath, unsigned long maxLength )
|
||||
{
|
||||
if(absPath == NULL){
|
||||
absPath = (wchar_t *)malloc(maxLength*sizeof(wchar_t));
|
||||
}
|
||||
wchar_t cwd[MAX_PATH];
|
||||
if (NULL == _wgetcwd( cwd, MAX_PATH))
|
||||
return NULL;
|
||||
|
||||
unsigned long len = wcslen(cwd);
|
||||
if(!(cwd[len-1] == TCHAR('/') || cwd[len-1] == TCHAR('\\'))&& len< maxLength){
|
||||
cwd[len] = TCHAR('\\');
|
||||
cwd[++len] = TCHAR('\0');
|
||||
}
|
||||
if(len+wcslen(relPath) < maxLength){
|
||||
#if (_WIN32_WCE > 300)
|
||||
if ( 0 < CeGetCanonicalPathName(relPath[0] == L'\\'? relPath :
|
||||
wcscat(cwd,relPath),
|
||||
absPath, maxLength, 0))
|
||||
return absPath;
|
||||
#else
|
||||
#error Need CeGetCanonicalPathName to build.
|
||||
// NO ACTUAL CeGetCanonicalPathName function in earlier versions of WinCE
|
||||
#endif
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int _wchdir(const WCHAR* path) {
|
||||
return SetEnvironmentVariableW(L"CWD", path);
|
||||
}
|
||||
|
||||
int _unlink(const char *filename)
|
||||
{
|
||||
wchar_t wname[MAX_PATH];
|
||||
|
||||
MultiByteToWideChar(CP_ACP,
|
||||
0,
|
||||
filename,
|
||||
strlen(filename)+1,
|
||||
wname,
|
||||
MAX_PATH );
|
||||
return DeleteFileW(wname)?0:-1;
|
||||
}
|
||||
|
||||
void abort(void)
|
||||
{
|
||||
#if defined(DEBUG)
|
||||
DebugBreak();
|
||||
#endif
|
||||
TerminateProcess((HANDLE) GetCurrentProcessId(), 3);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Locale Stuff
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
#define localeconv __not_supported_on_device_localeconv
|
||||
#include <locale.h>
|
||||
#undef localeconv
|
||||
|
||||
extern "C" {
|
||||
struct lconv * localeconv(void);
|
||||
}
|
||||
|
||||
static struct lconv s_locale_conv =
|
||||
{
|
||||
".", /* decimal_point */
|
||||
",", /* thousands_sep */
|
||||
"333", /* grouping */
|
||||
"$", /* int_curr_symbol */
|
||||
"$", /* currency_symbol */
|
||||
"", /* mon_decimal_point */
|
||||
"", /* mon_thousands_sep */
|
||||
"", /* mon_grouping */
|
||||
"+", /* positive_sign */
|
||||
"-", /* negative_sign */
|
||||
'2', /* int_frac_digits */
|
||||
'2', /* frac_digits */
|
||||
1, /* p_cs_precedes */
|
||||
1, /* p_sep_by_space */
|
||||
1, /* n_cs_precedes */
|
||||
1, /* n_sep_by_space */
|
||||
1, /* p_sign_posn */
|
||||
1, /* n_sign_posn */
|
||||
};
|
||||
|
||||
struct lconv * localeconv(void)
|
||||
{
|
||||
return &s_locale_conv;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// DllMain
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
|
||||
{
|
||||
// Perform actions based on the reason for calling.
|
||||
switch( fdwReason )
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
// Initialize once for each new process.
|
||||
// Return FALSE to fail DLL load.
|
||||
InitializeSpecialFolderEnvVars();
|
||||
break;
|
||||
|
||||
case DLL_THREAD_ATTACH:
|
||||
// Do thread-specific initialization.
|
||||
break;
|
||||
|
||||
case DLL_THREAD_DETACH:
|
||||
// Do thread-specific cleanup.
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
// Perform any necessary cleanup.
|
||||
break;
|
||||
}
|
||||
return TRUE; // Successful DLL_PROCESS_ATTACH.
|
||||
}
|
|
@ -1,229 +0,0 @@
|
|||
/* -*- Mode: C; c-basic-offset: 2; tab-width: 4; indent-tabs-mode: nil; -*- */
|
||||
/* ***** 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 MOZCE Lib.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Doug Turner <dougt@meer.net>.
|
||||
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* John Wolfe <wolfe@lobo.us>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
|
||||
#include "include/mozce_shunt.h"
|
||||
#include "time_conversions.h"
|
||||
#include <stdlib.h>
|
||||
#include <Windows.h>
|
||||
#include <altcecrt.h>
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Time Stuff
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
// This is the kind of crap that makes me hate microsoft. defined in their system headers, but not implemented anywhere.
|
||||
#define strftime __not_supported_on_device_strftime
|
||||
#define localtime __not_supported_on_device_localtime
|
||||
#define mktime __not_supported_on_device_mktime
|
||||
#define gmtime __not_supported_on_device_gmtime
|
||||
#define time __not_supported_on_device_time
|
||||
#define clock __not_supported_on_device_clock
|
||||
#include <time.h>
|
||||
#undef strftime
|
||||
#undef localtime
|
||||
#undef mktime
|
||||
#undef gmtime
|
||||
#undef time
|
||||
#undef clock
|
||||
|
||||
extern "C" {
|
||||
size_t strftime(char *, size_t, const char *, const struct tm *);
|
||||
struct tm* localtime(const time_t* inTimeT);
|
||||
time_t mktime(struct tm* inTM);
|
||||
struct tm* gmtime(const time_t* inTimeT);
|
||||
time_t time(time_t *);
|
||||
clock_t clock();
|
||||
}
|
||||
|
||||
static const int sDaysOfYear[12] = {
|
||||
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
|
||||
};
|
||||
static struct tm tmStorage;
|
||||
|
||||
size_t strftime(char *out, size_t maxsize, const char *pat, const struct tm *time)
|
||||
{
|
||||
size_t ret = 0;
|
||||
size_t wpatlen = MultiByteToWideChar(CP_ACP, 0, pat, -1, 0, 0);
|
||||
if (wpatlen) {
|
||||
wchar_t* wpat = (wchar_t*)calloc(wpatlen, sizeof(wchar_t));
|
||||
if (wpat) {
|
||||
wchar_t* tmpBuf = (wchar_t*)calloc(maxsize, sizeof(wchar_t));
|
||||
if (tmpBuf) {
|
||||
if (MultiByteToWideChar(CP_ACP, 0, pat, -1, wpat, wpatlen)) {
|
||||
if (wcsftime(tmpBuf, maxsize, wpat, time))
|
||||
ret = ::WideCharToMultiByte(CP_ACP, 0, tmpBuf, -1, out, maxsize, 0, 0);
|
||||
}
|
||||
free(tmpBuf);
|
||||
}
|
||||
free(wpat);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct tm* gmtime_r(const time_t* inTimeT, struct tm* outRetval)
|
||||
{
|
||||
struct tm* retval = NULL;
|
||||
|
||||
if(NULL != inTimeT) {
|
||||
SYSTEMTIME winGMTime;
|
||||
|
||||
time_t_2_SYSTEMTIME(winGMTime, *inTimeT);
|
||||
|
||||
outRetval->tm_sec = (int)winGMTime.wSecond;
|
||||
outRetval->tm_min = (int)winGMTime.wMinute;
|
||||
outRetval->tm_hour = (int)winGMTime.wHour;
|
||||
outRetval->tm_mday = (int)winGMTime.wDay;
|
||||
outRetval->tm_mon = (int)(winGMTime.wMonth - 1);
|
||||
outRetval->tm_year = (int)(winGMTime.wYear - 1900);
|
||||
outRetval->tm_wday = (int)winGMTime.wDayOfWeek;
|
||||
outRetval->tm_isdst = -1;
|
||||
|
||||
outRetval->tm_yday = (int)winGMTime.wDay + sDaysOfYear[outRetval->tm_mon];
|
||||
if(0 == (winGMTime.wYear & 3)) {
|
||||
if(2 < winGMTime.wMonth) {
|
||||
if(0 == winGMTime.wYear % 100) {
|
||||
if(0 == winGMTime.wYear % 400) {
|
||||
outRetval->tm_yday++;
|
||||
}
|
||||
}else {
|
||||
outRetval->tm_yday++;
|
||||
}
|
||||
}
|
||||
}
|
||||
retval = outRetval;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
struct tm* localtime_r(const time_t* inTimeT,struct tm* outRetval)
|
||||
{
|
||||
struct tm* retval = NULL;
|
||||
|
||||
if(NULL != inTimeT && NULL != outRetval) {
|
||||
SYSTEMTIME winLocalTime;
|
||||
|
||||
time_t_2_LOCALSYSTEMTIME(winLocalTime, *inTimeT);
|
||||
|
||||
outRetval->tm_sec = (int)winLocalTime.wSecond;
|
||||
outRetval->tm_min = (int)winLocalTime.wMinute;
|
||||
outRetval->tm_hour = (int)winLocalTime.wHour;
|
||||
outRetval->tm_mday = (int)winLocalTime.wDay;
|
||||
outRetval->tm_mon = (int)(winLocalTime.wMonth - 1);
|
||||
outRetval->tm_year = (int)(winLocalTime.wYear - 1900);
|
||||
outRetval->tm_wday = (int)winLocalTime.wDayOfWeek;
|
||||
outRetval->tm_isdst = -1;
|
||||
|
||||
outRetval->tm_yday = (int)winLocalTime.wDay + sDaysOfYear[outRetval->tm_mon];
|
||||
if(0 == (winLocalTime.wYear & 3)) {
|
||||
if(2 < winLocalTime.wMonth) {
|
||||
if(0 == winLocalTime.wYear % 100) {
|
||||
if(0 == winLocalTime.wYear % 400) {
|
||||
outRetval->tm_yday++;
|
||||
}
|
||||
} else {
|
||||
outRetval->tm_yday++;
|
||||
}
|
||||
}
|
||||
}
|
||||
retval = outRetval;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
struct tm* localtime(const time_t* inTimeT)
|
||||
{
|
||||
return localtime_r(inTimeT, &tmStorage);
|
||||
}
|
||||
|
||||
struct tm* gmtime(const time_t* inTimeT)
|
||||
{
|
||||
return gmtime_r(inTimeT, &tmStorage);
|
||||
}
|
||||
|
||||
|
||||
time_t mktime(struct tm* inTM)
|
||||
{
|
||||
time_t retval = (time_t)-1;
|
||||
|
||||
if(NULL != inTM) {
|
||||
SYSTEMTIME winTime;
|
||||
struct tm* gmTime = NULL;
|
||||
|
||||
memset(&winTime, 0, sizeof(winTime));
|
||||
|
||||
/*
|
||||
* Ignore tm_wday and tm_yday.
|
||||
* We likely have some problems with dst.
|
||||
*/
|
||||
winTime.wSecond = inTM->tm_sec;
|
||||
winTime.wMinute = inTM->tm_min;
|
||||
winTime.wHour = inTM->tm_hour;
|
||||
winTime.wDay = inTM->tm_mday;
|
||||
winTime.wMonth = inTM->tm_mon + 1;
|
||||
winTime.wYear = inTM->tm_year + 1900;
|
||||
|
||||
/*
|
||||
* First get our time_t.
|
||||
*/
|
||||
SYSTEMTIME_2_time_t(retval, winTime);
|
||||
|
||||
/*
|
||||
* Now overwrite the struct passed in with what we believe it should be.
|
||||
*/
|
||||
gmTime = gmtime_r(&retval, inTM);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
time_t time(time_t *)
|
||||
{
|
||||
time_t retval;
|
||||
SYSTEMTIME winTime;
|
||||
::GetSystemTime(&winTime);
|
||||
SYSTEMTIME_2_time_t(retval, winTime);
|
||||
return retval;
|
||||
}
|
||||
|
||||
clock_t clock()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* ***** 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 mozilla.org code, released
|
||||
* Jan 28, 2003.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2003
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Garrett Arch Blythe, 28-January-2003
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#if !defined(__time_conversions_h)
|
||||
#define __time_conversions_h
|
||||
|
||||
|
||||
#define TIME_BEGIN_MACRO do {
|
||||
#define TIME_END_MACRO } while(0);
|
||||
|
||||
/*
|
||||
* FILETIME has an epoch of 1601.
|
||||
* Precomputed the 1970 epoch so we do not have to below.
|
||||
*/
|
||||
#define FILETIME_1970 116444736000000000i64
|
||||
|
||||
/*
|
||||
* Marco to support add/sub/mul/div on a FILETIME level.
|
||||
*/
|
||||
#define FILETIME_ARITH(outFileTime, inFileTime, inOperation, inValue) \
|
||||
TIME_BEGIN_MACRO \
|
||||
ULARGE_INTEGER buffer1; \
|
||||
\
|
||||
buffer1.LowPart = inFileTime.dwLowDateTime; \
|
||||
buffer1.HighPart = inFileTime.dwHighDateTime; \
|
||||
buffer1.QuadPart = buffer1.QuadPart inOperation inValue; \
|
||||
outFileTime.dwLowDateTime = buffer1.LowPart; \
|
||||
outFileTime.dwHighDateTime = buffer1.HighPart; \
|
||||
TIME_END_MACRO
|
||||
|
||||
/*
|
||||
* FILETIME is in 100 nanosecond units.
|
||||
* Provide macros for conversion to other second units.
|
||||
*/
|
||||
#define FILETIME_2_MICROSECONDS(outTime, inFileTime) \
|
||||
TIME_BEGIN_MACRO \
|
||||
ULARGE_INTEGER buffer2; \
|
||||
\
|
||||
buffer2.LowPart = inFileTime.dwLowDateTime; \
|
||||
buffer2.HighPart = inFileTime.dwHighDateTime; \
|
||||
outTime = buffer2.QuadPart / 10i64; \
|
||||
TIME_END_MACRO
|
||||
#define FILETIME_2_MILLISECONDS(outTime, inFileTime) \
|
||||
TIME_BEGIN_MACRO \
|
||||
ULARGE_INTEGER buffer3; \
|
||||
\
|
||||
buffer3.LowPart = inFileTime.dwLowDateTime; \
|
||||
buffer3.HighPart = inFileTime.dwHighDateTime; \
|
||||
outTime = buffer3.QuadPart / 10000i64; \
|
||||
TIME_END_MACRO
|
||||
#define FILETIME_2_SECONDS(outTime, inFileTime) \
|
||||
TIME_BEGIN_MACRO \
|
||||
ULARGE_INTEGER buffer4; \
|
||||
\
|
||||
buffer4.LowPart = inFileTime.dwLowDateTime; \
|
||||
buffer4.HighPart = inFileTime.dwHighDateTime; \
|
||||
outTime = buffer4.QuadPart / 10000000i64; \
|
||||
TIME_END_MACRO
|
||||
#define SECONDS_2_FILETIME(outFileTime, inTime) \
|
||||
TIME_BEGIN_MACRO \
|
||||
ULARGE_INTEGER buffer5; \
|
||||
\
|
||||
buffer5.QuadPart = (ULONGLONG)inTime * 10000000i64; \
|
||||
outFileTime.dwLowDateTime = buffer5.LowPart; \
|
||||
outFileTime.dwHighDateTime = buffer5.HighPart; \
|
||||
TIME_END_MACRO
|
||||
|
||||
/*
|
||||
* Conversions from FILETIME 1601 epoch time to LIBC 1970 time.epoch.
|
||||
*/
|
||||
#define FILETIME_2_time_t(outTimeT, inFileTime) \
|
||||
TIME_BEGIN_MACRO \
|
||||
FILETIME result6; \
|
||||
ULONGLONG conversion6; \
|
||||
\
|
||||
FILETIME_ARITH(result6, inFileTime, -, FILETIME_1970); \
|
||||
FILETIME_2_SECONDS(conversion6, result6); \
|
||||
outTimeT = (time_t)conversion6; \
|
||||
TIME_END_MACRO
|
||||
#define time_t_2_FILETIME(outFileTime, inTimeT) \
|
||||
TIME_BEGIN_MACRO \
|
||||
FILETIME conversion7; \
|
||||
\
|
||||
SECONDS_2_FILETIME(conversion7, inTimeT); \
|
||||
FILETIME_ARITH(outFileTime, conversion7, +, FILETIME_1970); \
|
||||
TIME_END_MACRO
|
||||
|
||||
|
||||
/*
|
||||
* Sometimes SYSTEMTIME needs to be handled as well.
|
||||
*/
|
||||
#define SYSTEMTIME_2_time_t(outTimeT, inSystemTime) \
|
||||
TIME_BEGIN_MACRO \
|
||||
FILETIME result8; \
|
||||
\
|
||||
SystemTimeToFileTime(&inSystemTime, &result8); \
|
||||
FILETIME_2_time_t(outTimeT, result8); \
|
||||
TIME_END_MACRO
|
||||
#define time_t_2_SYSTEMTIME(outSystemTime, inTimeT) \
|
||||
TIME_BEGIN_MACRO \
|
||||
FILETIME conversion9; \
|
||||
\
|
||||
time_t_2_FILETIME(conversion9, inTimeT); \
|
||||
FileTimeToSystemTime(&conversion9, &outSystemTime); \
|
||||
TIME_END_MACRO
|
||||
#define time_t_2_LOCALSYSTEMTIME(outSystemTime, inTimeT) \
|
||||
TIME_BEGIN_MACRO \
|
||||
FILETIME conversion10; \
|
||||
FILETIME localConversion10; \
|
||||
\
|
||||
time_t_2_FILETIME(conversion10, inTimeT); \
|
||||
FileTimeToLocalFileTime(&conversion10, &localConversion10); \
|
||||
FileTimeToSystemTime(&localConversion10, &outSystemTime); \
|
||||
TIME_END_MACRO
|
||||
|
||||
|
||||
|
||||
#endif /* __time_conversions_h */
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
#
|
||||
# ***** 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 Mozilla CE Shunt Library.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Mozilla Corporation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2008
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# John Wolfe (wolfe@lobo.us)
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of 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 *****
|
||||
|
||||
# this file is used directly during configure as well as included from Makefile.in
|
||||
|
||||
DEVENV_FLAG=-
|
||||
|
||||
CC=cl -O2
|
||||
|
||||
MOZCE_DEVENV=vs$(MOZ_MSVCVERSION)
|
||||
|
||||
MOZCE_TOOLS_DIR=$(TOPSRCDIR)/build/wince/tools
|
||||
|
||||
ifdef MOZCE_NOT_CONFIGURE
|
||||
MOZCE_TOOLS_BIN_DIR=$(OBJDIR)/build/wince/tools
|
||||
else
|
||||
# if we're building the tools in configure, we want them to go directly to the sdk
|
||||
# so they get rebuilt once we have a full environment
|
||||
MOZCE_TOOLS_BIN_DIR=$(OBJDIR)/dist/sdk/bin
|
||||
endif
|
||||
|
||||
BUILD_SWITCH=$(DEVENV_FLAG)Build
|
||||
REBUILD_SWITCH=$(DEVENV_FLAG)Rebuild
|
||||
CLEAN_SWITCH=$(DEVENV_FLAG)clean
|
||||
|
||||
ifeq ($(VCINSTALLDIR),)
|
||||
$(error Environment variable VCINSTALLDIR not set! Are you using MozillaBuild?)
|
||||
endif
|
||||
|
||||
ifeq ($(WINCE_SDK_DIR),)
|
||||
$(error Environment variable WINCE_SDK_DIR not set! It must be passed to make if not running from configure)
|
||||
endif
|
||||
|
||||
ifeq ($(MOZ_MSVCVERSION),)
|
||||
$(error Environment variable MOZ_MSVCVERSION not set! Are you using MozillaBuild?)
|
||||
endif
|
||||
|
||||
CFLAGS += \
|
||||
-DVC_PATH='"$(subst \,\\,$(VCINSTALLDIR))\\"' \
|
||||
-DWM_SDK_PATH='"$(subst \,\\,$(WINCE_SDK_DIR))\\"' \
|
||||
-DMOZCE_DEVENV='"$(MOZCE_DEVENV)"' \
|
||||
-DTOPSRCDIR='"$(TOPSRCDIR)"' \
|
||||
$(NULL)
|
||||
|
||||
ifneq ($(WINDOWSSDKDIR),)
|
||||
CFLAGS += -DWIN_SDK_PATH='"$(subst \,\\,$(WINDOWSSDKDIR))"'
|
||||
else
|
||||
ifeq ($(SDKDIR),)
|
||||
$(error Environment variable WINDOWSSDKDIR not set! Are you using MozillaBuild?)
|
||||
else
|
||||
CFLAGS += -DWIN_SDK_PATH='"$(subst \,\\,$(SDKDIR))"'
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef VPATH
|
||||
CFLAGS += -DSHUNT_INC='"$(OBJDIR)/dist/include/mozce_shunt"'
|
||||
CFLAGS += -DSHUNT_LIB='"$(OBJDIR)/dist/lib"'
|
||||
CFLAGS += -DJEMALLOC_LIB='"$(OBJDIR)/dist/lib/jemalloc.lib"'
|
||||
endif
|
||||
CFLAGS += -DEBUG -Zi
|
||||
|
||||
SDK_TOOLS = $(MOZCE_TOOLS_BIN_DIR)/$(target)-as.exe \
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-gcc.exe \
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-lib.exe \
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-link.exe \
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-res.exe
|
||||
|
||||
all: libs export
|
||||
|
||||
libs: $(SDK_TOOLS)
|
||||
|
||||
clean: clobber
|
||||
|
||||
|
||||
clobber:
|
||||
rm $(MOZCE_TOOLS_BIN_DIR)/*.exe
|
||||
|
||||
$(MOZCE_TOOLS_BIN_DIR)/linkargs.obj: $(MOZCE_TOOLS_DIR)/linkargs.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
|
||||
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
|
||||
$(CC) $(CFLAGS) -c -Fo$(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_DIR)/linkargs.c
|
||||
|
||||
$(MOZCE_TOOLS_BIN_DIR)/toolspath.obj: $(MOZCE_TOOLS_DIR)/toolspath.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile
|
||||
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
|
||||
$(CC) $(CFLAGS) -c -Fo$(MOZCE_TOOLS_BIN_DIR)/toolspath.obj $(MOZCE_TOOLS_DIR)/toolspath.c
|
||||
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-as.exe: $(MOZCE_TOOLS_DIR)/arm-wince-as.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
|
||||
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-as.c -link $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-gcc.exe: $(MOZCE_TOOLS_DIR)/arm-wince-gcc.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
|
||||
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-gcc.c -link $(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-lib.exe: $(MOZCE_TOOLS_DIR)/arm-wince-lib.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
|
||||
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-lib.c -link $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-link.exe: $(MOZCE_TOOLS_DIR)/arm-wince-link.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
|
||||
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-link.c -link $(MOZCE_TOOLS_BIN_DIR)/linkargs.obj $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
|
||||
$(MOZCE_TOOLS_BIN_DIR)/$(target)-res.exe: $(MOZCE_TOOLS_DIR)/arm-wince-res.c $(MOZCE_TOOLS_DIR)/toolspath.h $(MOZCE_TOOLS_DIR)/Makefile $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
mkdir -p $(MOZCE_TOOLS_BIN_DIR);
|
||||
$(CC) $(CFLAGS) -Fo$(MOZCE_TOOLS_BIN_DIR) -Fe$@ $(MOZCE_TOOLS_DIR)/arm-wince-res.c -link $(MOZCE_TOOLS_BIN_DIR)/toolspath.obj
|
||||
|
||||
|
||||
export:: $(SDK_TOOLS)
|
||||
ifdef MOZCE_NOT_CONFIGURE
|
||||
mkdir -p $(OBJDIR)/dist/sdk/bin
|
||||
cp $^ $(OBJDIR)/dist/sdk/bin
|
||||
endif
|
|
@ -1,62 +0,0 @@
|
|||
# ***** 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 Mozilla core build scripts.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Brad Lassey <blassey@mozilla.com>
|
||||
#
|
||||
# Portions created by the Initial Developer are Copyright (C) 2005
|
||||
# the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# 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 *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
|
||||
TOPSRCDIR = $(topsrcdir)
|
||||
OBJDIR = $(shell cd $(DEPTH); pwd -W)
|
||||
CFLAGS += -DHAVE_SHUNT
|
||||
MOZCE_NOT_CONFIGURE=1
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
ifdef MOZ_MEMORY
|
||||
CFLAGS += -DMOZ_MEMORY
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/build/wince/tools/Makefile
|
||||
|
||||
export::
|
||||
|
||||
tools::
|
||||
|
||||
check::
|
||||
|
||||
.NOTPARALLEL:
|
|
@ -1,17 +0,0 @@
|
|||
#include "toolspath.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char* args[1000];
|
||||
int i = 0;
|
||||
|
||||
args[i++] = ASM_PATH;
|
||||
|
||||
// armasm.exe requires a space between -I and the path. See bug 508721
|
||||
args[i++] = "-I \"" WCE_INC "\"";
|
||||
|
||||
i += argpath_conv(&argv[1], &args[i]);
|
||||
|
||||
return run(args);
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
#include "toolspath.h"
|
||||
#include "linkargs.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int startOfArgvs;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int link = 0;
|
||||
int s = 0;
|
||||
int k = 0;
|
||||
|
||||
char* args[1000];
|
||||
char outputFileArg[1000];
|
||||
|
||||
args[i++] = CL_PATH;
|
||||
|
||||
#ifdef HAVE_SHUNT // simple test to see if we're in configure or not
|
||||
if(!getenv("NO_SHUNT")) {
|
||||
args[i++] = "/I\"" SHUNT_INC "\"";
|
||||
args[i++] = "/FI\"mozce_shunt.h\"";
|
||||
}
|
||||
#endif
|
||||
#ifdef MOZ_MEMORY
|
||||
args[i++] = "/DMOZ_MEMORY";
|
||||
#endif
|
||||
args[i++] = "/I\"" ATL_INC "\"";
|
||||
args[i++] = "/DMOZCE_STATIC_BUILD";
|
||||
args[i++] = "/DUNICODE";
|
||||
args[i++] = "/D_UNICODE_";
|
||||
args[i++] = "/DARM";
|
||||
args[i++] = "/D_ARM_";
|
||||
args[i++] = "/DWINCE";
|
||||
args[i++] = "/D_WIN32_WCE=0x502";
|
||||
args[i++] = "/DUNDER_CE";
|
||||
// args[i++] = "/DWIN32_PLATFORM_WFSP";
|
||||
args[i++] = "/DWIN32_PLATFORM_PSPC";
|
||||
// args[i++] = "/DPOCKETPC2003_UI_MODEL";
|
||||
args[i++] = "/D_WINDOWS";
|
||||
args[i++] = "/DNO_ERRNO";
|
||||
args[i++] = "/D_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA";
|
||||
|
||||
args[i++] = "/GS-"; // disable security checks
|
||||
args[i++] = "/GR-"; // disable C++ RTTI
|
||||
|
||||
startOfArgvs = i;
|
||||
|
||||
i += argpath_conv(&argv[1], &args[i]);
|
||||
|
||||
// if /Fe is passed, then link
|
||||
//
|
||||
// if -o is passed, then blank out this argument, and place a "/Fo"
|
||||
// before the next argument
|
||||
while(argv[j])
|
||||
{
|
||||
if (strncmp(argv[j], "-o", 2) == 0)
|
||||
{
|
||||
printf("%s is -o\n",argv[j]);
|
||||
|
||||
|
||||
link = strstr(args[startOfArgvs+j], ".obj") ? 0:1;
|
||||
|
||||
|
||||
// If we are outputting a .OBJ file, then we are
|
||||
// NOT linking, and we need to do some fancy
|
||||
// footwork to output "/FoFILENAME" as an argument
|
||||
args[startOfArgvs+j-1] = "";
|
||||
strcpy(outputFileArg, ( strstr(args[startOfArgvs+j], ".exe") )?"/Fe":"/Fo");
|
||||
strcat(outputFileArg, args[startOfArgvs+j]);
|
||||
args[startOfArgvs+j] = outputFileArg;
|
||||
}
|
||||
if (strcmp(argv[j], "-link") ||
|
||||
strcmp(argv[j], "-LINK") ||
|
||||
strcmp(argv[j], "/link") ||
|
||||
strcmp(argv[j], "/LINK"))
|
||||
link = 1;
|
||||
|
||||
checkLinkArgs(&k, &s, &i, &j, args, argv);
|
||||
j++;
|
||||
}
|
||||
|
||||
if (link)
|
||||
{
|
||||
args[i++] = "/link";
|
||||
addLinkArgs(k, s, &i, &j, args, argv);
|
||||
}
|
||||
|
||||
args[i] = NULL;
|
||||
|
||||
// dumpargs(args);
|
||||
return run(args);
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
#include "toolspath.h"
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char* args[1000];
|
||||
int i = 0;
|
||||
|
||||
args[i++] = LIB_PATH;
|
||||
|
||||
argpath_conv(&argv[1], &args[i]);
|
||||
|
||||
return run(args);
|
||||
|
||||
}
|