Merge "Allow notification listeners full DND access." into nyc-dev
am: 5776729
* commit '577672966cf466db37e6af1e383111de008154a3':
Allow notification listeners full DND access.
Change-Id: Iaa2d981df2df105a516ffa27849412fa907f0e05
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package com.android.server.notification;
|
package com.android.server.notification;
|
||||||
|
|
||||||
import android.app.AutomaticZenRule;
|
import android.annotation.NonNull;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -29,7 +29,6 @@ import android.os.UserHandle;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.notification.Condition;
|
import android.service.notification.Condition;
|
||||||
import android.service.notification.ConditionProviderService;
|
import android.service.notification.ConditionProviderService;
|
||||||
import android.service.notification.IConditionListener;
|
|
||||||
import android.service.notification.IConditionProvider;
|
import android.service.notification.IConditionProvider;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
@@ -82,6 +81,7 @@ public class ConditionProviders extends ManagedServices {
|
|||||||
c.caption = "condition provider";
|
c.caption = "condition provider";
|
||||||
c.serviceInterface = ConditionProviderService.SERVICE_INTERFACE;
|
c.serviceInterface = ConditionProviderService.SERVICE_INTERFACE;
|
||||||
c.secureSettingName = Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES;
|
c.secureSettingName = Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES;
|
||||||
|
c.secondarySettingName = Settings.Secure.ENABLED_NOTIFICATION_LISTENERS;
|
||||||
c.bindPermission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE;
|
c.bindPermission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE;
|
||||||
c.settingsAction = Settings.ACTION_CONDITION_PROVIDER_SETTINGS;
|
c.settingsAction = Settings.ACTION_CONDITION_PROVIDER_SETTINGS;
|
||||||
c.clientLabel = R.string.condition_provider_service_binding_label;
|
c.clientLabel = R.string.condition_provider_service_binding_label;
|
||||||
@@ -257,7 +257,7 @@ public class ConditionProviders extends ManagedServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName,
|
protected @NonNull ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName,
|
||||||
int userId) {
|
int userId) {
|
||||||
final ContentResolver cr = mContext.getContentResolver();
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
String settingValue = Settings.Secure.getStringForUser(
|
String settingValue = Settings.Secure.getStringForUser(
|
||||||
@@ -265,12 +265,17 @@ public class ConditionProviders extends ManagedServices {
|
|||||||
settingName,
|
settingName,
|
||||||
userId);
|
userId);
|
||||||
if (TextUtils.isEmpty(settingValue))
|
if (TextUtils.isEmpty(settingValue))
|
||||||
return null;
|
return new ArraySet<>();
|
||||||
String[] packages = settingValue.split(ENABLED_SERVICES_SEPARATOR);
|
String[] packages = settingValue.split(ENABLED_SERVICES_SEPARATOR);
|
||||||
ArraySet<ComponentName> result = new ArraySet<>(packages.length);
|
ArraySet<ComponentName> result = new ArraySet<>(packages.length);
|
||||||
for (int i = 0; i < packages.length; i++) {
|
for (int i = 0; i < packages.length; i++) {
|
||||||
if (!TextUtils.isEmpty(packages[i])) {
|
if (!TextUtils.isEmpty(packages[i])) {
|
||||||
result.addAll(queryPackageForServices(packages[i], userId));
|
final ComponentName component = ComponentName.unflattenFromString(packages[i]);
|
||||||
|
if (component != null) {
|
||||||
|
result.addAll(queryPackageForServices(component.getPackageName(), userId));
|
||||||
|
} else {
|
||||||
|
result.addAll(queryPackageForServices(packages[i], userId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -126,7 +126,8 @@ abstract public class ManagedServices {
|
|||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (Intent.ACTION_SETTING_RESTORED.equals(intent.getAction())) {
|
if (Intent.ACTION_SETTING_RESTORED.equals(intent.getAction())) {
|
||||||
String element = intent.getStringExtra(Intent.EXTRA_SETTING_NAME);
|
String element = intent.getStringExtra(Intent.EXTRA_SETTING_NAME);
|
||||||
if (Objects.equals(element, mConfig.secureSettingName)) {
|
if (Objects.equals(element, mConfig.secureSettingName)
|
||||||
|
|| Objects.equals(element, mConfig.secondarySettingName)) {
|
||||||
String prevValue = intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE);
|
String prevValue = intent.getStringExtra(Intent.EXTRA_SETTING_PREVIOUS_VALUE);
|
||||||
String newValue = intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE);
|
String newValue = intent.getStringExtra(Intent.EXTRA_SETTING_NEW_VALUE);
|
||||||
settingRestored(element, prevValue, newValue, getSendingUserId());
|
settingRestored(element, prevValue, newValue, getSendingUserId());
|
||||||
@@ -186,8 +187,8 @@ abstract public class ManagedServices {
|
|||||||
|
|
||||||
// By convention, restored settings are replicated to another settings
|
// By convention, restored settings are replicated to another settings
|
||||||
// entry, named similarly but with a disambiguation suffix.
|
// entry, named similarly but with a disambiguation suffix.
|
||||||
public static String restoredSettingName(Config config) {
|
public static String restoredSettingName(String setting) {
|
||||||
return config.secureSettingName + ":restored";
|
return setting + ":restored";
|
||||||
}
|
}
|
||||||
|
|
||||||
// The OS has done a restore of this service's saved state. We clone it to the
|
// The OS has done a restore of this service's saved state. We clone it to the
|
||||||
@@ -197,14 +198,14 @@ abstract public class ManagedServices {
|
|||||||
public void settingRestored(String element, String oldValue, String newValue, int userid) {
|
public void settingRestored(String element, String oldValue, String newValue, int userid) {
|
||||||
if (DEBUG) Slog.d(TAG, "Restored managed service setting: " + element
|
if (DEBUG) Slog.d(TAG, "Restored managed service setting: " + element
|
||||||
+ " ovalue=" + oldValue + " nvalue=" + newValue);
|
+ " ovalue=" + oldValue + " nvalue=" + newValue);
|
||||||
if (mConfig.secureSettingName.equals(element)) {
|
if (mConfig.secureSettingName.equals(element) ||
|
||||||
|
mConfig.secondarySettingName.equals(element)) {
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
mRestored = null;
|
|
||||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||||
restoredSettingName(mConfig),
|
restoredSettingName(element),
|
||||||
newValue,
|
newValue,
|
||||||
userid);
|
userid);
|
||||||
updateSettingsAccordingToInstalledServices(userid);
|
updateSettingsAccordingToInstalledServices(element, userid);
|
||||||
rebuildRestoredPackages();
|
rebuildRestoredPackages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,21 +344,25 @@ abstract public class ManagedServices {
|
|||||||
private void rebuildRestoredPackages() {
|
private void rebuildRestoredPackages() {
|
||||||
mRestoredPackages.clear();
|
mRestoredPackages.clear();
|
||||||
mSnoozingForCurrentProfiles.clear();
|
mSnoozingForCurrentProfiles.clear();
|
||||||
String settingName = restoredSettingName(mConfig);
|
String secureSettingName = restoredSettingName(mConfig.secureSettingName);
|
||||||
|
String secondarySettingName = mConfig.secondarySettingName == null
|
||||||
|
? null : restoredSettingName(mConfig.secondarySettingName);
|
||||||
int[] userIds = mUserProfiles.getCurrentProfileIds();
|
int[] userIds = mUserProfiles.getCurrentProfileIds();
|
||||||
final int N = userIds.length;
|
final int N = userIds.length;
|
||||||
for (int i = 0; i < N; ++i) {
|
for (int i = 0; i < N; ++i) {
|
||||||
ArraySet<ComponentName> names = loadComponentNamesFromSetting(settingName, userIds[i]);
|
ArraySet<ComponentName> names =
|
||||||
if (names == null)
|
loadComponentNamesFromSetting(secureSettingName, userIds[i]);
|
||||||
continue;
|
if (secondarySettingName != null) {
|
||||||
for (ComponentName name: names) {
|
names.addAll(loadComponentNamesFromSetting(secondarySettingName, userIds[i]));
|
||||||
|
}
|
||||||
|
for (ComponentName name : names) {
|
||||||
mRestoredPackages.add(name.getPackageName());
|
mRestoredPackages.add(name.getPackageName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName,
|
protected @NonNull ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName,
|
||||||
int userId) {
|
int userId) {
|
||||||
final ContentResolver cr = mContext.getContentResolver();
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
String settingValue = Settings.Secure.getStringForUser(
|
String settingValue = Settings.Secure.getStringForUser(
|
||||||
@@ -365,7 +370,7 @@ abstract public class ManagedServices {
|
|||||||
settingName,
|
settingName,
|
||||||
userId);
|
userId);
|
||||||
if (TextUtils.isEmpty(settingValue))
|
if (TextUtils.isEmpty(settingValue))
|
||||||
return null;
|
return new ArraySet<>();
|
||||||
String[] restored = settingValue.split(ENABLED_SERVICES_SEPARATOR);
|
String[] restored = settingValue.split(ENABLED_SERVICES_SEPARATOR);
|
||||||
ArraySet<ComponentName> result = new ArraySet<>(restored.length);
|
ArraySet<ComponentName> result = new ArraySet<>(restored.length);
|
||||||
for (int i = 0; i < restored.length; i++) {
|
for (int i = 0; i < restored.length; i++) {
|
||||||
@@ -405,7 +410,11 @@ abstract public class ManagedServices {
|
|||||||
int[] userIds = mUserProfiles.getCurrentProfileIds();
|
int[] userIds = mUserProfiles.getCurrentProfileIds();
|
||||||
final int N = userIds.length;
|
final int N = userIds.length;
|
||||||
for (int i = 0; i < N; ++i) {
|
for (int i = 0; i < N; ++i) {
|
||||||
updateSettingsAccordingToInstalledServices(userIds[i]);
|
updateSettingsAccordingToInstalledServices(mConfig.secureSettingName, userIds[i]);
|
||||||
|
if (mConfig.secondarySettingName != null) {
|
||||||
|
updateSettingsAccordingToInstalledServices(
|
||||||
|
mConfig.secondarySettingName, userIds[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rebuildRestoredPackages();
|
rebuildRestoredPackages();
|
||||||
}
|
}
|
||||||
@@ -442,13 +451,13 @@ abstract public class ManagedServices {
|
|||||||
return installed;
|
return installed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSettingsAccordingToInstalledServices(int userId) {
|
private void updateSettingsAccordingToInstalledServices(String setting, int userId) {
|
||||||
boolean restoredChanged = false;
|
boolean restoredChanged = false;
|
||||||
boolean currentChanged = false;
|
boolean currentChanged = false;
|
||||||
Set<ComponentName> restored =
|
Set<ComponentName> restored =
|
||||||
loadComponentNamesFromSetting(restoredSettingName(mConfig), userId);
|
loadComponentNamesFromSetting(restoredSettingName(setting), userId);
|
||||||
Set<ComponentName> current =
|
Set<ComponentName> current =
|
||||||
loadComponentNamesFromSetting(mConfig.secureSettingName, userId);
|
loadComponentNamesFromSetting(setting, userId);
|
||||||
// Load all services for all packages.
|
// Load all services for all packages.
|
||||||
Set<ComponentName> installed = queryPackageForServices(null, userId);
|
Set<ComponentName> installed = queryPackageForServices(null, userId);
|
||||||
|
|
||||||
@@ -478,13 +487,13 @@ abstract public class ManagedServices {
|
|||||||
|
|
||||||
if (currentChanged) {
|
if (currentChanged) {
|
||||||
if (DEBUG) Slog.v(TAG, "List of " + getCaption() + " services was updated " + current);
|
if (DEBUG) Slog.v(TAG, "List of " + getCaption() + " services was updated " + current);
|
||||||
storeComponentsToSetting(retained, mConfig.secureSettingName, userId);
|
storeComponentsToSetting(retained, setting, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restoredChanged) {
|
if (restoredChanged) {
|
||||||
if (DEBUG) Slog.v(TAG,
|
if (DEBUG) Slog.v(TAG,
|
||||||
"List of " + getCaption() + " restored services was updated " + restored);
|
"List of " + getCaption() + " restored services was updated " + restored);
|
||||||
storeComponentsToSetting(restored, restoredSettingName(mConfig), userId);
|
storeComponentsToSetting(restored, restoredSettingName(setting), userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,6 +511,10 @@ abstract public class ManagedServices {
|
|||||||
for (int i = 0; i < nUserIds; ++i) {
|
for (int i = 0; i < nUserIds; ++i) {
|
||||||
componentsByUser.put(userIds[i],
|
componentsByUser.put(userIds[i],
|
||||||
loadComponentNamesFromSetting(mConfig.secureSettingName, userIds[i]));
|
loadComponentNamesFromSetting(mConfig.secureSettingName, userIds[i]));
|
||||||
|
if (mConfig.secondarySettingName != null) {
|
||||||
|
componentsByUser.get(userIds[i]).addAll(
|
||||||
|
loadComponentNamesFromSetting(mConfig.secondarySettingName, userIds[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<ManagedServiceInfo> removableBoundServices = new ArrayList<>();
|
final ArrayList<ManagedServiceInfo> removableBoundServices = new ArrayList<>();
|
||||||
@@ -522,7 +535,7 @@ abstract public class ManagedServices {
|
|||||||
// decode the list of components
|
// decode the list of components
|
||||||
final ArraySet<ComponentName> userComponents = componentsByUser.get(userIds[i]);
|
final ArraySet<ComponentName> userComponents = componentsByUser.get(userIds[i]);
|
||||||
if (null == userComponents) {
|
if (null == userComponents) {
|
||||||
toAdd.put(userIds[i], new HashSet<ComponentName>());
|
toAdd.put(userIds[i], new ArraySet<ComponentName>());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,15 +788,25 @@ abstract public class ManagedServices {
|
|||||||
|
|
||||||
private class SettingsObserver extends ContentObserver {
|
private class SettingsObserver extends ContentObserver {
|
||||||
private final Uri mSecureSettingsUri = Settings.Secure.getUriFor(mConfig.secureSettingName);
|
private final Uri mSecureSettingsUri = Settings.Secure.getUriFor(mConfig.secureSettingName);
|
||||||
|
private final Uri mSecondarySettingsUri;
|
||||||
|
|
||||||
private SettingsObserver(Handler handler) {
|
private SettingsObserver(Handler handler) {
|
||||||
super(handler);
|
super(handler);
|
||||||
|
if (mConfig.secondarySettingName != null) {
|
||||||
|
mSecondarySettingsUri = Settings.Secure.getUriFor(mConfig.secondarySettingName);
|
||||||
|
} else {
|
||||||
|
mSecondarySettingsUri = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void observe() {
|
private void observe() {
|
||||||
ContentResolver resolver = mContext.getContentResolver();
|
ContentResolver resolver = mContext.getContentResolver();
|
||||||
resolver.registerContentObserver(mSecureSettingsUri,
|
resolver.registerContentObserver(mSecureSettingsUri,
|
||||||
false, this, UserHandle.USER_ALL);
|
false, this, UserHandle.USER_ALL);
|
||||||
|
if (mSecondarySettingsUri != null) {
|
||||||
|
resolver.registerContentObserver(mSecondarySettingsUri,
|
||||||
|
false, this, UserHandle.USER_ALL);
|
||||||
|
}
|
||||||
update(null);
|
update(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,9 +816,9 @@ abstract public class ManagedServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void update(Uri uri) {
|
private void update(Uri uri) {
|
||||||
if (uri == null || mSecureSettingsUri.equals(uri)) {
|
if (uri == null || mSecureSettingsUri.equals(uri)
|
||||||
if (DEBUG) Slog.d(TAG, "Setting changed: mSecureSettingsUri=" + mSecureSettingsUri +
|
|| uri.equals(mSecondarySettingsUri)) {
|
||||||
" / uri=" + uri);
|
if (DEBUG) Slog.d(TAG, "Setting changed: uri=" + uri);
|
||||||
rebindServices(false);
|
rebindServices(false);
|
||||||
rebuildRestoredPackages();
|
rebuildRestoredPackages();
|
||||||
}
|
}
|
||||||
@@ -917,6 +940,7 @@ abstract public class ManagedServices {
|
|||||||
public String caption;
|
public String caption;
|
||||||
public String serviceInterface;
|
public String serviceInterface;
|
||||||
public String secureSettingName;
|
public String secureSettingName;
|
||||||
|
public String secondarySettingName;
|
||||||
public String bindPermission;
|
public String bindPermission;
|
||||||
public String settingsAction;
|
public String settingsAction;
|
||||||
public int clientLabel;
|
public int clientLabel;
|
||||||
|
|||||||
Reference in New Issue
Block a user