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; protected final Object mMutex;
private final UserProfiles mUserProfiles; private final UserProfiles mUserProfiles;
private final IPackageManager mPm; private final IPackageManager mPm;
private final UserManager mUm; protected final UserManager mUm;
private final Config mConfig; private final Config mConfig;
private final Handler mHandler = new Handler(Looper.getMainLooper()); 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;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ParceledListSlice; import android.content.pm.ParceledListSlice;
import android.content.pm.UserInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.media.AudioAttributes; import android.media.AudioAttributes;
@@ -492,8 +493,8 @@ public class NotificationManagerService extends SystemService {
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId); | PackageManager.MATCH_DIRECT_BOOT_UNAWARE, userId);
for (ComponentName cn : approvedAssistants) { for (ComponentName cn : approvedAssistants) {
try { try {
getBinderService().setNotificationAssistantAccessGrantedForUser(cn, getBinderService().setNotificationAssistantAccessGrantedForUser(
userId, true); cn, userId, true);
} catch (RemoteException e) { } catch (RemoteException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -535,6 +536,8 @@ public class NotificationManagerService extends SystemService {
mConditionProviders.migrateToXml(); mConditionProviders.migrateToXml();
savePolicyFile(); savePolicyFile();
} }
mAssistants.ensureAssistant();
} }
private void loadPolicyFile() { private void loadPolicyFile() {
@@ -6140,11 +6143,14 @@ public class NotificationManagerService extends SystemService {
return !getServices().isEmpty(); return !getServices().isEmpty();
} }
protected void upgradeXml(final int xmlVersion, final int userId) { protected void ensureAssistant() {
if (xmlVersion == 0) { final List<UserInfo> activeUsers = mUm.getUsers(true);
// one time approval of the OOB assistant for (UserInfo userInfo : activeUsers) {
Slog.d(TAG, "Approving default notification assistant for user " + userId); int userId = userInfo.getUserHandle().getIdentifier();
readDefaultAssistant(userId); 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.ServiceInfo;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.os.UserManager; import android.os.UserManager;
import android.util.Slog;
import android.util.Xml; import android.util.Xml;
import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.FastXmlSerializer;
@@ -108,14 +107,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
} }
@Test @Test
public void testXmlUpgrade() throws Exception { public void testXmlUpgrade() {
String xml = "<enabled_assistants/>"; mAssistants.ensureAssistant();
XmlPullParser parser = Xml.newPullParser();
parser.setInput(new BufferedInputStream(
new ByteArrayInputStream(xml.toString().getBytes())), null);
parser.nextTag();
mAssistants.readXml(parser);
//once per user //once per user
verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt()); verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());
@@ -133,42 +126,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
parser.nextTag(); parser.nextTag();
mAssistants.readXml(parser); mAssistants.readXml(parser);
// once per user verify(mNm, never()).readDefaultAssistant(anyInt());
verify(mNm, times(mUm.getUsers().size())).readDefaultAssistant(anyInt());
verify(mAssistants, times(1)).addApprovedList( verify(mAssistants, times(1)).addApprovedList(
new ComponentName("b", "b").flattenToString(),10, true); 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 @Test
public void testReadPolicyXml_readApprovedServicesFromXml() throws Exception { public void testReadPolicyXml_readApprovedServicesFromXml() throws Exception {
final String preupgradeXml = "<notification-policy version=\"1\">" final String upgradeXml = "<notification-policy version=\"1\">"
+ "<zen></zen>" + "<zen></zen>"
+ "<ranking></ranking>" + "<ranking></ranking>"
+ "<enabled_listeners>" + "<enabled_listeners>"
@@ -2198,7 +2198,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
+ "</dnd_apps>" + "</dnd_apps>"
+ "</notification-policy>"; + "</notification-policy>";
mService.readPolicyXml( mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(preupgradeXml.getBytes())), false); new BufferedInputStream(new ByteArrayInputStream(upgradeXml.getBytes())), false);
verify(mListeners, times(1)).readXml(any()); verify(mListeners, times(1)).readXml(any());
verify(mConditionProviders, times(1)).readXml(any()); verify(mConditionProviders, times(1)).readXml(any());
verify(mAssistants, 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(mListeners, times(1)).migrateToXml();
verify(mConditionProviders, times(1)).migrateToXml(); verify(mConditionProviders, times(1)).migrateToXml();
verify(mAssistants, times(1)).migrateToXml(); verify(mAssistants, times(1)).migrateToXml();
verify(mAssistants, times(2)).ensureAssistant();
} }
@Test @Test
@@ -2225,6 +2226,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
verify(mListeners, times(2)).migrateToXml(); verify(mListeners, times(2)).migrateToXml();
verify(mConditionProviders, times(2)).migrateToXml(); verify(mConditionProviders, times(2)).migrateToXml();
verify(mAssistants, times(2)).migrateToXml(); verify(mAssistants, times(2)).migrateToXml();
verify(mAssistants, times(2)).ensureAssistant();
} }