summaryrefslogtreecommitdiffstats
path: root/core/java/android/content/pm/BaseThemeInfo.java
blob: 447040a54d6acf8bd6b821cdfe64cbe1f3d46462 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package android.content.pm;

import android.os.Parcelable;
import android.os.Parcel;
import android.util.Log;
import android.util.AttributeSet;
import android.content.res.Resources;

/**
 * @hide
 */
public class BaseThemeInfo implements Parcelable {

    /**
     * The name of the wallpaper image file.
     * Specifies a relative path in assets subfolder.
     * If the parent's name is "locked" - DRM protected.
     *
     * @see wallpaperImage attribute
     */
    public String wallpaperImageName;

    /**
     * The name of the favorites background image file.
     * Specifies a relative path in assets subfolder.
     * If the parent's name is "locked" - DRM protected.
     *
     * @see favesBackground attribute
     *
     */
    public String favesImageName;

    /**
     * The name of the favorite apps background image file.
     * Specifies a relative path in assets subfolder.
     * If the parent's name is "locked" - DRM protected.
     *
     * @see favesAppBackground attribute
     *
     */
    public String favesAppImageName;

    /**
     * The resource id of theme thumbnail.
     * Specifies a theme thumbnail image resource as @drawable/foo.
     *
     * @see thumbnail attribute
     *
     */
    public String thumbnail;

    /**
     * The theme id, which does not change when the theme is modified.
     * Specifies an Android UI Style using style name.
     *
     * @see themeId attribute
     *
     */
    public String themeId;

    /**
     * The style resource id of Android UI Style, supplied by the resource commpiler.
     * Specifies an Android UI Style id.
     *
     * @see styleId attribute
     *
     */
    public int styleResourceId = -1;

    /**
     * The name of the theme (as displayed by UI).
     *
     * @see name attribute
     *
     */
    public String name;

    /**
     * The name of the call ringtone audio file.
     * Specifies a relative path in assets subfolder.
     * If the parent's name is "locked" - DRM protected.
     *
     * @see ringtoneFileName attribute
     *
     */
    public String ringtoneFileName;

    /**
     * The name of the call ringtone as shown to user.
     *
     * @see ringtoneName attribute
     *
     */
    public String ringtoneName;

    /**
     * The name of the notification ringtone audio file.
     * Specifies a relative path in assets subfolder.
     * If the parent's name is "locked" - DRM protected.
     *
     * @see notificationRingtoneFileName attribute
     *
     */
    public String notificationRingtoneFileName;

    /**
     * The name of the notification ringtone as shown to user.
     *
     * @see notificationRingtoneName attribute
     *
     */
    public String notificationRingtoneName;

    /**
     * The author name of the theme package.
     *
     * @see author attribute
     *
     */
    public String author;

    /**
     * The copyright text.
     *
     * @see copyright attribute
     *
     */
    public String copyright;

    /**
     * {@hide}
     */
    // There is no corresposponding flag in manifest file
    // This flag is set to true iff any media resource is DRM protected
    public boolean isDrmProtected = false;

    /**
     * The name of the "main" theme style (as displayed by UI).
     *
     * @see themeStyleName attribute
     *
     */
    public String themeStyleName;

    /**
     * The filename of the preview image.
     * Specifies a theme preview image resource as a path into the assets
     * subfolder.
     *
     * @see preview attribute
     */
    public String preview;

    /**
     * {@hide}
     */
    public enum InfoObjectType {
        TYPE_THEME,
        TYPE_SOUNDPACK, /** Currently not supported. */
    }

    /**
     * {@hide}
     */
    public InfoObjectType type;

    /**
     * The name of a sound pack.
     *
     * @see soundpack attribute
     *
     */
    public String soundPackName;


    private static final String LOCKED_NAME = "locked/";

    /*
     * Describe the kinds of special objects contained in this Parcelable's
     * marshalled representation.
     *
     * @return a bitmask indicating the set of special object types marshalled
     * by the Parcelable.
     *
     * @see android.os.Parcelable#describeContents()
     */
    public int describeContents() {
        return 0;
    }

    /*
     * Flatten this object in to a Parcel.
     *
     * @param dest The Parcel in which the object should be written.
     * @param flags Additional flags about how the object should be written.
     * May be 0 or {@link #PARCELABLE_WRITE_RETURN_VALUE}.
     *
     * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
     */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(objectTypeToInt(type));
        dest.writeString(wallpaperImageName);
        dest.writeString(favesImageName);
        dest.writeString(favesAppImageName);
        dest.writeString(thumbnail);
        dest.writeString(themeId);
        dest.writeInt(styleResourceId);
        dest.writeString(name);
        dest.writeString(ringtoneFileName);
        dest.writeString(notificationRingtoneFileName);
        dest.writeString(ringtoneName);
        dest.writeString(notificationRingtoneName);
        dest.writeString(author);
        dest.writeString(copyright);
        dest.writeInt(isDrmProtected? 1 : 0);
        dest.writeString(soundPackName);
        dest.writeString(themeStyleName);
        dest.writeString(preview);
    }

    /** @hide */
    public static final Parcelable.Creator<BaseThemeInfo> CREATOR
            = new Parcelable.Creator<BaseThemeInfo>() {
        public BaseThemeInfo createFromParcel(Parcel source) {
            return new BaseThemeInfo(source);
        }

        public BaseThemeInfo[] newArray(int size) {
            return new BaseThemeInfo[size];
        }
    };

    /** @hide */
    public final String getResolvedString(Resources res, AttributeSet attrs, int index) {
        int resId = attrs.getAttributeResourceValue(index, 0);
        if (resId !=0 ) {
            return res.getString(resId);
        }
        return attrs.getAttributeValue(index);
    }

    protected BaseThemeInfo() {
    }

    protected BaseThemeInfo(Parcel source) {
        type = intToInfoObjectType(source.readInt());
        wallpaperImageName = source.readString();
        favesImageName = source.readString();
        favesAppImageName = source.readString();
        thumbnail = source.readString();
        themeId = source.readString();
        styleResourceId = source.readInt();
        name = source.readString();
        ringtoneFileName = source.readString();
        notificationRingtoneFileName = source.readString();
        ringtoneName = source.readString();
        notificationRingtoneName = source.readString();
        author = source.readString();
        copyright = source.readString();
        isDrmProtected = (source.readInt() != 0);
        soundPackName = source.readString();
        themeStyleName = source.readString();
        preview = source.readString();
    }

    protected void changeDrmFlagIfNeeded(String resourcePath) {
        if (resourcePath != null && resourcePath.contains(LOCKED_NAME)) {
            isDrmProtected = true;
        }
    }

    private int objectTypeToInt(InfoObjectType type) {
        switch (type) {
            case TYPE_THEME:
                return 0;

            case TYPE_SOUNDPACK:
                return 1;

            default:
                Log.e("BaseThemeInfo", "unknown type " + type.toString());
                return 0;
        }
    }

    private InfoObjectType intToInfoObjectType(int value) {
        switch (value) {
            case 0:
                return InfoObjectType.TYPE_THEME;

            case 1:
                return InfoObjectType.TYPE_SOUNDPACK;

            default:
                Log.e("BaseThemeInfo", "unknown value " + value);
                return InfoObjectType.TYPE_THEME;
        }
    }

}