From 274c583d04d44af7868ea0bb00eeec12f94258c5 Mon Sep 17 00:00:00 2001 From: Yuriy Liskov Date: Tue, 24 Dec 2024 01:22:38 +0200 Subject: [PATCH] atv channels: performance tweaks --- MediaServiceCore | 2 +- SharedModules | 2 +- .../app/presenters/dialogs/AppUpdatePresenter.java | 2 +- .../smartyoutubetv2/common/app/views/ViewManager.java | 6 +++--- .../smartyoutubetv2/common/misc/GDriveBackupWorker.java | 3 ++- .../liskovsoft/smartyoutubetv2/common/utils/Utils.java | 8 +++----- .../leanbackassistant/channels/UpdateChannelsWorker.java | 9 +++++++-- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/MediaServiceCore b/MediaServiceCore index bb5108684..cb6afe202 160000 --- a/MediaServiceCore +++ b/MediaServiceCore @@ -1 +1 @@ -Subproject commit bb5108684218613e947bcfc7e277f13456675269 +Subproject commit cb6afe2023c95690bba4699fca0c73e731f4a6b4 diff --git a/SharedModules b/SharedModules index b0580cefe..cf47d1328 160000 --- a/SharedModules +++ b/SharedModules @@ -1 +1 @@ -Subproject commit b0580cefe885443dac0d15983e1b11905b4a0d81 +Subproject commit cf47d132897371a4c462c8774d0bcb41b48de695 diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/dialogs/AppUpdatePresenter.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/dialogs/AppUpdatePresenter.java index aa88553ad..3c5834bec 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/dialogs/AppUpdatePresenter.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/dialogs/AppUpdatePresenter.java @@ -89,7 +89,7 @@ public class AppUpdatePresenter extends BasePresenter implements AppUpdate private void showUpdateDialog(String versionName, List changelog, String apkPath) { // Don't show update dialog if the player opened or the app is collapsed - if (getContext() == null || ViewManager.instance(getContext()).isPlayerInForeground() || !Utils.isAppInForeground()) { + if (getContext() == null || ViewManager.instance(getContext()).isPlayerInForeground() || !Utils.isAppInForegroundFixed()) { return; } diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/views/ViewManager.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/views/ViewManager.java index 52df642da..0544ab80a 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/views/ViewManager.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/views/ViewManager.java @@ -98,7 +98,7 @@ public class ViewManager { */ public void startView(Class viewClass, boolean forceStart) { // Skip starting activity twice to get rid of pausing/resuming activity cycle - if (Utils.isAppInForeground() && getTopView() != null && getTopView() == viewClass) { + if (Utils.isAppInForegroundFixed() && getTopView() != null && getTopView() == viewClass) { return; } @@ -454,11 +454,11 @@ public class ViewManager { } public boolean isPlayerInForeground() { - return Utils.isAppInForeground() && getTopView() == PlaybackView.class; + return Utils.isAppInForegroundFixed() && getTopView() == PlaybackView.class; } public void moveAppToForeground() { - if (!Utils.isAppInForeground()) { + if (!Utils.isAppInForegroundFixed()) { startView(SplashView.class); } } diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/misc/GDriveBackupWorker.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/misc/GDriveBackupWorker.java index 720eb2c6c..d8bad8f4b 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/misc/GDriveBackupWorker.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/misc/GDriveBackupWorker.java @@ -37,6 +37,7 @@ public class GDriveBackupWorker extends Worker { private static final String TAG = GDriveBackupWorker.class.getSimpleName(); private static final String WORK_NAME = TAG; private static final String BLOCKED_FILE_NAME = "blocked"; + private static final long REPEAT_INTERVAL_DAYS = 1; private static Disposable sAction; private final GDriveBackupManager mTask; @@ -54,7 +55,7 @@ public class GDriveBackupWorker extends Worker { workManager.enqueueUniquePeriodicWork( WORK_NAME, ExistingPeriodicWorkPolicy.UPDATE, // fix duplicates (when old worker is running) - new PeriodicWorkRequest.Builder(GDriveBackupWorker.class, 1, TimeUnit.DAYS).addTag(WORK_NAME).build() + new PeriodicWorkRequest.Builder(GDriveBackupWorker.class, REPEAT_INTERVAL_DAYS, TimeUnit.DAYS).addTag(WORK_NAME).build() ); } } diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/Utils.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/Utils.java index ce3eb8dc2..97bab0aa3 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/Utils.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/utils/Utils.java @@ -190,11 +190,9 @@ public class Utils { return Uri.parse(url); } - public static boolean isAppInForeground() { - ActivityManager.RunningAppProcessInfo appProcessInfo = new ActivityManager.RunningAppProcessInfo(); - ActivityManager.getMyMemoryState(appProcessInfo); - // Skip situation when splash presenter still running - return appProcessInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && SplashPresenter.instance(null).getView() == null; + public static boolean isAppInForegroundFixed() { + // Skip situation when the splash presenter still running + return Helpers.isAppInForeground() && SplashPresenter.instance(null).getView() == null; } /** diff --git a/leanbackassistant/src/main/java/com/liskovsoft/leanbackassistant/channels/UpdateChannelsWorker.java b/leanbackassistant/src/main/java/com/liskovsoft/leanbackassistant/channels/UpdateChannelsWorker.java index 97f85b246..188d17119 100644 --- a/leanbackassistant/src/main/java/com/liskovsoft/leanbackassistant/channels/UpdateChannelsWorker.java +++ b/leanbackassistant/src/main/java/com/liskovsoft/leanbackassistant/channels/UpdateChannelsWorker.java @@ -10,6 +10,7 @@ import androidx.work.WorkManager; import androidx.work.Worker; import androidx.work.WorkerParameters; +import com.liskovsoft.sharedutils.helpers.Helpers; import com.liskovsoft.sharedutils.mylogger.Log; import com.liskovsoft.sharedutils.prefs.GlobalPreferences; @@ -27,6 +28,7 @@ import java.util.concurrent.TimeUnit; public class UpdateChannelsWorker extends Worker { private static final String TAG = UpdateChannelsWorker.class.getSimpleName(); private static final String WORK_NAME = "Update channels"; + private static final long REPEAT_INTERVAL_MINUTES = 15; // 15 - minimal interval private final UpdateChannelsTask mTask; public UpdateChannelsWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { @@ -43,7 +45,7 @@ public class UpdateChannelsWorker extends Worker { workManager.enqueueUniquePeriodicWork( WORK_NAME, ExistingPeriodicWorkPolicy.UPDATE, // fix duplicates (when old worker is running) - new PeriodicWorkRequest.Builder(UpdateChannelsWorker.class, 20, TimeUnit.MINUTES).addTag(WORK_NAME).build() + new PeriodicWorkRequest.Builder(UpdateChannelsWorker.class, REPEAT_INTERVAL_MINUTES, TimeUnit.MINUTES).addTag(WORK_NAME).build() ); } } @@ -62,7 +64,10 @@ public class UpdateChannelsWorker extends Worker { public Result doWork() { Log.d(TAG, "Starting worker %s...", this); - mTask.run(); + // Improve performance. Run task when the app paused. + if (!Helpers.isAppInForeground()) { + mTask.run(); + } return Result.success(); }