Merge "Apply deliver-most-recent policy to LOGIN_ACCOUNTS_CHANGED." into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e7a445c946
@@ -38,6 +38,7 @@ import android.annotation.Nullable;
|
|||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.ActivityThread;
|
import android.app.ActivityThread;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
|
import android.app.BroadcastOptions;
|
||||||
import android.app.INotificationManager;
|
import android.app.INotificationManager;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
@@ -195,6 +196,9 @@ public class AccountManagerService
|
|||||||
private final IAccountAuthenticatorCache mAuthenticatorCache;
|
private final IAccountAuthenticatorCache mAuthenticatorCache;
|
||||||
private static final String PRE_N_DATABASE_NAME = "accounts.db";
|
private static final String PRE_N_DATABASE_NAME = "accounts.db";
|
||||||
private static final Intent ACCOUNTS_CHANGED_INTENT;
|
private static final Intent ACCOUNTS_CHANGED_INTENT;
|
||||||
|
private static final Bundle ACCOUNTS_CHANGED_OPTIONS = new BroadcastOptions()
|
||||||
|
.setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
|
||||||
|
.toBundle();
|
||||||
|
|
||||||
private static final int SIGNATURE_CHECK_MISMATCH = 0;
|
private static final int SIGNATURE_CHECK_MISMATCH = 0;
|
||||||
private static final int SIGNATURE_CHECK_MATCH = 1;
|
private static final int SIGNATURE_CHECK_MATCH = 1;
|
||||||
@@ -1075,7 +1079,8 @@ public class AccountManagerService
|
|||||||
Log.i(TAG, "the accountType= " + (accountType == null ? "" : accountType)
|
Log.i(TAG, "the accountType= " + (accountType == null ? "" : accountType)
|
||||||
+ " changed with useCase=" + useCase + " for userId=" + userId
|
+ " changed with useCase=" + useCase + " for userId=" + userId
|
||||||
+ ", sending broadcast of " + ACCOUNTS_CHANGED_INTENT.getAction());
|
+ ", sending broadcast of " + ACCOUNTS_CHANGED_INTENT.getAction());
|
||||||
mContext.sendBroadcastAsUser(ACCOUNTS_CHANGED_INTENT, new UserHandle(userId));
|
mContext.sendBroadcastAsUser(ACCOUNTS_CHANGED_INTENT, new UserHandle(userId),
|
||||||
|
null /* receiverPermission */, ACCOUNTS_CHANGED_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendAccountRemovedBroadcast(
|
private void sendAccountRemovedBroadcast(
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static org.mockito.Matchers.anyInt;
|
|||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.atLeast;
|
import static org.mockito.Mockito.atLeast;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.nullable;
|
import static org.mockito.Mockito.nullable;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@@ -37,6 +38,7 @@ import android.accounts.AccountManagerInternal;
|
|||||||
import android.accounts.CantAddAccountActivity;
|
import android.accounts.CantAddAccountActivity;
|
||||||
import android.accounts.IAccountManagerResponse;
|
import android.accounts.IAccountManagerResponse;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
|
import android.app.BroadcastOptions;
|
||||||
import android.app.INotificationManager;
|
import android.app.INotificationManager;
|
||||||
import android.app.PropertyInvalidatedCache;
|
import android.app.PropertyInvalidatedCache;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
@@ -171,6 +173,16 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
|||||||
setContext(mockContext);
|
setContext(mockContext);
|
||||||
mTestInjector = new TestInjector(realTestContext, mockContext, mMockNotificationManager);
|
mTestInjector = new TestInjector(realTestContext, mockContext, mMockNotificationManager);
|
||||||
mAms = new AccountManagerService(mTestInjector);
|
mAms = new AccountManagerService(mTestInjector);
|
||||||
|
doAnswer(invocation -> {
|
||||||
|
final Intent intent = invocation.getArgument(0);
|
||||||
|
final Bundle options = invocation.getArgument(3);
|
||||||
|
if (AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION.endsWith(intent.getAction())) {
|
||||||
|
final BroadcastOptions bOptions = new BroadcastOptions(options);
|
||||||
|
assertEquals(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT,
|
||||||
|
bOptions.getDeliveryGroupPolicy());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).when(mMockContext).sendBroadcastAsUser(any(), any(), any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -3142,7 +3154,7 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
|||||||
mAccountRemovedBroadcasts = 0;
|
mAccountRemovedBroadcasts = 0;
|
||||||
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
||||||
verify(mMockContext, atLeast(expectedBroadcasts)).sendBroadcastAsUser(captor.capture(),
|
verify(mMockContext, atLeast(expectedBroadcasts)).sendBroadcastAsUser(captor.capture(),
|
||||||
any(UserHandle.class));
|
any(UserHandle.class), any(), any());
|
||||||
for (Intent intent : captor.getAllValues()) {
|
for (Intent intent : captor.getAllValues()) {
|
||||||
if (AccountManager.ACTION_VISIBLE_ACCOUNTS_CHANGED.equals(intent.getAction())) {
|
if (AccountManager.ACTION_VISIBLE_ACCOUNTS_CHANGED.equals(intent.getAction())) {
|
||||||
mVisibleAccountsChangedBroadcasts++;
|
mVisibleAccountsChangedBroadcasts++;
|
||||||
@@ -3499,7 +3511,19 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendBroadcastAsUser(Intent intent, UserHandle user) {
|
public void sendBroadcastAsUser(Intent intent, UserHandle user) {
|
||||||
mMockContext.sendBroadcastAsUser(intent, user);
|
sendBroadcastAsUser(intent, user, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission,
|
||||||
|
Bundle options) {
|
||||||
|
mMockContext.sendBroadcastAsUser(intent, user, receiverPermission, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Intent registerReceiver(BroadcastReceiver receiver,
|
||||||
|
IntentFilter filter, String broadcastPermission, Handler scheduler) {
|
||||||
|
return mMockContext.registerReceiver(receiver, filter, broadcastPermission, scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user