Merge "RRO: remove ability to overlay assets"
This commit is contained in:
committed by
Android (Google) Code Review
commit
a2a52be5eb
1
core/tests/overlaytests/device/assets/package-name.txt
Normal file
1
core/tests/overlaytests/device/assets/package-name.txt
Normal file
@@ -0,0 +1 @@
|
||||
com.android.overlaytest
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
foo
|
||||
@@ -0,0 +1 @@
|
||||
com.android.overlaytest.app_overlay_one
|
||||
@@ -0,0 +1 @@
|
||||
bar
|
||||
@@ -0,0 +1 @@
|
||||
com.android.overlaytest.app_overlay_two
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user