From a95f6449f58a61f1ffa3ef04401c3ad2c0d27578 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 18 Oct 2020 10:10:01 +0200 Subject: [PATCH] GCM: Fix apps not always whitelisted from powersave Fixes #1188 --- .../java/org/microg/gms/gcm/McsService.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java index 328378c8..026c43fa 100644 --- a/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java +++ b/play-services-core/src/main/java/org/microg/gms/gcm/McsService.java @@ -561,6 +561,7 @@ public class McsService extends Service implements Handler.Callback { if (receiverPermission == null) { // Without receiver permission, we only restrict by package name + if (app.wakeForDelivery) addPowerSaveTempWhitelistApp(packageName); logd(this, "Deliver message to all receivers in package " + packageName); intent.setPackage(packageName); sendOrderedBroadcast(intent, null); @@ -573,18 +574,7 @@ public class McsService extends Service implements Handler.Callback { Intent targetIntent = new Intent(intent); targetIntent.setComponent(new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name)); if (resolveInfo.activityInfo.packageName.equals(packageName)) { - // Wake up the package itself - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && app.wakeForDelivery) { - try { - if (getUserIdMethod != null && addPowerSaveTempWhitelistAppMethod != null && deviceIdleController != null) { - int userId = (int) getUserIdMethod.invoke(null, getPackageManager().getApplicationInfo(packageName, 0).uid); - logd(this, "Adding app " + packageName + " for userId " + userId + " to the temp whitelist"); - addPowerSaveTempWhitelistAppMethod.invoke(deviceIdleController, packageName, 10000, userId, "GCM Push"); - } - } catch (Exception e) { - Log.w(TAG, e); - } - } + if (app.wakeForDelivery) addPowerSaveTempWhitelistApp(packageName); // We don't need receiver permission for our own package logd(this, "Deliver message to own receiver " + resolveInfo); sendOrderedBroadcast(targetIntent, null); @@ -598,6 +588,20 @@ public class McsService extends Service implements Handler.Callback { } } + private void addPowerSaveTempWhitelistApp(String packageName) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + try { + if (getUserIdMethod != null && addPowerSaveTempWhitelistAppMethod != null && deviceIdleController != null) { + int userId = (int) getUserIdMethod.invoke(null, getPackageManager().getApplicationInfo(packageName, 0).uid); + logd(this, "Adding app " + packageName + " for userId " + userId + " to the temp whitelist"); + addPowerSaveTempWhitelistAppMethod.invoke(deviceIdleController, packageName, 10000, userId, "GCM Push"); + } + } catch (Exception e) { + Log.w(TAG, e); + } + } + } + private void handleSelfMessage(DataMessageStanza msg) { for (AppData appData : msg.app_data) { if (IDLE_NOTIFICATION.equals(appData.key)) {