package com.itheima.mobilesafe.service;

import java.util.Iterator;

import com.itheima.mobilesafe.db.dao.BlackNumberDao;
import com.itheima.mobilesafe.receiver.SMSReceiver;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.telephony.SmsMessage;
import android.util.Log;

public class CallSMSSafeService extends Service {

	public static final String TAG = "CallSMSSafeService";
	private InnerSMSReceiver receiver;
	
	private BlackNumberDao dao;

	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		return null;
	}

	private class InnerSMSReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			Log.i(TAG, "内部广播接收者，短信到来了");
			//检查发件人是否是黑名单号码，且设置了短信拦截或全部拦截
			Object[] objs = (Object[]) intent.getExtras().get("pdus");
			for (Object obj : objs){
				SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) obj);
				String sender = smsMessage.getOriginatingAddress();
				String resultString = dao.findMode(sender);
				if ("2".equals(resultString)  || "3".equals(resultString)) {
					Log.i(TAG, "拦截短信:" + sender+ " 说：" + smsMessage.getMessageBody());
					abortBroadcast();
				}
			}
			
		}

	}

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();

		dao = new BlackNumberDao(this);
		
		// 注册广播接收者
		receiver = new InnerSMSReceiver();
		IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
		registerReceiver(receiver, filter);
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
		unregisterReceiver(receiver);
		receiver = null;
		
	}

}

@@ -118,60 +118,8 @@
 Dao;
-%0Aimport com.itheima.mobilesafe.receiver.SMSReceiver;
 %0A%0Aim
@@ -309,24 +309,75 @@
 os.IBinder;%0A
+import android.renderscript.RenderScript.Priority;%0A
 import andro
@@ -1618,16 +1618,73 @@
 IVED%22);%0A
+%09%09filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);%0A
 %09%09regist

fix sth