Merge "RRO: remove ability to overlay assets"

This commit is contained in:
TreeHugger Robot
2019-03-20 16:49:11 +00:00
committed by Android (Google) Code Review
8 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1 @@
com.android.overlaytest

View File

@@ -17,9 +17,12 @@
package com.android.overlaytest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.app.UiAutomation;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
@@ -30,6 +33,8 @@ import android.util.Xml;
import androidx.test.InstrumentationRegistry;
import com.android.internal.util.ArrayUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@@ -291,6 +296,33 @@ public abstract class OverlayBaseTest {
assertEquals(getExpected(no, so, mo), actual);
}
@Test
public void testAssetsNotPossibleToOverlay() throws Throwable {
final AssetManager am = mResources.getAssets();
// AssetManager#list will include assets from all loaded non-overlay
// APKs, including the framework; framework-res.apk contains at least
// assets/{images,webkit}. Rather than checking the list, verify that
// assets only present in overlays are never part of the list.
String[] files = am.list("");
assertTrue(ArrayUtils.contains(files, "package-name.txt"));
assertFalse(ArrayUtils.contains(files, "foo.txt"));
assertFalse(ArrayUtils.contains(files, "bar.txt"));
String contents = null;
try (InputStream is = am.open("package-name.txt")) {
final BufferedReader reader = new BufferedReader(
new InputStreamReader(is, StandardCharsets.UTF_8));
StringBuilder str = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
str.append(line);
}
contents = str.toString();
}
assertEquals("com.android.overlaytest", contents);
}
/*
* testMatrix* tests
*

View File

@@ -0,0 +1 @@
com.android.overlaytest.app_overlay_one

View File

@@ -0,0 +1 @@
com.android.overlaytest.app_overlay_two

View File

@@ -310,6 +310,9 @@ std::unique_ptr<AssetDir> AssetManager2::OpenDir(const std::string& dirname) con
// Start from the back.
for (auto iter = apk_assets_.rbegin(); iter != apk_assets_.rend(); ++iter) {
const ApkAssets* apk_assets = *iter;
if (apk_assets->IsOverlay()) {
continue;
}
auto func = [&](const StringPiece& name, FileType type) {
AssetDir::FileInfo info;
@@ -336,6 +339,13 @@ std::unique_ptr<Asset> AssetManager2::OpenNonAsset(const std::string& filename,
Asset::AccessMode mode,
ApkAssetsCookie* out_cookie) const {
for (int32_t i = apk_assets_.size() - 1; i >= 0; i--) {
// Prevent RRO from modifying assets and other entries accessed by file
// path. Explicitly asking for a path in a given package (denoted by a
// cookie) is still OK.
if (apk_assets_[i]->IsOverlay()) {
continue;
}
std::unique_ptr<Asset> asset = apk_assets_[i]->Open(filename, mode);
if (asset) {
if (out_cookie != nullptr) {

View File

@@ -80,6 +80,10 @@ class ApkAssets {
return loaded_arsc_.get();
}
inline bool IsOverlay() const {
return idmap_asset_.get() != nullptr;
}
private:
DISALLOW_COPY_AND_ASSIGN(ApkAssets);