Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of EXT_DIR with Android API 29 #208

Merged
merged 4 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
language: android
android:
components:
# Use the latest revision of Android SDK Tools
- tools
- platform-tools

# The BuildTools version used by the project
- build-tools-28.0.3
- android-28
- build-tools-29.0.2

# The SDK version used to compile the project
- android-29

sudo: false

Expand Down
6 changes: 3 additions & 3 deletions logback-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ apply from: "${rootProject.projectDir}/gradle/docs.gradle"
apply from: "${rootProject.projectDir}/gradle/deploy.gradle"

android {
compileSdkVersion 28
compileSdkVersion 29

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_5
Expand All @@ -16,7 +16,7 @@ android {

defaultConfig {
minSdkVersion 9
targetSdkVersion 28
targetSdkVersion 29
versionCode VERSION_CODE.toInteger()
versionName VERSION_NAME
}
Expand Down Expand Up @@ -52,7 +52,7 @@ dependencies {
}

testImplementation 'org.hamcrest:hamcrest-junit:2.0.0.0'
testImplementation 'org.robolectric:robolectric:4.0.2'
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation 'org.mockito:mockito-core:2.23.4'
testImplementation 'joda-time:joda-time:2.10.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void setupProperties(LoggerContext context) {
context.putProperties(props);
}

private static ContextWrapper getContext() {
protected static ContextWrapper getContext() {
try {
Class<?> c = Class.forName("android.app.AppGlobals");
Method method = c.getDeclaredMethod("getInitialApplication");
Expand Down Expand Up @@ -96,20 +96,41 @@ public String getMountedExternalStorageDirectoryPath() {
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED) ||
state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
path = absPath(Environment.getExternalStorageDirectory());
path = getExternalStorageDirectoryPath();
}
return path;
}

/**
* Gets the path to the external storage directory
*
* This API is available on SDK 8+. On API versions 29 onwards,
* this function uses the implementation in
* {@link android.content.Context#getExternalFilesDir(java.lang.String)}
* which is the proposed replacement for
* {@link android.os.Environment#getExternalStorageDirectory()}.
*
* @return the absolute path to the external storage directory
*/
@TargetApi(8)
@SuppressWarnings("deprecation")
public String getExternalStorageDirectoryPath() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
tony19 marked this conversation as resolved.
Show resolved Hide resolved
if (Build.VERSION.SDK_INT >= 29) {
return getExternalFilesDirectoryPath();
} else {
return Environment.getExternalStorageDirectory().getAbsolutePath();
}
}

/**
* Gets the path to the external storage directory
*
* This API is available on SDK 8+. This function uses the implementation in
* {@link android.content.Context#getExternalFilesDir(java.lang.String)}.
*
* @return the absolute path to the external storage directory
*/
@TargetApi(8)
public String getExternalFilesDirectoryPath() {
return this.context != null
? absPath(this.context.getExternalFilesDir(null))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public void before() {
public void getMountedExternalStorageDirectoryPathReturnsPathWhenMounted() {
ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED);
assertThat(contextUtil.getMountedExternalStorageDirectoryPath(),
is(Environment.getExternalStorageDirectory().getAbsolutePath()));
is(contextUtil.getContext().getExternalFilesDir(null).getAbsolutePath()));
}

@Test
public void getMountedExternalStorageDirectoryPathReturnsPathWhenMountedReadOnly() {
ShadowEnvironment.setExternalStorageState(Environment.MEDIA_MOUNTED_READ_ONLY);
assertThat(contextUtil.getMountedExternalStorageDirectoryPath(),
is(Environment.getExternalStorageDirectory().getAbsolutePath()));
is(contextUtil.getContext().getExternalFilesDir(null).getAbsolutePath()));
}

@Test
Expand Down Expand Up @@ -111,7 +111,7 @@ public void getMountedExternalStorageDirectoryPathReturnsNullWhenShared() {
@Test
public void getExternalStorageDirectoryPathIsNotEmpty() {
assertThat(contextUtil.getExternalStorageDirectoryPath(),
is(Environment.getExternalStorageDirectory().getAbsolutePath()));
is(contextUtil.getContext().getExternalFilesDir(null).getAbsolutePath()));
}

@Test
Expand Down