diff --git a/core/build.gradle b/core/build.gradle index eac9eb8c..cad23c99 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -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 diff --git a/core/src/androidTest/java/com/facebook/testing/screenshot/WindowAttachmentTest.java b/core/src/androidTest/java/com/facebook/testing/screenshot/WindowAttachmentTest.java index f6c7ec7a..8e49d603 100644 --- a/core/src/androidTest/java/com/facebook/testing/screenshot/WindowAttachmentTest.java +++ b/core/src/androidTest/java/com/facebook/testing/screenshot/WindowAttachmentTest.java @@ -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; diff --git a/core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java b/core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java index 2d6314d1..541efbfa 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java +++ b/core/src/main/java/com/facebook/testing/screenshot/WindowAttachment.java @@ -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 { diff --git a/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java b/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java index dd4eec29..ad2f5d19 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java +++ b/core/src/main/java/com/facebook/testing/screenshot/internal/AlbumImpl.java @@ -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; @@ -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") diff --git a/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java b/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java index 168f3eae..ba7fe7ff 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java +++ b/core/src/main/java/com/facebook/testing/screenshot/internal/ScreenshotDirectories.java @@ -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; @@ -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 = @@ -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); diff --git a/core/src/main/java/com/facebook/testing/screenshot/internal/TestNameDetector.java b/core/src/main/java/com/facebook/testing/screenshot/internal/TestNameDetector.java index b80bca74..3e86d4dc 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/internal/TestNameDetector.java +++ b/core/src/main/java/com/facebook/testing/screenshot/internal/TestNameDetector.java @@ -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 { diff --git a/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityIssuesDumper.java b/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityIssuesDumper.java index 21f515d4..92a17418 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityIssuesDumper.java +++ b/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityIssuesDumper.java @@ -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; diff --git a/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java b/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java index 55ea5471..6ca2e5e4 100644 --- a/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java +++ b/core/src/main/java/com/facebook/testing/screenshot/layouthierarchy/AccessibilityUtil.java @@ -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 diff --git a/plugin/src/py/android_screenshot_tests/pull_screenshots.py b/plugin/src/py/android_screenshot_tests/pull_screenshots.py index 8174bdea..e9e4553d 100755 --- a/plugin/src/py/android_screenshot_tests/pull_screenshots.py +++ b/plugin/src/py/android_screenshot_tests/pull_screenshots.py @@ -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)): diff --git a/sample/src/main/java/com/facebook/testing/screenshot/sample/MainActivity.kt b/sample/src/main/java/com/facebook/testing/screenshot/sample/MainActivity.kt index 99200634..ff879d9a 100644 --- a/sample/src/main/java/com/facebook/testing/screenshot/sample/MainActivity.kt +++ b/sample/src/main/java/com/facebook/testing/screenshot/sample/MainActivity.kt @@ -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 } diff --git a/versions.gradle b/versions.gradle index 1a39ab44..643c3cea 100644 --- a/versions.gradle +++ b/versions.gradle @@ -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, ] @@ -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}", @@ -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",