Android Question [SOLVED] - FileProvider and installing Apk's

Jmu5667

Well-Known Member
Licensed User
Longtime User
EDIT: https://github.com/sixo/silent-update/blob/master/app/src/main/java/eu/sisik/devowner/Utils.kt
The solition for this issue is only available if you(the app) are a system app. It does not work on unsigned app.


Hello

We have keys from a phone manufacturer that allows us sign our apps to become system apps. One of our app is a Launcher app and part of the functionality is to allow us push apps to the phone and allow the user install them.

In the unsigned version of the app this works perfectly.

In the signed version is does not work. As a test we signed B4A bridge with the manufacturer keys and tried to install an app on the phone via B4A Bridge and it failed. Below is the log data we have collected.
B4X:
Logger connected to: EX23V710D1110

--------- beginning of crash

FATAL EXCEPTION: main

Process: com.google.android.packageinstaller, PID: 15607

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.packageinstaller/com.android.packageinstaller.InstallStart}: java.lang.SecurityException: UID 10056 does not have permission to content://com.islesystems.launcher.provider/name/p4c3g7hf.apk [user 0]

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3484)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3648)

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2116)

at android.os.Handler.dispatchMessage(Handler.java:106)

at android.os.Looper.loop(Looper.java:223)

at android.app.ActivityThread.main(ActivityThread.java:7723)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)

Caused by: java.lang.SecurityException: UID 10056 does not have permission to content://com.islesystems.launcher.provider/name/p4c3g7hf.apk [user 0]

at android.os.Parcel.createExceptionOrNull(Parcel.java:2373)

at android.os.Parcel.createException(Parcel.java:2357)

at android.os.Parcel.readException(Parcel.java:2340)

at android.os.Parcel.readException(Parcel.java:2282)

at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:3696)

at android.app.Instrumentation.execStartActivity(Instrumentation.java:1723)

at android.app.Activity.startActivityForResult(Activity.java:5320)

at android.app.Activity.startActivityForResult(Activity.java:5278)

at android.app.Activity.startActivity(Activity.java:5664)

at android.app.Activity.startActivity(Activity.java:5617)

at com.android.packageinstaller.InstallStart.onCreate(InstallStart.java:143)

at android.app.Activity.performCreate(Activity.java:8000)

at android.app.Activity.performCreate(Activity.java:7984)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3457)

... 11 more

Caused by: android.os.RemoteException: Remote stack trace:

at com.android.server.uri.UriGrantsManagerService.checkGrantUriPermissionUnlocked(UriGrantsManagerService.java:1242)

at com.android.server.uri.UriGrantsManagerService.checkGrantUriPermissionFromIntentUnlocked(UriGrantsManagerService.java:614)

at com.android.server.uri.UriGrantsManagerService.access$1000(UriGrantsManagerService.java:114)

at com.android.server.uri.UriGrantsManagerService$LocalService.checkGrantUriPermissionFromIntent(UriGrantsManagerService.java:1399)

at com.android.server.wm.ActivityStarter$Request.resolveActivity(ActivityStarter.java:533)


The install function:
B4X:
Public Sub StartInstall As Boolean
    Dim success As Boolean

    If IsDownloaded Then
        Dim fileName As String = $"${ID}.apk"$
        If File.Exists(Provider.SharedFolder, fileName) Then
            Try
                Dim i As Intent               
                Dim phone As Phone
                If phone.SdkVersion >= 24 Then
                    Log(Provider.GetFileUri(fileName))                   
                    i.Initialize("android.intent.action.INSTALL_PACKAGE", Provider.GetFileUri(fileName))
                    i.Flags = Bit.Or(i.Flags, FLAG_GRANT_READ_URI_PERMISSION)
                Else
                    Provider.SetFileUriAsIntentData(i, fileName)
                    i.SetType("application/vnd.android.package-archive")
                End If
                StartActivity(i)
                success = True
                installStatus = INSTALL_STARTED
            Catch
                Log($"Error starting install for application id ${ID} Exception information: ${LastException}"$)
            End Try
        Else
            Log($"Downloaded APK for application id ${ID} cannot be found"$)
        End If
    Else
        Log($"APK for application id [${ID}] must be downloaded first"$)
    End If
    If Not(success) Then
        installStatus = INSTALL_FAILED
    End If
    Return success
   
End Sub

Manifest for file provider
B4X:
AddApplicationText(
      <provider
      android:name="android.support.v4.content.FileProvider"
      android:authorities="$PACKAGE$.provider"
      android:exported="false"
      android:grantUriPermissions="true">
      <meta-data
      android:name="android.support.FILE_PROVIDER_PATHS"
      android:resource="@xml/provider_paths"/>
      </provider>
    )
    CreateResource(xml, provider_paths,
       <files-path name="name" path="shared" />
    )

I have sent the log information to the Manufacturer hoping that it maybe the case that new keys are requried

Any suggestion are welcome

Regards

John.

@OliverA
 
Last edited:
Top