Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance | Code Improvements. #130

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions app/src/main/java/com/prey/PreyConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ public class PreyConfig {

public static final String JOB_ID_LOCK="job_id_lock";

private boolean securityPrivilegesAlreadyPrompted;

private Context ctx;


Expand All @@ -173,8 +171,6 @@ public class PreyConfig {
private int timeoutReport;
private boolean runOnce;

private boolean disablePowerOptions;


private PreyConfig(Context ctx) {
this.ctx = ctx;
Expand All @@ -186,7 +182,7 @@ private PreyConfig(Context ctx) {
this.minuteScheduled=getInt(PreyConfig.MINUTE_SCHEDULED, FileConfigReader.getInstance(ctx).getMinuteScheduled());
this.timeoutReport=getInt(PreyConfig.TIMEOUT_REPORT, FileConfigReader.getInstance(ctx).getTimeoutReport());
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ctx);
this.disablePowerOptions = settings.getBoolean(PreyConfig.PREFS_DISABLE_POWER_OPTIONS, false);
boolean disablePowerOptions = settings.getBoolean(PreyConfig.PREFS_DISABLE_POWER_OPTIONS, false);

}

Expand Down Expand Up @@ -375,7 +371,7 @@ public void setNotificationAndroid7(String notificationAndroid7){
}

public void setSecurityPrivilegesAlreadyPrompted(boolean securityPrivilegesAlreadyPrompted) {
this.securityPrivilegesAlreadyPrompted = securityPrivilegesAlreadyPrompted;
boolean securityPrivilegesAlreadyPrompted1 = securityPrivilegesAlreadyPrompted;
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ctx);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(PreyConfig.PREFS_SECURITY_PROMPT_SHOWN, securityPrivilegesAlreadyPrompted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public FileretrievalDatasource(Context context) {
public void createGeofence(FileretrievalDto dto) {
try {
dbHelper.insertFileretrieval(dto);
} catch (Exception e) {;
} catch (Exception e) {
try {
dbHelper.updateFileretrieval(dto);
} catch (Exception e1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ private void deleteZones(final Context ctx) {
}
if (removeList != null && removeList.size() > 0) {
LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, removeList);
String infoDelete = "[";
StringBuilder infoDelete = new StringBuilder("[");
for (int i = 0; removeList != null && i < removeList.size(); i++) {
infoDelete += removeList.get(i);
infoDelete.append(removeList.get(i));
if (i + 1 < removeList.size()) {
infoDelete += ",";
infoDelete.append(",");
}
}
infoDelete += "]";
infoDelete.append("]");
PreyLogger.d("infoDelete:" + infoDelete);
sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "stopped", infoDelete));
sendNotify(ctx, UtilJson.makeMapParam("start", "geofencing", "stopped", infoDelete.toString()));
}
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public void run() {
private void addZones(final Context ctx) {
List<com.google.android.gms.location.Geofence> mGeofenceList = new ArrayList<Geofence>();
final List<GeofenceDto> listToBdAdd = new ArrayList<GeofenceDto>();
String infoAdd = "[";
StringBuilder infoAdd = new StringBuilder("[");
for (int i = 0; listWeb != null && i < listWeb.size(); i++) {
GeofenceDto geo = listWeb.get(i);
if (!mapBD.containsKey(geo.getId())) {
Expand All @@ -150,15 +150,15 @@ private void addZones(final Context ctx) {
.setNotificationResponsiveness(FileConfigReader.getInstance(ctx).getGeofenceNotificationResponsiveness())
.build());

infoAdd += geo.id;
infoAdd.append(geo.id);
if (i + 1 < listWeb.size()) {
infoAdd += ",";
infoAdd.append(",");
}
}
}

infoAdd += "]";
final String infoExtra = infoAdd;
infoAdd.append("]");
final String infoExtra = infoAdd.toString();
PreyLogger.d("infoAdd:" + infoExtra);

GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
Expand Down Expand Up @@ -218,7 +218,7 @@ public void init(final Context ctx) {
List<GeofenceDto> listBD = dataSource.getAllGeofences();
List<com.google.android.gms.location.Geofence> mGeofenceList = new ArrayList<Geofence>();
final List<GeofenceDto> listToBdAdd = new ArrayList<GeofenceDto>();
String info = "[";
StringBuilder info = new StringBuilder("[");
for (int i = 0; listBD != null && i < listBD.size(); i++) {
GeofenceDto geo = listBD.get(i);
listToBdAdd.add(geo);
Expand All @@ -233,13 +233,13 @@ public void init(final Context ctx) {
.setTransitionTypes(transitionTypes)
.setLoiteringDelay(FileConfigReader.getInstance(ctx).getGeofenceLoiteringDelay())
.build());
info += geo.id;
info.append(geo.id);
if (i + 1 < listBD.size()) {
info += ",";
info.append(",");
}
}
info += "]";
final String extraInfo = info;
info.append("]");
final String extraInfo = info.toString();
PreyLogger.d("info:" + extraInfo);
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GeofenceDataSource(Context context) {
public void createGeofence(GeofenceDto geofence) {
try {
dbHelper.insertGeofence(geofence);
} catch (Exception e) {;
} catch (Exception e) {
try {
dbHelper.updateGeofence(geofence);
} catch (Exception e1) {
Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/com/prey/actions/geofences/GeofenceDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ public class GeofenceDto implements Comparable {
public int expires;

public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("id:").append(id);
sb.append(" name:").append(name);
sb.append(" latitude:").append(latitude);
sb.append(" longitude:").append(longitude);
sb.append(" radius:").append(radius);
sb.append(" expires:").append(expires).append("\n");
return sb.toString();
String sb = "id:" + id +
" name:" + name +
" latitude:" + latitude +
" longitude:" + longitude +
" radius:" + radius +
" expires:" + expires + "\n";
return sb;
}

public Geofence geofence() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ public class PreyLocationManager {
private PreyLocation lastLocation;
private static PreyLocationManager _instance = null;
private LocationManager androidLocationManager = null;
private Context ctx;

private PreyLocationManager(Context ctx) {
this.ctx = ctx;
Context ctx1 = ctx;
androidLocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/prey/actions/report/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ protected void onHandleIntent(Intent intent) {

jsonArray = new JSONArray();
if (!exclude.contains("picture"))
jsonArray.put(new String("picture"));
jsonArray.put("picture");
if (!exclude.contains("location"))
jsonArray.put(new String("location"));
jsonArray.put("location");
if (!exclude.contains("access_points_list"))
jsonArray.put(new String("access_points_list"));
jsonArray.put("access_points_list");
if (!exclude.contains("active_access_point"))
jsonArray.put(new String("active_access_point"));
jsonArray.put("active_access_point");

try {
List<ActionResult> lista = new ArrayList<ActionResult>();
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/prey/actions/sms/SMSParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public static List<JSONObject> getJSONListFromText(String command, String phoneN
json.put("options", null);
} else {
JSONObject jsonParameter = new JSONObject();
String parameter = "";
StringBuilder parameter = new StringBuilder();
for (int i = 3; listCommand != null && i < listCommand.size(); i++) {
parameter = parameter + " " + listCommand.get(i).toLowerCase();
parameter.append(" ").append(listCommand.get(i).toLowerCase());
}
parameter = parameter.trim();
jsonParameter.put("parameter", parameter);
parameter = new StringBuilder(parameter.toString().trim());
jsonParameter.put("parameter", parameter.toString());
jsonParameter.put("phoneNumber", phoneNumber);
json.put("options", jsonParameter);
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/prey/actions/wipe/WipeThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ public class WipeThread extends Thread {
private Context ctx;
private boolean wipe;
private boolean deleteSD;
private String messageId;
private String jobId;

public WipeThread(Context ctx,boolean wipe,boolean deleteSD, String messageId,String jobId) {
this.ctx = ctx;
this.deleteSD = deleteSD;
this.wipe = wipe;
this.messageId = messageId;
String messageId1 = messageId;
this.jobId = jobId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ public void onClick(DialogInterface dialog, int id) {
if (input != null) {
Context ctx = getApplicationContext();
String emailFeedback = FileConfigReader.getInstance(getApplicationContext()).getEmailFeedback();
StringBuffer subject = new StringBuffer();
subject.append(FileConfigReader.getInstance(ctx).getSubjectFeedback()).append(" ");
subject.append(PreyUtils.randomAlphaNumeric(7).toUpperCase());
String subject = FileConfigReader.getInstance(ctx).getSubjectFeedback() + " " +
PreyUtils.randomAlphaNumeric(7).toUpperCase();
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailFeedback});
intent.putExtra(Intent.EXTRA_SUBJECT, subject.toString());
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, input.getText().toString());
Intent chooser = Intent.createChooser(intent, ctx.getText(R.string.feedback_form_send_email));
startActivity(chooser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {

String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelJwt();

String postData = "token="+PreyConfig.getPreyConfig(getApplicationContext()).getTokenJwt();;
String postData = "token="+PreyConfig.getPreyConfig(getApplicationContext()).getTokenJwt();

byte[] postByte = EncodingUtils.getBytes(postData,"BASE64");
myWebView.postUrl(url,postByte);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
public class PermissionInformationActivity extends PreyActivity {

private static final int SECURITY_PRIVILEGES = 10;
private String congratsMessage;
private boolean first = false;

@Override
Expand All @@ -35,7 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Bundle bundle = getIntent().getExtras();
congratsMessage = bundle.getString("message");
String congratsMessage = bundle.getString("message");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
pSMS.setChecked(value);
pSMS.setDefaultValue(value);
if(value){
requestPermission();;
requestPermission();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class SimpleVideoActivity extends Activity implements
private SurfaceHolder mSurfaceHolder;
public static byte[] dataImagen = null;

private File directory;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -97,7 +95,6 @@ public void sendVideo(Context ctx) {
preyHttpResponse = PreyRestHttpClient
.getInstance(ctx)
.postAutentication(uri, parameters, entityFiles);
;
PreyLogger.i("status line:" + preyHttpResponse.getStatusCode());
} catch (Exception e) {
PreyLogger.e("Error causa:" + e.getMessage() + e.getMessage(), e);
Expand Down Expand Up @@ -126,7 +123,7 @@ public void takeVideo() {
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);

directory = new File(Environment.getExternalStorageDirectory()
File directory = new File(Environment.getExternalStorageDirectory()
.toString() + "/");
if (!directory.exists())
directory.mkdirs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static ArrayList<String> getSMSMessage(Object[] pdus) {
// str += " :";
// str += msgs[i].getMessageBody().toString();
// str += "\n";
smsMessages.add(msgs[i].getMessageBody().toString());
smsMessages.add(msgs[i].getMessageBody());
}
return smsMessages;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class BarcodeActivity extends Activity {
private CompoundButton autoFocus;
private CompoundButton useFlash;
private TextView statusMessage;
private TextView barcodeValue;

private static final int RC_BARCODE_CAPTURE = 9001;

Expand All @@ -48,7 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_barcode);

statusMessage = (TextView) findViewById(R.id.status_message);
barcodeValue = (TextView) findViewById(R.id.barcode_value);
TextView barcodeValue = (TextView) findViewById(R.id.barcode_value);

autoFocus = (CompoundButton) findViewById(R.id.auto_focus);
useFlash = (CompoundButton) findViewById(R.id.use_flash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ public class CameraSource {
private String mFocusMode = null;
private String mFlashMode = null;

private SurfaceView mDummySurfaceView;
private SurfaceTexture mDummySurfaceTexture;


private Thread mProcessingThread;
private FrameProcessingRunnable mFrameProcessor;
Expand Down Expand Up @@ -193,10 +190,10 @@ public CameraSource start() throws IOException {


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
SurfaceTexture mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME);
mCamera.setPreviewTexture(mDummySurfaceTexture);
} else {
mDummySurfaceView = new SurfaceView(mContext);
SurfaceView mDummySurfaceView = new SurfaceView(mContext);
mCamera.setPreviewDisplay(mDummySurfaceView.getHolder());
}
mCamera.startPreview();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void run() {
PreyLogger.d("LocationLowBatteryRunner");
try {
String jsonString = "[ {\"command\": \"get\",\"target\": \"location_low_battery\",\"options\": {}}]";
List<JSONObject> jsonObjectList = new JSONParser().getJSONFromTxt(ctx, jsonString.toString());
List<JSONObject> jsonObjectList = new JSONParser().getJSONFromTxt(ctx, jsonString);
if (jsonObjectList != null && jsonObjectList.size() > 0) {
ActionsController.getInstance(ctx).runActionJson(ctx, jsonObjectList);
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/prey/json/actions/PrivateIp.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public HttpDataService run(Context ctx, List<ActionResult> list, JSONObject para
String privateIp = phone.getWifi().getIpAddress();
parametersMap.put(privateIp, privateIp);
PreyLogger.d("privateIp:" + privateIp);
;

data.setSingleData(privateIp);

Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/prey/managers/PreyWindowsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class PreyWindowsManager {

private static PreyWindowsManager _instance = null;

private WindowManager window=null;
private int width = 0;
private int height = 0;

Expand All @@ -26,7 +25,7 @@ public static PreyWindowsManager getInstance(Context ctx){
return _instance;
}
private PreyWindowsManager(Context ctx) {
window = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
WindowManager window = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Display display = window.getDefaultDisplay();
width = display.getWidth();
height = display.getHeight();
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/prey/net/PreyRestHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

public class PreyRestHttpClient {

private static PreyRestHttpClient _instance = null;
private Context ctx = null;

private PreyRestHttpClient(Context ctx) {
Expand All @@ -38,7 +37,7 @@ private PreyRestHttpClient(Context ctx) {

public static PreyRestHttpClient getInstance(Context ctx) {

_instance = new PreyRestHttpClient(ctx);
PreyRestHttpClient _instance = new PreyRestHttpClient(ctx);
return _instance;

}
Expand Down
Loading