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 the debuggable value of the app's manifest, or null if not set.
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      * Returns the value of the manifest debuggable attribute. If the attribute was not set,
154      * then the method returns null.
155      * @return the manifest debuggable attribute.
156      */
getDebuggable()157     public Boolean getDebuggable() {
158         return mDebuggable;
159     }
160 
161     /**
162      * @return the required api version number for the Android app.
163      */
getRequiredApiVersionNumber()164     public String getRequiredApiVersionNumber() {
165         return mRequiredApiVersionNumber;
166     }
167 
168     /**
169      * @param retryMode the install retry mode to set
170      */
setRetryMode(InstallRetryMode retryMode)171     public void setRetryMode(InstallRetryMode retryMode) {
172         this.mRetryMode = retryMode;
173     }
174 
175     /**
176      * @return the installation retry mode
177      */
getRetryMode()178     public InstallRetryMode getRetryMode() {
179         return mRetryMode;
180     }
181 
182     /**
183      * @return the launch action
184      */
getLaunchAction()185     public IAndroidLaunchAction getLaunchAction() {
186         return mLaunchAction;
187     }
188 
189     /**
190      * @return the launch
191      */
getLaunch()192     public AndroidLaunch getLaunch() {
193         return mLaunch;
194     }
195 
196     /**
197      * @return the launch progress monitor
198      */
getMonitor()199     public IProgressMonitor getMonitor() {
200         return mMonitor;
201     }
202 
203     /**
204      * @param debugMode the debug mode to set
205      */
setDebugMode(boolean debugMode)206     public void setDebugMode(boolean debugMode) {
207         this.mDebugMode = debugMode;
208     }
209 
210     /**
211      * @return true if this is a debug launch
212      */
isDebugMode()213     public boolean isDebugMode() {
214         return mDebugMode;
215     }
216 
217     /**
218      * Increases the number of launch attempts
219      */
incrementAttemptCount()220     public void incrementAttemptCount() {
221         mAttemptCount++;
222     }
223 
224     /**
225      * @return the number of launch attempts made
226      */
getAttemptCount()227     public int getAttemptCount() {
228         return mAttemptCount;
229     }
230 
231     /**
232      * Set if launch has been cancelled
233      */
setCancelled(boolean cancelled)234     public void setCancelled(boolean cancelled) {
235         this.mCancelled = cancelled;
236     }
237 
238     /**
239      * @return true if launch has been cancelled
240      */
isCancelled()241     public boolean isCancelled() {
242         return mCancelled;
243     }
244 }
245