adb install works, but PackageInstaller instalation produces : Valid package ... is NOT installed/enabled for all users on AOSP Android Automotive

57 views
Skip to first unread message

Nemanja Stijak

unread,
Feb 11, 2025, 12:54:20 PMFeb 11
to android-webview-dev
Platform -  AOSP Android Automotive

I am trying to update webview via system app with pre-granted INSTALL_PACKAGES permission and using PackageInstaller.

And process of instalation goes through, packageInstaller returns that instalation is sucessfull in BroadcastReceiver.

I use webview providers xml to define package names of webviews:
<webviewproviders> <webviewprovider description="My Company Android WebView" packageName="com.mycompany.webview" availableByDefault="true" isFallback="false"> <signature>MIID[...]28x</signature> </webviewprovider> <webviewprovider description="Android WebView" packageName="com.android.webview" availableByDefault="true" isFallback="true"> </webviewprovider> </webviewproviders>


And before instalation of new webview dumpsys webviewupdate returns:
Current WebView Update Service state Fallback logic enabled: false Multiprocess enabled: true Current WebView package (name, version): (com.android.webview, 83.0.4103.120) Minimum targetSdkVersion: 30 Minimum WebView version code: 410412053 Number of relros started: 2 Number of relros finished: 2 WebView package dirty: false Any WebView package installed: true Preferred WebView package (name, version): (com.android.webview, 83.0.4103.120) WebView packages: com.mycompany.webview is NOT installed. Valid package com.android.webview (versionName: 83.0.4103.120, versionCode: 410412053, targetSdkVersion: 30) is installed/enabled for all users


After code based PackageInstaller I get error from the title
urrent WebView Update Service state Fallback logic enabled: false Multiprocess enabled: true Current WebView package (name, version): (com.android.webview, 83.0.4103.120) Minimum targetSdkVersion: 30 Minimum WebView version code: 410412053 Number of relros started: 2 Number of relros finished: 2 WebView package dirty: false Any WebView package installed: true Preferred WebView package (name, version): (com.android.webview, 83.0.4103.120) WebView packages: Valid package com.mycompany.webview (versionName: 129.0.6668.70, versionCode: 666807001, targetSdkVersion: 35) is NOT installed/enabled for all users Valid package com.android.webview (versionName: 83.0.4103.120, versionCode: 410412053, targetSdkVersion: 30) is installed/enabled for all users $ adb shell cmd webviewupdate set-webview-implementation com.mycompany.webview Failed to switch to com.mycompany.webview, the WebView implementation is now provided by com.android.webview.


Hower, if instead I use ADB to install it everything is fine.
$ adb install Webview.apk Performing Streamed Install Success $ adb shell dumpsys webviewupdate Current WebView Update Service state Fallback logic enabled: false Multiprocess enabled: true Current WebView package (name, version): (com.mycompany.webview, 129.0.6668.70) Minimum targetSdkVersion: 30 Minimum WebView version code: 410412053 Number of relros started: 2 Number of relros finished: 2 WebView package dirty: false Any WebView package installed: true Preferred WebView package (name, version): (com.mycompany.webview, 129.0.6668.70) WebView packages: Valid package com.mycompany.webview (versionName: 129.0.6668.70, versionCode: 666807001, targetSdkVersion: 35) is installed/enabled for all users Valid package com.android.webview (versionName: 83.0.4103.120, versionCode: 410412053, targetSdkVersion: 30) is installed/enabled for all users So, what makes PackageInstaller produce this particular error (Valid package but note installed/enabled for all users), while adb install goes as it should? Maybe something about it being not installed/enabled for all users? Am I missing something with package installer? Here is my package installer code: val packageInstaller = applicationContext.packageManager.packageInstaller
            val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL)

            withContext(Dispatchers.IO) {
                val sessionId = packageInstaller.createSession(params)
                val session = packageInstaller.openSession(sessionId)
                val outputStream = session.openWrite("webview.apk", 0, -1)
                val buffer = ByteArray(65536)

                var bytesRead: Int
                while ((fileInputStream.read(buffer).also { bytesRead = it }) != -1) {
                    outputStream.write(buffer, 0, bytesRead)
                }

                session.fsync(outputStream)
                fileInputStream.close()
                outputStream.close()

                val intent: Intent = Intent(PACKAGE_INSTALLED_ACTION)
                val pendingIntent = PendingIntent.getBroadcast(
                    applicationContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT
                )

                session.commit(pendingIntent.intentSender)
            }

Torne (Richard Coles)

unread,
Feb 11, 2025, 1:30:29 PMFeb 11
to Nemanja Stijak, android-webview-dev
adb install will install new apps for all users on the device by default unless you explicitly tell it which user you want to install it for. Normal package installs from the PackageInstaller API only install new apps for the current user.

It looks like the device has com.android.webview preinstalled but you are trying to install a different package name com.mycompany.webview? That's not a recommended setup - we only support having multiple WebView packages in the configuration to enable development/testing use cases where users are going to manually switch versions. Also, in Android 15 and later we only support having *one* default WebView in the configuration.

If your goal is to update the device's existing WebView then it should have the same package name and signing keys as the preinstalled version, *not* a new package name. You should either preinstall com.mycompany.webview (and not use com.android.webview at all), or your updates should also be called com.android.webview and install directly over the preinstalled version.

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/911c6daf-6b2f-435c-83b3-ed7fb6d568c7n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages