aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tradefed/targetprep
diff options
context:
space:
mode:
authorJed Estep <jestep@google.com>2016-04-21 00:32:37 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-04-21 00:32:38 +0000
commit32b8a5e1e4d5920a4f111415c59cb542793ebfbf (patch)
tree5ba48012a1b5464cb0a36faea2dab8268c75cb79 /src/com/android/tradefed/targetprep
parent48b62a6882ea56726ebc5a9854d48281288b8f2d (diff)
parent71832c71d1fe049a1f898c231f9b0405028fe12d (diff)
downloadtradefederation-32b8a5e1e4d5920a4f111415c59cb542793ebfbf.tar.gz
Merge "Enable OtaFaultInjectionPreparer to sign packages"
Diffstat (limited to 'src/com/android/tradefed/targetprep')
-rw-r--r--src/com/android/tradefed/targetprep/OtaFaultInjectionPreparer.java105
1 files changed, 0 insertions, 105 deletions
diff --git a/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparer.java b/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparer.java
deleted file mode 100644
index 3a6f6fa7a..000000000
--- a/src/com/android/tradefed/targetprep/OtaFaultInjectionPreparer.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.tradefed.targetprep;
-
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.build.IDeviceBuildInfo;
-import com.android.tradefed.config.Option;
-import com.android.tradefed.device.DeviceNotAvailableException;
-import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.util.ArrayUtil;
-import com.android.tradefed.util.ZipUtil;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.zip.ZipOutputStream;
-
-/**
- * An {@link ITargetPreparer} that adds fault injection configuration to an OTA package ZIP.
- */
-public class OtaFaultInjectionPreparer implements ITargetPreparer {
-
- protected static final String CFG_BASE = ".libotafault";
-
- @Option(name = "read-fault-file", description = "the filename to trigger a read fault")
- protected String mReadFaultFile = null;
-
- @Option(name = "write-fault-file", description = "the filename to trigger a write fault")
- protected String mWriteFaultFile = null;
-
- @Option(name = "fsync-fault-file", description = "the filename to trigger a fsync fault")
- protected String mFsyncFaultFile = null;
-
- @Option(name = "hit-cache", description = "whether or not to hit /cache/saved.file instead of "
- + "the targeted file")
- protected boolean mShouldHitCache = false;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setUp(ITestDevice device, IBuildInfo buildInfo)
- throws TargetSetupError, BuildError, DeviceNotAvailableException {
- if (!(buildInfo instanceof IDeviceBuildInfo)) {
- throw new TargetSetupError(
- "OtaFaultInjectionPreparer must receive an IDeviceBuildInfo");
- }
- IDeviceBuildInfo deviceBuild = (IDeviceBuildInfo) buildInfo;
- ZipOutputStream otaPackageStream = null;
- try {
- otaPackageStream = new ZipOutputStream(
- new FileOutputStream(deviceBuild.getOtaPackageFile()));
- if (mReadFaultFile != null) {
- addToConfig(otaPackageStream, "READ", mReadFaultFile);
- }
- if (mWriteFaultFile != null) {
- addToConfig(otaPackageStream, "WRITE", mWriteFaultFile);
- }
- if (mFsyncFaultFile != null) {
- addToConfig(otaPackageStream, "FSYNC", mFsyncFaultFile);
- }
- if (mShouldHitCache) {
- addToConfig(otaPackageStream, "CACHE", "");
- }
- } catch (IOException e) {
- throw new TargetSetupError("Could not add config files to OTA zip", e);
- } finally {
- try {
- if (otaPackageStream != null) {
- otaPackageStream.close();
- }
- } catch (IOException e) {
- throw new TargetSetupError("Could not close OTA zip file", e);
- }
- }
- }
-
- private void addToConfig(ZipOutputStream packageStream, String ioType, String targetFile)
- throws IOException {
- File cfgFile = new File(ioType);
- try {
- FileWriter cfgWriter = new FileWriter(cfgFile);
- cfgWriter.write(targetFile, 0, targetFile.length());
- cfgWriter.close();
- ZipUtil.addToZip(packageStream, cfgFile,
- ArrayUtil.list(CFG_BASE, File.separator));
- } finally {
- cfgFile.delete();
- }
- }
-} \ No newline at end of file