Merge change I5d199964 into eclair-mr2
* changes: add an IPC for sync initialization
This commit is contained in:
@ -21,6 +21,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.NetStat;
|
import android.os.NetStat;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.RemoteException;
|
||||||
import android.util.EventLog;
|
import android.util.EventLog;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -117,6 +118,12 @@ public abstract class AbstractThreadedSyncAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initialize(Account account, String authority) throws RemoteException {
|
||||||
|
Bundle extras = new Bundle();
|
||||||
|
extras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true);
|
||||||
|
startSync(null, authority, account, extras);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,4 +44,12 @@ oneway interface ISyncAdapter {
|
|||||||
* @param syncContext the ISyncContext that was passed to {@link #startSync}
|
* @param syncContext the ISyncContext that was passed to {@link #startSync}
|
||||||
*/
|
*/
|
||||||
void cancelSync(ISyncContext syncContext);
|
void cancelSync(ISyncContext syncContext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the SyncAdapter for this account and authority.
|
||||||
|
*
|
||||||
|
* @param account the account that should be synced
|
||||||
|
* @param authority the authority that should be synced
|
||||||
|
*/
|
||||||
|
void initialize(in Account account, String authority);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,12 @@ public abstract class SyncAdapter {
|
|||||||
public void cancelSync(ISyncContext syncContext) throws RemoteException {
|
public void cancelSync(ISyncContext syncContext) throws RemoteException {
|
||||||
SyncAdapter.this.cancelSync();
|
SyncAdapter.this.cancelSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void initialize(Account account, String authority) throws RemoteException {
|
||||||
|
Bundle extras = new Bundle();
|
||||||
|
extras.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true);
|
||||||
|
startSync(null, authority, account, extras);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Transport mTransport = new Transport();
|
Transport mTransport = new Transport();
|
||||||
|
@ -56,7 +56,9 @@ public class SyncContext {
|
|||||||
if (now < mLastHeartbeatSendTime + HEARTBEAT_SEND_INTERVAL_IN_MS) return;
|
if (now < mLastHeartbeatSendTime + HEARTBEAT_SEND_INTERVAL_IN_MS) return;
|
||||||
try {
|
try {
|
||||||
mLastHeartbeatSendTime = now;
|
mLastHeartbeatSendTime = now;
|
||||||
mSyncContext.sendHeartbeat();
|
if (mSyncContext != null) {
|
||||||
|
mSyncContext.sendHeartbeat();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// this should never happen
|
// this should never happen
|
||||||
}
|
}
|
||||||
@ -64,13 +66,15 @@ public class SyncContext {
|
|||||||
|
|
||||||
public void onFinished(SyncResult result) {
|
public void onFinished(SyncResult result) {
|
||||||
try {
|
try {
|
||||||
mSyncContext.onFinished(result);
|
if (mSyncContext != null) {
|
||||||
|
mSyncContext.onFinished(result);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// this should never happen
|
// this should never happen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBinder getSyncContextBinder() {
|
public IBinder getSyncContextBinder() {
|
||||||
return mSyncContext.asBinder();
|
return (mSyncContext == null) ? null : mSyncContext.asBinder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -544,6 +544,46 @@ class SyncManager implements OnAccountsUpdateListener {
|
|||||||
return (activeSyncContext != null) ? activeSyncContext.mSyncOperation.account : null;
|
return (activeSyncContext != null) ? activeSyncContext.mSyncOperation.account : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initializeSyncAdapter(Account account, String authority) {
|
||||||
|
SyncAdapterType syncAdapterType = SyncAdapterType.newKey(authority, account.type);
|
||||||
|
RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo =
|
||||||
|
mSyncAdapters.getServiceInfo(syncAdapterType);
|
||||||
|
if (syncAdapterInfo == null) {
|
||||||
|
Log.w(TAG, "can't find a sync adapter for " + syncAdapterType);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.setAction("android.content.SyncAdapter");
|
||||||
|
intent.setComponent(syncAdapterInfo.componentName);
|
||||||
|
mContext.bindService(intent, new InitializerServiceConnection(account, authority),
|
||||||
|
Context.BIND_AUTO_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class InitializerServiceConnection implements ServiceConnection {
|
||||||
|
private final Account mAccount;
|
||||||
|
private final String mAuthority;
|
||||||
|
|
||||||
|
public InitializerServiceConnection(Account account, String authority) {
|
||||||
|
mAccount = account;
|
||||||
|
mAuthority = authority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
|
try {
|
||||||
|
ISyncAdapter.Stub.asInterface(service).initialize(mAccount, mAuthority);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// doesn't matter, we will retry again later
|
||||||
|
} finally {
|
||||||
|
mContext.unbindService(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
|
mContext.unbindService(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether or not sync is enabled. Sync can be enabled by
|
* Returns whether or not sync is enabled. Sync can be enabled by
|
||||||
* setting the system property "ro.config.sync" to the value "yes".
|
* setting the system property "ro.config.sync" to the value "yes".
|
||||||
@ -686,36 +726,34 @@ class SyncManager implements OnAccountsUpdateListener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// make this an initialization sync if the isSyncable state is unknown
|
// initialize the SyncAdapter if the isSyncable state is unknown
|
||||||
Bundle extrasCopy = extras;
|
|
||||||
long delayCopy = delay;
|
|
||||||
if (isSyncable < 0) {
|
if (isSyncable < 0) {
|
||||||
extrasCopy = new Bundle(extras);
|
initializeSyncAdapter(account, authority);
|
||||||
extrasCopy.putBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, true);
|
continue;
|
||||||
delayCopy = -1; // expedite this
|
|
||||||
} else {
|
|
||||||
final boolean syncAutomatically = masterSyncAutomatically
|
|
||||||
&& mSyncStorageEngine.getSyncAutomatically(account, authority);
|
|
||||||
boolean syncAllowed =
|
|
||||||
manualSync || (backgroundDataUsageAllowed && syncAutomatically);
|
|
||||||
if (!syncAllowed) {
|
|
||||||
if (isLoggable) {
|
|
||||||
Log.d(TAG, "scheduleSync: sync of " + account + ", " + authority
|
|
||||||
+ " is not allowed, dropping request");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean syncAutomatically = masterSyncAutomatically
|
||||||
|
&& mSyncStorageEngine.getSyncAutomatically(account, authority);
|
||||||
|
boolean syncAllowed =
|
||||||
|
manualSync || (backgroundDataUsageAllowed && syncAutomatically);
|
||||||
|
if (!syncAllowed) {
|
||||||
|
if (isLoggable) {
|
||||||
|
Log.d(TAG, "scheduleSync: sync of " + account + ", " + authority
|
||||||
|
+ " is not allowed, dropping request");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (isLoggable) {
|
if (isLoggable) {
|
||||||
Log.v(TAG, "scheduleSync:"
|
Log.v(TAG, "scheduleSync:"
|
||||||
+ " delay " + delayCopy
|
+ " delay " + delay
|
||||||
+ ", source " + source
|
+ ", source " + source
|
||||||
+ ", account " + account
|
+ ", account " + account
|
||||||
+ ", authority " + authority
|
+ ", authority " + authority
|
||||||
+ ", extras " + extrasCopy);
|
+ ", extras " + extras);
|
||||||
}
|
}
|
||||||
scheduleSyncOperation(
|
scheduleSyncOperation(
|
||||||
new SyncOperation(account, source, authority, extrasCopy, delayCopy));
|
new SyncOperation(account, source, authority, extras, delay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user