Fix widget configuration for two-step process

- closes : #5124

Bug: java.lang.IllegalArgumentException: Bad widget id 2367
This commit is contained in:
MrSluffy
2024-12-30 08:31:17 +08:00
parent 45c8552319
commit aa8dd44d6a
2 changed files with 22 additions and 2 deletions

View File

@@ -1532,8 +1532,10 @@ public class Launcher extends StatefulActivity<LauncherState>
if (appWidgetInfo == null) {
appWidgetInfo = mAppWidgetManager.getLauncherAppWidgetInfo(appWidgetId,
itemInfo.getTargetComponent());
if (appWidgetInfo == null)
if (appWidgetInfo == null){
mAppWidgetHolder.deleteAppWidgetId(appWidgetId);
return;
}
}
if (hostView == null && !showPendingWidget) {

View File

@@ -238,6 +238,22 @@ public class LauncherWidgetHolder {
} catch (ActivityNotFoundException | SecurityException e) {
Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
sendActionCancelled(activity, requestCode);
} catch (IllegalArgumentException e) {
// Widget ID became invalid, possibly due to two-step configuration some cases
Log.e(this.getClass().getName(), "Widget ID became invalid during configuration", e);
handleInvalidWidgetId(activity, widgetId, requestCode);
}
}
private void handleInvalidWidgetId(BaseDraggingActivity activity, int widgetId, int requestCode) {
// Remove the invalid widget
deleteAppWidgetId(widgetId);
int newWidgetId = allocateAppWidgetId();
if (newWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
startConfigActivity(activity, newWidgetId, requestCode);
} else {
sendActionCancelled(activity, requestCode);
}
}
@@ -272,7 +288,9 @@ public class LauncherWidgetHolder {
// Must allow background activity start for U.
Utilities.allowBGLaunch(activityOptionsWrapper.options);
Bundle bundle = activityOptionsWrapper.toBundle();
bundle.putInt(KEY_SPLASH_SCREEN_STYLE, SPLASH_SCREEN_STYLE_EMPTY);
if (Utilities.ATLEAST_S) {
bundle.putInt(KEY_SPLASH_SCREEN_STYLE, SPLASH_SCREEN_STYLE_EMPTY);
}
return bundle;
}