mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Check calendar and contact permissions for calendar sync
This commit is contained in:
+25
-7
@@ -38,10 +38,12 @@ import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PR
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants.PREF_MOYOUNG_DEVICE_VERSION;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.moyoung.MoyoungConstants.PREF_MOYOUNG_WATCH_FACE;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
@@ -685,8 +687,6 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
addPreferenceHandlerFor(PREF_SOUNDS);
|
||||
addPreferenceHandlerFor(PREF_CAMERA_REMOTE);
|
||||
addPreferenceHandlerFor(PREF_SCREEN_LIFT_WRIST);
|
||||
addPreferenceHandlerFor(PREF_SYNC_CALENDAR);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_LOOKAHEAD_DAYS);
|
||||
|
||||
addPreferenceHandlerFor(PREF_BATTERY_POLLING_ENABLE);
|
||||
addPreferenceHandlerFor(PREF_BATTERY_POLLING_INTERVAL);
|
||||
@@ -1023,11 +1023,29 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_MAX_TITLE_LENGTH);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_MAX_DESC_LENGTH);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_TARGET_APP);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_CANCELED);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_DECLINED);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_FOCUS_TIME);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_ALL_DAY);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_WORKING_LOCATION);
|
||||
|
||||
final Preference syncCalendarPreference = findPreference(PREF_SYNC_CALENDAR);
|
||||
if (syncCalendarPreference != null) {
|
||||
if (requireContext().checkSelfPermission(Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
|
||||
syncCalendarPreference.setEnabled(false);
|
||||
syncCalendarPreference.setSummary(R.string.permission_not_granted_calendar);
|
||||
}
|
||||
if (requireContext().checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
|
||||
final Preference syncBirthdaysPreference = findPreference(PREF_SYNC_BIRTHDAYS);
|
||||
if (syncBirthdaysPreference != null) {
|
||||
syncBirthdaysPreference.setEnabled(false);
|
||||
syncBirthdaysPreference.setSummary(R.string.permission_not_granted_contacts);
|
||||
}
|
||||
}
|
||||
addPreferenceHandlerFor(PREF_SYNC_CALENDAR);
|
||||
addPreferenceHandlerFor(PREF_SYNC_BIRTHDAYS);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_LOOKAHEAD_DAYS);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_CANCELED);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_DECLINED);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_FOCUS_TIME);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_ALL_DAY);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_WORKING_LOCATION);
|
||||
}
|
||||
|
||||
addPreferenceHandlerFor(PREF_ATC_BLE_OEPL_MODEL);
|
||||
addPreferenceHandlerFor(PREF_ATC_BLE_OEPL_BLE_ADV_INTERVAL);
|
||||
|
||||
+17
-4
@@ -16,9 +16,11 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.util.calendar;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.CalendarContract;
|
||||
@@ -100,12 +102,23 @@ public class CalendarManager {
|
||||
|
||||
final List<CalendarEvent> calendarEventList = new ArrayList<>();
|
||||
|
||||
// Calendar events
|
||||
if (prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR, false)) {
|
||||
calendarEventList.addAll(getCalendarEvents(lookaheadDays));
|
||||
if (mContext.checkSelfPermission(Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
|
||||
calendarEventList.addAll(getCalendarEvents(lookaheadDays));
|
||||
} else {
|
||||
LOG.warn("Calendar sync is enabled, but calendar access is not granted");
|
||||
}
|
||||
}
|
||||
|
||||
// Contact birthdays
|
||||
if (prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SYNC_BIRTHDAYS, false)) {
|
||||
calendarEventList.addAll(getBirthdays(lookaheadDays));
|
||||
calendarEventList.sort(Comparator.comparingInt(CalendarEvent::getBeginSeconds));
|
||||
if (mContext.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
||||
calendarEventList.addAll(getBirthdays(lookaheadDays));
|
||||
calendarEventList.sort(Comparator.comparingInt(CalendarEvent::getBeginSeconds));
|
||||
} else {
|
||||
LOG.warn("Birthday sync is enabled, but contact access is not granted");
|
||||
}
|
||||
}
|
||||
|
||||
return calendarEventList;
|
||||
@@ -307,7 +320,7 @@ public class CalendarManager {
|
||||
));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
LOG.error("could not query birthdays, permission denied?", e);
|
||||
LOG.error("Failed to query birthdays", e);
|
||||
}
|
||||
return birthdays;
|
||||
}
|
||||
|
||||
@@ -447,6 +447,8 @@
|
||||
<string name="pref_summary_device_intents">Allow Bangle.js watch apps to send Android Intents, and allow other apps on Android (like Tasker) to send data to Bangle.js with the com.banglejs.uart.tx Intent. Needs permission to display over other apps to work in the background.</string>
|
||||
<string name="pref_summary_sync_calendar">Enables calendar alerts, even when disconnected</string>
|
||||
<string name="pref_title_sync_caldendar">Sync calendar events</string>
|
||||
<string name="permission_not_granted_contacts">Contacts permission not granted</string>
|
||||
<string name="permission_not_granted_calendar">Calendar permission not granted</string>
|
||||
<string name="pref_summary_calendar_sync_choose">Choose which calendars and color labels to sync to the device</string>
|
||||
<string name="pref_title_calendar_sync_choose">Calendars to sync</string>
|
||||
<string name="pref_title_calendar_sync_colors">Event colors to sync</string>
|
||||
|
||||
Reference in New Issue
Block a user