Skip to content

Commit

Permalink
Merge pull request #549 from hannesa2/api34-3.x
Browse files Browse the repository at this point in the history
Api34 3.x
  • Loading branch information
hannesa2 authored Jan 17, 2024
2 parents 7b20ce8 + a7392a7 commit a80aaef
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
max_line_length = 150

[*.{kt, kts}]
disabled_rules=no-consecutive-blank-lines,no-wildcard-imports,import-ordering,max-line-length,import-ordering,no-blank-line-before-rbrace,final-newline,indent,no-multi-spaces,comment-spacing,parameter-list-wrapping
ktlint_disabled_rules=argument-list-wrapping,wrapping,multiline-if-else,no-consecutive-blank-lines,no-wildcard-imports,import-ordering,max-line-length,import-ordering,no-blank-line-before-rbrace,final-newline,indent,no-multi-spaces,comment-spacing,parameter-list-wrapping
34 changes: 19 additions & 15 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,33 @@ on:

jobs:
Build:
name: Build & Test
runs-on: macOS-latest
name: Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
api: [ 28 ]
abi: [ x86_64 ]
os: [ ARM64 ]
api: [ 34 ]
abi: [ arm64-v8a ]
tag: [ 'default' ]
# include:
# - api: 31
# - os: macOS-latest
# abi: x86_64
# tag: 'google_apis'
# - api: 30
# abi: x86_64
# tag: 'google_apis'
# api: 28
# tag: 'default'
steps:
- uses: actions/checkout@v3
- name: set up JDK 11
- name: set up JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 11
java-version: 17
- name: Install Android SDK
uses: hannesa2/action-android/[email protected]
- name: Run tests
run: ./gradlew test
- name: Install Android SDK
uses: malinskiy/action-android/install-sdk@release/0.1.4
- name: Android Emulator test
uses: malinskiy/action-android/emulator-run-cmd@release/0.1.4
uses: hannesa2/action-android/[email protected].10
with:
cmd: ./gradlew cAT --continue
api: ${{ matrix.api }}
Expand Down Expand Up @@ -68,8 +67,13 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: set up JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 17
- name: Install Android SDK
uses: malinskiy/action-android/install-sdk@release/0.1.4
uses: hannesa2/action-android/[email protected].10
- name: Kotlin code checks
run: ./gradlew ktlintCheck
- name: Code checks
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ jobs:
fi
echo "PRE_RELEASE=$prerelease" >> $GITHUB_ENV
echo "prerelease=$prerelease"
- name: Install JDK 11
- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: 11
java-version: 17
- name: Install Android SDK
uses: malinskiy/action-android/install-sdk@release/0.1.4
uses: hannesa2/action-android/[email protected].10
- name: Build project
run: ./gradlew assembleRelease
env:
Expand Down
15 changes: 11 additions & 4 deletions basicSample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId "info.mqtt.java.example"
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode getGitCommitCount()
versionName getTag()

Expand All @@ -20,18 +20,25 @@ android {
buildFeatures {
viewBinding true
}
namespace 'info.mqtt.java.example'

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
namespace 'info.mqtt.java.example'
}

dependencies {
implementation project(':serviceLibrary')
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation "com.github.AppDevNext.Logcat:LogcatCoreLib:$logcatVersion"

implementation "androidx.core:core-ktx:1.10.0"
implementation "androidx.core:core-ktx:1.10.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

testImplementation 'junit:junit:4.13.2'
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.gradle.internal.jvm.Jvm

buildscript {
ext.kotlin_version = '1.8.20'
ext.kotlin_version = '1.8.22'
repositories {
mavenCentral()
google()
Expand All @@ -11,14 +11,14 @@ buildscript {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:11.1.0"
classpath "org.jlleitschuh.gradle:ktlint-gradle:11.5.0"
}
}

println "Gradle uses Java ${Jvm.current()}"

ext {
compileSdkVersion = 33
compileSdkVersion = 34
room_version = "2.5.1"
logcatVersion = "2.12"
}
Expand Down
15 changes: 11 additions & 4 deletions extendedSample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
defaultConfig {
applicationId 'info.mqtt.android.extsample'
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34
versionCode getGitCommitCount()
versionName getTag()

Expand All @@ -24,17 +24,24 @@ android {
buildFeatures {
viewBinding true
}
namespace 'info.mqtt.android.extsample'

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
namespace 'info.mqtt.android.extsample'
}

dependencies {
implementation project(':serviceLibrary')

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation "androidx.core:core-ktx:1.10.0"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
implementation "androidx.core:core-ktx:1.10.1"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "com.github.AppDevNext.Logcat:LogcatCoreUI:$logcatVersion"
implementation "androidx.room:room-runtime:$room_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ internal object Notify {
}

fun notification(context: Context, messageString: String, intent: Intent?, notificationTitle: Int) {

//Get the notification manage which we will use to display the notification
val ns = Context.NOTIFICATION_SERVICE
val notificationManager = context.getSystemService(ns) as NotificationManager
Expand Down
2 changes: 1 addition & 1 deletion jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jdk:
- openjdk11
- openjdk17
install:
- ./gradlew :serviceLibrary:build :serviceLibrary:publishToMavenLocal -x :serviceLibrary:test
- find . -name "*.aar"
14 changes: 11 additions & 3 deletions serviceLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {

defaultConfig {
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 34

// Android Studio 4.1 doesn't generate versionName in libraries any more
// https://developer.android.com/studio/releases/gradle-plugin#version_properties_removed_from_buildconfig_class_in_library_projects
Expand All @@ -35,15 +35,23 @@ android {
}
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
}
namespace 'info.mqtt.android.service'
testNamespace 'info.mqtt.android.service.test'
}

dependencies {
api "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.core:core-ktx:1.10.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "androidx.core:core-ktx:1.10.1"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "com.github.AppDevNext.Logcat:LogcatCoreLib:$logcatVersion"

Expand Down
4 changes: 3 additions & 1 deletion serviceLibrary/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

<application>
<!-- Mqtt Service -->
<service android:name="info.mqtt.android.service.MqttService" />
<service
android:name="info.mqtt.android.service.MqttService"
android:foregroundServiceType="dataSync" />

</application>

Expand Down
6 changes: 5 additions & 1 deletion serviceLibrary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<application>

<service android:name="info.mqtt.android.service.MqttService" />
<service
android:name="info.mqtt.android.service.MqttService"
android:foregroundServiceType="dataSync" />

</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ class MqttAndroidClient @JvmOverloads constructor(
private fun registerReceiver(receiver: BroadcastReceiver) {
val filter = IntentFilter()
filter.addAction(MqttServiceConstants.CALLBACK_TO_ACTIVITY)
context.registerReceiver(receiver, filter)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
context.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED)
else
context.registerReceiver(receiver, filter)
receiverRegistered = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ internal class MqttConnection(
}
} else {
alarmPingSender = AlarmPingSender(service)
setConnectingState(true)
myClient = MqttAsyncClient(serverURI, clientId, persistence, alarmPingSender)
//, null, new AndroidHighResolutionTimer());
myClient!!.setCallback(this)
service.traceDebug("Do Real connect!")
setConnectingState(true)
myClient!!.connect(connectOptions, invocationContext, listener)
}
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.os.PowerManager
import androidx.core.content.ContextCompat
import info.mqtt.android.service.room.MqMessageDatabase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -554,7 +555,10 @@ class MqttService : Service(), MqttTraceHandler {
private fun registerBroadcastReceivers() {
if (networkConnectionMonitor == null) {
networkConnectionMonitor = NetworkConnectionIntentReceiver()
registerReceiver(networkConnectionMonitor, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
ContextCompat.registerReceiver(
this, networkConnectionMonitor, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION),
ContextCompat.RECEIVER_NOT_EXPORTED
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.content.IntentFilter
import android.os.Build
import android.os.PowerManager
import android.os.SystemClock
import androidx.core.content.ContextCompat
import info.mqtt.android.service.MqttService
import info.mqtt.android.service.MqttServiceConstants
import kotlinx.coroutines.*
Expand Down Expand Up @@ -52,7 +53,7 @@ internal class AlarmPingSender(val service: MqttService) : MqttPingSender {
override fun start() {
val action = MqttServiceConstants.PING_SENDER + clientComms!!.client.clientId
Timber.d("Register AlarmReceiver to MqttService$action")
service.registerReceiver(alarmReceiver, IntentFilter(action))
ContextCompat.registerReceiver(service, alarmReceiver, IntentFilter(action), ContextCompat.RECEIVER_NOT_EXPORTED)
pendingIntent = PendingIntent.getBroadcast(service, 0, Intent(action), pendingIntentFlags)
schedule(clientComms!!.keepAlive)
hasStarted = true
Expand All @@ -61,10 +62,10 @@ internal class AlarmPingSender(val service: MqttService) : MqttPingSender {
override fun stop() {
Timber.d("Unregister AlarmReceiver to MqttService ${clientComms!!.client.clientId}")
if (hasStarted) {
if (pendingIntent != null) {
pendingIntent?.let {
// Cancel Alarm.
val alarmManager = service.getSystemService(Service.ALARM_SERVICE) as AlarmManager
alarmManager.cancel(pendingIntent)
alarmManager.cancel(it)
}
hasStarted = false
try {
Expand All @@ -79,14 +80,16 @@ internal class AlarmPingSender(val service: MqttService) : MqttPingSender {
val nextAlarmInMilliseconds = SystemClock.elapsedRealtime() + delayInMilliseconds
Timber.d("Schedule next alarm at $nextAlarmInMilliseconds ms")
val alarmManager = service.getSystemService(Service.ALARM_SERVICE) as AlarmManager
if (Build.VERSION.SDK_INT >= 23) {
// In SDK 23 and above, dosing will prevent setExact, setExactAndAllowWhileIdle will force
// the device to run this task whilst dosing.
Timber.d("Alarm schedule using setExactAndAllowWhileIdle, next: $delayInMilliseconds")
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextAlarmInMilliseconds, pendingIntent)
} else
Timber.d("Alarm schedule using setExact, delay: $delayInMilliseconds")
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextAlarmInMilliseconds, pendingIntent)
pendingIntent?.let {
if (Build.VERSION.SDK_INT >= 23) {
// In SDK 23 and above, dosing will prevent setExact, setExactAndAllowWhileIdle will force
// the device to run this task whilst dosing.
Timber.d("Alarm schedule using setExactAndAllowWhileIdle, next: $delayInMilliseconds")
alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextAlarmInMilliseconds, it)
} else
Timber.d("Alarm schedule using setExact, delay: $delayInMilliseconds")
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextAlarmInMilliseconds, it)
}
}

fun backgroundExecute(comms: ClientComms?): Boolean {
Expand Down

0 comments on commit a80aaef

Please sign in to comment.