1/*
2 * Copyright (C) 2007 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
17package android.content.pm;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.util.Printer;
22
23/**
24 * Information you can retrieve about a particular application
25 * activity or receiver. This corresponds to information collected
26 * from the AndroidManifest.xml's <activity> and
27 * <receiver> tags.
28 */
29public class ActivityInfo extends ComponentInfo
30        implements Parcelable {
31    /**
32     * A style resource identifier (in the package's resources) of this
33     * activity's theme.  From the "theme" attribute or, if not set, 0.
34     */
35    public int theme;
36
37    /**
38     * Constant corresponding to <code>standard</code> in
39     * the {@link android.R.attr#launchMode} attribute.
40     */
41    public static final int LAUNCH_MULTIPLE = 0;
42    /**
43     * Constant corresponding to <code>singleTop</code> in
44     * the {@link android.R.attr#launchMode} attribute.
45     */
46    public static final int LAUNCH_SINGLE_TOP = 1;
47    /**
48     * Constant corresponding to <code>singleTask</code> in
49     * the {@link android.R.attr#launchMode} attribute.
50     */
51    public static final int LAUNCH_SINGLE_TASK = 2;
52    /**
53     * Constant corresponding to <code>singleInstance</code> in
54     * the {@link android.R.attr#launchMode} attribute.
55     */
56    public static final int LAUNCH_SINGLE_INSTANCE = 3;
57    /**
58     * The launch mode style requested by the activity.  From the
59     * {@link android.R.attr#launchMode} attribute, one of
60     * {@link #LAUNCH_MULTIPLE},
61     * {@link #LAUNCH_SINGLE_TOP}, {@link #LAUNCH_SINGLE_TASK}, or
62     * {@link #LAUNCH_SINGLE_INSTANCE}.
63     */
64    public int launchMode;
65
66    /**
67     * Optional name of a permission required to be able to access this
68     * Activity.  From the "permission" attribute.
69     */
70    public String permission;
71
72    /**
73     * The affinity this activity has for another task in the system.  The
74     * string here is the name of the task, often the package name of the
75     * overall package.  If null, the activity has no affinity.  Set from the
76     * {@link android.R.attr#taskAffinity} attribute.
77     */
78    public String taskAffinity;
79
80    /**
81     * If this is an activity alias, this is the real activity class to run
82     * for it.  Otherwise, this is null.
83     */
84    public String targetActivity;
85
86    /**
87     * Bit in {@link #flags} indicating whether this activity is able to
88     * run in multiple processes.  If
89     * true, the system may instantiate it in the some process as the
90     * process starting it in order to conserve resources.  If false, the
91     * default, it always runs in {@link #processName}.  Set from the
92     * {@link android.R.attr#multiprocess} attribute.
93     */
94    public static final int FLAG_MULTIPROCESS = 0x0001;
95    /**
96     * Bit in {@link #flags} indicating that, when the activity's task is
97     * relaunched from home, this activity should be finished.
98     * Set from the
99     * {@link android.R.attr#finishOnTaskLaunch} attribute.
100     */
101    public static final int FLAG_FINISH_ON_TASK_LAUNCH = 0x0002;
102    /**
103     * Bit in {@link #flags} indicating that, when the activity is the root
104     * of a task, that task's stack should be cleared each time the user
105     * re-launches it from home.  As a result, the user will always
106     * return to the original activity at the top of the task.
107     * This flag only applies to activities that
108     * are used to start the root of a new task.  Set from the
109     * {@link android.R.attr#clearTaskOnLaunch} attribute.
110     */
111    public static final int FLAG_CLEAR_TASK_ON_LAUNCH = 0x0004;
112    /**
113     * Bit in {@link #flags} indicating that, when the activity is the root
114     * of a task, that task's stack should never be cleared when it is
115     * relaunched from home.  Set from the
116     * {@link android.R.attr#alwaysRetainTaskState} attribute.
117     */
118    public static final int FLAG_ALWAYS_RETAIN_TASK_STATE = 0x0008;
119    /**
120     * Bit in {@link #flags} indicating that the activity's state
121     * is not required to be saved, so that if there is a failure the
122     * activity will not be removed from the activity stack.  Set from the
123     * {@link android.R.attr#stateNotNeeded} attribute.
124     */
125    public static final int FLAG_STATE_NOT_NEEDED = 0x0010;
126    /**
127     * Bit in {@link #flags} that indicates that the activity should not
128     * appear in the list of recently launched activities.  Set from the
129     * {@link android.R.attr#excludeFromRecents} attribute.
130     */
131    public static final int FLAG_EXCLUDE_FROM_RECENTS = 0x0020;
132    /**
133     * Bit in {@link #flags} that indicates that the activity can be moved
134     * between tasks based on its task affinity.  Set from the
135     * {@link android.R.attr#allowTaskReparenting} attribute.
136     */
137    public static final int FLAG_ALLOW_TASK_REPARENTING = 0x0040;
138    /**
139     * Bit in {@link #flags} indicating that, when the user navigates away
140     * from an activity, it should be finished.
141     * Set from the
142     * {@link android.R.attr#noHistory} attribute.
143     */
144    public static final int FLAG_NO_HISTORY = 0x0080;
145    /**
146     * Bit in {@link #flags} indicating that, when a request to close system
147     * windows happens, this activity is finished.
148     * Set from the
149     * {@link android.R.attr#finishOnCloseSystemDialogs} attribute.
150     */
151    public static final int FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS = 0x0100;
152    /**
153     * Options that have been set in the activity declaration in the
154     * manifest: {@link #FLAG_MULTIPROCESS},
155     * {@link #FLAG_FINISH_ON_TASK_LAUNCH}, {@link #FLAG_CLEAR_TASK_ON_LAUNCH},
156     * {@link #FLAG_ALWAYS_RETAIN_TASK_STATE},
157     * {@link #FLAG_STATE_NOT_NEEDED}, {@link #FLAG_EXCLUDE_FROM_RECENTS},
158     * {@link #FLAG_ALLOW_TASK_REPARENTING}, {@link #FLAG_NO_HISTORY},
159     * {@link #FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS}.
160     */
161    public int flags;
162
163    /**
164     * Constant corresponding to <code>unspecified</code> in
165     * the {@link android.R.attr#screenOrientation} attribute.
166     */
167    public static final int SCREEN_ORIENTATION_UNSPECIFIED = -1;
168    /**
169     * Constant corresponding to <code>landscape</code> in
170     * the {@link android.R.attr#screenOrientation} attribute.
171     */
172    public static final int SCREEN_ORIENTATION_LANDSCAPE = 0;
173    /**
174     * Constant corresponding to <code>portrait</code> in
175     * the {@link android.R.attr#screenOrientation} attribute.
176     */
177    public static final int SCREEN_ORIENTATION_PORTRAIT = 1;
178    /**
179     * Constant corresponding to <code>user</code> in
180     * the {@link android.R.attr#screenOrientation} attribute.
181     */
182    public static final int SCREEN_ORIENTATION_USER = 2;
183    /**
184     * Constant corresponding to <code>behind</code> in
185     * the {@link android.R.attr#screenOrientation} attribute.
186     */
187    public static final int SCREEN_ORIENTATION_BEHIND = 3;
188    /**
189     * Constant corresponding to <code>sensor</code> in
190     * the {@link android.R.attr#screenOrientation} attribute.
191     */
192    public static final int SCREEN_ORIENTATION_SENSOR = 4;
193
194    /**
195     * Constant corresponding to <code>sensor</code> in
196     * the {@link android.R.attr#screenOrientation} attribute.
197     */
198    public static final int SCREEN_ORIENTATION_NOSENSOR = 5;
199    /**
200     * The preferred screen orientation this activity would like to run in.
201     * From the {@link android.R.attr#screenOrientation} attribute, one of
202     * {@link #SCREEN_ORIENTATION_UNSPECIFIED},
203     * {@link #SCREEN_ORIENTATION_LANDSCAPE},
204     * {@link #SCREEN_ORIENTATION_PORTRAIT},
205     * {@link #SCREEN_ORIENTATION_USER},
206     * {@link #SCREEN_ORIENTATION_BEHIND},
207     * {@link #SCREEN_ORIENTATION_SENSOR},
208     * {@link #SCREEN_ORIENTATION_NOSENSOR}.
209     */
210    public int screenOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
211
212    /**
213     * Bit in {@link #configChanges} that indicates that the activity
214     * can itself handle changes to the IMSI MCC.  Set from the
215     * {@link android.R.attr#configChanges} attribute.
216     */
217    public static final int CONFIG_MCC = 0x0001;
218    /**
219     * Bit in {@link #configChanges} that indicates that the activity
220     * can itself handle changes to the IMSI MNC.  Set from the
221     * {@link android.R.attr#configChanges} attribute.
222     */
223    public static final int CONFIG_MNC = 0x0002;
224    /**
225     * Bit in {@link #configChanges} that indicates that the activity
226     * can itself handle changes to the locale.  Set from the
227     * {@link android.R.attr#configChanges} attribute.
228     */
229    public static final int CONFIG_LOCALE = 0x0004;
230    /**
231     * Bit in {@link #configChanges} that indicates that the activity
232     * can itself handle changes to the touchscreen type.  Set from the
233     * {@link android.R.attr#configChanges} attribute.
234     */
235    public static final int CONFIG_TOUCHSCREEN = 0x0008;
236    /**
237     * Bit in {@link #configChanges} that indicates that the activity
238     * can itself handle changes to the keyboard type.  Set from the
239     * {@link android.R.attr#configChanges} attribute.
240     */
241    public static final int CONFIG_KEYBOARD = 0x0010;
242    /**
243     * Bit in {@link #configChanges} that indicates that the activity
244     * can itself handle changes to the keyboard or navigation being hidden/exposed.
245     * Note that inspite of the name, this applies to the changes to any
246     * hidden states: keyboard or navigation.
247     * Set from the {@link android.R.attr#configChanges} attribute.
248     */
249    public static final int CONFIG_KEYBOARD_HIDDEN = 0x0020;
250    /**
251     * Bit in {@link #configChanges} that indicates that the activity
252     * can itself handle changes to the navigation type.  Set from the
253     * {@link android.R.attr#configChanges} attribute.
254     */
255    public static final int CONFIG_NAVIGATION = 0x0040;
256    /**
257     * Bit in {@link #configChanges} that indicates that the activity
258     * can itself handle changes to the screen orientation.  Set from the
259     * {@link android.R.attr#configChanges} attribute.
260     */
261    public static final int CONFIG_ORIENTATION = 0x0080;
262    /**
263     * Bit in {@link #configChanges} that indicates that the activity
264     * can itself handle changes to the screen layout.  Set from the
265     * {@link android.R.attr#configChanges} attribute.
266     */
267    public static final int CONFIG_SCREEN_LAYOUT = 0x0100;
268    /**
269     * Bit in {@link #configChanges} that indicates that the activity
270     * can itself handle the ui mode. Set from the
271     * {@link android.R.attr#configChanges} attribute.
272     */
273    public static final int CONFIG_UI_MODE = 0x0200;
274    /**
275     * Bit in {@link #configChanges} that indicates that the activity
276     * can itself handle changes to the font scaling factor.  Set from the
277     * {@link android.R.attr#configChanges} attribute.  This is
278     * not a core resource configutation, but a higher-level value, so its
279     * constant starts at the high bits.
280     */
281    public static final int CONFIG_FONT_SCALE = 0x40000000;
282
283    /**
284     * Bit mask of kinds of configuration changes that this activity
285     * can handle itself (without being restarted by the system).
286     * Contains any combination of {@link #CONFIG_FONT_SCALE},
287     * {@link #CONFIG_MCC}, {@link #CONFIG_MNC},
288     * {@link #CONFIG_LOCALE}, {@link #CONFIG_TOUCHSCREEN},
289     * {@link #CONFIG_KEYBOARD}, {@link #CONFIG_NAVIGATION},
290     * {@link #CONFIG_ORIENTATION}, and {@link #CONFIG_SCREEN_LAYOUT}.  Set from the
291     * {@link android.R.attr#configChanges} attribute.
292     */
293    public int configChanges;
294
295    /**
296     * The desired soft input mode for this activity's main window.
297     * Set from the {@link android.R.attr#windowSoftInputMode} attribute
298     * in the activity's manifest.  May be any of the same values allowed
299     * for {@link android.view.WindowManager.LayoutParams#softInputMode
300     * WindowManager.LayoutParams.softInputMode}.  If 0 (unspecified),
301     * the mode from the theme will be used.
302     */
303    public int softInputMode;
304
305    public ActivityInfo() {
306    }
307
308    public ActivityInfo(ActivityInfo orig) {
309        super(orig);
310        theme = orig.theme;
311        launchMode = orig.launchMode;
312        permission = orig.permission;
313        taskAffinity = orig.taskAffinity;
314        targetActivity = orig.targetActivity;
315        flags = orig.flags;
316        screenOrientation = orig.screenOrientation;
317        configChanges = orig.configChanges;
318        softInputMode = orig.softInputMode;
319    }
320
321    /**
322     * Return the theme resource identifier to use for this activity.  If
323     * the activity defines a theme, that is used; else, the application
324     * theme is used.
325     *
326     * @return The theme associated with this activity.
327     */
328    public final int getThemeResource() {
329        return theme != 0 ? theme : applicationInfo.theme;
330    }
331
332    public void dump(Printer pw, String prefix) {
333        super.dumpFront(pw, prefix);
334        if (permission != null) {
335            pw.println(prefix + "permission=" + permission);
336        }
337        pw.println(prefix + "taskAffinity=" + taskAffinity
338                + " targetActivity=" + targetActivity);
339        if (launchMode != 0 || flags != 0 || theme != 0) {
340            pw.println(prefix + "launchMode=" + launchMode
341                    + " flags=0x" + Integer.toHexString(flags)
342                    + " theme=0x" + Integer.toHexString(theme));
343        }
344        if (screenOrientation != SCREEN_ORIENTATION_UNSPECIFIED
345                || configChanges != 0 || softInputMode != 0) {
346            pw.println(prefix + "screenOrientation=" + screenOrientation
347                    + " configChanges=0x" + Integer.toHexString(configChanges)
348                    + " softInputMode=0x" + Integer.toHexString(softInputMode));
349        }
350        super.dumpBack(pw, prefix);
351    }
352
353    public String toString() {
354        return "ActivityInfo{"
355            + Integer.toHexString(System.identityHashCode(this))
356            + " " + name + "}";
357    }
358
359    public int describeContents() {
360        return 0;
361    }
362
363    public void writeToParcel(Parcel dest, int parcelableFlags) {
364        super.writeToParcel(dest, parcelableFlags);
365        dest.writeInt(theme);
366        dest.writeInt(launchMode);
367        dest.writeString(permission);
368        dest.writeString(taskAffinity);
369        dest.writeString(targetActivity);
370        dest.writeInt(flags);
371        dest.writeInt(screenOrientation);
372        dest.writeInt(configChanges);
373        dest.writeInt(softInputMode);
374    }
375
376    public static final Parcelable.Creator<ActivityInfo> CREATOR
377            = new Parcelable.Creator<ActivityInfo>() {
378        public ActivityInfo createFromParcel(Parcel source) {
379            return new ActivityInfo(source);
380        }
381        public ActivityInfo[] newArray(int size) {
382            return new ActivityInfo[size];
383        }
384    };
385
386    private ActivityInfo(Parcel source) {
387        super(source);
388        theme = source.readInt();
389        launchMode = source.readInt();
390        permission = source.readString();
391        taskAffinity = source.readString();
392        targetActivity = source.readString();
393        flags = source.readInt();
394        screenOrientation = source.readInt();
395        configChanges = source.readInt();
396        softInputMode = source.readInt();
397    }
398}
399