Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 17 | package android.app; |
| 18 | |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 20 | import android.app.slice.Slice; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 23 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 25 | import android.content.pm.PackageManager.NameNotFoundException; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 26 | import android.content.pm.ResolveInfo; |
| 27 | import android.content.pm.ServiceInfo; |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 28 | import android.content.res.Resources; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 29 | import android.content.res.Resources.NotFoundException; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 30 | import android.content.res.TypedArray; |
| 31 | import android.content.res.XmlResourceParser; |
| 32 | import android.graphics.drawable.Drawable; |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 33 | import android.net.Uri; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 34 | import android.os.Parcel; |
| 35 | import android.os.Parcelable; |
| 36 | import android.service.wallpaper.WallpaperService; |
| 37 | import android.util.AttributeSet; |
| 38 | import android.util.Printer; |
| 39 | import android.util.Xml; |
wilsonshih | 968b30e | 2018-11-20 20:16:58 +0800 | [diff] [blame] | 40 | import android.view.SurfaceHolder; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 41 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 42 | import org.xmlpull.v1.XmlPullParser; |
| 43 | import org.xmlpull.v1.XmlPullParserException; |
| 44 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 45 | import java.io.IOException; |
| 46 | |
| 47 | /** |
| 48 | * This class is used to specify meta information of a wallpaper service. |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 49 | */ |
| 50 | public final class WallpaperInfo implements Parcelable { |
| 51 | static final String TAG = "WallpaperInfo"; |
| 52 | |
| 53 | /** |
| 54 | * The Service that implements this wallpaper component. |
| 55 | */ |
| 56 | final ResolveInfo mService; |
| 57 | |
| 58 | /** |
| 59 | * The wallpaper setting activity's name, to |
| 60 | * launch the setting activity of this wallpaper. |
| 61 | */ |
| 62 | final String mSettingsActivityName; |
| 63 | |
| 64 | /** |
Daniel Sandler | 465ccb8 | 2009-09-16 15:54:39 -0400 | [diff] [blame] | 65 | * Resource identifier for this wallpaper's thumbnail image. |
| 66 | */ |
| 67 | final int mThumbnailResource; |
| 68 | |
| 69 | /** |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 70 | * Resource identifier for a string indicating the author of the wallpaper. |
| 71 | */ |
| 72 | final int mAuthorResource; |
| 73 | |
| 74 | /** |
| 75 | * Resource identifier for a string containing a short description of the wallpaper. |
| 76 | */ |
| 77 | final int mDescriptionResource; |
| 78 | |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 79 | final int mContextUriResource; |
| 80 | final int mContextDescriptionResource; |
| 81 | final boolean mShowMetadataInPreview; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 82 | final boolean mSupportsAmbientMode; |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 83 | final String mSettingsSliceUri; |
wilsonshih | 968b30e | 2018-11-20 20:16:58 +0800 | [diff] [blame] | 84 | final boolean mSupportMultipleDisplays; |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 85 | |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 86 | /** |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 87 | * Constructor. |
| 88 | * |
| 89 | * @param context The Context in which we are parsing the wallpaper. |
| 90 | * @param service The ResolveInfo returned from the package manager about |
| 91 | * this wallpaper's component. |
| 92 | */ |
| 93 | public WallpaperInfo(Context context, ResolveInfo service) |
| 94 | throws XmlPullParserException, IOException { |
| 95 | mService = service; |
| 96 | ServiceInfo si = service.serviceInfo; |
| 97 | |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 98 | final PackageManager pm = context.getPackageManager(); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 99 | XmlResourceParser parser = null; |
| 100 | try { |
| 101 | parser = si.loadXmlMetaData(pm, WallpaperService.SERVICE_META_DATA); |
| 102 | if (parser == null) { |
| 103 | throw new XmlPullParserException("No " |
| 104 | + WallpaperService.SERVICE_META_DATA + " meta-data"); |
| 105 | } |
| 106 | |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 107 | Resources res = pm.getResourcesForApplication(si.applicationInfo); |
| 108 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 109 | AttributeSet attrs = Xml.asAttributeSet(parser); |
| 110 | |
| 111 | int type; |
| 112 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 113 | && type != XmlPullParser.START_TAG) { |
| 114 | } |
| 115 | |
| 116 | String nodeName = parser.getName(); |
| 117 | if (!"wallpaper".equals(nodeName)) { |
| 118 | throw new XmlPullParserException( |
| 119 | "Meta-data does not start with wallpaper tag"); |
| 120 | } |
| 121 | |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 122 | TypedArray sa = res.obtainAttributes(attrs, |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 123 | com.android.internal.R.styleable.Wallpaper); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 124 | mSettingsActivityName = sa.getString( |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 125 | com.android.internal.R.styleable.Wallpaper_settingsActivity); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 126 | mThumbnailResource = sa.getResourceId( |
Daniel Sandler | 465ccb8 | 2009-09-16 15:54:39 -0400 | [diff] [blame] | 127 | com.android.internal.R.styleable.Wallpaper_thumbnail, |
| 128 | -1); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 129 | mAuthorResource = sa.getResourceId( |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 130 | com.android.internal.R.styleable.Wallpaper_author, |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 131 | -1); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 132 | mDescriptionResource = sa.getResourceId( |
Dianne Hackborn | 23ef7b4 | 2009-11-18 18:20:39 -0800 | [diff] [blame] | 133 | com.android.internal.R.styleable.Wallpaper_description, |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 134 | -1); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 135 | mContextUriResource = sa.getResourceId( |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 136 | com.android.internal.R.styleable.Wallpaper_contextUri, |
| 137 | -1); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 138 | mContextDescriptionResource = sa.getResourceId( |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 139 | com.android.internal.R.styleable.Wallpaper_contextDescription, |
| 140 | -1); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 141 | mShowMetadataInPreview = sa.getBoolean( |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 142 | com.android.internal.R.styleable.Wallpaper_showMetadataInPreview, |
| 143 | false); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 144 | mSupportsAmbientMode = sa.getBoolean( |
| 145 | com.android.internal.R.styleable.Wallpaper_supportsAmbientMode, |
| 146 | false); |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 147 | mSettingsSliceUri = sa.getString( |
| 148 | com.android.internal.R.styleable.Wallpaper_settingsSliceUri); |
wilsonshih | 968b30e | 2018-11-20 20:16:58 +0800 | [diff] [blame] | 149 | mSupportMultipleDisplays = sa.getBoolean( |
| 150 | com.android.internal.R.styleable.Wallpaper_supportsMultipleDisplays, |
| 151 | false); |
Daniel Sandler | 465ccb8 | 2009-09-16 15:54:39 -0400 | [diff] [blame] | 152 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 153 | sa.recycle(); |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 154 | } catch (NameNotFoundException e) { |
| 155 | throw new XmlPullParserException( |
| 156 | "Unable to create context for: " + si.packageName); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 157 | } finally { |
| 158 | if (parser != null) parser.close(); |
| 159 | } |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | WallpaperInfo(Parcel source) { |
| 163 | mSettingsActivityName = source.readString(); |
Daniel Sandler | 465ccb8 | 2009-09-16 15:54:39 -0400 | [diff] [blame] | 164 | mThumbnailResource = source.readInt(); |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 165 | mAuthorResource = source.readInt(); |
| 166 | mDescriptionResource = source.readInt(); |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 167 | mContextUriResource = source.readInt(); |
| 168 | mContextDescriptionResource = source.readInt(); |
| 169 | mShowMetadataInPreview = source.readInt() != 0; |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 170 | mSupportsAmbientMode = source.readInt() != 0; |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 171 | mSettingsSliceUri = source.readString(); |
wilsonshih | 968b30e | 2018-11-20 20:16:58 +0800 | [diff] [blame] | 172 | mSupportMultipleDisplays = source.readInt() != 0; |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 173 | mService = ResolveInfo.CREATOR.createFromParcel(source); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Return the .apk package that implements this wallpaper. |
| 178 | */ |
| 179 | public String getPackageName() { |
| 180 | return mService.serviceInfo.packageName; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Return the class name of the service component that implements |
| 185 | * this wallpaper. |
| 186 | */ |
| 187 | public String getServiceName() { |
| 188 | return mService.serviceInfo.name; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Return the raw information about the Service implementing this |
| 193 | * wallpaper. Do not modify the returned object. |
| 194 | */ |
| 195 | public ServiceInfo getServiceInfo() { |
| 196 | return mService.serviceInfo; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Return the component of the service that implements this wallpaper. |
| 201 | */ |
| 202 | public ComponentName getComponent() { |
| 203 | return new ComponentName(mService.serviceInfo.packageName, |
| 204 | mService.serviceInfo.name); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Load the user-displayed label for this wallpaper. |
| 209 | * |
| 210 | * @param pm Supply a PackageManager used to load the wallpaper's |
| 211 | * resources. |
| 212 | */ |
| 213 | public CharSequence loadLabel(PackageManager pm) { |
| 214 | return mService.loadLabel(pm); |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Load the user-displayed icon for this wallpaper. |
| 219 | * |
| 220 | * @param pm Supply a PackageManager used to load the wallpaper's |
| 221 | * resources. |
| 222 | */ |
| 223 | public Drawable loadIcon(PackageManager pm) { |
| 224 | return mService.loadIcon(pm); |
| 225 | } |
| 226 | |
| 227 | /** |
Daniel Sandler | 465ccb8 | 2009-09-16 15:54:39 -0400 | [diff] [blame] | 228 | * Load the thumbnail image for this wallpaper. |
| 229 | * |
| 230 | * @param pm Supply a PackageManager used to load the wallpaper's |
| 231 | * resources. |
| 232 | */ |
| 233 | public Drawable loadThumbnail(PackageManager pm) { |
| 234 | if (mThumbnailResource < 0) return null; |
| 235 | |
| 236 | return pm.getDrawable(mService.serviceInfo.packageName, |
| 237 | mThumbnailResource, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 238 | mService.serviceInfo.applicationInfo); |
Daniel Sandler | 465ccb8 | 2009-09-16 15:54:39 -0400 | [diff] [blame] | 239 | } |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * Return a string indicating the author(s) of this wallpaper. |
| 243 | */ |
| 244 | public CharSequence loadAuthor(PackageManager pm) throws NotFoundException { |
| 245 | if (mAuthorResource <= 0) throw new NotFoundException(); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 246 | String packageName = mService.resolvePackageName; |
| 247 | ApplicationInfo applicationInfo = null; |
| 248 | if (packageName == null) { |
| 249 | packageName = mService.serviceInfo.packageName; |
| 250 | applicationInfo = mService.serviceInfo.applicationInfo; |
| 251 | } |
| 252 | return pm.getText(packageName, mAuthorResource, applicationInfo); |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Return a brief summary of this wallpaper's behavior. |
| 257 | */ |
| 258 | public CharSequence loadDescription(PackageManager pm) throws NotFoundException { |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 259 | String packageName = mService.resolvePackageName; |
| 260 | ApplicationInfo applicationInfo = null; |
| 261 | if (packageName == null) { |
| 262 | packageName = mService.serviceInfo.packageName; |
| 263 | applicationInfo = mService.serviceInfo.applicationInfo; |
| 264 | } |
| 265 | if (mService.serviceInfo.descriptionRes != 0) { |
| 266 | return pm.getText(packageName, mService.serviceInfo.descriptionRes, |
| 267 | applicationInfo); |
| 268 | |
| 269 | } |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 270 | if (mDescriptionResource <= 0) throw new NotFoundException(); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 271 | return pm.getText(packageName, mDescriptionResource, |
| 272 | mService.serviceInfo.applicationInfo); |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 273 | } |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 274 | |
| 275 | /** |
| 276 | * Returns an URI that specifies a link for further context about this wallpaper. |
| 277 | * |
| 278 | * @param pm An instance of {@link PackageManager} to retrieve the URI. |
| 279 | * @return The URI. |
| 280 | */ |
| 281 | public Uri loadContextUri(PackageManager pm) throws NotFoundException { |
| 282 | if (mContextUriResource <= 0) throw new NotFoundException(); |
| 283 | String packageName = mService.resolvePackageName; |
| 284 | ApplicationInfo applicationInfo = null; |
| 285 | if (packageName == null) { |
| 286 | packageName = mService.serviceInfo.packageName; |
| 287 | applicationInfo = mService.serviceInfo.applicationInfo; |
| 288 | } |
| 289 | String contextUriString = pm.getText( |
| 290 | packageName, mContextUriResource, applicationInfo).toString(); |
| 291 | if (contextUriString == null) { |
| 292 | return null; |
| 293 | } |
| 294 | return Uri.parse(contextUriString); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Retrieves a title of the URI that specifies a link for further context about this wallpaper. |
| 299 | * |
| 300 | * @param pm An instance of {@link PackageManager} to retrieve the title. |
| 301 | * @return The title. |
| 302 | */ |
| 303 | public CharSequence loadContextDescription(PackageManager pm) throws NotFoundException { |
| 304 | if (mContextDescriptionResource <= 0) throw new NotFoundException(); |
| 305 | String packageName = mService.resolvePackageName; |
| 306 | ApplicationInfo applicationInfo = null; |
| 307 | if (packageName == null) { |
| 308 | packageName = mService.serviceInfo.packageName; |
| 309 | applicationInfo = mService.serviceInfo.applicationInfo; |
| 310 | } |
| 311 | return pm.getText(packageName, mContextDescriptionResource, applicationInfo).toString(); |
| 312 | } |
| 313 | |
| 314 | /** |
Jorim Jaggi | d136ba1 | 2016-06-23 16:25:52 -0700 | [diff] [blame] | 315 | * Queries whether any metadata should be shown when previewing the wallpaper. If this value is |
| 316 | * set to true, any component that shows a preview of this live wallpaper should also show |
| 317 | * accompanying information like {@link #loadLabel}, |
| 318 | * {@link #loadDescription}, {@link #loadAuthor} and |
| 319 | * {@link #loadContextDescription(PackageManager)}, so the user gets to know further information |
| 320 | * about this wallpaper. |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 321 | * |
| 322 | * @return Whether any metadata should be shown when previewing the wallpaper. |
| 323 | */ |
| 324 | public boolean getShowMetadataInPreview() { |
| 325 | return mShowMetadataInPreview; |
| 326 | } |
| 327 | |
Daniel Sandler | 465ccb8 | 2009-09-16 15:54:39 -0400 | [diff] [blame] | 328 | /** |
Lucas Dupin | 8f09a50 | 2018-07-27 16:47:45 +0800 | [diff] [blame] | 329 | * Returns whether a wallpaper was optimized or not for ambient mode and can be drawn in there. |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 330 | * |
Lucas Dupin | 8f09a50 | 2018-07-27 16:47:45 +0800 | [diff] [blame] | 331 | * @see WallpaperService.Engine#onAmbientModeChanged(boolean, boolean) |
| 332 | * @see WallpaperService.Engine#isInAmbientMode() |
| 333 | * @return {@code true} if wallpaper can draw when in ambient mode. |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 334 | * @hide |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 335 | */ |
Lucas Dupin | 4c8c327 | 2018-11-06 17:47:48 -0800 | [diff] [blame] | 336 | @SystemApi |
Lucas Dupin | 8f09a50 | 2018-07-27 16:47:45 +0800 | [diff] [blame] | 337 | public boolean supportsAmbientMode() { |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 338 | return mSupportsAmbientMode; |
| 339 | } |
| 340 | |
| 341 | /** |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 342 | * Return the class name of an activity that provides a settings UI for |
| 343 | * the wallpaper. You can launch this activity be starting it with |
| 344 | * an {@link android.content.Intent} whose action is MAIN and with an |
| 345 | * explicit {@link android.content.ComponentName} |
| 346 | * composed of {@link #getPackageName} and the class name returned here. |
| 347 | * |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 348 | * <p>{@code null} will be returned if there is no settings activity associated |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 349 | * with the wallpaper. |
| 350 | */ |
| 351 | public String getSettingsActivity() { |
| 352 | return mSettingsActivityName; |
| 353 | } |
| 354 | |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 355 | /** |
| 356 | * Returns an URI that provides a settings {@link Slice} for this wallpaper. |
| 357 | * |
| 358 | * <p>{@code null} will be returned if there is no settings Slice URI associated |
| 359 | * with the wallpaper. |
| 360 | * |
| 361 | * @return The URI. |
| 362 | */ |
| 363 | public Uri getSettingsSliceUri() { |
| 364 | if (mSettingsSliceUri == null) { |
| 365 | return null; |
| 366 | } |
| 367 | return Uri.parse(mSettingsSliceUri); |
| 368 | } |
| 369 | |
wilsonshih | 968b30e | 2018-11-20 20:16:58 +0800 | [diff] [blame] | 370 | /** |
| 371 | * Returns whether this wallpaper service can support multiple engines to render on each surface |
| 372 | * independently. An example use case is a multi-display set-up where the wallpaper service can |
| 373 | * render surfaces to each of the connected displays. |
wilsonshih | fd058f6 | 2019-02-13 15:57:06 +0800 | [diff] [blame] | 374 | * <p> |
| 375 | * This corresponds to the value {@link android.R.styleable#Wallpaper_supportsMultipleDisplays} |
| 376 | * in the XML description of the wallpaper. |
| 377 | * <p> |
| 378 | * The default value is {@code false}. |
wilsonshih | 968b30e | 2018-11-20 20:16:58 +0800 | [diff] [blame] | 379 | * |
| 380 | * @see WallpaperService#onCreateEngine() |
| 381 | * @see WallpaperService.Engine#onCreate(SurfaceHolder) |
| 382 | * @return {@code true} if multiple engines can render independently on each surface. |
wilsonshih | fd058f6 | 2019-02-13 15:57:06 +0800 | [diff] [blame] | 383 | * |
| 384 | * @attr ref android.R.styleable#Wallpaper_supportsMultipleDisplays |
wilsonshih | 968b30e | 2018-11-20 20:16:58 +0800 | [diff] [blame] | 385 | */ |
| 386 | public boolean supportsMultipleDisplays() { |
| 387 | return mSupportMultipleDisplays; |
| 388 | } |
| 389 | |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 390 | public void dump(Printer pw, String prefix) { |
| 391 | pw.println(prefix + "Service:"); |
| 392 | mService.dump(pw, prefix + " "); |
| 393 | pw.println(prefix + "mSettingsActivityName=" + mSettingsActivityName); |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public String toString() { |
| 398 | return "WallpaperInfo{" + mService.serviceInfo.name |
| 399 | + ", settings: " |
| 400 | + mSettingsActivityName + "}"; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Used to package this object into a {@link Parcel}. |
| 405 | * |
| 406 | * @param dest The {@link Parcel} to be written. |
| 407 | * @param flags The flags used for parceling. |
| 408 | */ |
| 409 | public void writeToParcel(Parcel dest, int flags) { |
| 410 | dest.writeString(mSettingsActivityName); |
Daniel Sandler | 465ccb8 | 2009-09-16 15:54:39 -0400 | [diff] [blame] | 411 | dest.writeInt(mThumbnailResource); |
Daniel Sandler | 18a509d | 2009-11-05 15:05:27 -0500 | [diff] [blame] | 412 | dest.writeInt(mAuthorResource); |
| 413 | dest.writeInt(mDescriptionResource); |
Jorim Jaggi | 526505d | 2016-05-24 00:29:19 -0700 | [diff] [blame] | 414 | dest.writeInt(mContextUriResource); |
| 415 | dest.writeInt(mContextDescriptionResource); |
| 416 | dest.writeInt(mShowMetadataInPreview ? 1 : 0); |
Lucas Dupin | 7517b5d | 2017-08-22 12:51:25 -0700 | [diff] [blame] | 417 | dest.writeInt(mSupportsAmbientMode ? 1 : 0); |
Weien Wang | 4710c04 | 2018-10-05 19:46:41 +0800 | [diff] [blame] | 418 | dest.writeString(mSettingsSliceUri); |
wilsonshih | 968b30e | 2018-11-20 20:16:58 +0800 | [diff] [blame] | 419 | dest.writeInt(mSupportMultipleDisplays ? 1 : 0); |
Dianne Hackborn | eb03465 | 2009-09-07 00:49:58 -0700 | [diff] [blame] | 420 | mService.writeToParcel(dest, flags); |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Used to make this class parcelable. |
| 425 | */ |
| 426 | public static final Parcelable.Creator<WallpaperInfo> CREATOR = new Parcelable.Creator<WallpaperInfo>() { |
| 427 | public WallpaperInfo createFromParcel(Parcel source) { |
| 428 | return new WallpaperInfo(source); |
| 429 | } |
| 430 | |
| 431 | public WallpaperInfo[] newArray(int size) { |
| 432 | return new WallpaperInfo[size]; |
| 433 | } |
| 434 | }; |
| 435 | |
| 436 | public int describeContents() { |
| 437 | return 0; |
| 438 | } |
| 439 | } |