mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-04-21 01:33:36 +00:00
restore dnd && use ServiceManager
This commit is contained in:
parent
1407405ba0
commit
2905efc94e
2 changed files with 23 additions and 5 deletions
|
|
@ -7,7 +7,6 @@ import com.genymobile.scrcpy.util.SettingsException;
|
|||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Looper;
|
||||
import android.system.ErrnoException;
|
||||
|
|
@ -82,14 +81,13 @@ public final class CleanUp {
|
|||
}
|
||||
}
|
||||
|
||||
int previousDoNotDisturbMode = NotificationManager.INTERRUPTION_FILTER_NONE;
|
||||
int previousDoNotDisturbMode = -1;
|
||||
if (options.getDoNotDisturb()) {
|
||||
try {
|
||||
FakeContext context = FakeContext.get();
|
||||
NotificationManager notificationManager = (NotificationManager) context
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationManager notificationManager = ServiceManager.getNotificationManager();
|
||||
previousDoNotDisturbMode = notificationManager.getCurrentInterruptionFilter();
|
||||
notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALARMS);
|
||||
|
||||
} catch (Exception e) {
|
||||
Ln.e("Could not set dnd mode", e);
|
||||
}
|
||||
|
|
@ -284,6 +282,11 @@ public final class CleanUp {
|
|||
}
|
||||
}
|
||||
|
||||
if(previousDoNotDisturbMode != -1) {
|
||||
Ln.i("Restoring DoNotDisturbMode");
|
||||
ServiceManager.getNotificationManager().setInterruptionFilter(previousDoNotDisturbMode);
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.genymobile.scrcpy.wrappers;
|
|||
|
||||
import com.genymobile.scrcpy.FakeContext;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.hardware.camera2.CameraManager;
|
||||
|
|
@ -32,6 +33,7 @@ public final class ServiceManager {
|
|||
private static ClipboardManager clipboardManager;
|
||||
private static ActivityManager activityManager;
|
||||
private static CameraManager cameraManager;
|
||||
private static NotificationManager notificationManager;
|
||||
|
||||
private ServiceManager() {
|
||||
/* not instantiable */
|
||||
|
|
@ -109,4 +111,17 @@ public final class ServiceManager {
|
|||
}
|
||||
return cameraManager;
|
||||
}
|
||||
|
||||
public static NotificationManager getNotificationManager() {
|
||||
if (notificationManager == null) {
|
||||
try {
|
||||
// a similar method like CameraManager is only available for Android >= 16
|
||||
// https://android.googlesource.com/platform/frameworks/base/+blame/refs/tags/android-16.0.0_r4/core/java/android/app/NotificationManager.java#718
|
||||
notificationManager = (NotificationManager) FakeContext.get().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
return notificationManager;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue