Add metrics in AccountManager
Add metrics for addAccount, addAccountExplicitly, startAddAccountSession, and getAuthToken Bug: 182980755 Test: verified manually using make statsd_testdrive && ./out/host/linux-x86/bin/statsd_testdrive 103 Change-Id: I6cc0f9cb7a4b1e53d22ddcef0f03e7d42587b42e
This commit is contained in:
@@ -1027,7 +1027,8 @@ public class AccountManager {
|
||||
public boolean addAccountExplicitly(Account account, String password, Bundle userdata) {
|
||||
if (account == null) throw new IllegalArgumentException("account is null");
|
||||
try {
|
||||
return mService.addAccountExplicitly(account, password, userdata);
|
||||
return mService.addAccountExplicitly(
|
||||
account, password, userdata, mContext.getOpPackageName());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
@@ -1064,7 +1065,7 @@ public class AccountManager {
|
||||
throw new IllegalArgumentException("account is null");
|
||||
try {
|
||||
return mService.addAccountExplicitlyWithVisibility(account, password, extras,
|
||||
visibility);
|
||||
visibility, mContext.getOpPackageName());
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ interface IAccountManager {
|
||||
in String[] features, String opPackageName);
|
||||
void getAccountsByFeatures(in IAccountManagerResponse response, String accountType,
|
||||
in String[] features, String opPackageName);
|
||||
boolean addAccountExplicitly(in Account account, String password, in Bundle extras);
|
||||
boolean addAccountExplicitly(in Account account, String password, in Bundle extras, in String opPackageName);
|
||||
void removeAccountAsUser(in IAccountManagerResponse response, in Account account,
|
||||
boolean expectActivityLaunch, int userId);
|
||||
boolean removeAccountExplicitly(in Account account);
|
||||
@@ -107,7 +107,7 @@ interface IAccountManager {
|
||||
/* Returns Map<String, Integer> from package name to visibility with all values stored for given account */
|
||||
Map getPackagesAndVisibilityForAccount(in Account account);
|
||||
boolean addAccountExplicitlyWithVisibility(in Account account, String password, in Bundle extras,
|
||||
in Map visibility);
|
||||
in Map visibility, in String opPackageName);
|
||||
boolean setAccountVisibility(in Account a, in String packageName, int newVisibility);
|
||||
int getAccountVisibility(in Account a, in String packageName);
|
||||
/* Type may be null returns Map <Account, Integer>*/
|
||||
|
||||
@@ -42,6 +42,7 @@ import android.app.INotificationManager;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.admin.DevicePolicyEventLogger;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.app.admin.DevicePolicyManagerInternal;
|
||||
import android.content.BroadcastReceiver;
|
||||
@@ -85,6 +86,7 @@ import android.os.StrictMode;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.stats.devicepolicy.DevicePolicyEnums;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
@@ -105,7 +107,6 @@ import com.android.internal.util.Preconditions;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.ServiceThread;
|
||||
import com.android.server.SystemService;
|
||||
import com.android.server.SystemService.TargetUser;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
import com.google.android.collect.Sets;
|
||||
@@ -456,7 +457,7 @@ public class AccountManagerService
|
||||
|
||||
@Override
|
||||
public boolean addAccountExplicitlyWithVisibility(Account account, String password,
|
||||
Bundle extras, Map packageToVisibility) {
|
||||
Bundle extras, Map packageToVisibility, String opPackageName) {
|
||||
Bundle.setDefusable(extras, true);
|
||||
int callingUid = Binder.getCallingUid();
|
||||
int userId = UserHandle.getCallingUserId();
|
||||
@@ -481,7 +482,7 @@ public class AccountManagerService
|
||||
try {
|
||||
UserAccounts accounts = getUserAccounts(userId);
|
||||
return addAccountInternal(accounts, account, password, extras, callingUid,
|
||||
(Map<String, Integer>) packageToVisibility);
|
||||
(Map<String, Integer>) packageToVisibility, opPackageName);
|
||||
} finally {
|
||||
restoreCallingIdentity(identityToken);
|
||||
}
|
||||
@@ -1650,8 +1651,10 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAccountExplicitly(Account account, String password, Bundle extras) {
|
||||
return addAccountExplicitlyWithVisibility(account, password, extras, null);
|
||||
public boolean addAccountExplicitly(
|
||||
Account account, String password, Bundle extras, String opPackageName) {
|
||||
return addAccountExplicitlyWithVisibility(
|
||||
account, password, extras, /* packageToVisibility= */ null, opPackageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1807,7 +1810,8 @@ public class AccountManagerService
|
||||
}
|
||||
|
||||
private boolean addAccountInternal(UserAccounts accounts, Account account, String password,
|
||||
Bundle extras, int callingUid, Map<String, Integer> packageToVisibility) {
|
||||
Bundle extras, int callingUid, Map<String, Integer> packageToVisibility,
|
||||
String opPackageName) {
|
||||
Bundle.setDefusable(extras, true);
|
||||
if (account == null) {
|
||||
return false;
|
||||
@@ -1879,9 +1883,59 @@ public class AccountManagerService
|
||||
// Only send LOGIN_ACCOUNTS_CHANGED when the database changed.
|
||||
sendAccountsChangedBroadcast(accounts.userId);
|
||||
|
||||
logAddAccountExplicitlyMetrics(opPackageName, account.type, packageToVisibility);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void logAddAccountExplicitlyMetrics(
|
||||
String callerPackage, String accountType,
|
||||
@Nullable Map<String, Integer> accountVisibility) {
|
||||
// Although this is not a 'device policy' API, enterprise is the current use case.
|
||||
DevicePolicyEventLogger
|
||||
.createEvent(DevicePolicyEnums.ADD_ACCOUNT_EXPLICITLY)
|
||||
.setStrings(
|
||||
TextUtils.emptyIfNull(accountType),
|
||||
TextUtils.emptyIfNull(callerPackage),
|
||||
findPackagesPerVisibility(accountVisibility))
|
||||
.write();
|
||||
}
|
||||
|
||||
private String[] findPackagesPerVisibility(@Nullable Map<String, Integer> accountVisibility) {
|
||||
Map<Integer, Set<String>> packagesPerVisibility = new HashMap<>();
|
||||
if (accountVisibility != null) {
|
||||
for (Entry<String, Integer> entry : accountVisibility.entrySet()) {
|
||||
if (!packagesPerVisibility.containsKey(entry.getValue())) {
|
||||
packagesPerVisibility.put(entry.getValue(), new HashSet<>());
|
||||
}
|
||||
packagesPerVisibility.get(entry.getValue()).add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
String[] packagesPerVisibilityStr = new String[5];
|
||||
packagesPerVisibilityStr[AccountManager.VISIBILITY_UNDEFINED] = getPackagesForVisibilityStr(
|
||||
AccountManager.VISIBILITY_UNDEFINED, packagesPerVisibility);
|
||||
packagesPerVisibilityStr[AccountManager.VISIBILITY_VISIBLE] = getPackagesForVisibilityStr(
|
||||
AccountManager.VISIBILITY_VISIBLE, packagesPerVisibility);
|
||||
packagesPerVisibilityStr[AccountManager.VISIBILITY_USER_MANAGED_VISIBLE] =
|
||||
getPackagesForVisibilityStr(
|
||||
AccountManager.VISIBILITY_USER_MANAGED_VISIBLE, packagesPerVisibility);
|
||||
packagesPerVisibilityStr[AccountManager.VISIBILITY_NOT_VISIBLE] =
|
||||
getPackagesForVisibilityStr(
|
||||
AccountManager.VISIBILITY_NOT_VISIBLE, packagesPerVisibility);
|
||||
packagesPerVisibilityStr[AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE] =
|
||||
getPackagesForVisibilityStr(
|
||||
AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE, packagesPerVisibility);
|
||||
return packagesPerVisibilityStr;
|
||||
}
|
||||
|
||||
private String getPackagesForVisibilityStr(
|
||||
int visibility, Map<Integer, Set<String>> packagesPerVisibility) {
|
||||
return visibility + ":"
|
||||
+ (packagesPerVisibility.containsKey(visibility)
|
||||
? TextUtils.join(",", packagesPerVisibility.get(visibility))
|
||||
: "");
|
||||
}
|
||||
|
||||
private boolean isLocalUnlockedUser(int userId) {
|
||||
synchronized (mUsers) {
|
||||
return mLocalUnlockedUsers.get(userId);
|
||||
@@ -2898,6 +2952,7 @@ public class AccountManagerService
|
||||
if (!customTokens && permissionGranted) {
|
||||
String authToken = readAuthTokenInternal(accounts, account, authTokenType);
|
||||
if (authToken != null) {
|
||||
logGetAuthTokenMetrics(callerPkg, account.type);
|
||||
Bundle result = new Bundle();
|
||||
result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
|
||||
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
|
||||
@@ -2920,6 +2975,7 @@ public class AccountManagerService
|
||||
callerPkg,
|
||||
callerPkgSigDigest);
|
||||
if (token != null) {
|
||||
logGetAuthTokenMetrics(callerPkg, account.type);
|
||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||
Log.v(TAG, "getAuthToken: cache hit ofr custom token authenticator.");
|
||||
}
|
||||
@@ -2958,6 +3014,7 @@ public class AccountManagerService
|
||||
mAuthenticator.getAuthTokenLabel(this, authTokenType);
|
||||
} else {
|
||||
mAuthenticator.getAuthToken(this, account, authTokenType, loginOptions);
|
||||
logGetAuthTokenMetrics(callerPkg, account.type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3040,6 +3097,16 @@ public class AccountManagerService
|
||||
}
|
||||
}
|
||||
|
||||
private void logGetAuthTokenMetrics(final String callerPackage, String accountType) {
|
||||
// Although this is not a 'device policy' API, enterprise is the current use case.
|
||||
DevicePolicyEventLogger
|
||||
.createEvent(DevicePolicyEnums.GET_ACCOUNT_AUTH_TOKEN)
|
||||
.setStrings(
|
||||
TextUtils.emptyIfNull(callerPackage),
|
||||
TextUtils.emptyIfNull(accountType))
|
||||
.write();
|
||||
}
|
||||
|
||||
private byte[] calculatePackageSignatureDigest(String callerPkg) {
|
||||
MessageDigest digester;
|
||||
try {
|
||||
@@ -3189,38 +3256,8 @@ public class AccountManagerService
|
||||
userId);
|
||||
return;
|
||||
}
|
||||
|
||||
final int pid = Binder.getCallingPid();
|
||||
final Bundle options = (optionsIn == null) ? new Bundle() : optionsIn;
|
||||
options.putInt(AccountManager.KEY_CALLER_UID, uid);
|
||||
options.putInt(AccountManager.KEY_CALLER_PID, pid);
|
||||
|
||||
int usrId = UserHandle.getCallingUserId();
|
||||
final long identityToken = clearCallingIdentity();
|
||||
try {
|
||||
UserAccounts accounts = getUserAccounts(usrId);
|
||||
logRecordWithUid(
|
||||
accounts, AccountsDb.DEBUG_ACTION_CALLED_ACCOUNT_ADD, AccountsDb.TABLE_ACCOUNTS,
|
||||
uid);
|
||||
new Session(accounts, response, accountType, expectActivityLaunch,
|
||||
true /* stripAuthTokenFromResult */, null /* accountName */,
|
||||
false /* authDetailsRequired */, true /* updateLastAuthenticationTime */) {
|
||||
@Override
|
||||
public void run() throws RemoteException {
|
||||
mAuthenticator.addAccount(this, mAccountType, authTokenType, requiredFeatures,
|
||||
options);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toDebugString(long now) {
|
||||
return super.toDebugString(now) + ", addAccount"
|
||||
+ ", accountType " + accountType
|
||||
+ ", requiredFeatures " + Arrays.toString(requiredFeatures);
|
||||
}
|
||||
}.bind();
|
||||
} finally {
|
||||
restoreCallingIdentity(identityToken);
|
||||
}
|
||||
addAccountAndLogMetrics(response, accountType, authTokenType, requiredFeatures,
|
||||
expectActivityLaunch, optionsIn, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -3270,7 +3307,14 @@ public class AccountManagerService
|
||||
userId);
|
||||
return;
|
||||
}
|
||||
addAccountAndLogMetrics(response, accountType, authTokenType, requiredFeatures,
|
||||
expectActivityLaunch, optionsIn, userId);
|
||||
}
|
||||
|
||||
private void addAccountAndLogMetrics(
|
||||
IAccountManagerResponse response, String accountType,
|
||||
String authTokenType, String[] requiredFeatures,
|
||||
boolean expectActivityLaunch, Bundle optionsIn, int userId) {
|
||||
final int pid = Binder.getCallingPid();
|
||||
final int uid = Binder.getCallingUid();
|
||||
final Bundle options = (optionsIn == null) ? new Bundle() : optionsIn;
|
||||
@@ -3288,8 +3332,12 @@ public class AccountManagerService
|
||||
false /* authDetailsRequired */, true /* updateLastAuthenticationTime */) {
|
||||
@Override
|
||||
public void run() throws RemoteException {
|
||||
mAuthenticator.addAccount(this, mAccountType, authTokenType, requiredFeatures,
|
||||
options);
|
||||
mAuthenticator.addAccount(
|
||||
this, mAccountType, authTokenType, requiredFeatures, options);
|
||||
String callerPackage = options.getString(
|
||||
AccountManager.KEY_ANDROID_PACKAGE_NAME);
|
||||
logAddAccountMetrics(
|
||||
callerPackage, accountType, requiredFeatures, authTokenType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -3298,8 +3346,8 @@ public class AccountManagerService
|
||||
+ ", accountType " + accountType
|
||||
+ ", requiredFeatures "
|
||||
+ (requiredFeatures != null
|
||||
? TextUtils.join(",", requiredFeatures)
|
||||
: null);
|
||||
? TextUtils.join(",", requiredFeatures)
|
||||
: null);
|
||||
}
|
||||
}.bind();
|
||||
} finally {
|
||||
@@ -3307,6 +3355,22 @@ public class AccountManagerService
|
||||
}
|
||||
}
|
||||
|
||||
private void logAddAccountMetrics(
|
||||
String callerPackage, String accountType, String[] requiredFeatures,
|
||||
String authTokenType) {
|
||||
// Although this is not a 'device policy' API, enterprise is the current use case.
|
||||
DevicePolicyEventLogger
|
||||
.createEvent(DevicePolicyEnums.ADD_ACCOUNT)
|
||||
.setStrings(
|
||||
TextUtils.emptyIfNull(accountType),
|
||||
TextUtils.emptyIfNull(callerPackage),
|
||||
TextUtils.emptyIfNull(authTokenType),
|
||||
requiredFeatures == null
|
||||
? ""
|
||||
: TextUtils.join(";", requiredFeatures))
|
||||
.write();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAddAccountSession(
|
||||
final IAccountManagerResponse response,
|
||||
@@ -3378,6 +3442,7 @@ public class AccountManagerService
|
||||
public void run() throws RemoteException {
|
||||
mAuthenticator.startAddAccountSession(this, mAccountType, authTokenType,
|
||||
requiredFeatures, options);
|
||||
logAddAccountMetrics(callerPkg, accountType, requiredFeatures, authTokenType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -203,12 +203,18 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
Account a12 = new Account("account1", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_2);
|
||||
Account a22 = new Account("account2", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_2);
|
||||
Account a32 = new Account("account3", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_2);
|
||||
mAms.addAccountExplicitly(a11, "p11", null);
|
||||
mAms.addAccountExplicitly(a12, "p12", null);
|
||||
mAms.addAccountExplicitly(a21, "p21", null);
|
||||
mAms.addAccountExplicitly(a22, "p22", null);
|
||||
mAms.addAccountExplicitly(a31, "p31", null);
|
||||
mAms.addAccountExplicitly(a32, "p32", null);
|
||||
mAms.addAccountExplicitly(
|
||||
a11, /* password= */ "p11", /* extras= */ null, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
a12, /* password= */ "p12", /* extras= */ null, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
a21, /* password= */ "p21", /* extras= */ null, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
a22, /* password= */ "p22", /* extras= */ null, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
a31, /* password= */ "p31", /* extras= */ null, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
a32, /* password= */ "p32", /* extras= */ null, /* callerPackage= */ null);
|
||||
|
||||
String[] list = new String[]{AccountManagerServiceTestFixtures.CALLER_PACKAGE};
|
||||
when(mMockPackageManager.getPackagesForUid(anyInt())).thenReturn(list);
|
||||
@@ -246,8 +252,10 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
unlockSystemUser();
|
||||
Account a11 = new Account("account1", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1);
|
||||
Account a12 = new Account("account1", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_2);
|
||||
mAms.addAccountExplicitly(a11, "p11", null);
|
||||
mAms.addAccountExplicitly(a12, "p12", null);
|
||||
mAms.addAccountExplicitly(
|
||||
a11, /* password= */ "p11", /* extras= */ null, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
a12, /* password= */ "p12", /* extras= */ null, /* callerPackage= */ null);
|
||||
|
||||
assertEquals("p11", mAms.getPassword(a11));
|
||||
assertEquals("p12", mAms.getPassword(a12));
|
||||
@@ -271,8 +279,8 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
u12.putString("a", "a_a12");
|
||||
u12.putString("b", "b_a12");
|
||||
u12.putString("c", "c_a12");
|
||||
mAms.addAccountExplicitly(a11, "p11", u11);
|
||||
mAms.addAccountExplicitly(a12, "p12", u12);
|
||||
mAms.addAccountExplicitly(a11, /* password= */ "p11", u11, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(a12, /* password= */ "p12", u12, /* callerPackage= */ null);
|
||||
|
||||
assertEquals("a_a11", mAms.getUserData(a11, "a"));
|
||||
assertEquals("b_a11", mAms.getUserData(a11, "b"));
|
||||
@@ -297,8 +305,10 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
unlockSystemUser();
|
||||
Account a11 = new Account("account1", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1);
|
||||
Account a12 = new Account("account1", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_2);
|
||||
mAms.addAccountExplicitly(a11, "p11", null);
|
||||
mAms.addAccountExplicitly(a12, "p12", null);
|
||||
mAms.addAccountExplicitly(
|
||||
a11, /* password= */ "p11", /* extras= */ null, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
a12, /* password= */ "p12", /* extras= */ null, /* callerPackage= */ null);
|
||||
|
||||
mAms.setAuthToken(a11, "att1", "a11_att1");
|
||||
mAms.setAuthToken(a11, "att2", "a11_att2");
|
||||
@@ -334,8 +344,10 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
unlockSystemUser();
|
||||
Account a1 = new Account("account1", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1);
|
||||
Account a2 = new Account("account2", AccountManagerServiceTestFixtures.ACCOUNT_TYPE_2);
|
||||
mAms.addAccountExplicitly(a1, "p1", null);
|
||||
mAms.addAccountExplicitly(a2, "p2", null);
|
||||
mAms.addAccountExplicitly(
|
||||
a1, /* password= */ "p1", /* extras= */ null, /* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
a2, /* password= */ "p2", /* extras= */ null, /* callerPackage= */ null);
|
||||
|
||||
Context originalContext = ((MyMockContext)getContext()).mTestContext;
|
||||
// create a separate instance of AMS. It initially assumes that user0 is locked
|
||||
@@ -1426,7 +1438,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
when(mMockPackageManager.getPackagesForUid(anyInt())).thenReturn(list);
|
||||
|
||||
unlockSystemUser();
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p1", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p1",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
Account[] addedAccounts =
|
||||
mAms.getAccounts(UserHandle.USER_SYSTEM, mContext.getOpPackageName());
|
||||
assertEquals(1, addedAccounts.length);
|
||||
@@ -1508,9 +1524,17 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE);
|
||||
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "P11", null, visibility1);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "P11",
|
||||
/* extras= */ null,
|
||||
visibility1,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "P12", null, visibility2);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "P12",
|
||||
/* extras= */ null,
|
||||
visibility2,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
Account[] accounts = mAms.getAccountsByTypeForPackage(
|
||||
null, "otherPackageName",
|
||||
@@ -1631,7 +1655,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
when(mMockContext.getPackageManager()).thenReturn(mMockPackageManager);
|
||||
String[] list = new String[]{AccountManagerServiceTestFixtures.CALLER_PACKAGE};
|
||||
when(mMockPackageManager.getPackagesForUid(anyInt())).thenReturn(list);
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
mAms.setAuthToken(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
"authTokenType", AccountManagerServiceTestFixtures.AUTH_TOKEN);
|
||||
@@ -2438,7 +2466,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
public void testGetAccountByTypeAndFeaturesWithNoFeaturesAndOneVisibleAccount()
|
||||
throws Exception {
|
||||
unlockSystemUser();
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.getAccountByTypeAndFeatures(
|
||||
mMockAccountManagerResponse,
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1,
|
||||
@@ -2460,7 +2492,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
visibility.put(AccountManagerServiceTestFixtures.CALLER_PACKAGE,
|
||||
AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE);
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null, visibility);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
visibility,
|
||||
/* callerPackage= */ null);
|
||||
mAms.getAccountByTypeAndFeatures(
|
||||
mMockAccountManagerResponse,
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1,
|
||||
@@ -2476,8 +2512,16 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
@SmallTest
|
||||
public void testGetAccountByTypeAndFeaturesWithNoFeaturesAndTwoAccounts() throws Exception {
|
||||
unlockSystemUser();
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p12", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "p12",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
mAms.getAccountByTypeAndFeatures(
|
||||
mMockAccountManagerResponse,
|
||||
@@ -2519,7 +2563,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
public void testGetAccountByTypeAndFeaturesWithFeaturesAndNoQualifiedAccount()
|
||||
throws Exception {
|
||||
unlockSystemUser();
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p12", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "p12",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mAms.getAccountByTypeAndFeatures(
|
||||
mMockAccountManagerResponse,
|
||||
@@ -2539,8 +2587,16 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
public void testGetAccountByTypeAndFeaturesWithFeaturesAndOneQualifiedAccount()
|
||||
throws Exception {
|
||||
unlockSystemUser();
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p12", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "p12",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mAms.getAccountByTypeAndFeatures(
|
||||
mMockAccountManagerResponse,
|
||||
@@ -2564,7 +2620,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
visibility.put(AccountManagerServiceTestFixtures.CALLER_PACKAGE,
|
||||
AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE);
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null, visibility);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
visibility,
|
||||
/* callerPackage= */ null);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mAms.getAccountByTypeAndFeatures(
|
||||
mMockAccountManagerResponse,
|
||||
@@ -2583,9 +2643,21 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
public void testGetAccountByTypeAndFeaturesWithFeaturesAndTwoQualifiedAccount()
|
||||
throws Exception {
|
||||
unlockSystemUser();
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS_2, "p12", null);
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p13", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS_2,
|
||||
/* password= */ "p12",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "p13",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
mAms.getAccountByTypeAndFeatures(
|
||||
mMockAccountManagerResponse,
|
||||
@@ -2666,8 +2738,16 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
public void testGetAccountsByFeaturesNullFeatureReturnsAllAccounts() throws Exception {
|
||||
unlockSystemUser();
|
||||
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p12", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "p12",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Response response = new Response(latch, mMockAccountManagerResponse);
|
||||
@@ -2691,8 +2771,16 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
public void testGetAccountsByFeaturesReturnsAccountsWithFeaturesOnly() throws Exception {
|
||||
unlockSystemUser();
|
||||
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p12", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "p12",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Response response = new Response(latch, mMockAccountManagerResponse);
|
||||
@@ -2713,8 +2801,16 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
@SmallTest
|
||||
public void testGetAccountsByFeaturesError() throws Exception {
|
||||
unlockSystemUser();
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_ERROR, "p12", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_ERROR,
|
||||
/* password= */ "p12",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Response response = new Response(latch, mMockAccountManagerResponse);
|
||||
@@ -2758,7 +2854,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
new String [] {AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1},
|
||||
"testpackage"); // opPackageName
|
||||
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
// Notification about new account
|
||||
updateBroadcastCounters(2);
|
||||
assertEquals(mVisibleAccountsChangedBroadcasts, 1);
|
||||
@@ -2772,9 +2872,16 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
new String [] {AccountManagerServiceTestFixtures.ACCOUNT_TYPE_2},
|
||||
"testpackage"); // opPackageName
|
||||
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p11", null);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
// Notification about new account
|
||||
|
||||
updateBroadcastCounters(2);
|
||||
@@ -2794,14 +2901,21 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
new String [] {AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1},
|
||||
AccountManagerServiceTestFixtures.CALLER_PACKAGE);
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null, visibility);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null, visibility,
|
||||
/* callerPackage= */ null);
|
||||
mAms.unregisterAccountListener(
|
||||
new String [] {AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1},
|
||||
AccountManagerServiceTestFixtures.CALLER_PACKAGE);
|
||||
|
||||
addAccountRemovedReceiver(AccountManagerServiceTestFixtures.CALLER_PACKAGE);
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "p11", null, visibility);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
visibility,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
updateBroadcastCounters(3);
|
||||
assertEquals(mVisibleAccountsChangedBroadcasts, 1);
|
||||
@@ -2839,7 +2953,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
new String [] {AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1},
|
||||
"testpackage3"); // opPackageName
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null, visibility);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
visibility,
|
||||
/* callerPackage= */ null);
|
||||
updateBroadcastCounters(4);
|
||||
assertEquals(mVisibleAccountsChangedBroadcasts, 3);
|
||||
assertEquals(mLoginAccountsChangedBroadcasts, 1);
|
||||
@@ -2856,7 +2974,10 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
|
||||
// Add account of another type.
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS_TYPE_2, "p11", null);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS_TYPE_2,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
updateBroadcastCounters(8);
|
||||
assertEquals(mVisibleAccountsChangedBroadcasts, 5);
|
||||
@@ -2884,7 +3005,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
new String [] {AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1},
|
||||
"testpackage3"); // opPackageName
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null, visibility);
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
visibility,
|
||||
/* callerPackage= */ null);
|
||||
|
||||
updateBroadcastCounters(2);
|
||||
assertEquals(mVisibleAccountsChangedBroadcasts, 1);
|
||||
@@ -2904,7 +3029,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
mAms.registerAccountListener(
|
||||
new String [] {AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1},
|
||||
"testpackage"); // opPackageName
|
||||
mAms.addAccountExplicitly(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "p11", null);
|
||||
mAms.addAccountExplicitly(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
|
||||
/* password= */ "p11",
|
||||
/* extras= */ null,
|
||||
/* callerPackage= */ null);
|
||||
mAms.setPassword(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "pwd");
|
||||
updateBroadcastCounters(4);
|
||||
assertEquals(mVisibleAccountsChangedBroadcasts, 2);
|
||||
@@ -2963,7 +3092,8 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
|
||||
Account a1 = new Account("account1",
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1);
|
||||
mAms.addAccountExplicitly(a1, "p1", null);
|
||||
mAms.addAccountExplicitly(
|
||||
a1, /* password= */ "p1", /* extras= */ null, /* callerPackage= */ null);
|
||||
List<String> errors = Collections.synchronizedList(new ArrayList<>());
|
||||
int readerCount = 2;
|
||||
ExecutorService es = Executors.newFixedThreadPool(readerCount + 1);
|
||||
@@ -3040,7 +3170,8 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
|
||||
Account a1 = new Account("account1",
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1);
|
||||
mAms.addAccountExplicitly(a1, "p1", null);
|
||||
mAms.addAccountExplicitly(
|
||||
a1, /* password= */ "p1", /* extras= */ null, /* callerPackage= */ null);
|
||||
List<String> errors = Collections.synchronizedList(new ArrayList<>());
|
||||
int readerCount = 2;
|
||||
ExecutorService es = Executors.newFixedThreadPool(readerCount + 1);
|
||||
|
||||
Reference in New Issue
Block a user