Fix lint security issues

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

@ -20,6 +20,7 @@ import com.todoroo.andlib.utility.DateUtilities;
import org.tasks.Notifier; import org.tasks.Notifier;
import org.tasks.injection.BroadcastComponent; import org.tasks.injection.BroadcastComponent;
import org.tasks.injection.InjectingBroadcastReceiver; import org.tasks.injection.InjectingBroadcastReceiver;
import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
import javax.inject.Inject; import javax.inject.Inject;
@ -34,6 +35,7 @@ public class PhoneStateChangedReceiver extends InjectingBroadcastReceiver {
@Inject Preferences preferences; @Inject Preferences preferences;
@Inject Notifier notifier; @Inject Notifier notifier;
@Inject PermissionChecker permissionChecker;
@Override @Override
public void onReceive(final Context context, Intent intent) { public void onReceive(final Context context, Intent intent) {
@ -67,24 +69,12 @@ public class PhoneStateChangedReceiver extends InjectingBroadcastReceiver {
AndroidUtilities.sleepDeep(WAIT_BEFORE_READ_LOG); AndroidUtilities.sleepDeep(WAIT_BEFORE_READ_LOG);
Cursor calls; Cursor calls;
try { try {
calls = context.getContentResolver().query( calls = getMissedCalls(context);
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"
);
} catch (Exception e) { // Sometimes database is locked, retry once } catch (Exception e) { // Sometimes database is locked, retry once
Timber.e(e, e.getMessage()); Timber.e(e, e.getMessage());
AndroidUtilities.sleepDeep(300L); AndroidUtilities.sleepDeep(300L);
try { try {
calls = context.getContentResolver().query( calls = getMissedCalls(context);
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"
);
} catch (Exception e2) { } catch (Exception e2) {
Timber.e(e2, e2.getMessage()); Timber.e(e2, e2.getMessage());
calls = null; 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 @Override
protected void inject(BroadcastComponent component) { protected void inject(BroadcastComponent component) {
component.inject(this); component.inject(this);

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

Loading…
Cancel
Save