From: David A. Velasco Date: Mon, 11 Nov 2013 09:08:16 +0000 (+0100) Subject: Reviewed integration with sychronization framework to fix problems in Android 4.4 X-Git-Tag: oc-android-1.5.5~135^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/cc39a76a90e6ecd572dbb249faae4e00b115832f?ds=inline;hp=-c Reviewed integration with sychronization framework to fix problems in Android 4.4 --- cc39a76a90e6ecd572dbb249faae4e00b115832f diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2035a9de..767b171b 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -38,7 +38,7 @@ + android:targetSdkVersion="19" /> @@ -112,7 +112,8 @@ + android:exported="true" + android:process=":sync"> diff --git a/project.properties b/project.properties index 716944a4..c9e58408 100644 --- a/project.properties +++ b/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-17 +target=android-19 android.library.reference.1=actionbarsherlock/library diff --git a/res/values/setup.xml b/res/values/setup.xml index a2fb403f..226b6182 100644 --- a/res/values/setup.xml +++ b/res/values/setup.xml @@ -2,8 +2,8 @@ ownCloud - owncloud - org.owncloud + owncloud + org.owncloud owncloud.db ownCloud owncloud diff --git a/res/xml/syncadapter_files.xml b/res/xml/syncadapter_files.xml index 25b018c2..8c8d8b36 100644 --- a/res/xml/syncadapter_files.xml +++ b/res/xml/syncadapter_files.xml @@ -25,4 +25,7 @@ android:contentAuthority="@string/authority" android:accountType="@string/account_type" android:supportsUploading="true" + android:userVisible="true" + android:allowParallelSyncs="true" + android:isAlwaysSyncable="true" /> diff --git a/src/com/owncloud/android/authentication/AccountAuthenticator.java b/src/com/owncloud/android/authentication/AccountAuthenticator.java index a2a38e89..ff0782d5 100644 --- a/src/com/owncloud/android/authentication/AccountAuthenticator.java +++ b/src/com/owncloud/android/authentication/AccountAuthenticator.java @@ -48,15 +48,6 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator { * Is used by android system to assign accounts to authenticators. Should be * used by application and all extensions. */ - /* These constants are now in MainApp - public static final String ACCOUNT_TYPE = "owncloud"; - public static final String AUTHORITY = "org.owncloud"; - public static final String AUTH_TOKEN_TYPE = "org.owncloud"; - public static final String AUTH_TOKEN_TYPE_PASSWORD = "owncloud.password"; - public static final String AUTH_TOKEN_TYPE_ACCESS_TOKEN = "owncloud.oauth2.access_token"; - public static final String AUTH_TOKEN_TYPE_REFRESH_TOKEN = "owncloud.oauth2.refresh_token"; - public static final String AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE = "owncloud.saml.web_sso.session_cookie"; - */ public static final String KEY_AUTH_TOKEN_TYPE = "authTokenType"; public static final String KEY_REQUIRED_FEATURES = "requiredFeatures"; public static final String KEY_LOGIN_OPTIONS = "loginOptions"; diff --git a/src/com/owncloud/android/authentication/AccountAuthenticatorService.java b/src/com/owncloud/android/authentication/AccountAuthenticatorService.java index 4c91f6e4..c479cea1 100644 --- a/src/com/owncloud/android/authentication/AccountAuthenticatorService.java +++ b/src/com/owncloud/android/authentication/AccountAuthenticatorService.java @@ -25,7 +25,6 @@ import android.os.IBinder; public class AccountAuthenticatorService extends Service { private AccountAuthenticator mAuthenticator; - //static final public String ACCOUNT_TYPE = "owncloud"; @Override public void onCreate() { diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 635e10ca..0ad985ee 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -391,14 +391,16 @@ public class FileDataStorageManager { if (id > FileDataStorageManager.ROOT_PARENT_ID) { Log_OC.d(TAG, "Updating size of " + id); if (getContentResolver() != null) { - getContentResolver().update(ProviderTableMeta.CONTENT_URI_DIR, null, + getContentResolver().update(ProviderTableMeta.CONTENT_URI_DIR, + new ContentValues(), // won't be used, but cannot be null; crashes in KLP ProviderTableMeta._ID + "=?", new String[] { String.valueOf(id) }); } else { try { - getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_DIR, null, - ProviderTableMeta._ID + "=?", - new String[] { String.valueOf(id) }); + getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_DIR, + new ContentValues(), // won't be used, but cannot be null; crashes in KLP + ProviderTableMeta._ID + "=?", + new String[] { String.valueOf(id) }); } catch (RemoteException e) { Log_OC.e(TAG, "Exception in update of folder size through compatibility patch " + e.getMessage()); diff --git a/src/com/owncloud/android/media/MediaServiceBinder.java b/src/com/owncloud/android/media/MediaServiceBinder.java index 4fab8bdf..ab018f67 100644 --- a/src/com/owncloud/android/media/MediaServiceBinder.java +++ b/src/com/owncloud/android/media/MediaServiceBinder.java @@ -176,6 +176,12 @@ public class MediaServiceBinder extends Binder implements MediaController.MediaP return (currentState == MediaService.State.PLAYING || currentState == MediaService.State.PAUSED); } + + @Override + public int getAudioSessionId() { + return 1; // not really used + } + } diff --git a/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java b/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java index a3e7926a..6e815579 100644 --- a/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/AbstractOwnCloudSyncAdapter.java @@ -53,7 +53,7 @@ public abstract class AbstractOwnCloudSyncAdapter extends private AccountManager accountManager; private Account account; - private ContentProviderClient contentProvider; + private ContentProviderClient mContentProviderClient; private FileDataStorageManager mStoreManager; private WebdavClient mClient = null; @@ -63,6 +63,11 @@ public abstract class AbstractOwnCloudSyncAdapter extends this.setAccountManager(AccountManager.get(context)); } + public AbstractOwnCloudSyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) { + super(context, autoInitialize, allowParallelSyncs); + this.setAccountManager(AccountManager.get(context)); + } + public AccountManager getAccountManager() { return accountManager; } @@ -79,12 +84,12 @@ public abstract class AbstractOwnCloudSyncAdapter extends this.account = account; } - public ContentProviderClient getContentProvider() { - return contentProvider; + public ContentProviderClient getContentProviderClient() { + return mContentProviderClient; } - public void setContentProvider(ContentProviderClient contentProvider) { - this.contentProvider = contentProvider; + public void setContentProviderClient(ContentProviderClient contentProvider) { + this.mContentProviderClient = contentProvider; } public void setStorageManager(FileDataStorageManager storage_manager) { diff --git a/src/com/owncloud/android/syncadapter/ContactSyncAdapter.java b/src/com/owncloud/android/syncadapter/ContactSyncAdapter.java index b07c048a..662c8a64 100644 --- a/src/com/owncloud/android/syncadapter/ContactSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/ContactSyncAdapter.java @@ -53,7 +53,7 @@ public class ContactSyncAdapter extends AbstractOwnCloudSyncAdapter { public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { setAccount(account); - setContentProvider(provider); + setContentProviderClient(provider); Cursor c = getLocalContacts(false); if (c.moveToFirst()) { do { diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index 7a00b2ef..5b0376c3 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java @@ -98,7 +98,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { /** - * Creates an {@link FileSyncAdapter} + * Creates a {@link FileSyncAdapter} * * {@inheritDoc} */ @@ -108,11 +108,21 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { /** + * Creates a {@link FileSyncAdapter} + * + * {@inheritDoc} + */ + public FileSyncAdapter(Context context, boolean autoInitialize, boolean allowParallelSyncs) { + super(context, autoInitialize, allowParallelSyncs); + } + + + /** * {@inheritDoc} */ @Override public synchronized void onPerformSync(Account account, Bundle extras, - String authority, ContentProviderClient provider, + String authority, ContentProviderClient providerClient, SyncResult syncResult) { mCancellation = false; @@ -127,8 +137,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { mSyncResult.delayUntil = 60*60*24; // avoid too many automatic synchronizations this.setAccount(account); - this.setContentProvider(provider); - this.setStorageManager(new FileDataStorageManager(account, provider)); + this.setContentProviderClient(providerClient); + this.setStorageManager(new FileDataStorageManager(account, providerClient)); try { this.initClientForCurrentAccount(); } catch (IOException e) { diff --git a/src/com/owncloud/android/syncadapter/FileSyncService.java b/src/com/owncloud/android/syncadapter/FileSyncService.java index 3c999753..dafc771b 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncService.java +++ b/src/com/owncloud/android/syncadapter/FileSyncService.java @@ -17,6 +17,8 @@ */ package com.owncloud.android.syncadapter; +import com.owncloud.android.Log_OC; + import android.app.Service; import android.content.Intent; import android.os.IBinder; @@ -37,6 +39,11 @@ public class FileSyncService extends Service { public static final String ACCOUNT_NAME = "ACCOUNT_NAME"; public static final String SYNC_RESULT = "SYNC_RESULT"; + // Storage for an instance of the sync adapter + private static FileSyncAdapter sSyncAdapter = null; + // Object to use as a thread-safe lock + private static final Object sSyncAdapterLock = new Object(); + public static String getSyncMessage(){ return FileSyncService.class.getName().toString() + SYNC_MESSAGE; } @@ -45,6 +52,11 @@ public class FileSyncService extends Service { */ @Override public void onCreate() { + synchronized (sSyncAdapterLock) { + if (sSyncAdapter == null) { + sSyncAdapter = new FileSyncAdapter(getApplicationContext(), true); + } + } } /* @@ -52,7 +64,7 @@ public class FileSyncService extends Service { */ @Override public IBinder onBind(Intent intent) { - return new FileSyncAdapter(getApplicationContext(), true).getSyncAdapterBinder(); + return sSyncAdapter.getSyncAdapterBinder(); } } diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index d58de5eb..39b7bd8a 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -31,8 +31,10 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; +import android.content.IntentFilter.AuthorityEntry; import android.content.ServiceConnection; import android.content.SharedPreferences; +import android.content.SyncRequest; import android.content.res.Resources.NotFoundException; import android.database.Cursor; import android.net.Uri; @@ -494,12 +496,27 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } private void startSynchronization() { - ContentResolver.cancelSync(null, MainApp.getAuthTokenType()); // cancel the current synchronizations of any ownCloud account - Bundle bundle = new Bundle(); - bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); - ContentResolver.requestSync( - getAccount(), - MainApp.getAuthTokenType(), bundle); + Log_OC.e(TAG, "Got to start sync"); + if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) { + Log_OC.e(TAG, "Canceling all syncs for " + MainApp.getAuthority()); + ContentResolver.cancelSync(null, MainApp.getAuthority()); // cancel the current synchronizations of any ownCloud account + Bundle bundle = new Bundle(); + bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); + bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); + Log_OC.e(TAG, "Requesting sync for " + getAccount().name + " at " + MainApp.getAuthority()); + ContentResolver.requestSync( + getAccount(), + MainApp.getAuthority(), bundle); + } else { + Log_OC.e(TAG, "Requesting sync for " + getAccount().name + " at " + MainApp.getAuthority() + " with new API"); + SyncRequest.Builder builder = new SyncRequest.Builder(); + builder.setSyncAdapter(getAccount(), MainApp.getAuthority()); + builder.setExpedited(true); + builder.setManual(true); + builder.syncOnce(); + SyncRequest request = builder.build(); + ContentResolver.requestSync(request); + } }