Search in sources :

Example 11 with SmsMessage

use of android.telephony.SmsMessage in project Aegis by Decad3nce.

the class SMSReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_SMS_RECEIVED)) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            Log.i(TAG, "Received SMS");
            SmsMessage[] messages = getMessagesFromIntent(intent);
            for (SmsMessage sms : messages) {
                String body = sms.getMessageBody();
                address = sms.getOriginatingAddress();
                // TODO: whitelist/blacklist of allowed senders
                boolean alarmEnabled = preferences.getBoolean(SMSAlarmFragment.PREFERENCES_ALARM_ENABLED, context.getResources().getBoolean(R.bool.config_default_alarm_enabled));
                boolean lockEnabled = preferences.getBoolean(SMSLockFragment.PREFERENCES_LOCK_ENABLED, context.getResources().getBoolean(R.bool.config_default_lock_enabled));
                boolean wipeEnabled = preferences.getBoolean(SMSWipeFragment.PREFERENCES_WIPE_ENABLED, context.getResources().getBoolean(R.bool.config_default_wipe_enabled));
                boolean dataEnabled = preferences.getBoolean(SMSDataFragment.PREFERENCES_DATA_ENABLED, context.getResources().getBoolean(R.bool.config_default_data_enabled));
                boolean googleBackup = preferences.getBoolean(AdvancedSettingsFragment.PREFERENCES_GOOGLE_BACKUP_CHECKED, context.getResources().getBoolean(R.bool.config_default_google_backup_enabled));
                boolean dropboxBackup = preferences.getBoolean(AdvancedSettingsFragment.PREFERENCES_DROPBOX_BACKUP_CHECKED, context.getResources().getBoolean(R.bool.config_default_dropbox_backup_enabled));
                boolean locateEnabled = preferences.getBoolean(SMSLocateFragment.PREFERENCES_LOCATE_ENABLED, context.getResources().getBoolean(R.bool.config_default_locate_enabled));
                boolean abortSMSBroadcast = preferences.getBoolean(AdvancedSettingsFragment.PREFERENCES_ABORT_BROADCAST, context.getResources().getBoolean(R.bool.config_default_advanced_enable_abort_broadcast));
                String activationAlarmSms = preferences.getString(SMSAlarmFragment.PREFERENCES_ALARM_ACTIVATION_SMS, context.getResources().getString(R.string.config_default_alarm_activation_sms));
                String activationLockSms = preferences.getString(SMSLockFragment.PREFERENCES_LOCK_ACTIVATION_SMS, context.getResources().getString(R.string.config_default_lock_activation_sms));
                String activationWipeSms = preferences.getString(SMSWipeFragment.PREFERENCES_WIPE_ACTIVATION_SMS, context.getResources().getString(R.string.config_default_wipe_activation_sms));
                String activationDataSms = preferences.getString(SMSDataFragment.PREFERENCES_DATA_ACTIVATION_SMS, context.getResources().getString(R.string.config_default_data_activation_sms));
                String activationLocateSms = preferences.getString(SMSLocateFragment.PREFERENCES_LOCATE_ACTIVATION_SMS, context.getResources().getString(R.string.config_default_locate_activation_sms));
                String stopLocateSms = preferences.getString(SMSLocateFragment.PREFERENCES_LOCATE_STOP_SMS, context.getResources().getString(R.string.config_default_locate_stop_sms));
                boolean locateLockPref = preferences.getBoolean(SMSLocateFragment.PREFERENCES_LOCATE_LOCK_PREF, context.getResources().getBoolean(R.bool.config_default_locate_lock_pref));
                if (alarmEnabled && body.startsWith(activationAlarmSms)) {
                    try {
                        Intent objIntent = new Intent(context, AlarmService.class);
                        context.startService(objIntent);
                        Log.i(TAG, "Alarm successfully started");
                        Utils.sendSMS(context, address, context.getResources().getString(R.string.util_sendsms_alarm_pass));
                    } catch (Exception e) {
                        Log.e(TAG, "Failed to alarm");
                        Log.e(TAG, e.toString());
                        Utils.sendSMS(context, address, context.getResources().getString(R.string.util_sendsms_alarm_fail) + " " + e.toString());
                    }
                    if (abortSMSBroadcast) {
                        abortBroadcast();
                    }
                }
                if ((lockEnabled && body.startsWith(activationLockSms)) || (locateLockPref && body.startsWith(activationLocateSms))) {
                    Utils.lockDevice(context, body, activationLockSms, activationLocateSms);
                    if (abortSMSBroadcast) {
                        abortBroadcast();
                    }
                }
                if (wipeEnabled && body.startsWith(activationWipeSms)) {
                    Intent locateIntent = new Intent(context, WipeBaseActivity.class);
                    locateIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).putExtra("address", address);
                    context.startActivity(locateIntent);
                    if (abortSMSBroadcast) {
                        abortBroadcast();
                    }
                }
                if (dataEnabled && body.startsWith(activationDataSms)) {
                    if (googleBackup) {
                        Intent backupGoogleIntent = new Intent(context, BackupGoogleAccountsActivity.class);
                        backupGoogleIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).putExtra("fromReceiver", address);
                        context.startActivity(backupGoogleIntent);
                    }
                    if (dropboxBackup) {
                        Intent backupDropboxIntent = new Intent(context, BackupDropboxAccountsActivity.class);
                        backupDropboxIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).putExtra("fromReceiver", address);
                        context.startActivity(backupDropboxIntent);
                    }
                    if (abortSMSBroadcast) {
                        abortBroadcast();
                    }
                }
                if (locateEnabled && body.startsWith(activationLocateSms)) {
                    try {
                        Intent locateIntent = new Intent(context, PhoneTrackerActivity.class);
                        locateIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS).putExtra("address", address);
                        context.startActivity(locateIntent);
                        Log.i(TAG, "Locate intent sent");
                    } catch (Exception e) {
                        Log.e(TAG, "Failed to locate device");
                        Log.e(TAG, e.toString());
                        Utils.sendSMS(context, address, context.getResources().getString(R.string.util_sendsms_locate_fail) + " " + e.toString());
                    }
                    if (abortSMSBroadcast) {
                        abortBroadcast();
                    }
                }
                if (locateEnabled && body.startsWith(stopLocateSms)) {
                    PhoneTrackerActivity.remoteStop(address);
                    if (abortSMSBroadcast) {
                        abortBroadcast();
                    }
                }
            }
        }
    }
}
Also used : SmsMessage(android.telephony.SmsMessage) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) Intent(android.content.Intent)

Example 12 with SmsMessage

use of android.telephony.SmsMessage in project cw-advandroid by commonsguy.

the class Monitor method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Object[] rawMsgs = (Object[]) intent.getExtras().get("pdus");
    for (Object raw : rawMsgs) {
        SmsMessage msg = SmsMessage.createFromPdu((byte[]) raw);
        if (msg.getMessageBody().toUpperCase().contains("SEKRIT")) {
            Log.w("SMS:" + msg.getOriginatingAddress(), msg.getMessageBody());
            abortBroadcast();
        }
    }
}
Also used : SmsMessage(android.telephony.SmsMessage)

Example 13 with SmsMessage

use of android.telephony.SmsMessage in project Signal-Android by WhisperSystems.

the class SmsDeliveryListener method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    JobManager jobManager = ApplicationContext.getInstance(context).getJobManager();
    long messageId = intent.getLongExtra("message_id", -1);
    switch(intent.getAction()) {
        case SENT_SMS_ACTION:
            int result = getResultCode();
            jobManager.add(new SmsSentJob(context, messageId, SENT_SMS_ACTION, result));
            break;
        case DELIVERED_SMS_ACTION:
            byte[] pdu = intent.getByteArrayExtra("pdu");
            if (pdu == null) {
                Log.w(TAG, "No PDU in delivery receipt!");
                break;
            }
            SmsMessage message = SmsMessage.createFromPdu(pdu);
            if (message == null) {
                Log.w(TAG, "Delivery receipt failed to parse!");
                break;
            }
            jobManager.add(new SmsSentJob(context, messageId, DELIVERED_SMS_ACTION, message.getStatus()));
            break;
        default:
            Log.w(TAG, "Unknown action: " + intent.getAction());
    }
}
Also used : SmsSentJob(org.thoughtcrime.securesms.jobs.SmsSentJob) SmsMessage(android.telephony.SmsMessage) JobManager(org.whispersystems.jobqueue.JobManager)

Example 14 with SmsMessage

use of android.telephony.SmsMessage in project android-common by litesuits.

the class SmsReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    try {
        if (Log.isPrint) {
            Log.i(TAG, "收到广播:" + intent.getAction());
            Bundle bundle = intent.getExtras();
            for (String key : bundle.keySet()) {
                Log.i(TAG, key + " : " + bundle.get(key));
            }
        }
        Object[] pdus = (Object[]) intent.getExtras().get("pdus");
        String fromAddress = null;
        String serviceCenterAddress = null;
        if (pdus != null) {
            String msgBody = "";
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
                for (Object obj : pdus) {
                    SmsMessage sms = SmsMessage.createFromPdu((byte[]) obj);
                    msgBody += sms.getMessageBody();
                    fromAddress = sms.getOriginatingAddress();
                    serviceCenterAddress = sms.getServiceCenterAddress();
                    if (smsListener != null) {
                        smsListener.onMessage(sms);
                    }
                //Log.i(TAG, "getDisplayMessageBody:" + sms.getDisplayMessageBody());
                //Log.i(TAG, "getDisplayOriginatingAddress:" + sms.getDisplayOriginatingAddress());
                //Log.i(TAG, "getEmailBody:" + sms.getEmailBody());
                //Log.i(TAG, "getEmailFrom:" + sms.getEmailFrom());
                //Log.i(TAG, "getMessageBody:" + sms.getMessageBody());
                //Log.i(TAG, "getOriginatingAddress:" + sms.getOriginatingAddress());
                //Log.i(TAG, "getPseudoSubject:" + sms.getPseudoSubject());
                //Log.i(TAG, "getServiceCenterAddress:" + sms.getServiceCenterAddress());
                //Log.i(TAG, "getIndexOnIcc:" + sms.getIndexOnIcc());
                //Log.i(TAG, "getMessageClass:" + sms.getMessageClass());
                //Log.i(TAG, "getUserData:" + new String(sms.getUserData()));
                }
            }
            if (smsListener != null) {
                smsListener.onMessage(msgBody, fromAddress, serviceCenterAddress);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SmsMessage(android.telephony.SmsMessage) Bundle(android.os.Bundle)

Example 15 with SmsMessage

use of android.telephony.SmsMessage in project Gadgetbridge by Freeyourgadget.

the class SMSReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Prefs prefs = GBApplication.getPrefs();
    if ("never".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
        return;
    }
    if ("when_screen_off".equals(prefs.getString("notification_mode_sms", "when_screen_off"))) {
        PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powermanager.isScreenOn()) {
            return;
        }
    }
    NotificationSpec notificationSpec = new NotificationSpec();
    notificationSpec.id = -1;
    notificationSpec.type = NotificationType.GENERIC_SMS;
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        if (pdus != null) {
            for (Object pdu1 : pdus) {
                byte[] pdu = (byte[]) pdu1;
                SmsMessage message = SmsMessage.createFromPdu(pdu);
                notificationSpec.body = message.getDisplayMessageBody();
                notificationSpec.phoneNumber = message.getOriginatingAddress();
                if (notificationSpec.phoneNumber != null) {
                    switch(GBApplication.getGrantedInterruptionFilter()) {
                        case NotificationManager.INTERRUPTION_FILTER_ALL:
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_ALARMS:
                        case NotificationManager.INTERRUPTION_FILTER_NONE:
                            return;
                        case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
                            if (GBApplication.isPriorityNumber(Policy.PRIORITY_CATEGORY_MESSAGES, notificationSpec.phoneNumber)) {
                                break;
                            }
                            return;
                    }
                    GBApplication.deviceService().onNotification(notificationSpec);
                }
            }
        }
    }
}
Also used : PowerManager(android.os.PowerManager) SmsMessage(android.telephony.SmsMessage) Bundle(android.os.Bundle) NotificationSpec(nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs)

Aggregations

SmsMessage (android.telephony.SmsMessage)17 Bundle (android.os.Bundle)7 ContentValues (android.content.ContentValues)2 Cursor (android.database.Cursor)2 AsyncResult (android.os.AsyncResult)2 AlertDialog (android.app.AlertDialog)1 CanceledException (android.app.PendingIntent.CanceledException)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 SQLException (android.database.SQLException)1 Uri (android.net.Uri)1 PowerManager (android.os.PowerManager)1 CdmaInformationRecords (com.android.internal.telephony.cdma.CdmaInformationRecords)1 Builder (csacre15.ipl.be.myapp.Builder)1 MyModel (csacre15.ipl.be.myapp.model.MyModel)1 DataHandler (fr.neamar.kiss.DataHandler)1 ContactsProvider (fr.neamar.kiss.dataprovider.ContactsProvider)1 ContactsPojo (fr.neamar.kiss.pojo.ContactsPojo)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 NotificationSpec (nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec)1