Add missing change notification dispatches.

These missing dispatches were leading tests to be flaky since they
would only pass if some other activity happened to dispatch the
notificatons at the same time.

Test: tsAppSearchTestCases:android.app.appsearch.cts.app.GlobalSearchSessionCtsTest#testAddObserver_schemaChange_removed (repeatedly)
Bug: 193494000
Bug: 218898037
Change-Id: I6276ae079866186bd4ff91ad723c959aaa4efc49
diff --git a/service/java/com/android/server/appsearch/AppSearchManagerService.java b/service/java/com/android/server/appsearch/AppSearchManagerService.java
index 375e7bd..4b4cbf1 100644
--- a/service/java/com/android/server/appsearch/AppSearchManagerService.java
+++ b/service/java/com/android/server/appsearch/AppSearchManagerService.java
@@ -243,6 +243,7 @@
                                 userContext, userHandle, AppSearchConfig.getInstance(EXECUTOR));
                 //TODO(b/145759910) clear visibility setting for package.
                 instance.getAppSearchImpl().clearPackageData(packageName);
+                dispatchChangeNotifications(instance);
                 instance.getLogger().removeCachedUidForPackage(packageName);
             }
         } catch (Throwable t) {
@@ -375,6 +376,10 @@
                     invokeCallbackOnResult(callback,
                             AppSearchResult.newSuccessfulResult(setSchemaResponse.getBundle()));
 
+                    // Schedule a task to dispatch change notifications. See requirements for where
+                    // the method is called documented in the method description.
+                    dispatchChangeNotifications(instance);
+
                     // setSchema will sync the schemas in the request to AppSearch, any existing
                     // schemas which  is not included in the request will be delete if we force
                     // override incompatible schemas. And all documents of these types will be