Loading services/tests/servicestests/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ android_test { ":PackageParserTestApp1", ":PackageParserTestApp2", ":PackageParserTestApp3", ":apex.test", ], resource_zips: [":FrameworksServicesTests_apks_as_resources"], } Loading services/tests/servicestests/res/raw/apex_test.apexdeleted 100644 → 0 −311 KiB File deleted. View file services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java +22 −20 Original line number Diff line number Diff line Loading @@ -36,7 +36,6 @@ import android.apex.ApexSessionParams; import android.apex.IApexService; import android.content.Context; import android.content.pm.PackageInfo; import android.os.FileUtils; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; Loading @@ -44,7 +43,6 @@ import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.frameworks.servicestests.R; import com.android.server.pm.parsing.PackageParser2; import com.android.server.pm.parsing.TestPackageParser2; Loading @@ -52,11 +50,12 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @SmallTest @Presubmit Loading @@ -64,6 +63,7 @@ import java.io.InputStream; public class ApexManagerTest { private static final String TEST_APEX_PKG = "com.android.apex.test"; private static final String TEST_APEX_FILE_NAME = "apex.test.apex"; private static final int TEST_SESSION_ID = 99999999; private static final int[] TEST_CHILD_SESSION_ID = {8888, 7777}; private ApexManager mApexManager; Loading Loading @@ -274,7 +274,7 @@ public class ApexManagerTest { } private ApexInfo[] createApexInfo(boolean isActive, boolean isFactory) { File apexFile = copyRawResourceToFile(TEST_APEX_PKG, R.raw.apex_test); File apexFile = extractResource(TEST_APEX_PKG, TEST_APEX_FILE_NAME); ApexInfo apexInfo = new ApexInfo(); apexInfo.isActive = isActive; apexInfo.isFactory = isFactory; Loading Loading @@ -308,27 +308,29 @@ public class ApexManagerTest { return params; } /** * Copies a specified {@code resourceId} to a temp file. Returns a non-null file if the copy * succeeded */ File copyRawResourceToFile(String baseName, int resourceId) { File outFile; // Extracts the binary data from a resource and writes it to a temp file private static File extractResource(String baseName, String fullResourceName) { File file; try { outFile = File.createTempFile(baseName, ".apex"); file = File.createTempFile(baseName, ".apex"); } catch (IOException e) { throw new AssertionError("CreateTempFile IOException" + e); } try (InputStream is = mContext.getResources().openRawResource(resourceId); FileOutputStream os = new FileOutputStream(outFile)) { assertThat(FileUtils.copy(is, os)).isGreaterThan(0L); } catch (FileNotFoundException e) { throw new AssertionError("File not found exception " + e); try ( InputStream in = ApexManager.class.getClassLoader() .getResourceAsStream(fullResourceName); OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { if (in == null) { throw new IllegalArgumentException("Resource not found: " + fullResourceName); } byte[] buf = new byte[65536]; int chunkSize; while ((chunkSize = in.read(buf)) != -1) { out.write(buf, 0, chunkSize); } return file; } catch (IOException e) { throw new AssertionError("IOException" + e); throw new AssertionError("Exception while converting stream to file" + e); } return outFile; } } Loading
services/tests/servicestests/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,7 @@ android_test { ":PackageParserTestApp1", ":PackageParserTestApp2", ":PackageParserTestApp3", ":apex.test", ], resource_zips: [":FrameworksServicesTests_apks_as_resources"], } Loading
services/tests/servicestests/res/raw/apex_test.apexdeleted 100644 → 0 −311 KiB File deleted. View file
services/tests/servicestests/src/com/android/server/pm/ApexManagerTest.java +22 −20 Original line number Diff line number Diff line Loading @@ -36,7 +36,6 @@ import android.apex.ApexSessionParams; import android.apex.IApexService; import android.content.Context; import android.content.pm.PackageInfo; import android.os.FileUtils; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; Loading @@ -44,7 +43,6 @@ import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import com.android.frameworks.servicestests.R; import com.android.server.pm.parsing.PackageParser2; import com.android.server.pm.parsing.TestPackageParser2; Loading @@ -52,11 +50,12 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @SmallTest @Presubmit Loading @@ -64,6 +63,7 @@ import java.io.InputStream; public class ApexManagerTest { private static final String TEST_APEX_PKG = "com.android.apex.test"; private static final String TEST_APEX_FILE_NAME = "apex.test.apex"; private static final int TEST_SESSION_ID = 99999999; private static final int[] TEST_CHILD_SESSION_ID = {8888, 7777}; private ApexManager mApexManager; Loading Loading @@ -274,7 +274,7 @@ public class ApexManagerTest { } private ApexInfo[] createApexInfo(boolean isActive, boolean isFactory) { File apexFile = copyRawResourceToFile(TEST_APEX_PKG, R.raw.apex_test); File apexFile = extractResource(TEST_APEX_PKG, TEST_APEX_FILE_NAME); ApexInfo apexInfo = new ApexInfo(); apexInfo.isActive = isActive; apexInfo.isFactory = isFactory; Loading Loading @@ -308,27 +308,29 @@ public class ApexManagerTest { return params; } /** * Copies a specified {@code resourceId} to a temp file. Returns a non-null file if the copy * succeeded */ File copyRawResourceToFile(String baseName, int resourceId) { File outFile; // Extracts the binary data from a resource and writes it to a temp file private static File extractResource(String baseName, String fullResourceName) { File file; try { outFile = File.createTempFile(baseName, ".apex"); file = File.createTempFile(baseName, ".apex"); } catch (IOException e) { throw new AssertionError("CreateTempFile IOException" + e); } try (InputStream is = mContext.getResources().openRawResource(resourceId); FileOutputStream os = new FileOutputStream(outFile)) { assertThat(FileUtils.copy(is, os)).isGreaterThan(0L); } catch (FileNotFoundException e) { throw new AssertionError("File not found exception " + e); try ( InputStream in = ApexManager.class.getClassLoader() .getResourceAsStream(fullResourceName); OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { if (in == null) { throw new IllegalArgumentException("Resource not found: " + fullResourceName); } byte[] buf = new byte[65536]; int chunkSize; while ((chunkSize = in.read(buf)) != -1) { out.write(buf, 0, chunkSize); } return file; } catch (IOException e) { throw new AssertionError("IOException" + e); throw new AssertionError("Exception while converting stream to file" + e); } return outFile; } }