Skip to content

Commit

Permalink
Fix #464: add PackageName to all broadcasted intents
Browse files Browse the repository at this point in the history
  • Loading branch information
Binnette committed Nov 27, 2024
1 parent a0bef4b commit 1f74916
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
25 changes: 15 additions & 10 deletions app/src/main/java/net/osmtracker/service/gps/GPSLogger.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package net.osmtracker.service.gps;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.activity.TrackLogger;
import net.osmtracker.db.DataHelper;
import net.osmtracker.db.TrackContentProvider;
import net.osmtracker.listener.PressureListener;
import net.osmtracker.listener.SensorListener;

import android.Manifest;
import android.app.Notification;
import android.app.NotificationChannel;
Expand All @@ -27,9 +19,18 @@
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import android.util.Log;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.activity.TrackLogger;
import net.osmtracker.db.DataHelper;
import net.osmtracker.db.TrackContentProvider;
import net.osmtracker.listener.PressureListener;
import net.osmtracker.listener.SensorListener;

/**
* GPS logging service.
Expand Down Expand Up @@ -222,7 +223,11 @@ public void onCreate() {
filter.addAction(OSMTracker.INTENT_DELETE_WP);
filter.addAction(OSMTracker.INTENT_START_TRACKING);
filter.addAction(OSMTracker.INTENT_STOP_TRACKING);
registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(receiver, filter);
}

// Register ourselves for location updates
lmgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Expand Down
32 changes: 15 additions & 17 deletions app/src/main/java/net/osmtracker/view/TextNoteDialog.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package net.osmtracker.view;

import java.util.UUID;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -13,8 +8,12 @@
import android.view.WindowManager.LayoutParams;
import android.widget.EditText;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.db.TrackContentProvider;

import java.util.UUID;

public class TextNoteDialog extends AlertDialog {

/**
Expand Down Expand Up @@ -63,19 +62,20 @@ public TextNoteDialog(Context context, long trackId) {
this.setCancelable(true);
this.setView(input);

this.setButton(context.getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
this.setButton(context.getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Track waypoint with user input text
Intent intent = new Intent(OSMTracker.INTENT_UPDATE_WP);
intent.putExtra(TrackContentProvider.Schema.COL_TRACK_ID, TextNoteDialog.this.wayPointTrackId);
intent.putExtra(OSMTracker.INTENT_KEY_NAME, input.getText().toString());
intent.putExtra(OSMTracker.INTENT_KEY_UUID, TextNoteDialog.this.wayPointUuid);
TextNoteDialog.this.context.sendBroadcast(intent);
intent.setPackage(getContext().getPackageName());
context.sendBroadcast(intent);
}
});

this.setButton2(context.getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
this.setButton2(context.getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// cancel the dialog
Expand All @@ -89,7 +89,8 @@ public void onCancel(DialogInterface dialog) {
// delete the waypoint because user canceled this dialog
Intent intent = new Intent(OSMTracker.INTENT_DELETE_WP);
intent.putExtra(OSMTracker.INTENT_KEY_UUID, TextNoteDialog.this.wayPointUuid);
TextNoteDialog.this.context.sendBroadcast(intent);
intent.setPackage(getContext().getPackageName());
context.sendBroadcast(intent);
}
});

Expand All @@ -100,14 +101,15 @@ public void onCancel(DialogInterface dialog) {
*/
@Override
protected void onStart() {
if(wayPointUuid == null){
if (wayPointUuid == null) {
// there is no UUID set for the waypoint we're working on
// so we need to generate a UUID and track this point
wayPointUuid = UUID.randomUUID().toString();
Intent intent = new Intent(OSMTracker.INTENT_TRACK_WP);
intent.putExtra(TrackContentProvider.Schema.COL_TRACK_ID, wayPointTrackId);
intent.putExtra(OSMTracker.INTENT_KEY_UUID, wayPointUuid);
intent.putExtra(OSMTracker.INTENT_KEY_NAME, context.getResources().getString(R.string.gpsstatus_record_textnote));
intent.setPackage(getContext().getPackageName());
context.sendBroadcast(intent);
}

Expand All @@ -120,18 +122,18 @@ protected void onStart() {
* resets values of this dialog
* such as the input fields text and the waypoints uuid
*/
public void resetValues(){
public void resetValues() {
wayPointUuid = null;
input.setText("");
}

/**
* restoring values from the savedInstaceState
* restoring values from the savedInstanceState
*/
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
String text = savedInstanceState.getString(KEY_INPUT_TEXT);
if(text != null){
if (text != null) {
input.setText(text);
}
wayPointUuid = savedInstanceState.getString(KEY_WAYPOINT_UUID);
Expand All @@ -150,8 +152,4 @@ public Bundle onSaveInstanceState() {
extras.putString(KEY_WAYPOINT_UUID, wayPointUuid);
return extras;
}




}
20 changes: 11 additions & 9 deletions app/src/main/java/net/osmtracker/view/VoiceRecDialog.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package net.osmtracker.view;

import java.io.File;
import java.util.Date;
import java.util.UUID;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.db.DataHelper;
import net.osmtracker.db.TrackContentProvider.Schema;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -24,6 +15,15 @@
import android.view.KeyEvent;
import android.widget.Toast;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.db.DataHelper;
import net.osmtracker.db.TrackContentProvider.Schema;

import java.io.File;
import java.util.Date;
import java.util.UUID;

public class VoiceRecDialog extends ProgressDialog implements OnInfoListener{

private final static String TAG = VoiceRecDialog.class.getSimpleName();
Expand Down Expand Up @@ -151,6 +151,7 @@ public void onStart() {
intent.putExtra(Schema.COL_TRACK_ID, wayPointTrackId);
intent.putExtra(OSMTracker.INTENT_KEY_UUID, wayPointUuid);
intent.putExtra(OSMTracker.INTENT_KEY_NAME, context.getResources().getString(R.string.wpt_voicerec));
intent.setPackage(getContext().getPackageName());
context.sendBroadcast(intent);
}

Expand Down Expand Up @@ -215,6 +216,7 @@ public void onStart() {
intent.putExtra(Schema.COL_TRACK_ID, wayPointTrackId);
intent.putExtra(OSMTracker.INTENT_KEY_UUID, wayPointUuid);
intent.putExtra(OSMTracker.INTENT_KEY_LINK, audioFile.getName());
intent.setPackage(getContext().getPackageName());
context.sendBroadcast(intent);
} else {
Log.w(TAG,"onStart() no suitable audioFile could be created");
Expand Down

0 comments on commit 1f74916

Please sign in to comment.