From bc6724923ccf15d2e031e29227df44a13a697737 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 12 Jun 2024 18:34:58 +0200 Subject: [PATCH 01/29] Add git@github.com:element-hq/element-android-enterprise.git as a git module. --- .gitmodules | 3 +++ enterprise | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 enterprise diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..aa54a9d8ae --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "enterprise"] + path = enterprise + url = git@github.com:element-hq/element-android-enterprise.git diff --git a/enterprise b/enterprise new file mode 160000 index 0000000000..1ae9686f0e --- /dev/null +++ b/enterprise @@ -0,0 +1 @@ +Subproject commit 1ae9686f0e4b40e5f78d4b21a6fd898325409f73 From d43a8c8bea0b706bf1892397df265a46fb43b997 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 12 Jun 2024 18:53:28 +0200 Subject: [PATCH 02/29] Add first EnterpriseService. --- app/build.gradle.kts | 22 +++++++++++++- enterprise | 2 +- features/enterprise/api/build.gradle.kts | 27 +++++++++++++++++ .../EnterpriseService.kt | 21 +++++++++++++ features/enterprise/impl/build.gradle.kts | 30 +++++++++++++++++++ .../DefaultEnterpriseService.kt | 28 +++++++++++++++++ plugins/src/main/kotlin/Enterprise.kt | 22 ++++++++++++++ plugins/src/main/kotlin/Versions.kt | 2 +- .../kotlin/extension/DependencyHandleScope.kt | 5 ++++ settings.gradle.kts | 1 + .../tests/konsist/KonsistClassNameTest.kt | 1 + 11 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 features/enterprise/api/build.gradle.kts create mode 100644 features/enterprise/api/src/main/kotlin/io.element.android.features.enterprise.api/EnterpriseService.kt create mode 100644 features/enterprise/impl/build.gradle.kts create mode 100644 features/enterprise/impl/src/main/kotlin/io.element.android.features.enterprise.impl/DefaultEnterpriseService.kt create mode 100644 plugins/src/main/kotlin/Enterprise.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a4a4b1ee16..92febf82d9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -17,6 +17,7 @@ @file:Suppress("UnstableApiUsage") import com.android.build.api.variant.FilterConfiguration.FilterType.ABI +import extension.allEnterpriseImpl import extension.allFeaturesImpl import extension.allLibrariesImpl import extension.allServicesImpl @@ -46,7 +47,11 @@ android { namespace = "io.element.android.x" defaultConfig { - applicationId = "io.element.android.x" + if (isEnterpriseBuild) { + applicationId = "io.element.enterprise" + } else { + applicationId = "io.element.android.x" + } targetSdk = Versions.targetSdk versionCode = Versions.versionCode versionName = Versions.versionName @@ -170,6 +175,20 @@ android { buildConfigField("String", "FLAVOR_DESCRIPTION", "\"FDroid\"") } } + + packaging { + resources.pickFirsts.addAll( + listOf( + "kotlin/annotation/annotation.kotlin_builtins", + "kotlin/collections/collections.kotlin_builtins", + "kotlin/coroutines/coroutines.kotlin_builtins", + "kotlin/internal/internal.kotlin_builtins", + "kotlin/kotlin.kotlin_builtins", + "kotlin/ranges/ranges.kotlin_builtins", + "kotlin/reflect/reflect.kotlin_builtins", + ) + ) + } } androidComponents { @@ -222,6 +241,7 @@ knit { dependencies { allLibrariesImpl() allServicesImpl() + allEnterpriseImpl(rootDir, logger) allFeaturesImpl(rootDir, logger) implementation(projects.features.migration.api) implementation(projects.anvilannotations) diff --git a/enterprise b/enterprise index 1ae9686f0e..2e9be17450 160000 --- a/enterprise +++ b/enterprise @@ -1 +1 @@ -Subproject commit 1ae9686f0e4b40e5f78d4b21a6fd898325409f73 +Subproject commit 2e9be1745035ee60a3e9f32f5a65be363ea24a92 diff --git a/features/enterprise/api/build.gradle.kts b/features/enterprise/api/build.gradle.kts new file mode 100644 index 0000000000..6e9cd26834 --- /dev/null +++ b/features/enterprise/api/build.gradle.kts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +plugins { + id("io.element.android-library") +} + +android { + namespace = "io.element.android.features.enterprise.api" +} + +dependencies { + implementation(projects.libraries.architecture) + implementation(projects.libraries.matrix.api) +} diff --git a/features/enterprise/api/src/main/kotlin/io.element.android.features.enterprise.api/EnterpriseService.kt b/features/enterprise/api/src/main/kotlin/io.element.android.features.enterprise.api/EnterpriseService.kt new file mode 100644 index 0000000000..74d56b3191 --- /dev/null +++ b/features/enterprise/api/src/main/kotlin/io.element.android.features.enterprise.api/EnterpriseService.kt @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.enterprise.api + +interface EnterpriseService { + suspend fun isEnterpriseUser(): Boolean +} diff --git a/features/enterprise/impl/build.gradle.kts b/features/enterprise/impl/build.gradle.kts new file mode 100644 index 0000000000..e6d477b0ed --- /dev/null +++ b/features/enterprise/impl/build.gradle.kts @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +plugins { + id("io.element.android-library") + alias(libs.plugins.anvil) +} + +android { + namespace = "io.element.android.features.enterprise.impl" +} + +dependencies { + implementation(projects.anvilannotations) + api(libs.anvil.compiler.api) + api(projects.features.enterprise.api) + implementation(projects.libraries.architecture) +} diff --git a/features/enterprise/impl/src/main/kotlin/io.element.android.features.enterprise.impl/DefaultEnterpriseService.kt b/features/enterprise/impl/src/main/kotlin/io.element.android.features.enterprise.impl/DefaultEnterpriseService.kt new file mode 100644 index 0000000000..751c189c76 --- /dev/null +++ b/features/enterprise/impl/src/main/kotlin/io.element.android.features.enterprise.impl/DefaultEnterpriseService.kt @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.enterprise.impl + +import com.squareup.anvil.annotations.ContributesBinding +import io.element.android.features.enterprise.api.EnterpriseService +import io.element.android.libraries.di.SessionScope +import javax.inject.Inject + +@ContributesBinding(SessionScope::class) +class DefaultEnterpriseService @Inject constructor( +) : EnterpriseService { + override suspend fun isEnterpriseUser(): Boolean = false +} diff --git a/plugins/src/main/kotlin/Enterprise.kt b/plugins/src/main/kotlin/Enterprise.kt new file mode 100644 index 0000000000..65762c05d6 --- /dev/null +++ b/plugins/src/main/kotlin/Enterprise.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File + +/** + * Are we building with the enterprise sources? + */ +val isEnterpriseBuild = File("enterprise/README.md").exists() diff --git a/plugins/src/main/kotlin/Versions.kt b/plugins/src/main/kotlin/Versions.kt index 76a66dd519..97ac5aeaf5 100644 --- a/plugins/src/main/kotlin/Versions.kt +++ b/plugins/src/main/kotlin/Versions.kt @@ -64,7 +64,7 @@ object Versions { const val compileSdk = 34 const val targetSdk = 33 // When updating the `minSdk`, make sure to update the value of `minSdkVersion` in the file `tools/release/release.sh` - const val minSdk = 24 + val minSdk = if (isEnterpriseBuild) 26 else 24 val javaCompileVersion = JavaVersion.VERSION_17 val javaLanguageVersion: JavaLanguageVersion = JavaLanguageVersion.of(11) } diff --git a/plugins/src/main/kotlin/extension/DependencyHandleScope.kt b/plugins/src/main/kotlin/extension/DependencyHandleScope.kt index 4aa635b489..9fd82af4ae 100644 --- a/plugins/src/main/kotlin/extension/DependencyHandleScope.kt +++ b/plugins/src/main/kotlin/extension/DependencyHandleScope.kt @@ -130,6 +130,11 @@ fun DependencyHandlerScope.allServicesImpl() { implementation(project(":services:toolbox:impl")) } +fun DependencyHandlerScope.allEnterpriseImpl(rootDir: File, logger: Logger) { + val enterpriseDir = File(rootDir, "enterprise") + addImplementationProjects(enterpriseDir, ":enterprise", "impl", logger) +} + fun DependencyHandlerScope.allFeaturesApi(rootDir: File, logger: Logger) { val featuresDir = File(rootDir, "features") addImplementationProjects(featuresDir, ":features", "api", logger) diff --git a/settings.gradle.kts b/settings.gradle.kts index b154f4585e..693a258447 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -87,6 +87,7 @@ fun includeProjects(directory: File, path: String, maxDepth: Int = 1) { } } +includeProjects(File(rootDir, "enterprise"), ":enterprise", maxDepth = 2) includeProjects(File(rootDir, "features"), ":features") includeProjects(File(rootDir, "libraries"), ":libraries") includeProjects(File(rootDir, "services"), ":services") diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt index f126640149..a34f0282a7 100644 --- a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt @@ -112,6 +112,7 @@ class KonsistClassNameTest { "DBov", "Default", "DataStore", + "Enterprise", "FileExtensionExtractor", "KeyStore", "Matrix", From e6b91c4c36de126ea3438eef4188a3d555cbbbf3 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 12 Jun 2024 19:19:42 +0200 Subject: [PATCH 03/29] CI: build Element Enterprise --- .github/workflows/build_enterprise.yml | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/build_enterprise.yml diff --git a/.github/workflows/build_enterprise.yml b/.github/workflows/build_enterprise.yml new file mode 100644 index 0000000000..a9b8706c98 --- /dev/null +++ b/.github/workflows/build_enterprise.yml @@ -0,0 +1,64 @@ +name: Enterprise APK Build + +on: + workflow_dispatch: + pull_request: + merge_group: + push: + branches: [ develop ] + +# Enrich gradle.properties for CI/CD +env: + GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx7g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.incremental=false -XX:+UseG1GC + CI_GRADLE_ARG_PROPERTIES: --stacktrace -Dsonar.gradle.skipCompile=true + +jobs: + build: + name: Build Enterprise APKs + runs-on: ubuntu-latest + # Skip for `main` + if: github.ref != 'refs/heads/main' + strategy: + matrix: + variant: [debug, release, nightly] + fail-fast: false + # Allow all jobs on develop. Just one per PR. + concurrency: + group: ${{ github.ref == 'refs/heads/develop' && format('build-develop-enterprise-{0}-{1}', matrix.variant, github.sha) || format('build-enterprise-{0}-{1}', matrix.variant, github.ref) }} + cancel-in-progress: true + steps: + - uses: actions/checkout@v4 + with: + submodules: 'true' + # Ensure we are building the branch and not the branch after being merged on develop + # https://github.com/actions/checkout/issues/881 + ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }} + - name: Use JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '17' + - name: Configure gradle + uses: gradle/actions/setup-gradle@v3 + with: + cache-read-only: ${{ github.ref != 'refs/heads/develop' }} + - name: Assemble debug Gplay Enterprise APK + if: ${{ matrix.variant == 'debug' }} + env: + ELEMENT_ANDROID_MAPTILER_API_KEY: ${{ secrets.MAPTILER_KEY }} + ELEMENT_ANDROID_MAPTILER_LIGHT_MAP_ID: ${{ secrets.MAPTILER_LIGHT_MAP_ID }} + ELEMENT_ANDROID_MAPTILER_DARK_MAP_ID: ${{ secrets.MAPTILER_DARK_MAP_ID }} + run: ./gradlew :app:assembleGplayDebug -PallWarningsAsErrors=true $CI_GRADLE_ARG_PROPERTIES + - name: Upload debug Enterprise APKs + if: ${{ matrix.variant == 'debug' }} + uses: actions/upload-artifact@v4 + with: + name: elementx-enterprise-debug + path: | + app/build/outputs/apk/gplay/debug/*-universal-debug.apk + - name: Compile release sources + if: ${{ matrix.variant == 'release' }} + run: ./gradlew compileReleaseSources -PallWarningsAsErrors=true $CI_GRADLE_ARG_PROPERTIES + - name: Compile nightly sources + if: ${{ matrix.variant == 'nightly' }} + run: ./gradlew compileGplayNightlySources -PallWarningsAsErrors=true $CI_GRADLE_ARG_PROPERTIES From 3ca0a05212398abb6fb388bdac4826677798c975 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 12 Jun 2024 19:21:55 +0200 Subject: [PATCH 04/29] CI: build Element Enterprise nightly --- .github/workflows/nightly_enterprise.yml | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/nightly_enterprise.yml diff --git a/.github/workflows/nightly_enterprise.yml b/.github/workflows/nightly_enterprise.yml new file mode 100644 index 0000000000..97dc23c312 --- /dev/null +++ b/.github/workflows/nightly_enterprise.yml @@ -0,0 +1,53 @@ +name: Build and release Enterprise nightly application + +on: + workflow_dispatch: + schedule: + # Every nights at 4 + - cron: "0 4 * * *" + +env: + GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx6g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.incremental=false -XX:+UseG1GC + CI_GRADLE_ARG_PROPERTIES: --stacktrace --no-daemon -Dsonar.gradle.skipCompile=true + +jobs: + nightly: + name: Build and publish Enterprise nightly bundle to Firebase + runs-on: ubuntu-latest + if: ${{ github.repository == 'element-hq/element-x-android' }} + steps: + - uses: actions/checkout@v4 + with: + submodules: 'true' + - name: Use JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '17' + - name: Install towncrier + run: | + python3 -m pip install towncrier + - name: Prepare changelog file + run: | + mv towncrier.toml towncrier.toml.bak + sed 's/CHANGES\.md/CHANGES_NIGHTLY\.md/' towncrier.toml.bak > towncrier.toml + rm towncrier.toml.bak + yes n | towncrier build --version nightly + - name: Build and upload Nightly application + run: | + ./gradlew assembleGplayNightly appDistributionUploadGplayNightly $CI_GRADLE_ARG_PROPERTIES + env: + ELEMENT_ANDROID_MAPTILER_API_KEY: ${{ secrets.MAPTILER_KEY }} + ELEMENT_ANDROID_MAPTILER_LIGHT_MAP_ID: ${{ secrets.MAPTILER_LIGHT_MAP_ID }} + ELEMENT_ANDROID_MAPTILER_DARK_MAP_ID: ${{ secrets.MAPTILER_DARK_MAP_ID }} + ELEMENT_ANDROID_NIGHTLY_KEYID: ${{ secrets.ELEMENT_ANDROID_NIGHTLY_KEYID }} + ELEMENT_ANDROID_NIGHTLY_KEYPASSWORD: ${{ secrets.ELEMENT_ANDROID_NIGHTLY_KEYPASSWORD }} + ELEMENT_ANDROID_NIGHTLY_STOREPASSWORD: ${{ secrets.ELEMENT_ANDROID_NIGHTLY_STOREPASSWORD }} + FIREBASE_TOKEN: ${{ secrets.ELEMENT_ANDROID_NIGHTLY_FIREBASE_TOKEN }} + - name: Additionally upload Nightly APK to browserstack for testing + continue-on-error: true # don't block anything by this upload failing (for now) + run: | + curl -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_PASSWORD" -X POST "https://api-cloud.browserstack.com/app-automate/upload" -F "file=@app/build/outputs/apk/gplay/nightly/app-gplay-universal-nightly.apk" -F "custom_id=element-x-android-nightly" + env: + BROWSERSTACK_USERNAME: ${{ secrets.ELEMENT_ANDROID_BROWSERSTACK_USERNAME }} + BROWSERSTACK_PASSWORD: ${{ secrets.ELEMENT_ANDROID_BROWSERSTACK_ACCESS_KEY }} From a75df67c4dab86a1944a8c14d0deb7f198b0bb8e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 12 Jun 2024 19:23:07 +0200 Subject: [PATCH 05/29] CI: release Element Enterprise --- .github/workflows/release.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f596d5e438..af3abba254 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,6 +39,36 @@ jobs: path: | app/build/outputs/bundle/gplayRelease/app-gplay-release.aab + enterprise: + name: Create App Bundle Enterprise + runs-on: ubuntu-latest + concurrency: + group: ${{ format('build-release-main-gplay-{0}', github.sha) }} + cancel-in-progress: true + steps: + - uses: actions/checkout@v4 + with: + submodules: 'true' + - name: Use JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' # See 'Supported distributions' for available options + java-version: '17' + - name: Configure gradle + uses: gradle/actions/setup-gradle@v3 + - name: Create Enterprise app bundle + env: + ELEMENT_ANDROID_MAPTILER_API_KEY: ${{ secrets.MAPTILER_KEY }} + ELEMENT_ANDROID_MAPTILER_LIGHT_MAP_ID: ${{ secrets.MAPTILER_LIGHT_MAP_ID }} + ELEMENT_ANDROID_MAPTILER_DARK_MAP_ID: ${{ secrets.MAPTILER_DARK_MAP_ID }} + run: ./gradlew bundleGplayRelease $CI_GRADLE_ARG_PROPERTIES + - name: Upload bundle as artifact + uses: actions/upload-artifact@v4 + with: + name: elementx-enterprise-app-gplay-bundle-unsigned + path: | + app/build/outputs/bundle/gplayRelease/app-gplay-release.aab + fdroid: name: Create APKs (FDroid) runs-on: ubuntu-latest From 4fdf5907eee175ca91f01b14e94d8b29abf80c21 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 09:41:15 +0200 Subject: [PATCH 06/29] Use deploy key to build Element Enterprise --- .github/workflows/build_enterprise.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_enterprise.yml b/.github/workflows/build_enterprise.yml index a9b8706c98..6b47b57c2e 100644 --- a/.github/workflows/build_enterprise.yml +++ b/.github/workflows/build_enterprise.yml @@ -29,10 +29,15 @@ jobs: steps: - uses: actions/checkout@v4 with: - submodules: 'true' # Ensure we are building the branch and not the branch after being merged on develop # https://github.com/actions/checkout/issues/881 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }} + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 with: From e7893560fdebfeece15fad715e9854bcb4bafb1e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 09:48:55 +0200 Subject: [PATCH 07/29] Use deploy key to build Element Enterprise --- .github/workflows/nightly_enterprise.yml | 6 +++++- .github/workflows/release.yml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/nightly_enterprise.yml b/.github/workflows/nightly_enterprise.yml index 97dc23c312..9cd80fe094 100644 --- a/.github/workflows/nightly_enterprise.yml +++ b/.github/workflows/nightly_enterprise.yml @@ -17,8 +17,12 @@ jobs: if: ${{ github.repository == 'element-hq/element-x-android' }} steps: - uses: actions/checkout@v4 + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 with: - submodules: 'true' + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af3abba254..b58f2f3348 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -47,8 +47,12 @@ jobs: cancel-in-progress: true steps: - uses: actions/checkout@v4 + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 with: - submodules: 'true' + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 with: From d19829b845f947043dc274a83260644339b4a129 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 09:49:27 +0200 Subject: [PATCH 08/29] Apply quality checks to Element Enterprise modules. --- .github/workflows/danger.yml | 6 ++++++ .github/workflows/quality.yml | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index 4d71f56617..405bb346c5 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -8,6 +8,12 @@ jobs: name: Danger main check steps: - uses: actions/checkout@v4 + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - run: | npm install --save-dev @babel/plugin-transform-flow-strip-types - name: Danger diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 1c3ab1d7d5..52a0b10572 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -18,6 +18,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Run code quality check suite run: ./tools/check/check_code_quality.sh @@ -68,6 +74,12 @@ jobs: # Ensure we are building the branch and not the branch after being merged on develop # https://github.com/actions/checkout/issues/881 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }} + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 with: @@ -100,6 +112,12 @@ jobs: # Ensure we are building the branch and not the branch after being merged on develop # https://github.com/actions/checkout/issues/881 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }} + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 with: @@ -136,6 +154,12 @@ jobs: # Ensure we are building the branch and not the branch after being merged on develop # https://github.com/actions/checkout/issues/881 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }} + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 with: @@ -168,6 +192,12 @@ jobs: # Ensure we are building the branch and not the branch after being merged on develop # https://github.com/actions/checkout/issues/881 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }} + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 with: @@ -200,6 +230,12 @@ jobs: # Ensure we are building the branch and not the branch after being merged on develop # https://github.com/actions/checkout/issues/881 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }} + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 with: From 1ba0399dbc165fdd11343b6da0ad9f5801c35bac Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 09:50:00 +0200 Subject: [PATCH 09/29] Run tests on Element Enterprise modules. --- .github/workflows/tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1d41100940..eb5dbd456c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -38,6 +38,12 @@ jobs: # Ensure we are building the branch and not the branch after being merged on develop # https://github.com/actions/checkout/issues/881 ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.ref }} + - name: Add SSH private keys for submodule repositories + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} + - name: Clone submodules + run: git submodule update --init --recursive - name: ☕️ Use JDK 17 uses: actions/setup-java@v4 with: From f591b48bed7eb304b6cd1ab618679a3b6c437f2c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 10:12:52 +0200 Subject: [PATCH 10/29] Fix quality issue and add tests. --- .../enterprise/api}/EnterpriseService.kt | 5 ++- features/enterprise/impl/build.gradle.kts | 6 ++++ .../impl}/DefaultEnterpriseService.kt | 8 +++-- .../impl/DefaultEnterpriseServiceTest.kt | 36 +++++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) rename features/enterprise/api/src/main/kotlin/{io.element.android.features.enterprise.api => io/element/android/features/enterprise/api}/EnterpriseService.kt (80%) rename features/enterprise/impl/src/main/kotlin/{io.element.android.features.enterprise.impl => io/element/android/features/enterprise/impl}/DefaultEnterpriseService.kt (76%) create mode 100644 features/enterprise/impl/src/test/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseServiceTest.kt diff --git a/features/enterprise/api/src/main/kotlin/io.element.android.features.enterprise.api/EnterpriseService.kt b/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt similarity index 80% rename from features/enterprise/api/src/main/kotlin/io.element.android.features.enterprise.api/EnterpriseService.kt rename to features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt index 74d56b3191..3c27af8629 100644 --- a/features/enterprise/api/src/main/kotlin/io.element.android.features.enterprise.api/EnterpriseService.kt +++ b/features/enterprise/api/src/main/kotlin/io/element/android/features/enterprise/api/EnterpriseService.kt @@ -16,6 +16,9 @@ package io.element.android.features.enterprise.api +import io.element.android.libraries.matrix.api.core.SessionId + interface EnterpriseService { - suspend fun isEnterpriseUser(): Boolean + val isEnterpriseBuild: Boolean + suspend fun isEnterpriseUser(sessionId: SessionId): Boolean } diff --git a/features/enterprise/impl/build.gradle.kts b/features/enterprise/impl/build.gradle.kts index e6d477b0ed..52be564089 100644 --- a/features/enterprise/impl/build.gradle.kts +++ b/features/enterprise/impl/build.gradle.kts @@ -27,4 +27,10 @@ dependencies { api(libs.anvil.compiler.api) api(projects.features.enterprise.api) implementation(projects.libraries.architecture) + implementation(projects.libraries.matrix.api) + + testImplementation(libs.coroutines.test) + testImplementation(libs.test.junit) + testImplementation(libs.test.truth) + testImplementation(projects.libraries.matrix.test) } diff --git a/features/enterprise/impl/src/main/kotlin/io.element.android.features.enterprise.impl/DefaultEnterpriseService.kt b/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt similarity index 76% rename from features/enterprise/impl/src/main/kotlin/io.element.android.features.enterprise.impl/DefaultEnterpriseService.kt rename to features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt index 751c189c76..f8bb46b749 100644 --- a/features/enterprise/impl/src/main/kotlin/io.element.android.features.enterprise.impl/DefaultEnterpriseService.kt +++ b/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt @@ -18,11 +18,13 @@ package io.element.android.features.enterprise.impl import com.squareup.anvil.annotations.ContributesBinding import io.element.android.features.enterprise.api.EnterpriseService -import io.element.android.libraries.di.SessionScope +import io.element.android.libraries.di.AppScope +import io.element.android.libraries.matrix.api.core.SessionId import javax.inject.Inject -@ContributesBinding(SessionScope::class) +@ContributesBinding(AppScope::class) class DefaultEnterpriseService @Inject constructor( + override val isEnterpriseBuild: Boolean = false ) : EnterpriseService { - override suspend fun isEnterpriseUser(): Boolean = false + override suspend fun isEnterpriseUser(sessionId: SessionId) = false } diff --git a/features/enterprise/impl/src/test/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseServiceTest.kt b/features/enterprise/impl/src/test/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseServiceTest.kt new file mode 100644 index 0000000000..003ca2ffc9 --- /dev/null +++ b/features/enterprise/impl/src/test/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseServiceTest.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.features.enterprise.impl + +import com.google.common.truth.Truth.assertThat +import io.element.android.libraries.matrix.test.A_SESSION_ID +import kotlinx.coroutines.test.runTest +import org.junit.Test + +class DefaultEnterpriseServiceTest { + @Test + fun `isEnterpriseBuild is false`() { + val defaultEnterpriseService = DefaultEnterpriseService() + assertThat(defaultEnterpriseService.isEnterpriseBuild).isFalse() + } + + @Test + fun `isEnterpriseUser always return false`() = runTest { + val defaultEnterpriseService = DefaultEnterpriseService() + assertThat(defaultEnterpriseService.isEnterpriseUser(A_SESSION_ID)).isFalse() + } +} From 03491b81e7407e498859bf8ddddbf477034c12a7 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 10:33:46 +0200 Subject: [PATCH 11/29] lift out assignment. --- app/build.gradle.kts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 92febf82d9..8a5464bc04 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -47,10 +47,10 @@ android { namespace = "io.element.android.x" defaultConfig { - if (isEnterpriseBuild) { - applicationId = "io.element.enterprise" + applicationId = if (isEnterpriseBuild) { + "io.element.enterprise" } else { - applicationId = "io.element.android.x" + "io.element.android.x" } targetSdk = Versions.targetSdk versionCode = Versions.versionCode From ff78512b78e8c939c0ceda8c8161c788ea557ba2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 11:14:53 +0200 Subject: [PATCH 12/29] Add `isEnterpriseBuild` to BuildMeta --- app/src/main/kotlin/io/element/android/x/di/AppModule.kt | 8 +++++++- .../io/element/android/libraries/core/meta/BuildMeta.kt | 1 + .../android/libraries/matrix/test/core/BuildMeta.kt | 2 ++ .../io/element/android/samples/minimal/Singleton.kt | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/io/element/android/x/di/AppModule.kt b/app/src/main/kotlin/io/element/android/x/di/AppModule.kt index dd0ad775fe..7614d54e01 100644 --- a/app/src/main/kotlin/io/element/android/x/di/AppModule.kt +++ b/app/src/main/kotlin/io/element/android/x/di/AppModule.kt @@ -24,6 +24,7 @@ import com.squareup.anvil.annotations.ContributesTo import dagger.Module import dagger.Provides import io.element.android.appconfig.ApplicationConfig +import io.element.android.features.enterprise.api.EnterpriseService import io.element.android.features.messages.impl.timeline.components.customreaction.DefaultEmojibaseProvider import io.element.android.features.messages.impl.timeline.components.customreaction.EmojibaseProvider import io.element.android.libraries.androidutils.system.getVersionCodeFromManifest @@ -77,13 +78,18 @@ object AppModule { @Provides @SingleIn(AppScope::class) - fun providesBuildMeta(@ApplicationContext context: Context, buildType: BuildType) = BuildMeta( + fun providesBuildMeta( + @ApplicationContext context: Context, + buildType: BuildType, + enterpriseService: EnterpriseService, + ) = BuildMeta( isDebuggable = BuildConfig.DEBUG, buildType = buildType, applicationName = ApplicationConfig.APPLICATION_NAME.takeIf { it.isNotEmpty() } ?: context.getString(R.string.app_name), productionApplicationName = ApplicationConfig.PRODUCTION_APPLICATION_NAME, desktopApplicationName = ApplicationConfig.DESKTOP_APPLICATION_NAME, applicationId = BuildConfig.APPLICATION_ID, + isEnterpriseBuild = enterpriseService.isEnterpriseBuild, // TODO EAx Config.LOW_PRIVACY_LOG_ENABLE, lowPrivacyLoggingEnabled = false, versionName = BuildConfig.VERSION_NAME, diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt index a9cb78548f..2d62a5be70 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt @@ -23,6 +23,7 @@ data class BuildMeta( val productionApplicationName: String, val desktopApplicationName: String, val applicationId: String, + val isEnterpriseBuild: Boolean, val lowPrivacyLoggingEnabled: Boolean, val versionName: String, val versionCode: Long, diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt index 52c15d05a4..569c33db7d 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/core/BuildMeta.kt @@ -26,6 +26,7 @@ fun aBuildMeta( productionApplicationName: String = applicationName, desktopApplicationName: String = applicationName, applicationId: String = "", + isEnterpriseBuild: Boolean = false, lowPrivacyLoggingEnabled: Boolean = true, versionName: String = "", versionCode: Long = 0, @@ -40,6 +41,7 @@ fun aBuildMeta( productionApplicationName = productionApplicationName, desktopApplicationName = desktopApplicationName, applicationId = applicationId, + isEnterpriseBuild = isEnterpriseBuild, lowPrivacyLoggingEnabled = lowPrivacyLoggingEnabled, versionName = versionName, versionCode = versionCode, diff --git a/samples/minimal/src/main/kotlin/io/element/android/samples/minimal/Singleton.kt b/samples/minimal/src/main/kotlin/io/element/android/samples/minimal/Singleton.kt index 9c09d0bc98..22cfd643a1 100644 --- a/samples/minimal/src/main/kotlin/io/element/android/samples/minimal/Singleton.kt +++ b/samples/minimal/src/main/kotlin/io/element/android/samples/minimal/Singleton.kt @@ -36,6 +36,7 @@ object Singleton { productionApplicationName = "EAX-Minimal", desktopApplicationName = "EAX-Minimal-Desktop", applicationId = "io.element.android.samples.minimal", + isEnterpriseBuild = false, lowPrivacyLoggingEnabled = false, versionName = "0.1.0", versionCode = 1, From 96249c14bdd6ceb668303bd6fd2a6708458e38a7 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 11:44:44 +0200 Subject: [PATCH 13/29] Change application name for EXE build --- app/build.gradle.kts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 8a5464bc04..b980965753 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -104,15 +104,21 @@ android { } } + val baseAppName = if (isEnterpriseBuild) { + "Element Enterprise" + } else { + "Element X" + } + buildTypes { getByName("debug") { - resValue("string", "app_name", "Element X dbg") + resValue("string", "app_name", "$baseAppName dbg") applicationIdSuffix = ".debug" signingConfig = signingConfigs.getByName("debug") } getByName("release") { - resValue("string", "app_name", "Element X") + resValue("string", "app_name", baseAppName) signingConfig = signingConfigs.getByName("debug") postprocessing { @@ -129,7 +135,7 @@ android { initWith(release) applicationIdSuffix = ".nightly" versionNameSuffix = "-nightly" - resValue("string", "app_name", "Element X nightly") + resValue("string", "app_name", "$baseAppName nightly") matchingFallbacks += listOf("release") signingConfig = signingConfigs.getByName("nightly") From ab5a54afd012f6a2830d38fdc00dd64494816f48 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 11:46:34 +0200 Subject: [PATCH 14/29] Fix compilation issue. --- .../features/enterprise/impl/DefaultEnterpriseService.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt b/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt index f8bb46b749..0b32e66a79 100644 --- a/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt +++ b/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt @@ -24,7 +24,8 @@ import javax.inject.Inject @ContributesBinding(AppScope::class) class DefaultEnterpriseService @Inject constructor( - override val isEnterpriseBuild: Boolean = false ) : EnterpriseService { + override val isEnterpriseBuild = false + override suspend fun isEnterpriseUser(sessionId: SessionId) = false } From f339bd5d25594f1a536daa9de92af6d5ec2a4798 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 13 Jun 2024 12:21:26 +0200 Subject: [PATCH 15/29] Gradle: log which application is built. --- app/build.gradle.kts | 1 + plugins/src/main/kotlin/Logger.kt | 55 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 plugins/src/main/kotlin/Logger.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b980965753..58110245cd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -109,6 +109,7 @@ android { } else { "Element X" } + logger.warnInBox("Building $baseAppName") buildTypes { getByName("debug") { diff --git a/plugins/src/main/kotlin/Logger.kt b/plugins/src/main/kotlin/Logger.kt new file mode 100644 index 0000000000..fa608e7df4 --- /dev/null +++ b/plugins/src/main/kotlin/Logger.kt @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.gradle.api.logging.Logger +import kotlin.math.max + +fun Logger.warnInBox( + text: String, + minBoxWidth: Int = 80, + padding: Int = 4, +) { + val textLength = text.length + val boxWidth = max(textLength + 2, minBoxWidth) + val textPadding = max((boxWidth - textLength) / 2, 1) + warn( + buildString { + append(" ".repeat(padding)) + append("┌") + append("─".repeat(boxWidth)) + append("┐") + } + ) + warn( + buildString { + append(" ".repeat(padding)) + append("│") + append(" ".repeat(textPadding)) + append(text) + append(" ".repeat(textPadding)) + if (textLength % 2 == 1 && boxWidth == minBoxWidth) append(" ") + append("│") + } + ) + warn( + buildString { + append(" ".repeat(padding)) + append("└") + append("─".repeat(boxWidth)) + append("┘") + } + ) +} From 3139ab06c9ca9bc41f187e891f9c62620f06c954 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 14 Jun 2024 11:42:37 +0200 Subject: [PATCH 16/29] Fix quality issue --- .../features/enterprise/impl/DefaultEnterpriseService.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt b/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt index 0b32e66a79..c3387259b8 100644 --- a/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt +++ b/features/enterprise/impl/src/main/kotlin/io/element/android/features/enterprise/impl/DefaultEnterpriseService.kt @@ -23,8 +23,7 @@ import io.element.android.libraries.matrix.api.core.SessionId import javax.inject.Inject @ContributesBinding(AppScope::class) -class DefaultEnterpriseService @Inject constructor( -) : EnterpriseService { +class DefaultEnterpriseService @Inject constructor() : EnterpriseService { override val isEnterpriseBuild = false override suspend fun isEnterpriseUser(sessionId: SessionId) = false From 94d72e09612eed74b3a6c2dd0a1b1d9f2a0cbd56 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 14 Jun 2024 11:42:57 +0200 Subject: [PATCH 17/29] Add 'Enterprise' label to rageshake --- .../features/rageshake/impl/reporter/DefaultBugReporter.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt index f9f8d7e5b9..72e668c3f4 100755 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt @@ -169,6 +169,9 @@ class DefaultBugReporter @Inject constructor( currentTracingFilter?.let { builder.addFormDataPart("tracing_filter", it) } + if (buildMeta.isEnterpriseBuild) { + builder.addFormDataPart("label", "Enterprise") + } // add the gzipped files, don't cancel the whole upload if only some file failed to upload var totalUploadedSize = 0L var uploadedSomeLogs = false From d43b0e840180b7cf0d6f29165621150b7401d711 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Jun 2024 10:43:46 +0200 Subject: [PATCH 18/29] Remove the method `supportNotificationChannels()` from SystemUtils, it has been copied in `NotificationChannels.kt` --- .../android/libraries/androidutils/system/SystemUtils.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt index 49e055cc29..5b9866254d 100644 --- a/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt +++ b/libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/system/SystemUtils.kt @@ -26,16 +26,12 @@ import android.os.Build import android.provider.Settings import android.widget.Toast import androidx.activity.result.ActivityResultLauncher -import androidx.annotation.ChecksSdkIntAtLeast import androidx.annotation.RequiresApi import androidx.core.content.pm.PackageInfoCompat import io.element.android.libraries.androidutils.R import io.element.android.libraries.androidutils.compat.getApplicationInfoCompat import io.element.android.libraries.core.mimetype.MimeTypes -@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O) -fun supportNotificationChannels() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O - /** * Return the application label of the provided package. If not found, the package is returned. */ From 68cc0cf8764737bad966afea9d4f35fb88ef0ceb Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Jun 2024 10:57:29 +0200 Subject: [PATCH 19/29] Lint: Disable check of "ObsoleteSdkInt" since the min sdk is higher on Enterprise builds --- plugins/src/main/kotlin/extension/CommonExtension.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/src/main/kotlin/extension/CommonExtension.kt b/plugins/src/main/kotlin/extension/CommonExtension.kt index 271b1565f5..bc063d5921 100644 --- a/plugins/src/main/kotlin/extension/CommonExtension.kt +++ b/plugins/src/main/kotlin/extension/CommonExtension.kt @@ -18,6 +18,7 @@ package extension import Versions import com.android.build.api.dsl.CommonExtension +import isEnterpriseBuild import org.gradle.accessors.dm.LibrariesForLibs import org.gradle.api.JavaVersion import org.gradle.api.Project @@ -46,6 +47,11 @@ fun CommonExtension<*, *, *, *, *, *>.androidConfig(project: Project) { lint { lintConfig = File("${project.rootDir}/tools/lint/lint.xml") + if (isEnterpriseBuild) { + // Disable check on ObsoleteSdkInt for Enterprise builds + // since the min sdk is higher for Enterprise builds + disable.add("ObsoleteSdkInt") + } checkDependencies = false abortOnError = true ignoreTestFixturesSources = true From 4f39490fd0213f9945831a8c2debba1e8d9878f3 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 27 Jun 2024 09:34:49 +0200 Subject: [PATCH 20/29] Remove useless if, this workflow is not triggered when pushing the `main` branch. --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59991cdcf9..92380492a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,8 +16,6 @@ jobs: debug: name: Build APKs runs-on: ubuntu-latest - # Skip for `main` - if: github.ref != 'refs/heads/main' strategy: matrix: variant: [debug, release, nightly, samples] From 66bd58a8b2533f12fad0874e48065bfdaf189a34 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 27 Jun 2024 09:35:33 +0200 Subject: [PATCH 21/29] Skip build Element Enterprise on forks. --- .github/workflows/build_enterprise.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_enterprise.yml b/.github/workflows/build_enterprise.yml index 6b47b57c2e..7547d5291c 100644 --- a/.github/workflows/build_enterprise.yml +++ b/.github/workflows/build_enterprise.yml @@ -16,8 +16,8 @@ jobs: build: name: Build Enterprise APKs runs-on: ubuntu-latest - # Skip for `main` - if: github.ref != 'refs/heads/main' + # Skip in forks + if: github.repository == 'element-hq/element-x-android' strategy: matrix: variant: [debug, release, nightly] From 4fa33721dded0a99d1fe72bb2c163c760ab2d91c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 27 Jun 2024 14:06:02 +0200 Subject: [PATCH 22/29] Remove not needed dependency on libs.anvil.compiler.api and fix compilation issue of EXA. --- features/enterprise/impl/build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/features/enterprise/impl/build.gradle.kts b/features/enterprise/impl/build.gradle.kts index 52be564089..eb87d9310b 100644 --- a/features/enterprise/impl/build.gradle.kts +++ b/features/enterprise/impl/build.gradle.kts @@ -24,7 +24,6 @@ android { dependencies { implementation(projects.anvilannotations) - api(libs.anvil.compiler.api) api(projects.features.enterprise.api) implementation(projects.libraries.architecture) implementation(projects.libraries.matrix.api) From 92db08909c54d71d2cec186b89d8b3aceb7d0e4d Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 27 Jun 2024 15:30:26 +0200 Subject: [PATCH 23/29] Use Apache License URL with https. --- .idea/copyright/NewVector.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.idea/copyright/NewVector.xml b/.idea/copyright/NewVector.xml index 72a4f2e779..c6843ecc26 100644 --- a/.idea/copyright/NewVector.xml +++ b/.idea/copyright/NewVector.xml @@ -1,6 +1,6 @@ - - \ No newline at end of file + From 4047f4395dcbd5db4fadcc07f22c28922e5307ef Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 27 Jun 2024 15:55:57 +0200 Subject: [PATCH 24/29] Let Konsist checks the license header --- .../tests/konsist/KonsistLicenseTest.kt | 85 +++++++++++++++++++ tools/detekt/detekt.yml | 4 +- tools/detekt/license.template | 15 ---- 3 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt delete mode 100644 tools/detekt/license.template diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt new file mode 100644 index 0000000000..e6cbf9ca14 --- /dev/null +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistLicenseTest.kt @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.element.android.tests.konsist + +import com.lemonappdev.konsist.api.Konsist +import com.lemonappdev.konsist.api.verify.assertTrue +import org.junit.Test + +class KonsistLicenseTest { + private val publicLicense = """ + /\* + (?:.*\n)* \* Copyright \(c\) 20\d\d New Vector Ltd + (?:.*\n)* \* + \* Licensed under the Apache License, Version 2\.0 \(the "License"\); + \* you may not use this file except in compliance with the License\. + \* You may obtain a copy of the License at + \* + \* {5}https?://www\.apache\.org/licenses/LICENSE-2\.0 + \* + \* Unless required by applicable law or agreed to in writing, software + \* distributed under the License is distributed on an "AS IS" BASIS, + \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. + \* See the License for the specific language governing permissions and + \* limitations under the License\. + \*/ + """.trimIndent().toRegex() + + private val enterpriseLicense = """ + /\* + \* © 20\d\d New Vector Limited, Element Software SARL, Element Software Inc\., + \* and Element Software GmbH \(the "Element Group"\) only make this file available + \* under a proprietary license model\. + \* + \* Without a proprietary license with us, you cannot use this file\. The terms of + \* the proprietary license agreement between you and any member of the Element Group + \* shall always apply to your use of this file\. Unauthorised use, copying, distribution, + \* or modification of this file, via any medium, is strictly prohibited\. + \* + \* For details about the licensing terms, you must either visit our website or contact + \* a member of our sales team\. + \*/ + """.trimIndent().toRegex() + + @Test + fun `assert that FOSS files have the correct license header`() { + Konsist + .scopeFromProject() + .files + .filter { + it.path.contains("/enterprise/features").not() && + it.nameWithExtension != "locales.kt" && + it.name.startsWith("Template ").not() + } + .assertTrue { + publicLicense.containsMatchIn(it.text) + } + } + + @Test + fun `assert that Enterprise files have the correct license header`() { + Konsist + .scopeFromProject() + .files + .filter { + it.path.contains("/enterprise/features") + } + .assertTrue { + enterpriseLicense.containsMatchIn(it.text) + } + } +} diff --git a/tools/detekt/detekt.yml b/tools/detekt/detekt.yml index cffb824ea4..7212a58ce3 100644 --- a/tools/detekt/detekt.yml +++ b/tools/detekt/detekt.yml @@ -197,9 +197,7 @@ performance: # Note: all rules for `comments` are disabled by default, but I put them here to be aware of their existence comments: AbsentOrWrongFileLicense: - active: true - licenseTemplateFile: 'license.template' - licenseTemplateIsRegex: true + active: false CommentOverPrivateFunction: active: false CommentOverPrivateProperty: diff --git a/tools/detekt/license.template b/tools/detekt/license.template deleted file mode 100644 index 08cadc82f9..0000000000 --- a/tools/detekt/license.template +++ /dev/null @@ -1,15 +0,0 @@ -\/\* -(?:.*\n)* \* Copyright \(c\) 20\d\d New Vector Ltd -(?:.*\n)* \* - \* Licensed under the Apache License, Version 2\.0 \(the "License"\); - \* you may not use this file except in compliance with the License\. - \* You may obtain a copy of the License at - \* - \* http(?:s)?:\/\/www\.apache\.org\/licenses\/LICENSE-2\.0 - \* - \* Unless required by applicable law or agreed to in writing, software - \* distributed under the License is distributed on an "AS IS" BASIS, - \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. - \* See the License for the specific language governing permissions and - \* limitations under the License\. - \*\/ From 8a65719e44601b19c6c8360e31273d4d29ca5c23 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 11:21:25 +0200 Subject: [PATCH 25/29] Update license header --- enterprise | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enterprise b/enterprise index 2e9be17450..ceb65e32d9 160000 --- a/enterprise +++ b/enterprise @@ -1 +1 @@ -Subproject commit 2e9be1745035ee60a3e9f32f5a65be363ea24a92 +Subproject commit ceb65e32d95052c028a37654a4a0410639f69053 From 4ccbe3a7ec001914102559c2fcc4b0034ed989e8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 11:30:12 +0200 Subject: [PATCH 26/29] Create a scope for enterprise files This allow to let the correct Copyright be applied when creating new file. --- .idea/copyright/{NewVector.xml => Element_FOSS.xml} | 2 +- .idea/copyright/Enterprise.xml | 6 ++++++ .idea/copyright/profiles_settings.xml | 6 +++++- .idea/scopes/Enterprise.xml | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) rename .idea/copyright/{NewVector.xml => Element_FOSS.xml} (93%) create mode 100644 .idea/copyright/Enterprise.xml create mode 100644 .idea/scopes/Enterprise.xml diff --git a/.idea/copyright/NewVector.xml b/.idea/copyright/Element_FOSS.xml similarity index 93% rename from .idea/copyright/NewVector.xml rename to .idea/copyright/Element_FOSS.xml index c6843ecc26..4ab92252ae 100644 --- a/.idea/copyright/NewVector.xml +++ b/.idea/copyright/Element_FOSS.xml @@ -1,6 +1,6 @@ diff --git a/.idea/copyright/Enterprise.xml b/.idea/copyright/Enterprise.xml new file mode 100644 index 0000000000..2d430b4613 --- /dev/null +++ b/.idea/copyright/Enterprise.xml @@ -0,0 +1,6 @@ + + + + diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml index 0875fcecb1..69d52afca4 100644 --- a/.idea/copyright/profiles_settings.xml +++ b/.idea/copyright/profiles_settings.xml @@ -1,3 +1,7 @@ - + + + + + \ No newline at end of file diff --git a/.idea/scopes/Enterprise.xml b/.idea/scopes/Enterprise.xml new file mode 100644 index 0000000000..83599ae680 --- /dev/null +++ b/.idea/scopes/Enterprise.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file From c4bb13098fb64460a5059da14cdcff6b814259f4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 11:53:43 +0200 Subject: [PATCH 27/29] Add a check on `isEnterpriseBuild` before including enterprise module. This is not strictly necessary, since if the enterprise modules are not there, nothing will be included by `allEnterpriseImpl()`, but for clarity, it's better to add this check. --- app/build.gradle.kts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 58110245cd..50a9254398 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -248,7 +248,9 @@ knit { dependencies { allLibrariesImpl() allServicesImpl() - allEnterpriseImpl(rootDir, logger) + if (isEnterpriseBuild) { + allEnterpriseImpl(rootDir, logger) + } allFeaturesImpl(rootDir, logger) implementation(projects.features.migration.api) implementation(projects.anvilannotations) From 0fb7f621ba22b4c00fcb16552653c8f8390c8891 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 11:54:54 +0200 Subject: [PATCH 28/29] Remove unnecessary `packaging` configuration. --- app/build.gradle.kts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 50a9254398..56f77d6ccc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -182,20 +182,6 @@ android { buildConfigField("String", "FLAVOR_DESCRIPTION", "\"FDroid\"") } } - - packaging { - resources.pickFirsts.addAll( - listOf( - "kotlin/annotation/annotation.kotlin_builtins", - "kotlin/collections/collections.kotlin_builtins", - "kotlin/coroutines/coroutines.kotlin_builtins", - "kotlin/internal/internal.kotlin_builtins", - "kotlin/kotlin.kotlin_builtins", - "kotlin/ranges/ranges.kotlin_builtins", - "kotlin/reflect/reflect.kotlin_builtins", - ) - ) - } } androidComponents { From 9a4ec53612e550418382e99067320d2ba1975360 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 1 Jul 2024 12:20:15 +0200 Subject: [PATCH 29/29] Do not clone submodules in forks. --- .github/workflows/danger.yml | 1 + .github/workflows/quality.yml | 6 ++++++ .github/workflows/tests.yml | 1 + 3 files changed, 8 insertions(+) diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index 405bb346c5..b4fd79e5dd 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -13,6 +13,7 @@ jobs: with: ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} - name: Clone submodules + if: github.repository == 'element-hq/element-x-android' run: git submodule update --init --recursive - run: | npm install --save-dev @babel/plugin-transform-flow-strip-types diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 52a0b10572..ff435ee988 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -23,6 +23,7 @@ jobs: with: ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} - name: Clone submodules + if: github.repository == 'element-hq/element-x-android' run: git submodule update --init --recursive - name: Run code quality check suite run: ./tools/check/check_code_quality.sh @@ -79,6 +80,7 @@ jobs: with: ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} - name: Clone submodules + if: github.repository == 'element-hq/element-x-android' run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 @@ -117,6 +119,7 @@ jobs: with: ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} - name: Clone submodules + if: github.repository == 'element-hq/element-x-android' run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 @@ -159,6 +162,7 @@ jobs: with: ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} - name: Clone submodules + if: github.repository == 'element-hq/element-x-android' run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 @@ -197,6 +201,7 @@ jobs: with: ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} - name: Clone submodules + if: github.repository == 'element-hq/element-x-android' run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 @@ -235,6 +240,7 @@ jobs: with: ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} - name: Clone submodules + if: github.repository == 'element-hq/element-x-android' run: git submodule update --init --recursive - name: Use JDK 17 uses: actions/setup-java@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eb5dbd456c..a132fd7d14 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,6 +43,7 @@ jobs: with: ssh-private-key: ${{ secrets.ELEMENT_ENTERPRISE_DEPLOY_KEY }} - name: Clone submodules + if: github.repository == 'element-hq/element-x-android' run: git submodule update --init --recursive - name: ☕️ Use JDK 17 uses: actions/setup-java@v4