Skip to content

Commit

Permalink
Improve handling of the POST_NOTIFICATIONS permission
Browse files Browse the repository at this point in the history
  • Loading branch information
amberin committed Jun 14, 2024
1 parent b84d44f commit 2d84a5b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/src/main/java/com/orgzly/android/prefs/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ public static void remindersForEventsEnabled(Context context, boolean value) {
getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply();
}

public static boolean anyNotificationsEnabled(Context context) {
return (
showSyncNotifications(context) ||
newNoteNotification(context) ||
remindersForScheduledEnabled(context) ||
remindersForDeadlineEnabled(context) ||
remindersForEventsEnabled(context)
);
}

public static boolean remindersSound(Context context) {
return getDefaultSharedPreferences(context).getBoolean(
context.getResources().getString(R.string.pref_key_reminders_sound),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
Expand Down Expand Up @@ -71,6 +72,7 @@
import com.orgzly.android.usecase.UseCase;
import com.orgzly.android.usecase.UseCaseResult;
import com.orgzly.android.usecase.UseCaseWorker;
import com.orgzly.android.util.AppPermissions;
import com.orgzly.android.util.LogUtils;
import com.orgzly.org.datetime.OrgDateTime;

Expand Down Expand Up @@ -143,6 +145,13 @@ protected void onCreate(Bundle savedInstanceState) {

setupDisplay(savedInstanceState);

if (AppPreferences.anyNotificationsEnabled(this)) {
if (Build.VERSION.SDK_INT >= 33) {
// Ensure we have the POST_NOTIFICATIONS permission
AppPermissions.isGrantedOrRequest(this, AppPermissions.Usage.POST_NOTIFICATIONS);
}
}

if (AppPreferences.newNoteNotification(this)) {
Notifications.showOngoingNotification(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class GitRepoActivity : CommonActivity(), GitPreferences {
// Using SSH transport requires notification permission (for server key verification)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
AppPermissions.isGrantedOrRequest(
App.getCurrentActivity(),
this,
AppPermissions.Usage.POST_NOTIFICATIONS
)
}
Expand Down

0 comments on commit 2d84a5b

Please sign in to comment.