blob: b61d4d8aac0c60f040ad0baedc3ecd63b6a891a7 [file] [log] [blame]
Jason Monkdcb5e2f2017-11-15 20:19:43 -05001/*
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 */
16package androidx.app.slice.compat;
17
Jason Monk6fa0c9b2017-12-12 20:55:35 -050018import static androidx.app.slice.SliceConvert.wrap;
19
Jason Monk2a7d0fc2017-11-15 10:10:24 -050020import android.annotation.TargetApi;
Jason Monkdcb5e2f2017-11-15 20:19:43 -050021import android.app.slice.Slice;
22import android.app.slice.SliceProvider;
23import android.app.slice.SliceSpec;
24import android.content.Intent;
25import android.net.Uri;
26import android.support.annotation.NonNull;
27import android.support.annotation.RestrictTo;
28import android.support.annotation.RestrictTo.Scope;
29
30import java.util.List;
31
32import androidx.app.slice.SliceConvert;
33
34/**
35 * @hide
36 */
37@RestrictTo(Scope.LIBRARY)
Jason Monk2a7d0fc2017-11-15 10:10:24 -050038@TargetApi(28)
Jason Monkdcb5e2f2017-11-15 20:19:43 -050039public 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 Monk6fa0c9b2017-12-12 20:55:35 -050054 androidx.app.slice.SliceProvider.setSpecs(wrap(supportedVersions));
Jason Monka09cb672018-01-08 13:17:36 -050055 try {
56 return SliceConvert.unwrap(mSliceProvider.onBindSlice(sliceUri));
57 } finally {
58 androidx.app.slice.SliceProvider.setSpecs(null);
59 }
Jason Monkdcb5e2f2017-11-15 20:19:43 -050060 }
61
62 /**
63 * Maps intents to uris.
64 */
65 @Override
66 public @NonNull Uri onMapIntentToUri(Intent intent) {
67 return mSliceProvider.onMapIntentToUri(intent);
68 }
69}