Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): File.read().text wrongly returns null for JSON files on Android Q #10931

Merged
merged 3 commits into from Jun 5, 2019

Conversation

jquick-axway
Copy link
Contributor

JIRA:
https://jira.appcelerator.org/browse/TIMOB-26954

Summary:

  • Caused by Android Q returning mime-type "application/json" which Titanium's TiMimeTypeHelper Java class incorrectly interpreted as a binary type.
  • Modified Ti.Blob object's "text" property to always return text, even if it's a binary type.
    • Now matches iOS' behavior.
  • Modified Ti.Blob object's toString() method to only return blob's text if mime-type is a known text type, like how "text" property used to work.

Test:

  1. Build and run the below code on Android Q (aka: Android 10).
  2. Verify that an alert appears on screen reading: Success!
// Create the JSON data to test with.
var jsonOriginalData = {
	myBoolean: true,
	myNumber: 123.456,
	myString: "Hello World",
	myArray: [false, true, -1, 0, 1, 123.456, "", "My String"],
	myDictionary: {
		nestedBoolean: false,
		nestedNumber: -43.21,
		nestedString: "This is a test.",
		nestedArray: [true, 123, "Hello Again"],
	},
};
var jsonOriginalString = JSON.stringify(jsonOriginalData);

// Write above JSON data to file.
var jsonFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "test.json");
jsonFile.write(jsonOriginalString);
Ti.API.info("@@@ JSON string written:\n" + jsonOriginalString);

// Read the JSON file that was just written above.
var jsonReadString = jsonFile.read().text;
Ti.API.info("@@@ JSON string read:\n" + jsonReadString);

// Check if JSON was written/read to/from file successfully.
if (jsonReadString === jsonOriginalString) {
	alert("Success!");
} else {
	alert("Failed!");
}

…on Android Q

- Modified Ti.Blob "text" property to always return text even if its a binary type, like iOS.
- Modified Ti.Blob toString() method to only return blob's text if mimetype is a known text type, like how "text" property used to work.
@jquick-axway jquick-axway added this to the 8.2.0 milestone Jun 4, 2019
@build build requested a review from a team June 4, 2019 03:13
@build
Copy link
Contributor

build commented Jun 4, 2019

Messages
📖

💾 Here's the generated SDK zipfile.

📖

✅ All tests are passing
Nice one! All 3613 tests are passing.
(There are 464 tests skipped)

Generated by 🚫 dangerJS against f33892b

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS

@lokeshchdhry
Copy link
Contributor

lokeshchdhry commented Jun 5, 2019

FR Passed.

JSON file is read successfully on Android Q.

Studio Ver: 5.1.3.201905231615
SDK Ver: 8.2.0 local build
OS Ver: 10.14.5
Xcode Ver: Xcode 10.2.1
Appc NPM: 4.2.13
Appc CLI: 7.0.12-70X.4
Daemon Ver: 1.1.3
Ti CLI Ver: 5.1.1
Alloy Ver: 1.13.10
Node Ver: 8.15.1
NPM Ver: 6.4.1
Java Ver: 10.0.2
Devices: Android Q emulator.

@lokeshchdhry lokeshchdhry merged commit 3f49d79 into tidev:master Jun 5, 2019
hansemannn pushed a commit to hansemannn/titanium_mobile that referenced this pull request Jul 8, 2019
…on Android Q (tidev#10931)

- Modified Ti.Blob "text" property to always return text even if its a binary type, like iOS.
- Modified Ti.Blob toString() method to only return blob's text if mimetype is a known text type, like how "text" property used to work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants