Skip to content

Commit 3cd1905

Browse files
mjwilliams43The Android Automerger
authored andcommitted
Redact Account info from getCurrentSyncs
BUG:26094635 If the caller to ContentResolver#getCurrentSyncs does not hold the GET_ACCOUNTS permission, return a SyncInfo object that does not contain any Account information. Change-Id: I5628ebe1f56c8e3f784aaf1b3281e6b829d19314 (cherry picked from commit b63057e)
1 parent b22f3f2 commit 3cd1905

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

core/java/android/content/SyncInfo.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
* Information about the sync operation that is currently underway.
2525
*/
2626
public class SyncInfo implements Parcelable {
27+
/**
28+
* Used when the caller receiving this object doesn't have permission to access the accounts
29+
* on device.
30+
* @See Manifest.permission.GET_ACCOUNTS
31+
*/
32+
private static final Account REDACTED_ACCOUNT = new Account("*****", "*****");
33+
2734
/** @hide */
2835
public final int authorityId;
2936

@@ -44,6 +51,17 @@ public class SyncInfo implements Parcelable {
4451
*/
4552
public final long startTime;
4653

54+
/**
55+
* Creates a SyncInfo object with an unusable Account. Used when the caller receiving this
56+
* object doesn't have access to the accounts on the device.
57+
* @See Manifest.permission.GET_ACCOUNTS
58+
* @hide
59+
*/
60+
public static SyncInfo createAccountRedacted(
61+
int authorityId, String authority, long startTime) {
62+
return new SyncInfo(authorityId, REDACTED_ACCOUNT, authority, startTime);
63+
}
64+
4765
/** @hide */
4866
public SyncInfo(int authorityId, Account account, String authority, long startTime) {
4967
this.authorityId = authorityId;

services/core/java/com/android/server/content/ContentService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,13 @@ public List<SyncInfo> getCurrentSyncsAsUser(int userId) {
815815
mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS,
816816
"no permission to read the sync stats");
817817

818+
final boolean canAccessAccounts =
819+
mContext.checkCallingOrSelfPermission(Manifest.permission.GET_ACCOUNTS)
820+
== PackageManager.PERMISSION_GRANTED;
818821
long identityToken = clearCallingIdentity();
819822
try {
820-
return getSyncManager().getSyncStorageEngine().getCurrentSyncsCopy(userId);
823+
return getSyncManager().getSyncStorageEngine()
824+
.getCurrentSyncsCopy(userId, canAccessAccounts);
821825
} finally {
822826
restoreCallingIdentity(identityToken);
823827
}

services/core/java/com/android/server/content/SyncStorageEngine.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,15 +1459,23 @@ private List<SyncInfo> getCurrentSyncs(int userId) {
14591459
}
14601460

14611461
/**
1462-
* @return a copy of the current syncs data structure. Will not return
1463-
* null.
1462+
* @param userId Id of user to return current sync info.
1463+
* @param canAccessAccounts Determines whether to redact Account information from the result.
1464+
* @return a copy of the current syncs data structure. Will not return null.
14641465
*/
1465-
public List<SyncInfo> getCurrentSyncsCopy(int userId) {
1466+
public List<SyncInfo> getCurrentSyncsCopy(int userId, boolean canAccessAccounts) {
14661467
synchronized (mAuthorities) {
14671468
final List<SyncInfo> syncs = getCurrentSyncsLocked(userId);
14681469
final List<SyncInfo> syncsCopy = new ArrayList<SyncInfo>();
14691470
for (SyncInfo sync : syncs) {
1470-
syncsCopy.add(new SyncInfo(sync));
1471+
SyncInfo copy;
1472+
if (!canAccessAccounts) {
1473+
copy = SyncInfo.createAccountRedacted(
1474+
sync.authorityId, sync.authority, sync.startTime);
1475+
} else {
1476+
copy = new SyncInfo(sync);
1477+
}
1478+
syncsCopy.add(copy);
14711479
}
14721480
return syncsCopy;
14731481
}

0 commit comments

Comments
 (0)