Added more logs to help debug file picking in chat

This commit is contained in:
Sylvain Berfini 2019-08-19 13:34:16 +02:00
parent 4a62fbb95c
commit 35d9141ae3
2 changed files with 51 additions and 18 deletions

View file

@ -428,11 +428,14 @@ public class ChatMessagesFragment extends Fragment
if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) { if (requestCode == ADD_PHOTO && resultCode == Activity.RESULT_OK) {
String fileToUploadPath = null; String fileToUploadPath = null;
if (data.getData() != null) { if (data.getData() != null) {
Log.i(
"[Chat Messages Fragment] Intent data after picking file is "
+ data.getData().toString());
if (data.getData().toString().contains("com.android.contacts/contacts/")) { if (data.getData().toString().contains("com.android.contacts/contacts/")) {
if (FileUtils.getCVSPathFromLookupUri(data.getData().toString()) != null) { Uri cvsPath = FileUtils.getCVSPathFromLookupUri(data.getData().toString());
fileToUploadPath = if (cvsPath != null) {
FileUtils.getCVSPathFromLookupUri(data.getData().toString()) fileToUploadPath = cvsPath.toString();
.toString(); Log.i("[Chat Messages Fragment] Found CVS path: " + fileToUploadPath);
} else { } else {
// TODO Error // TODO Error
return; return;
@ -440,12 +443,21 @@ public class ChatMessagesFragment extends Fragment
} else { } else {
fileToUploadPath = fileToUploadPath =
FileUtils.getRealPathFromURI(getActivity(), data.getData()); FileUtils.getRealPathFromURI(getActivity(), data.getData());
Log.i(
"[Chat Messages Fragment] Resolved path for data is: "
+ fileToUploadPath);
} }
if (fileToUploadPath == null) { if (fileToUploadPath == null) {
fileToUploadPath = data.getData().toString(); fileToUploadPath = data.getData().toString();
Log.i(
"[Chat Messages Fragment] Couldn't resolve path, using as-is: "
+ fileToUploadPath);
} }
} else if (mImageToUploadUri != null) { } else if (mImageToUploadUri != null) {
fileToUploadPath = mImageToUploadUri.getPath(); fileToUploadPath = mImageToUploadUri.getPath();
Log.i(
"[Chat Messages Fragment] Using pre-created path for dynamic capture "
+ fileToUploadPath);
} }
if (fileToUploadPath.startsWith("content://") if (fileToUploadPath.startsWith("content://")
@ -454,6 +466,9 @@ public class ChatMessagesFragment extends Fragment
fileToUploadPath = fileToUploadPath =
FileUtils.getFilePath( FileUtils.getFilePath(
getActivity().getApplicationContext(), uriToParse); getActivity().getApplicationContext(), uriToParse);
Log.i(
"[Chat Messages Fragment] Path was using a content or file scheme, real path is: "
+ fileToUploadPath);
if (fileToUploadPath == null) { if (fileToUploadPath == null) {
Log.e( Log.e(
"[Chat Messages Fragment] Failed to get access to file " "[Chat Messages Fragment] Failed to get access to file "
@ -462,6 +477,9 @@ public class ChatMessagesFragment extends Fragment
} else if (fileToUploadPath.contains("com.android.contacts/contacts/")) { } else if (fileToUploadPath.contains("com.android.contacts/contacts/")) {
fileToUploadPath = fileToUploadPath =
FileUtils.getCVSPathFromLookupUri(fileToUploadPath).toString(); FileUtils.getCVSPathFromLookupUri(fileToUploadPath).toString();
Log.i(
"[Chat Messages Fragment] Path was using a contact scheme, real path is: "
+ fileToUploadPath);
} }
if (fileToUploadPath != null) { if (fileToUploadPath != null) {
@ -470,6 +488,9 @@ public class ChatMessagesFragment extends Fragment
} else { } else {
addFileToPendingList(fileToUploadPath); addFileToPendingList(fileToUploadPath);
} }
} else {
Log.e(
"[Chat Messages Fragment] Failed to get a path that we could use, aborting attachment");
} }
} else { } else {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);

View file

@ -38,6 +38,7 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.R;
import org.linphone.core.Address; import org.linphone.core.Address;
import org.linphone.core.Friend; import org.linphone.core.Friend;
import org.linphone.core.FriendList; import org.linphone.core.FriendList;
@ -81,14 +82,22 @@ public class FileUtils {
try { try {
File localFile = createFile(context, name); File localFile = createFile(context, name);
InputStream remoteFile = context.getContentResolver().openInputStream(uri); InputStream remoteFile = context.getContentResolver().openInputStream(uri);
Log.i(
"[File Utils] Trying to copy file from "
+ uri.toString()
+ " to local file "
+ localFile.getAbsolutePath());
if (copyToFile(remoteFile, localFile)) { if (copyToFile(remoteFile, localFile)) {
Log.i("[File Utils] Copy successful");
result = localFile.getAbsolutePath(); result = localFile.getAbsolutePath();
} else {
Log.e("[File Utils] Copy failed");
} }
remoteFile.close(); remoteFile.close();
} catch (IOException e) { } catch (IOException e) {
Log.e("[File Utils] Enable to get sharing file ", e); Log.e("[File Utils] getFilePath exception: ", e);
} }
return result; return result;
@ -128,8 +137,9 @@ public class FileUtils {
} }
return true; return true;
} catch (IOException e) { } catch (IOException e) {
return false; Log.e("[File Utils] copyToFile exception: " + e);
} }
return false;
} }
private static File createFile(Context context, String fileName) { private static File createFile(Context context, String fileName) {
@ -182,12 +192,9 @@ public class FileUtils {
public static String getStorageDirectory(Context mContext) { public static String getStorageDirectory(Context mContext) {
String storageDir = String storageDir =
Environment.getExternalStorageDirectory() Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/" + "/"
+ mContext.getString( + mContext.getString(R.string.app_name);
mContext.getResources()
.getIdentifier(
"app_name", "string", mContext.getPackageName()));
File file = new File(storageDir); File file = new File(storageDir);
if (!file.isDirectory() || !file.exists()) { if (!file.isDirectory() || !file.exists()) {
Log.w( Log.w(
@ -196,7 +203,11 @@ public class FileUtils {
+ " doesn't seem to exists yet, let's create it"); + " doesn't seem to exists yet, let's create it");
boolean result = file.mkdirs(); boolean result = file.mkdirs();
if (!result) { if (!result) {
Log.e("[File Utils] Couldn't create directory " + file.getAbsolutePath()); Log.e(
"[File Utils] Couldn't create media directory "
+ file.getAbsolutePath()
+ ", using external storage dir instead");
return Environment.getExternalStorageDirectory().getAbsolutePath();
} }
LinphoneManager.getInstance().getMediaScanner().scanFile(file, null); LinphoneManager.getInstance().getMediaScanner().scanFile(file, null);
} }
@ -207,10 +218,7 @@ public class FileUtils {
String recordingsDir = String recordingsDir =
Environment.getExternalStorageDirectory() Environment.getExternalStorageDirectory()
+ "/" + "/"
+ mContext.getString( + mContext.getString(R.string.app_name)
mContext.getResources()
.getIdentifier(
"app_name", "string", mContext.getPackageName()))
+ "/recordings"; + "/recordings";
File file = new File(recordingsDir); File file = new File(recordingsDir);
if (!file.isDirectory() || !file.exists()) { if (!file.isDirectory() || !file.exists()) {
@ -220,7 +228,11 @@ public class FileUtils {
+ " doesn't seem to exists yet, let's create it"); + " doesn't seem to exists yet, let's create it");
boolean result = file.mkdirs(); boolean result = file.mkdirs();
if (!result) { if (!result) {
Log.e("[File Utils] Couldn't create directory " + file.getAbsolutePath()); Log.e(
"[File Utils] Couldn't create recordings directory "
+ file.getAbsolutePath()
+ ", using external storage dir instead");
return Environment.getExternalStorageDirectory().getAbsolutePath();
} }
LinphoneManager.getInstance().getMediaScanner().scanFile(file, null); LinphoneManager.getInstance().getMediaScanner().scanFile(file, null);
} }
@ -250,7 +262,7 @@ public class FileUtils {
fw.close(); fw.close();
return Uri.fromFile(vcfFile); return Uri.fromFile(vcfFile);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e("[File Utils] createCVSFromString exception: " + e);
} }
return null; return null;
} }