1/*
2 * Copyright (C) 2015 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
17package android.support.v4.app;
18
19import android.os.Build;
20import android.os.Bundle;
21import android.os.IBinder;
22
23/**
24 * Helper for accessing features in {@link Bundle}
25 * introduced after API level 4 in a backwards compatible fashion.
26 */
27public final class BundleCompat {
28
29    private BundleCompat() {}
30
31    /**
32     * A convenience method to handle getting an {@link IBinder} inside a {@link Bundle} for all
33     * Android versions.
34     * @param bundle The bundle to get the {@link IBinder}.
35     * @param key    The key to use while getting the {@link IBinder}.
36     * @return       The {@link IBinder} that was obtained.
37     */
38    public static IBinder getBinder(Bundle bundle, String key) {
39        if (Build.VERSION.SDK_INT >= 18) {
40            return BundleCompatJellybeanMR2.getBinder(bundle, key);
41        } else {
42            return BundleCompatDonut.getBinder(bundle, key);
43        }
44    }
45
46    /**
47     * A convenience method to handle putting an {@link IBinder} inside a {@link Bundle} for all
48     * Android versions.
49     * @param bundle The bundle to insert the {@link IBinder}.
50     * @param key    The key to use while putting the {@link IBinder}.
51     * @param binder The {@link IBinder} to put.
52     */
53    public static void putBinder(Bundle bundle, String key, IBinder binder) {
54        if (Build.VERSION.SDK_INT >= 18) {
55            BundleCompatJellybeanMR2.putBinder(bundle, key, binder);
56        } else {
57            BundleCompatDonut.putBinder(bundle, key, binder);
58        }
59    }
60}
61