Fix lint security issues

pull/384/head
Alex Baker 9 years ago
parent 9dbc4041ec
commit 97ab2ec235

@ -20,6 +20,7 @@ import com.todoroo.andlib.utility.DateUtilities;
import org.tasks.Notifier;
import org.tasks.injection.BroadcastComponent;
import org.tasks.injection.InjectingBroadcastReceiver;
import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
@ -34,6 +35,7 @@ public class PhoneStateChangedReceiver extends InjectingBroadcastReceiver {
@Inject Preferences preferences;
@Inject Notifier notifier;
@Inject PermissionChecker permissionChecker;
@Override
public void onReceive(final Context context, Intent intent) {
@ -67,24 +69,12 @@ public class PhoneStateChangedReceiver extends InjectingBroadcastReceiver {
AndroidUtilities.sleepDeep(WAIT_BEFORE_READ_LOG);
Cursor calls;
try {
calls = context.getContentResolver().query(
Calls.CONTENT_URI,
new String[] { Calls.NUMBER, Calls.DATE, Calls.CACHED_NAME },
Calls.TYPE + " = ? AND " + Calls.NEW + " = ?",
new String[] { Integer.toString(Calls.MISSED_TYPE), "1" },
Calls.DATE + " DESC"
);
calls = getMissedCalls(context);
} catch (Exception e) { // Sometimes database is locked, retry once
Timber.e(e, e.getMessage());
AndroidUtilities.sleepDeep(300L);
try {
calls = context.getContentResolver().query(
Calls.CONTENT_URI,
new String[] { Calls.NUMBER, Calls.DATE, Calls.CACHED_NAME },
Calls.TYPE + " = ? AND " + Calls.NEW + " = ?",
new String[] { Integer.toString(Calls.MISSED_TYPE), "1" },
Calls.DATE + " DESC"
);
calls = getMissedCalls(context);
} catch (Exception e2) {
Timber.e(e2, e2.getMessage());
calls = null;
@ -133,6 +123,20 @@ public class PhoneStateChangedReceiver extends InjectingBroadcastReceiver {
}
}
private Cursor getMissedCalls(Context context) {
if (permissionChecker.canAccessMissedCallPermissions()) {
//noinspection MissingPermission
return context.getContentResolver().query(
Calls.CONTENT_URI,
new String[]{Calls.NUMBER, Calls.DATE, Calls.CACHED_NAME},
Calls.TYPE + " = ? AND " + Calls.NEW + " = ?",
new String[]{Integer.toString(Calls.MISSED_TYPE), "1"},
Calls.DATE + " DESC"
);
}
return null;
}
@Override
protected void inject(BroadcastComponent component) {
component.inject(this);

@ -21,6 +21,7 @@ import org.tasks.R;
import org.tasks.calendars.AndroidCalendar;
import org.tasks.calendars.CalendarProvider;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.Preferences;
import java.util.TimeZone;
@ -37,14 +38,16 @@ public class GCalHelper {
private final TaskService taskService;
private final Preferences preferences;
private final CalendarProvider calendarProvider;
private PermissionChecker permissionChecker;
private final ContentResolver cr;
@Inject
public GCalHelper(@ForApplication Context context, TaskService taskService, Preferences preferences,
CalendarProvider calendarProvider) {
CalendarProvider calendarProvider, PermissionChecker permissionChecker) {
this.taskService = taskService;
this.preferences = preferences;
this.calendarProvider = calendarProvider;
this.permissionChecker = permissionChecker;
cr = context.getContentResolver();
}
@ -84,13 +87,17 @@ public class GCalHelper {
}
public Uri createTaskEvent(Task task, ContentValues values, boolean deleteEventIfExists) {
if (!permissionChecker.canAccessCalendars()) {
return null;
}
String eventuri = getTaskEventUri(task);
if(!TextUtils.isEmpty(eventuri) && deleteEventIfExists) {
deleteTaskEvent(task);
}
try{
try {
values.put(CalendarContract.Events.TITLE, task.getTitle());
values.put(CalendarContract.Events.DESCRIPTION, task.getNotes());
values.put(CalendarContract.Events.HAS_ALARM, 0);
@ -105,11 +112,11 @@ public class GCalHelper {
createStartAndEndDate(task, values);
//noinspection MissingPermission
Uri eventUri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
cr.notifyChange(eventUri, null);
return eventUri;
} catch (Exception e) {
// won't work on emulator
Timber.e(e, e.getMessage());

Loading…
Cancel
Save