1 /*
2  * Copyright (C) 2017 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 package com.android.wallpaper.model;
17 
18 import android.app.Activity;
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.os.Build;
22 import android.os.Parcel;
23 
24 import com.android.wallpaper.R;
25 import com.android.wallpaper.asset.Asset;
26 import com.android.wallpaper.asset.BuiltInWallpaperAsset;
27 import com.android.wallpaper.asset.ResourceAsset;
28 
29 import java.util.Arrays;
30 import java.util.List;
31 
32 /**
33  * Represents the default built-in wallpaper on the device.
34  */
35 public class DefaultWallpaperInfo extends WallpaperInfo {
36     public static final Creator<DefaultWallpaperInfo> CREATOR =
37             new Creator<DefaultWallpaperInfo>() {
38                 @Override
39                 public DefaultWallpaperInfo createFromParcel(Parcel in) {
40                     return new DefaultWallpaperInfo(in);
41                 }
42 
43                 @Override
44                 public DefaultWallpaperInfo[] newArray(int size) {
45                     return new DefaultWallpaperInfo[size];
46                 }
47             };
48     private Asset mAsset;
49 
DefaultWallpaperInfo()50     public DefaultWallpaperInfo() {}
51 
DefaultWallpaperInfo(Parcel in)52     private DefaultWallpaperInfo(Parcel in) {
53         super(in);
54     }
55 
56     @Override
getAttributions(Context context)57     public List<String> getAttributions(Context context) {
58         return Arrays.asList(context.getResources().getString(R.string.fallback_wallpaper_title));
59     }
60 
61     @Override
getAsset(Context context)62     public Asset getAsset(Context context) {
63         if (mAsset == null) {
64             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
65                 mAsset = new BuiltInWallpaperAsset(context);
66             } else {
67                 Resources sysRes = Resources.getSystem();
68                 mAsset = new ResourceAsset(
69                         sysRes,
70                         sysRes.getIdentifier(
71                                 "default_wallpaper" /* name */,
72                                 "drawable" /* defType */,
73                                 "android" /* defPackage */));
74             }
75         }
76         return mAsset;
77     }
78 
79     @Override
getThumbAsset(Context context)80     public Asset getThumbAsset(Context context) {
81         // Same asset as full size.
82         return getAsset(context);
83     }
84 
85     @Override
getCollectionId(Context context)86     public String getCollectionId(Context context) {
87         return context.getString(R.string.on_device_wallpaper_collection_id);
88     }
89 
90     @Override
getWallpaperId()91     public String getWallpaperId() {
92         return "built-in-wallpaper";
93     }
94 
95     @Override
showPreview(Activity srcActivity, InlinePreviewIntentFactory factory, int requestCode)96     public void showPreview(Activity srcActivity, InlinePreviewIntentFactory factory,
97                             int requestCode) {
98         srcActivity.startActivityForResult(factory.newIntent(srcActivity, this), requestCode);
99     }
100 
101     @Override
102     @BackupPermission
getBackupPermission()103     public int getBackupPermission() {
104         return BACKUP_NOT_ALLOWED;
105     }
106 
107     @Override
writeToParcel(Parcel parcel, int i)108     public void writeToParcel(Parcel parcel, int i) {
109         super.writeToParcel(parcel, i);
110     }
111 }
112