How can I detect that a "Screen Time" process has crashed?

258 Views Asked by At

The issue:

Create a simple two tabs view:

 TabView {
     Tab1View()
           .tabItem {
                        Label("Tab 1", systemImage: "1.circle.fill")
                    }
     Tab2View()
           .tabItem {
                        Label("Tab 2", systemImage: "2.circle.fill")
                    }
     }

Each tab has a different "Screen Time" report, e.g.

struct Tab2View: View {
    var body: some View {
            DeviceActivityReport(Utils.weeklyContext, filter: Utils.filterWeekly)
    }
}

When you switch the tabs quickly, the "Screen Time" process crashes, leaving both reports blank.

Here is a video illustrating the issue:

https://www.youtube.com/watch?v=WrRpohf9tmw&ab_channel=MarcinCzech

A simple project with code to replicate:

https://github.com/AndroidGecko/Screen-Time/tree/screen_time_issues

I have filed it via a Feedback Assistant, but I can see that some apps have somehow found a workaround to this issue — so wondering how they did it.

The size of the "DeviceReportActivity" remains the same (it's just blank), so there is no way to tell if it crashed.

However, apps like Jomo or Opal have tabs with two "Screen Time" reports. And if you switch tabs quickly, you can see it breaking, but somehow they make it re-appear. We can refresh the view using .id() on the report, but I cannot see a way of detecting when the report (screen time process) has crashed. Forcing a new .id on each tab switch is not feasible as it re-fetches the whole report (Jomo and Opal don't do it).

Question: How can I detect that a "Screen Time" process has crashed?

1

There are 1 best solutions below

2
Faisal Memon On

I think the problem is originating from your third party library, RiveRuntime.

The DeviceActivityReport is not technically crashing because when I reproduce the problem and then look on the list of crash dumps, there is no crash dump.

I am able to reproduce the problem reliably just by having:

VStack(spacing: 10) {
                Text("Rive View in Screen Time Extension")
                DeviceActivityReport(context, filter: filter)
                DeviceActivityReport(context, filter: filter)
                DeviceActivityReport(context, filter: filter)
                ...

However when I did system profiling, which requires a Release build, I noticed an issue with your configuration:

ld: warning: linking against a dylib which is not safe for use in application extensions: /Users/username/Library/Developer/Xcode/DerivedData/Screen_Time-blyljiictkbafcchdezmsppdawwr/Build/Products/Release-iphoneos/RiveRuntime.framework/RiveRuntime

When I remove the use of the RiveRuntime.framework I can no longer get it to fail. The device reports come out correctly each time.