Ensure the dex use database cannot grow unboundedly.

Its size can theoretically be

  O(<owning package> X <dex path> X <loading package>)

Owning and loading packages are limited by the valid entries in the
package database. Dex paths from primary dex'es are also limited by the
installed packages. However dex paths for secondary dex'es can
potentially be unbounded, so impose a limit on them.

The limit is fixed for any given owning package, which is simpler than
limiting based on loading package. That restricts a package from adding
an arbitrary number of secondary dex files in itself. Also check that
the dex file exists if the loading package is different from the owning
one, so that the former cannot consume entries up to the limit for the
latter.

The class loader context strings for secondary dex files are also not
guaranteed bounded, so impose a limit on them as well.

Test: atest DexUseManagerTest
Test: Install app_debug.apk from b/391895923  #comment3 and verify that
      it can run until OOM repeatedly without growing the database to
      more than 650 KiB.
Bug: 391895923
Flag: EXEMPT bugfix
Ignore-AOSP-First: Security fix
(cherry picked from commit e29eb53ebf11fdb891762db7dd927e95a0858fc0)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:1c45139acc64ad0990ce8038f7188ada3b91c81c)
Merged-In: Ic50bf22000730282d90a4f6aa1c49379357fe77a
Change-Id: Ic50bf22000730282d90a4f6aa1c49379357fe77a
3 files changed