Log if user has restricted app from being allowed to run in background (Android 9+)
This commit is contained in:
parent
28c2b86b75
commit
4c30791582
4 changed files with 24 additions and 0 deletions
|
@ -1391,6 +1391,11 @@ public class LinphoneActivity extends LinphoneGenericActivity
|
|||
this, permissions, PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE);
|
||||
}
|
||||
ContactsManager.getInstance().initializeContactManager(this);
|
||||
|
||||
if (DeviceUtils.isAppUserRestricted(this)) {
|
||||
Log.w(
|
||||
"[Linphone Activity] Device has been restricted by user (Android 9+), push notifications won't work !");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
import static org.linphone.compatibility.Compatibility.CHAT_NOTIFICATIONS_GROUP;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Person;
|
||||
|
@ -78,4 +79,10 @@ class ApiTwentyEightPlus {
|
|||
.addAction(ApiTwentyFourPlus.getMarkMessageAsReadAction(context, notif))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static boolean isAppUserRestricted(Context context) {
|
||||
ActivityManager activityManager =
|
||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
return activityManager.isBackgroundRestricted();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,4 +196,11 @@ public class Compatibility {
|
|||
ApiTwentyOnePlus.closeContentProviderClient(client);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAppUserRestricted(Context context) {
|
||||
if (Version.sdkAboveOrEqual(Version.API28_PIE_90)) {
|
||||
return ApiTwentyEightPlus.isAppUserRestricted(context);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import android.widget.TextView;
|
|||
import androidx.core.content.ContextCompat;
|
||||
import java.util.List;
|
||||
import org.linphone.R;
|
||||
import org.linphone.compatibility.Compatibility;
|
||||
import org.linphone.core.tools.Log;
|
||||
import org.linphone.settings.LinphonePreferences;
|
||||
|
||||
|
@ -120,6 +121,10 @@ public class DeviceUtils {
|
|||
return getDevicePowerManagerIntent(context) != null;
|
||||
}
|
||||
|
||||
public static boolean isAppUserRestricted(Context context) {
|
||||
return Compatibility.isAppUserRestricted(context);
|
||||
}
|
||||
|
||||
public static void displayDialogIfDeviceHasPowerManagerThatCouldPreventPushNotifications(
|
||||
final Context context) {
|
||||
for (final Intent intent : POWERMANAGER_INTENTS) {
|
||||
|
|
Loading…
Reference in a new issue