diff options
author | Dianne Hackborn <hackbod@google.com> | 2009-05-06 00:28:37 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2009-05-06 00:28:37 -0700 |
commit | 7a1355950172b7a549820e9a2cd4a9b2099ec32f (patch) | |
tree | dc8940cdf38bae09e3427e44ebf1328861abc20b /core/java/android/content/ContentService.java | |
parent | 39a8bb26326ceeaad5b46d29bf485329c67ced2f (diff) | |
parent | 231cc608d06ffc31c24bf8aa8c8275bdd2636581 (diff) | |
download | frameworks_base-7a1355950172b7a549820e9a2cd4a9b2099ec32f.zip frameworks_base-7a1355950172b7a549820e9a2cd4a9b2099ec32f.tar.gz frameworks_base-7a1355950172b7a549820e9a2cd4a9b2099ec32f.tar.bz2 |
merged 231cc608d06ffc31c24bf8aa8c8275bdd2636581
Diffstat (limited to 'core/java/android/content/ContentService.java')
-rw-r--r-- | core/java/android/content/ContentService.java | 170 |
1 files changed, 168 insertions, 2 deletions
diff --git a/core/java/android/content/ContentService.java b/core/java/android/content/ContentService.java index b028868..c768ffa 100644 --- a/core/java/android/content/ContentService.java +++ b/core/java/android/content/ContentService.java @@ -16,11 +16,13 @@ package android.content; +import android.accounts.Account; import android.database.IContentObserver; import android.database.sqlite.SQLiteException; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; +import android.os.Parcel; import android.os.RemoteException; import android.os.ServiceManager; import android.util.Config; @@ -34,7 +36,7 @@ import java.util.ArrayList; /** * {@hide} */ -public final class ContentService extends ContentServiceNative { +public final class ContentService extends IContentService.Stub { private static final String TAG = "ContentService"; private Context mContext; private boolean mFactoryTest; @@ -73,6 +75,21 @@ public final class ContentService extends ContentServiceNative { } } + @Override + public boolean onTransact(int code, Parcel data, Parcel reply, int flags) + throws RemoteException { + try { + return super.onTransact(code, data, reply, flags); + } catch (RuntimeException e) { + // The content service only throws security exceptions, so let's + // log all others. + if (!(e instanceof SecurityException)) { + Log.e(TAG, "Content Service Crash", e); + } + throw e; + } + } + /*package*/ ContentService(Context context, boolean factoryTest) { mContext = context; mFactoryTest = factoryTest; @@ -204,9 +221,158 @@ public final class ContentService extends ContentServiceNative { } } + public boolean getSyncProviderAutomatically(String providerName) { + mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS, + "no permission to read the sync settings"); + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + return syncManager.getSyncStorageEngine().getSyncProviderAutomatically( + null, providerName); + } + } finally { + restoreCallingIdentity(identityToken); + } + return false; + } + + public void setSyncProviderAutomatically(String providerName, boolean sync) { + mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS, + "no permission to write the sync settings"); + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + syncManager.getSyncStorageEngine().setSyncProviderAutomatically( + null, providerName, sync); + } + } finally { + restoreCallingIdentity(identityToken); + } + } + + public boolean getListenForNetworkTickles() { + mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_SETTINGS, + "no permission to read the sync settings"); + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + return syncManager.getSyncStorageEngine().getListenForNetworkTickles(); + } + } finally { + restoreCallingIdentity(identityToken); + } + return false; + } + + public void setListenForNetworkTickles(boolean flag) { + mContext.enforceCallingOrSelfPermission(Manifest.permission.WRITE_SYNC_SETTINGS, + "no permission to write the sync settings"); + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + syncManager.getSyncStorageEngine().setListenForNetworkTickles(flag); + } + } finally { + restoreCallingIdentity(identityToken); + } + } + + public boolean isSyncActive(Account account, String authority) { + mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS, + "no permission to read the sync stats"); + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + return syncManager.getSyncStorageEngine().isSyncActive( + account, authority); + } + } finally { + restoreCallingIdentity(identityToken); + } + return false; + } + + public ActiveSyncInfo getActiveSync() { + mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS, + "no permission to read the sync stats"); + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + return syncManager.getSyncStorageEngine().getActiveSync(); + } + } finally { + restoreCallingIdentity(identityToken); + } + return null; + } + + public SyncStatusInfo getStatusByAuthority(String authority) { + mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS, + "no permission to read the sync stats"); + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + return syncManager.getSyncStorageEngine().getStatusByAuthority( + authority); + } + } finally { + restoreCallingIdentity(identityToken); + } + return null; + } + + public boolean isAuthorityPending(Account account, String authority) { + mContext.enforceCallingOrSelfPermission(Manifest.permission.READ_SYNC_STATS, + "no permission to read the sync stats"); + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + return syncManager.getSyncStorageEngine().isAuthorityPending( + account, authority); + } + } finally { + restoreCallingIdentity(identityToken); + } + return false; + } + + public void addStatusChangeListener(int mask, ISyncStatusObserver callback) { + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + syncManager.getSyncStorageEngine().addStatusChangeListener( + mask, callback); + } + } finally { + restoreCallingIdentity(identityToken); + } + } + + public void removeStatusChangeListener(ISyncStatusObserver callback) { + long identityToken = clearCallingIdentity(); + try { + SyncManager syncManager = getSyncManager(); + if (syncManager != null) { + syncManager.getSyncStorageEngine().removeStatusChangeListener( + callback); + } + } finally { + restoreCallingIdentity(identityToken); + } + } + public static IContentService main(Context context, boolean factoryTest) { ContentService service = new ContentService(context, factoryTest); - ServiceManager.addService("content", service); + ServiceManager.addService(ContentResolver.CONTENT_SERVICE_NAME, service); return service; } |