From 74bd28cbd9fff4e294b7ede63f09d946084ac804 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 9 Apr 2023 18:45:57 +0530 Subject: [PATCH 1/3] Update AndroidX Core to 1.10.0. --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index a2617aa58..5e3e5cbcb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -205,7 +205,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'androidx.core:core-ktx:1.8.0' + implementation 'androidx.core:core-ktx:1.10.0' implementation 'androidx.documentfile:documentfile:1.0.1' implementation 'androidx.fragment:fragment-ktx:1.4.1' implementation "androidx.lifecycle:lifecycle-livedata-ktx:${androidxLifecycleVersion}" From acebabd02817a9f8bd6e1d22e36c29e56fbe92d8 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 9 Apr 2023 18:46:15 +0530 Subject: [PATCH 2/3] Use AndroidX's PendingIntentCompat class. --- .../org/schabi/newpipe/NewVersionWorker.kt | 4 +- .../org/schabi/newpipe/error/ErrorUtil.kt | 5 +- .../feed/notifications/NotificationHelper.kt | 5 +- .../local/feed/service/FeedLoadService.kt | 6 +- .../player/notification/NotificationUtil.java | 8 +-- .../newpipe/util/PendingIntentCompat.java | 69 ------------------- .../giga/service/DownloadManagerService.java | 6 +- 7 files changed, 18 insertions(+), 85 deletions(-) delete mode 100644 app/src/main/java/org/schabi/newpipe/util/PendingIntentCompat.java diff --git a/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt b/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt index dac831fe4..c46dd6348 100644 --- a/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt +++ b/app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt @@ -6,6 +6,7 @@ import android.util.Log import android.widget.Toast import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.app.PendingIntentCompat import androidx.core.content.ContextCompat import androidx.core.content.edit import androidx.core.net.toUri @@ -19,7 +20,6 @@ import com.grack.nanojson.JsonParser import com.grack.nanojson.JsonParserException import org.schabi.newpipe.extractor.downloader.Response import org.schabi.newpipe.extractor.exceptions.ReCaptchaException -import org.schabi.newpipe.util.PendingIntentCompat import org.schabi.newpipe.util.ReleaseVersionUtil.coerceUpdateCheckExpiry import org.schabi.newpipe.util.ReleaseVersionUtil.isLastUpdateCheckExpired import org.schabi.newpipe.util.ReleaseVersionUtil.isReleaseApk @@ -60,7 +60,7 @@ class NewVersionWorker( val intent = Intent(Intent.ACTION_VIEW, apkLocationUrl?.toUri()) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) val pendingIntent = PendingIntentCompat.getActivity( - applicationContext, 0, intent, 0 + applicationContext, 0, intent, 0, false ) val channelId = applicationContext.getString(R.string.app_update_notification_channel_id) val notificationBuilder = NotificationCompat.Builder(applicationContext, channelId) diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt index c7b9beeed..daa598509 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt @@ -9,10 +9,10 @@ import android.view.View import android.widget.Toast import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.app.PendingIntentCompat import androidx.fragment.app.Fragment import com.google.android.material.snackbar.Snackbar import org.schabi.newpipe.R -import org.schabi.newpipe.util.PendingIntentCompat /** * This class contains all of the methods that should be used to let the user know that an error has @@ -118,7 +118,8 @@ class ErrorUtil { context, 0, getErrorActivityIntent(context, errorInfo), - PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_UPDATE_CURRENT, + false ) ) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt index 61a4936c8..dc863126e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt @@ -10,6 +10,7 @@ import android.os.Build import android.provider.Settings import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.app.PendingIntentCompat import androidx.core.content.ContextCompat import androidx.preference.PreferenceManager import com.squareup.picasso.Picasso @@ -19,7 +20,6 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem import org.schabi.newpipe.local.feed.service.FeedUpdateInfo import org.schabi.newpipe.util.Localization import org.schabi.newpipe.util.NavigationHelper -import org.schabi.newpipe.util.PendingIntentCompat import org.schabi.newpipe.util.PicassoHelper /** @@ -76,7 +76,8 @@ class NotificationHelper(val context: Context) { NavigationHelper .getChannelIntent(context, data.listInfo.serviceId, data.listInfo.url) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), - 0 + 0, + false ) ) diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt index 0850fef8c..ff5734feb 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt @@ -29,6 +29,7 @@ import android.os.IBinder import android.util.Log import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat +import androidx.core.app.PendingIntentCompat import androidx.core.app.ServiceCompat import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers import io.reactivex.rxjava3.core.Flowable @@ -42,7 +43,6 @@ import org.schabi.newpipe.extractor.ListInfo import org.schabi.newpipe.extractor.stream.StreamInfoItem import org.schabi.newpipe.local.feed.service.FeedEventManager.Event.ErrorResultEvent import org.schabi.newpipe.local.feed.service.FeedEventManager.postEvent -import org.schabi.newpipe.util.PendingIntentCompat import java.util.concurrent.TimeUnit class FeedLoadService : Service() { @@ -152,8 +152,8 @@ class FeedLoadService : Service() { private lateinit var notificationBuilder: NotificationCompat.Builder private fun createNotification(): NotificationCompat.Builder { - val cancelActionIntent = - PendingIntentCompat.getBroadcast(this, NOTIFICATION_ID, Intent(ACTION_CANCEL), 0) + val cancelActionIntent = PendingIntentCompat + .getBroadcast(this, NOTIFICATION_ID, Intent(ACTION_CANCEL), 0, false) return NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) .setOngoing(true) diff --git a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java index 6e50dda7d..05c2e3af6 100644 --- a/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java @@ -13,6 +13,7 @@ import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; +import androidx.core.app.PendingIntentCompat; import androidx.core.app.ServiceCompat; import androidx.core.content.ContextCompat; @@ -21,7 +22,6 @@ import org.schabi.newpipe.R; import org.schabi.newpipe.player.Player; import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi; import org.schabi.newpipe.util.NavigationHelper; -import org.schabi.newpipe.util.PendingIntentCompat; import java.util.List; import java.util.Objects; @@ -134,7 +134,7 @@ public final class NotificationUtil { .setColorized(player.getPrefs().getBoolean( player.getContext().getString(R.string.notification_colorize_key), true)) .setDeleteIntent(PendingIntentCompat.getBroadcast(player.getContext(), - NOTIFICATION_ID, new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT)); + NOTIFICATION_ID, new Intent(ACTION_CLOSE), FLAG_UPDATE_CURRENT, false)); // set the initial value for the video thumbnail, updatable with updateNotificationThumbnail setLargeIcon(builder); @@ -152,7 +152,7 @@ public final class NotificationUtil { // also update content intent, in case the user switched players notificationBuilder.setContentIntent(PendingIntentCompat.getActivity(player.getContext(), - NOTIFICATION_ID, getIntentForNotification(), FLAG_UPDATE_CURRENT)); + NOTIFICATION_ID, getIntentForNotification(), FLAG_UPDATE_CURRENT, false)); notificationBuilder.setContentTitle(player.getVideoTitle()); notificationBuilder.setContentText(player.getUploaderName()); notificationBuilder.setTicker(player.getVideoTitle()); @@ -335,7 +335,7 @@ public final class NotificationUtil { final String intentAction) { return new NotificationCompat.Action(drawable, player.getContext().getString(title), PendingIntentCompat.getBroadcast(player.getContext(), NOTIFICATION_ID, - new Intent(intentAction), FLAG_UPDATE_CURRENT)); + new Intent(intentAction), FLAG_UPDATE_CURRENT, false)); } private Intent getIntentForNotification() { diff --git a/app/src/main/java/org/schabi/newpipe/util/PendingIntentCompat.java b/app/src/main/java/org/schabi/newpipe/util/PendingIntentCompat.java deleted file mode 100644 index 6b9c36eab..000000000 --- a/app/src/main/java/org/schabi/newpipe/util/PendingIntentCompat.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.schabi.newpipe.util; - -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.os.Build; - -import androidx.annotation.NonNull; - -public final class PendingIntentCompat { - private PendingIntentCompat() { - } - - private static int addImmutableFlag(final int flags) { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - ? flags | PendingIntent.FLAG_IMMUTABLE : flags; - } - - /** - * Creates a {@link PendingIntent} to start an activity. It is immutable on API level 23 and - * greater. - * - * @param context The context in which the activity should be started. - * @param requestCode The request code - * @param intent The Intent of the activity to be launched. - * @param flags The flags for the intent. - * @return The pending intent. - * @see PendingIntent#getActivity(Context, int, Intent, int) - */ - @NonNull - public static PendingIntent getActivity(@NonNull final Context context, final int requestCode, - @NonNull final Intent intent, final int flags) { - return PendingIntent.getActivity(context, requestCode, intent, addImmutableFlag(flags)); - } - - /** - * Creates a {@link PendingIntent} to start a service. It is immutable on API level 23 and - * greater. - * - * @param context The context in which the service should be started. - * @param requestCode The request code - * @param intent The Intent of the service to be launched. - * @param flags The flags for the intent. - * @return The pending intent. - * @see PendingIntent#getService(Context, int, Intent, int) - */ - @NonNull - public static PendingIntent getService(@NonNull final Context context, final int requestCode, - @NonNull final Intent intent, final int flags) { - return PendingIntent.getService(context, requestCode, intent, addImmutableFlag(flags)); - } - - /** - * Creates a {@link PendingIntent} to perform a broadcast. It is immutable on API level 23 and - * greater. - * - * @param context The context in which the broadcast should be performed. - * @param requestCode The request code - * @param intent The Intent to be broadcast. - * @param flags The flags for the intent. - * @return The pending intent. - * @see PendingIntent#getBroadcast(Context, int, Intent, int) - */ - @NonNull - public static PendingIntent getBroadcast(@NonNull final Context context, final int requestCode, - @NonNull final Intent intent, final int flags) { - return PendingIntent.getBroadcast(context, requestCode, intent, addImmutableFlag(flags)); - } -} diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java index edc6bb6fd..009a4f4be 100755 --- a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java @@ -33,6 +33,7 @@ import androidx.annotation.StringRes; import androidx.collection.SparseArrayCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat.Builder; +import androidx.core.app.PendingIntentCompat; import androidx.core.app.ServiceCompat; import androidx.core.content.ContextCompat; import androidx.preference.PreferenceManager; @@ -43,7 +44,6 @@ import org.schabi.newpipe.player.helper.LockManager; import org.schabi.newpipe.streams.io.StoredDirectoryHelper; import org.schabi.newpipe.streams.io.StoredFileHelper; import org.schabi.newpipe.util.Localization; -import org.schabi.newpipe.util.PendingIntentCompat; import java.io.File; import java.io.IOException; @@ -146,7 +146,7 @@ public class DownloadManagerService extends Service { mOpenDownloadList = PendingIntentCompat.getActivity(this, 0, openDownloadListIntent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT, false); icLauncher = BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher); @@ -487,7 +487,7 @@ public class DownloadManagerService extends Service { private PendingIntent makePendingIntent(String action) { Intent intent = new Intent(this, DownloadManagerService.class).setAction(action); return PendingIntentCompat.getService(this, intent.hashCode(), intent, - PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent.FLAG_UPDATE_CURRENT, false); } private void manageLock(boolean acquire) { From 20f0011921d7a80787c17d39dc361778b629ef70 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 13 Apr 2023 10:44:20 +0530 Subject: [PATCH 3/3] Fix Sonar failure. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1384d0a9c..d199d60f8 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.6.21' + ext.kotlin_version = '1.8.20' repositories { google() mavenCentral()