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 * service. This corresponds to information collected from the
26 * AndroidManifest.xml's <service> tags.
27 */
28public class ServiceInfo extends ComponentInfo
29        implements Parcelable {
30    /**
31     * Optional name of a permission required to be able to access this
32     * Service.  From the "permission" attribute.
33     */
34    public String permission;
35
36    /**
37     * Bit in {@link #flags}: If set, the service will automatically be
38     * stopped by the system if the user removes a task that is rooted
39     * in one of the application's activities.  Set from the
40     * {@link android.R.attr#stopWithTask} attribute.
41     */
42    public static final int FLAG_STOP_WITH_TASK = 0x0001;
43
44    /**
45     * Bit in {@link #flags}: If set, the service will run in its own
46     * isolated process.  Set from the
47     * {@link android.R.attr#isolatedProcess} attribute.
48     */
49    public static final int FLAG_ISOLATED_PROCESS = 0x0002;
50
51    /**
52     * Bit in {@link #flags}: If set, the service can be bound and run in the
53     * calling application's package, rather than the package in which it is
54     * declared.  Set from {@link android.R.attr#externalService} attribute.
55     */
56    public static final int FLAG_EXTERNAL_SERVICE = 0x0004;
57
58    /**
59     * Bit in {@link #flags}: If set, a single instance of the service will
60     * run for all users on the device.  Set from the
61     * {@link android.R.attr#singleUser} attribute.
62     */
63    public static final int FLAG_SINGLE_USER = 0x40000000;
64
65    /**
66     * Options that have been set in the service declaration in the
67     * manifest.
68     * These include:
69     * {@link #FLAG_STOP_WITH_TASK}, {@link #FLAG_ISOLATED_PROCESS},
70     * {@link #FLAG_SINGLE_USER}.
71     */
72    public int flags;
73
74    public ServiceInfo() {
75    }
76
77    public ServiceInfo(ServiceInfo orig) {
78        super(orig);
79        permission = orig.permission;
80        flags = orig.flags;
81    }
82
83    public void dump(Printer pw, String prefix) {
84        dump(pw, prefix, DUMP_FLAG_ALL);
85    }
86
87    /** @hide */
88    void dump(Printer pw, String prefix, int flags) {
89        super.dumpFront(pw, prefix);
90        pw.println(prefix + "permission=" + permission);
91        pw.println(prefix + "flags=0x" + Integer.toHexString(flags));
92        super.dumpBack(pw, prefix, flags);
93    }
94
95    public String toString() {
96        return "ServiceInfo{"
97            + Integer.toHexString(System.identityHashCode(this))
98            + " " + name + "}";
99    }
100
101    public int describeContents() {
102        return 0;
103    }
104
105    public void writeToParcel(Parcel dest, int parcelableFlags) {
106        super.writeToParcel(dest, parcelableFlags);
107        dest.writeString(permission);
108        dest.writeInt(flags);
109    }
110
111    public static final Creator<ServiceInfo> CREATOR =
112        new Creator<ServiceInfo>() {
113        public ServiceInfo createFromParcel(Parcel source) {
114            return new ServiceInfo(source);
115        }
116        public ServiceInfo[] newArray(int size) {
117            return new ServiceInfo[size];
118        }
119    };
120
121    private ServiceInfo(Parcel source) {
122        super(source);
123        permission = source.readString();
124        flags = source.readInt();
125    }
126}
127