WallpaperInfo.java revision eb034652c2037a47ebfd99779e8383bb8bb528af
1package android.app; 2 3import org.xmlpull.v1.XmlPullParser; 4import org.xmlpull.v1.XmlPullParserException; 5 6import android.content.ComponentName; 7import android.content.Context; 8import android.content.pm.ApplicationInfo; 9import android.content.pm.PackageManager; 10import android.content.pm.ResolveInfo; 11import android.content.pm.ServiceInfo; 12import android.content.res.TypedArray; 13import android.content.res.XmlResourceParser; 14import android.graphics.drawable.Drawable; 15import android.os.Parcel; 16import android.os.Parcelable; 17import android.service.wallpaper.WallpaperService; 18import android.util.AttributeSet; 19import android.util.Printer; 20import android.util.Xml; 21 22import java.io.IOException; 23 24/** 25 * This class is used to specify meta information of a wallpaper service. 26 * @hide Live Wallpaper 27 */ 28public final class WallpaperInfo implements Parcelable { 29 static final String TAG = "WallpaperInfo"; 30 31 /** 32 * The Service that implements this wallpaper component. 33 */ 34 final ResolveInfo mService; 35 36 /** 37 * The wallpaper setting activity's name, to 38 * launch the setting activity of this wallpaper. 39 */ 40 final String mSettingsActivityName; 41 42 /** 43 * Constructor. 44 * 45 * @param context The Context in which we are parsing the wallpaper. 46 * @param service The ResolveInfo returned from the package manager about 47 * this wallpaper's component. 48 */ 49 public WallpaperInfo(Context context, ResolveInfo service) 50 throws XmlPullParserException, IOException { 51 mService = service; 52 ServiceInfo si = service.serviceInfo; 53 54 PackageManager pm = context.getPackageManager(); 55 String settingsActivityComponent = null; 56 57 XmlResourceParser parser = null; 58 try { 59 parser = si.loadXmlMetaData(pm, WallpaperService.SERVICE_META_DATA); 60 if (parser == null) { 61 throw new XmlPullParserException("No " 62 + WallpaperService.SERVICE_META_DATA + " meta-data"); 63 } 64 65 AttributeSet attrs = Xml.asAttributeSet(parser); 66 67 int type; 68 while ((type=parser.next()) != XmlPullParser.END_DOCUMENT 69 && type != XmlPullParser.START_TAG) { 70 } 71 72 String nodeName = parser.getName(); 73 if (!"wallpaper".equals(nodeName)) { 74 throw new XmlPullParserException( 75 "Meta-data does not start with wallpaper tag"); 76 } 77 78 TypedArray sa = context.getResources().obtainAttributes(attrs, 79 com.android.internal.R.styleable.Wallpaper); 80 settingsActivityComponent = sa.getString( 81 com.android.internal.R.styleable.Wallpaper_settingsActivity); 82 sa.recycle(); 83 } finally { 84 if (parser != null) parser.close(); 85 } 86 87 mSettingsActivityName = settingsActivityComponent; 88 } 89 90 WallpaperInfo(Parcel source) { 91 mSettingsActivityName = source.readString(); 92 mService = ResolveInfo.CREATOR.createFromParcel(source); 93 } 94 95 /** 96 * Return the .apk package that implements this wallpaper. 97 */ 98 public String getPackageName() { 99 return mService.serviceInfo.packageName; 100 } 101 102 /** 103 * Return the class name of the service component that implements 104 * this wallpaper. 105 */ 106 public String getServiceName() { 107 return mService.serviceInfo.name; 108 } 109 110 /** 111 * Return the raw information about the Service implementing this 112 * wallpaper. Do not modify the returned object. 113 */ 114 public ServiceInfo getServiceInfo() { 115 return mService.serviceInfo; 116 } 117 118 /** 119 * Return the component of the service that implements this wallpaper. 120 */ 121 public ComponentName getComponent() { 122 return new ComponentName(mService.serviceInfo.packageName, 123 mService.serviceInfo.name); 124 } 125 126 /** 127 * Load the user-displayed label for this wallpaper. 128 * 129 * @param pm Supply a PackageManager used to load the wallpaper's 130 * resources. 131 */ 132 public CharSequence loadLabel(PackageManager pm) { 133 return mService.loadLabel(pm); 134 } 135 136 /** 137 * Load the user-displayed icon for this wallpaper. 138 * 139 * @param pm Supply a PackageManager used to load the wallpaper's 140 * resources. 141 */ 142 public Drawable loadIcon(PackageManager pm) { 143 return mService.loadIcon(pm); 144 } 145 146 /** 147 * Return the class name of an activity that provides a settings UI for 148 * the wallpaper. You can launch this activity be starting it with 149 * an {@link android.content.Intent} whose action is MAIN and with an 150 * explicit {@link android.content.ComponentName} 151 * composed of {@link #getPackageName} and the class name returned here. 152 * 153 * <p>A null will be returned if there is no settings activity associated 154 * with the wallpaper. 155 */ 156 public String getSettingsActivity() { 157 return mSettingsActivityName; 158 } 159 160 public void dump(Printer pw, String prefix) { 161 pw.println(prefix + "Service:"); 162 mService.dump(pw, prefix + " "); 163 pw.println(prefix + "mSettingsActivityName=" + mSettingsActivityName); 164 } 165 166 @Override 167 public String toString() { 168 return "WallpaperInfo{" + mService.serviceInfo.name 169 + ", settings: " 170 + mSettingsActivityName + "}"; 171 } 172 173 /** 174 * Used to package this object into a {@link Parcel}. 175 * 176 * @param dest The {@link Parcel} to be written. 177 * @param flags The flags used for parceling. 178 */ 179 public void writeToParcel(Parcel dest, int flags) { 180 dest.writeString(mSettingsActivityName); 181 mService.writeToParcel(dest, flags); 182 } 183 184 /** 185 * Used to make this class parcelable. 186 */ 187 public static final Parcelable.Creator<WallpaperInfo> CREATOR = new Parcelable.Creator<WallpaperInfo>() { 188 public WallpaperInfo createFromParcel(Parcel source) { 189 return new WallpaperInfo(source); 190 } 191 192 public WallpaperInfo[] newArray(int size) { 193 return new WallpaperInfo[size]; 194 } 195 }; 196 197 public int describeContents() { 198 return 0; 199 } 200} 201