Skip to content

Commit b5060e6

Browse files
committed
use androidx preferences, fix translation errors, prevent zip path traversal attack
1 parent 06a3a99 commit b5060e6

File tree

65 files changed

+534
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+534
-494
lines changed

FileManager/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
dependencies {
4-
implementation 'com.github.openintents:distribution:3.0.2'
4+
implementation 'com.github.openintents:distribution:3.2.0'
55
implementation 'androidx.appcompat:appcompat:1.1.0'
6+
implementation "androidx.preference:preference:1.1.0"
7+
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
8+
implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta3"
69

10+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
711
androidTestImplementation 'androidx.test:runner:1.2.0'
812
androidTestImplementation 'androidx.test:rules:1.2.0'
913
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
@@ -15,7 +19,6 @@ dependencies {
1519

1620
android {
1721
compileSdkVersion compile_sdk_version
18-
buildToolsVersion build_tools_version
1922

2023
defaultConfig {
2124
applicationId "org.openintents.filemanager"

FileManager/src/androidTest/java/org/openintents/filemanager/test/ActivityResultTestRule.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
package androidTest.java.org.openintents.filemanager.test;
1+
package org.openintents.filemanager.test;
22

33
import android.annotation.TargetApi;
44
import android.app.Activity;
55
import android.content.Intent;
66
import android.os.Build;
7+
78
import androidx.annotation.NonNull;
89
import androidx.test.rule.ActivityTestRule;
910

1011
import org.hamcrest.Description;
1112
import org.hamcrest.Matcher;
13+
import org.hamcrest.MatcherAssert;
14+
import org.hamcrest.Matchers;
1215
import org.hamcrest.TypeSafeMatcher;
1316

1417
import java.lang.reflect.Field;
1518

1619
import static android.app.Instrumentation.ActivityResult;
17-
import static org.hamcrest.MatcherAssert.assertThat;
18-
import static org.hamcrest.Matchers.is;
1920

2021
public class ActivityResultTestRule<T extends Activity> extends ActivityTestRule<T> {
2122

FileManager/src/androidTest/java/org/openintents/filemanager/test/BaseTestFileManager.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
package androidTest.java.org.openintents.filemanager.test;
1+
package org.openintents.filemanager.test;
22

3-
import androidx.test.espresso.ViewAssertion;
4-
import androidx.test.espresso.matcher.BoundedMatcher;
53
import android.view.View;
64
import android.widget.Adapter;
75
import android.widget.AdapterView;
86

7+
import androidx.test.espresso.Espresso;
8+
import androidx.test.espresso.ViewAssertion;
9+
import androidx.test.espresso.action.ViewActions;
10+
import androidx.test.espresso.matcher.BoundedMatcher;
11+
912
import org.hamcrest.Description;
1013
import org.hamcrest.Matcher;
14+
import org.hamcrest.Matchers;
1115
import org.hamcrest.TypeSafeMatcher;
1216
import org.openintents.filemanager.bookmarks.BookmarkListAdapter;
1317
import org.openintents.filemanager.files.FileHolder;
@@ -16,14 +20,7 @@
1620
import java.io.FileOutputStream;
1721
import java.io.IOException;
1822
import java.io.OutputStreamWriter;
19-
20-
import static androidx.test.espresso.Espresso.onData;
21-
import static androidx.test.espresso.action.ViewActions.click;
22-
import static androidx.test.espresso.action.ViewActions.longClick;
23-
import static androidx.test.espresso.action.ViewActions.pressBack;
24-
import static org.hamcrest.Matchers.allOf;
25-
import static org.hamcrest.Matchers.instanceOf;
26-
import static org.hamcrest.Matchers.is;
23+
import java.nio.charset.StandardCharsets;
2724

2825
public class BaseTestFileManager {
2926
public static final String TEST_DIRECTORY = "oi-filemanager-tests";
@@ -49,7 +46,7 @@ protected static void cleanDirectory(File file) {
4946

5047
protected static void createFile(String path, String content) throws IOException {
5148
File file = new File(path);
52-
OutputStreamWriter wr = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
49+
OutputStreamWriter wr = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
5350
wr.write(content);
5451
wr.close();
5552
}

FileManager/src/androidTest/java/org/openintents/filemanager/test/DirectoryScannerIdlingResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package androidTest.java.org.openintents.filemanager.test;
1+
package org.openintents.filemanager.test;
22

33
import androidx.test.espresso.IdlingResource;
44

FileManager/src/androidTest/java/org/openintents/filemanager/test/TestActivityTestRule.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
package androidTest.java.org.openintents.filemanager.test;
17+
package org.openintents.filemanager.test;
1818

1919
import android.app.Activity;
2020
import android.app.Instrumentation;
2121
import android.content.Intent;
22+
import android.util.Log;
23+
2224
import androidx.annotation.Nullable;
2325
import androidx.test.InstrumentationRegistry;
2426
import androidx.test.annotation.Beta;
27+
import androidx.test.espresso.intent.Checks;
2528
import androidx.test.rule.UiThreadTestRule;
26-
import android.util.Log;
2729

2830
import org.junit.runner.Description;
2931
import org.junit.runners.model.Statement;
3032

31-
import static androidx.test.internal.util.Checks.checkNotNull;
32-
3333
/**
3434
* This rule provides functional testing of a single activity. The activity under test will be
3535
* launched before each test annotated with

FileManager/src/androidTest/java/org/openintents/filemanager/test/TestFileManagerActivity.java

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
/*
2-
* This is an example test project created in Eclipse to test NotePad which is a sample
2+
* This is an example test project created in Eclipse to test NotePad which is a sample
33
* project located in AndroidSDK/samples/android-11/NotePad
44
* Just click on File --> New --> Project --> Android Project --> Create Project from existing source and
55
* select NotePad.
6-
*
6+
*
77
* Then you can run these test cases either on the emulator or on device. You right click
88
* the test project and select Run As --> Run As Android JUnit Test
9-
*
9+
*
1010
* @author Renas Reda, [email protected]
11-
*
11+
*
1212
*/
1313

14-
package androidTest.java.org.openintents.filemanager.test;
14+
package org.openintents.filemanager.test;
1515

1616
import android.content.Context;
1717
import android.content.SharedPreferences;
1818
import android.os.Environment;
1919
import android.preference.PreferenceManager;
20-
import androidx.test.InstrumentationRegistry;
21-
import androidx.test.espresso.Espresso;
22-
import androidx.test.rule.ActivityTestRule;
23-
import androidx.test.runner.AndroidJUnit4;
2420
import android.text.format.Formatter;
2521
import android.view.KeyEvent;
2622
import android.view.View;
2723
import android.widget.ListView;
2824

25+
import androidx.test.InstrumentationRegistry;
26+
import androidx.test.espresso.Espresso;
27+
import androidx.test.espresso.action.ViewActions;
28+
import androidx.test.espresso.assertion.ViewAssertions;
29+
import androidx.test.espresso.matcher.ViewMatchers;
30+
import androidx.test.rule.ActivityTestRule;
31+
import androidx.test.runner.AndroidJUnit4;
32+
2933
import org.hamcrest.Description;
3034
import org.hamcrest.Matcher;
35+
import org.hamcrest.Matchers;
3136
import org.hamcrest.TypeSafeMatcher;
3237
import org.junit.After;
3338
import org.junit.Before;
@@ -46,27 +51,8 @@
4651
import java.io.IOException;
4752
import java.util.Random;
4853

49-
import static androidx.test.espresso.Espresso.onData;
50-
import static androidx.test.espresso.Espresso.onView;
51-
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
52-
import static androidx.test.espresso.Espresso.openContextualActionModeOverflowMenu;
53-
import static androidx.test.espresso.Espresso.pressBack;
54-
import static androidx.test.espresso.action.ViewActions.click;
55-
import static androidx.test.espresso.action.ViewActions.longClick;
56-
import static androidx.test.espresso.action.ViewActions.pressKey;
57-
import static androidx.test.espresso.action.ViewActions.replaceText;
58-
import static androidx.test.espresso.assertion.ViewAssertions.matches;
59-
import static androidx.test.espresso.matcher.ViewMatchers.assertThat;
60-
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
61-
import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription;
62-
import static androidx.test.espresso.matcher.ViewMatchers.withId;
63-
import static androidx.test.espresso.matcher.ViewMatchers.withText;
64-
import static org.hamcrest.Matchers.allOf;
65-
import static org.hamcrest.Matchers.is;
66-
import static org.hamcrest.Matchers.not;
67-
6854
@RunWith(AndroidJUnit4.class)
69-
public class TestFileManagerActivity extends BaseTestFileManager {
55+
public class TestFileManagerActivity extends org.openintents.filemanager.test.BaseTestFileManager {
7056

7157
private static String filenameIsInRightDirectory;
7258
@Rule
@@ -379,9 +365,9 @@ private void setAscending(boolean enabled) {
379365
@Test
380366
public void testBrowseToOnPressEnter() throws IOException {
381367

382-
/*
368+
/*
383369
* We start at the SD card.
384-
*/
370+
*/
385371
Espresso.onView(ViewMatchers.withText(Environment.getExternalStorageDirectory().getParentFile().getName())).perform(ViewActions.longClick());
386372
Espresso.onView(ViewMatchers.withId(R.id.path_bar_path_edit_text)).perform(ViewActions.click()); // Let the editText have focus to be able to send the enter key.
387373
Espresso.onView(ViewMatchers.withId(R.id.path_bar_path_edit_text)).perform(ViewActions.replaceText(sdcardPath + TEST_DIRECTORY));

FileManager/src/androidTest/java/org/openintents/filemanager/test/TestFileManagerActivityWithIntents.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
package androidTest.java.org.openintents.filemanager.test;
1+
package org.openintents.filemanager.test;
22

33
import android.content.Intent;
44
import android.net.Uri;
55
import android.os.Environment;
6+
7+
import androidx.test.espresso.assertion.ViewAssertions;
8+
import androidx.test.espresso.matcher.ViewMatchers;
69
import androidx.test.rule.ActivityTestRule;
710
import androidx.test.runner.AndroidJUnit4;
811

@@ -14,9 +17,6 @@
1417

1518
import java.io.IOException;
1619

17-
import static androidx.test.espresso.assertion.ViewAssertions.matches;
18-
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
19-
2020
@RunWith(AndroidJUnit4.class)
2121
public class TestFileManagerActivityWithIntents extends BaseTestFileManager {
2222

FileManager/src/androidTest/java/org/openintents/filemanager/test/TestIntentFilterActivityForPickFile.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
package androidTest.java.org.openintents.filemanager.test;
1+
package org.openintents.filemanager.test;
22

33
import android.content.Intent;
44
import android.net.Uri;
55
import android.os.Environment;
6+
7+
import androidx.test.espresso.assertion.ViewAssertions;
8+
import androidx.test.espresso.matcher.ViewMatchers;
69
import androidx.test.rule.ActivityTestRule;
710
import androidx.test.runner.AndroidJUnit4;
811

@@ -15,9 +18,6 @@
1518

1619
import java.io.IOException;
1720

18-
import static androidx.test.espresso.assertion.ViewAssertions.matches;
19-
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
20-
2121
@RunWith(AndroidJUnit4.class)
2222
public class TestIntentFilterActivityForPickFile extends BaseTestFileManager {
2323

FileManager/src/androidTest/java/org/openintents/filemanager/test/TestPickFilePathHistory.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
package androidTest.java.org.openintents.filemanager.test;
1+
package org.openintents.filemanager.test;
22

33
import android.content.Intent;
44
import android.net.Uri;
55
import android.os.Environment;
6+
import android.view.View;
7+
68
import androidx.test.InstrumentationRegistry;
79
import androidx.test.espresso.Espresso;
10+
import androidx.test.espresso.action.ViewActions;
11+
import androidx.test.espresso.assertion.ViewAssertions;
812
import androidx.test.espresso.matcher.BoundedMatcher;
13+
import androidx.test.espresso.matcher.ViewMatchers;
914
import androidx.test.rule.UiThreadTestRule;
1015
import androidx.test.runner.AndroidJUnit4;
11-
import android.view.View;
1216

1317
import org.hamcrest.Description;
1418
import org.hamcrest.Matcher;
19+
import org.hamcrest.Matchers;
1520
import org.junit.Before;
1621
import org.junit.Rule;
1722
import org.junit.Test;
@@ -24,14 +29,6 @@
2429
import java.io.File;
2530
import java.io.IOException;
2631

27-
import static androidx.test.espresso.Espresso.onView;
28-
import static androidx.test.espresso.action.ViewActions.click;
29-
import static androidx.test.espresso.assertion.ViewAssertions.matches;
30-
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
31-
import static androidx.test.espresso.matcher.ViewMatchers.withId;
32-
import static androidx.test.espresso.matcher.ViewMatchers.withText;
33-
import static org.hamcrest.Matchers.endsWith;
34-
3532
@RunWith(AndroidJUnit4.class)
3633
public class TestPickFilePathHistory extends BaseTestFileManager {
3734

FileManager/src/androidTest/java/org/openintents/filemanager/test/TestPickFileResult.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
package androidTest.java.org.openintents.filemanager.test;
1+
package org.openintents.filemanager.test;
22

33
import android.app.Activity;
44
import android.content.Intent;
55
import android.net.Uri;
66
import android.os.Environment;
7+
8+
import androidx.test.espresso.Espresso;
9+
import androidx.test.espresso.action.ViewActions;
10+
import androidx.test.espresso.intent.matcher.IntentMatchers;
11+
import androidx.test.espresso.matcher.ViewMatchers;
712
import androidx.test.runner.AndroidJUnit4;
813

14+
import org.junit.Assert;
915
import org.junit.BeforeClass;
1016
import org.junit.Rule;
1117
import org.junit.Test;
@@ -15,13 +21,8 @@
1521

1622
import java.io.IOException;
1723

18-
import static androidx.test.espresso.Espresso.onView;
19-
import static androidx.test.espresso.action.ViewActions.click;
20-
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasData;
21-
import static androidx.test.espresso.matcher.ViewMatchers.withText;
22-
import static org.junit.Assert.assertThat;
23-
import static androidTest.java.org.openintents.filemanager.test.ActivityResultTestRule.hasResultCode;
24-
import static androidTest.java.org.openintents.filemanager.test.ActivityResultTestRule.hasResultData;
24+
import static org.openintents.filemanager.test.ActivityResultTestRule.hasResultCode;
25+
import static org.openintents.filemanager.test.ActivityResultTestRule.hasResultData;
2526

2627
@RunWith(AndroidJUnit4.class)
2728
public class TestPickFileResult extends BaseTestFileManager {

0 commit comments

Comments
 (0)