Support root ejection

Provides a control to unmount shares pinned to the left pane of the
Files App.

This fixes #3.
This commit is contained in:
rthakohov 2017-08-18 14:30:37 -07:00
parent 5b32f0dc18
commit fb00658664
4 changed files with 23 additions and 6 deletions

View file

@ -653,6 +653,8 @@ void Java_com_google_android_sambadocumentsprovider_nativefacade_NativeCredentia
}
SambaClient::CredentialCache *cache =
reinterpret_cast<SambaClient::CredentialCache *>(pointer);
cache->remove(uri);
}
void Java_com_google_android_sambadocumentsprovider_SambaConfiguration_setEnv(

View file

@ -77,15 +77,16 @@ public class ShareManager implements Iterable<String> {
final Map<String, ShareTuple> shareMap = new HashMap<>(serverStringSet.size());
final List<String> forceEncryption = new ArrayList<>();
for (String serverString : serverStringSet) {
String decryptedString = serverString;
try {
serverString = mEncryptionManager.decrypt(serverString);
decryptedString = mEncryptionManager.decrypt(serverString);
} catch (EncryptionException e) {
Log.i(TAG, "Failed to decrypt server data: ", e);
forceEncryption.add(serverString);
}
String uri = decode(serverString, shareMap);
String uri = decode(decryptedString, shareMap);
if (uri != null) {
mServerStringMap.put(uri, serverString);
}
@ -152,8 +153,10 @@ public class ShareManager implements Iterable<String> {
throw new IllegalStateException("Failed to encode credential tuple.");
}
String encryptedString;
try {
mServerStringSet.add(mEncryptionManager.encrypt(serverString));
encryptedString = mEncryptionManager.encrypt(serverString);
mServerStringSet.add(encryptedString);
} catch (EncryptionException e) {
throw new IllegalStateException("Failed to encrypt server data", e);
}
@ -164,7 +167,7 @@ public class ShareManager implements Iterable<String> {
mMountedServerSet.remove(uri);
}
mPref.edit().putStringSet(SERVER_STRING_SET_KEY, mServerStringSet).apply();
mServerStringMap.put(uri, serverString);
mServerStringMap.put(uri, encryptedString);
if (shouldNotify) {
notifyServerChange();
@ -215,6 +218,9 @@ public class ShareManager implements Iterable<String> {
}
mServerStringMap.remove(uri);
mMountedServerSet.remove(uri);
mPref.edit().putStringSet(SERVER_STRING_SET_KEY, mServerStringSet).apply();
mCredentialCache.removeCredential(uri);

View file

@ -18,8 +18,8 @@
package com.google.android.sambadocumentsprovider.cache;
import android.net.Uri;
import com.google.android.sambadocumentsprovider.document.DocumentMetadata;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

View file

@ -220,7 +220,7 @@ public class SambaDocumentsProvider extends DocumentsProvider {
toRootId(metadata),
toDocumentId(parsedUri),
name,
Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD,
Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD | Root.FLAG_SUPPORTS_EJECT,
R.drawable.ic_folder_shared
});
}
@ -229,6 +229,15 @@ public class SambaDocumentsProvider extends DocumentsProvider {
return cursor;
}
@Override
public void ejectRoot(String rootId) {
if (BuildConfig.DEBUG) Log.d(TAG, "Ejecting root: " + rootId);
if (!mShareManager.unmountServer(rootId)) {
throw new IllegalStateException("Failed to eject root: " + rootId);
}
}
@Override
public boolean isChildDocument(String parentDocumentId, String documentId) {
final String parentUri = toUriString(parentDocumentId);