Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | package android.content.pm; |
| 18 | |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 19 | import android.annotation.IntDef; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 22 | import android.util.Printer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 24 | import java.lang.annotation.Retention; |
| 25 | import java.lang.annotation.RetentionPolicy; |
| 26 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | /** |
| 28 | * Information you can retrieve about a particular application |
| 29 | * service. This corresponds to information collected from the |
| 30 | * AndroidManifest.xml's <service> tags. |
| 31 | */ |
| 32 | public class ServiceInfo extends ComponentInfo |
| 33 | implements Parcelable { |
| 34 | /** |
| 35 | * Optional name of a permission required to be able to access this |
| 36 | * Service. From the "permission" attribute. |
| 37 | */ |
| 38 | public String permission; |
| 39 | |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Bit in {@link #flags}: If set, the service will automatically be |
| 42 | * stopped by the system if the user removes a task that is rooted |
| 43 | * in one of the application's activities. Set from the |
| 44 | * {@link android.R.attr#stopWithTask} attribute. |
| 45 | */ |
| 46 | public static final int FLAG_STOP_WITH_TASK = 0x0001; |
| 47 | |
| 48 | /** |
Dianne Hackborn | a0c283e | 2012-02-09 10:47:01 -0800 | [diff] [blame] | 49 | * Bit in {@link #flags}: If set, the service will run in its own |
| 50 | * isolated process. Set from the |
| 51 | * {@link android.R.attr#isolatedProcess} attribute. |
| 52 | */ |
| 53 | public static final int FLAG_ISOLATED_PROCESS = 0x0002; |
| 54 | |
| 55 | /** |
Robert Sesek | b9a8666 | 2015-12-09 16:22:45 -0500 | [diff] [blame] | 56 | * Bit in {@link #flags}: If set, the service can be bound and run in the |
| 57 | * calling application's package, rather than the package in which it is |
| 58 | * declared. Set from {@link android.R.attr#externalService} attribute. |
Robert Sesek | b9a8666 | 2015-12-09 16:22:45 -0500 | [diff] [blame] | 59 | */ |
| 60 | public static final int FLAG_EXTERNAL_SERVICE = 0x0004; |
| 61 | |
| 62 | /** |
Martijn Coenen | e066c5c | 2018-10-31 16:50:30 +0100 | [diff] [blame] | 63 | * Bit in {@link #flags}: If set, the service (which must be isolated) |
| 64 | * will be spawned from an Application Zygote, instead of the regular Zygote. |
| 65 | * The Application Zygote will pre-initialize the application's class loader, |
| 66 | * and call a static callback into the application to allow it to perform |
| 67 | * application-specific preloads (such as loading a shared library). Therefore, |
| 68 | * spawning from the Application Zygote will typically reduce the service |
| 69 | * launch time and reduce its memory usage. The downside of using this flag |
| 70 | * is that you will have an additional process (the app zygote itself) that |
| 71 | * is taking up memory. Whether actual memory usage is improved therefore |
| 72 | * strongly depends on the number of isolated services that an application |
| 73 | * starts, and how much memory those services save by preloading. Therefore, |
| 74 | * it is recommended to measure memory usage under typical workloads to |
| 75 | * determine whether it makes sense to use this flag. |
| 76 | */ |
| 77 | public static final int FLAG_USE_APP_ZYGOTE = 0x0008; |
| 78 | |
| 79 | /** |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 80 | * Bit in {@link #flags} indicating if the service is visible to ephemeral applications. |
| 81 | * @hide |
| 82 | */ |
Todd Kennedy | c05f5d1 | 2017-04-25 11:11:40 -0700 | [diff] [blame] | 83 | public static final int FLAG_VISIBLE_TO_INSTANT_APP = 0x100000; |
Todd Kennedy | 7bc3a70 | 2016-12-08 14:54:48 -0800 | [diff] [blame] | 84 | |
| 85 | /** |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 86 | * Bit in {@link #flags}: If set, a single instance of the service will |
| 87 | * run for all users on the device. Set from the |
| 88 | * {@link android.R.attr#singleUser} attribute. |
| 89 | */ |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 90 | public static final int FLAG_SINGLE_USER = 0x40000000; |
Dianne Hackborn | b4163a6 | 2012-08-02 18:31:26 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 93 | * Options that have been set in the service declaration in the |
| 94 | * manifest. |
| 95 | * These include: |
Dianne Hackborn | 7d19e02 | 2012-08-07 19:12:33 -0700 | [diff] [blame] | 96 | * {@link #FLAG_STOP_WITH_TASK}, {@link #FLAG_ISOLATED_PROCESS}, |
| 97 | * {@link #FLAG_SINGLE_USER}. |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 98 | */ |
| 99 | public int flags; |
| 100 | |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 101 | /** |
| 102 | * The default foreground service type if not been set in manifest file. |
| 103 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 104 | public static final int FOREGROUND_SERVICE_TYPE_NONE = 0; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 105 | |
| 106 | /** |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 107 | * Constant corresponding to <code>dataSync</code> in |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 108 | * the {@link android.R.attr#foregroundServiceType} attribute. |
| 109 | * Data(photo, file, account) upload/download, backup/restore, import/export, fetch, |
| 110 | * transfer over network between device and cloud. |
| 111 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 112 | public static final int FOREGROUND_SERVICE_TYPE_DATA_SYNC = 1 << 0; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 113 | |
| 114 | /** |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 115 | * Constant corresponding to <code>mediaPlayback</code> in |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 116 | * the {@link android.R.attr#foregroundServiceType} attribute. |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 117 | * Music, video, news or other media playback. |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 118 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 119 | public static final int FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK = 1 << 1; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * Constant corresponding to <code>phoneCall</code> in |
| 123 | * the {@link android.R.attr#foregroundServiceType} attribute. |
| 124 | * Ongoing phone call or video conference. |
| 125 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 126 | public static final int FOREGROUND_SERVICE_TYPE_PHONE_CALL = 1 << 2; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * Constant corresponding to <code>location</code> in |
| 130 | * the {@link android.R.attr#foregroundServiceType} attribute. |
| 131 | * GPS, map, navigation location update. |
| 132 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 133 | public static final int FOREGROUND_SERVICE_TYPE_LOCATION = 1 << 3; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 134 | |
| 135 | /** |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 136 | * Constant corresponding to <code>connectedDevice</code> in |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 137 | * the {@link android.R.attr#foregroundServiceType} attribute. |
| 138 | * Auto, bluetooth, TV or other devices connection, monitoring and interaction. |
| 139 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 140 | public static final int FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE = 1 << 4; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 141 | |
| 142 | /** |
Narayan Kamath | 06265a3 | 2019-03-06 15:45:48 +0000 | [diff] [blame] | 143 | * Constant corresponding to {@code mediaProjection} in |
| 144 | * the {@link android.R.attr#foregroundServiceType} attribute. |
| 145 | * Managing a media projection session, e.g for screen recording or taking screenshots. |
| 146 | */ |
| 147 | public static final int FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION = 1 << 5; |
| 148 | |
| 149 | /** |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 150 | * A special value indicates to use all types set in manifest file. |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 151 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 152 | public static final int FOREGROUND_SERVICE_TYPE_MANIFEST = -1; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 153 | |
| 154 | /** |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 155 | * The set of flags for foreground service type. |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 156 | * The foreground service type is set in {@link android.R.attr#foregroundServiceType} |
| 157 | * attribute. |
| 158 | * @hide |
| 159 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 160 | @IntDef(flag = true, prefix = { "FOREGROUND_SERVICE_TYPE_" }, value = { |
Hui Yu | b8dcbee | 2019-02-14 13:50:01 -0800 | [diff] [blame] | 161 | FOREGROUND_SERVICE_TYPE_MANIFEST, |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 162 | FOREGROUND_SERVICE_TYPE_NONE, |
| 163 | FOREGROUND_SERVICE_TYPE_DATA_SYNC, |
| 164 | FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK, |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 165 | FOREGROUND_SERVICE_TYPE_PHONE_CALL, |
| 166 | FOREGROUND_SERVICE_TYPE_LOCATION, |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 167 | FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE, |
Narayan Kamath | 06265a3 | 2019-03-06 15:45:48 +0000 | [diff] [blame] | 168 | FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION, |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 169 | }) |
| 170 | @Retention(RetentionPolicy.SOURCE) |
| 171 | public @interface ForegroundServiceType {} |
| 172 | |
| 173 | /** |
| 174 | * The type of foreground service, set in |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 175 | * {@link android.R.attr#foregroundServiceType} attribute by ORing flags in |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 176 | * {@link ForegroundServiceType} |
| 177 | * @hide |
| 178 | */ |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 179 | public @ForegroundServiceType int mForegroundServiceType = FOREGROUND_SERVICE_TYPE_NONE; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | public ServiceInfo() { |
| 182 | } |
| 183 | |
| 184 | public ServiceInfo(ServiceInfo orig) { |
| 185 | super(orig); |
| 186 | permission = orig.permission; |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 187 | flags = orig.flags; |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 188 | mForegroundServiceType = orig.mForegroundServiceType; |
| 189 | } |
| 190 | |
| 191 | /** |
Hui Yu | b8dcbee | 2019-02-14 13:50:01 -0800 | [diff] [blame] | 192 | * Return foreground service type specified in the manifest.. |
| 193 | * @return foreground service type specified in the manifest. |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 194 | */ |
Hui Yu | b8dcbee | 2019-02-14 13:50:01 -0800 | [diff] [blame] | 195 | public @ForegroundServiceType int getForegroundServiceType() { |
Hui Yu | 1ea8552 | 2018-12-06 16:59:18 -0800 | [diff] [blame] | 196 | return mForegroundServiceType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 199 | public void dump(Printer pw, String prefix) { |
Dianne Hackborn | 6ac42ae | 2015-12-08 17:22:10 -0800 | [diff] [blame] | 200 | dump(pw, prefix, DUMP_FLAG_ALL); |
| 201 | } |
| 202 | |
| 203 | /** @hide */ |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 204 | void dump(Printer pw, String prefix, int dumpFlags) { |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 205 | super.dumpFront(pw, prefix); |
| 206 | pw.println(prefix + "permission=" + permission); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 207 | pw.println(prefix + "flags=0x" + Integer.toHexString(flags)); |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 208 | super.dumpBack(pw, prefix, dumpFlags); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 209 | } |
Yohei Yukawa | 8f27217 | 2017-08-31 00:26:01 -0700 | [diff] [blame] | 210 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | public String toString() { |
| 212 | return "ServiceInfo{" |
| 213 | + Integer.toHexString(System.identityHashCode(this)) |
| 214 | + " " + name + "}"; |
| 215 | } |
| 216 | |
| 217 | public int describeContents() { |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 222 | super.writeToParcel(dest, parcelableFlags); |
| 223 | dest.writeString(permission); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 224 | dest.writeInt(flags); |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 225 | dest.writeInt(mForegroundServiceType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 228 | public static final @android.annotation.NonNull Creator<ServiceInfo> CREATOR = |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | new Creator<ServiceInfo>() { |
| 230 | public ServiceInfo createFromParcel(Parcel source) { |
| 231 | return new ServiceInfo(source); |
| 232 | } |
| 233 | public ServiceInfo[] newArray(int size) { |
| 234 | return new ServiceInfo[size]; |
| 235 | } |
| 236 | }; |
| 237 | |
| 238 | private ServiceInfo(Parcel source) { |
| 239 | super(source); |
| 240 | permission = source.readString(); |
Dianne Hackborn | 0c5001d | 2011-04-12 18:16:08 -0700 | [diff] [blame] | 241 | flags = source.readInt(); |
Hui Yu | 2d4207f | 2019-01-22 15:32:20 -0800 | [diff] [blame] | 242 | mForegroundServiceType = source.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } |
| 244 | } |