| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.test; |
| 18 |
|
| 19 |
import android.content.ContentResolver; |
| 20 |
import android.content.Context; |
| 21 |
import android.os.Bundle; |
| 22 |
import android.os.SystemClock; |
| 23 |
import android.net.Uri; |
| 24 |
import android.accounts.Account; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
@Deprecated |
| 37 |
public class SyncBaseInstrumentation extends InstrumentationTestCase { |
| 38 |
private Context mTargetContext; |
| 39 |
ContentResolver mContentResolver; |
| 40 |
private static final int MAX_TIME_FOR_SYNC_IN_MINS = 20; |
| 41 |
|
| 42 |
@Override |
| 43 |
protected void setUp() throws Exception { |
| 44 |
super.setUp(); |
| 45 |
mTargetContext = getInstrumentation().getTargetContext(); |
| 46 |
mContentResolver = mTargetContext.getContentResolver(); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
protected void syncProvider(Uri uri, String accountName, String authority) throws Exception { |
| 54 |
Bundle extras = new Bundle(); |
| 55 |
extras.putBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, true); |
| 56 |
Account account = new Account(accountName, "com.google"); |
| 57 |
|
| 58 |
ContentResolver.requestSync(account, authority, extras); |
| 59 |
long startTimeInMillis = SystemClock.elapsedRealtime(); |
| 60 |
long endTimeInMillis = startTimeInMillis + MAX_TIME_FOR_SYNC_IN_MINS * 60000; |
| 61 |
|
| 62 |
int counter = 0; |
| 63 |
|
| 64 |
|
| 65 |
while (counter < 2) { |
| 66 |
|
| 67 |
Thread.sleep(1000); |
| 68 |
|
| 69 |
if (SystemClock.elapsedRealtime() > endTimeInMillis) { |
| 70 |
break; |
| 71 |
} |
| 72 |
|
| 73 |
if (ContentResolver.isSyncActive(account, authority)) { |
| 74 |
counter = 0; |
| 75 |
continue; |
| 76 |
} |
| 77 |
counter++; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
protected void cancelSyncsandDisableAutoSync() { |
| 82 |
ContentResolver.setMasterSyncAutomatically(false); |
| 83 |
ContentResolver.cancelSync(null , null ); |
| 84 |
} |
| 85 |
} |