1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package vogar.android; 18 19 import java.io.File; 20 import java.util.Collections; 21 import java.util.LinkedHashSet; 22 import java.util.Set; 23 import vogar.Action; 24 import vogar.Classpath; 25 import vogar.Mode; 26 import vogar.Run; 27 import vogar.commands.VmCommandBuilder; 28 import vogar.tasks.ExtractJarResourceTask; 29 import vogar.tasks.Task; 30 31 /** 32 * Runs an action in the context of an android.app.Activity on a device 33 */ 34 public final class ActivityMode implements Mode { 35 private final Run run; 36 ActivityMode(Run run)37 public ActivityMode(Run run) { 38 this.run = run; 39 } 40 installTasks()41 @Override public Set<Task> installTasks() { 42 return Collections.<Task>singleton( 43 new ExtractJarResourceTask("/vogar/vogar.keystore", run.keystore)); 44 } 45 installActionTasks(Action action, File jar)46 @Override public Set<Task> installActionTasks(Action action, File jar) { 47 return Collections.<Task>singleton(new InstallApkTask(run, action, jar)); 48 } 49 executeActionTask(Action action, boolean useLargeTimeout)50 @Override public Task executeActionTask(Action action, boolean useLargeTimeout) { 51 return new RunActivityTask(run, action, useLargeTimeout); 52 } 53 cleanupTasks(Action action)54 @Override public Set<Task> cleanupTasks(Action action) { 55 Set<Task> result = new LinkedHashSet<Task>(); 56 result.add(run.target.rmTask(action.getUserDir())); 57 result.add(new UninstallApkTask(run.androidSdk, action.getName())); 58 return result; 59 } 60 newVmCommandBuilder(Action action, File workingDirectory)61 @Override public VmCommandBuilder newVmCommandBuilder(Action action, File workingDirectory) { 62 throw new UnsupportedOperationException(); 63 } 64 getRuntimeClasspath(Action action)65 @Override public Classpath getRuntimeClasspath(Action action) { 66 throw new UnsupportedOperationException(); 67 } 68 } 69