use of com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException in project keepass2android by PhilippC.
the class GoogleDriveFileStorage method initializeAccountOrPath.
private void initializeAccountOrPath(final JavaFileStorage.FileStorageSetupActivity setupAct, final String accountNameOrPath) {
final Activity activity = ((Activity) setupAct);
final Context appContext = activity.getApplicationContext();
String accountNameTemp;
GDrivePath gdrivePath = null;
if (accountNameOrPath.startsWith(getProtocolPrefix())) {
gdrivePath = new GDrivePath();
// don't verify yet, we're not yet initialized:
try {
gdrivePath.setPathWithoutVerify(accountNameOrPath);
} catch (Exception e) {
finishWithError(setupAct, e);
}
accountNameTemp = gdrivePath.getAccount();
} else
accountNameTemp = accountNameOrPath;
final String accountName = accountNameTemp;
AsyncTask<Object, Void, AsyncTaskResult<String>> task = new AsyncTask<Object, Void, AsyncTaskResult<String>>() {
@Override
protected AsyncTaskResult<String> doInBackground(Object... arg0) {
try {
initializeAccount(appContext, accountName);
if (setupAct.getProcessName().equals(PROCESS_NAME_SELECTFILE))
setupAct.getState().putString(EXTRA_PATH, getRootPathForAccount(accountName));
return new AsyncTaskResult<String>("ok");
} catch (Exception anyError) {
return new AsyncTaskResult<String>(anyError);
}
}
@Override
protected void onPostExecute(AsyncTaskResult<String> result) {
Exception error = result.getError();
if (error != null) {
if (UserRecoverableAuthIOException.class.isAssignableFrom(error.getClass())) {
mAccountData.remove(accountName);
activity.startActivityForResult(((UserRecoverableAuthIOException) error).getIntent(), REQUEST_AUTHORIZATION);
} else {
finishWithError(setupAct, error);
}
} else if (isCancelled()) {
// cancel handling here
logDebug("Async Task cancelled!");
activity.setResult(Activity.RESULT_CANCELED);
activity.finish();
} else {
// all right!
finishActivityWithSuccess(setupAct);
}
}
};
task.execute(new Object[] {});
}
use of com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException in project Aegis by Decad3nce.
the class BackupGoogleAccountsActivity method saveFileToDrive.
private void saveFileToDrive() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
if (!isAegisFolderAvailable()) {
createAegisFolder();
}
FileContent mediaContent = null;
File body = new File();
File file = null;
if (callLogs) {
Log.i(TAG, "Generating new file to upload: " + callLogFileUri);
java.io.File callFileContent = new java.io.File(callLogFileUri.getPath());
mediaContent = new FileContent("text/plain", callFileContent);
body.setTitle(callFileContent.getName());
body.setParents(Arrays.asList(new ParentReference().setId(getAegisFolder())));
body.setMimeType("text/plain");
file = service.files().insert(body, mediaContent).execute();
if (file != null) {
Log.i(TAG, "File uploaded successfully: " + file.getTitle());
Utils.sendSMS(context, address, context.getResources().getString(R.string.util_sendsms_data_recovery_pass) + " " + file.getTitle() + " to Google Drive");
deleteFile(file.getTitle());
finish();
}
}
if (smsLogs) {
Log.i(TAG, "Generating new file to upload: " + smsLogFileUri);
java.io.File smsFileContent = new java.io.File(smsLogFileUri.getPath());
mediaContent = new FileContent("text/plain", smsFileContent);
body.setTitle(smsFileContent.getName());
body.setParents(Arrays.asList(new ParentReference().setId(getAegisFolder())));
body.setMimeType("text/plain");
file = service.files().insert(body, mediaContent).execute();
if (file != null) {
Log.i(TAG, "File uploaded successfully: " + file.getTitle());
Utils.sendSMS(context, address, context.getResources().getString(R.string.util_sendsms_data_recovery_pass) + " " + file.getTitle() + " to Google Drive");
deleteFile(file.getTitle());
finish();
}
}
} catch (UserRecoverableAuthIOException e) {
Log.i(TAG, "Exception: " + e.toString());
startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
} catch (IOException e) {
Log.i(TAG, "Exception: " + e.toString());
e.printStackTrace();
Utils.sendSMS(context, address, context.getResources().getString(R.string.util_sendsms_data_recovery_fail));
}
}
});
t.start();
}
use of com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException in project Aegis by Decad3nce.
the class BackupGoogleAccountsActivity method createAegisFolder.
private void createAegisFolder() {
Log.i(TAG, "Creating aeGis folder");
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
File body = new File();
body.setTitle("aeGis Backup");
body.setDescription("Backup stored by aeGis");
body.setMimeType("application/vnd.google-apps.folder");
File file = service.files().insert(body).execute();
if (file != null) {
finish();
}
} catch (UserRecoverableAuthIOException e) {
startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
} catch (IOException e) {
e.printStackTrace();
}
}
});
t.start();
}
Aggregations