Bug 790393 - Add MozPower.factoryReset() for factory reset. r=cjones, r=vingtetun, sr=sicking
authorShih-Chiang Chien <schien@mozilla.com>
Thu, 04 Oct 2012 17:28:34 +0800
changeset 111107 9ae8f8f7028fbd5793247806c7ffcaaf3ed79a67
parent 111106 a0158d3707850441cbbd3156395390380d90ef36
child 111108 d587ce3af2f357775ac939e346fc1de374a264a3
push id16873
push userryanvm@gmail.com
push dateTue, 23 Oct 2012 02:22:36 +0000
treeherdermozilla-inbound@c6fe2305d29c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones, vingtetun, sicking
bugs790393
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 790393 - Add MozPower.factoryReset() for factory reset. r=cjones, r=vingtetun, sr=sicking
b2g/components/b2g.idl
b2g/installer/package-manifest.in
dom/power/PowerManager.cpp
dom/power/nsIDOMPowerManager.idl
hal/Hal.cpp
hal/Hal.h
hal/Makefile.in
hal/fallback/FallbackFactoryReset.cpp
hal/gonk/GonkHal.cpp
hal/gonk/nsIRecoveryService.idl
hal/sandbox/PHal.ipdl
hal/sandbox/SandboxHal.cpp
--- a/b2g/components/b2g.idl
+++ b/b2g/components/b2g.idl
@@ -36,42 +36,8 @@ interface nsIB2GKeyboard : nsISupports
   // If the value passed in parameter isn't valid (in the term of HTML5
   // Forms Validation), the value will simply be ignored by the element. 
   void setValue(in jsval value);
 
   void removeFocus();
 
   attribute nsIDOMEventListener onfocuschange;
 };
-
-[scriptable, uuid(acb93ff8-aa6d-4bc8-bedd-2a6a3b802a74)]
-interface nsIRecoveryService : nsISupports
-{
-  /**
-   * Possible values of fotaStatus.result. These should stay in sync with
-   * librecovery/librecovery.h
-   */
-  const long FOTA_UPDATE_UNKNOWN = 0;
-  const long FOTA_UPDATE_FAIL    = 1;
-  const long FOTA_UPDATE_SUCCESS = 2;
-
-  /**
-   * Uses recovery to wipe the data and cache partitions. If this call is
-   * successful, the device should reboot before the function call ever returns.
-   *
-   * @throws NS_ERROR_FAILURE when rebooting into recovery fails for some reason.
-   */
-  void factoryReset();
-
-  /**
-   * Use recovery to install an OTA update.zip. If this call is
-   * successful, the device should reboot before the function call ever returns.
-   *
-   * @throws NS_ERROR_FAILURE when rebooting into recovery fails for some reason.
-   */
-  void installFotaUpdate(in string updatePath);
-
-  /**
-   * @return The status of the last FOTA update. One of FOTA_UPDATE_UNKNOWN,
-   *         FOTA_UPDATE_FAIL, FOTA_UPDATE_SUCCESS.
-   */
-  long getFotaUpdateStatus();
-};
--- a/b2g/installer/package-manifest.in
+++ b/b2g/installer/package-manifest.in
@@ -217,16 +217,17 @@
 @BINPATH@/components/fastfind.xpt
 @BINPATH@/components/feeds.xpt
 #ifdef MOZ_GTK2
 @BINPATH@/components/filepicker.xpt
 #endif
 @BINPATH@/components/find.xpt
 @BINPATH@/components/fuel.xpt
 @BINPATH@/components/gfx.xpt
+@BINPATH@/components/hal.xpt
 @BINPATH@/components/html5.xpt
 @BINPATH@/components/htmlparser.xpt
 @BINPATH@/components/imglib2.xpt
 @BINPATH@/components/imgicon.xpt
 @BINPATH@/components/inspector.xpt
 @BINPATH@/components/intl.xpt
 @BINPATH@/components/jar.xpt
 @BINPATH@/components/jetpack.xpt
--- a/dom/power/PowerManager.cpp
+++ b/dom/power/PowerManager.cpp
@@ -66,16 +66,23 @@ PowerManager::Reboot()
   NS_ENSURE_STATE(pmService);
 
   pmService->Reboot();
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
+PowerManager::FactoryReset()
+{
+  hal::FactoryReset();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 PowerManager::PowerOff()
 {
   nsCOMPtr<nsIPowerManagerService> pmService =
     do_GetService(POWERMANAGERSERVICE_CONTRACTID);
   NS_ENSURE_STATE(pmService);
 
   pmService->PowerOff();
 
--- a/dom/power/nsIDOMPowerManager.idl
+++ b/dom/power/nsIDOMPowerManager.idl
@@ -5,21 +5,22 @@
 
 #include "nsISupports.idl"
 
 interface nsIDOMMozWakeLockListener;
 
 /**
  * This interface implements navigator.mozPower
  */
-[scriptable, uuid(256a3287-f528-45b5-9ba8-2b3650c056e6)]
+[scriptable, uuid(7b181fef-2757-4198-89a0-8c426b8439ea)]
 interface nsIDOMMozPowerManager : nsISupports
 {
     void    powerOff();
     void    reboot();
+    void    factoryReset();
 
     /**
      * The listeners are notified when a resource changes its lock state to:
      *  - unlocked
      *  - locked but not visible
      *  - locked and visible
      */
     void    addWakeLockListener(in nsIDOMMozWakeLockListener aListener);
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -995,10 +995,16 @@ GetFMBandSettings(FMRadioCountry aCountr
       break;
     default:
       MOZ_ASSERT(0);
       break;
     };
     return settings;
 }
 
+void FactoryReset()
+{
+  AssertMainThread();
+  PROXY_IF_SANDBOXED(FactoryReset());
+}
+
 } // namespace hal
 } // namespace mozilla
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -512,16 +512,21 @@ hal::FMRadioSettings GetFMBandSettings(h
  * Start a watchdog to compulsively shutdown the system if it hangs.
  * @param aMode Specify how to shutdown the system.
  * @param aTimeoutSecs Specify the delayed seconds to shutdown the system.
  * 
  * This API is currently only allowed to be used from the main process.
  */
 void StartForceQuitWatchdog(hal::ShutdownMode aMode, int32_t aTimeoutSecs);
 
+/**
+ * Perform Factory Reset to wipe out all user data.
+ */
+void FactoryReset();
+
 } // namespace MOZ_HAL_NAMESPACE
 } // namespace mozilla
 
 #ifdef MOZ_DEFINED_HAL_NAMESPACE
 # undef MOZ_DEFINED_HAL_NAMESPACE
 # undef MOZ_HAL_NAMESPACE
 #endif
 
--- a/hal/Makefile.in
+++ b/hal/Makefile.in
@@ -16,31 +16,36 @@ VPATH       = \
   $(srcdir)/windows \
   $(srcdir)/cocoa \
   $(NULL)
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE         = hal
 LIBRARY_NAME   = hal_s
+XPIDL_MODULE   = hal
 FORCE_STATIC_LIB = 1
 LIBXUL_LIBRARY = 1
 EXPORT_LIBRARY = 1
 FAIL_ON_WARNINGS = 1
 
 EXPORTS_NAMESPACES = mozilla
 EXPORTS_mozilla = \
   Hal.h \
   HalImpl.h \
   HalSandbox.h \
   HalSensor.h \
   HalTypes.h \
   HalWakeLock.h \
   $(NULL)
 
+XPIDLSRCS = \
+  nsIRecoveryService.idl \
+  $(NULL)
+
 CPPSRCS = \
   Hal.cpp \
   SandboxHal.cpp \
   WindowIdentifier.cpp \
   HalWakeLock.cpp \
   $(NULL)
 
 ifeq (android,$(MOZ_WIDGET_TOOLKIT))
@@ -122,16 +127,17 @@ ifneq (gonk,$(MOZ_WIDGET_TOOLKIT)) #{
 CPPSRCS += \
   FallbackLights.cpp  \
   FallbackTime.cpp \
   FallbackWakeLocks.cpp \
   FallbackSwitch.cpp \
   FallbackScreenPower.cpp \
   FallbackProcessPriority.cpp \
   FallbackFMRadio.cpp \
+  FallbackFactoryReset.cpp \
   $(NULL)
 endif #}
 
 # Fallbacks for backends implemented on Android only.
 ifneq (android,$(MOZ_WIDGET_TOOLKIT))
 CPPSRCS += FallbackNetwork.cpp
 endif
 
new file mode 100644
--- /dev/null
+++ b/hal/fallback/FallbackFactoryReset.cpp
@@ -0,0 +1,18 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=8 et :
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "Hal.h"
+
+namespace mozilla {
+namespace hal_impl {
+
+void
+FactoryReset()
+{}
+
+} // namespace hal_impl
+} // namespace mozilla
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -41,16 +41,17 @@
 #include "mozilla/Monitor.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Preferences.h"
 #include "nsAlgorithm.h"
 #include "nsPrintfCString.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
+#include "nsIRecoveryService.h"
 #include "nsIRunnable.h"
 #include "nsScreenManagerGonk.h"
 #include "nsThreadUtils.h"
 #include "nsThreadUtils.h"
 #include "nsIThread.h"
 #include "nsXULAppAPI.h"
 #include "OrientationObserver.h"
 #include "UeventPoller.h"
@@ -947,10 +948,23 @@ SetProcessPriority(int aPid, ProcessPrio
 
     int success = setpriority(PRIO_PROCESS, aPid, nice);
     if (success != 0) {
       HAL_LOG(("Failed to set nice for pid %d to %d", aPid, nice));
     }
   }
 }
 
+void
+FactoryReset()
+{
+  nsCOMPtr<nsIRecoveryService> recoveryService =
+    do_GetService("@mozilla.org/recovery-service;1");
+  if (!recoveryService) {
+    NS_WARNING("Could not get recovery service!");
+    return;
+  }
+
+  recoveryService->FactoryReset();
+}
+
 } // hal_impl
 } // mozilla
new file mode 100644
--- /dev/null
+++ b/hal/gonk/nsIRecoveryService.idl
@@ -0,0 +1,39 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsISupports.idl"
+
+[scriptable, uuid(acb93ff8-aa6d-4bc8-bedd-2a6a3b802a74)]
+interface nsIRecoveryService : nsISupports
+{
+  /**
+   * Possible values of fotaStatus.result. These should stay in sync with
+   * librecovery/librecovery.h
+   */
+  const long FOTA_UPDATE_UNKNOWN = 0;
+  const long FOTA_UPDATE_FAIL    = 1;
+  const long FOTA_UPDATE_SUCCESS = 2;
+
+  /**
+   * Uses recovery to wipe the data and cache partitions. If this call is
+   * successful, the device should reboot before the function call ever returns.
+   *
+   * @throws NS_ERROR_FAILURE when rebooting into recovery fails for some reason.
+   */
+  void factoryReset();
+
+  /**
+   * Use recovery to install an OTA update.zip. If this call is
+   * successful, the device should reboot before the function call ever returns.
+   *
+   * @throws NS_ERROR_FAILURE when rebooting into recovery fails for some reason.
+   */
+  void installFotaUpdate(in string updatePath);
+
+  /**
+   * @return The status of the last FOTA update. One of FOTA_UPDATE_UNKNOWN,
+   *         FOTA_UPDATE_FAIL, FOTA_UPDATE_SUCCESS.
+   */
+  long getFotaUpdateStatus();
+};
--- a/hal/sandbox/PHal.ipdl
+++ b/hal/sandbox/PHal.ipdl
@@ -173,16 +173,18 @@ parent:
     sync GetFMRadioFrequency()
       returns (uint32_t frequency);
     sync IsFMRadioOn()
       returns (bool radioOn);
     sync GetFMRadioSignalStrength()
       returns (uint32_t strength);
     CancelFMRadioSeek();
 
+    FactoryReset();
+
 child:
     NotifySensorChange(SensorData aSensorData);
 
 parent:
     EnableSensorNotifications(SensorType aSensor);
     DisableSensorNotifications(SensorType aSensor);
 
     __delete__();
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -376,16 +376,22 @@ GetFMRadioSignalStrength()
 }
 
 void
 CancelFMRadioSeek()
 {
   Hal()->SendCancelFMRadioSeek();
 }
 
+void
+FactoryReset()
+{
+  Hal()->SendFactoryReset();
+}
+
 class HalParent : public PHalParent
                 , public BatteryObserver
                 , public NetworkObserver
                 , public ISensorObserver
                 , public WakeLockObserver
                 , public ScreenConfigurationObserver
                 , public SwitchObserver
                 , public SystemTimeObserver
@@ -837,16 +843,26 @@ public:
   RecvCancelFMRadioSeek()
   {
     if (!AssertAppProcessPermission(this, "fmradio")) {
       return false;
     }
     hal::CancelFMRadioSeek();
     return true;
   }
+
+  virtual bool
+  RecvFactoryReset()
+  {
+    if (!AssertAppProcessPermission(this, "power")) {
+      return false;
+    }
+    hal::FactoryReset();
+    return true;
+  }
 };
 
 class HalChild : public PHalChild {
 public:
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE
   {
     sHalChildIsLive = true;