Skip to content

Commit

Permalink
Add support for Android 6
Browse files Browse the repository at this point in the history
  • Loading branch information
oaliaga committed Jan 27, 2016
1 parent aea92a6 commit 3a27979
Show file tree
Hide file tree
Showing 41 changed files with 1,010 additions and 229 deletions.
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@
android:name="com.prey.activities.DeviceReadyActivity"
android:configChanges="keyboardHidden|orientation"
android:noHistory="true"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light" />





<activity
android:name=".activities.TourActivity1"
Expand Down
31 changes: 18 additions & 13 deletions app/src/main/java/com/prey/PreyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@
******************************************************************************/
package com.prey;

import android.Manifest;
import android.app.Application;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.v4.content.PermissionChecker;

import com.prey.actions.geofences.GeofenceController;
import com.prey.actions.report.ReportScheduled;
import com.prey.activities.DeviceReadyActivity;
import com.prey.net.PreyWebServices;

import java.util.Date;
import java.util.Locale;

public class PreyApp extends Application {

Expand All @@ -22,7 +29,7 @@ public class PreyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
try{
try {
mLastPause = 0;
PreyLogger.d("__________________");
PreyLogger.i("Application launched!");
Expand All @@ -32,30 +39,25 @@ public void onCreate() {
if (deviceKey != null && deviceKey != "") {
PreyConfig.getPreyConfig(this).registerC2dm();
}

if (PreyConfig.getPreyConfig(this).isMissing()) {
if (PreyConfig.getPreyConfig(this).getIntervalReport() != null && !"".equals(PreyConfig.getPreyConfig(this).getIntervalReport())) {
ReportScheduled.getInstance(this).run();
}
}

PreyLogger.d("InstallationDate:" + PreyConfig.getPreyConfig(this).getInstallationDate());
if(PreyConfig.getPreyConfig(this).getInstallationDate()==0) {
if (PreyConfig.getPreyConfig(this).getInstallationDate() == 0) {
PreyConfig.getPreyConfig(this).setInstallationDate(new Date().getTime());
PreyWebServices.getInstance().sendEvent(this, PreyConfig.ANDROID_INIT);
}

String sessionId = PreyUtils.randomAlphaNumeric(16);
PreyLogger.d("#######sessionId:" + sessionId);
PreyConfig.getPreyConfig(this).setSessionId(sessionId);
String PreyVersion=PreyConfig.getPreyConfig(this).getPreyVersion();
String preferencePreyVersion=PreyConfig.getPreyConfig(this).getPreferencePreyVersion(); ;
if(PreyVersion.equals(preferencePreyVersion)) {
String PreyVersion = PreyConfig.getPreyConfig(this).getPreyVersion();
String preferencePreyVersion = PreyConfig.getPreyConfig(this).getPreferencePreyVersion();
if (PreyVersion.equals(preferencePreyVersion)) {
PreyConfig.getPreyConfig(this).setPreferencePreyVersion(PreyVersion);
PreyWebServices.getInstance().sendEvent(this, PreyConfig.ANDROID_VERSION_UPDATED);
}


if (deviceKey != null && deviceKey != "") {
PreyConfig.getPreyConfig(this).registerC2dm();
new Thread() {
Expand All @@ -64,7 +66,10 @@ public void run() {
}
}.start();
}

}catch(Exception e){}
} catch (Exception e) {
PreyLogger.e("Error PreyApp:" + e.getMessage(), e);
}
}


}
99 changes: 75 additions & 24 deletions app/src/main/java/com/prey/PreyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

package com.prey;

import android.*;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.content.PermissionChecker;
import android.telephony.TelephonyManager;

import com.google.android.gms.common.ConnectionResult;
Expand Down Expand Up @@ -52,7 +55,7 @@ public class PreyConfig {
// max "age" in ms of last location (default 120000).
public static final long LAST_LOCATION_MAX_AGE = 30 * MILLISECONDS_PER_SECOND;

public static final int LOCATION_PRIORITY = LocationRequest.PRIORITY_HIGH_ACCURACY;
public static final int LOCATION_PRIORITY_HIGHT = LocationRequest.PRIORITY_HIGH_ACCURACY;

public static final long FASTEST_INTERVAL = 40 * MILLISECONDS_PER_SECOND;

Expand Down Expand Up @@ -124,6 +127,14 @@ public class PreyConfig {
public static final String SIM_SERIAL_NUMBER = "SIM_SERIAL_NUMBER";
public static final String VERSION_PREY_DEFAULT="1.5.2";

public static final String CAN_ACCESS_FINE_LOCATION = "CAN_ACCESS_FINE_LOCATION";
public static final String CAN_ACCESS_COARSE_LOCATION = "CAN_ACCESS_COARSE_LOCATION";
public static final String CAN_ACCESS_CAMARA = "CAN_ACCESS_CAMARA";
public static final String CAN_ACCESS_READ_PHONE_STATE = "CAN_ACCESS_READ_PHONE_STATE";


public static final int NOTIFY_ANDROID_6 = 6;

private boolean securityPrivilegesAlreadyPrompted;

private Context ctx;
Expand Down Expand Up @@ -254,16 +265,50 @@ public boolean getProtectTour() {
}



public void setCanAccessFineLocation(boolean canAccessFineLocation) {
this.saveBoolean(PreyConfig.CAN_ACCESS_FINE_LOCATION, canAccessFineLocation);
}

public boolean canAccessFineLocation() {
return getBoolean(PreyConfig.CAN_ACCESS_FINE_LOCATION, false);
}

public void setCanAccessCoarseLocation(boolean canAccessCoarseLocation) {
this.saveBoolean(PreyConfig.CAN_ACCESS_COARSE_LOCATION, canAccessCoarseLocation);
}

public boolean canAccessCoarseLocation() {
return getBoolean(PreyConfig.CAN_ACCESS_COARSE_LOCATION, false);
}

public void setCanAccessCamara(boolean canAccessCamara) {
this.saveBoolean(PreyConfig.CAN_ACCESS_CAMARA, canAccessCamara);
}

public boolean canAccessCamara() {
return getBoolean(PreyConfig.CAN_ACCESS_CAMARA, false);
}

public void setCanAccessReadPhoneState(boolean canAccessReadPhoneState) {
this.saveBoolean(PreyConfig.CAN_ACCESS_READ_PHONE_STATE, canAccessReadPhoneState);
}

public boolean canAccessReadPhoneState() {
return getBoolean(PreyConfig.CAN_ACCESS_READ_PHONE_STATE, false);
}


public String getApiKey(){
return getString(PreyConfig.API_KEY, null);
}

public void setApiKey(String apikey){
this.saveString(PreyConfig.API_KEY,apikey);
this.saveString(PreyConfig.API_KEY, apikey);
}

public String getDeviceId(){
return getString(PreyConfig.DEVICE_ID,null);
return getString(PreyConfig.DEVICE_ID, null);
}

public void setDeviceId(String deviceId){
Expand All @@ -290,23 +335,27 @@ public String getPreyVersion() {
}

public boolean isFroyoOrAbove() {
return android.os.Build.VERSION.SDK_INT> Build.VERSION_CODES.FROYO;
return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
}

public boolean isGingerbreadOrAbove() {
return android.os.Build.VERSION.SDK_INT> Build.VERSION_CODES.GINGERBREAD;
return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
}

public boolean isIceCreamSandwichOrAbove() {
return android.os.Build.VERSION.SDK_INT> Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
}

public boolean isEclairOrAbove(){
return android.os.Build.VERSION.SDK_INT> Build.VERSION_CODES.ECLAIR;
return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR;
}

public boolean isCupcakeOrAbove() {
return android.os.Build.VERSION.SDK_INT> Build.VERSION_CODES.CUPCAKE;
return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.CUPCAKE;
}

public boolean isMarshmallowOrAbove() {
return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}

public String getLastEvent() {
Expand Down Expand Up @@ -347,8 +396,8 @@ public boolean isThisDeviceAlreadyRegisteredWithPrey() {
}

public boolean isSimChanged() {
TelephonyManager telephonyManager = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
String simSerial=telephonyManager.getSimSerialNumber();

String simSerial=new PreyPhone(ctx).getSimSerialNumber();
PreyLogger.i("simSerial:" + simSerial + " actual:" + getSimSerialNumber());
if (getSimSerialNumber()==null||"".equals(getSimSerialNumber())){
if(simSerial!=null&&!"".equals(simSerial)){
Expand Down Expand Up @@ -395,8 +444,11 @@ public void setRun(boolean run) {
public void registerC2dm(){
boolean error=false;

if (PreyEmail.getEmail(this.ctx) != null) {
PreyLogger.i("c2dm:"+PreyEmail.getEmail(this.ctx));

// if (PreyEmail.getEmail(this.ctx) != null) {
String deviceId = PreyConfig.getPreyConfig(ctx).getDeviceId();
PreyLogger.i("deviceId:"+deviceId);
if (deviceId != null && !"".equals(deviceId)) {
try {

Expand All @@ -419,7 +471,7 @@ public void registerC2dm(){

if (error) {
try {
if (PreyEmail.getEmail(this.ctx) != null) {
// if (PreyEmail.getEmail(this.ctx) != null) {
PreyLogger.d("______________________");
PreyLogger.d("___ registerC2dm 2_____");

Expand All @@ -430,14 +482,14 @@ public void registerC2dm(){


PreyLogger.d("______________________");
}
// }
} catch (Exception e) {
PreyLogger.e("Error :" + e.getMessage(), e);

}
}
}
}
// }


}
Expand Down Expand Up @@ -567,7 +619,7 @@ public String getEmail() {
return getString(PreyConfig.EMAIL, "");
}

public void setEmail(String email){
public void setEmail(String email) {
saveString(PreyConfig.EMAIL, email);
}

Expand All @@ -577,7 +629,7 @@ public void setAccountVerified() {


public boolean isSendData(){
return getBoolean(PreyConfig.SEND_DATA,false);
return getBoolean(PreyConfig.SEND_DATA, false);
}

public void setSendData(boolean sendData) {
Expand All @@ -596,18 +648,14 @@ public void saveAccount(PreyAccountData accountData) {
}

public void saveSimInformation() {
TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
String simSerial=telephonyManager.getSimSerialNumber();
String simSerial=new PreyPhone(ctx).getSimSerialNumber();
if (simSerial !=null){
this.setSimSerialNumber(simSerial);
}
this.saveString(PreyConfig.PREFS_SIM_SERIAL_NUMBER, this.getSimSerialNumber());
PreyLogger.d("SIM Serial number stored: " + this.getSimSerialNumber());
}




public boolean isMissing() {
return getBoolean(PreyConfig.PREFS_IS_MISSING, false);
}
Expand Down Expand Up @@ -750,11 +798,11 @@ public void setPinNumber(int pin){
saveInt(PreyConfig.PIN_NUMBER, pin);
}

public int getPinNumber(){
return getInt(PreyConfig.PIN_NUMBER,-1);
public int getPinNumber() {
return getInt(PreyConfig.PIN_NUMBER, -1);
}

public void setSmsCommand(boolean smsCommand){
public void setSmsCommand(boolean smsCommand) {
saveBoolean(PreyConfig.SMS_COMMAND, smsCommand);
}

Expand All @@ -781,4 +829,7 @@ public boolean isLocationLowBattery() {
public int getGeofenceMaximumAccuracy(){
return FileConfigReader.getInstance(this.ctx).getGeofenceMaximumAccuracy();
}



}
9 changes: 9 additions & 0 deletions app/src/main/java/com/prey/PreyEmail.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public static String getEmail(Context context) {
Account account = getAccount(context,accountManager);
if (account != null) {
return account.name;
}else{
PreyLogger.i("account nulo");
}

}else{
PreyLogger.i("sdk menor");
}
return null;

Expand All @@ -63,7 +68,11 @@ private static Account getAccount(Context context,AccountManager accountManager)
Account[] accounts = accountManager.getAccountsByType("com.google");
if (accounts.length > 0) {
return accounts[0];
}else{
PreyLogger.i("account length 0");
}
}else {
PreyLogger.i("account bajo eckair");
}
return null;
}
Expand Down
Loading

0 comments on commit 3a27979

Please sign in to comment.