| 1 |
/* |
| 2 |
* Copyright (C) 2010 Ryszard Wiśniewski <[email protected]> |
| 3 |
* Copyright (C) 2010 Connor Tumbleson <[email protected]> |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* https://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
*/ |
| 17 |
package brut.androlib.aapt2; |
| 18 |
|
| 19 |
import brut.androlib.*; |
| 20 |
import brut.androlib.options.BuildOptions; |
| 21 |
import brut.androlib.res.data.ResTable; |
| 22 |
import brut.common.BrutException; |
| 23 |
import brut.directory.ExtFile; |
| 24 |
import brut.util.OS; |
| 25 |
import org.junit.AfterClass; |
| 26 |
import org.junit.BeforeClass; |
| 27 |
import org.junit.Test; |
| 28 |
|
| 29 |
import java.io.File; |
| 30 |
|
| 31 |
import static org.junit.Assert.*; |
| 32 |
|
| 33 |
public class NonStandardPkgIdTest extends BaseTest { |
| 34 |
|
| 35 |
@BeforeClass |
| 36 |
public static void beforeClass() throws Exception { |
| 37 |
TestUtils.cleanFrameworkFile(); |
| 38 |
|
| 39 |
sTmpDir = new ExtFile(OS.createTempDirectory()); |
| 40 |
sTmpDir.deleteOnExit(); |
| 41 |
|
| 42 |
sTestOrigDir = new ExtFile(sTmpDir, "pkgid8-orig"); |
| 43 |
sTestNewDir = new ExtFile(sTmpDir, "pkgid8-new"); |
| 44 |
LOGGER.info("Unpacking pkgid8..."); |
| 45 |
TestUtils.copyResourceDir(BuildAndDecodeTest.class, "aapt2/pkgid8/", sTestOrigDir); |
| 46 |
|
| 47 |
BuildOptions buildOptions = new BuildOptions(); |
| 48 |
buildOptions.useAapt2 = true; |
| 49 |
buildOptions.verbose = true; |
| 50 |
|
| 51 |
LOGGER.info("Building pkgid8.apk..."); |
| 52 |
File testApk = new File(sTmpDir, "pkgid8.apk"); |
| 53 |
new Androlib(buildOptions).build(sTestOrigDir, testApk); |
| 54 |
|
| 55 |
LOGGER.info("Decoding pkgid8.apk..."); |
| 56 |
ApkDecoder apkDecoder = new ApkDecoder(testApk); |
| 57 |
apkDecoder.setOutDir(sTestNewDir); |
| 58 |
apkDecoder.decode(); |
| 59 |
mResTable = apkDecoder.getResTable(); |
| 60 |
} |
| 61 |
|
| 62 |
@AfterClass |
| 63 |
public static void afterClass() throws BrutException { |
| 64 |
OS.rmdir(sTmpDir); |
| 65 |
} |
| 66 |
|
| 67 |
@Test |
| 68 |
public void buildAndDecodeTest() { |
| 69 |
assertTrue(sTestNewDir.isDirectory()); |
| 70 |
} |
| 71 |
|
| 72 |
@Test |
| 73 |
public void valuesStringsTest() throws BrutException { |
| 74 |
compareValuesFiles("values/strings.xml"); |
| 75 |
} |
| 76 |
|
| 77 |
@Test |
| 78 |
public void confirmManifestStructureTest() throws BrutException { |
| 79 |
compareXmlFiles("AndroidManifest.xml"); |
| 80 |
} |
| 81 |
|
| 82 |
@Test |
| 83 |
public void confirmResourcesAreFromPkgId8() throws AndrolibException { |
| 84 |
assertEquals(0x80, mResTable.getPackageId()); |
| 85 |
|
| 86 |
assertEquals(0x80, mResTable.getResSpec(0x80020000).getPackage().getId()); |
| 87 |
assertEquals(0x80, mResTable.getResSpec(0x80020001).getPackage().getId()); |
| 88 |
assertEquals(0x80, mResTable.getResSpec(0x80030000).getPackage().getId()); |
| 89 |
} |
| 90 |
|
| 91 |
private static ResTable mResTable; |
| 92 |
} |