1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
10 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
11 Cu.import("resource://gre/modules/ctypes.jsm");
13 const RECOVERYSERVICE_CID = Components.ID("{b3caca5d-0bb0-48c6-912b-6be6cbf08832}");
14 const RECOVERYSERVICE_CONTRACTID = "@mozilla.org/recovery-service;1";
17 dump("-*- RecoveryService: " + msg + "\n");
20 #ifdef MOZ_WIDGET_GONK
21 let librecovery = (function() {
24 library = ctypes.open("librecovery.so");
26 log("Unable to open librecovery.so");
27 throw Cr.NS_ERROR_FAILURE;
29 let FotaUpdateStatus = new ctypes.StructType("FotaUpdateStatus", [
30 { result: ctypes.int },
31 { updatePath: ctypes.char.ptr }
35 factoryReset: library.declare("factoryReset",
38 installFotaUpdate: library.declare("installFotaUpdate",
44 FotaUpdateStatus: FotaUpdateStatus,
45 getFotaUpdateStatus: library.declare("getFotaUpdateStatus",
53 function RecoveryService() {}
55 RecoveryService.prototype = {
56 classID: RECOVERYSERVICE_CID,
57 QueryInterface: XPCOMUtils.generateQI([Ci.nsIRecoveryService]),
58 classInfo: XPCOMUtils.generateCI({
59 classID: RECOVERYSERVICE_CID,
60 contractID: RECOVERYSERVICE_CONTRACTID,
61 interfaces: [Ci.nsIRecoveryService],
62 classDescription: "B2G Recovery Service"
65 factoryReset: function RS_factoryReset() {
66 #ifdef MOZ_WIDGET_GONK
67 // If this succeeds, then the device reboots and this never returns
68 if (librecovery.factoryReset() != 0) {
69 log("Error: Factory reset failed");
72 throw Cr.NS_ERROR_FAILURE;
75 installFotaUpdate: function RS_installFotaUpdate(updatePath) {
76 #ifdef MOZ_WIDGET_GONK
77 // If this succeeds, then the device reboots and this never returns
78 if (librecovery.installFotaUpdate(updatePath, updatePath.length) != 0) {
79 log("Error: FOTA install failed");
82 throw Cr.NS_ERROR_FAILURE;
85 getFotaUpdateStatus: function RS_getFotaUpdateStatus() {
86 let status = Ci.nsIRecoveryService.FOTA_UPDATE_UNKNOWN;
87 #ifdef MOZ_WIDGET_GONK
88 let cStatus = librecovery.FotaUpdateStatus();
90 if (librecovery.getFotaUpdateStatus(cStatus.address()) == 0) {
91 status = cStatus.result;
99 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RecoveryService]);