Skip to content

Commit

Permalink
Update to LTS plugin version, rewrite FullScreenActivity to kotlin, f…
Browse files Browse the repository at this point in the history
…ixes for Android API 31 (#2)

* feat: Add full screen notification, fix target API version 31:on 31:

commit 72ee17b
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Tue Aug 16 14:58:03 2022 +0200

    restore selecting flag for os version

commit fe398f6
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Tue Aug 16 14:01:25 2022 +0200

    Update flag check for API 31

commit cefe7c0
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Tue Aug 16 12:28:35 2022 +0200

    fix flags

commit 61c19fa
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Tue Aug 16 12:15:16 2022 +0200

    fix pending intent flag

commit 1aff7e7
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Tue Aug 16 08:32:02 2022 +0200

    fix variable

commit d85abfa
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Tue Aug 16 08:24:11 2022 +0200

    fix typing

commit 279242d
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Tue Aug 16 08:06:35 2022 +0200

    fix compile issues

commit 9a0e9c3
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 17:00:28 2022 +0200

    fix parse int

commit 3aafe54
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 16:24:37 2022 +0200

    fix translation to kotlin

commit 6650697
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 16:06:32 2022 +0200

    fix fetch push constant

commit f4da44c
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 15:36:58 2022 +0200

    fix full screen activity path

commit 16aa608
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 15:35:25 2022 +0200

    fix fcmservice path

commit 1119044
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 15:24:05 2022 +0200

    fix source order

commit a53c4b4
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 15:09:53 2022 +0200

    chore: update to kotlin file version

commit 7c643f2
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 15:09:52 2022 +0200

    Rename .java to .kt

commit 6066326
Merge: a9939fa aa23f4b
Author: p.mikolajczak@tkhtechnology.com <p.mikolajczak@tkhtechnology.com>
Date:   Fri Aug 12 14:29:06 2022 +0200

    Merge branch 'MX002-5965' of https://github.com/mjcctech/cordova-plugin-push into MX002-6941

commit aa23f4b
Author: mjaruzel <m.jaruzel@cctechnology.pl>
Date:   Fri Oct 1 11:58:15 2021 +0200

    add missing import

commit 0d2a82b
Author: mjaruzel <m.jaruzel@cctechnology.pl>
Date:   Fri Oct 1 11:27:48 2021 +0200

    fix whitespace

commit 4bc2cb9
Author: mjaruzel <m.jaruzel@cctechnology.pl>
Date:   Fri Oct 1 11:13:53 2021 +0200

    rollback whitespace changes

commit 6cae4a1
Author: mjaruzel <m.jaruzel@cctechnology.pl>
Date:   Fri Oct 1 10:55:31 2021 +0200

    rollback whitespace changes

commit 6bc5655
Author: mjaruzel <m.jaruzel@cctechnology.pl>
Date:   Fri Oct 1 10:23:01 2021 +0200

    Add full screen activity

* remove unused variable, logging

* fix typo
  • Loading branch information
pmtkh authored Aug 16, 2022
1 parent 6bca515 commit 67ac1c0
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 14 deletions.
5 changes: 4 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="${applicationId}.permission.PushHandlerActivity"/>
<permission android:name="${applicationId}.permission.PushHandlerActivity" android:protectionLevel="signature"></permission>
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
</config-file>

<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.adobe.phonegap.push.FullScreenActivity" android:showOnLockScreen="true" android:turnScreenOn="true" android:theme="@android:style/Theme.DeviceDefault.NoActionBar"/>
<activity android:name="com.adobe.phonegap.push.PushHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.PushHandlerActivity"/>
<activity android:name="com.adobe.phonegap.push.BackgroundHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.BackgroundHandlerActivity">
<intent-filter>
Expand Down Expand Up @@ -77,8 +79,9 @@
<framework src="me.leolin:ShortcutBadger:1.1.22@aar"/>
<framework src="com.google.firebase:firebase-messaging:$FCM_VERSION"/>

<source-file src="src/android/com/adobe/phonegap/push/FCMService.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushConstants.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/FullScreenActivity.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/FCMService.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushHandlerActivity.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/BackgroundHandlerActivity.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushInstanceIDListenerService.kt" target-dir="java/com/adobe/phonegap/push/"/>
Expand Down
40 changes: 27 additions & 13 deletions src/android/com/adobe/phonegap/push/FCMService.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.adobe.phonegap.push

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
Expand Down Expand Up @@ -436,19 +437,22 @@ class FCMService : FirebaseMessagingService() {
private fun createNotification(extras: Bundle?) {
val mNotificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val appName = getAppName(this)
val fullScreenIntent: Boolean = extras?.getString(PushConstants.FULL_SCREEN_NOTIFICATION, "").equals("1")
Log.d(TAG, "fullScreenIntent = $fullScreenIntent")
val notId = parseNotificationIdToInt(extras)
val notificationIntent = Intent(this, PushHandlerActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(PushConstants.PUSH_BUNDLE, extras)
putExtra(PushConstants.NOT_ID, notId)
}
val activityClass: Class<out Activity?> =
if (fullScreenIntent) FullScreenActivity::class.java else PushHandlerActivity::class.java
val notificationIntent = Intent(this, activityClass)
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP)
notificationIntent.putExtra(PushConstants.PUSH_BUNDLE, extras)
notificationIntent.putExtra(PushConstants.NOT_ID, notId)
val random = SecureRandom()
var requestCode = random.nextInt()
val contentIntent = PendingIntent.getActivity(
this,
requestCode,
notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)
val dismissedNotificationIntent = Intent(
this,
Expand All @@ -467,7 +471,7 @@ class FCMService : FirebaseMessagingService() {
this,
requestCode,
dismissedNotificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE
)

val mBuilder: NotificationCompat.Builder =
Expand All @@ -479,7 +483,17 @@ class FCMService : FirebaseMessagingService() {
.setContentIntent(contentIntent)
.setDeleteIntent(deleteIntent)
.setAutoCancel(true)

if (fullScreenIntent) {
mBuilder
.setFullScreenIntent(contentIntent, true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
} else {
mBuilder.setContentIntent(contentIntent)
}
val prefs: SharedPreferences = context.getSharedPreferences(
PushConstants.COM_ADOBE_PHONEGAP_PUSH,
Context.MODE_PRIVATE
)
val localIcon = pushSharedPref.getString(PushConstants.ICON, null)
val localIconColor = pushSharedPref.getString(PushConstants.ICON_COLOR, null)
val soundOption = pushSharedPref.getBoolean(PushConstants.SOUND, true)
Expand Down Expand Up @@ -654,7 +668,6 @@ class FCMService : FirebaseMessagingService() {
var intent: Intent?
var pIntent: PendingIntent?
val callback = action.getString(PushConstants.CALLBACK)

when {
inline -> {
Log.d(TAG, "Version: ${Build.VERSION.SDK_INT} = ${Build.VERSION_CODES.M}")
Expand All @@ -672,11 +685,12 @@ class FCMService : FirebaseMessagingService() {
pIntent = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
Log.d(TAG, "push activity for notId $notId")


PendingIntent.getActivity(
this,
uniquePendingIntentRequestCode,
intent,
PendingIntent.FLAG_ONE_SHOT
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE
)
} else {
Log.d(TAG, "push receiver for notId $notId")
Expand All @@ -685,7 +699,7 @@ class FCMService : FirebaseMessagingService() {
this,
uniquePendingIntentRequestCode,
intent,
PendingIntent.FLAG_ONE_SHOT
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_MUTABLE
)
}
}
Expand All @@ -696,7 +710,7 @@ class FCMService : FirebaseMessagingService() {
pIntent = PendingIntent.getActivity(
this, uniquePendingIntentRequestCode,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)
}

Expand All @@ -706,7 +720,7 @@ class FCMService : FirebaseMessagingService() {
pIntent = PendingIntent.getBroadcast(
this, uniquePendingIntentRequestCode,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
)
}
}
Expand Down
85 changes: 85 additions & 0 deletions src/android/com/adobe/phonegap/push/FullScreenActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.adobe.phonegap.push

import android.app.Activity
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.WindowManager

class FullScreenActivity : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
Log.d(LOG_TAG, "onCreate")
super.onCreate(savedInstanceState)
turnScreenOnAndKeyguardOff()
forceMainActivityReload()
finish()
}

private fun forceMainActivityReload() {
val pm: PackageManager = getPackageManager()
val launchIntent: Intent? =
pm.getLaunchIntentForPackage(getApplicationContext().getPackageName())
launchIntent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
launchIntent?.addFlags(Intent.FLAG_FROM_BACKGROUND)
startActivity(launchIntent)
}

protected override fun onDestroy() {
super.onDestroy()
Log.d(LOG_TAG, "onDestroy")
turnScreenOffAndKeyguardOn()
}

private fun turnScreenOnAndKeyguardOff() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
Log.d(LOG_TAG, "setShowWhenLocked")
setShowWhenLocked(true)
setTurnScreenOn(true)
} else {
Log.d(LOG_TAG, "addFlags")
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
)
}
val keyguardManager: KeyguardManager? = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && keyguardManager != null) {
keyguardManager?.requestDismissKeyguard(this, object : KeyguardManager.KeyguardDismissCallback() {
override fun onDismissCancelled() {
super.onDismissCancelled()
Log.d(LOG_TAG, "canceled")
}

override fun onDismissError() {
super.onDismissError()
Log.d(LOG_TAG, "onDismissError")
}

override fun onDismissSucceeded() {
super.onDismissSucceeded()
Log.d(LOG_TAG, "onDismissSucceeded")
}
})
}
}

private fun turnScreenOffAndKeyguardOn() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(false)
setTurnScreenOn(false)
} else {
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
or WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
)
}
}

companion object {
private const val LOG_TAG = "FullScreenActivity"
}
}
1 change: 1 addition & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ object PushConstants {
const val CLEAR_NOTIFICATION: String = "clearNotification"
const val MESSAGE_ID: String = "google.message_id"
const val IS_ENABLED: String = "isEnabled"
const val FULL_SCREEN_NOTIFICATION: String = "full-screen-notification"
}

0 comments on commit 67ac1c0

Please sign in to comment.