Merge "Ensure that the blocking helper will run" into pi-dev

This commit is contained in:
Julia Reynolds
2018-04-03 22:48:05 +00:00
committed by Android (Google) Code Review
4 changed files with 21 additions and 54 deletions

View File

@@ -110,7 +110,7 @@ abstract public class ManagedServices {
protected final Object mMutex;
private final UserProfiles mUserProfiles;
private final IPackageManager mPm;
private final UserManager mUm;
protected final UserManager mUm;
private final Config mConfig;
private final Handler mHandler = new Handler(Looper.getMainLooper());

View File

@@ -114,6 +114,7 @@ import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ParceledListSlice;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.media.AudioAttributes;
@@ -492,8 +493,8 @@ public class NotificationManagerService extends SystemService {
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId);
for (ComponentName cn : approvedAssistants) {
try {
getBinderService().setNotificationAssistantAccessGrantedForUser(cn,
userId, true);
getBinderService().setNotificationAssistantAccessGrantedForUser(
cn, userId, true);
} catch (RemoteException e) {
e.printStackTrace();
}
@@ -535,6 +536,8 @@ public class NotificationManagerService extends SystemService {
mConditionProviders.migrateToXml();
savePolicyFile();
}
mAssistants.ensureAssistant();
}
private void loadPolicyFile() {
@@ -6140,11 +6143,14 @@ public class NotificationManagerService extends SystemService {
return !getServices().isEmpty();
}
protected void upgradeXml(final int xmlVersion, final int userId) {
if (xmlVersion == 0) {
// one time approval of the OOB assistant
Slog.d(TAG, "Approving default notification assistant for user " + userId);
readDefaultAssistant(userId);
protected void ensureAssistant() {
final List<UserInfo> activeUsers = mUm.getUsers(true);
for (UserInfo userInfo : activeUsers) {
int userId = userInfo.getUserHandle().getIdentifier();
if (getAllowedPackages(userId).isEmpty()) {
Slog.d(TAG, "Approving default notification assistant for user " + userId);
readDefaultAssistant(userId);
}
}
}
}

View File

@@ -33,7 +33,6 @@ import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo;
import android.os.UserManager;
import android.util.Slog;
import android.util.Xml;
import com.android.internal.util.FastXmlSerializer;
@@ -108,14 +107,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
}
@Test
public void testXmlUpgrade() throws Exception {
String xml = "<enabled_assistants/>";
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new BufferedInputStream(
new ByteArrayInputStream(xml.toString().getBytes())), null);
parser.nextTag();
mAssistants.readXml(parser);
public void testXmlUpgrade() {
mAssistants.ensureAssistant();
//once per user
verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());
@@ -133,42 +126,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
parser.nextTag();
mAssistants.readXml(parser);
// once per user
verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());
verify(mNm, never()).readDefaultAssistant(anyInt());
verify(mAssistants, times(1)).addApprovedList(
new ComponentName("b", "b").flattenToString(),10, true);
}
@Test
public void testXmlUpgradeOnce() throws Exception {
String xml = "<enabled_assistants/>";
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new BufferedInputStream(
new ByteArrayInputStream(xml.toString().getBytes())), null);
parser.nextTag();
mAssistants.readXml(parser);
XmlSerializer serializer = new FastXmlSerializer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.setOutput(new BufferedOutputStream(baos), "utf-8");
serializer.startDocument(null, true);
mAssistants.writeXml(serializer, true);
serializer.endDocument();
serializer.flush();
//once per user
verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());
Mockito.reset(mNm);
parser = Xml.newPullParser();
parser.setInput(new BufferedInputStream(
new ByteArrayInputStream(baos.toByteArray())), null);
parser.nextTag();
mAssistants.readXml(parser);
//once per user
verify(mNm, never()).readDefaultAssistant(anyInt());
}
}

View File

@@ -2184,7 +2184,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
@Test
public void testReadPolicyXml_readApprovedServicesFromXml() throws Exception {
final String preupgradeXml = "<notification-policy version=\"1\">"
final String upgradeXml = "<notification-policy version=\"1\">"
+ "<zen></zen>"
+ "<ranking></ranking>"
+ "<enabled_listeners>"
@@ -2198,7 +2198,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
+ "</dnd_apps>"
+ "</notification-policy>";
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(preupgradeXml.getBytes())), false);
new BufferedInputStream(new ByteArrayInputStream(upgradeXml.getBytes())), false);
verify(mListeners, times(1)).readXml(any());
verify(mConditionProviders, times(1)).readXml(any());
verify(mAssistants, times(1)).readXml(any());
@@ -2207,6 +2207,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
verify(mListeners, times(1)).migrateToXml();
verify(mConditionProviders, times(1)).migrateToXml();
verify(mAssistants, times(1)).migrateToXml();
verify(mAssistants, times(2)).ensureAssistant();
}
@Test
@@ -2225,6 +2226,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
verify(mListeners, times(2)).migrateToXml();
verify(mConditionProviders, times(2)).migrateToXml();
verify(mAssistants, times(2)).migrateToXml();
verify(mAssistants, times(2)).ensureAssistant();
}