mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-12-23 23:38:50 -05:00
enabled more logging in GDriveFileStorage
This commit is contained in:
parent
7613af6c81
commit
5e7f489e76
@ -93,11 +93,11 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
|
|
||||||
public void setPathWithoutVerify(String path) throws UnsupportedEncodingException, InvalidPathException
|
public void setPathWithoutVerify(String path) throws UnsupportedEncodingException, InvalidPathException
|
||||||
{
|
{
|
||||||
//Log.d(TAG, "setPath: "+path);
|
logDebug("setPath: "+path);
|
||||||
mAccount = extractAccount(path);
|
mAccount = extractAccount(path);
|
||||||
mAccountLocalPath = path.substring(getProtocolPrefix().length()+encode(mAccount).length()+1);
|
mAccountLocalPath = path.substring(getProtocolPrefix().length()+encode(mAccount).length()+1);
|
||||||
//Log.d(TAG, " mAccount=" + mAccount);
|
logDebug(" mAccount=" + mAccount);
|
||||||
//Log.d(TAG, " mAccountLocalPath=" + mAccountLocalPath);
|
logDebug(" mAccountLocalPath=" + mAccountLocalPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GDrivePath(String parentPath, File fileToAppend) throws UnsupportedEncodingException, FileNotFoundException, IOException, InvalidPathException
|
public GDrivePath(String parentPath, File fileToAppend) throws UnsupportedEncodingException, FileNotFoundException, IOException, InvalidPathException
|
||||||
@ -144,13 +144,13 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
for (int i=0;i<parts.length;i++)
|
for (int i=0;i<parts.length;i++)
|
||||||
{
|
{
|
||||||
String part = parts[i];
|
String part = parts[i];
|
||||||
//Log.d(TAG, "parsing part " + part);
|
logDebug("parsing part " + part);
|
||||||
int indexOfSeparator = part.lastIndexOf(NAME_ID_SEP);
|
int indexOfSeparator = part.lastIndexOf(NAME_ID_SEP);
|
||||||
if (indexOfSeparator < 0)
|
if (indexOfSeparator < 0)
|
||||||
throw new FileNotFoundException("invalid path " + mAccountLocalPath);
|
throw new FileNotFoundException("invalid path " + mAccountLocalPath);
|
||||||
String id = part.substring(indexOfSeparator+NAME_ID_SEP.length());
|
String id = part.substring(indexOfSeparator+NAME_ID_SEP.length());
|
||||||
String name = decode(part.substring(0, indexOfSeparator));
|
String name = decode(part.substring(0, indexOfSeparator));
|
||||||
//Log.d(TAG, " name=" + name);
|
logDebug(" name=" + name);
|
||||||
FileSystemEntryData thisFolder = accountData.mFolderCache.get(id);
|
FileSystemEntryData thisFolder = accountData.mFolderCache.get(id);
|
||||||
if (thisFolder == null)
|
if (thisFolder == null)
|
||||||
{
|
{
|
||||||
@ -198,7 +198,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
for (int i=0;i<parts.length;i++)
|
for (int i=0;i<parts.length;i++)
|
||||||
{
|
{
|
||||||
String part = parts[i];
|
String part = parts[i];
|
||||||
//Log.d(TAG, "parsing part " + part);
|
logDebug("parsing part " + part);
|
||||||
int indexOfSeparator = part.lastIndexOf(NAME_ID_SEP);
|
int indexOfSeparator = part.lastIndexOf(NAME_ID_SEP);
|
||||||
if (indexOfSeparator < 0)
|
if (indexOfSeparator < 0)
|
||||||
{
|
{
|
||||||
@ -335,14 +335,14 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
|
|
||||||
private File getFileForPath(GDrivePath path, Drive driveService)
|
private File getFileForPath(GDrivePath path, Drive driveService)
|
||||||
throws IOException, InvalidPathException {
|
throws IOException, InvalidPathException {
|
||||||
//Log.d(TAG,"getFileForPath... ");
|
logDebug("getFileForPath... ");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//throw new IOException("argh");
|
//throw new IOException("argh");
|
||||||
String driveId = path.getGDriveId();
|
String driveId = path.getGDriveId();
|
||||||
//Log.d(TAG, "id"+driveId);
|
logDebug("id"+driveId);
|
||||||
File file = driveService.files().get(driveId).execute();
|
File file = driveService.files().get(driveId).execute();
|
||||||
//Log.d(TAG,"...done.");
|
logDebug("...done.");
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
@ -408,7 +408,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
{
|
{
|
||||||
File file = getDriveService(parentGdrivePath.getAccount()).files().insert(body).execute();
|
File file = getDriveService(parentGdrivePath.getAccount()).files().insert(body).execute();
|
||||||
|
|
||||||
//Log.d(TAG, "created folder "+newDirName+" in "+parentPath+". id: "+file.getId());
|
logDebug("created folder "+newDirName+" in "+parentPath+". id: "+file.getId());
|
||||||
|
|
||||||
//add to cache to avoid network traffic if this folder is accessed (which is likely to happen soon)
|
//add to cache to avoid network traffic if this folder is accessed (which is likely to happen soon)
|
||||||
FileSystemEntryData newCacheEntry = new FileSystemEntryData();
|
FileSystemEntryData newCacheEntry = new FileSystemEntryData();
|
||||||
@ -462,7 +462,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
|
|
||||||
if (driveService.files().get(parentId).execute().getLabels().getTrashed())
|
if (driveService.files().get(parentId).execute().getLabels().getTrashed())
|
||||||
throw new FileNotFoundException(parentPath + " is trashed!");
|
throw new FileNotFoundException(parentPath + " is trashed!");
|
||||||
//Log.d(TAG, "listing files in "+parentId);
|
logDebug("listing files in "+parentId);
|
||||||
Files.List request = driveService.files().list()
|
Files.List request = driveService.files().list()
|
||||||
.setQ("trashed=false and '"+parentId+"' in parents");
|
.setQ("trashed=false and '"+parentId+"' in parents");
|
||||||
|
|
||||||
@ -473,7 +473,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
for (File file : files.getItems()) {
|
for (File file : files.getItems()) {
|
||||||
|
|
||||||
String path = new GDrivePath(parentPath, file).getFullPath();
|
String path = new GDrivePath(parentPath, file).getFullPath();
|
||||||
//Log.d(TAG, "listing file "+path);
|
logDebug("listing file "+path);
|
||||||
FileEntry e = convertToFileEntry(file, path);
|
FileEntry e = convertToFileEntry(file, path);
|
||||||
|
|
||||||
result.add(e);
|
result.add(e);
|
||||||
@ -537,12 +537,12 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Log.d(TAG, "getFileEntry "+filename);
|
logDebug("getFileEntry "+filename);
|
||||||
GDrivePath gdrivePath = new GDrivePath(filename);
|
GDrivePath gdrivePath = new GDrivePath(filename);
|
||||||
FileEntry res = convertToFileEntry(
|
FileEntry res = convertToFileEntry(
|
||||||
getFileForPath(gdrivePath, getDriveService(gdrivePath.getAccount())),
|
getFileForPath(gdrivePath, getDriveService(gdrivePath.getAccount())),
|
||||||
filename);
|
filename);
|
||||||
//Log.d(TAG, "getFileEntry res"+res);
|
logDebug("getFileEntry res"+res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -580,22 +580,22 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
|
|
||||||
private Drive getDriveService(String accountName)
|
private Drive getDriveService(String accountName)
|
||||||
{
|
{
|
||||||
//Log.d(TAG, "getDriveService "+accountName);
|
logDebug("getDriveService "+accountName);
|
||||||
AccountData accountData = mAccountData.get(accountName);
|
AccountData accountData = mAccountData.get(accountName);
|
||||||
//Log.d(TAG, "accountData "+accountData);
|
logDebug("accountData "+accountData);
|
||||||
return accountData.drive;
|
return accountData.drive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(final JavaFileStorage.FileStorageSetupActivity setupAct, int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(final JavaFileStorage.FileStorageSetupActivity setupAct, int requestCode, int resultCode, Intent data) {
|
||||||
//Log.d(TAG, "ActivityResult: "+requestCode+"/"+resultCode);
|
logDebug("ActivityResult: "+requestCode+"/"+resultCode);
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case REQUEST_ACCOUNT_PICKER:
|
case REQUEST_ACCOUNT_PICKER:
|
||||||
//Log.d(TAG, "ActivityResult: REQUEST_ACCOUNT_PICKER");
|
logDebug("ActivityResult: REQUEST_ACCOUNT_PICKER");
|
||||||
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, "Initialize Account name="+accountName);
|
logDebug("Initialize Account name="+accountName);
|
||||||
initializeAccountOrPath(setupAct, accountName);
|
initializeAccountOrPath(setupAct, accountName);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -611,7 +611,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
if (resultCode == Activity.RESULT_OK) {
|
if (resultCode == Activity.RESULT_OK) {
|
||||||
//for (String k: data.getExtras().keySet())
|
//for (String k: data.getExtras().keySet())
|
||||||
//{
|
//{
|
||||||
//Log.d(TAG, data.getExtras().get(k).toString());
|
//logDebug(data.getExtras().get(k).toString());
|
||||||
//}
|
//}
|
||||||
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
||||||
if (accountName != null) {
|
if (accountName != null) {
|
||||||
@ -669,7 +669,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
AccountData newAccountData = new AccountData();
|
AccountData newAccountData = new AccountData();
|
||||||
newAccountData.drive = createDriveService(accountName, activity);
|
newAccountData.drive = createDriveService(accountName, activity);
|
||||||
mAccountData.put(accountName, newAccountData);
|
mAccountData.put(accountName, newAccountData);
|
||||||
//Log.d(TAG, "Added account data for " + accountName);
|
logDebug("Added account data for " + accountName);
|
||||||
newAccountData.mFolderCache = buildFoldersCache(accountName);
|
newAccountData.mFolderCache = buildFoldersCache(accountName);
|
||||||
|
|
||||||
About about = newAccountData.drive.about().get().execute();
|
About about = newAccountData.drive.about().get().execute();
|
||||||
@ -704,7 +704,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
}
|
}
|
||||||
} else if ( isCancelled()) {
|
} else if ( isCancelled()) {
|
||||||
// cancel handling here
|
// cancel handling here
|
||||||
//Log.d(TAG,"Async Task cancelled!");
|
logDebug("Async Task cancelled!");
|
||||||
|
|
||||||
activity.setResult(Activity.RESULT_CANCELED);
|
activity.setResult(Activity.RESULT_CANCELED);
|
||||||
activity.finish();
|
activity.finish();
|
||||||
@ -730,12 +730,12 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
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");
|
logDebug("buildFoldersCache");
|
||||||
FileList folders=getDriveService(accountName).files().list().setQ("mimeType='"+FOLDER_MIME_TYPE+"' and trashed=false")
|
FileList folders=getDriveService(accountName).files().list().setQ("mimeType='"+FOLDER_MIME_TYPE+"' and trashed=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());
|
logDebug("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();
|
||||||
@ -747,7 +747,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
folderCache.put(thisFolder.id, thisFolder);
|
folderCache.put(thisFolder.id, thisFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log.d(TAG,"that's it!");
|
logDebug("that's it!");
|
||||||
return folderCache;
|
return folderCache;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -787,7 +787,7 @@ public class GoogleDriveFileStorage extends JavaFileStorageBase {
|
|||||||
{
|
{
|
||||||
GoogleAccountCredential credential = createCredential(activity);
|
GoogleAccountCredential credential = createCredential(activity);
|
||||||
|
|
||||||
//Log.d(TAG, "starting REQUEST_ACCOUNT_PICKER");
|
logDebug("starting REQUEST_ACCOUNT_PICKER");
|
||||||
activity.startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
|
activity.startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,11 @@ public abstract class JavaFileStorageBase implements JavaFileStorage{
|
|||||||
final static protected String NAME_ID_SEP = "-KP2A-";
|
final static protected String NAME_ID_SEP = "-KP2A-";
|
||||||
final static protected String TAG = "KP2AJ";
|
final static protected String TAG = "KP2AJ";
|
||||||
|
|
||||||
|
protected void logDebug(String text)
|
||||||
|
{
|
||||||
|
Log.d(TAG, text);
|
||||||
|
}
|
||||||
|
|
||||||
protected String getProtocolPrefix()
|
protected String getProtocolPrefix()
|
||||||
{
|
{
|
||||||
return getProtocolId()+"://";
|
return getProtocolId()+"://";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="32" android:versionName="0.9.2-r3" package="keepass2android.keepass2android" android:installLocation="auto">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="33" android:versionName="0.9.2-r3" package="keepass2android.keepass2android" android:installLocation="auto">
|
||||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14" />
|
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="14" />
|
||||||
<permission android:description="@string/permission_desc" android:icon="@drawable/ic_launcher" android:label="KP2A internal file browsing" android:name="keepass2android.keepass2android.permission.KP2aInternalFileBrowsing" android:protectionLevel="signature" />
|
<permission android:description="@string/permission_desc" android:icon="@drawable/ic_launcher" android:label="KP2A internal file browsing" android:name="keepass2android.keepass2android.permission.KP2aInternalFileBrowsing" android:protectionLevel="signature" />
|
||||||
<application android:label="keepass2android" android:icon="@drawable/ic_launcher">
|
<application android:label="keepass2android" android:icon="@drawable/ic_launcher">
|
||||||
|
Loading…
Reference in New Issue
Block a user