Clean up zen rules and permissions immediately on uninstall.

Change-Id: I8d03f4a4347b7d7bffbe267961c75ed5863a4113
Fixes: 30740759
This commit is contained in:
Julia Reynolds
2016-08-08 17:19:26 -04:00
parent 0b26adbb8b
commit 6434eb2e04
5 changed files with 37 additions and 15 deletions

View File

@@ -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 @@ public class ConditionProviders extends ManagedServices {
}
}
@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);

View File

@@ -217,8 +217,8 @@ abstract public class ManagedServices {
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 @@ abstract public class ManagedServices {
if (anyServicesInvolved) {
// if we're not replacing a package, clean up orphaned bits
if (!queryReplace) {
if (removingPackage) {
updateSettingsAccordingToInstalledServices();
rebuildRestoredPackages();
}

View File

@@ -696,9 +696,9 @@ public class NotificationManagerService extends SystemService {
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 @@ public class NotificationManagerService extends SystemService {
}
}
}
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 @@ public class NotificationManagerService extends SystemService {
}
@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();

View File

@@ -504,8 +504,8 @@ public class RankingHelper implements RankingConfig {
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
}

View File

@@ -147,6 +147,7 @@ public class ZenModeConditions implements ConditionProviders.Callback {
if (mConditionProviders.subscribeIfNecessary(rule.component, rule.conditionId)) {
mSubscriptions.put(rule.conditionId, rule.component);
} else {
rule.condition = null;
if (DEBUG) Log.d(TAG, "zmc failed to subscribe");
}
}