package jp.muo.smsproxy;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

public class SmsReceiver extends BroadcastReceiver {
	public static final String TAG = "smsProxy";

	@Override
	public void onReceive(Context context, Intent intent) {
		// Log.d(TAG, "received");
		SmsProxyManager mgr = new SmsProxyManager(context);
        mgr.setType(SmsProxyManager.Mode.SMS);
		Bundle bundle = intent.getExtras();
        SmsMessage[] msgs = null;
        if (bundle != null && mgr.isEnabled() && !mgr.getProxyTo().equals("")) {
        	String msgText = "";
            Object[] pdus = (Object[]) bundle.get("pdus");
            if (pdus.length == 0) {
            	return;
            }
        	// Log.d(TAG, Integer.toString(pdus.length) + " messages found");
            msgs = new SmsMessage[pdus.length];
            String smsTemplate = context.getString(R.string.sms_content);
            for (int i = 0; i < msgs.length; ++i) {
                msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                msgText += String.format(smsTemplate, msgs[i].getOriginatingAddress(), msgs[i].getMessageBody().toString());
            }
        	// Log.d(TAG, "msg: " + msgText);
            mgr.send(msgText);
        }
	}
}

@@ -528,42 +528,8 @@
 ();%0A
-        SmsMessage%5B%5D msgs = null;%0A
     
@@ -601,24 +601,24 @@
 uals(%22%22)) %7B%0A
+
         %09Str
@@ -844,56 +844,8 @@
 %22);%0A
-            msgs = new SmsMessage%5Bpdus.length%5D;%0A
     
@@ -946,19 +946,19 @@
  0; i %3C 
-msg
+pdu
 s.length
@@ -982,23 +982,33 @@
         
+S
 ms
-gs%5Bi%5D
+Message orgSms
  = SmsMe
@@ -1099,23 +1099,22 @@
 mplate, 
-msgs%5Bi%5D
+orgSms
 .getOrig
@@ -1135,15 +1135,14 @@
 (), 
-msgs%5Bi%5D
+orgSms
 .get

remove unused array