Android Open Source - Aegis S I M State Receiver






From Project

Back to project page Aegis.

License

The source code is released under:

GNU General Public License

If you think the Android project Aegis listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.decad3nce.aegis;
/*w w  w .j  a  va 2  s. c  om*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.decad3nce.aegis.Fragments.AdvancedSettingsFragment;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class SIMStateReceiver extends BroadcastReceiver {
    private static final String TAG = "aeGis";
    
    private static final String ACTION_SIM_STATE_CHANGED = "android.intent.action.SIM_STATE_CHANGED";
    private static final String EXTRAS_SIM_STATUS = "ss";
    private Context mContext;

    @Override
    public void onReceive(Context context, Intent intent) {
        mContext = context;
        final SharedPreferences preferences = PreferenceManager
                .getDefaultSharedPreferences(context);
        String address = preferences
                .getString(AdvancedSettingsFragment.PREFERENCES_BACKUP_PHONE_NUMBER, context.getResources()
                        .getString(R.string.config_default_advanced_backup_phone_number));
        if (intent.getAction().equals(ACTION_SIM_STATE_CHANGED)) {
            Log.v(TAG, "SIM STATUS CHANGED");
            Bundle extras = intent.getExtras();
            
            if(extras != null) {
                String ss = extras.getString(EXTRAS_SIM_STATUS);
                
                if(ss.equals("ABSENT")) {
                    Log.v(TAG, "SIM IS ABSENT");
                } else if (ss.equals("IMSI") || ss.equals("LOADED")) {
                    Log.v(TAG, "SIM IS PRIMED");
                    TelephonyManager mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                    String imsi = mTelephonyManager.getSubscriberId();
                    if(isInList(imsi)) {
                        Log.v(TAG, "SIM ACCEPTED");
                    } else {
                        Utils.lockDeviceDefault(context);
                        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());
                        }
                        Log.v(TAG, "SIM NOT IN LIST, LOCK IT AND TRACK IT TO BACKUP NUMBER!");
                    }
                    Log.v(TAG, "SIM IMSI " + imsi);
                } else {
                    Log.v(TAG, "SIM IS " + ss);
                }
            }
        }
        
    }

    /*
     * But really, should make this logic a bit better. Empty arraylist just passes through.
     * If the device doesn't actually give a proper imsi from the new SIM card, then it's wide open
     * to usage.
     */
    private boolean isInList(String imsi) {
        ArrayList<String> identifiers;
        Set<String> set = getList();
        if(set == null) {
            identifiers = new ArrayList<String>();
        } else {
            identifiers = new ArrayList<String>(set);
        }

        if(identifiers == null)
            return true;

        if(identifiers.contains(imsi) || identifiers.isEmpty()) {
            return true;
        }
        return false;
    }

    private Set<String> getList() {
        Set<String> set = new HashSet<String>();
        SharedPreferences prefs = mContext.getSharedPreferences("imsi_list", 0);
        set = prefs.getStringSet("identifiers", null);
        if(set == null)
            return null;
        Log.v(TAG, set.toString());
        return set;
    }
}




Java Source Code List

com.decad3nce.aegis.AegisActivity.java
com.decad3nce.aegis.AlarmService.java
com.decad3nce.aegis.BackupDropboxAccountsActivity.java
com.decad3nce.aegis.BackupGoogleAccountsActivity.java
com.decad3nce.aegis.BackupUtils.java
com.decad3nce.aegis.DeviceAdmin.java
com.decad3nce.aegis.DialerCodeReceiver.java
com.decad3nce.aegis.DrawerLayoutAdapter.java
com.decad3nce.aegis.FontAdapter.java
com.decad3nce.aegis.LoginActivity.java
com.decad3nce.aegis.PhoneTrackerActivity.java
com.decad3nce.aegis.RegisterActivity.java
com.decad3nce.aegis.RootTask.java
com.decad3nce.aegis.SIMStateReceiver.java
com.decad3nce.aegis.SMSReceiver.java
com.decad3nce.aegis.Utils.java
com.decad3nce.aegis.WipeBaseActivity.java
com.decad3nce.aegis.WipeTask.java
com.decad3nce.aegis.Fragments.AboutFragment.java
com.decad3nce.aegis.Fragments.AdvancedSettingsFragment.java
com.decad3nce.aegis.Fragments.BackupAccountsDialogFragment.java
com.decad3nce.aegis.Fragments.ChooseBackupProgramDialogFragment.java
com.decad3nce.aegis.Fragments.InstallToSystemDialogFragment.java
com.decad3nce.aegis.Fragments.SIMListFragment.java
com.decad3nce.aegis.Fragments.SMSAlarmFragment.java
com.decad3nce.aegis.Fragments.SMSDataFragment.java
com.decad3nce.aegis.Fragments.SMSLocateFragment.java
com.decad3nce.aegis.Fragments.SMSLockFragment.java
com.decad3nce.aegis.Fragments.SMSWipeFragment.java