Bug 719795 - Crash when GeckoSmsManager.init is called more than once [r=blassey,mounir]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 24 Jan 2012 08:06:47 -0800
changeset 86467 7cafa419af61f3952e2cd7d875aa6a46f4169dc9
parent 86466 4976f17b061ac8630839280b298a9198a754514a
child 86468 5efbddddb54f1bc7639d4b0066af13abd2cbb99b
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey, mounir
bugs719795
milestone12.0a1
Bug 719795 - Crash when GeckoSmsManager.init is called more than once [r=blassey,mounir]
embedding/android/GeckoApp.java
embedding/android/GeckoSmsManager.java
embedding/android/SmsManager.java.in
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoSmsManager.java
mobile/android/base/SmsManager.java.in
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -409,17 +409,17 @@ abstract public class GeckoApp
         mConnectivityReceiver = new GeckoConnectivityReceiver();
 
         IntentFilter batteryFilter = new IntentFilter();
         batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
         mBatteryReceiver = new GeckoBatteryManager();
         registerReceiver(mBatteryReceiver, batteryFilter);
 
         if (SmsManager.getInstance() != null) {
-            SmsManager.getInstance().init();
+            SmsManager.getInstance().start();
         }
 
         GeckoNetworkManager.getInstance().init();
 
         if (!checkAndSetLaunchState(LaunchState.PreLaunch,
                                     LaunchState.Launching))
             return;
 
@@ -575,17 +575,19 @@ abstract public class GeckoApp
         Log.i(LOG_FILE_NAME, "destroy");
 
         // Tell Gecko to shutting down; we'll end up calling System.exit()
         // in onXreExit.
         if (isFinishing())
             GeckoAppShell.sendEventToGecko(new GeckoEvent(GeckoEvent.ACTIVITY_SHUTDOWN));
 
         if (SmsManager.getInstance() != null) {
-            SmsManager.getInstance().shutdown();
+            SmsManager.getInstance().stop();
+            if (isFinishing())
+                SmsManager.getInstance().shutdown();
         }
 
         GeckoNetworkManager.getInstance().stop();
 
         super.onDestroy();
 
         unregisterReceiver(mBatteryReceiver);
     }
--- a/embedding/android/GeckoSmsManager.java
+++ b/embedding/android/GeckoSmsManager.java
@@ -351,25 +351,27 @@ public class GeckoSmsManager
    */
   private final static int kDeliveryStateSent     = 0;
   private final static int kDeliveryStateReceived = 1;
   private final static int kDeliveryStateUnknown  = 2;
   private final static int kDeliveryStateEndGuard = 3;
 
   private final static String[] kRequiredMessageRows = new String[] { "_id", "address", "body", "date", "type" };
 
-  public void init() {
+  public GeckoSmsManager() {
+    SmsIOThread.getInstance().start();
+  }
+
+  public void start() {
     IntentFilter smsFilter = new IntentFilter();
     smsFilter.addAction(GeckoSmsManager.ACTION_SMS_RECEIVED);
     smsFilter.addAction(GeckoSmsManager.ACTION_SMS_SENT);
     smsFilter.addAction(GeckoSmsManager.ACTION_SMS_DELIVERED);
 
     GeckoApp.mAppContext.registerReceiver(this, smsFilter);
-
-    SmsIOThread.getInstance().start();
   }
 
   @Override
   public void onReceive(Context context, Intent intent) {
     if (intent.getAction().equals(ACTION_SMS_RECEIVED)) {
       // TODO: Try to find the receiver number to be able to populate
       //       SmsMessage.receiver.
       // TODO: Get the id and the date from the stock app saved message.
@@ -920,15 +922,17 @@ public class GeckoSmsManager
       GeckoAppShell.notifyReadingMessageListFailed(kUnknownError, aRequestId, aProcessId);
     }
   }
 
   public void clearMessageList(int aListId) {
     MessagesListManager.getInstance().remove(aListId);
   }
 
-  public void shutdown() {
+  public void stop() {
     GeckoApp.mAppContext.unregisterReceiver(this);
+  }
 
+  public void shutdown() {
     SmsIOThread.getInstance().interrupt();
     MessagesListManager.getInstance().clear();
   }
 }
--- a/embedding/android/SmsManager.java.in
+++ b/embedding/android/SmsManager.java.in
@@ -52,17 +52,18 @@ class SmsManager
     }
 #endif
     return sInstance;
   }
 }
 
 interface ISmsManager
 {
-  public void init();
+  public void start();
+  public void stop();
   public void shutdown();
 
   public int getNumberOfMessagesForText(String aText);
   public void send(String aNumber, String aMessage, int aRequestId, long aProcessId);
   public int saveSentMessage(String aRecipient, String aBody, long aDate);
   public void getMessage(int aMessageId, int aRequestId, long aProcessId);
   public void deleteMessage(int aMessageId, int aRequestId, long aProcessId);
   public void createMessageList(long aStartDate, long aEndDate, String[] aNumbers, int aNumbersCount, int aDeliveryState, boolean aReverse, int aRequestId, long aProcessId);
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -1688,23 +1688,23 @@ abstract public class GeckoApp
         mConnectivityReceiver = new GeckoConnectivityReceiver();
 
         IntentFilter batteryFilter = new IntentFilter();
         batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
         mBatteryReceiver = new GeckoBatteryManager();
         registerReceiver(mBatteryReceiver, batteryFilter);
 
         if (SmsManager.getInstance() != null) {
-          SmsManager.getInstance().init();
+          SmsManager.getInstance().start();
         }
 
         GeckoNetworkManager.getInstance().init();
 
         final GeckoApp self = this;
- 
+
         GeckoAppShell.getHandler().postDelayed(new Runnable() {
             public void run() {
                 Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState");
 
                 /*
                   XXXX see bug 635342
                    We want to disable this code if possible.  It is about 145ms in runtime
                 SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
@@ -2011,17 +2011,19 @@ abstract public class GeckoApp
         GeckoAppShell.unregisterGeckoEventListener("Permissions:Data", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("Downloads:Done", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("CharEncoding:Data", GeckoApp.mAppContext);
         GeckoAppShell.unregisterGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext);
 
         mFavicons.close();
 
         if (SmsManager.getInstance() != null) {
-          SmsManager.getInstance().shutdown();
+            SmsManager.getInstance().stop();
+            if (isFinishing())
+                SmsManager.getInstance().shutdown();
         }
 
         GeckoNetworkManager.getInstance().stop();
 
         super.onDestroy();
 
         unregisterReceiver(mBatteryReceiver);
     }
--- a/mobile/android/base/GeckoSmsManager.java
+++ b/mobile/android/base/GeckoSmsManager.java
@@ -351,25 +351,27 @@ public class GeckoSmsManager
    */
   private final static int kDeliveryStateSent     = 0;
   private final static int kDeliveryStateReceived = 1;
   private final static int kDeliveryStateUnknown  = 2;
   private final static int kDeliveryStateEndGuard = 3;
 
   private final static String[] kRequiredMessageRows = new String[] { "_id", "address", "body", "date", "type" };
 
-  public void init() {
+  public GeckoSmsManager() {
+    SmsIOThread.getInstance().start();
+  }
+
+  public void start() {
     IntentFilter smsFilter = new IntentFilter();
     smsFilter.addAction(GeckoSmsManager.ACTION_SMS_RECEIVED);
     smsFilter.addAction(GeckoSmsManager.ACTION_SMS_SENT);
     smsFilter.addAction(GeckoSmsManager.ACTION_SMS_DELIVERED);
 
     GeckoApp.mAppContext.registerReceiver(this, smsFilter);
-
-    SmsIOThread.getInstance().start();
   }
 
   @Override
   public void onReceive(Context context, Intent intent) {
     if (intent.getAction().equals(ACTION_SMS_RECEIVED)) {
       // TODO: Try to find the receiver number to be able to populate
       //       SmsMessage.receiver.
       // TODO: Get the id and the date from the stock app saved message.
@@ -920,15 +922,17 @@ public class GeckoSmsManager
       GeckoAppShell.notifyReadingMessageListFailed(kUnknownError, aRequestId, aProcessId);
     }
   }
 
   public void clearMessageList(int aListId) {
     MessagesListManager.getInstance().remove(aListId);
   }
 
-  public void shutdown() {
+  public void stop() {
     GeckoApp.mAppContext.unregisterReceiver(this);
+  }
 
+  public void shutdown() {
     SmsIOThread.getInstance().interrupt();
     MessagesListManager.getInstance().clear();
   }
 }
--- a/mobile/android/base/SmsManager.java.in
+++ b/mobile/android/base/SmsManager.java.in
@@ -52,17 +52,18 @@ class SmsManager
     }
 #endif
     return sInstance;
   }
 }
 
 interface ISmsManager
 {
-  public void init();
+  public void start();
+  public void stop();
   public void shutdown();
 
   public int getNumberOfMessagesForText(String aText);
   public void send(String aNumber, String aMessage, int aRequestId, long aProcessId);
   public int saveSentMessage(String aRecipient, String aBody, long aDate);
   public void getMessage(int aMessageId, int aRequestId, long aProcessId);
   public void deleteMessage(int aMessageId, int aRequestId, long aProcessId);
   public void createMessageList(long aStartDate, long aEndDate, String[] aNumbers, int aNumbersCount, int aDeliveryState, boolean aReverse, int aRequestId, long aProcessId);