1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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 com.android.ide.eclipse.adt.internal.launch; 18 19 import com.android.ddmlib.IDevice; 20 21 import org.eclipse.core.resources.IFile; 22 import org.eclipse.core.resources.IProject; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 25 /** 26 * A delayed launch waiting for a device to be present or ready before the 27 * application is launched. 28 */ 29 public final class DelayedLaunchInfo { 30 31 /** 32 * Used to indicate behavior when Android app already exists 33 */ 34 enum InstallRetryMode { 35 NEVER, ALWAYS, PROMPT; 36 } 37 38 /** The device on which to launch the app */ 39 private IDevice mDevice = null; 40 41 /** The eclipse project */ 42 private final IProject mProject; 43 44 /** Package name */ 45 private final String mPackageName; 46 47 /** Debug package name */ 48 private final String mDebugPackageName; 49 50 /** IFile to the package (.apk) file */ 51 private final IFile mPackageFile; 52 53 /** debuggable attribute of the manifest file. */ 54 private final Boolean mDebuggable; 55 56 /** Required Api level by the app. null means no requirements */ 57 private final String mRequiredApiVersionNumber; 58 59 private InstallRetryMode mRetryMode = InstallRetryMode.NEVER; 60 61 /** Launch action. */ 62 private final IAndroidLaunchAction mLaunchAction; 63 64 /** the launch object */ 65 private final AndroidLaunch mLaunch; 66 67 /** the monitor object */ 68 private final IProgressMonitor mMonitor; 69 70 /** debug mode flag */ 71 private boolean mDebugMode; 72 73 /** current number of launch attempts */ 74 private int mAttemptCount = 0; 75 76 /** cancellation state of launch */ 77 private boolean mCancelled = false; 78 79 /** 80 * Basic constructor with activity and package info. 81 * 82 * @param project the eclipse project that corresponds to Android app 83 * @param packageName package name of Android app 84 * @param debugPackageName the package name of the Andriod app to debug 85 * @param launchAction action to perform after app install 86 * @param pack IFile to the package (.apk) file 87 * @param debuggable debuggable attribute of the app's manifest file. 88 * @param requiredApiVersionNumber required SDK version by the app. null means no requirements. 89 * @param launch the launch object 90 * @param monitor progress monitor for launch 91 */ DelayedLaunchInfo(IProject project, String packageName, String debugPackageName, IAndroidLaunchAction launchAction, IFile pack, Boolean debuggable, String requiredApiVersionNumber, AndroidLaunch launch, IProgressMonitor monitor)92 public DelayedLaunchInfo(IProject project, String packageName, String debugPackageName, 93 IAndroidLaunchAction launchAction, IFile pack, Boolean debuggable, 94 String requiredApiVersionNumber, AndroidLaunch launch, IProgressMonitor monitor) { 95 mProject = project; 96 mPackageName = packageName; 97 mDebugPackageName = debugPackageName; 98 mPackageFile = pack; 99 mLaunchAction = launchAction; 100 mLaunch = launch; 101 mMonitor = monitor; 102 mDebuggable = debuggable; 103 mRequiredApiVersionNumber = requiredApiVersionNumber; 104 } 105 106 /** 107 * @return the device on which to launch the app 108 */ getDevice()109 public IDevice getDevice() { 110 return mDevice; 111 } 112 113 /** 114 * Set the device on which to launch the app 115 */ setDevice(IDevice device)116 public void setDevice(IDevice device) { 117 mDevice = device; 118 } 119 120 /** 121 * @return the eclipse project that corresponds to Android app 122 */ getProject()123 public IProject getProject() { 124 return mProject; 125 } 126 127 /** 128 * @return the package name of the Android app 129 */ getPackageName()130 public String getPackageName() { 131 return mPackageName; 132 } 133 134 /** 135 * Returns the Android app process name that the debugger should connect to. Typically this is 136 * the same value as {@link #getPackageName()}. 137 */ getDebugPackageName()138 public String getDebugPackageName() { 139 if (mDebugPackageName == null) { 140 return getPackageName(); 141 } 142 return mDebugPackageName; 143 } 144 145 /** 146 * @return the application package file 147 */ getPackageFile()148 public IFile getPackageFile() { 149 return mPackageFile; 150 } 151 152 /** 153 * @return true if Android app is marked as debuggable in its manifest 154 */ getDebuggable()155 public Boolean getDebuggable() { 156 return mDebuggable; 157 } 158 159 /** 160 * @return the required api version number for the Android app. 161 */ getRequiredApiVersionNumber()162 public String getRequiredApiVersionNumber() { 163 return mRequiredApiVersionNumber; 164 } 165 166 /** 167 * @param retryMode the install retry mode to set 168 */ setRetryMode(InstallRetryMode retryMode)169 public void setRetryMode(InstallRetryMode retryMode) { 170 this.mRetryMode = retryMode; 171 } 172 173 /** 174 * @return the installation retry mode 175 */ getRetryMode()176 public InstallRetryMode getRetryMode() { 177 return mRetryMode; 178 } 179 180 /** 181 * @return the launch action 182 */ getLaunchAction()183 public IAndroidLaunchAction getLaunchAction() { 184 return mLaunchAction; 185 } 186 187 /** 188 * @return the launch 189 */ getLaunch()190 public AndroidLaunch getLaunch() { 191 return mLaunch; 192 } 193 194 /** 195 * @return the launch progress monitor 196 */ getMonitor()197 public IProgressMonitor getMonitor() { 198 return mMonitor; 199 } 200 201 /** 202 * @param debugMode the debug mode to set 203 */ setDebugMode(boolean debugMode)204 public void setDebugMode(boolean debugMode) { 205 this.mDebugMode = debugMode; 206 } 207 208 /** 209 * @return true if this is a debug launch 210 */ isDebugMode()211 public boolean isDebugMode() { 212 return mDebugMode; 213 } 214 215 /** 216 * Increases the number of launch attempts 217 */ incrementAttemptCount()218 public void incrementAttemptCount() { 219 mAttemptCount++; 220 } 221 222 /** 223 * @return the number of launch attempts made 224 */ getAttemptCount()225 public int getAttemptCount() { 226 return mAttemptCount; 227 } 228 229 /** 230 * Set if launch has been cancelled 231 */ setCancelled(boolean cancelled)232 public void setCancelled(boolean cancelled) { 233 this.mCancelled = cancelled; 234 } 235 236 /** 237 * @return true if launch has been cancelled 238 */ isCancelled()239 public boolean isCancelled() { 240 return mCancelled; 241 } 242 } 243