@@ -20,15 +20,15 @@ import android.annotation.SuppressLint
2020import android.app.Notification
2121import android.app.NotificationManager
2222import android.app.PendingIntent
23+ import android.app.PendingIntent.FLAG_IMMUTABLE
24+ import android.app.PendingIntent.FLAG_UPDATE_CURRENT
2325import android.app.RemoteInput
2426import android.content.BroadcastReceiver
2527import android.content.Context
2628import android.content.Intent
2729import android.content.IntentFilter
2830import android.net.Uri
2931import android.os.Build.VERSION.SDK_INT
30- import android.os.Build.VERSION_CODES.N
31- import android.os.Build.VERSION_CODES.O
3232import android.os.Build.VERSION_CODES.P
3333import android.os.Bundle
3434import android.os.Process
@@ -125,7 +125,7 @@ internal class MessagingBuilder(private val mContext: Context, private val mCont
125125 if (onRead != null ) mMarkReadPendingIntents[sbn.key] = onRead // Mapped by evolved key,
126126 val messages = buildMessages(conversation)
127127 val remoteInput = ext.remoteInput
128- if (SDK_INT >= N && onReply != null && remoteInput != null && conversation.isChat()) {
128+ if (onReply != null && remoteInput != null && conversation.isChat()) {
129129 val inputHistory = n.extras.getCharSequenceArray(Notification .EXTRA_REMOTE_INPUT_HISTORY )
130130 val proxy = proxyDirectReply(conversation.nid, sbn, onReply, remoteInput, inputHistory)
131131 val replyRemoteInput = RemoteInput .Builder (remoteInput.resultKey).addExtras(remoteInput.extras)
@@ -154,9 +154,9 @@ internal class MessagingBuilder(private val mContext: Context, private val mCont
154154 .putExtra(EXTRA_REPLY_ACTION , onReply).putExtra(EXTRA_RESULT_KEY , remoteInput.resultKey)
155155 .putExtra(EXTRA_ORIGINAL_KEY , sbn.originalKey).putExtra(EXTRA_CONVERSATION_ID , cid)
156156 .putExtra(Intent .EXTRA_USER , sbn.user)
157- if (SDK_INT >= N && inputHistory != null )
157+ if (inputHistory != null )
158158 proxy.putCharSequenceArrayListExtra(Notification .EXTRA_REMOTE_INPUT_HISTORY , arrayListOf (* inputHistory))
159- return PendingIntent .getBroadcast(mContext, 0 , proxy.setPackage(mContext.packageName), PendingIntent . FLAG_UPDATE_CURRENT )
159+ return PendingIntent .getBroadcast(mContext, 0 , proxy.setPackage(mContext.packageName), FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE )
160160 }
161161
162162 private val mReplyReceiver: BroadcastReceiver = object : BroadcastReceiver () { override fun onReceive (context : Context , proxy : Intent ) {
@@ -182,22 +182,20 @@ internal class MessagingBuilder(private val mContext: Context, private val mCont
182182 RemoteInput .addResultsToIntent(arrayOf(RemoteInput .Builder (resultKey).build()), proxy, results)
183183 } ? : input
184184
185- val history = if ( SDK_INT >= N ) proxy.getCharSequenceArrayListExtra(Notification .EXTRA_REMOTE_INPUT_HISTORY ) else null
185+ val history = proxy.getCharSequenceArrayListExtra(Notification .EXTRA_REMOTE_INPUT_HISTORY )
186186 try {
187187 val inputData = addTargetPackageAndWakeUp(replyAction)
188188 inputData.clipData = proxy.clipData
189189 replyAction.send(mContext, 0 , inputData, PendingIntent .OnFinished { pendingIntent: PendingIntent , intent: Intent , _: Int , _: String? , _: Bundle ? ->
190190 if (BuildConfig .DEBUG ) Log .d(TAG , " Reply sent: " + intent.toUri(0 ))
191- if (SDK_INT >= N ) {
192- val addition = Bundle ()
193- val inputs: Array <CharSequence >
194- val toCurrentUser = Process .myUserHandle() == pendingIntent.creatorUserHandle
195- inputs = if (toCurrentUser && context.packageManager.queryBroadcastReceivers(intent, 0 ).isEmpty())
196- arrayOf(context.getString(R .string.wechat_with_no_reply_receiver))
197- else history?.apply { add(0 , text) }?.toTypedArray() ? : arrayOf(text)
198- addition.putCharSequenceArray(Notification .EXTRA_REMOTE_INPUT_HISTORY , inputs)
199- mController.recastNotification(originalKey ? : key, addition)
200- }
191+ val addition = Bundle ()
192+ val inputs: Array <CharSequence >
193+ val toCurrentUser = Process .myUserHandle() == pendingIntent.creatorUserHandle
194+ inputs = if (toCurrentUser && context.packageManager.queryBroadcastReceivers(intent, 0 ).isEmpty())
195+ arrayOf(context.getString(R .string.wechat_with_no_reply_receiver))
196+ else history?.apply { add(0 , text) }?.toTypedArray() ? : arrayOf(text)
197+ addition.putCharSequenceArray(Notification .EXTRA_REMOTE_INPUT_HISTORY , inputs)
198+ mController.recastNotification(originalKey ? : key, addition)
201199 markRead(key)
202200 }, null )
203201 } catch (e: PendingIntent .CanceledException ) {
@@ -251,10 +249,9 @@ internal class MessagingBuilder(private val mContext: Context, private val mCont
251249 val bigText = StringBuilder ().append(convs.summary).append(" \n T:" ).append(convs.ticker)
252250 val messages = if (convs.ext != null ) convs.ext!! .messages else null
253251 if (messages != null ) for (msg in messages) bigText.append(" \n " ).append(msg)
254- val n = Notification .Builder (context).setSmallIcon(android.R .drawable.stat_sys_warning)
252+ val n = Notification .Builder (context, " Debug " ).setSmallIcon(android.R .drawable.stat_sys_warning)
255253 .setContentTitle(convs.id).setContentText(convs.ticker).setSubText(summary).setShowWhen(true )
256254 .setStyle(Notification .BigTextStyle ().setBigContentTitle(convs.title).bigText(bigText.toString()))
257- if (SDK_INT >= O ) n.setChannelId(" Debug" )
258255 context.getSystemService(NotificationManager ::class .java)
259256 .notify(if (convs.id != null ) convs.id.hashCode() else convs.title.hashCode(), n.build())
260257 }
@@ -319,10 +316,8 @@ internal class MessagingBuilder(private val mContext: Context, private val mCont
319316
320317 fun flatIntoExtras (messaging : NotificationCompat .MessagingStyle , extras : Bundle ) {
321318 val user = messaging.user
322- if (user != null ) {
323- extras.putCharSequence(NotificationCompat .EXTRA_SELF_DISPLAY_NAME , user.name)
324- if (SDK_INT >= P ) extras.putParcelable(Notification .EXTRA_MESSAGING_PERSON , user.toNative()) // Not included in NotificationCompat
325- }
319+ extras.putCharSequence(NotificationCompat .EXTRA_SELF_DISPLAY_NAME , user.name)
320+ if (SDK_INT >= P ) extras.putParcelable(Notification .EXTRA_MESSAGING_PERSON , user.toNative()) // Not included in NotificationCompat
326321 if (messaging.conversationTitle != null )
327322 extras.putCharSequence(NotificationCompat .EXTRA_CONVERSATION_TITLE , messaging.conversationTitle)
328323 val messages = messaging.messages
@@ -344,7 +339,7 @@ internal class MessagingBuilder(private val mContext: Context, private val mCont
344339 }
345340 if (message.dataMimeType != null ) putString(KEY_DATA_MIME_TYPE , message.dataMimeType)
346341 if (message.dataUri != null ) putParcelable(KEY_DATA_URI , message.dataUri)
347- if (SDK_INT >= O && ! message.extras.isEmpty) putBundle(KEY_EXTRAS_BUNDLE , message.extras)
342+ if (! message.extras.isEmpty) putBundle(KEY_EXTRAS_BUNDLE , message.extras)
348343 // if (message.isRemoteInputHistory()) putBoolean(KEY_REMOTE_INPUT_HISTORY, message.isRemoteInputHistory());
349344 }
350345
0 commit comments