Clean up zen rules and permissions immediately on uninstall. am: 6434eb2e04
am: eaf9974125
Change-Id: I80252835f84de0fc22491c5aa95595819c0d945c
diff --git a/services/core/java/com/android/server/notification/ConditionProviders.java b/services/core/java/com/android/server/notification/ConditionProviders.java
index 62fe70c..2fab288 100644
--- a/services/core/java/com/android/server/notification/ConditionProviders.java
+++ b/services/core/java/com/android/server/notification/ConditionProviders.java
@@ -17,6 +17,8 @@
package com.android.server.notification;
import android.annotation.NonNull;
+import android.app.INotificationManager;
+import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -161,6 +163,25 @@
}
}
+ @Override
+ public void onPackagesChanged(boolean removingPackage, String[] pkgList) {
+ if (removingPackage) {
+ INotificationManager inm = NotificationManager.getService();
+
+ if (pkgList != null && (pkgList.length > 0)) {
+ for (String pkgName : pkgList) {
+ try {
+ inm.removeAutomaticZenRules(pkgName);
+ inm.setNotificationPolicyAccessGranted(pkgName, false);
+ } catch (Exception e) {
+ Slog.e(TAG, "Failed to clean up rules for " + pkgName, e);
+ }
+ }
+ }
+ }
+ super.onPackagesChanged(removingPackage, pkgList);
+ }
+
public ManagedServiceInfo checkServiceToken(IConditionProvider provider) {
synchronized(mMutex) {
return checkServiceTokenLocked(provider);
diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java
index dc85dd7..14e2ba3 100644
--- a/services/core/java/com/android/server/notification/ManagedServices.java
+++ b/services/core/java/com/android/server/notification/ManagedServices.java
@@ -217,8 +217,8 @@
return mEnabledServicesPackageNames.contains(pkg);
}
- public void onPackagesChanged(boolean queryReplace, String[] pkgList) {
- if (DEBUG) Slog.d(TAG, "onPackagesChanged queryReplace=" + queryReplace
+ public void onPackagesChanged(boolean removingPackage, String[] pkgList) {
+ if (DEBUG) Slog.d(TAG, "onPackagesChanged removingPackage=" + removingPackage
+ " pkgList=" + (pkgList == null ? null : Arrays.asList(pkgList))
+ " mEnabledServicesPackageNames=" + mEnabledServicesPackageNames);
boolean anyServicesInvolved = false;
@@ -234,7 +234,7 @@
if (anyServicesInvolved) {
// if we're not replacing a package, clean up orphaned bits
- if (!queryReplace) {
+ if (removingPackage) {
updateSettingsAccordingToInstalledServices();
rebuildRestoredPackages();
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index e713d0c..cee5a46 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -696,9 +696,9 @@
int changeUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE,
UserHandle.USER_ALL);
String pkgList[] = null;
- boolean queryReplace = queryRemove &&
- intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
- if (DBG) Slog.i(TAG, "action=" + action + " queryReplace=" + queryReplace);
+ boolean removingPackage = queryRemove &&
+ !intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
+ if (DBG) Slog.i(TAG, "action=" + action + " removing=" + removingPackage);
if (action.equals(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE)) {
pkgList = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
} else if (action.equals(Intent.ACTION_PACKAGES_SUSPENDED)) {
@@ -747,10 +747,10 @@
}
}
}
- mListeners.onPackagesChanged(queryReplace, pkgList);
- mRankerServices.onPackagesChanged(queryReplace, pkgList);
- mConditionProviders.onPackagesChanged(queryReplace, pkgList);
- mRankingHelper.onPackagesChanged(queryReplace, pkgList);
+ mListeners.onPackagesChanged(removingPackage, pkgList);
+ mRankerServices.onPackagesChanged(removingPackage, pkgList);
+ mConditionProviders.onPackagesChanged(removingPackage, pkgList);
+ mRankingHelper.onPackagesChanged(removingPackage, pkgList);
}
}
};
@@ -3894,14 +3894,14 @@
}
@Override
- public void onPackagesChanged(boolean queryReplace, String[] pkgList) {
- if (DEBUG) Slog.d(TAG, "onPackagesChanged queryReplace=" + queryReplace
+ public void onPackagesChanged(boolean removingPackage, String[] pkgList) {
+ if (DEBUG) Slog.d(TAG, "onPackagesChanged removingPackage=" + removingPackage
+ " pkgList=" + (pkgList == null ? null : Arrays.asList(pkgList)));
if (mRankerServicePackageName == null) {
return;
}
- if (pkgList != null && (pkgList.length > 0)) {
+ if (pkgList != null && (pkgList.length > 0) && !removingPackage) {
for (String pkgName : pkgList) {
if (mRankerServicePackageName.equals(pkgName)) {
registerRanker();
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index c7325bb..32c5b13 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -504,8 +504,8 @@
return packageBans;
}
- public void onPackagesChanged(boolean queryReplace, String[] pkgList) {
- if (queryReplace || pkgList == null || pkgList.length == 0
+ public void onPackagesChanged(boolean removingPackage, String[] pkgList) {
+ if (!removingPackage || pkgList == null || pkgList.length == 0
|| mRestoredWithoutUids.isEmpty()) {
return; // nothing to do
}
diff --git a/services/core/java/com/android/server/notification/ZenModeConditions.java b/services/core/java/com/android/server/notification/ZenModeConditions.java
index 4cd61fd..7badecf 100644
--- a/services/core/java/com/android/server/notification/ZenModeConditions.java
+++ b/services/core/java/com/android/server/notification/ZenModeConditions.java
@@ -152,6 +152,7 @@
mSubscriptions.put(rule.conditionId, rule.component);
}
} else {
+ rule.condition = null;
if (DEBUG) Log.d(TAG, "zmc failed to subscribe");
}
}