CAMERA permission workaroud

1,361 views
Skip to first unread message

Ivan

unread,
Oct 28, 2017, 5:42:55 PM10/28/17
to CodenameOne Discussions
Hi guys,

with last version of libs (189) I'm getting security exception (see below) which was resolved previously in CN1 using workaround requesting permissions (https://stackoverflow.com/questions/45548597/codenameone-capture-capturephoto-requests-wrong-permission)

My app worked OK on device doogee x5max until now.

It's regression or it was removed on purpose or it's different issue?

thanks

Ivan

[EDT] 0:0:0,92 - Exception: java.lang.SecurityException - Permission Denial: starting Intent { act=android.media.action.
IMAGE_CAPTURE flg=0x4000003 cmp=com.mediatek.camera/com.android.camera.CaptureActivity clip={text/uri-list U:file:///storage/emulated/0/Pictures/Hive%20Tracker/IMG_20171028_230800.jpg} (has extras) } from ProcessRecord{ec17a7e 5166:com.koppert.hivetracker/u0a94} (pid=5166, uid=10094) with revoked permission android.permission.CAMERA
java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.IMAGE_CAPTURE flg=0x4000003 cmp=com.mediatek.camera/com.android.camera.CaptureActivity clip={text/uri-list U:file:///storage/emulated/0/Pictures/Hive%20Tracker/IMG_20171028_230800.jpg} (has extras) } from ProcessRecord{ec17a7e 5166:com.koppert.hivetracker/u0a94} (pid=5166, uid=10094) with revoked permission android.permission.CAMERA
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2817)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
at android.app.Activity.startActivityForResult(Activity.java:3978)
at android.app.Activity.startActivityForResult(Activity.java:3930)
at com.codename1.impl.android.CodenameOneActivity.startActivityForResult(CodenameOneActivity.java:576)
at com.codename1.impl.android.AndroidImplementation.capturePhoto(AndroidImplementation.java:6035)
at com.codename1.ui.Display.capturePhoto(Display.java:3173)
at com.codename1.capture.Capture.capturePhoto(Capture.java:77)
at com.codename1.capture.Capture.capturePhoto(Capture.java:143)
at com.codename1.capture.Capture.capturePhoto(Capture.java:85)
at com.koppert.hivetracker.view.QuestionaryOption.lambda$new$3(Unknown Source)
at com.koppert.hivetracker.view.QuestionaryOption$$Lambda$2.actionPerformed(Unknown Source)
at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349)
at com.codename1.ui.Button.fireActionEvent(Button.java:499)
at com.codename1.ui.Button.released(Button.java:533)
at com.codename1.ui.Button.pointerReleased(Button.java:637)
at com.codename1.ui.Form.pointerReleased(Form.java:2794)
at com.codename1.ui.Component.pointerReleased(Component.java:4016)
at com.codename1.ui.Display.handleEvent(Display.java:2032)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1028)
at com.codename1.ui.Display.mainEDTLoop(Display.java:946)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread$1.run(CodenameOneThread.java:60)
at java.lang.Thread.run(Thread.java:818)


If you are experiencing an issue please mention the full platform your issue applies to:
IDE: Eclipse
Desktop OS Ubuntu 16.04
Simulator
Device doogee x5max , android 6.0

Shai Almog

unread,
Oct 29, 2017, 1:07:53 AM10/29/17
to CodenameOne Discussions
Hi,
this isn't a recent regression as this was never the issue. Camera permission shouldn't be requested as we invoke an intent and that's a request that should be made by the intent provider not by us. I think this might be related to an app you might have installed recently on the device that took over the camera intent.

Ivan

unread,
Oct 29, 2017, 12:30:45 PM10/29/17
to CodenameOne Discussions
Hi Shai, thanks for answer but I'm confused little bit now.

I tried it on another device with Android 6.0.1 (Xiaomi Redmi A4) and the behavior is the same.
I start the photo capturing, I get the question to allow photo capturing, I click yes and then I get above mentioned security exception.
I found stack overflow discussion (mentioned in my previos post) about Android M Camera Intent + permission bug where you write about to add workaround to CN1 for that (on August 11th 2017).
Is there the workaround or what should I do to make the camera working?







Dňa nedeľa, 29. októbra 2017 6:07:53 UTC+1 Shai Almog napísal(-a):

Ivan

unread,
Oct 29, 2017, 1:08:56 PM10/29/17
to CodenameOne Discussions
I had this in build hints

<uses-permission android:name="android.permission.CAMERA"/><uses-feature android:name="android.hardware.camera" android:required="false"/>

and when I removed it, it works also on 6.0.x

Shai Almog

unread,
Oct 30, 2017, 12:59:43 AM10/30/17
to CodenameOne Discussions
That's a bug in Android 6 because of the broken way permissions were changed in Android. If you have that hint they get confused and assume you need the permission.

Ivan

unread,
Dec 4, 2017, 6:41:50 PM12/4/17
to CodenameOne Discussions
Hi Shai, I'm in troubles with Android 6 permissions again and previous solution does not work for my second application

I have two applications in the same eclipse workspace (CN1 v.3.8), libs ver. 196, no android hints at all, build.xml of the same version (3.8) ... setup is the same (except theme.res)

One application, mentioned in posts above (let's name it app A) works as follows:
I install app A on Android 6, run it. try to capture photo. Application asks for permission to access media, files, ... I allow the access, camera is started. Everything works OK.
I check the phone Setting -> Permissions -> Camera and the application A is NOT in list of permissions for camera (despite this works ok)

Second application (let's name it app B) work as follows:
I install app B on Android 6, run it. try to capture photo. Application asks for permission to access media, files, ... I allow the access, camera is NOT started, exception occurs (SecurityException - Permission Denial, same like in my first post)
I check the phone Setting -> Permissions -> Camera and the application B IS in list of permissions for camera, but is OFF (despite I clicked ALLOW in permissions dialog at runtime)
When I set here the permission manually everything works ok.
(also when I set target SDK = 21 app B works ok)

Do you have an idea why two applications with the same setup behave differently?
Why the app A does not appear in list of camera permissions but works and app B does appear there but the permission is not allowed despite the user allowed it at runtime?

thanks in advance for each advice






Shai Almog

unread,
Dec 5, 2017, 12:24:14 AM12/5/17
to CodenameOne Discussions
Hi,
this is effectively because Android is stupid.

Permission isn't required because it's asked by the other intent so it has nothing to do with our app. The problem is that if the app does request the permission the way that permission passes through the intent chain is "flaky" for security purposes. I'm not sure how to workaround this, I'd check the manifest to see if a permission slipped in from somewhere.
Reply all
Reply to author
Forward
0 new messages