Various errors moving app to sdcard depending on api level - android

A user asked me about a crash while using the app on the sd card. My app was not movable to the sdcard so I added to the manifest android:installLocation="auto" and tried to move it to the external memory. Using it on my real device (34 gb/ 47 gb free on internal/external memory) I get the space not sufficient error. I understood that this is a generic error used for other issues so I fired up the emulator and checked the logcat.
Partial manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.user.app"
android:installLocation="auto"
>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.VIBRATE" />
<queries>
<package android:name="org...." />
</queries>
On my device with android 11 I get
D/PackageManager: START MOVE PACKAGE: pkg{com.github.user.app.debug}
volumeUuid{3231-6462}
I/ActivityTaskManager: START u0 {flg=0x24000000 cmp=com.android.settings/.deviceinfo.StorageWizardMoveProgress (has extras)} from uid 1000
D/RestrictionPolicy: isSettingsChangesAllowedAsUser, userId 0 : true
E/LockGuard: Calling thread PackageManager is holding PACKAGES while trying to acquire DPMS
java.lang.RuntimeException: Calling thread PackageManager is holding PACKAGES while trying to acquire DPMS
at com.android.server.LockGuard.doLog(LockGuard.java:179)
at com.android.server.LockGuard.guard(LockGuard.java:166)
at com.android.server.devicepolicy.DevicePolicyManagerService.getLockObject(DevicePolicyManagerService.java:779)
at com.android.server.devicepolicy.DevicePolicyManagerService.packageHasActiveAdmins(DevicePolicyManagerService.java:5158)
at com.android.server.pm.PackageManagerService.isPackageDeviceAdmin(PackageManagerService.java:22599)
at com.android.server.pm.PackageManagerService.isPackageDeviceAdminOnAnyUser(PackageManagerService.java:22572)
at com.android.server.pm.PackageManagerService.movePackageInternal(PackageManagerService.java:28919)
at com.android.server.pm.PackageManagerService.lambda$movePackage$45$PackageManagerService(PackageManagerService.java:28837)
at com.android.server.pm.-$$Lambda$PackageManagerService$fXZo1oAlF-92gGHcSdrHuC0WLPc.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.os.HandlerThread.run(HandlerThread.java:67)
at com.android.server.ServiceThread.run(ServiceThread.java:44)
...
V/PackageManager: Move 6 created Bundle[{android.intent.extra.PACKAGE_NAME=com.github.user.app.debug, android.intent.extra.TITLE=App-dev}]
I/PackageManager: measurePath: /storage/3231-6462
...
V/PackageManager: Move 6 status 53
...
D/PackageManager: result of install: -15{120868786}
V/PackageManager: Move 6 status -6
On an android api 30 emulator
W/PackageManager: Failed to move com.github.user.app.debug
com.android.server.pm.PackageManagerException: Move only supported for modern cluster style installs
at com.android.server.pm.PackageManagerService.movePackageInternal(PackageManagerService.java:23180)
at com.android.server.pm.PackageManagerService.lambda$movePackage$41$PackageManagerService(PackageManagerService.java:23125)
at com.android.server.pm.-$$Lambda$PackageManagerService$ECakc05vOVsUm8ydpi2Z-HghH4w.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.os.HandlerThread.run(HandlerThread.java:67)
at com.android.server.ServiceThread.run(ServiceThread.java:44)
This is the interested part in PackageManager:
final File probe = new File(pkg.codePath);
final File probeOat = new File(probe, "oat");
if (!probe.isDirectory() || !probeOat.isDirectory()) {
throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,
"Move only supported for modern cluster style installs");
}
I tried again on a fresh api 25 emulator and I get the same error, different exception:
W/installd: type=1400 audit(0.0:879): avc: denied { sys_admin } for capability=21 scontext=u:r:installd:s0 tcontext=u:r:installd:s0 tclass=capability permissive=0
D/installd: Detected label change from u:object_r:system_data_file:s0 to u:object_r:app_data_file:s0:c512,c768 at /mnt/expand/2e6f3762-8f82-4c9f-9633-f74b10070b25/user/0/com.github. user.app.debug; running recursive restorecon
D/installd: Detected label change from u:object_r:system_data_file:s0 to u:object_r:app_data_file:s0:c512,c768 at /mnt/expand/2e6f3762-8f82-4c9f-9633-f74b10070b25/user_de/0/com.github. user.app.debug; running recursive restorecon
D/installd: Copying /data/user_de/0/com.github. user.app.debug to /mnt/expand/2e6f3762-8f82-4c9f-9633-f74b10070b25/user_de/0
D/installd: Copying /data/data/com.github. user.app.debug to /mnt/expand/2e6f3762-8f82-4c9f-9633-f74b10070b25/user/0
W/PackageParser: Unknown element under <manifest>: queries at /mnt/expand/2e6f3762-8f82-4c9f-9633-f74b10070b25/app/com.github.user.app.debug-1/base.apk Binary XML file line #18
W/PackageManager: installPackageLI
D/PackageManager: Cleaning up com.github.user.app.debug on 2e6f3762-8f82-4c9f-9633-f74b10070b25
V/PackageManager: Move 0 status -6
D/StorageSettings: Finished with status -6
W/ActivityManager: Duplicate finish request
I tried to upload an apk instead of letting Android Studio do it but it did not work. Googling the errors only brought me to the soure code links. Any help is appreciated.

I experienced the same issue on an APK installed from Android Studio. Switching between debug and release did not make a difference.
My goal was to install the app onto external to test it, which I was finally able to do under Run/Debug Configurations > Installation Options > Install Flags by adding --install-location 2

Related

Android BIND_JOB_SERVICE & sepolicy

I have a valid manifest file with the right permission & "exported" set as well. But, I still get the below error:
Error: Requires permission android.permission.BIND_JOB_SERVICE
The command (initiated over adb) is a running a service (via "am startservice") & the manifest file has these details:
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE" />
Logcat doesn't have anything useful, just throws the permission required error (which the APK already has). This seems like a sepolicy restriction since if I remove the policy (by running "setenforce 0"), then the command works fine (no errors seen as well)
I've tried running in "permissive" mode but it doesn't show any useful messages. Is there any way to figure out what policy needs to be turned on?
Here's the actual error from logcat:
05-16 14:03:32.892 566 897 W ActivityManager: Permission Denial: Accessing service com.abc.def/.MyService from pid=6757, uid=2000 requires android.permission.BIND_JOB_SERVICE
What I found was, putting the same command in a bash script and sourcing it works fine!!

Android O (api 26): root-app not recognized as "priviledged"

I have an app that works well on Android N.
It is (via root) installed into /system/priv-app/* and gets the permissions granted that are only for priviledged apps.
Now on Android O Preview, the app does not get the permissions granted:
08-12 20:30:01.178 687 814 W PackageManager: Privileged permission android.permission.CAPTURE_AUDIO_OUTPUT for package eu.asd.service - not in privapp-permissions whitelist
08-12 20:30:01.178 687 814 W PackageManager: Privileged permission android.permission.UPDATE_APP_OPS_STATS for package eu.asd.service - not in privapp-permissions whitelist
08-12 20:30:01.178 687 814 W PackageManager: Privileged permission android.permission.WRITE_SECURE_SETTINGS for package eu.asd.service - not in privapp-permissions whitelist
Anyone knows where this "privapp-permissions whitelist" comes from, and what to do, to get onto this list on a rooted Android?
There should be a xml file where the priv-app permissions for you app are listed. Please check /system/etc/permissions
You'll have to add your permissions to one of the files inside.
Example:
<privapp-permissions package="[your package name]">
<permission name="android.permission.PERMISSION_YOU_WANT"/>
....
</privapp-permissions>
Adding to #pedrop's correct answer - in case you are developing your own AOSP, you can edit these XMLs before compilation and have them inserted to the build. The files can be found in the source code. There is one file for the platform (all devices and vendors), one for each vendor and one for each device.
You can find them in the following locations:
1. Platform -
AOSP/frameworks/base/data/etc/privapp-permissions-platform.xml
2. Vendor -
AOSP/vendor/VENDOR_NAME/proprietary/system/etc/permissions/privapp-permissions-VENDOR.xml
3. Device -
AOSP/vendor/VENDOR_DEVICES/DEVICE_NAME/proprietary/etc/permissions/privapp-permissions-DEVICE_NAME.xml

App not working in all devices

I made a music player app. It runs properly in some devices but it crashes in some others. I am not able to understand the error. How do I fix it? All I understand is the first error and that is I have to take separate permission for read phone state permission.
Error 1:
java.lang.RuntimeException: Unable to create service beatbox.neelay.beatbox.MediaService: java.lang.SecurityException: Neither user 10103 nor current process has android.permission.READ_PHONE_STATE.
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2804)
at android.app.ActivityThread.access$1900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1404)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.SecurityException: Neither user 10103 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1499)
at com.android.internal.telephony.ITelephonyRegistry$Stub$Proxy.listenForSubscriber(ITelephonyRegistry.java:544)
at android.telephony.TelephonyManager.listen(TelephonyManager.java:2514)
at beatbox.neelay.beatbox.MediaService.callStateListener(MediaService.java:612)
at beatbox.neelay.beatbox.MediaService.onCreate(MediaService.java:126)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2794)
... 9 more
This is the error that is submitted by the user.
Error 2:
Writing exception to parcel
java.lang.SecurityException:
External path: /storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1481126994678: Neither user 10199 nor current process has android.permission.WRITE_EXTERNAL_STORAGE.
at android.app.ContextImpl.enforce(ContextImpl.java:1443)
at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1475)
at android.content.ContextWrapper.enforceCallingOrSelfPermission(ContextWrapper.java:675)
at com.android.providers.media.MediaProvider.enforceCallingOrSelfPermissionAndAppOps(MediaProvider.java:6793)
at com.android.providers.media.MediaProvider.checkAccess(MediaProvider.java:5570)
at com.android.providers.media.MediaProvider.ensureFileExists(MediaProvider.java:4381)
at com.android.providers.media.MediaProvider.getAlbumArtOutputUri(MediaProvider.java:5834)
at com.android.providers.media.MediaProvider.makeThumbInternal(MediaProvider.java:5976)
at com.android.providers.media.MediaProvider.getThumb(MediaProvider.java:5897)
at com.android.providers.media.MediaProvider.openFile(MediaProvider.java:5466)
at android.content.ContentProvider.openAssetFile(ContentProvider.java:1427)
at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1607)
at android.content.ContentProvider.openTypedAssetFile(ContentProvider.java:1673)
at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:430)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313)
at android.os.Binder.execTransact(Binder.java:458)
I have take permission for Android m both in manifest and in Java, and I'm not using any function of write external storage but then also it is showing this error.
On Android >=6.0, We have to request permission runtime.
Step1: add in AndroidManifest.xml file
Step2: Request permission.
Step3: Handle callback when you request permission.
Check this one: Permission at Run Time
Edit: I think you have similar Issue:
you must add this permissions
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
to AndroidManifest.xml file
It might be because some of the devices are running Android 6.0 or higher and others are not.
See https://developer.android.com/training/permissions/requesting.html
If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.

ACCESS_WIFI_STATE error on emulator

I've declared the following permission on the manifest:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
And per the docs it's a normal permission so no need to request it at runtime on devices running Android M or higher.
The app has crashed but I've tested on multiple devices (with android N) and the app works has expected. Any idea why it has crashed on an emulator with Android SDK built for x86 running android 7.0?
Here is the stacktrace:
Fatal Exception: java.lang.SecurityException: WifiService: Neither user 10076 nor current process has android.permission.ACCESS_WIFI_STATE.
at android.os.Parcel.readException(Parcel.java:1683)
at android.os.Parcel.readException(Parcel.java:1636)
at android.net.wifi.IWifiManager$Stub$Proxy.getWifiEnabledState(IWifiManager.java:1198)
at android.net.wifi.WifiManager.getWifiState(WifiManager.java:1455)
at android.net.wifi.WifiManager.isWifiEnabled(WifiManager.java:1467)
...
To work with WifiManager when scanning the Connections from Android 6.0 it needs to access your location, so that is either the fine location or the coarse location, Add the following to Manifes.xml:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Since Android M (6+) you have to ask the user for permissions during runtime, like iOS-applications for instance.
You can read the docs here, a quick solution is to use a library, e.g EasyPermission or EasyPermission
https://github.com/jineshfrancs/EasyPermission
https://github.com/lalosoft/EasyPermissions
Usage:
easyPermission.requestPermission(this, Manifest.permission.ACCESS_WIFI_STATE);

APK Expansion File Download exception

I recently implemented the APK Expansion File code, described in
http://developer.android.com/guide/market/expansion-files.html, into
my app. I updated the manifest, created the Service and Receiver files
and update my main activity onCreate() to conform to the instructions
in the guide.
I created a signed apk of my app, and uploaded it to my Google Play
account, along with the obb file. These were saved as "drafts".
I then used adb to install my signed APK onto my device and ran it and
immediately got the following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MyApp}:
android.database.sqlite.SQLiteException: no such table:
MetadataColumns: , while compiling: SELECT APKVERSION,_id,DOWNLOADSTATUS,DOWNLOADFLAGS FROM MetadataColumns LIMIT 1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 1821)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 1842)
at android.app.ActivityThread.access$1500(ActivityThread.java: 132)
at android.app.ActivityThread $H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4263)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: no such table:
MetadataColumns: , while compiling: SELECT APKVERSION,_id,DOWNLOADSTATUS,DOWNLOADFLAGS FROM MetadataColumns LIMIT 1
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java: 92)
at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java: 65)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java: 49)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java: 53)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java: 1438)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java: 1406)
at com.google.android.vending.expansion.downloader.impl.t.<init>(SourceFile: 76)
at com.google.android.vending.expansion.downloader.impl.t.a(SourceFile: 44)
at com.google.android.vending.expansion.downloader.impl.DownloaderService.a(SourceFile: 634)
What is interesting is that if I run my app through the Eclipse
debugger, I can execute the code that caused the exception, and
continue normal processing, getting a message "Download failed because
you may not have purchased this app".
Any idea why, on a signed version, there is an SQLite exception in the
downloader library, specifically DownloadsDB.java?
My Project Build Target is 2.3.3
I have the Google Play License, Downloader and Zip libraries
referenced by my project
And I have the following in my manifest:
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" /
<uses-permission android:name="com.android.vending.CHECK_LICENSE" /
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<service android:name=".MyAppDownloaderService" />
<receiver android:name=".MyAppAlarmReceiver" />
TIA,
jb
I did not get exactly the same exception but this might be your problem:
http://code.google.com/p/android/issues/detail?id=31663
The code in DownloadsDB.java is a bit sloppy and occurrences of:
if (null != cur && cur.moveToFirst()) { ... }
must be changed to:
if (null != cur) { if (cur.moveToFirst()) { ... } }
Yes but now approach has been changed a bit. each and every application has key,
this error comes basically for few reasons, make sure :
you are logged in from your test acoount into your device.
key are same in your code as well.
you have mentioned the size of expansion file in code correctly in bytes.
after uploading wait for 3-4 hours, then it will start downloading, instantly it does not work.

Categories

Resources