Improvements to GDrive implementation, started integration with KP2A app (file chooser not yet working)

This commit is contained in:
Philipp Crocoll
2013-10-25 04:05:37 +02:00
parent ea89a40330
commit e3b18b88b3
18 changed files with 1886 additions and 4512 deletions

View File

@@ -32,6 +32,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="GooglePlayServicesFroyoLib">
<HintPath>..\Components\googleplayservicesfroyo-9.0\lib\android\GooglePlayServicesFroyoLib.dll</HintPath>
</Reference>
<Reference Include="Mono.Android" /> <Reference Include="Mono.Android" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@@ -63,14 +66,79 @@
<Link>Jars\dropbox-android-sdk-1.5.4.jar</Link> <Link>Jars\dropbox-android-sdk-1.5.4.jar</Link>
</EmbeddedReferenceJar> </EmbeddedReferenceJar>
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\json_simple-1.1.jar">
<Link>Jars\json_simple-1.1.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-api-client-1.16.0-rc.jar">
<Link>Jars\google-api-client-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-api-client-android-1.16.0-rc.jar">
<Link>Jars\google-api-client-android-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-api-services-drive-v2-rev102-1.16.0-rc.jar">
<Link>Jars\google-api-services-drive-v2-rev102-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-http-client-1.16.0-rc.jar">
<Link>Jars\google-http-client-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-http-client-android-1.16.0-rc.jar">
<Link>Jars\google-http-client-android-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-http-client-gson-1.16.0-rc.jar">
<Link>Jars\google-http-client-gson-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-http-client-jackson-1.16.0-rc.jar">
<Link>Jars\google-http-client-jackson-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-http-client-jackson2-1.16.0-rc.jar">
<Link>Jars\google-http-client-jackson2-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\google-oauth-client-1.16.0-rc.jar">
<Link>Jars\google-oauth-client-1.16.0-rc.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\gson-2.1.jar">
<Link>Jars\gson-2.1.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\httpmime-4.0.3.jar"> <EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\httpmime-4.0.3.jar">
<Link>Jars\httpmime-4.0.3.jar</Link> <Link>Jars\httpmime-4.0.3.jar</Link>
</EmbeddedReferenceJar> </EmbeddedReferenceJar>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\json_simple-1.1.jar"> <EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\jackson-core-2.1.3.jar">
<Link>Jars\json_simple-1.1.jar</Link> <Link>Jars\jackson-core-2.1.3.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\jackson-core-asl-1.9.11.jar">
<Link>Jars\jackson-core-asl-1.9.11.jar</Link>
</EmbeddedReferenceJar>
</ItemGroup>
<ItemGroup>
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\jsr305-1.3.9.jar">
<Link>Jars\jsr305-1.3.9.jar</Link>
</EmbeddedReferenceJar> </EmbeddedReferenceJar>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.Bindings.targets" /> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.Bindings.targets" />

View File

@@ -20,7 +20,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>False</Optimize> <Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath> <OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_KEYTRANSFORM;INCLUDE_FILECHOOSER;INCLUDE_JAVAFILESTORAGE</DefineConstants> <DefineConstants>DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_KEYTRANSFORM;EXCLUDE_FILECHOOSER;EXCLUDE_JAVAFILESTORAGE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause> <ConsolePause>False</ConsolePause>

View File

@@ -129,7 +129,7 @@ namespace keepass2android.Io
return (!ioc.IsLocalFile()) && (ioc.CredSaveMode != IOCredSaveMode.SaveCred); return (!ioc.IsLocalFile()) && (ioc.CredSaveMode != IOCredSaveMode.SaveCred);
} }
public void CreateDirectory(IOConnectionInfo ioc) public void CreateDirectory(IOConnectionInfo ioc, string newDirName)
{ {
//TODO //TODO
throw new NotImplementedException(); throw new NotImplementedException();

View File

@@ -421,9 +421,9 @@ namespace keepass2android.Io
return _cachedStorage.RequiresCredentials(ioc); return _cachedStorage.RequiresCredentials(ioc);
} }
public void CreateDirectory(IOConnectionInfo ioc) public void CreateDirectory(IOConnectionInfo ioc, string newDirName)
{ {
_cachedStorage.CreateDirectory(ioc); _cachedStorage.CreateDirectory(ioc, newDirName);
} }
public IEnumerable<FileDescription> ListContents(IOConnectionInfo ioc) public IEnumerable<FileDescription> ListContents(IOConnectionInfo ioc)

View File

@@ -10,5 +10,7 @@ namespace keepass2android.Io
public bool CanRead { get; set; } public bool CanRead { get; set; }
public bool CanWrite { get; set; } public bool CanWrite { get; set; }
public long SizeInBytes { get; set; } public long SizeInBytes { get; set; }
public String DisplayName { get; set; }
} }
} }

View File

@@ -14,68 +14,13 @@ using KeePassLib.Serialization;
namespace keepass2android.Io namespace keepass2android.Io
{ {
/*public class GDriveFileStorage: IFileStorage public class GoogleDriveFileStorage : JavaFileStorage
{ {
public IEnumerable<string> SupportedProtocols { get { yield return "gdrive"; } } public GoogleDriveFileStorage(Context ctx, IKp2aApp app) :
public void Delete(IOConnectionInfo ioc) base(new Keepass2android.Javafilestorage.GoogleDriveFileStorage(), app)
{ {
throw new NotImplementedException();
}
public bool CheckForFileChangeFast(IOConnectionInfo ioc, string previousFileVersion)
{
throw new NotImplementedException();
}
public string GetCurrentFileVersionFast(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
public Stream OpenFileForRead(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
public IWriteTransaction OpenWriteTransaction(IOConnectionInfo ioc, bool useFileTransaction)
{
throw new NotImplementedException();
} }
public bool CompleteIoId() }
{
throw new NotImplementedException();
}
public bool? FileExists()
{
throw new NotImplementedException();
}
public string GetFilenameWithoutPathAndExt(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
public bool RequiresCredentials(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
public void CreateDirectory(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
public IEnumerable<FileDescription> ListContents(IOConnectionInfo convertPathToIoc)
{
throw new NotImplementedException();
}
public FileDescription GetFileDescription(IOConnectionInfo ioc)
{
throw new NotImplementedException();
}
}*/
} }

View File

@@ -105,7 +105,7 @@ namespace keepass2android.Io
/// <summary> /// <summary>
/// Creates the directory described by ioc /// Creates the directory described by ioc
/// </summary> /// </summary>
void CreateDirectory(IOConnectionInfo ioc); void CreateDirectory(IOConnectionInfo ioc, string newDirName);
/// <summary> /// <summary>
/// Lists the contents of the given path /// Lists the contents of the given path

View File

@@ -172,11 +172,11 @@ namespace keepass2android.Io
return false; return false;
} }
public void CreateDirectory(IOConnectionInfo ioc) public void CreateDirectory(IOConnectionInfo ioc, string newDirName)
{ {
try try
{ {
Jfs.CreateFolder(IocToPath(ioc)); Jfs.CreateFolder(IocToPath(ioc), newDirName);
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
@@ -213,6 +213,7 @@ namespace keepass2android.Io
{ {
CanRead = e.CanRead, CanRead = e.CanRead,
CanWrite = e.CanWrite, CanWrite = e.CanWrite,
DisplayName = e.DisplayName,
IsDirectory = e.IsDirectory, IsDirectory = e.IsDirectory,
LastModified = JavaTimeToCSharp(e.LastModifiedTime), LastModified = JavaTimeToCSharp(e.LastModifiedTime),
Path = e.Path, Path = e.Path,

View File

@@ -20,7 +20,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath> <OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_KEYTRANSFORM;INCLUDE_FILECHOOSER;INCLUDE_JAVAFILESTORAGE</DefineConstants> <DefineConstants>TRACE;DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_KEYTRANSFORM;EXCLUDE_FILECHOOSER;EXCLUDE_JAVAFILESTORAGE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>

View File

@@ -31,6 +31,7 @@ import com.google.api.services.drive.model.FileList;
import com.google.api.services.drive.model.ParentReference; import com.google.api.services.drive.model.ParentReference;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.accounts.AccountsException;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
@@ -285,9 +286,28 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
private File getFileForPath(GDrivePath path, Drive driveService) private File getFileForPath(GDrivePath path, Drive driveService)
throws IOException, InvalidPathException { throws IOException, InvalidPathException {
Log.d(TAG,"getFileForPath... ");
try
{
//throw new IOException("argh");
String driveId = path.getGDriveId();
Log.d(TAG, "id"+driveId);
File file = driveService.files().get(driveId).execute();
Log.d(TAG,"...done.");
return file;
}
catch (IOException e)
{
e.printStackTrace();
throw e;
}
catch (InvalidPathException e)
{
e.printStackTrace();
throw e;
}
File file = driveService.files().get(path.getGDriveId()).execute();
return file;
} }
private InputStream getFileContent(File driveFile, Drive driveService) throws IOException { private InputStream getFileContent(File driveFile, Drive driveService) throws IOException {
@@ -425,6 +445,12 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
} }
private Exception convertException(Exception e) { private Exception convertException(Exception e) {
if (UserRecoverableAuthIOException.class.isAssignableFrom(e.getClass()))
{
UserRecoverableAuthIOException ure = (UserRecoverableAuthIOException) e;
//this is not really nice because it removes data from the cache which might still be valid but we don't have the account name here...
mAccountData.clear();
}
if (GoogleJsonResponseException.class.isAssignableFrom(e.getClass()) ) if (GoogleJsonResponseException.class.isAssignableFrom(e.getClass()) )
{ {
GoogleJsonResponseException jsonEx = (GoogleJsonResponseException)e; GoogleJsonResponseException jsonEx = (GoogleJsonResponseException)e;
@@ -462,13 +488,17 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
try try
{ {
Log.d(TAG, "getFileEntry "+filename);
GDrivePath gdrivePath = new GDrivePath(filename); GDrivePath gdrivePath = new GDrivePath(filename);
return convertToFileEntry( FileEntry res = convertToFileEntry(
getFileForPath(gdrivePath, getDriveService(gdrivePath.getAccount())), getFileForPath(gdrivePath, getDriveService(gdrivePath.getAccount())),
filename); filename);
Log.d(TAG, "getFileEntry res"+res);
return res;
} }
catch (Exception e) catch (Exception e)
{ {
Log.d(TAG, "Exception in getFileEntry! "+e);
throw convertException(e); throw convertException(e);
} }
} }
@@ -501,7 +531,9 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
private Drive getDriveService(String accountName) private Drive getDriveService(String accountName)
{ {
Log.d(TAG, "getDriveService "+accountName);
AccountData accountData = mAccountData.get(accountName); AccountData accountData = mAccountData.get(accountName);
Log.d(TAG, "accountData "+accountData);
return accountData.drive; return accountData.drive;
} }
@@ -514,24 +546,9 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) { if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) {
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
if (accountName != null) { if (accountName != null) {
Log.d(TAG, "Account name="+accountName); Log.d(TAG, "Initialize Account name="+accountName);
//try initializeAccount(setupAct, accountName);
{
//listFolders("root", 0);
initializeAccount(setupAct, accountName);
//testAuthAndReturn(setupAct, accountName, activity, result);
} /*catch (UnsupportedEncodingException e) {
Log.e(TAG, "UnsupportedEncodingException: "+e.toString());
Intent retData = new Intent();
retData.putExtra(EXTRA_ERROR_MESSAGE, e.getMessage());
((Activity)activity).setResult(Activity.RESULT_CANCELED, retData);
((Activity)activity).finish();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
return; return;
} }
} }
@@ -568,61 +585,6 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
} }
/* private void testAuthAndReturn(
final JavaFileStorage.FileStorageSetupActivity setupAct,
String accountName, final Activity activity, final boolean[] result)
throws UnsupportedEncodingException {
setupAct.getState().putString(EXTRA_PATH, getProtocolId()+"://"+URLEncoder.encode(accountName, "ISO-8859-1")+"/");
Thread thread = new Thread() {
@Override
public void run() {
//try to list files:
//todo: is there a simpler way to test if the user is authorized?
try
{
Log.d(TAG,"get files");
Files.List request = getDriveService(accountName, activity).files().list();
Log.d(TAG,"get files exec");
request.execute();
Log.d(TAG,"ok!");
result[0] = true;
}
catch (UserRecoverableAuthIOException e) {
Log.d(TAG,"UserRecoverableAuthIOException ");
activity.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
}
catch (Throwable t)
{
Log.d(TAG, "Exception: " +t.getMessage());
t.printStackTrace();
Intent data = new Intent();
data.putExtra(EXTRA_ERROR_MESSAGE, t.getMessage());
activity.setResult(Activity.RESULT_CANCELED, data);
activity.finish();
}
}// run()
};
thread.start();
try {
thread.join();
if (result[0])
{
finishActivityWithSuccess(setupAct);
}
} catch (InterruptedException e) {
Intent retData = new Intent();
retData.putExtra(EXTRA_ERROR_MESSAGE, e.getMessage());
activity.setResult(Activity.RESULT_CANCELED, retData);
activity.finish();
}
}
*/
private void initializeAccount(final JavaFileStorage.FileStorageSetupActivity setupAct, final String accountName) { private void initializeAccount(final JavaFileStorage.FileStorageSetupActivity setupAct, final String accountName) {
final Activity activity = ((Activity)setupAct); final Activity activity = ((Activity)setupAct);
@@ -633,17 +595,21 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
@Override @Override
protected AsyncTaskResult<String> doInBackground(Object... arg0) { protected AsyncTaskResult<String> doInBackground(Object... arg0) {
try { try {
AccountData newAccountData = new AccountData(); if (!mAccountData.containsKey(accountName))
newAccountData.drive = createDriveService(accountName, activity); {
mAccountData.put(accountName, newAccountData); AccountData newAccountData = new AccountData();
Log.d(TAG, "Added account data for " + accountName); newAccountData.drive = createDriveService(accountName, activity);
newAccountData.mFolderCache = buildFoldersCache(accountName); mAccountData.put(accountName, newAccountData);
Log.d(TAG, "Added account data for " + accountName);
newAccountData.mFolderCache = buildFoldersCache(accountName);
About about = newAccountData.drive.about().get().execute(); About about = newAccountData.drive.about().get().execute();
newAccountData.mRootFolderId = about.getRootFolderId(); newAccountData.mRootFolderId = about.getRootFolderId();
}
if (setupAct.getProcessName().equals(PROCESS_NAME_SELECTFILE))
setupAct.getState().putString(EXTRA_PATH, getRootPathForAccount(accountName));
setupAct.getState().putString(EXTRA_PATH, getRootPathForAccount(accountName));
return new AsyncTaskResult<String>("ok"); return new AsyncTaskResult<String>("ok");
} catch ( Exception anyError) { } catch ( Exception anyError) {
return new AsyncTaskResult<String>(anyError); return new AsyncTaskResult<String>(anyError);
@@ -660,6 +626,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
if (error != null ) { if (error != null ) {
if (UserRecoverableAuthIOException.class.isAssignableFrom(error.getClass())) if (UserRecoverableAuthIOException.class.isAssignableFrom(error.getClass()))
{ {
mAccountData.remove(accountName);
activity.startActivityForResult(((UserRecoverableAuthIOException)error).getIntent(), REQUEST_AUTHORIZATION); activity.startActivityForResult(((UserRecoverableAuthIOException)error).getIntent(), REQUEST_AUTHORIZATION);
} }
else else
@@ -696,12 +663,12 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
private HashMap<String,FileSystemEntryData> buildFoldersCache(String accountName) throws IOException { private HashMap<String,FileSystemEntryData> buildFoldersCache(String accountName) throws IOException {
HashMap<String, FileSystemEntryData> folderCache = new HashMap<String, GoogleDriveFileStorage.FileSystemEntryData>(); HashMap<String, FileSystemEntryData> folderCache = new HashMap<String, GoogleDriveFileStorage.FileSystemEntryData>();
Log.d(TAG,"buildFoldersCache");
FileList folders=getDriveService(accountName).files().list().setQ("mimeType='"+FOLDER_MIME_TYPE+"' and trashed=false and hidden=false") FileList folders=getDriveService(accountName).files().list().setQ("mimeType='"+FOLDER_MIME_TYPE+"' and trashed=false and hidden=false")
.setFields("items(id,title,parents),nextPageToken") .setFields("items(id,title,parents),nextPageToken")
.execute(); .execute();
for(File fl: folders.getItems()){ for(File fl: folders.getItems()){
Log.d(TAG,"buildFoldersCache: " + fl.getTitle());
FileSystemEntryData thisFolder = new FileSystemEntryData(); FileSystemEntryData thisFolder = new FileSystemEntryData();
thisFolder.id = fl.getId(); thisFolder.id = fl.getId();
thisFolder.displayName = fl.getTitle(); thisFolder.displayName = fl.getTitle();
@@ -713,6 +680,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
folderCache.put(thisFolder.id, thisFolder); folderCache.put(thisFolder.id, thisFolder);
} }
Log.d(TAG,"that's it!");
return folderCache; return folderCache;
} }
@@ -733,9 +701,19 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
if (setupActivity.getProcessName().equals(PROCESS_NAME_SELECTFILE)) if (setupActivity.getProcessName().equals(PROCESS_NAME_SELECTFILE))
{ {
Intent data = new Intent(); Intent data = new Intent();
Log.d(TAG,setupActivity.getState().getString(EXTRA_PATH)); if (setupActivity == (null))
Log.d(TAG, "setupActivity is null");
else
if (setupActivity.getState() == null)
Log.d(TAG, "getState is null");
else
if (setupActivity.getState().getString(EXTRA_PATH) == null)
Log.d(TAG, "setupActivity.getState().getString(EXTRA_PATH) is null");
else
Log.d(TAG,setupActivity.getState().getString(EXTRA_PATH));
String path = setupActivity.getState().getString(EXTRA_PATH); String path = setupActivity.getState().getString(EXTRA_PATH);
data.putExtra(EXTRA_PATH, path); if (path != null)
data.putExtra(EXTRA_PATH, path);
activity.setResult(RESULT_FILECHOOSER_PREPARED, data); activity.setResult(RESULT_FILECHOOSER_PREPARED, data);
activity.finish(); activity.finish();
return; return;
@@ -785,52 +763,28 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
if (PROCESS_NAME_FILE_USAGE_SETUP.equals(setupAct.getProcessName())) if (PROCESS_NAME_FILE_USAGE_SETUP.equals(setupAct.getProcessName()))
{ {
/*TODO
GoogleAccountCredential credential = createCredential(activity); GoogleAccountCredential credential = createCredential(activity);
final GDrivePath path;
String storedAccountName = PreferenceManager.getDefaultSharedPreferences(activity).getString("GDRIVE_ACCOUNT_NAME", null); try
if (storedAccountName != null)
{ {
credential.setSelectedAccountName(storedAccountName); path = new GDrivePath(setupAct.getPath());
Thread thread = new Thread() {
@Override
public void run() {
Activity activity = (Activity)setupAct;
//try to list files:
//todo: is there a simpler way to test if the user is authorized?
try
{
service.files().list().execute();
}
catch (UserRecoverableAuthIOException e) {
activity.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
}
catch (Throwable t)
{
Intent data = new Intent();
data.putExtra(EXTRA_ERROR_MESSAGE, t.getMessage());
activity.setResult(Activity.RESULT_CANCELED, data);
activity.finish();
}
}// run()
};
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
Intent data = new Intent();
data.putExtra(EXTRA_ERROR_MESSAGE, e.getMessage());
activity.setResult(Activity.RESULT_CANCELED, data);
activity.finish();
}
} }
*/ catch (Exception e)
{
Intent data = new Intent();
data.putExtra(EXTRA_ERROR_MESSAGE, e.getMessage());
activity.setResult(Activity.RESULT_CANCELED, data);
activity.finish();
return;
}
if (path.getAccount() != null)
{
credential.setSelectedAccountName(path.getAccount());
initializeAccount(setupAct, path.getAccount());
}
} }
} }

View File

@@ -3,6 +3,7 @@ package keepass2android.kp2afilechooser;
public class FileEntry { public class FileEntry {
public String path; public String path;
public String displayName;
public boolean isDirectory; public boolean isDirectory;
public long lastModifiedTime; public long lastModifiedTime;
public boolean canRead; public boolean canRead;

View File

@@ -268,8 +268,7 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
return null; return null;
} }
String fname = getFilenameFromPath(parentPath); FileEntry e = this.getFileEntryCached(parentPath);
matrixCursor = BaseFileProviderUtils.newBaseFileCursor(); matrixCursor = BaseFileProviderUtils.newBaseFileCursor();
@@ -284,14 +283,14 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
getAuthority()) getAuthority())
.buildUpon().appendPath(parentPath) .buildUpon().appendPath(parentPath)
.build().toString()); .build().toString());
newRow.add(parentPath); newRow.add(e.path);
newRow.add(fname); newRow.add(e.displayName);
newRow.add(true); //can read newRow.add(e.canRead); //can read
newRow.add(true); //can write newRow.add(e.canWrite); //can write
newRow.add(0); newRow.add(0);
newRow.add(type); newRow.add(type);
newRow.add(0); newRow.add(0);
newRow.add(FileUtils.getResIcon(type, fname)); newRow.add(FileUtils.getResIcon(type, e.displayName));
return matrixCursor; return matrixCursor;
} }
@@ -312,14 +311,7 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
return matrixCursor; return matrixCursor;
}// doAnswerApiCommand() }// doAnswerApiCommand()
protected String getFilenameFromPath(String path) {
path = removeTrailingSlash(path);
int lastSlashPos = path.lastIndexOf("/");
//if path is root, return its name. empty is ok
if (lastSlashPos == -1)
return path;
return path.substring(lastSlashPos+1);
}
/* /*
private String addProtocol(String path) { private String addProtocol(String path) {
if (path == null) if (path == null)
@@ -418,9 +410,10 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
Boolean.toString(hasMoreFiles[0])).build() Boolean.toString(hasMoreFiles[0])).build()
.toString()); .toString());
newRow.add(dirName); newRow.add(dirName);
newRow.add(getFilenameFromPath(dirName)); String displayName = getFileEntryCached(dirName).displayName;
newRow.add(displayName);
Log.d(CLASSNAME, "Returning name " + getFilenameFromPath(dirName)+" for " +dirName); Log.d(CLASSNAME, "Returning name " + displayName+" for " +dirName);
} }
} }
@@ -455,7 +448,9 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
.buildUpon().appendPath(f.path) .buildUpon().appendPath(f.path)
.build().toString()); .build().toString());
newRow.add(f.path); newRow.add(f.path);
newRow.add(getFilenameFromPath(f.path)); if (f.displayName == null)
Log.w("KP2AJ", "displayName is null for " + f.path);
newRow.add(f.displayName);
newRow.add(f.canRead ? 1 : 0); newRow.add(f.canRead ? 1 : 0);
newRow.add(f.canWrite ? 1 : 0); newRow.add(f.canWrite ? 1 : 0);
newRow.add(f.sizeInBytes); newRow.add(f.sizeInBytes);
@@ -464,7 +459,7 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
newRow.add(f.lastModifiedTime); newRow.add(f.lastModifiedTime);
else else
newRow.add(null); newRow.add(null);
newRow.add(FileUtils.getResIcon(type, getFilenameFromPath(f.path))); newRow.add(FileUtils.getResIcon(type, f.displayName));
return newRow; return newRow;
} }
@@ -563,13 +558,13 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
.buildUpon().appendPath(filename) .buildUpon().appendPath(filename)
.build().toString()); .build().toString());
newRow.add(filename); newRow.add(filename);
newRow.add(getFilenameFromPath(filename)); newRow.add(filename);
newRow.add(0); newRow.add(0);
newRow.add(0); newRow.add(0);
newRow.add(0); newRow.add(0);
newRow.add(type); newRow.add(type);
newRow.add(null); newRow.add(null);
newRow.add(FileUtils.getResIcon(type, getFilenameFromPath(filename))); newRow.add(FileUtils.getResIcon(type, filename));
} }
/** /**

File diff suppressed because it is too large Load Diff

View File

@@ -356,8 +356,8 @@
<string name="ChangeLog_0_9"> <string name="ChangeLog_0_9">
<b>Version 0.9 preview 2</b>\n <b>Version 0.9</b>\n
* Integrated Dropbox support (read/write databases; Keepass2Android regular edition only)\n * Integrated Dropbox and Google Drive support (read/write databases; Keepass2Android regular edition only)\n
* Integrated custom file browser (based on android-filechooser by HBA)\n * Integrated custom file browser (based on android-filechooser by HBA)\n
* Improved user interface for creating new databases\n * Improved user interface for creating new databases\n
* Included custom font DejaVu Sans Mono for displaying passwords\n * Included custom font DejaVu Sans Mono for displaying passwords\n

View File

@@ -392,6 +392,7 @@ namespace keepass2android
{ {
#if !EXCLUDE_JAVAFILESTORAGE #if !EXCLUDE_JAVAFILESTORAGE
new DropboxFileStorage(Application.Context, this), new DropboxFileStorage(Application.Context, this),
new GoogleDriveFileStorage(Application.Context, this),
#endif #endif
new BuiltInFileStorage() new BuiltInFileStorage()
}; };

View File

@@ -33,8 +33,7 @@ namespace keepass2android
try try
{ {
parentDirectory = parentDirectory.TrimEnd('/'); App.Kp2a.GetFileStorage(parentDirectory).CreateDirectory(ConvertPathToIoc(parentDirectory), newDirName);
App.Kp2a.GetFileStorage(parentDirectory).CreateDirectory(ConvertPathToIoc(parentDirectory + "/" + newDirName));
return true; return true;
} }
catch (Exception e) catch (Exception e)
@@ -103,6 +102,7 @@ namespace keepass2android
{ {
CanRead = e.CanRead, CanRead = e.CanRead,
CanWrite = e.CanWrite, CanWrite = e.CanWrite,
DisplayName = e.DisplayName,
IsDirectory = e.IsDirectory, IsDirectory = e.IsDirectory,
LastModifiedTime = CSharpTimeToJava(e.LastModified), LastModifiedTime = CSharpTimeToJava(e.LastModified),
Path = e.Path, Path = e.Path,

View File

@@ -20,6 +20,8 @@ namespace keepass2android.fileselect
,Keepass2android.Javafilestorage.IJavaFileStorageFileStorageSetupActivity ,Keepass2android.Javafilestorage.IJavaFileStorageFileStorageSetupActivity
#endif #endif
{ {
private bool isRecreated = false;
protected override void OnCreate(Bundle bundle) protected override void OnCreate(Bundle bundle)
{ {
base.OnCreate(bundle); base.OnCreate(bundle);
@@ -34,16 +36,21 @@ namespace keepass2android.fileselect
if (bundle == null) if (bundle == null)
State = new Bundle(); State = new Bundle();
else else
{
State = (Bundle) bundle.Clone(); State = (Bundle) bundle.Clone();
isRecreated = true;
}
App.Kp2a.GetFileStorage(Ioc).OnCreate(this, bundle); if (!isRecreated)
App.Kp2a.GetFileStorage(Ioc).OnCreate(this, bundle);
} }
protected override void OnStart() protected override void OnStart()
{ {
base.OnStart(); base.OnStart();
App.Kp2a.GetFileStorage(Ioc).OnStart(this); if (!isRecreated)
App.Kp2a.GetFileStorage(Ioc).OnStart(this);
} }
protected override void OnResume() protected override void OnResume()

View File

@@ -24,7 +24,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>False</Optimize> <Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath> <OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_KEYTRANSFORM;INCLUDE_FILECHOOSER;INCLUDE_JAVAFILESTORAGE</DefineConstants> <DefineConstants>DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;EXCLUDE_KEYTRANSFORM;EXCLUDE_FILECHOOSER;EXCLUDE_JAVAFILESTORAGE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause> <ConsolePause>False</ConsolePause>
@@ -71,6 +71,10 @@
<DeployExternal>True</DeployExternal> <DeployExternal>True</DeployExternal>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="GooglePlayServicesFroyoLib, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Components\googleplayservicesfroyo-9.0\lib\android\GooglePlayServicesFroyoLib.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@@ -666,15 +670,15 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\AndroidFileChooserBinding\AndroidFileChooserBinding.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_FILECHOOSER'))"> <ProjectReference Include="..\AndroidFileChooserBinding\AndroidFileChooserBinding.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_FILECHOOSER'))">
<Project>{3c0f7fe5-639f-4422-a087-8b26cf862d1b}</Project> <Project>{3C0F7FE5-639F-4422-A087-8B26CF862D1B}</Project>
<Name>AndroidFileChooserBinding</Name> <Name>AndroidFileChooserBinding</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\AppCompatV7Binding\AppCompatV7Binding.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_FILECHOOSER'))"> <ProjectReference Include="..\AppCompatV7Binding\AppCompatV7Binding.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_FILECHOOSER'))">
<Project>{23233a28-d74f-4bf8-b4d8-834060840bd7}</Project> <Project>{23233A28-D74F-4BF8-B4D8-834060840BD7}</Project>
<Name>AppCompatV7Binding</Name> <Name>AppCompatV7Binding</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\JavaFileStorageBindings\JavaFileStorageBindings.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_JAVAFILESTORAGE'))"> <ProjectReference Include="..\JavaFileStorageBindings\JavaFileStorageBindings.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_JAVAFILESTORAGE'))">
<Project>{48574278-4779-4b3a-a9e4-9cf1bc285d0b}</Project> <Project>{48574278-4779-4B3A-A9E4-9CF1BC285D0B}</Project>
<Name>JavaFileStorageBindings</Name> <Name>JavaFileStorageBindings</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\KeePassLib2Android\KeePassLib2Android.csproj"> <ProjectReference Include="..\KeePassLib2Android\KeePassLib2Android.csproj">
@@ -682,7 +686,7 @@
<Name>KeePassLib2Android</Name> <Name>KeePassLib2Android</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Kp2aBusinessLogic\Kp2aBusinessLogic.csproj"> <ProjectReference Include="..\Kp2aBusinessLogic\Kp2aBusinessLogic.csproj">
<Project>{53a9cb7f-6553-4bc0-b56b-9410bb2e59aa}</Project> <Project>{53A9CB7F-6553-4BC0-B56B-9410BB2E59AA}</Project>
<Name>Kp2aBusinessLogic</Name> <Name>Kp2aBusinessLogic</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\kp2akeytransform\kp2akeytransform.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_KEYTRANSFORM'))"> <ProjectReference Include="..\kp2akeytransform\kp2akeytransform.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_KEYTRANSFORM'))">
@@ -694,7 +698,7 @@
<Name>Kp2aKeyboardBinding</Name> <Name>Kp2aKeyboardBinding</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\TwofishCipher\TwofishCipher.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_TWOFISH'))"> <ProjectReference Include="..\TwofishCipher\TwofishCipher.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_TWOFISH'))">
<Project>{5cf675a5-9bee-4720-bed9-d5bf14a2ebf9}</Project> <Project>{5CF675A5-9BEE-4720-BED9-D5BF14A2EBF9}</Project>
<Name>TwofishCipher</Name> <Name>TwofishCipher</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
@@ -856,4 +860,13 @@
<ItemGroup> <ItemGroup>
<AndroidResource Include="Resources\layout\text_with_help.xml" /> <AndroidResource Include="Resources\layout\text_with_help.xml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<XamarinComponentReference Include="googleplayservicesfroyo">
<Version>9.0</Version>
<Visible>False</Visible>
</XamarinComponentReference>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout-v14\text_with_help.xml" />
</ItemGroup>
</Project> </Project>