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

refactor(android)(9_3_X): honor Android 11 "package visibility" #11985

Merged
merged 3 commits into from Oct 26, 2020

Conversation

jquick-axway
Copy link
Contributor

@jquick-axway jquick-axway commented Aug 29, 2020

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

Summary:

  • Now auto-injects <queries/> entry if Ti.UI.createEmailDialog() API is used.
  • Modified Ti.Platform.openURL() to not fail if <queries/> entry is missing in "tiapp.xml" file.
    • The <queries/> entry is now only required for Ti.Platform.canOpenURL().
  • Updated docs for Ti.Platform.canOpenURL() with <queries/> URL scheme examples.

E-Mail Dialog Test:

  1. Create a "Classic" project with the below "tiapp.xml" setting and "app.js" code.
  2. Build and run on Android 11.
  3. Tap on the "Send E-Mail" button.
  4. Verify the device's e-mail app appears.
  5. Open Finder/WindowsExplorer.
  6. Go to folder: ./build/android/app/build/intermediates/merged_manifests/debug
  7. Verify "AndroidManifest.xml" contains a <queries/> block with mimeType set to "message/rfc822".

tiapp.xml

<ti:app>
	<android>
		<manifest>
			<uses-sdk android:targetSdkVersion="30"/>
		</manifest>
	</android>
</ti:app>

app.js

var window = Ti.UI.createWindow();
var button = Ti.UI.createButton({ title: "Send E-Mail" });
button.addEventListener("click", function() {
	var dialog = Ti.UI.createEmailDialog();
	if (dialog.isSupported()) {
		dialog.subject = "E-Mail Test";
		dialog.toRecipients = ["john.doe@domain.com", "jane.doe@domain.com"];
		dialog.messageBody = "This is the e-mail's body.\nThis is the second line.";
		dialog.open();
	} else {
		alert("E-mail app not configured on this device.");
	}
});
window.add(button);
window.open();

canOpenURL() Test:
(This test is based on PR #10881 .)

  1. Create a "Classic" project with the below "tiapp.xml" settings and "app.js" code.
  2. Build and run on Android 11.
  3. Tap on every "canOpenURL" button and verify they all display an alert displaying true. (The "tel" and "geo" URLs will return false if a phone or maps app is not installed respectively.)
  4. Delete the entire <queries/> block from the "tiapp.xml" file.
  5. Rebuild and run on Android 11.
  6. Tap on every "canOpenURL" button and verify they all display false in the alert. (Note that they will still return true on Android 10 and older.)
  7. Tap on every "openURL" button and verify that they display the URL's contents. (See PR feat(android): Added Ti.Platform.canOpenURL() support #10881 for what they should display.)

tiapp.xml

<ti:app>
	<android>
		<manifest>
			<uses-sdk android:targetSdkVersion="30"/>
			<queries>
				<intent>
					<action android:name="android.intent.action.VIEW"/>
					<data android:scheme="geo"/>
				</intent>
				<intent>
					<action android:name="android.intent.action.VIEW"/>
					<data android:scheme="https"/>
				</intent>
				<intent>
					<action android:name="android.intent.action.VIEW"/>
					<data android:mimeType="image/*"/>
				</intent>
				<intent>
					<action android:name="android.intent.action.VIEW"/>
					<data android:scheme="mailto"/>
				</intent>
				<intent>
					<action android:name="android.intent.action.VIEW"/>
					<data android:scheme="tel"/>
				</intent>
			</queries>
		</manifest>
	</android>
</ti:app>

app.js

function createTableRowForUrl(url) {
	var row = Ti.UI.createTableViewRow({
		layout: "horizontal",
	});
	row.add(Ti.UI.createLabel({
		text: url,
		top: "10dp",
		left: "10dp",
		right: "10dp",
		width: Ti.UI.FILL,
		height: Ti.UI.SIZE,
	}));
	var canOpenButton = Ti.UI.createButton({
		title: "canOpenURL()",
		top: "10dp",
		bottom: "10dp",
		left: "10dp",
		width: Ti.UI.SIZE,
		height: Ti.UI.SIZE,
	});
	canOpenButton.addEventListener("click", function() {
		var canOpen = Ti.Platform.canOpenURL(url);
		Ti.API.info("@@@ canOpenURL() returned '" + canOpen + "' for URL: " + url);
		alert("canOpenURL() returned:\n" + canOpen);
	});
	row.add(canOpenButton);
	var openButton = Ti.UI.createButton({
		title: "openURL()",
		top: "10dp",
		bottom: "10dp",
		left: "10dp",
		width: Ti.UI.SIZE,
		height: Ti.UI.SIZE,
	});
	openButton.addEventListener("click", function() {
		var wasOpened = Ti.Platform.openURL(url);
		Ti.API.info("@@@ openURL() returned '" + wasOpened + "' for URL: " + url);
	});
	row.add(openButton);
	return row;
}

var tableRows = [];
tableRows.push(createTableRowForUrl("http://www.appcelerator.com"));
tableRows.push(createTableRowForUrl("https://www.appcelerator.com"));
tableRows.push(createTableRowForUrl("mailto:user@domain.com"));
tableRows.push(createTableRowForUrl("mailto:user@domain.com?cc=johndoe@domain.com,janedoe@domain.com&bcc=bsmith@domain.com&subject=The%20Subject&body=This%20is%20a%20test.%0AHello%20World!"));
tableRows.push(createTableRowForUrl("tel:123-456-7890"));
tableRows.push(createTableRowForUrl("geo:37.774,-122.431?z=12"));  // San Francisco
tableRows.push(createTableRowForUrl("badscheme://i.dont.exist"));
if (OS_ANDROID) {
	var sourceFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "assets/images/tab1@2x.png");
	var externalFilePath = Ti.Filesystem.applicationDataDirectory + "Copy of " + sourceFile.name;
	sourceFile.copy(externalFilePath);
	tableRows.push(createTableRowForUrl("assets/images/tab1.png"));
	tableRows.push(createTableRowForUrl("/assets/images/tab1.png"));
	tableRows.push(createTableRowForUrl("././assets/images/.././images/tab1.png"));
	tableRows.push(createTableRowForUrl(sourceFile.nativePath));
	tableRows.push(createTableRowForUrl(externalFilePath));
	tableRows.push(createTableRowForUrl(Ti.Filesystem.getFile(externalFilePath).nativePath));
	tableRows.push(createTableRowForUrl("content://" + Ti.App.id + ".tifileprovider/assets/Resources/assets/images/tab1.png"));
	tableRows.push(createTableRowForUrl(Ti.Filesystem.resourcesDirectory + "assets/images/tab1.png"));
	tableRows.push(createTableRowForUrl("file:///android_asset/Resources/assets/images/tab1.png"));
	tableRows.push(createTableRowForUrl("android.resource://" + Ti.App.id + "/drawable/appicon"));
}

var window = Ti.UI.createWindow({
	extendSafeArea: false,
	fullscreen: true,
	theme: "Theme.AppCompat.NoTitleBar",
});
var tableView = Ti.UI.createTableView({
	data: tableRows,
});
window.add(tableView);
window.open();

- Now auto-injects <queries/> entry if Ti.UI.createEmailDialog() API is used.
  * Needed by EmailDialog.isSupport() method.
- Modified Ti.Platform.openURL() to not fail if <queries/> entry is missing in "tiapp.xml" file.
  * The <queries/> entry is now only required for Ti.Platform.canOpenURL().
- Updated docs for Ti.Platform.canOpenURL() with <queries/> examples.

Fixes TIMOB-28050
@build
Copy link
Contributor

build commented Aug 29, 2020

Fails
🚫 Tests have failed, see below for more information.
Messages
📖

💾 Here's the generated SDK zipfile.

📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.
📖 ❌ 2 tests have failed There are 2 tests failing and 983 skipped out of 10928 total tests.

Tests:

ClassnameNameTimeError
android.emulator.Titanium.UI.Android.ProgressIndicatordialog indeterminant - show in different windows (11)5.332
Error: timeout of 5000ms exceeded
at Titanium.<anonymous> (/ti-mocha.js:6535:53723)
ios.macos.Titanium.UI.iOS.CollisionBehavior.exampleworks (10.15.4)15.027
Error: timeout of 15000ms exceeded
file:///Users/build/jenkins/workspace/ium-sdk_titanium_mobile_PR-11985/tmp/mocha/build/iphone/build/Products/Debug-maccatalyst/mocha.app/Contents/Resources/ti-mocha.js:4326:27

Generated by 🚫 dangerJS against 1d2ac47

@jquick-axway jquick-axway changed the title refactor(android): honor Android 11 "package visibility" refactor(android)(9_3_X): honor Android 11 "package visibility" Aug 29, 2020
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

@jquick-axway jquick-axway added the backport master when applied, PRs with this label will get an auto-generated backport to master branch on merge label Sep 21, 2020
@ssjsamir ssjsamir self-requested a review October 9, 2020 15:14
Copy link
Contributor

@ssjsamir ssjsamir left a comment

Choose a reason for hiding this comment

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

@jquick-axway With the first example if I create a fresh app everything works as expected but If i use an app previously created the application just opens and closes (crashes) without an error message in the logs.

With the 2nd example at step 3. badscheme://i.dont.exist and file:///android_asset/TitaniumLogo.png return false is this expected?

Test Environment
MacOS Big Sur: 11.0 Beta 8
Java Version: 1.8.0_242
Android NDK: 21.3.6528147
Node.js: 12.18.1
""NPM":"5.0.0","CLI":"8.1.1""
Pixel XL Sim (11.0)

@jquick-axway
Copy link
Contributor Author

@ssjsamir,

Regarding badscheme://i.dont.exist, yes it should return false.

Regarding file:///android_asset/TitaniumLogo.png, your project is missing that PNG which is why it failed. I just removed that line from the test code. I didn't mean to leave it in. The file:///android_asset/Resources/assets/images/tab1.png line already exercises a file:///android_asset/* URL so that test is good enough.

@sgtcoolguy sgtcoolguy merged commit a85b1eb into tidev:9_3_X Oct 26, 2020
@build
Copy link
Contributor

build commented Oct 26, 2020

The backport to master failed:

The process 'git' failed with exit code 128

Check the run for full details
To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Check out the target branch
git checkout master
# Make sure it's up to date
git pull
# Check out your branch
git checkout -b backport-11985-to-master
# Apply the commits from the PR
curl -s https://github.com/appcelerator/titanium_mobile/commit/9d2d4f068ac9ca1ffad26f7a2e46615954a35b2a.patch | git am -3 --ignore-whitespace
# Push it to GitHub
git push --set-upstream origin backport-11985-to-master

Then, create a pull request where the base branch is master and the compare/head branch is backport-11985-to-master.

@ewanharris ewanharris removed backport master when applied, PRs with this label will get an auto-generated backport to master branch on merge master backport failed labels Mar 16, 2021
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

6 participants