Skip to content

Commit

Permalink
Grant IO permissions to run on API > 21 devices
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 committed Apr 15, 2019
1 parent 03dd5c1 commit fe51556
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@

package org.odk.collect.android;

import android.Manifest;
import android.content.ContentValues;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.preference.PreferenceManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.GrantPermissionRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.odk.collect.android.application.Collect;
Expand All @@ -48,6 +51,12 @@
@RunWith(AndroidJUnit4.class)
public class ResetAppStateTestCase {

@Rule
public GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
);

@Before
public void setUp() throws IOException {
resetAppState(Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package org.odk.collect.android.dao;

import android.Manifest;
import android.database.Cursor;
import android.support.test.rule.GrantPermissionRule;
import android.support.test.runner.AndroidJUnit4;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.odk.collect.android.application.Collect;
Expand All @@ -39,6 +42,12 @@ public class InstancesDaoTest {

private InstancesDao instancesDao;

@Rule
public GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
);

@Before
public void setUp() {
instancesDao = new InstancesDao();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ private boolean deleteFolderContents(String path) {
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();

for (File f : files) {
result = deleteRecursive(f);
if (files != null) {
for (File f : files) {
result = deleteRecursive(f);
}
}
}
return result;
Expand Down

0 comments on commit fe51556

Please sign in to comment.