Commit 0995c644 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Log specific Android 9+ restrictions in Android PlatformHelper

parent 77983fe5
......@@ -142,6 +142,15 @@ public class AndroidPlatformHelper {
Log.e("[Platform Helper] failed to install some resources.");
}
if (DeviceUtils.isAppUserRestricted(mContext)) {
Log.w("[Platform Helper] Device has been restricted by user (Android 9+), push notifications won't work !");
}
int bucket = DeviceUtils.getAppStandbyBucket(mContext);
if (bucket > 0) {
Log.w("[Platform Helper] Device is in bucket " + DeviceUtils.getAppStandbyBucketNameFromValue(bucket));
}
mIsInInteractiveMode = true;
}
......
/*
DeviceUtils.java
Copyright (C) 2019 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.core.tools;
import android.content.Context;
import org.linphone.mediastream.Version;
public class DeviceUtils {
public static boolean isAppUserRestricted(Context context) {
if (Version.sdkAboveOrEqual(Version.API28_PIE_90)) {
return DeviceUtils28.isAppUserRestricted(context);
}
return false;
}
public static int getAppStandbyBucket(Context context) {
if (Version.sdkAboveOrEqual(Version.API28_PIE_90)) {
return DeviceUtils28.getAppStandbyBucket(context);
}
return 0;
}
public static String getAppStandbyBucketNameFromValue(int bucket) {
if (Version.sdkAboveOrEqual(Version.API28_PIE_90)) {
return DeviceUtils28.getAppStandbyBucketNameFromValue(bucket);
}
return null;
}
}
/*
DeviceUtils28.java
Copyright (C) 2019 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.linphone.core.tools;
import android.content.Context;
import android.app.ActivityManager;
import android.app.usage.UsageStatsManager;
import android.content.Context;
public class DeviceUtils28 {
public static boolean isAppUserRestricted(Context context) {
ActivityManager activityManager =
(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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment