Advertisement
death2all110

SMSWakeUpService.class

Jul 17th, 2012
1,446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. public class SMSWakeUpService extends SMSIntentService
  2. {
  3.   private static final int MSG_DELETE_SMS = 5291453;
  4.   private static final String TAG = "SMSWakupService";
  5.   private Context context;
  6.   final Handler hndSMSDelete = new Handler()
  7.   {
  8.     int retVal;
  9.  
  10.     public void handleMessage(Message paramMessage)
  11.     {
  12.       if (paramMessage.what == 5291453)
  13.       {
  14.         Uri localUri = Uri.parse("content://sms/");
  15.         String str = (String)paramMessage.obj;
  16.         Log.d("SMSWakupService", "SMS message proccessed.. deleting from inbox sms=" + str);
  17.         ContentResolver localContentResolver = SMSWakeUpService.this.context.getContentResolver();
  18.         String[] arrayOfString = new String[1];
  19.         arrayOfString[0] = str;
  20.         this.retVal = localContentResolver.delete(localUri, "body like ?", arrayOfString);
  21.         if (this.retVal < 1)
  22.           Log.w("SMSWakupService", "Could NOT delete sms from inbox =" + str);
  23.       }
  24.     }
  25.   };
  26.   private SMSDBAdapter smsDbAdapter;
  27.  
  28.   public SMSWakeUpService()
  29.   {
  30.     super("SMSWakupService");
  31.   }
  32.  
  33.   protected void checkSMSPrefix(Intent paramIntent)
  34.   {
  35.     String str1 = paramIntent.getStringExtra("SMS_FILTERING");
  36.     if ((str1 != null) && (str1.contains(":")))
  37.     {
  38.       StringTokenizer localStringTokenizer = new StringTokenizer(str1, ":");
  39.       while (true)
  40.       {
  41.         String str3;
  42.         try
  43.         {
  44.           String str2 = localStringTokenizer.nextToken();
  45.           Log.d("SMSWakupService", "smsPrefix = " + str2);
  46.           if (!str2.startsWith("//VZW"))
  47.             break;
  48.           str3 = str2 + ":";
  49.           if (this.smsDbAdapter != null)
  50.             continue;
  51.           Log.e("SMSWakupService", "smsDbAdapter  == NULL");
  52.           SQLiteDatabase localSQLiteDatabase = this.smsDbAdapter.openDBforRead();
  53.           Cursor localCursor = null;
  54.           if (localSQLiteDatabase == null)
  55.             continue;
  56.           localCursor = this.smsDbAdapter.getAppNameBySmsPrefix(str3, localSQLiteDatabase);
  57.           if (localCursor != null)
  58.             continue;
  59.           Log.w("SMSWakupService", "curAppNames == null ");
  60.           if ((localCursor != null) && (localCursor.getCount() > 0))
  61.           {
  62.             String str4 = str3 + "%";
  63.             this.hndSMSDelete.sendMessageDelayed(this.hndSMSDelete.obtainMessage(5291453, str4), 2000L);
  64.             if (localCursor.moveToNext())
  65.               continue;
  66.             if (localCursor == null)
  67.               break;
  68.             localCursor.close();
  69.             this.smsDbAdapter.closeDBforRead(localSQLiteDatabase);
  70.             break;
  71.             String str5 = localCursor.getString(2);
  72.             try
  73.             {
  74.               Intent localIntent = new Intent(str5);
  75.               localIntent.putExtra("WAKE_UP_SMS_MSG", str1);
  76.               Log.d("SMSWakupService", "sending broadcast to:" + str5);
  77.               this.context.sendBroadcast(localIntent);
  78.             }
  79.             catch (Exception localException)
  80.             {
  81.               Log.e("SMSWakupService", localException.getMessage());
  82.             }
  83.             continue;
  84.           }
  85.         }
  86.         catch (NoSuchElementException localNoSuchElementException)
  87.         {
  88.           Log.w("SMSWakupService", "Invalid SMS");
  89.         }
  90.         Log.d("SMSWakupService", "No matching prefix found: smsPrefix = " + str3);
  91.       }
  92.     }
  93.   }
  94.  
  95.   public void onCreate()
  96.   {
  97.     this.context = getApplicationContext();
  98.     this.smsDbAdapter = new SMSDBAdapter(this.context);
  99.     super.onCreate();
  100.   }
  101.  
  102.   public void onDestroy()
  103.   {
  104.     this.smsDbAdapter.close();
  105.     super.onDestroy();
  106.   }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement