Gracefully handle exception when processing widget loads event while device is locked.

Bug: 277189566
Test: test starting launcher and editing widgets
Change-Id: Id15da3f3471374b02f1e2bf2e0a45dc801957241
This commit is contained in:
Fengjiang Li
2023-04-12 09:14:57 -07:00
parent f6bf07a5fe
commit e82b3fa8df

View File

@@ -78,8 +78,16 @@ public class WidgetManagerHelper {
return allWidgetsSteam(mContext).collect(Collectors.toList());
}
return mAppWidgetManager.getInstalledProvidersForPackage(
packageUser.mPackageName, packageUser.mUser);
try {
return mAppWidgetManager.getInstalledProvidersForPackage(
packageUser.mPackageName, packageUser.mUser);
} catch (IllegalStateException e) {
// b/277189566: Launcher will load the widget when it gets the user-unlock event.
// If exception is thrown because of device is locked, it means a race condition occurs
// that the user got locked again while launcher is processing the event. In this case
// we should return empty list.
return Collections.emptyList();
}
}
/**