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

Finalize #254 & SVG generation #280

Merged
merged 33 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ac32d2c
Remove unused code
TWiStErRob Jun 20, 2023
48059fe
Remove external storage access from SVG app
TWiStErRob Jun 20, 2023
f25ab98
Merge fix254 branch
TWiStErRob Jun 21, 2023
4d438cc
Remove unused BackupZipFileImporter
TWiStErRob Jun 20, 2023
c693ef8
Using scoped storage this is now automatic
TWiStErRob Jun 21, 2023
6c00952
Fix stack traces during normal operation
TWiStErRob Jun 21, 2023
a05c8c0
Embrace UTP for SVG generation and new CI
TWiStErRob Jun 22, 2023
74b587d
Clean up ci
TWiStErRob Jun 22, 2023
3af0652
Stricter execution
TWiStErRob Jun 22, 2023
7c9750b
Update libs to latest to include jcenter fix
TWiStErRob Jun 24, 2023
21a6dda
Add diagnostic to find the reason for
TWiStErRob Jun 24, 2023
1f05cf9
"No result found." is not enough, list fully
TWiStErRob Jun 24, 2023
712d0af
The list shows missing Android folder, probably because it's a fresh …
TWiStErRob Jun 24, 2023
96be7b0
Fix empty lines
TWiStErRob Jun 24, 2023
3c549ad
Increase timeout, boot takes ages
TWiStErRob Jun 24, 2023
e4ad06f
Explain
TWiStErRob Jun 24, 2023
4fad4b1
All versions
TWiStErRob Jun 24, 2023
69318d6
Also run SVG test just for coverage of the SVG files
TWiStErRob Jun 24, 2023
c239779
Longer emulator timeout
TWiStErRob Jun 24, 2023
7f191a3
Diagnose more
TWiStErRob Jun 24, 2023
eb5b01f
List all folders
TWiStErRob Jun 25, 2023
efdc475
List Android folders too
TWiStErRob Jun 25, 2023
c96b65b
Create folder
TWiStErRob Jun 25, 2023
cdced0b
Make the new folder discoverable
TWiStErRob Jun 26, 2023
58794c9
Extract to separate file, emulator runner doesn't support multiline
TWiStErRob Jun 26, 2023
1eaf887
Add root access for 27
TWiStErRob Jun 26, 2023
e6026b9
Add Generated SVG report
TWiStErRob Jun 28, 2023
407e6ae
Tabs
TWiStErRob Jun 28, 2023
019324c
Clean up warnings and formatting
TWiStErRob Jun 28, 2023
5604699
Make file executable
TWiStErRob Jun 28, 2023
8c217a2
Allow glob to resolve
TWiStErRob Jun 28, 2023
744f67d
Trigger only on main for all API levels.
TWiStErRob Jun 28, 2023
64f62d0
Keep double quotes, because otherwise it triggers https://github.com/…
TWiStErRob Jun 28, 2023
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
90 changes: 90 additions & 0 deletions .github/workflows/svg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: SVG
on:
workflow_dispatch:
push:
branches:
- '**'
TWiStErRob marked this conversation as resolved.
Show resolved Hide resolved

jobs:

validate:
name: "🦺 Validation"
runs-on: ubuntu-latest
timeout-minutes: 2
permissions:
# actions/checkout
contents: read
steps:
- name: "Checkout ${{ github.ref }} branch in ${{ github.repository }} repository."
uses: actions/checkout@v3
with:
submodules: true

- name: "Validate Gradle Wrapper JARs."
uses: gradle/wrapper-validation-action@v1


instrumentation:
name: "🎨 Generate SVGs on ${{ matrix.android-api }}"
needs: validate
runs-on: macos-latest
timeout-minutes: 20
permissions:
# actions/checkout
contents: read
# EnricoMi/publish-unit-test-result-action -> https://github.com/EnricoMi/publish-unit-test-result-action#permissions
checks: write
strategy:
fail-fast: false
matrix:
# The API level, see https://apilevels.com/.
android-api:
- 21
- 23
- 29
- 33
TWiStErRob marked this conversation as resolved.
Show resolved Hide resolved
steps:
- name: "Set up JDK 11."
uses: actions/setup-java@v3
with:
java-version: 11
distribution: zulu

- name: "Checkout ${{ github.ref }} branch in ${{ github.repository }} repository."
uses: actions/checkout@v3
with:
submodules: true

- name: "Run SVG generation on emulator."
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.android-api }}
# TODEL Some are not available: https://issuetracker.google.com/issues/267458959
target: ${{ matrix.android-api >= 32 && 'google_apis' || 'default' }}
arch: ${{ matrix.android-api >= 21 && 'x86_64' || 'x86' }}
profile: pixel
# Ensure that /storage/sdcard exists, without this the stock DocumentsUI will be non-functional.
sdcard-path-or-size: 100M
script: |
adb devices -l
./gradlew --no-daemon --stacktrace :android:data:svg:connectedCheck -Pandroid.experimental.androidTest.useUnifiedTestPlatform=true -Pandroid.testInstrumentationRunnerArguments.class=net.twisterrob.inventory.android.data.svg.DumpImages

- name: "Upload 'SVG ${{ matrix.android-api }}' artifact."
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: 'SVG ${{ matrix.android-api }}'
path: |
${{ github.workspace }}/**/build/reports/androidTests/connected/
${{ github.workspace }}/**/build/outputs/androidTest-results/connected/
${{ github.workspace }}/**/build/outputs/connected_android_test_additional_output/

- name: "Publish 'SVG Results ${{ matrix.android-api }}' check suite."
if: success() || failure()
uses: EnricoMi/publish-unit-test-result-action/composite@v2
with:
check_name: '🔔 Test: SVG Results ${{ matrix.android-api }}'
comment_mode: off
report_individual_runs: true
test_changes_limit: 0
junit_files: ${{ github.workspace }}/**/build/outputs/androidTest-results/connected/TEST-*.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,20 @@
public class BackupZipUriImporter implements ZipImporter<Uri> {
private final @NonNull ContentResolver contentResolver;
private final @NonNull BackupZipStreamImporter streamImporter;
private final @NonNull BackupZipFileImporter fileImporter;

@Inject
public BackupZipUriImporter(
@ApplicationContext
@NonNull ContentResolver contentResolver,
@NonNull BackupZipStreamImporter streamImporter,
@NonNull BackupZipFileImporter fileImporter
@NonNull BackupZipStreamImporter streamImporter
) {
this.contentResolver = contentResolver;
this.streamImporter = streamImporter;
this.fileImporter = fileImporter;
}

@Override public void importFrom(Uri uri) throws Exception {
try {
if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
importFile(uri);
} else {
importStream(uri);
}
importStream(uri);
} catch (Exception ex) {
IllegalArgumentException cause = new IllegalArgumentException("Source URI: " + uri);
//noinspection ThrowableNotThrown
Expand All @@ -45,10 +38,6 @@ public BackupZipUriImporter(
}
}

private void importFile(Uri uri) throws Exception {
fileImporter.importFrom(new File(uri.getPath()));
}

private void importStream(Uri uri) throws Exception {
InputStream stream = contentResolver.openInputStream(uri);
try {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,12 @@ class Paths {
private static final String PUBLIC_TEMP_FOLDER_NAME = "temp";
public static final String BACKUP_DATA_FILENAME = "data.xml";

public static @NonNull File getExportFile(File exportFolder) throws IOException {
IOTools.ensure(exportFolder);
return new File(exportFolder, getExportFileName(Calendar.getInstance()));
}
public static @NonNull String getExportFileName(Calendar now) {
return getFileName("Inventory", now, "zip");
}
public static @NonNull String getFileName(String prefix, Calendar now, String extension) {
return String.format(Locale.ROOT, "%s_%tF_%<tH-%<tM-%<tS.%s", prefix, now, extension);
}
@SuppressWarnings("deprecation") // see requestLegacyExternalStorage
public static @NonNull File getPhoneHome() {
StrictMode.ThreadPolicy originalPolicy = StrictMode.allowThreadDiskWrites();
try {
// D/StrictMode: StrictMode policy violation; ~duration=17 ms: android.os.strictmode.DiskReadViolation
// at java.io.File.isDirectory(File.java:845)
// at net.twisterrob.java.io.IOTools.isValidDir(IOTools.java:375)
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
if (!IOTools.isValidDir(dir)) { // fall back to /sdcard
dir = Environment.getExternalStorageDirectory();
}
if (!IOTools.isValidDir(dir)) { // fall back to /
dir = Environment.getRootDirectory();
}
return dir;
} finally {
StrictMode.setThreadPolicy(originalPolicy);
}
}

/**
* Make sure to add <code>.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)</code> to the intent.
* @param file from {@link #getShareFile}
Expand Down Expand Up @@ -185,7 +161,7 @@ private ColorMatrixColorFilter createTintFilter(Context context) {
)
));
}

public static DrawableRequestBuilder<Integer> svg() {
return instance.svgRequestTinted.clone();
}
Expand Down
36 changes: 36 additions & 0 deletions android/data/svg/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
App to generate all SVG files.

## Firebase
This is an app instead of a test project, because Firebase Testlab requires and app APK and a test APK.

## Local & Manual CI
```
gradlew :android:data:svg:connectedCheck -Pandroid.testInstrumentationRunnerArguments.class=net.twisterrob.inventory.android.data.svg.DumpImages -Pandroid.experimental.androidTest.useUnifiedTestPlatform=true
```
will output on device to:
```
/storage/sdcard/Android/data/net.twisterrob.inventory.data.debug/files/test_data/svg_<sdk>.zip
```
which is then pulled by AGP's `connectedCheck` as
```
android/data/svg/build/outputs/connected_android_test_additional_output/debugAndroidTest/connected/<emulator name>/svg_<sdk>.zip
```

## Gradle Managed Devices
Only work above 29
```
gradlew
:android:data:svg:gmdGroupDebugAndroidTest
-Pandroid.testInstrumentationRunnerArguments.class=net.twisterrob.inventory.android.data.svg.DumpImages
-Pandroid.experimental.androidTest.useUnifiedTestPlatform=true
--continue
```
output is in:
```
android/data/svg/build/outputs/managed_device_android_test_additional_output/<gmd name>/svg_<sdk>.zip
```

Potential diagnostic helpers:
```
-Pandroid.experimental.testOptions.managedDevices.setupTimeoutMinutes=300
--max-workers 1
-Pandroid.experimental.testOptions.managedDevices.maxConcurrentDevices=1
-Dorg.gradle.workers.max=1
```
18 changes: 18 additions & 0 deletions android/data/svg/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ android {
multiDexKeepProguard project(":android").file("src/androidTest/multidex.pro")
}
}
testOptions {
managedDevices {
def apiDevices = (29..33).collect {api ->
devices.register("api${api}", com.android.build.api.dsl.ManagedVirtualDevice) {
device = "Pixel 2"
apiLevel = api
require64Bit = true
// https://issuetracker.google.com/issues/267458959
systemImageSource = api == 32 || api == 33 ? "google_apis" : "default"
}
}
groups.register("gmd") { group ->
apiDevices.each { device ->
group.targetDevices.addLater(device)
}
}
}
}
}

androidComponents {
Expand Down
7 changes: 0 additions & 7 deletions android/data/svg/src/androidTest/AndroidManifest.xml

This file was deleted.

Loading
Loading