Only request the POST_NOTIFICATIONS permission in tests on API 33

This commit is contained in:
Alexander Bakker 2022-09-14 21:36:31 +02:00
parent 1e3ceefeec
commit 06405d10ad
3 changed files with 13 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package com.beemdevelopment.aegis;
import android.Manifest;
import android.os.Build;
import android.view.View;
import androidx.annotation.Nullable;
@ -29,6 +30,7 @@ import java.lang.reflect.InvocationTargetException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import javax.crypto.NoSuchPaddingException;
@ -45,7 +47,7 @@ public abstract class AegisTest {
public HiltAndroidRule hiltRule = new HiltAndroidRule(this);
@Rule
public final GrantPermissionRule permRule = GrantPermissionRule.grant(Manifest.permission.POST_NOTIFICATIONS);
public final GrantPermissionRule permRule = getGrantPermissionRule();
@Inject
protected VaultManager _vaultManager;
@ -58,6 +60,14 @@ public abstract class AegisTest {
hiltRule.inject();
}
private static GrantPermissionRule getGrantPermissionRule() {
List<String> perms = new ArrayList<>();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
perms.add(Manifest.permission.POST_NOTIFICATIONS);
}
return GrantPermissionRule.grant(perms.toArray(new String[0]));
}
protected AegisApplicationBase getApp() {
return (AegisApplicationBase) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
}

View file

@ -94,7 +94,7 @@ public class AuthActivity extends AegisActivity {
// A persistent notification is shown to let the user know that the vault is unlocked. Permission
// to do so is required since API 33, so for existing users, we have to request permission here
// in order to be able to show the notification after unlock.
if (Build.VERSION.SDK_INT >= 33) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
PermissionHelper.request(this, CODE_PERM_NOTIFICATIONS, Manifest.permission.POST_NOTIFICATIONS);
}
} else {

View file

@ -81,7 +81,7 @@ public class IntroActivity extends IntroBaseActivity {
// If the user has enabled encryption, we need to request permission to show notifications
// in order to be able to show the "Vault unlocked" notification.
if (newSlide == DoneSlide.class && getState().getSerializable("creds") != null) {
if (Build.VERSION.SDK_INT >= 33) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
PermissionHelper.request(this, CODE_PERM_NOTIFICATIONS, Manifest.permission.POST_NOTIFICATIONS);
}
}