Skip to content

Commit

Permalink
New pass to reduce non-existent class loads
Browse files Browse the repository at this point in the history
Summary:
Inflating an .xml file to class instances is kinda strange. Elements in xml files for SDK classes are using the class simple name, which makes [PhoneLayoutInflater guess what package it is in](https://cs.android.com/android/platform/superproject/+/android-13.0.0_r1:frameworks/base/core/java/com/android/internal/policy/PhoneLayoutInflater.java;l=28?q=PhoneLayoutInflater&ss=android) at runtime. In practice, most of the elements will be either:
- application classes, which are fully qualified
- SDK classes for which PhoneLayoutInflater's first guess is correct

But, there are some classes for which the first few guesses are wrong, like: https://developer.android.com/reference/android/view/ViewStub?hl=en, https://developer.android.com/reference/android/view/View

This means in practice, load of non-existent `android.widget.ViewStub` is attempted and so is `android.webkit.ViewStub`, etc. These are probably not the ones the application developer is expecting.

We exploit the fact that [LayoutInflater looks for a special tag](https://cs.android.com/android/platform/superproject/+/android-13.0.0_r1:frameworks/base/core/java/android/view/LayoutInflater.java;l=986?q=LayoutInflater&ss=android) `<view class="fully qualified class name" />` and rewrite the binary files to use this form. Should save some erroneous class loads on startup.

Reviewed By: agampe

Differential Revision: D47616756

fbshipit-source-id: e47343517157175ee16e09f1c37edf5ec36816fd
  • Loading branch information
wsanville authored and facebook-github-bot committed Aug 14, 2023
1 parent 17bd16b commit 651e489
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/tests/ClassPropertiesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class MockAndroidResources : public AndroidResources {
return boost::none;
}

void fully_qualify_layout(
const std::unordered_map<std::string, std::string>&,
const std::string&,
size_t*) override {}

ManifestClassInfo get_manifest_class_info() override {
ManifestClassInfo info;

Expand Down

0 comments on commit 651e489

Please sign in to comment.