mirror of https://github.com/nextcloud/android
Grant notifications
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
9afa560b70
commit
6b65947054
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2023 Tobias Kaminsky
|
||||
* Copyright (C) 2021 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.test
|
||||
|
||||
import android.Manifest
|
||||
import android.os.Build
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
|
||||
class GrantNotificationPermissionRule private constructor() {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun grant(): TestRule = when {
|
||||
Build.VERSION.SDK_INT > Build.VERSION_CODES.R -> GrantPermissionRule.grant(
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
)
|
||||
else -> GrantManageNotificationPermissionRule()
|
||||
}
|
||||
}
|
||||
|
||||
private class GrantManageNotificationPermissionRule : TestRule {
|
||||
override fun apply(base: Statement, description: Description): Statement = object : Statement() {
|
||||
override fun evaluate() {
|
||||
InstrumentationRegistry.getInstrumentation().uiAutomation.executeShellCommand(
|
||||
"appops set --uid ${InstrumentationRegistry.getInstrumentation().targetContext.packageName} " +
|
||||
"POST_NOTIFICATION allow"
|
||||
)
|
||||
base.evaluate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import com.nextcloud.client.preferences.AppPreferencesImpl;
|
|||
import com.nextcloud.client.preferences.DarkMode;
|
||||
import com.nextcloud.common.NextcloudClient;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.nextcloud.test.GrantNotificationPermissionRule;
|
||||
import com.nextcloud.test.GrantStoragePermissionRule;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
@ -83,6 +84,9 @@ import static org.junit.Assume.assumeTrue;
|
|||
public abstract class AbstractIT {
|
||||
@Rule
|
||||
public final TestRule permissionRule = GrantStoragePermissionRule.grant();
|
||||
|
||||
@Rule
|
||||
public final TestRule notificationPermissionRule = GrantNotificationPermissionRule.grant();
|
||||
|
||||
protected static OwnCloudClient client;
|
||||
protected static NextcloudClient nextcloudClient;
|
||||
|
|
Loading…
Reference in New Issue