• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.compat;
17 
18 import android.content.Context;
19 import android.graphics.Bitmap;
20 import android.graphics.Rect;
21 import android.os.ParcelFileDescriptor;
22 import android.util.Log;
23 
24 import java.io.IOException;
25 import java.io.InputStream;
26 
27 /**
28  * The Android N implementation of {@link WallpaperManagerCompat} which uses the new N API methods
29  * if available and delegates back to older implementations if not.
30  */
31 public class WallpaperManagerCompatVN extends WallpaperManagerCompatV16 {
32 
33     private static final String TAG = "WallpaperMgrCompatVN";
34 
WallpaperManagerCompatVN(Context context)35     public WallpaperManagerCompatVN(Context context) {
36         super(context);
37     }
38 
39     @Override
setStream(final InputStream data, Rect visibleCropHint, boolean allowBackup, int whichWallpaper)40     public int setStream(final InputStream data, Rect visibleCropHint, boolean allowBackup,
41                          int whichWallpaper) throws IOException {
42         return mWallpaperManager.setStream(data, visibleCropHint, allowBackup, whichWallpaper);
43     }
44 
45     @Override
setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup, int whichWallpaper)46     public int setBitmap(Bitmap fullImage, Rect visibleCropHint, boolean allowBackup,
47                          int whichWallpaper) throws IOException {
48         return mWallpaperManager.setBitmap(fullImage, visibleCropHint, allowBackup, whichWallpaper);
49     }
50 
51     @Override
getWallpaperId(@allpaperLocation int whichWallpaper)52     public int getWallpaperId(@WallpaperLocation int whichWallpaper) {
53         return mWallpaperManager.getWallpaperId(whichWallpaper);
54     }
55 
56     @Override
getWallpaperFile(int whichWallpaper)57     public ParcelFileDescriptor getWallpaperFile(int whichWallpaper) {
58         ParcelFileDescriptor parcelFd = null;
59         try {
60             parcelFd = mWallpaperManager.getWallpaperFile(whichWallpaper);
61         } catch (Exception e) {
62             // Note: We put a catch-all exception handler here to handle RemoteException /
63             // DeadSystemException that can happen due to an Android N framework bug manifesting if a user
64             // had restored their device from a previous device backup.
65             Log.e(TAG, "Exception on getWallpaperFile", e);
66         }
67         return parcelFd;
68     }
69 }
70