Log in which Android standby bucket the app is in if running on Android 9+ device
This commit is contained in:
parent
9b43b3e248
commit
5f09435bbb
4 changed files with 46 additions and 0 deletions
|
@ -1395,6 +1395,13 @@ public class LinphoneActivity extends LinphoneGenericActivity
|
|||
"[Linphone Activity] Device has been restricted by user (Android 9+), push notifications won't work !");
|
||||
}
|
||||
|
||||
int bucket = DeviceUtils.getAppStandbyBucket(this);
|
||||
if (bucket > 0) {
|
||||
Log.w(
|
||||
"[Linphone Activity] Device is in bucket "
|
||||
+ Compatibility.getAppStandbyBucketNameFromValue(bucket));
|
||||
}
|
||||
|
||||
IntentUtils.handleIntent(this, getIntent());
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.app.ActivityManager;
|
|||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Person;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Icon;
|
||||
|
@ -85,4 +86,24 @@ class ApiTwentyEightPlus {
|
|||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
return activityManager.isBackgroundRestricted();
|
||||
}
|
||||
|
||||
public static int getAppStandbyBucket(Context context) {
|
||||
UsageStatsManager usageStatsManager =
|
||||
(UsageStatsManager) context.getSystemService(Context.USAGE_STATS_SERVICE);
|
||||
return usageStatsManager.getAppStandbyBucket();
|
||||
}
|
||||
|
||||
public static String getAppStandbyBucketNameFromValue(int bucket) {
|
||||
switch (bucket) {
|
||||
case UsageStatsManager.STANDBY_BUCKET_ACTIVE:
|
||||
return "STANDBY_BUCKET_ACTIVE";
|
||||
case UsageStatsManager.STANDBY_BUCKET_FREQUENT:
|
||||
return "STANDBY_BUCKET_FREQUENT";
|
||||
case UsageStatsManager.STANDBY_BUCKET_RARE:
|
||||
return "STANDBY_BUCKET_RARE";
|
||||
case UsageStatsManager.STANDBY_BUCKET_WORKING_SET:
|
||||
return "STANDBY_BUCKET_WORKING_SET";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,4 +210,18 @@ public class Compatibility {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getAppStandbyBucket(Context context) {
|
||||
if (Version.sdkAboveOrEqual(Version.API28_PIE_90)) {
|
||||
return ApiTwentyEightPlus.getAppStandbyBucket(context);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static String getAppStandbyBucketNameFromValue(int bucket) {
|
||||
if (Version.sdkAboveOrEqual(Version.API28_PIE_90)) {
|
||||
return ApiTwentyEightPlus.getAppStandbyBucketNameFromValue(bucket);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,6 +125,10 @@ public class DeviceUtils {
|
|||
return Compatibility.isAppUserRestricted(context);
|
||||
}
|
||||
|
||||
public static int getAppStandbyBucket(Context context) {
|
||||
return Compatibility.getAppStandbyBucket(context);
|
||||
}
|
||||
|
||||
public static void displayDialogIfDeviceHasPowerManagerThatCouldPreventPushNotifications(
|
||||
final Context context) {
|
||||
for (final Intent intent : POWERMANAGER_INTENTS) {
|
||||
|
|
Loading…
Reference in a new issue