Jason Monk | dcb5e2f | 2017-11-15 20:19:43 -0500 | [diff] [blame] | 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 androidx.app.slice.compat; |
| 17 | |
Jason Monk | 6fa0c9b | 2017-12-12 20:55:35 -0500 | [diff] [blame] | 18 | import static androidx.app.slice.SliceConvert.wrap; |
| 19 | |
Jason Monk | 2a7d0fc | 2017-11-15 10:10:24 -0500 | [diff] [blame] | 20 | import android.annotation.TargetApi; |
Jason Monk | dcb5e2f | 2017-11-15 20:19:43 -0500 | [diff] [blame] | 21 | import android.app.slice.Slice; |
| 22 | import android.app.slice.SliceProvider; |
| 23 | import android.app.slice.SliceSpec; |
| 24 | import android.content.Intent; |
| 25 | import android.net.Uri; |
| 26 | import android.support.annotation.NonNull; |
| 27 | import android.support.annotation.RestrictTo; |
| 28 | import android.support.annotation.RestrictTo.Scope; |
| 29 | |
| 30 | import java.util.List; |
| 31 | |
| 32 | import androidx.app.slice.SliceConvert; |
| 33 | |
| 34 | /** |
| 35 | * @hide |
| 36 | */ |
| 37 | @RestrictTo(Scope.LIBRARY) |
Jason Monk | 2a7d0fc | 2017-11-15 10:10:24 -0500 | [diff] [blame] | 38 | @TargetApi(28) |
Jason Monk | dcb5e2f | 2017-11-15 20:19:43 -0500 | [diff] [blame] | 39 | public class SliceProviderWrapper extends SliceProvider { |
| 40 | |
| 41 | private androidx.app.slice.SliceProvider mSliceProvider; |
| 42 | |
| 43 | public SliceProviderWrapper(androidx.app.slice.SliceProvider provider) { |
| 44 | mSliceProvider = provider; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public boolean onCreate() { |
| 49 | return mSliceProvider.onCreateSliceProvider(); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public Slice onBindSlice(Uri sliceUri, List<SliceSpec> supportedVersions) { |
Jason Monk | 6fa0c9b | 2017-12-12 20:55:35 -0500 | [diff] [blame] | 54 | androidx.app.slice.SliceProvider.setSpecs(wrap(supportedVersions)); |
Jason Monk | a09cb67 | 2018-01-08 13:17:36 -0500 | [diff] [blame] | 55 | try { |
| 56 | return SliceConvert.unwrap(mSliceProvider.onBindSlice(sliceUri)); |
| 57 | } finally { |
| 58 | androidx.app.slice.SliceProvider.setSpecs(null); |
| 59 | } |
Jason Monk | dcb5e2f | 2017-11-15 20:19:43 -0500 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Maps intents to uris. |
| 64 | */ |
| 65 | @Override |
| 66 | public @NonNull Uri onMapIntentToUri(Intent intent) { |
| 67 | return mSliceProvider.onMapIntentToUri(intent); |
| 68 | } |
| 69 | } |