2121import android .accounts .Account ;
2222import android .annotation .MainThread ;
2323import android .annotation .NonNull ;
24+ import android .os .Binder ;
2425import android .os .Build ;
2526import android .os .Bundle ;
2627import 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