• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 org.eclipse.core.runtime.CoreException;
20 import org.eclipse.debug.core.ILaunchConfiguration;
21 
22 /**
23  * Launch configuration data. This stores the result of querying the
24  * {@link ILaunchConfiguration} so that it's only done once.
25  */
26 public class AndroidLaunchConfiguration {
27 
28     /**
29      * Launch action. See {@link LaunchConfigDelegate#ACTION_DEFAULT},
30      * {@link LaunchConfigDelegate#ACTION_ACTIVITY},
31      * {@link LaunchConfigDelegate#ACTION_DO_NOTHING}
32      */
33     public int mLaunchAction = LaunchConfigDelegate.DEFAULT_LAUNCH_ACTION;
34 
35     /**
36      * Target selection mode for the configuration: either {@link #AUTO} or {@link #MANUAL}.
37      */
38     public enum TargetMode {
39         /** Automatic target selection mode. */
40         AUTO(true),
41         /** Manual target selection mode. */
42         MANUAL(false);
43 
44         private boolean mValue;
45 
TargetMode(boolean value)46         TargetMode(boolean value) {
47             mValue = value;
48         }
49 
getValue()50         public boolean getValue() {
51             return mValue;
52         }
53 
getMode(boolean value)54         public static TargetMode getMode(boolean value) {
55             for (TargetMode mode : values()) {
56                 if (mode.mValue == value) {
57                     return mode;
58                 }
59             }
60 
61             return null;
62         }
63     }
64 
65     /**
66      * Target selection mode.
67      * @see TargetMode
68      */
69     public TargetMode mTargetMode = LaunchConfigDelegate.DEFAULT_TARGET_MODE;
70 
71     /**
72      * Indicates whether the emulator should be called with -wipe-data
73      */
74     public boolean mWipeData = LaunchConfigDelegate.DEFAULT_WIPE_DATA;
75 
76     /**
77      * Indicates whether the emulator should be called with -no-boot-anim
78      */
79     public boolean mNoBootAnim = LaunchConfigDelegate.DEFAULT_NO_BOOT_ANIM;
80 
81     /**
82      * AVD Name.
83      */
84     public String mAvdName = null;
85 
86     public String mNetworkSpeed = EmulatorConfigTab.getSpeed(
87             LaunchConfigDelegate.DEFAULT_SPEED);
88     public String mNetworkDelay = EmulatorConfigTab.getDelay(
89             LaunchConfigDelegate.DEFAULT_DELAY);
90 
91     /**
92      * Optional custom command line parameter to launch the emulator
93      */
94     public String mEmulatorCommandLine;
95 
96     /**
97      * Initialized the structure from an ILaunchConfiguration object.
98      * @param config
99      */
set(ILaunchConfiguration config)100     public void set(ILaunchConfiguration config) {
101         try {
102             mLaunchAction = config.getAttribute(LaunchConfigDelegate.ATTR_LAUNCH_ACTION,
103                     mLaunchAction);
104         } catch (CoreException e1) {
105             // nothing to be done here, we'll use the default value
106         }
107 
108         try {
109             boolean value = config.getAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE,
110                     mTargetMode.getValue());
111             mTargetMode = TargetMode.getMode(value);
112         } catch (CoreException e) {
113             // nothing to be done here, we'll use the default value
114         }
115 
116         try {
117             mAvdName = config.getAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, mAvdName);
118         } catch (CoreException e) {
119             // ignore
120         }
121 
122         int index = LaunchConfigDelegate.DEFAULT_SPEED;
123         try {
124             index = config.getAttribute(LaunchConfigDelegate.ATTR_SPEED, index);
125         } catch (CoreException e) {
126             // nothing to be done here, we'll use the default value
127         }
128         mNetworkSpeed = EmulatorConfigTab.getSpeed(index);
129 
130         index = LaunchConfigDelegate.DEFAULT_DELAY;
131         try {
132             index = config.getAttribute(LaunchConfigDelegate.ATTR_DELAY, index);
133         } catch (CoreException e) {
134             // nothing to be done here, we'll use the default value
135         }
136         mNetworkDelay = EmulatorConfigTab.getDelay(index);
137 
138         try {
139             mEmulatorCommandLine = config.getAttribute(
140                     LaunchConfigDelegate.ATTR_COMMANDLINE, ""); //$NON-NLS-1$
141         } catch (CoreException e) {
142             // lets not do anything here, we'll use the default value
143         }
144 
145         try {
146             mWipeData = config.getAttribute(LaunchConfigDelegate.ATTR_WIPE_DATA, mWipeData);
147         } catch (CoreException e) {
148             // nothing to be done here, we'll use the default value
149         }
150 
151         try {
152             mNoBootAnim = config.getAttribute(LaunchConfigDelegate.ATTR_NO_BOOT_ANIM,
153                                               mNoBootAnim);
154         } catch (CoreException e) {
155             // nothing to be done here, we'll use the default value
156         }
157     }
158 }
159 
160