Skip to content

Commit cbee4d9

Browse files
Makoto Onukiofficialputuid
authored andcommitted
Only allow the system server to connect to sync adapters
Bug: 203229608 Test: Manual test with changing the check logic + debug log Change-Id: If18009f61360564d02dcda9b1e5fa15685e3250f (cherry picked from commit 5827052) (cherry picked from commit 7d1397a) Merged-In: If18009f61360564d02dcda9b1e5fa15685e3250f
1 parent 4a554ec commit cbee4d9

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

core/java/android/content/AbstractThreadedSyncAdapter.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.accounts.Account;
2222
import android.annotation.MainThread;
2323
import android.annotation.NonNull;
24+
import android.os.Binder;
2425
import android.os.Build;
2526
import android.os.Bundle;
2627
import android.os.Handler;
@@ -171,8 +172,20 @@ private Account toSyncKey(Account account) {
171172
}
172173

173174
private class ISyncAdapterImpl extends ISyncAdapter.Stub {
175+
private boolean isCallerSystem() {
176+
final long callingUid = Binder.getCallingUid();
177+
if (callingUid != Process.SYSTEM_UID) {
178+
android.util.EventLog.writeEvent(0x534e4554, "203229608", -1, "");
179+
return false;
180+
}
181+
return true;
182+
}
183+
174184
@Override
175185
public void onUnsyncableAccount(ISyncAdapterUnsyncableAccountCallback cb) {
186+
if (!isCallerSystem()) {
187+
return;
188+
}
176189
Handler.getMain().sendMessage(obtainMessage(
177190
AbstractThreadedSyncAdapter::handleOnUnsyncableAccount,
178191
AbstractThreadedSyncAdapter.this, cb));
@@ -181,12 +194,16 @@ public void onUnsyncableAccount(ISyncAdapterUnsyncableAccountCallback cb) {
181194
@Override
182195
public void startSync(ISyncContext syncContext, String authority, Account account,
183196
Bundle extras) {
197+
if (!isCallerSystem()) {
198+
return;
199+
}
184200
if (ENABLE_LOG) {
185201
if (extras != null) {
186202
extras.size(); // Unparcel so its toString() will show the contents.
187203
}
188204
Log.d(TAG, "startSync() start " + authority + " " + account + " " + extras);
189205
}
206+
190207
try {
191208
final SyncContext syncContextClient = new SyncContext(syncContext);
192209

@@ -242,6 +259,9 @@ public void startSync(ISyncContext syncContext, String authority, Account accoun
242259

243260
@Override
244261
public void cancelSync(ISyncContext syncContext) {
262+
if (!isCallerSystem()) {
263+
return;
264+
}
245265
try {
246266
// synchronize to make sure that mSyncThreads doesn't change between when we
247267
// check it and when we use it

0 commit comments

Comments
 (0)