[Libreoffice-commits] online.git: android/lib
Jan Holesovsky (via logerrit)
logerrit at kemper.freedesktop.org
Fri Feb 14 10:03:46 UTC 2020
android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java | 45 +++++++++-
1 file changed, 43 insertions(+), 2 deletions(-)
New commits:
commit 7c90a32b51c070e79488d5c5e4536a936a35b420
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Thu Feb 13 21:21:23 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Feb 14 11:03:28 2020 +0100
android: Copy data back if the content: URI allows that.
So that saving back to the apps that called us works (if the app gave us
the permission to do so, that is).
Change-Id: Idaf47f1d1cf9ea3fef57ac885fc6b91bc4f84be4
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/88632
Tested-by: Jan Holesovsky <kendy at collabora.com>
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
index 90021f1c6..424e0cd09 100644
--- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
+++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
@@ -266,8 +266,10 @@ public class LOActivity extends AppCompatActivity {
if (getIntent().getData() != null) {
if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
- isDocEditable = false;
- Toast.makeText(this, getResources().getString(R.string.temp_file_saving_disabled), Toast.LENGTH_SHORT).show();
+ isDocEditable = (getIntent().getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0;
+ if (!isDocEditable)
+ Toast.makeText(this, getResources().getString(R.string.temp_file_saving_disabled), Toast.LENGTH_SHORT).show();
+
if (copyFileToTemp() && mTempFile != null) {
documentUri = mTempFile.toURI();
urlToLoad = documentUri.toString();
@@ -397,6 +399,7 @@ public class LOActivity extends AppCompatActivity {
}
}
+ /** When we get the file via a content: URI, we need to put it to a temp file. */
private boolean copyFileToTemp() {
ContentResolver contentResolver = getContentResolver();
FileChannel inputChannel = null;
@@ -437,6 +440,42 @@ public class LOActivity extends AppCompatActivity {
}
}
+ /** Check that we have created a temp file, and if yes, copy it back to the content: URI. */
+ private void copyTempBackToIntent() {
+ if (!isDocEditable || mTempFile == null || getIntent().getData() == null || !getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT))
+ return;
+
+ ContentResolver contentResolver = getContentResolver();
+ FileChannel inputChannel = null;
+ FileChannel outputChannel = null;
+
+ try {
+ try {
+ AssetFileDescriptor assetFD = contentResolver.openAssetFileDescriptor(getIntent().getData(), "w");
+ if (assetFD == null) {
+ Log.e(TAG, "couldn't create assetfiledescriptor from " + getIntent().getDataString());
+ return;
+ }
+ outputChannel = assetFD.createOutputStream().getChannel();
+ inputChannel = new FileInputStream(mTempFile).getChannel();
+
+ long bytesTransferred = 0;
+ // might not copy all at once, so make sure everything gets copied....
+ while (bytesTransferred < inputChannel.size()) {
+ bytesTransferred += outputChannel.transferFrom(inputChannel, bytesTransferred, inputChannel.size());
+ }
+ Log.e(TAG, "Success copying " + bytesTransferred + " bytes");
+ } finally {
+ if (inputChannel != null) inputChannel.close();
+ if (outputChannel != null) outputChannel.close();
+ }
+ } catch (FileNotFoundException e) {
+ Log.e(TAG, "file not found: " + e.getMessage());
+ } catch (Exception e) {
+ Log.e(TAG, "exception: " + e.getMessage());
+ }
+ }
+
@Override
protected void onResume() {
super.onResume();
@@ -560,6 +599,7 @@ public class LOActivity extends AppCompatActivity {
@Override
public void run() {
postMobileMessageNative("BYE");
+ copyTempBackToIntent();
runOnUiThread(new Runnable() {
@Override
@@ -702,6 +742,7 @@ public class LOActivity extends AppCompatActivity {
initiateSlideShow();
return false;
case "SAVE":
+ copyTempBackToIntent();
sendBroadcast(messageAndParam[0], messageAndParam[1]);
return false;
case "downloadas":
More information about the Libreoffice-commits
mailing list