Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6b59f29 authored by Juffin Alex Varghese's avatar Juffin Alex Varghese
Browse files

Bluetooth-OPP: Truncating receiving filename

Truncating receiving filename if name exceeds MAX_LENGTH. Otherwise,
files having non-ascii characters as filename are failed to receive.

CRs-Fixed: 576621
Change-Id: Ie2a60cf6bfe6bb5bfa8ab69a7b85b3cd8bd08479
parent 8a636b95
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import android.content.ContentResolver;
import android.content.ContentValues;
@@ -164,7 +166,7 @@ public class BluetoothOppReceiveFileInfo {
            filename = filename.substring(0, dotIndex);
        }

        if ((filename != null) && (filename.length() > OPP_LENGTH_OF_FILE_NAME)) {
        if ((filename != null) && (filename.getBytes().length > OPP_LENGTH_OF_FILE_NAME)) {
          /* Including extn of the file, Linux supports 255 character as a maximum length of the
           * file name to be created. Hence, Instead of sending OBEX_HTTP_INTERNAL_ERROR,
           * as a response, truncate the length of the file name and save it. This check majorly
@@ -172,7 +174,14 @@ public class BluetoothOppReceiveFileInfo {
           * more than 255 characters, But the server rejects the card just because the length of
           * vcf file name received exceeds 255 Characters.
           */
          filename = filename.substring(0, OPP_LENGTH_OF_FILE_NAME);
          try {
              byte[] oldfilename = filename.getBytes("UTF-8");
              byte[] newfilename = new byte[OPP_LENGTH_OF_FILE_NAME];
              System.arraycopy(oldfilename, 0, newfilename, 0, OPP_LENGTH_OF_FILE_NAME);
              filename = new String(newfilename, "UTF-8");
          } catch (UnsupportedEncodingException e) {
              Log.e(Constants.TAG, "Exception: " + e);
          }
          if (D) Log.d(Constants.TAG, "File name is too long. Name is truncated as: " + filename);
        }