rns-nativecall 0.7.5 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,16 +6,15 @@ import android.app.PendingIntent
|
|
|
6
6
|
import android.content.Context
|
|
7
7
|
import android.content.Intent
|
|
8
8
|
import android.os.Build
|
|
9
|
+
import androidx.core.app.NotificationCompat
|
|
9
10
|
import android.media.Ringtone
|
|
10
11
|
import android.media.RingtoneManager
|
|
11
12
|
import android.graphics.Color
|
|
12
13
|
|
|
13
14
|
import androidx.core.app.Person
|
|
14
|
-
import androidx.core.app.NotificationCompat
|
|
15
15
|
|
|
16
16
|
import android.app.KeyguardManager
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
object NativeCallManager {
|
|
20
19
|
|
|
21
20
|
private var ringtone: Ringtone? = null
|
|
@@ -27,16 +26,22 @@ object NativeCallManager {
|
|
|
27
26
|
|
|
28
27
|
val name = data["name"] ?: "Incoming Call"
|
|
29
28
|
val callType = data["callType"] ?: "audio"
|
|
30
|
-
// --- LOCK SCREEN GATEKEEPER ---
|
|
31
|
-
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
|
32
|
-
if (keyguardManager.isKeyguardLocked) {
|
|
33
|
-
// Device is locked? We bounce it!
|
|
34
|
-
CallState.markCanceled(uuid, context) // Save to disk so Headless/Splash sees it's invalid
|
|
35
|
-
showMissedCallNotification(context, data, uuid)
|
|
36
|
-
return // Kill the flow here
|
|
37
|
-
}
|
|
38
29
|
val notificationId = uuid.hashCode()
|
|
39
30
|
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// --- LOCK SCREEN GATEKEEPER ---
|
|
35
|
+
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
|
36
|
+
if (keyguardManager.isKeyguardLocked) {
|
|
37
|
+
// Device is locked? We bounce it!
|
|
38
|
+
CallState.markCanceled(uuid, context)
|
|
39
|
+
showMissedCallNotification(context, data, uuid)
|
|
40
|
+
return // 🛑 Flow stops here
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
40
45
|
val pendingFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
41
46
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
|
42
47
|
} else {
|
|
@@ -122,107 +127,14 @@ object NativeCallManager {
|
|
|
122
127
|
}
|
|
123
128
|
}
|
|
124
129
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
// val pendingFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
134
|
-
// PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
|
|
135
|
-
// } else {
|
|
136
|
-
// PendingIntent.FLAG_UPDATE_CURRENT
|
|
137
|
-
// }
|
|
138
|
-
|
|
139
|
-
// // 1. Setup the Intents
|
|
140
|
-
// val intentToActivity = Intent(context, AcceptCallActivity::class.java).apply {
|
|
141
|
-
// this.action = "ACTION_ANSWER_$uuid"
|
|
142
|
-
// data.forEach { (key, value) -> this.putExtra(key, value) }
|
|
143
|
-
// this.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
|
144
|
-
// }
|
|
145
|
-
|
|
146
|
-
// val fullScreenPendingIntent = PendingIntent.getActivity(
|
|
147
|
-
// context, notificationId, intentToActivity, pendingFlags
|
|
148
|
-
// )
|
|
149
|
-
|
|
150
|
-
// val rejectIntent = Intent(context, CallActionReceiver::class.java).apply {
|
|
151
|
-
// this.action = "ACTION_REJECT_$uuid"
|
|
152
|
-
// this.putExtra("EXTRA_CALL_UUID", uuid)
|
|
153
|
-
// data.forEach { (key, value) -> this.putExtra(key, value) }
|
|
154
|
-
// }
|
|
155
|
-
|
|
156
|
-
// // Fix: Define the missing rejectPendingIntent
|
|
157
|
-
// val rejectPendingIntent = PendingIntent.getBroadcast(
|
|
158
|
-
// context, notificationId, rejectIntent, pendingFlags
|
|
159
|
-
// )
|
|
160
|
-
|
|
161
|
-
// // 2. Create the Person object for CallStyle
|
|
162
|
-
// val caller = Person.Builder()
|
|
163
|
-
// .setName(name)
|
|
164
|
-
// .setImportant(true)
|
|
165
|
-
// .build()
|
|
166
|
-
|
|
167
|
-
// val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
168
|
-
|
|
169
|
-
// // 3. Setup Channel
|
|
170
|
-
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
171
|
-
// val channel = NotificationChannel(
|
|
172
|
-
// channelId,
|
|
173
|
-
// "Incoming Calls",
|
|
174
|
-
// NotificationManager.IMPORTANCE_HIGH
|
|
175
|
-
// ).apply {
|
|
176
|
-
// enableVibration(true)
|
|
177
|
-
// vibrationPattern = longArrayOf(0, 500, 500, 500)
|
|
178
|
-
// lightColor = Color.GREEN
|
|
179
|
-
// setBypassDnd(true)
|
|
180
|
-
// setSound(null, null)
|
|
181
|
-
// }
|
|
182
|
-
// notificationManager.createNotificationChannel(channel)
|
|
183
|
-
// }
|
|
184
|
-
|
|
185
|
-
// // 4. Build with CallStyle
|
|
186
|
-
// val builder = NotificationCompat.Builder(context, channelId)
|
|
187
|
-
// .setSmallIcon(context.applicationInfo.icon)
|
|
188
|
-
// .setPriority(NotificationCompat.PRIORITY_MAX)
|
|
189
|
-
// .setCategory(NotificationCompat.CATEGORY_CALL)
|
|
190
|
-
// .setOngoing(true)
|
|
191
|
-
// .setAutoCancel(false)
|
|
192
|
-
// .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
193
|
-
// .setFullScreenIntent(fullScreenPendingIntent, true)
|
|
194
|
-
// .setStyle(
|
|
195
|
-
// NotificationCompat.CallStyle.forIncomingCall(
|
|
196
|
-
// caller,
|
|
197
|
-
// rejectPendingIntent,
|
|
198
|
-
// fullScreenPendingIntent
|
|
199
|
-
// )
|
|
200
|
-
// )
|
|
201
|
-
|
|
202
|
-
// notificationManager.notify(notificationId, builder.build())
|
|
203
|
-
|
|
204
|
-
// // 5. Start Ringtone
|
|
205
|
-
// try {
|
|
206
|
-
// val ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)
|
|
207
|
-
// ringtone = RingtoneManager.getRingtone(context, ringtoneUri)
|
|
208
|
-
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
209
|
-
// ringtone?.isLooping = true
|
|
210
|
-
// }
|
|
211
|
-
// ringtone?.play()
|
|
212
|
-
// } catch (e: Exception) {
|
|
213
|
-
// e.printStackTrace()
|
|
214
|
-
// }
|
|
215
|
-
// }
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// fun stopRingtone() {
|
|
219
|
-
// try {
|
|
220
|
-
// ringtone?.let { if (it.isPlaying) it.stop() }
|
|
221
|
-
// ringtone = null
|
|
222
|
-
// } catch (e: Exception) {
|
|
223
|
-
// ringtone = null
|
|
224
|
-
// }
|
|
225
|
-
// }
|
|
130
|
+
fun stopRingtone() {
|
|
131
|
+
try {
|
|
132
|
+
ringtone?.let { if (it.isPlaying) it.stop() }
|
|
133
|
+
ringtone = null
|
|
134
|
+
} catch (e: Exception) {
|
|
135
|
+
ringtone = null
|
|
136
|
+
}
|
|
137
|
+
}
|
|
226
138
|
|
|
227
139
|
fun connecting(context: Context, uuid: String, name: String, callType: String) {
|
|
228
140
|
val notificationId = uuid.hashCode()
|
|
@@ -262,6 +174,7 @@ fun aborting(context: Context, uuid: String, name: String, callType: String) {
|
|
|
262
174
|
notificationManager.notify(notificationId, builder.build())
|
|
263
175
|
}
|
|
264
176
|
|
|
177
|
+
|
|
265
178
|
fun dismissIncomingCall(context: Context, uuid: String?) {
|
|
266
179
|
stopRingtone()
|
|
267
180
|
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|