Bug 674725 - Part AB - Create a thread to handle SMS IO on Android. r=cjones
This commit is contained in:
@@ -55,6 +55,8 @@ import android.content.ContentUris;
|
||||
import android.net.Uri;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import android.telephony.SmsManager;
|
||||
import android.telephony.SmsMessage;
|
||||
@@ -226,6 +228,28 @@ class Postman
|
||||
}
|
||||
}
|
||||
|
||||
class SmsIOThread extends Thread {
|
||||
private final static SmsIOThread sInstance = new SmsIOThread();
|
||||
|
||||
private Handler mHandler;
|
||||
|
||||
public static SmsIOThread getInstance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public boolean execute(Runnable r) {
|
||||
return mHandler.post(r);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
|
||||
mHandler = new Handler();
|
||||
|
||||
Looper.loop();
|
||||
}
|
||||
}
|
||||
|
||||
public class GeckoSmsManager
|
||||
extends BroadcastReceiver
|
||||
{
|
||||
@@ -244,6 +268,10 @@ public class GeckoSmsManager
|
||||
public final static int kUnknownError = 2;
|
||||
public final static int kInternalError = 3;
|
||||
|
||||
public static void init() {
|
||||
SmsIOThread.getInstance().start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(ACTION_SMS_RECEIVED)) {
|
||||
@@ -485,4 +513,8 @@ public class GeckoSmsManager
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
SmsIOThread.getInstance().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user