Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}