Merge changes from topic "Sync-fix-redo" into tm-dev

* changes:
  Only allow the system server to connect to sync adapters
  Revert "Only allow the system server to connect to sync adapters"
This commit is contained in:
Makoto Onuki
2022-04-20 18:42:55 +00:00
committed by Android (Google) Code Review

View File

@@ -172,17 +172,20 @@ public abstract class AbstractThreadedSyncAdapter {
} }
private class ISyncAdapterImpl extends ISyncAdapter.Stub { private class ISyncAdapterImpl extends ISyncAdapter.Stub {
private void enforceCallerSystem() { private boolean isCallerSystem() {
final long callingUid = Binder.getCallingUid(); final long callingUid = Binder.getCallingUid();
if (callingUid != Process.SYSTEM_UID) { if (callingUid != Process.SYSTEM_UID) {
android.util.EventLog.writeEvent(0x534e4554, "203229608", -1, ""); android.util.EventLog.writeEvent(0x534e4554, "203229608", -1, "");
return; return false;
} }
return true;
} }
@Override @Override
public void onUnsyncableAccount(ISyncAdapterUnsyncableAccountCallback cb) { public void onUnsyncableAccount(ISyncAdapterUnsyncableAccountCallback cb) {
enforceCallerSystem(); if (!isCallerSystem()) {
return;
}
Handler.getMain().sendMessage(obtainMessage( Handler.getMain().sendMessage(obtainMessage(
AbstractThreadedSyncAdapter::handleOnUnsyncableAccount, AbstractThreadedSyncAdapter::handleOnUnsyncableAccount,
AbstractThreadedSyncAdapter.this, cb)); AbstractThreadedSyncAdapter.this, cb));
@@ -191,13 +194,15 @@ public abstract class AbstractThreadedSyncAdapter {
@Override @Override
public void startSync(ISyncContext syncContext, String authority, Account account, public void startSync(ISyncContext syncContext, String authority, Account account,
Bundle extras) { Bundle extras) {
if (!isCallerSystem()) {
return;
}
if (ENABLE_LOG) { if (ENABLE_LOG) {
if (extras != null) { if (extras != null) {
extras.size(); // Unparcel so its toString() will show the contents. extras.size(); // Unparcel so its toString() will show the contents.
} }
Log.d(TAG, "startSync() start " + authority + " " + account + " " + extras); Log.d(TAG, "startSync() start " + authority + " " + account + " " + extras);
} }
enforceCallerSystem();
try { try {
final SyncContext syncContextClient = new SyncContext(syncContext); final SyncContext syncContextClient = new SyncContext(syncContext);
@@ -254,7 +259,9 @@ public abstract class AbstractThreadedSyncAdapter {
@Override @Override
public void cancelSync(ISyncContext syncContext) { public void cancelSync(ISyncContext syncContext) {
enforceCallerSystem(); if (!isCallerSystem()) {
return;
}
try { try {
// synchronize to make sure that mSyncThreads doesn't change between when we // synchronize to make sure that mSyncThreads doesn't change between when we
// check it and when we use it // check it and when we use it