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): autoFocus causing crash on some versions of Android #11454

Merged
merged 13 commits into from Mar 26, 2020

Conversation

harnk
Copy link
Contributor

@harnk harnk commented Jan 27, 2020

  • Refactor Ti.Media.takePicture auto-focus callback
  • Prevent auto-focus related crashes on older Android verions
TEST CASE
const overlay = Ti.UI.createView({});
const takePicture = Ti.UI.createButton({ title: 'Take Picture' });

takePicture.addEventListener('click', _ => {
    Ti.Media.takePicture();
});
overlay.add(takePicture);

function showCamera(e) {
    Ti.Media.showCamera({
        success: e => {
            if (e.success) {
                console.log('Taken picture successfully!');
            } else {
                console.error(JSON.stringify(e, null, 2));
            }
        },
        saveToPhotoGallery: true,
        autohide: false,
        overlay: overlay,
        mediaTypes: [ Ti.Media.MEDIA_TYPE_PHOTO ]
    });
}

if (Ti.Meda.hasCameraPermissions()) {
    showCamera();
} else {
    Ti.Media.requestCameraPermissions(e => {
        if (e.success) {
            showCamera();
        }
    });
}

JIRA Ticket

Scott Null and others added 2 commits January 27, 2020 11:26
Crash occurs on some devices running Android versions 5.01, 5.1 and 6.0.1 when taking a picture.
@harnk
Copy link
Contributor Author

harnk commented Jan 27, 2020

Crash Details: E/TiExceptionHandler: (main) [55,37938] autoFocus failed

    android.hardware.Camera.native_autoFocus(Native Method)
    android.hardware.Camera.autoFocus(Camera.java:1308)
    ti.modules.titanium.media.TiCameraActivity$2.onAutoFocus(TiCameraActivity.java:735)
    android.hardware.Camera$EventHandler.handleMessage(Camera.java:1161)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:135)
    android.app.ActivityThread.main(ActivityThread.java:5254)
    java.lang.reflect.Method.invoke(Native Method)
    java.lang.reflect.Method.invoke(Method.java:372)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

@build
Copy link
Contributor

build commented Jan 27, 2020

Warnings
⚠️ This PR has milestone set to 9.0.1, but the version defined in package.json is 9.1.0 Please either: - Update the milestone on the PR - Update the version in package.json - Hold the PR to be merged later after a release and version bump on this branch
Messages
📖

💾 Here's the generated SDK zipfile.

📖

🎊 Welcome to the Titanium SDK community, harnk! Thank you so much for your PR, you're helping us make Titanium better. 🎁

📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.
📖

✅ All tests are passing
Nice one! All 6525 tests are passing.
(There are 697 skipped tests not included in that total)

Generated by 🚫 dangerJS against d813849

@garymathews
Copy link
Contributor

Thanks @harnk! I've pushed a few minor changes to address another similar issue.

Copy link
Contributor

@jquick-axway jquick-axway 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

@ssjsamir ssjsamir self-requested a review March 25, 2020 13:56
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.

FR Passed: Autofocus no longer causing crashes on a variety of devices/android versions.

Environment

MacOS Catalina: 10.15.1 beta
Xcode: 11.3
Java Version: 1.8.0_131
Android NDK: 21.1.6273396-beta2
Node.js: 10.16.3
""NPM":"5.0.0-1","CLI":"8.0.0-master.10""
Pixel xl (7.1.1) 
Nexus 60(8.0)
Pixel XL (10)
Samsung Galaxy S4 (5.1)

@ssjsamir ssjsamir merged commit e482247 into tidev:master Mar 26, 2020
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

7 participants