catch exception when checking phone lock state
This commit is contained in:
parent
bac62261f8
commit
3e333eb972
|
@ -1138,23 +1138,23 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isScreenLocked() {
|
public boolean isScreenLocked() {
|
||||||
final KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
|
final KeyguardManager keyguardManager = getSystemService(KeyguardManager.class);
|
||||||
final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
final PowerManager powerManager = getSystemService(PowerManager.class);
|
||||||
final boolean locked = keyguardManager != null && keyguardManager.isKeyguardLocked();
|
final boolean locked = keyguardManager != null && keyguardManager.isKeyguardLocked();
|
||||||
final boolean interactive = powerManager != null && powerManager.isInteractive();
|
final boolean interactive;
|
||||||
|
try {
|
||||||
|
interactive = powerManager != null && powerManager.isInteractive();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return locked || !interactive;
|
return locked || !interactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPhoneSilenced() {
|
private boolean isPhoneSilenced() {
|
||||||
final boolean notificationDnd;
|
final NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
final int filter = notificationManager == null ? NotificationManager.INTERRUPTION_FILTER_UNKNOWN : notificationManager.getCurrentInterruptionFilter();
|
||||||
final NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
final boolean notificationDnd = filter >= NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
||||||
final int filter = notificationManager == null ? NotificationManager.INTERRUPTION_FILTER_UNKNOWN : notificationManager.getCurrentInterruptionFilter();
|
final AudioManager audioManager = getSystemService(AudioManager.class);
|
||||||
notificationDnd = filter >= NotificationManager.INTERRUPTION_FILTER_PRIORITY;
|
|
||||||
} else {
|
|
||||||
notificationDnd = false;
|
|
||||||
}
|
|
||||||
final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
||||||
final int ringerMode = audioManager == null ? AudioManager.RINGER_MODE_NORMAL : audioManager.getRingerMode();
|
final int ringerMode = audioManager == null ? AudioManager.RINGER_MODE_NORMAL : audioManager.getRingerMode();
|
||||||
try {
|
try {
|
||||||
if (treatVibrateAsSilent()) {
|
if (treatVibrateAsSilent()) {
|
||||||
|
@ -1162,7 +1162,7 @@ public class XmppConnectionService extends Service {
|
||||||
} else {
|
} else {
|
||||||
return notificationDnd || ringerMode == AudioManager.RINGER_MODE_SILENT;
|
return notificationDnd || ringerMode == AudioManager.RINGER_MODE_SILENT;
|
||||||
}
|
}
|
||||||
} catch (Throwable throwable) {
|
} catch (final Throwable throwable) {
|
||||||
Log.d(Config.LOGTAG, "platform bug in isPhoneSilenced (" + throwable.getMessage() + ")");
|
Log.d(Config.LOGTAG, "platform bug in isPhoneSilenced (" + throwable.getMessage() + ")");
|
||||||
return notificationDnd;
|
return notificationDnd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue