// Path: Seraphimdroid/app/src/main/java/org/owasp/seraphimdroid/services/SIMCheckService.java
// public class SIMCheckService extends IntentService {
// 
// 	String idSIM1;
// 	int idSIM2;
// 	Boolean isSIM1Detected, isSIM2Detected;
// 	Context context;
// 	static TelephonyManager telephony;
// 	SharedPreferences defaultPrefs;
// 	
// 	public SIMCheckService() {
// 		super("SIMCheckService");
// 	}
// 
// 	@Override
// 	protected void onHandleIntent(Intent intent) {
// 		
// 		context = getApplicationContext();
// 		telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// 		defaultPrefs = PreferenceManager.getDefaultSharedPreferences(context);
// 		
// //		isSIM1Detected = telephony.getDataState()==telephony.SIM_STATE_READY;
// 		if(telephony.getSimSerialNumber()!=null) {
// 			idSIM1 = telephony.getSimSerialNumber() + telephony.getNetworkOperator() + telephony.getNetworkCountryIso();
// 		}
//         
//         String oldSIM1 = null;
//         if(defaultPrefs.contains("sim_1")) {
//         	oldSIM1 = defaultPrefs.getString("sim_1", "");
//         }
//         
//         //SIM not found
//         if(idSIM1==null) return;
//         
//         //SIM Check
//         if(oldSIM1==null || (wasPresent(idSIM1, oldSIM1)==false)) {
//         	//show lock
//         	Toast.makeText(getApplicationContext(), "SIM Change Detected", Toast.LENGTH_SHORT).show();
//         	showLock(idSIM1);
//         	return;
//         }
//                 
// 	}
// 	
// 	private Boolean wasPresent(String id, String oldSIM) {
// 		if(oldSIM!=null ) {
// 			if(oldSIM.equals(id+"")) {
// 				return true;
// 			}
// 			return false;
// 		}
// 		return false;
// 	}
// 	
// 	private void showLock(final String id) {
// 		Intent passwordAct = new Intent(context, PasswordActivity.class);
// 		passwordAct.putExtra("PACKAGE_NAME", "SIM Change");
// 		passwordAct.putExtra("device_id", id+"");
// 		passwordAct.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
// 		context.startActivity(passwordAct);
// 	}
// 
// }


import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.owasp.seraphimdroid.services.SIMCheckService;
package org.owasp.seraphimdroid.receiver;



public class BootReceiver extends BroadcastReceiver {

	private AlarmManager alarmMgr;
	private PendingIntent alarmIntent;
	
	@Override
	public void onReceive(Context context, Intent arg1) {
		if (Intent.ACTION_BOOT_COMPLETED.equals(arg1.getAction())) {
			//Alarm Manager for Settings Check
			alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
			Intent intent = new Intent(context, SettingsCheckAlarmReceiver.class);
			alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

			SharedPreferences defaults = PreferenceManager
					.getDefaultSharedPreferences(context);
			
			java.util.Calendar calendar = java.util.Calendar.getInstance();
			calendar.setTimeInMillis(System.currentTimeMillis());
			//Run at Midnight
			calendar.set(java.util.Calendar.HOUR_OF_DAY, 0);
			calendar.set(java.util.Calendar.MINUTE, 0);

			alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
			        defaults.getInt("settings_interval", 24*60*60*1000), alarmIntent);
			
			//SIM Card Service
// Path: Seraphimdroid/app/src/main/java/org/owasp/seraphimdroid/services/SIMCheckService.java
// public class SIMCheckService extends IntentService {
// 
// 	String idSIM1;
// 	int idSIM2;
// 	Boolean isSIM1Detected, isSIM2Detected;
// 	Context context;
// 	static TelephonyManager telephony;
// 	SharedPreferences defaultPrefs;
// 	
// 	public SIMCheckService() {
// 		super("SIMCheckService");
// 	}
// 
// 	@Override
// 	protected void onHandleIntent(Intent intent) {
// 		
// 		context = getApplicationContext();
// 		telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// 		defaultPrefs = PreferenceManager.getDefaultSharedPreferences(context);
// 		
// //		isSIM1Detected = telephony.getDataState()==telephony.SIM_STATE_READY;
// 		if(telephony.getSimSerialNumber()!=null) {
// 			idSIM1 = telephony.getSimSerialNumber() + telephony.getNetworkOperator() + telephony.getNetworkCountryIso();
// 		}
//         
//         String oldSIM1 = null;
//         if(defaultPrefs.contains("sim_1")) {
//         	oldSIM1 = defaultPrefs.getString("sim_1", "");
//         }
//         
//         //SIM not found
//         if(idSIM1==null) return;
//         
//         //SIM Check
//         if(oldSIM1==null || (wasPresent(idSIM1, oldSIM1)==false)) {
//         	//show lock
//         	Toast.makeText(getApplicationContext(), "SIM Change Detected", Toast.LENGTH_SHORT).show();
//         	showLock(idSIM1);
//         	return;
//         }
//                 
// 	}
// 	
// 	private Boolean wasPresent(String id, String oldSIM) {
// 		if(oldSIM!=null ) {
// 			if(oldSIM.equals(id+"")) {
// 				return true;
// 			}
// 			return false;
// 		}
// 		return false;
// 	}
// 	
// 	private void showLock(final String id) {
// 		Intent passwordAct = new Intent(context, PasswordActivity.class);
// 		passwordAct.putExtra("PACKAGE_NAME", "SIM Change");
// 		passwordAct.putExtra("device_id", id+"");
// 		passwordAct.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
// 		context.startActivity(passwordAct);
// 	}
// 
// }


// Path: Seraphimdroid/app/src/main/java/org/owasp/seraphimdroid/receiver/BootReceiver.java
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.owasp.seraphimdroid.services.SIMCheckService;

package org.owasp.seraphimdroid.receiver;



public class BootReceiver extends BroadcastReceiver {

	private AlarmManager alarmMgr;
	private PendingIntent alarmIntent;
	
	@Override
	public void onReceive(Context context, Intent arg1) {
		if (Intent.ACTION_BOOT_COMPLETED.equals(arg1.getAction())) {
			//Alarm Manager for Settings Check
			alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
			Intent intent = new Intent(context, SettingsCheckAlarmReceiver.class);
			alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

			SharedPreferences defaults = PreferenceManager
					.getDefaultSharedPreferences(context);
			
			java.util.Calendar calendar = java.util.Calendar.getInstance();
			calendar.setTimeInMillis(System.currentTimeMillis());
			//Run at Midnight
			calendar.set(java.util.Calendar.HOUR_OF_DAY, 0);
			calendar.set(java.util.Calendar.MINUTE, 0);

			alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
			        defaults.getInt("settings_interval", 24*60*60*1000), alarmIntent);
			
			//SIM Card Service
			context.startService(new Intent(context, SIMCheckService.class));