mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-12-23 07:28:48 -05:00
Improvements to GDrive implementation, started integration with KP2A app (file chooser not yet working)
This commit is contained in:
parent
ea89a40330
commit
e3b18b88b3
@ -32,6 +32,9 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="GooglePlayServicesFroyoLib">
|
||||
<HintPath>..\Components\googleplayservicesfroyo-9.0\lib\android\GooglePlayServicesFroyoLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Android" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@ -63,14 +66,79 @@
|
||||
<Link>Jars\dropbox-android-sdk-1.5.4.jar</Link>
|
||||
</EmbeddedReferenceJar>
|
||||
</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>
|
||||
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\httpmime-4.0.3.jar">
|
||||
<Link>Jars\httpmime-4.0.3.jar</Link>
|
||||
</EmbeddedReferenceJar>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\json_simple-1.1.jar">
|
||||
<Link>Jars\json_simple-1.1.jar</Link>
|
||||
<EmbeddedReferenceJar Include="..\java\JavaFileStorage\libs\jackson-core-2.1.3.jar">
|
||||
<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>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.Bindings.targets" />
|
||||
|
@ -20,7 +20,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<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>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>False</ConsolePause>
|
||||
|
@ -129,7 +129,7 @@ namespace keepass2android.Io
|
||||
return (!ioc.IsLocalFile()) && (ioc.CredSaveMode != IOCredSaveMode.SaveCred);
|
||||
}
|
||||
|
||||
public void CreateDirectory(IOConnectionInfo ioc)
|
||||
public void CreateDirectory(IOConnectionInfo ioc, string newDirName)
|
||||
{
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
|
@ -421,9 +421,9 @@ namespace keepass2android.Io
|
||||
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)
|
||||
|
@ -10,5 +10,7 @@ namespace keepass2android.Io
|
||||
public bool CanRead { get; set; }
|
||||
public bool CanWrite { get; set; }
|
||||
public long SizeInBytes { get; set; }
|
||||
|
||||
public String DisplayName { get; set; }
|
||||
}
|
||||
}
|
@ -14,68 +14,13 @@ using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android.Io
|
||||
{
|
||||
/*public class GDriveFileStorage: IFileStorage
|
||||
public class GoogleDriveFileStorage : JavaFileStorage
|
||||
{
|
||||
public IEnumerable<string> SupportedProtocols { get { yield return "gdrive"; } }
|
||||
public void Delete(IOConnectionInfo ioc)
|
||||
public GoogleDriveFileStorage(Context ctx, IKp2aApp app) :
|
||||
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();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
@ -105,7 +105,7 @@ namespace keepass2android.Io
|
||||
/// <summary>
|
||||
/// Creates the directory described by ioc
|
||||
/// </summary>
|
||||
void CreateDirectory(IOConnectionInfo ioc);
|
||||
void CreateDirectory(IOConnectionInfo ioc, string newDirName);
|
||||
|
||||
/// <summary>
|
||||
/// Lists the contents of the given path
|
||||
|
@ -172,11 +172,11 @@ namespace keepass2android.Io
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CreateDirectory(IOConnectionInfo ioc)
|
||||
public void CreateDirectory(IOConnectionInfo ioc, string newDirName)
|
||||
{
|
||||
try
|
||||
{
|
||||
Jfs.CreateFolder(IocToPath(ioc));
|
||||
Jfs.CreateFolder(IocToPath(ioc), newDirName);
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
@ -213,6 +213,7 @@ namespace keepass2android.Io
|
||||
{
|
||||
CanRead = e.CanRead,
|
||||
CanWrite = e.CanWrite,
|
||||
DisplayName = e.DisplayName,
|
||||
IsDirectory = e.IsDirectory,
|
||||
LastModified = JavaTimeToCSharp(e.LastModifiedTime),
|
||||
Path = e.Path,
|
||||
|
@ -20,7 +20,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<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>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
|
@ -31,6 +31,7 @@ import com.google.api.services.drive.model.FileList;
|
||||
import com.google.api.services.drive.model.ParentReference;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountsException;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
@ -285,9 +286,28 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
|
||||
private File getFileForPath(GDrivePath path, Drive driveService)
|
||||
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 {
|
||||
@ -425,6 +445,12 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
}
|
||||
|
||||
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()) )
|
||||
{
|
||||
GoogleJsonResponseException jsonEx = (GoogleJsonResponseException)e;
|
||||
@ -462,13 +488,17 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
|
||||
try
|
||||
{
|
||||
Log.d(TAG, "getFileEntry "+filename);
|
||||
GDrivePath gdrivePath = new GDrivePath(filename);
|
||||
return convertToFileEntry(
|
||||
FileEntry res = convertToFileEntry(
|
||||
getFileForPath(gdrivePath, getDriveService(gdrivePath.getAccount())),
|
||||
filename);
|
||||
Log.d(TAG, "getFileEntry res"+res);
|
||||
return res;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.d(TAG, "Exception in getFileEntry! "+e);
|
||||
throw convertException(e);
|
||||
}
|
||||
}
|
||||
@ -501,7 +531,9 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
|
||||
private Drive getDriveService(String accountName)
|
||||
{
|
||||
Log.d(TAG, "getDriveService "+accountName);
|
||||
AccountData accountData = mAccountData.get(accountName);
|
||||
Log.d(TAG, "accountData "+accountData);
|
||||
return accountData.drive;
|
||||
}
|
||||
|
||||
@ -514,24 +546,9 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) {
|
||||
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
||||
if (accountName != null) {
|
||||
Log.d(TAG, "Account name="+accountName);
|
||||
//try
|
||||
{
|
||||
//listFolders("root", 0);
|
||||
initializeAccount(setupAct, accountName);
|
||||
//testAuthAndReturn(setupAct, accountName, activity, result);
|
||||
Log.d(TAG, "Initialize Account name="+accountName);
|
||||
initializeAccount(setupAct, accountName);
|
||||
|
||||
|
||||
} /*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;
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
|
||||
final Activity activity = ((Activity)setupAct);
|
||||
@ -633,17 +595,21 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
@Override
|
||||
protected AsyncTaskResult<String> doInBackground(Object... arg0) {
|
||||
try {
|
||||
AccountData newAccountData = new AccountData();
|
||||
newAccountData.drive = createDriveService(accountName, activity);
|
||||
mAccountData.put(accountName, newAccountData);
|
||||
Log.d(TAG, "Added account data for " + accountName);
|
||||
newAccountData.mFolderCache = buildFoldersCache(accountName);
|
||||
if (!mAccountData.containsKey(accountName))
|
||||
{
|
||||
AccountData newAccountData = new AccountData();
|
||||
newAccountData.drive = createDriveService(accountName, activity);
|
||||
mAccountData.put(accountName, newAccountData);
|
||||
Log.d(TAG, "Added account data for " + accountName);
|
||||
newAccountData.mFolderCache = buildFoldersCache(accountName);
|
||||
|
||||
About about = newAccountData.drive.about().get().execute();
|
||||
newAccountData.mRootFolderId = about.getRootFolderId();
|
||||
}
|
||||
|
||||
About about = newAccountData.drive.about().get().execute();
|
||||
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");
|
||||
} catch ( Exception anyError) {
|
||||
return new AsyncTaskResult<String>(anyError);
|
||||
@ -660,6 +626,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
if (error != null ) {
|
||||
if (UserRecoverableAuthIOException.class.isAssignableFrom(error.getClass()))
|
||||
{
|
||||
mAccountData.remove(accountName);
|
||||
activity.startActivityForResult(((UserRecoverableAuthIOException)error).getIntent(), REQUEST_AUTHORIZATION);
|
||||
}
|
||||
else
|
||||
@ -696,12 +663,12 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
private HashMap<String,FileSystemEntryData> buildFoldersCache(String accountName) throws IOException {
|
||||
|
||||
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")
|
||||
.setFields("items(id,title,parents),nextPageToken")
|
||||
.execute();
|
||||
for(File fl: folders.getItems()){
|
||||
|
||||
Log.d(TAG,"buildFoldersCache: " + fl.getTitle());
|
||||
FileSystemEntryData thisFolder = new FileSystemEntryData();
|
||||
thisFolder.id = fl.getId();
|
||||
thisFolder.displayName = fl.getTitle();
|
||||
@ -713,6 +680,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
folderCache.put(thisFolder.id, thisFolder);
|
||||
}
|
||||
|
||||
Log.d(TAG,"that's it!");
|
||||
return folderCache;
|
||||
|
||||
}
|
||||
@ -733,9 +701,19 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
if (setupActivity.getProcessName().equals(PROCESS_NAME_SELECTFILE))
|
||||
{
|
||||
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);
|
||||
data.putExtra(EXTRA_PATH, path);
|
||||
if (path != null)
|
||||
data.putExtra(EXTRA_PATH, path);
|
||||
activity.setResult(RESULT_FILECHOOSER_PREPARED, data);
|
||||
activity.finish();
|
||||
return;
|
||||
@ -785,52 +763,28 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
||||
|
||||
if (PROCESS_NAME_FILE_USAGE_SETUP.equals(setupAct.getProcessName()))
|
||||
{
|
||||
/*TODO
|
||||
GoogleAccountCredential credential = createCredential(activity);
|
||||
|
||||
String storedAccountName = PreferenceManager.getDefaultSharedPreferences(activity).getString("GDRIVE_ACCOUNT_NAME", null);
|
||||
|
||||
if (storedAccountName != null)
|
||||
final GDrivePath path;
|
||||
try
|
||||
{
|
||||
credential.setSelectedAccountName(storedAccountName);
|
||||
|
||||
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();
|
||||
}
|
||||
path = new GDrivePath(setupAct.getPath());
|
||||
}
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package keepass2android.kp2afilechooser;
|
||||
|
||||
public class FileEntry {
|
||||
public String path;
|
||||
public String displayName;
|
||||
public boolean isDirectory;
|
||||
public long lastModifiedTime;
|
||||
public boolean canRead;
|
||||
|
@ -268,8 +268,7 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
String fname = getFilenameFromPath(parentPath);
|
||||
|
||||
FileEntry e = this.getFileEntryCached(parentPath);
|
||||
|
||||
matrixCursor = BaseFileProviderUtils.newBaseFileCursor();
|
||||
|
||||
@ -284,14 +283,14 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
|
||||
getAuthority())
|
||||
.buildUpon().appendPath(parentPath)
|
||||
.build().toString());
|
||||
newRow.add(parentPath);
|
||||
newRow.add(fname);
|
||||
newRow.add(true); //can read
|
||||
newRow.add(true); //can write
|
||||
newRow.add(e.path);
|
||||
newRow.add(e.displayName);
|
||||
newRow.add(e.canRead); //can read
|
||||
newRow.add(e.canWrite); //can write
|
||||
newRow.add(0);
|
||||
newRow.add(type);
|
||||
newRow.add(0);
|
||||
newRow.add(FileUtils.getResIcon(type, fname));
|
||||
newRow.add(FileUtils.getResIcon(type, e.displayName));
|
||||
return matrixCursor;
|
||||
}
|
||||
|
||||
@ -312,14 +311,7 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
|
||||
return matrixCursor;
|
||||
}// 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) {
|
||||
if (path == null)
|
||||
@ -418,9 +410,10 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
|
||||
Boolean.toString(hasMoreFiles[0])).build()
|
||||
.toString());
|
||||
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)
|
||||
.build().toString());
|
||||
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.canWrite ? 1 : 0);
|
||||
newRow.add(f.sizeInBytes);
|
||||
@ -464,7 +459,7 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
|
||||
newRow.add(f.lastModifiedTime);
|
||||
else
|
||||
newRow.add(null);
|
||||
newRow.add(FileUtils.getResIcon(type, getFilenameFromPath(f.path)));
|
||||
newRow.add(FileUtils.getResIcon(type, f.displayName));
|
||||
return newRow;
|
||||
}
|
||||
|
||||
@ -563,13 +558,13 @@ public abstract class Kp2aFileProvider extends BaseFileProvider {
|
||||
.buildUpon().appendPath(filename)
|
||||
.build().toString());
|
||||
newRow.add(filename);
|
||||
newRow.add(getFilenameFromPath(filename));
|
||||
newRow.add(filename);
|
||||
newRow.add(0);
|
||||
newRow.add(0);
|
||||
newRow.add(0);
|
||||
newRow.add(type);
|
||||
newRow.add(null);
|
||||
newRow.add(FileUtils.getResIcon(type, getFilenameFromPath(filename)));
|
||||
newRow.add(FileUtils.getResIcon(type, filename));
|
||||
}
|
||||
|
||||
/**
|
||||
|
5945
src/keepass2android/Resources/Resource.designer.cs
generated
5945
src/keepass2android/Resources/Resource.designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -356,8 +356,8 @@
|
||||
|
||||
|
||||
<string name="ChangeLog_0_9">
|
||||
<b>Version 0.9 preview 2</b>\n
|
||||
* Integrated Dropbox support (read/write databases; Keepass2Android regular edition only)\n
|
||||
<b>Version 0.9</b>\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
|
||||
* Improved user interface for creating new databases\n
|
||||
* Included custom font DejaVu Sans Mono for displaying passwords\n
|
||||
|
@ -392,6 +392,7 @@ namespace keepass2android
|
||||
{
|
||||
#if !EXCLUDE_JAVAFILESTORAGE
|
||||
new DropboxFileStorage(Application.Context, this),
|
||||
new GoogleDriveFileStorage(Application.Context, this),
|
||||
#endif
|
||||
new BuiltInFileStorage()
|
||||
};
|
||||
|
@ -33,8 +33,7 @@ namespace keepass2android
|
||||
|
||||
try
|
||||
{
|
||||
parentDirectory = parentDirectory.TrimEnd('/');
|
||||
App.Kp2a.GetFileStorage(parentDirectory).CreateDirectory(ConvertPathToIoc(parentDirectory + "/" + newDirName));
|
||||
App.Kp2a.GetFileStorage(parentDirectory).CreateDirectory(ConvertPathToIoc(parentDirectory), newDirName);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -103,6 +102,7 @@ namespace keepass2android
|
||||
{
|
||||
CanRead = e.CanRead,
|
||||
CanWrite = e.CanWrite,
|
||||
DisplayName = e.DisplayName,
|
||||
IsDirectory = e.IsDirectory,
|
||||
LastModifiedTime = CSharpTimeToJava(e.LastModified),
|
||||
Path = e.Path,
|
||||
|
@ -20,6 +20,8 @@ namespace keepass2android.fileselect
|
||||
,Keepass2android.Javafilestorage.IJavaFileStorageFileStorageSetupActivity
|
||||
#endif
|
||||
{
|
||||
private bool isRecreated = false;
|
||||
|
||||
protected override void OnCreate(Bundle bundle)
|
||||
{
|
||||
base.OnCreate(bundle);
|
||||
@ -34,16 +36,21 @@ namespace keepass2android.fileselect
|
||||
if (bundle == null)
|
||||
State = new Bundle();
|
||||
else
|
||||
{
|
||||
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()
|
||||
{
|
||||
base.OnStart();
|
||||
App.Kp2a.GetFileStorage(Ioc).OnStart(this);
|
||||
if (!isRecreated)
|
||||
App.Kp2a.GetFileStorage(Ioc).OnStart(this);
|
||||
}
|
||||
|
||||
protected override void OnResume()
|
||||
|
@ -24,7 +24,7 @@
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>False</Optimize>
|
||||
<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>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>False</ConsolePause>
|
||||
@ -71,6 +71,10 @@
|
||||
<DeployExternal>True</DeployExternal>
|
||||
</PropertyGroup>
|
||||
<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.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
@ -666,15 +670,15 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<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>
|
||||
</ProjectReference>
|
||||
<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>
|
||||
</ProjectReference>
|
||||
<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>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\KeePassLib2Android\KeePassLib2Android.csproj">
|
||||
@ -682,7 +686,7 @@
|
||||
<Name>KeePassLib2Android</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Kp2aBusinessLogic\Kp2aBusinessLogic.csproj">
|
||||
<Project>{53a9cb7f-6553-4bc0-b56b-9410bb2e59aa}</Project>
|
||||
<Project>{53A9CB7F-6553-4BC0-B56B-9410BB2E59AA}</Project>
|
||||
<Name>Kp2aBusinessLogic</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\kp2akeytransform\kp2akeytransform.csproj" Condition="!$(DefineConstants.Contains('EXCLUDE_KEYTRANSFORM'))">
|
||||
@ -694,7 +698,7 @@
|
||||
<Name>Kp2aKeyboardBinding</Name>
|
||||
</ProjectReference>
|
||||
<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>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
@ -856,4 +860,13 @@
|
||||
<ItemGroup>
|
||||
<AndroidResource Include="Resources\layout\text_with_help.xml" />
|
||||
</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>
|
Loading…
Reference in New Issue
Block a user