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 public download directoty to by-pass scoped storage (API 30) #273

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ dependencies {
compileOnly deps.jsr305

implementation deps.supportAppCompat
implementation deps.supportAnnotation
implementation deps.gson

androidTestImplementation deps.dexmaker
androidTestImplementation deps.dexmakerDx
androidTestImplementation deps.junit
androidTestImplementation deps.androidTestRules
androidTestImplementation deps.androidTestJunit
androidTestImplementation deps.espresso
androidTestImplementation deps.mockito
androidTestImplementation deps.dexmakerMockito
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import android.widget.LinearLayout;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.Espresso;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.WeakHashMap;
import javax.annotation.Nullable;

@SuppressLint("PrivateApi")
public abstract class WindowAttachment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
Expand All @@ -32,7 +33,6 @@
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nullable;

/** A "local" implementation of Album. */
@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -98,11 +99,11 @@ private void grantPermission(Context context, String permission) {
}

private File getSdcardDir(String type) {
String externalStorage = System.getenv("EXTERNAL_STORAGE");
File publicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

if (externalStorage == null) {
if (publicDir == null) {
throw new RuntimeException(
"No $EXTERNAL_STORAGE has been set on the device, please report this bug!");
"No Downloads directory has been found on the device, please report this bug!");
}

String sdcardDirectory =
Expand All @@ -111,7 +112,7 @@ private File getSdcardDir(String type) {
: DEFAULT_SDCARD_DIRECTORY;

String parent =
String.format("%s/%s/%s/", externalStorage, sdcardDirectory, mContext.getPackageName());
String.format("%s/%s/%s/", publicDir, sdcardDirectory, mContext.getPackageName());

String child = String.format("%s/screenshots-%s", parent, type);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package com.facebook.testing.screenshot.internal;

import androidx.annotation.Nullable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import javax.annotation.Nullable;

/** Detect the test name and class that is being run currently. */
public class TestNameDetector {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import javax.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;

/**
* This class provides utility methods for determining certain accessibility properties of {@link
Expand Down
50 changes: 31 additions & 19 deletions plugin/src/py/android_screenshot_tests/pull_screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,32 +456,44 @@ def android_path_join(a, *args):


def pull_metadata(package, dir, adb_puller):
root_screenshot_dir = android_path_join(
adb_puller.get_external_data_dir(), "screenshots"
)
metadata_file = android_path_join(
root_screenshot_dir, package, "screenshots-default/metadata.json"
)

old_metadata_file = android_path_join(
OLD_ROOT_SCREENSHOT_DIR, package, "app_screenshots-default/metadata.json"
)

if adb_puller.remote_file_exists(metadata_file):
adb_puller.pull(metadata_file, join(dir, "metadata.json"))
elif adb_puller.remote_file_exists(old_metadata_file):
adb_puller.pull(old_metadata_file, join(dir, "metadata.json"))
metadata_file = old_metadata_file
else:
create_empty_metadata_file(dir)
metadata_file = None
external_dir = adb_puller.get_external_data_dir()

possible_location = [
android_path_join(
external_dir,
'Download/screenshots',
package,
'screenshots-default/metadata.json'),
android_path_join(
external_dir,
"screenshots",
package,
'screenshots-default/metadata.json'),
android_path_join(
OLD_ROOT_SCREENSHOT_DIR,
package,
'app_screenshots-default/metadata.json')
]

for location in possible_location:
if adb_puller.remote_file_exists(location):
adb_puller.pull(location, join(dir, 'metadata.json'))
metadata_file = location
break

if metadata_file == None:
metadata_file = create_empty_metadata_file(dir)

return metadata_file.replace("metadata.json", "")


def create_empty_metadata_file(dir):
with open(join(dir, "metadata.json"), "w") as out:
metadata_file = join(dir, 'metadata.json')
with open(metadata_file, "w") as out:
out.write("{}")

return metadata_file

def pull_images(dir, device_dir, test_run_id, adb_puller):
if adb_puller.remote_file_exists(android_path_join(device_dir, test_run_id)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MainActivity : AppCompatActivity() {

private fun Intent.string(name: String, defValue: String): String {
if (hasExtra(name)) {
return getStringExtra(name)
return getStringExtra(name)!!
}
return defValue
}
Expand Down
20 changes: 11 additions & 9 deletions versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ ext {
final lithoVersion = "0.40.0"

versions = [
kotlin : '1.3.61',
targetSdk : 28,
compileSdk: 28,
kotlin : '1.4.21',
targetSdk : 30,
compileSdk: 30,
minSdk : 14,
]

Expand All @@ -36,8 +36,9 @@ ext {
]

deps = [
supportAppCompat : "androidx.appcompat:appcompat:1.1.0",
supportDesign : "com.google.android.material:material:1.1.0",
supportAppCompat : "androidx.appcompat:appcompat:1.2.0",
supportAnnotation : "androidx.annotation:annotation:1.1.0",
supportDesign : "com.google.android.material:material:1.2.1",
supportMultidex : "androidx.multidex:multidex:2.0.1",

kotlinStdlib : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}",
Expand All @@ -60,10 +61,11 @@ ext {
dexmakerDx : "com.crittercism.dexmaker:dexmaker-dx:$dexmakerVersion",
dexmakerMockito : "com.crittercism.dexmaker:dexmaker-mockito:$dexmakerVersion",

espresso : "androidx.test.espresso:espresso-core:3.1.0",
testRunner : "androidx.test:runner:1.2.0",
orchestrator : "androidx.test:orchestrator:1.2.0",
androidTestRules : "androidx.test:rules:1.1.0",
espresso : "androidx.test.espresso:espresso-core:3.3.0",
testRunner : "androidx.test:runner:1.3.0",
androidTestRules : "androidx.test:rules:1.3.0",
androidTestJunit : "androidx.test.ext:junit:1.1.2",
orchestrator : "androidx.test:orchestrator:1.3.0",
junit : "junit:junit:4.12",
mockito : "org.mockito:mockito-core:1.10.19",
hamcrest : "org.hamcrest:hamcrest-core:1.3",
Expand Down