MediaScannerConnection fails on Android 6 because of permission denial - android-permissions

I use a MediaScannerConnection to call its scanFile method, for adding images to device gallery. But in Android 6 I receive this exceptions when I execute it:
E/DatabaseUtils: java.lang.SecurityException: Permission Denial:
reading com.android.providers.media.MediaProvider uri
content://media/external/fs_id from pid=22984, uid=10078 requires
android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
and
E/iu.UploadsManager: java.lang.SecurityException: Permission Denial:
reading com.android.providers.media.MediaProvider uri
content://media/external/fs_id from pid=22984, uid=10078 requires
android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
Any help?

Related

#ionic-native/zip not working on API 31, open failed: EACCES (Permission denied)

I am working on a legacy ionic-cordova project, running my android app on API level 31 (upgraded recently).
I have android:requestLegacyExternalStorage="true" and the permissions
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
on my AndroidManifest.xml file. Also checked my permissions with 'cordova-plugin-android-permissions' and also 'cordova-diagnostic-plugin' for 'READ_EXTERNAL_STORAGE' & 'WRITE_EXTERNAL_STORAGE' permissions and got granted: true,
But I still can not use the 'cordova-plugin-zip', due to EACCES (Permission denied),
this is the error I get on Android Studio:
2023-01-11 13:06:36.328 14977-22760/es.my-app.my-app E/Zip: An error occurred while unzipping.
java.io.FileNotFoundException: /storage/emulated/0/Download/some-file.KMZ: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileInputStream.<init>(FileInputStream.java:160)
at java.io.FileInputStream.<init>(FileInputStream.java:115)
at org.apache.cordova.CordovaResourceApi.openForRead(CordovaResourceApi.java:250)
at org.apache.cordova.CordovaResourceApi.openForRead(CordovaResourceApi.java:233)
at org.apache.cordova.Zip.unzipSync(Zip.java:84)
at org.apache.cordova.Zip.access$000(Zip.java:23)
at org.apache.cordova.Zip$1.run(Zip.java:39)
Previews to the update, the Zip.unzip method from '#ionic-native/zip' used to work fine to decompress my .kmz files, but now it throws an error: -1 due to permissions denied while trying to read from the External Storage.
Finally, I came up with an OK solution, starting from API 31, to have full access to the external storage there is a particular permission: 'MANAGE_EXTERNAL_STORAGE', in order to register my app for that permission, firstly I had to add it to the 'config.xml' file like so:
<widget xmlns:android="http://schemas.android.com/apk/res/android">
<platform name="android">
...
<config-file parent="/manifest" target="AndroidManifest.xml">
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
</config-file>
...
</platform>
</widget>
it is important to add xmlns:android="http://schemas.android.com/apk/res/android" at the widget tag.
Then to request the 'MANAGE_EXTERNAL_STORAGE' permission I modified the .java file of the plugin on android studion like so:
...
public class FileChooser extends CordovaPlugin {
#Override
public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R && !android.os.Environment.isExternalStorageManager()) {
try {
Intent intent = new Intent();
intent.setAction(android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Uri uri = Uri.fromParts("package", cordova.getContext().getPackageName(), null);
intent.setData(uri);
cordova.getActivity().startActivity(intent);
} catch (Exception e) {
Intent intent = new Intent();
intent.setAction(android.provider.Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
cordova.getActivity().startActivity(intent);
}
}
.... plugin code ...
}
}
The execute function is the starting point of execution for the plugin, there, I added the code that requests permission before executing the rest of the plugin processes...
NOTE: with the newer scoped stotage restrictions for android the 'MANAGE_EXTERNAL_STORAGE' permission might make it hard to publish your app on play store, there are other, more complex, strategies to access the external storage that will not cause that trouble.

Unable to start receiver com.google.android.finsky.instantapps.PhenotypeUpdateReceiver: java.lang.IllegalStateException

I have released my game to play console which is made using Unity. The Pre-launch report, reported the following crash issues during internal testing.
java.lang.RuntimeException: Unable to start receiver com.google.android.finsky.instantapps.PhenotypeUpdateReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.gms.phenotype.UPDATE cmp=com.android.vending/com.google.android.finsky.instantapps.PhenotypeUpdateService }: app is in background uid UidRecord{46dceb4 u0a249 TRNB bg:+10m41s432ms idle change:uncached procs:4 proclist:29801,29978,30388,30591, seq(0,0,0)}
AND
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
I am not sure, where exactly the error is and why?
Full trace for the first issue:
FATAL EXCEPTION: main
Process: com.android.vending:instant_app_installer, PID: 19323
java.lang.RuntimeException: Unable to start receiver com.google.android.finsky.instantapps.PhenotypeUpdateReceiver: android.app.BackgroundServiceStartNotAllowedException: Not allowed to start service Intent { act=com.google.android.gms.phenotype.UPDATE cmp=com.android.vending/com.google.android.finsky.instantapps.PhenotypeUpdateService }: app is in background uid UidRecord{64ad173 u0a135 TRNB bg:+13m22s373ms idle change:uncached procs:0 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4317)
at android.app.ActivityThread.access$1600(ActivityThread.java:247)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2064)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: android.app.BackgroundServiceStartNotAllowedException: Not allowed to start service Intent { act=com.google.android.gms.phenotype.UPDATE cmp=com.android.vending/com.google.android.finsky.instantapps.PhenotypeUpdateService }: app is in background uid UidRecord{64ad173 u0a135 TRNB bg:+13m22s373ms idle change:uncached procs:0 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1861)
at android.app.ContextImpl.startService(ContextImpl.java:1817)
at android.content.ContextWrapper.startService(ContextWrapper.java:774)
at alj.a(PG:2)
at alm.a(PG:3)
at wnv.a(PG:2)
at com.google.android.finsky.instantapps.PhenotypeUpdateReceiver.onReceive(PG:6)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4308)
... 9 more
Full trace for the second issue:
FATAL EXCEPTION: pool-3-thread-1
Process: com.HefazSofts.AayaanTheRunner, PID: 19257
java.lang.IllegalArgumentException: com.HefazSofts.AayaanTheRunner: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:174)
at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108)
at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86)
at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)

Connecting to secured remote AEM repository

In order to create JCR nodes, We are trying to programmatically connect to a remote AEM instance using the JcrUtils.getRepository(...) method to acquire the handle to the repository instance.
This instance is secured and checks for a cookie in the request to let the user in.
Is there a way to pass the cookie to JcrUtils (or other methods of connecting to an AEM repository)?
Right now, when running the code JcrUtils.getRepository("http://host:port/crx/server"); it just throws the following exception:
javax.jcr.RepositoryException: Unable to access a repository with the following settings:
org.apache.jackrabbit.repository.uri: https://<host>:<port>/crx/server
The following RepositoryFactory classes were consulted:
org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory: declined
org.apache.jackrabbit.jcr2spi.Jcr2spiRepositoryFactory: declined
org.apache.jackrabbit.commons.JndiRepositoryFactory: declined
org.apache.jackrabbit.core.RepositoryFactoryImpl: declined
org.apache.jackrabbit.rmi.repository.RmiRepositoryFactory: failed
because of RemoteRuntimeException: java.rmi.RemoteException: Failed to read the resource at URL https://<host>:<port>/crx/server; nested exception is:
java.io.StreamCorruptedException: invalid stream header: 3C21444F
because of RemoteException: Failed to read the resource at URL https://<host>:<port>/crx/server; nested exception is:
java.io.StreamCorruptedException: invalid stream header: 3C21444F
because of StreamCorruptedException: invalid stream header: 3C21444F
Perhaps the repository you are trying to access is not available at the moment.
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:223)
at org.apache.jackrabbit.commons.JcrUtils.getRepository(JcrUtils.java:263)
...
There is no way to pass cookie via JcrUtils.getRepository(...) it accepts URI as a string.
In your logs looks like org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory doesn't exist in application classpath.
Make sure you added to dependencies following libs
jackrabbit-jcr-commons
jackrabbit-jcr2dav
in case you are using Maven:
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr-commons</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-jcr2dav</artifactId>
<version>2.10.1</version>
</dependency>
I am getting similar issue as #user3239244 but only in case of https.
I am trying to access repository from standalone java application
repository = JcrUtils.getRepository(url)
Works for http and fails for https
From logs:
javax.jcr.RepositoryException: Unable to access a repository with the
following settings:
org.apache.jackrabbit.repository.uri: https://localhost:5433/crx/server The following RepositoryFactory
classes were consulted:
org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory: declined
org.apache.jackrabbit.jcr2spi.Jcr2spiRepositoryFactory: declined
org.apache.jackrabbit.commons.JndiRepositoryFactory: declined
org.apache.jackrabbit.core.RepositoryFactoryImpl: declined
org.apache.jackrabbit.rmi.repository.RmiRepositoryFactory: failed
because of RepositoryException: Failed to read the resource at URL https://localhost:5433/crx/server
because of SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
because of ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
because of SunCertPathBuilderException: unable to find valid certification path to requested target

Can't log into workbench

I deployed kie-drools-wb-distribution-wars-6.1.0.Final-jboss-as7.0.war into a JBoss 6.3 AS, and added an admin user in the application realm using the add-user.sh command. The login page of KIE Workbench can display, but when I click the login button, the following error occurs:
BWEB000065: HTTP Status 400 - JBWEB000006: Invalid direct reference to
form login page
JBWEB000309: type JBWEB000067: Status report
JBWEB000068: message JBWEB000006: Invalid direct reference to form
login page
JBWEB000069: description JBWEB000120: The request sent by the client
was syntactically incorrect.
JBoss Web/7.4.8.Final-redhat-4
I also deployed the Tomcat version, the login page failed to authenticate the user login with the following errors:
HTTP Status 500 - Filter execution threw an exception type
Exception report message
Filter execution threw an exception description
The server encountered an internal error that prevented it from fulfilling this request.
exception javax.servlet.ServletException: Filter execution threw an exception
root cause java.lang.NoClassDefFoundError: javax/security/jacc/PolicyContext
org.uberfire.security.server.auth.source.JACCAuthenticationSource.getSubjectFrom‌​Container(JACCAuthenticationSource.java:155)
org.uberfire.security.server.auth.source.JACCAuthenticationSource.loadRoles(JACC‌​AuthenticationSource.java:88)
org.uberfire.security.server.auth.HttpAuthenticationManager.authenticate(HttpAut‌​henticationManager.java:178)
org.uberfire.security.server.HttpSecurityManagerImpl.authenticate(HttpSecurityMa‌​nagerImpl.java:216)
org.uberfire.security.server.UberFireSecurityFilter.authenticate(UberFireSecurit‌​yFilter.java:337) org.uberfire.security.server.UberFireSecurityFilter.doFilter(UberFireSecurityFil‌​ter.java:278)
root cause java.lang.ClassNotFoundException: javax.security.jacc.PolicyContext org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:17‌​20)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:15‌​71)
org.uberfire.security.server.auth.source.JACCAuthenticationSource.getSubjectFrom‌​Container(JACCAuthenticationSource.java:155)
org.uberfire.security.server.auth.source.JACCAuthenticationSource.loadRoles(JACC‌​AuthenticationSource.java:88)
org.uberfire.security.server.auth.HttpAuthenticationManager.authenticate(HttpAut‌​henticationManager.java:178)
org.uberfire.security.server.HttpSecurityManagerImpl.authenticate(HttpSecurityMa‌​nagerImpl.java:216)
org.uberfire.security.server.UberFireSecurityFilter.authenticate(UberFireSecurit‌​yFilter.java:337)
org.uberfire.security.server.UberFireSecurityFilter.doFilter(UberFireSecurityFil‌​ter.java:278)
That is because you have not download the KIE Execution Server, please download this: https://download.jboss.org/drools/release/6.5.0.Final/kie-server-distribution-6.5.0.Final.zip. Put it in the tomcat webapps folder, and config the setenv.sh like this:
CATALINA_OPTS="-Xmx512M -XX:MaxPermSize=512m -Dbtm.root=$CATALINA_HOME
-Dorg.jbpm.cdi.bm=java:comp/env/BeanManager -Dbitronix.tm.configuration=$CATALINA_HOME/conf/btm-config.properties -Djbpm.tsr.jndi.lookup=java:comp/env/TransactionSynchronizationRegistry
-Djava.security.auth.login.config=$CATALINA_HOME/webapps/kie-drools-web/WEB-INF/classes/login.config
-Dorg.kie.server.persistence.ds=java:comp/env/jdbc/jbpm -Dorg.kie.server.persistence.tm=org.hibernate.service.jta.platform.internal.BitronixJtaPlatform
-Dorg.kie.server.id=tomcat-kieserver -Dorg.kie.server.location=http://localhost:8080/kie-server-6.5.0.Final-webc/services/rest/server
-Dorg.kie.server.controller=http://localhost:8080/kie-drools-web/rest/controller
-Dorg.kie.server.user=tomcat -Dorg.kie.server.pwd=tomcat -Dorg.kie.server.controller.user=tomcat -Dorg.kie.server.controller.pwd=tomcat"

spring security facebook error with session

am using spring security Facebook 0.6 , am able to get user authentication from facebook but when user tries to access my application then it shows error as follows
2012-02-16 11:06:22,376 [http-8080-1] ERROR hibernate.LazyInitializationException - could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at
org.codehaus.groovy.grails.orm.hibernate.proxy.HibernateProxyHandler.unwrapProxy(HibernateProxyHandler.java:83)
at
org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil.unwrapProxy(GrailsHibernateUtil.java:404)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil$unwrapProxy.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil$unwrapProxy.call(Unknown Source)
at org.codehaus.groovy.grails.plugins.orm.hibernate.HibernatePluginSupport$__clinit__closure94.doCall(HibernatePluginSupport.groovy:397)
You seem to be trying to access the user object which is stored in session, can you show us the code.
Try reattaching the detached user object before you access any of the fields.
//get user from session
user.attach()