Skip to content

Commit

Permalink
Sync fork (#12)
Browse files Browse the repository at this point in the history
* Cleanup/depedencies (Tribler#183)

* Rename FOC dir to foc

* Remove unused dependencies + import transitive dependencies

* Fix import types

* Delete FOC directory

* Delete test/FOC directory

* Rename FOC in androidTest

* Make Service Notification Visible on SDK 31+ (Tribler#185)

* Ask for notification permission

* Update notification style

* Bump `kotlin-ipv8` version

* Unify dependency versions

* Bump `versionName`

* Add caching + fix `buildCode`

* Disable daemons + upgrade `actions/checkout`

* Remove depth from action

* Update fetch depth in apk main

* Add caching to apk main

* Remove daemon in apk main

---------

Co-authored-by: Rowdy Chotkan <[email protected]>
Co-authored-by: Rowdy Mitchell Chotkan <[email protected]>
  • Loading branch information
3 people authored Mar 2, 2024
1 parent 745c2ab commit a24d01c
Show file tree
Hide file tree
Showing 35 changed files with 375 additions and 334 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/apk_debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/checkout_submodules

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
cache: 'gradle'

- name: Build debug APK
run: ./gradlew assembleDebug
run: ./gradlew assembleDebug --no-daemon

- name: Upload APK
uses: actions/upload-artifact@v1
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/apk_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/checkout_submodules

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
cache: 'gradle'

- name: Build release APK
run: |
echo $KEYSTORE_FILE | base64 -d > app/build.keystore
./gradlew assembleRelease \
--no-daemon \
-Pandroid.injected.signing.store.file=$(pwd)/app/build.keystore \
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD \
-Pandroid.injected.signing.key.alias=$KEY_ALIAS \
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/apk_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ jobs:
name: apk_build
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: refs/pull/${{github.event.pull_request.number}}/merge

- uses: ./.github/actions/checkout_submodules

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
cache: 'gradle'

- name: Build release APK
run: |
echo $KEYSTORE_FILE | base64 -d > app/build.keystore
./gradlew assembleRelease \
--no-daemon \
-Pandroid.injected.signing.store.file=$(pwd)/app/build.keystore \
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD \
-Pandroid.injected.signing.key.alias=$KEY_ALIAS \
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ jobs:
- uses: ./.github/actions/checkout_submodules

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'

# TODO: Without this step, the Gradle check task fails with the following error:
# Execution failed for task ':common:verifyDebugDatabaseMigration'.
# > A failure occurred while executing app.cash.sqldelight.gradle.VerifyMigrationTask$VerifyMigrationAction
# > No suitable driver found for jdbc:sqlite:
- name: Run verifyDebugDatabase
run: bash ./gradlew verifyDebugDatabaseMigration
cache: 'gradle'

- name: Run check
run: bash ./gradlew check
run: ./gradlew check --no-daemon

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
90 changes: 47 additions & 43 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {

dependencies {
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
classpath("com.google.dagger:hilt-android-gradle-plugin:$hilt_ver")
classpath("com.google.dagger:hilt-android-gradle-plugin:$dagger_version")

}
}
Expand All @@ -31,7 +31,13 @@ ktlint {

// Generate a version code from git commit count
static def generateVersionCode() {
return "git rev-list HEAD --count".execute().text.trim().toInteger()
// Unix
def result = "git rev-list HEAD --count".execute().text.trim()
// Windows
if (result.empty) result = "PowerShell -Command git rev-list HEAD --count".execute().text.trim()
if (result.empty) throw new RuntimeException("Could not generate versioncode: ${result.text}")
println("Generated the following version code: " + result.toInteger())
return result.toInteger()
}


Expand All @@ -42,11 +48,10 @@ android {
compileSdk 34
targetSdkVersion 34
versionCode generateVersionCode()
versionName "0.3.3"
versionName "0.3.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
keyAlias "trustchain"
Expand Down Expand Up @@ -116,43 +121,25 @@ dependencies {
implementation project(':eurotoken')
implementation project(':valuetransfer')
implementation project(':peerai')
api(project(':common')) {
exclude group: 'net.java.dev.jna'
}
api(project(':common-ethereum')) {
exclude group: 'net.java.dev.jna'
}
api(project(':currencyii')) {
exclude group: 'net.java.dev.jna'
}
api(project(':musicdao')) {
exclude group: 'net.java.dev.jna'
}

implementation 'org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc'
implementation project(':common')
implementation project(':currencyii')
implementation project(':musicdao')

// AndroidX
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "androidx.core:core-ktx:$core_version"
implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version"
implementation "androidx.recyclerview:recyclerview:$recyclerview_version"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.fragment:fragment-ktx:$fragment_version"
implementation "androidx.preference:preference-ktx:1.2.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.work:work-runtime-ktx:2.7.1"

// Firebase
implementation 'com.google.firebase:firebase-analytics:21.2.0'
implementation 'com.google.firebase:firebase-crashlytics:18.3.1'

// Material
implementation 'com.google.android.material:material:1.7.0'
implementation "com.google.android.material:material:$material_version"

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand All @@ -161,29 +148,46 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

// Logging
implementation 'io.github.microutils:kotlin-logging:1.7.7'
implementation('net.java.dev.jna:jna:5.12.1@aar')
implementation('com.github.tony19:logback-android:2.0.0')

implementation 'com.github.MattSkala:recyclerview-itemadapter:0.4'
implementation "com.github.MattSkala:recyclerview-itemadapter:$recyclerview_adapter_version"
implementation project(':currencyii')

// Testing
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
testImplementation "junit:junit:$junit_version"
androidTestImplementation "androidx.test.ext:junit:$android_junit_version"

// Hilt
implementation("com.google.dagger:hilt-android:$hilt_ver")
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
implementation("androidx.hilt:hilt-navigation-compose:1.1.0-alpha01")
kapt("com.google.dagger:hilt-android-compiler:$hilt_ver")
implementation("com.google.dagger:hilt-android:$dagger_version")
kapt("com.google.dagger:hilt-android-compiler:$dagger_version")

// Room
implementation "androidx.room:room-runtime:$room_version"
implementation("androidx.room:room-ktx:$room_version")
annotationProcessor "androidx.room:room-compiler:$room_version"
kapt("androidx.room:room-compiler:$room_version")

// Transitive dependencies
androidTestImplementation 'androidx.test:monitor:1.6.1'
implementation 'androidx.annotation:annotation:1.5.0'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation "androidx.core:core:$core_version"
implementation 'androidx.datastore:datastore-core:1.0.0'
implementation 'androidx.datastore:datastore-preferences-core:1.0.0'
implementation "androidx.fragment:fragment:$fragment_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.sqlite:sqlite:2.4.0'
implementation "app.cash.sqldelight:android-driver:$sqldelight_version"
implementation "app.cash.sqldelight:runtime:$sqldelight_version"
implementation 'com.google.dagger:dagger:2.50'
implementation "com.google.dagger:hilt-core:$dagger_version"
implementation 'com.google.errorprone:error_prone_annotations:2.9.0'
implementation 'com.google.guava:guava:31.0.1-android'
implementation 'javax.inject:javax.inject:1'
implementation(project(':ipv8')) {
exclude module: 'lazysodium-java'
}
implementation project(':ipv8-android')
kapt 'com.google.dagger:dagger-compiler:2.50'
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ import android.app.PendingIntent
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.app.TaskStackBuilder
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.ipv8.android.service.IPv8Service
import nl.tudelft.trustchain.app.R
import nl.tudelft.trustchain.app.ui.dashboard.DashboardActivity

class TrustChainService : IPv8Service() {
override fun onCreate() {
super.onCreate()
scope.launch {
while (true) {
updateNotification()
delay(1000)
}
}
}

override fun createNotification(): NotificationCompat.Builder {
val trustChainDashboardIntent = Intent(this, DashboardActivity::class.java)
val flags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
Expand All @@ -18,9 +31,11 @@ class TrustChainService : IPv8Service() {
.getPendingIntent(0, flags)

return NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_CONNECTION)
.setContentTitle("IPv8")
.setContentText("Running")
.setSmallIcon(R.drawable.ic_insert_link_black_24dp)
.setContentTitle("IPv8 Service")
.setContentText("Connected to ${IPv8Android.getInstance().network.verifiedPeers.size} peers")
.setSmallIcon(R.drawable.ic_device_hub_black_24dp)
.setColor(getColor(R.color.colorPrimary))
.setContentIntent(pendingIntent)
.setOnlyAlertOnce(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class DashboardActivity : AppCompatActivity() {
// Handle init of IPv8 after requesting permissions; only if Android 12 or higher.
// onPermissionsDenied() is run until user has accepted permissions.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!hasBluetoothPermissions()) {
requestBluetoothPermissions()
if (!hasBluetoothPermissions() || !hasNotificationPermissions()) {
requestPermissions()
} else {
// Only initialize IPv8 if it has not been initialized yet.
try {
Expand Down Expand Up @@ -71,14 +71,19 @@ class DashboardActivity : AppCompatActivity() {
checkSelfPermission(BLUETOOTH_PERMISSIONS_SCAN) == PackageManager.PERMISSION_GRANTED
}

private fun requestBluetoothPermissions() {
private fun hasNotificationPermissions(): Boolean {
return checkSelfPermission(NOTIFICATION_PERMISSION) == PackageManager.PERMISSION_GRANTED
}

private fun requestPermissions() {
requestPermissions(
arrayOf(
BLUETOOTH_PERMISSIONS_ADVERTISE,
BLUETOOTH_PERMISSIONS_CONNECT,
BLUETOOTH_PERMISSIONS_SCAN
BLUETOOTH_PERMISSIONS_SCAN,
NOTIFICATION_PERMISSION
),
BLUETOOTH_PERMISSIONS_REQUEST_CODE
PERMISSIONS_REQUEST_CODE
)
}

Expand All @@ -87,19 +92,17 @@ class DashboardActivity : AppCompatActivity() {
permissions: Array<out String>,
grantResults: IntArray
) {
when (requestCode) {
BLUETOOTH_PERMISSIONS_REQUEST_CODE -> {
if (hasBluetoothPermissions()) {
(application as TrustChainApplication).initIPv8()
} else {
onPermissionsDenied()
}
if (requestCode == PERMISSIONS_REQUEST_CODE) {
if (!hasBluetoothPermissions() || !hasNotificationPermissions()) {
onPermissionsDenied()
} else {
(application as TrustChainApplication).initIPv8()
}
else -> super.onRequestPermissionsResult(requestCode, permissions, grantResults)
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
}

@Suppress("DEPRECATION")
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
Expand All @@ -113,12 +116,11 @@ class DashboardActivity : AppCompatActivity() {
onPermissionsDenied()
}
}

else -> {
@Suppress("DEPRECATION") // TODO: Fix deprecation issue.
super.onActivityResult(requestCode, resultCode, data)
}
}
@Suppress("DEPRECATION") // TODO: Fix deprecation issue.
super.onActivityResult(requestCode, resultCode, data)
}

Expand All @@ -141,10 +143,11 @@ class DashboardActivity : AppCompatActivity() {
}

companion object {
private const val BLUETOOTH_PERMISSIONS_REQUEST_CODE = 200
private const val PERMISSIONS_REQUEST_CODE = 200
private const val SETTINGS_INTENT_CODE = 1000
private const val BLUETOOTH_PERMISSIONS_SCAN = "android.permission.BLUETOOTH_SCAN"
private const val BLUETOOTH_PERMISSIONS_CONNECT = "android.permission.BLUETOOTH_CONNECT"
private const val BLUETOOTH_PERMISSIONS_ADVERTISE = "android.permission.BLUETOOTH_ADVERTISE"
private const val NOTIFICATION_PERMISSION = "android.permission.POST_NOTIFICATIONS"
}
}
Loading

0 comments on commit a24d01c

Please sign in to comment.