Add ability to uninstall app widgets to ShadowAppWidgetManager.java

PiperOrigin-RevId: 394579316
diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowAppWidgetManagerTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowAppWidgetManagerTest.java
index cab172f..3774edb 100644
--- a/robolectric/src/test/java/org/robolectric/shadows/ShadowAppWidgetManagerTest.java
+++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowAppWidgetManagerTest.java
@@ -210,6 +210,45 @@
   }
 
   @Test
+  public void removeInstalledProviders_returnsWidgetList() {
+    AppWidgetProviderInfo info1 = new AppWidgetProviderInfo();
+    info1.label = "abc";
+    AppWidgetProviderInfo info2 = new AppWidgetProviderInfo();
+    info2.label = "def";
+    shadowAppWidgetManager.addInstalledProvider(info1);
+    shadowAppWidgetManager.addInstalledProvider(info2);
+    List<AppWidgetProviderInfo> installedProviders = appWidgetManager.getInstalledProviders();
+    assertEquals(2, installedProviders.size());
+    assertEquals(info1, installedProviders.get(0));
+    assertEquals(info2, installedProviders.get(1));
+    assertTrue(shadowAppWidgetManager.removeInstalledProvider(info1));
+    installedProviders = appWidgetManager.getInstalledProviders();
+    assertEquals(1, installedProviders.size());
+    assertEquals(info2, installedProviders.get(0));
+  }
+
+  @Test
+  public void tryRemoveNotInstalledProviders_noChange() {
+    AppWidgetProviderInfo info1 = new AppWidgetProviderInfo();
+    info1.label = "abc";
+    AppWidgetProviderInfo info2 = new AppWidgetProviderInfo();
+    info2.label = "def";
+    AppWidgetProviderInfo info3 = new AppWidgetProviderInfo();
+    info2.label = "efa";
+    shadowAppWidgetManager.addInstalledProvider(info1);
+    shadowAppWidgetManager.addInstalledProvider(info2);
+    List<AppWidgetProviderInfo> installedProviders = appWidgetManager.getInstalledProviders();
+    assertEquals(2, installedProviders.size());
+    assertEquals(info1, installedProviders.get(0));
+    assertEquals(info2, installedProviders.get(1));
+    assertFalse(shadowAppWidgetManager.removeInstalledProvider(info3));
+    installedProviders = appWidgetManager.getInstalledProviders();
+    assertEquals(2, installedProviders.size());
+    assertEquals(info1, installedProviders.get(0));
+    assertEquals(info2, installedProviders.get(1));
+  }
+
+  @Test
   @Config(minSdk = L)
   public void getInstalledProvidersForProfile_returnsWidgetList() {
     UserHandle userHandle = UserHandle.CURRENT;
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAppWidgetManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAppWidgetManager.java
index 4fe89a8..b747854 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAppWidgetManager.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowAppWidgetManager.java
@@ -155,6 +155,10 @@
     installedProviders.add(appWidgetProviderInfo);
   }
 
+  public boolean removeInstalledProvider(AppWidgetProviderInfo appWidgetProviderInfo) {
+    return installedProviders.remove(appWidgetProviderInfo);
+  }
+
   public void addInstalledProvidersForProfile(
       UserHandle userHandle, AppWidgetProviderInfo appWidgetProviderInfo) {
     installedProvidersForProfile.put(userHandle, appWidgetProviderInfo);