Browse Source

notify storageprovider on account creation/removal

Signed-off-by: Jens Mueller <tschenser@gmx.de>
Jens Mueller 5 years ago
parent
commit
fa5e5dd8cd

+ 8 - 0
src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -62,6 +62,7 @@ import android.os.Bundle;
 import android.os.Handler;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.IBinder;
 import android.preference.PreferenceManager;
 import android.preference.PreferenceManager;
+import android.provider.DocumentsContract;
 import android.text.Editable;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.InputType;
 import android.text.TextUtils;
 import android.text.TextUtils;
@@ -1768,6 +1769,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             setAccountAuthenticatorResult(intent.getExtras());
             setAccountAuthenticatorResult(intent.getExtras());
             setResult(RESULT_OK, intent);
             setResult(RESULT_OK, intent);
 
 
+            // notify Document Provider
+            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+                String authority = getResources().getString(R.string.document_provider_authority);
+                Uri rootsUri = DocumentsContract.buildRootsUri(authority);
+                getContentResolver().notifyChange(rootsUri, null);
+            }
+
             return true;
             return true;
         }
         }
     }
     }

+ 10 - 0
src/main/java/com/owncloud/android/jobs/AccountRemovalJob.java

@@ -30,6 +30,9 @@ import android.accounts.AccountManagerCallback;
 import android.accounts.AccountManagerFuture;
 import android.accounts.AccountManagerFuture;
 import android.content.ContentResolver;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Context;
+import android.net.Uri;
+import android.os.Build;
+import android.provider.DocumentsContract;
 import android.text.TextUtils;
 import android.text.TextUtils;
 
 
 import com.evernote.android.job.Job;
 import com.evernote.android.job.Job;
@@ -142,6 +145,13 @@ public class AccountRemovalJob extends Job implements AccountManagerCallback<Boo
                 new RemoteWipeSuccessRemoteOperation(authToken).execute(client);
                 new RemoteWipeSuccessRemoteOperation(authToken).execute(client);
             }
             }
 
 
+            // notify Document Provider
+            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+                String authority = context.getResources().getString(R.string.document_provider_authority);
+                Uri rootsUri = DocumentsContract.buildRootsUri(authority);
+                context.getContentResolver().notifyChange(rootsUri, null);
+            }
+
             return Result.SUCCESS;
             return Result.SUCCESS;
         } else {
         } else {
             return Result.FAILURE;
             return Result.FAILURE;

+ 2 - 1
src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -125,6 +125,8 @@ public class DocumentsStorageProvider extends DocumentsProvider {
             return new FileCursor();
             return new FileCursor();
         }
         }
 
 
+        initiateStorageMap();
+
         final RootCursor result = new RootCursor(projection);
         final RootCursor result = new RootCursor(projection);
         for(int i = 0; i < rootIdToStorageManager.size(); i++) {
         for(int i = 0; i < rootIdToStorageManager.size(); i++) {
             result.addRoot(new Document(rootIdToStorageManager.valueAt(i), ROOT_PATH), getContext());
             result.addRoot(new Document(rootIdToStorageManager.valueAt(i), ROOT_PATH), getContext());
@@ -291,7 +293,6 @@ public class DocumentsStorageProvider extends DocumentsProvider {
     @Override
     @Override
     public boolean onCreate() {
     public boolean onCreate() {
         accountManager = UserAccountManagerImpl.fromContext(getContext());
         accountManager = UserAccountManagerImpl.fromContext(getContext());
-        initiateStorageMap();
         return true;
         return true;
     }
     }