From 1ea391744d855722bc3c210aa9ad269da17d1c07 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 24 Jan 2012 08:06:47 -0800 Subject: [PATCH] Bug 719795 - Crash when GeckoSmsManager.init is called more than once [r=blassey,mounir] --- embedding/android/GeckoApp.java | 6 ++++-- embedding/android/GeckoSmsManager.java | 12 ++++++++---- embedding/android/SmsManager.java.in | 3 ++- mobile/android/base/GeckoApp.java | 8 +++++--- mobile/android/base/GeckoSmsManager.java | 12 ++++++++---- mobile/android/base/SmsManager.java.in | 3 ++- 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index 274012dbccae..6761b905b6d2 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -414,7 +414,7 @@ abstract public class GeckoApp registerReceiver(mBatteryReceiver, batteryFilter); if (SmsManager.getInstance() != null) { - SmsManager.getInstance().init(); + SmsManager.getInstance().start(); } GeckoNetworkManager.getInstance().init(); @@ -580,7 +580,9 @@ abstract public class GeckoApp 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(); diff --git a/embedding/android/GeckoSmsManager.java b/embedding/android/GeckoSmsManager.java index 5e813067fb56..51018d4e2bbd 100644 --- a/embedding/android/GeckoSmsManager.java +++ b/embedding/android/GeckoSmsManager.java @@ -356,15 +356,17 @@ public class GeckoSmsManager 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 @@ -925,9 +927,11 @@ public class GeckoSmsManager MessagesListManager.getInstance().remove(aListId); } - public void shutdown() { + public void stop() { GeckoApp.mAppContext.unregisterReceiver(this); + } + public void shutdown() { SmsIOThread.getInstance().interrupt(); MessagesListManager.getInstance().clear(); } diff --git a/embedding/android/SmsManager.java.in b/embedding/android/SmsManager.java.in index c913f92e8649..60bff463dc45 100644 --- a/embedding/android/SmsManager.java.in +++ b/embedding/android/SmsManager.java.in @@ -57,7 +57,8 @@ class SmsManager interface ISmsManager { - public void init(); + public void start(); + public void stop(); public void shutdown(); public int getNumberOfMessagesForText(String aText); diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index 695f38b55b63..5833a1021062 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1693,13 +1693,13 @@ abstract public class GeckoApp 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"); @@ -2016,7 +2016,9 @@ abstract public class GeckoApp mFavicons.close(); if (SmsManager.getInstance() != null) { - SmsManager.getInstance().shutdown(); + SmsManager.getInstance().stop(); + if (isFinishing()) + SmsManager.getInstance().shutdown(); } GeckoNetworkManager.getInstance().stop(); diff --git a/mobile/android/base/GeckoSmsManager.java b/mobile/android/base/GeckoSmsManager.java index 5e813067fb56..51018d4e2bbd 100644 --- a/mobile/android/base/GeckoSmsManager.java +++ b/mobile/android/base/GeckoSmsManager.java @@ -356,15 +356,17 @@ public class GeckoSmsManager 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 @@ -925,9 +927,11 @@ public class GeckoSmsManager MessagesListManager.getInstance().remove(aListId); } - public void shutdown() { + public void stop() { GeckoApp.mAppContext.unregisterReceiver(this); + } + public void shutdown() { SmsIOThread.getInstance().interrupt(); MessagesListManager.getInstance().clear(); } diff --git a/mobile/android/base/SmsManager.java.in b/mobile/android/base/SmsManager.java.in index c913f92e8649..60bff463dc45 100644 --- a/mobile/android/base/SmsManager.java.in +++ b/mobile/android/base/SmsManager.java.in @@ -57,7 +57,8 @@ class SmsManager interface ISmsManager { - public void init(); + public void start(); + public void stop(); public void shutdown(); public int getNumberOfMessagesForText(String aText);