mirror of
https://github.com/moparisthebest/keepass2android
synced 2025-01-30 14:40:21 -05:00
Added scope offline_access. According to the docs, this should solve the problem with repeated permission requests.
Added logging for SkyDriveFileStorage
This commit is contained in:
parent
074fea3539
commit
5693970665
@ -49,7 +49,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
|
|
||||||
private HashMap<String /* id */, SkyDriveObject> mFolderCache = new HashMap<String, SkyDriveObject>();
|
private HashMap<String /* id */, SkyDriveObject> mFolderCache = new HashMap<String, SkyDriveObject>();
|
||||||
|
|
||||||
public static final String[] SCOPES = { "wl.signin", "wl.skydrive_update", };
|
public static final String[] SCOPES = { "wl.signin", "wl.skydrive_update", "wl.offline_access"};
|
||||||
|
|
||||||
// see http://stackoverflow.com/questions/17997688/howto-to-parse-skydrive-api-date-in-java
|
// see http://stackoverflow.com/questions/17997688/howto-to-parse-skydrive-api-date-in-java
|
||||||
SimpleDateFormat SKYDRIVE_DATEFORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH);
|
SimpleDateFormat SKYDRIVE_DATEFORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH);
|
||||||
@ -136,8 +136,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
public void setPathWithoutVerify(String path)
|
public void setPathWithoutVerify(String path)
|
||||||
throws UnsupportedEncodingException, InvalidPathException {
|
throws UnsupportedEncodingException, InvalidPathException {
|
||||||
mPath = path.substring(getProtocolPrefix().length());
|
mPath = path.substring(getProtocolPrefix().length());
|
||||||
// Log.d(TAG, " mAccount=" + mAccount);
|
logDebug( " mPath=" + mPath);
|
||||||
// Log.d(TAG, " mAccountLocalPath=" + mAccountLocalPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the path exists
|
// make sure the path exists
|
||||||
@ -153,17 +152,17 @@ public class SkyDriveFileStorage 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 " + mPath);
|
throw new FileNotFoundException("invalid path " + mPath);
|
||||||
String id = decode(part.substring(indexOfSeparator
|
String id = decode(part.substring(indexOfSeparator
|
||||||
+ NAME_ID_SEP.length()));
|
+ 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);
|
||||||
SkyDriveObject thisFolder = mFolderCache.get(id);
|
SkyDriveObject thisFolder = mFolderCache.get(id);
|
||||||
if (thisFolder == null) {
|
if (thisFolder == null) {
|
||||||
//Log.d(TAG, "adding to cache");
|
logDebug( "adding to cache");
|
||||||
thisFolder = tryAddToCache(id);
|
thisFolder = tryAddToCache(id);
|
||||||
|
|
||||||
// check if it's still null
|
// check if it's still null
|
||||||
@ -199,7 +198,7 @@ public class SkyDriveFileStorage 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) {
|
||||||
// seems invalid, but we're very generous here
|
// seems invalid, but we're very generous here
|
||||||
@ -284,6 +283,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public SkyDriveFileStorage(String clientId, Context appContext) {
|
public SkyDriveFileStorage(String clientId, Context appContext) {
|
||||||
|
logDebug("Constructing SkyDriveFileStorage");
|
||||||
mAuthClient = new LiveAuthClient(appContext, clientId);
|
mAuthClient = new LiveAuthClient(appContext, clientId);
|
||||||
mAppContext = appContext;
|
mAppContext = appContext;
|
||||||
mClientId = clientId;
|
mClientId = clientId;
|
||||||
@ -291,6 +291,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void login(final FileStorageSetupActivity activity) {
|
void login(final FileStorageSetupActivity activity) {
|
||||||
|
logDebug("skydrive login");
|
||||||
mAuthClient.login((Activity) activity, Arrays.asList(SCOPES),
|
mAuthClient.login((Activity) activity, Arrays.asList(SCOPES),
|
||||||
new LiveAuthListener() {
|
new LiveAuthListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -315,7 +316,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
|
|
||||||
private void initialize(final FileStorageSetupActivity setupAct,
|
private void initialize(final FileStorageSetupActivity setupAct,
|
||||||
LiveConnectSession session) {
|
LiveConnectSession session) {
|
||||||
|
logDebug("skydrive initialize");
|
||||||
mConnectClient = new LiveConnectClient(session);
|
mConnectClient = new LiveConnectClient(session);
|
||||||
|
|
||||||
final Activity activity = (Activity)setupAct;
|
final Activity activity = (Activity)setupAct;
|
||||||
@ -359,6 +360,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
private void initializeFoldersCache() throws LiveOperationException,
|
private void initializeFoldersCache() throws LiveOperationException,
|
||||||
SkyDriveException, FileNotFoundException {
|
SkyDriveException, FileNotFoundException {
|
||||||
|
|
||||||
|
logDebug("skydrive initializeFoldersCache");
|
||||||
//use alias for now (overwritten later):
|
//use alias for now (overwritten later):
|
||||||
mRootFolderId = "me/skydrive";
|
mRootFolderId = "me/skydrive";
|
||||||
|
|
||||||
@ -375,7 +377,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
.optJSONObject(i));
|
.optJSONObject(i));
|
||||||
if (skyDriveObj == null)
|
if (skyDriveObj == null)
|
||||||
continue; // ignored type
|
continue; // ignored type
|
||||||
//Log.d(TAG, "adding "+skyDriveObj.getName()+" to cache with id " + skyDriveObj.getId()+" in "+skyDriveObj.getParentId());
|
logDebug( "adding "+skyDriveObj.getName()+" to cache with id " + skyDriveObj.getId()+" in "+skyDriveObj.getParentId());
|
||||||
mFolderCache.put(skyDriveObj.getId(), skyDriveObj);
|
mFolderCache.put(skyDriveObj.getId(), skyDriveObj);
|
||||||
|
|
||||||
mRootFolderId = skyDriveObj.getParentId();
|
mRootFolderId = skyDriveObj.getParentId();
|
||||||
@ -397,7 +399,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
|
JSONObject error = result.optJSONObject(JsonKeys.ERROR);
|
||||||
String message = error.optString(JsonKeys.MESSAGE);
|
String message = error.optString(JsonKeys.MESSAGE);
|
||||||
String code = error.optString(JsonKeys.CODE);
|
String code = error.optString(JsonKeys.CODE);
|
||||||
//Log.d(TAG, "Code: "+code);
|
logDebug( "Code: "+code);
|
||||||
if ("resource_not_found".equals(code))
|
if ("resource_not_found".equals(code))
|
||||||
throw new FileNotFoundException(message);
|
throw new FileNotFoundException(message);
|
||||||
else
|
else
|
||||||
@ -503,6 +505,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
logDebug("Error getting file version.");
|
||||||
Log.w(TAG,"Error getting file version:");
|
Log.w(TAG,"Error getting file version:");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
@ -514,7 +517,9 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
public InputStream openFileForRead(String path) throws Exception {
|
public InputStream openFileForRead(String path) throws Exception {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
logDebug("openFileForRead: " + path);
|
||||||
LiveDownloadOperation op = mConnectClient.download(new SkyDrivePath(path).getSkyDriveId()+"/content");
|
LiveDownloadOperation op = mConnectClient.download(new SkyDrivePath(path).getSkyDriveId()+"/content");
|
||||||
|
logDebug("openFileForRead ok" + path);
|
||||||
return op.getStream();
|
return op.getStream();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -529,6 +534,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
logDebug("uploadFile to "+path);
|
||||||
SkyDrivePath driveTargetPath = new SkyDrivePath(path);
|
SkyDrivePath driveTargetPath = new SkyDrivePath(path);
|
||||||
SkyDrivePath driveUploadPath = driveTargetPath;
|
SkyDrivePath driveUploadPath = driveTargetPath;
|
||||||
SkyDrivePath driveTempPath = null;
|
SkyDrivePath driveTempPath = null;
|
||||||
@ -600,7 +606,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
private Exception convertException(Exception e) throws Exception {
|
private Exception convertException(Exception e) throws Exception {
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
logDebug(e.toString());
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
|
|
||||||
throw e;
|
throw e;
|
||||||
@ -640,7 +646,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
.optJSONObject(i));
|
.optJSONObject(i));
|
||||||
if (skyDriveObj == null)
|
if (skyDriveObj == null)
|
||||||
continue; // ignored type
|
continue; // ignored type
|
||||||
//Log.d(TAG, "listing "+skyDriveObj.getName()+" with id " + skyDriveObj.getId()+" in "+skyDriveObj.getParentId());
|
logDebug( "listing "+skyDriveObj.getName()+" with id " + skyDriveObj.getId()+" in "+skyDriveObj.getParentId());
|
||||||
|
|
||||||
resultList.add(convertToFileEntry(parentDrivePath, skyDriveObj));
|
resultList.add(convertToFileEntry(parentDrivePath, skyDriveObj));
|
||||||
}
|
}
|
||||||
@ -667,13 +673,14 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.w(TAG, "Cannot parse time " + skyDriveObj.getUpdatedTime());
|
Log.w(TAG, "Cannot parse time " + skyDriveObj.getUpdatedTime());
|
||||||
|
logDebug("Cannot parse time! " + e.toString());
|
||||||
res.lastModifiedTime = -1;
|
res.lastModifiedTime = -1;
|
||||||
}
|
}
|
||||||
if (parentPath == null) //this is the case if we're listing the parent path itself
|
if (parentPath == null) //this is the case if we're listing the parent path itself
|
||||||
res.path = getProtocolPrefix();
|
res.path = getProtocolPrefix();
|
||||||
else
|
else
|
||||||
res.path = new SkyDrivePath(parentPath.getFullPath(), skyDriveObj.toJson()).getFullPath();
|
res.path = new SkyDrivePath(parentPath.getFullPath(), skyDriveObj.toJson()).getFullPath();
|
||||||
//Log.d(TAG, "path: "+res.path);
|
logDebug( "path: "+res.path);
|
||||||
if (SkyDriveFile.class.isAssignableFrom(skyDriveObj.getClass()))
|
if (SkyDriveFile.class.isAssignableFrom(skyDriveObj.getClass()))
|
||||||
{
|
{
|
||||||
res.sizeInBytes = ((SkyDriveFile)skyDriveObj).getSize();
|
res.sizeInBytes = ((SkyDriveFile)skyDriveObj).getSize();
|
||||||
@ -687,8 +694,8 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
SkyDrivePath drivePath = new SkyDrivePath(filename);
|
SkyDrivePath drivePath = new SkyDrivePath(filename);
|
||||||
//Log.d(TAG, "getFileEntry for "+ filename +" = "+drivePath.getFullPath());
|
logDebug( "getFileEntry for "+ filename +" = "+drivePath.getFullPath());
|
||||||
//Log.d(TAG, " parent is "+drivePath.getParentPath());
|
logDebug( " parent is "+drivePath.getParentPath());
|
||||||
return convertToFileEntry(drivePath.getParentPath(),getSkyDriveObject(drivePath));
|
return convertToFileEntry(drivePath.getParentPath(),getSkyDriveObject(drivePath));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -730,6 +737,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
public void onStart(final FileStorageSetupActivity activity) {
|
public void onStart(final FileStorageSetupActivity activity) {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
logDebug("skydrive onStart");
|
||||||
initialize(activity);
|
initialize(activity);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -751,15 +759,16 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
LiveConnectSession session, Object userState) {
|
LiveConnectSession session, Object userState) {
|
||||||
|
|
||||||
if (status == LiveStatus.CONNECTED) {
|
if (status == LiveStatus.CONNECTED) {
|
||||||
|
logDebug("connected!");
|
||||||
initialize(activity, session);
|
initialize(activity, session);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (status == LiveStatus.NOT_CONNECTED)
|
if (status == LiveStatus.NOT_CONNECTED)
|
||||||
Log.d(TAG, "not connected");
|
logDebug( "not connected");
|
||||||
else if (status == LiveStatus.UNKNOWN)
|
else if (status == LiveStatus.UNKNOWN)
|
||||||
Log.d(TAG, "unknown");
|
logDebug( "unknown");
|
||||||
else
|
else
|
||||||
Log.d(TAG, "unexpected status " + status);
|
logDebug( "unexpected status " + status);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
login(activity);
|
login(activity);
|
||||||
@ -768,6 +777,7 @@ public class SkyDriveFileStorage extends JavaFileStorageBase {
|
|||||||
{
|
{
|
||||||
//this may happen if an un-cancelled login progress is already in progress.
|
//this may happen if an un-cancelled login progress is already in progress.
|
||||||
//however, the activity might have been destroyed, so try again with another auth client next time
|
//however, the activity might have been destroyed, so try again with another auth client next time
|
||||||
|
logDebug("IllegalStateException: Recreating AuthClient");
|
||||||
mAuthClient = new LiveAuthClient(mAppContext, mClientId);
|
mAuthClient = new LiveAuthClient(mAppContext, mClientId);
|
||||||
finishWithError(activity, e);
|
finishWithError(activity, e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user