Skip to content

Commit 7bbc68f

Browse files
committed
Screen Sharing issue fixed
1 parent e6cf86d commit 7bbc68f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
buildscript {
22
ext {
3-
kotlin_version = '1.8.0'
3+
kotlin_version = '1.8.20'
44
compose_version = '1.4.0'
55
}
66

protect/src/main/java/com/webileapps/safeguard/ScreenSharingDetector.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.media.MediaRouter;
5+
import android.os.Build;
56
import android.util.Log;
67
import android.hardware.display.DisplayManager;
78
import android.view.Display;
@@ -13,14 +14,29 @@ public static boolean isScreenSharingActive(Context context) {
1314
MediaRouter mediaRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
1415
MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
1516

16-
boolean isScreenSharing = route != null && route.isEnabled() &&
17-
route.getDeviceType() == MediaRouter.RouteInfo.DEVICE_TYPE_TV;
17+
boolean isScreenSharing = false;
18+
19+
if (route != null && route.isEnabled()) {
20+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
21+
// Only call getDeviceType() on API 24 and above
22+
isScreenSharing = route.getDeviceType() == MediaRouter.RouteInfo.DEVICE_TYPE_TV;
23+
} else {
24+
// Fallback logic if needed for lower APIs — or assume no screen sharing
25+
Log.w(TAG, "getDeviceType() not supported on API < 24");
26+
}
27+
}
28+
1829
Log.d(TAG, "Screen Sharing Active: " + isScreenSharing);
1930
return isScreenSharing;
31+
2032
}
2133

2234
public static boolean isScreenMirrored(Context context) {
2335
DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
36+
if (displayManager == null) {
37+
Log.w(TAG, "DisplayManager not available. Cannot check for screen mirroring.");
38+
return false;
39+
}
2440
Display[] displays = displayManager.getDisplays();
2541

2642
for (Display display : displays) {

0 commit comments

Comments
 (0)