1/*
2 * Copyright (C) 2021 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 com.android.bedstead.remoteframeworkclasses;
18
19import android.accounts.AccountManagerCallback;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import com.google.android.enterprise.connectedapps.annotations.CustomParcelableWrapper;
24import com.google.android.enterprise.connectedapps.internal.Bundler;
25import com.google.android.enterprise.connectedapps.internal.BundlerType;
26
27/**
28 * This parcelable wrapper just passes null to callers.
29 *
30 * <p>It is not functional and only enables use of {@link AccountManagerCallback} for clients
31 * which do not need to actually use the {@link AccountManagerCallback} param or return value.
32 */
33@CustomParcelableWrapper(originalType = AccountManagerCallback.class)
34public final class NullParcelableAccountManagerCallback<F> implements Parcelable {
35
36    /**
37     * Create a wrapper for a given {@link AccountManagerCallback}.
38     */
39    public static <F> NullParcelableAccountManagerCallback of(
40            Bundler bundler, BundlerType type,
41            AccountManagerCallback<F> accountManagerCallback) {
42
43        if (accountManagerCallback != null) {
44            throw new IllegalArgumentException("accountManagerCallback can only be null");
45        }
46
47        return new NullParcelableAccountManagerCallback<F>();
48    }
49
50    private NullParcelableAccountManagerCallback() {
51    }
52
53    public AccountManagerCallback<F> get() {
54        return null;
55    }
56
57    @Override
58    public void writeToParcel(Parcel dest, int flags) {
59    }
60
61    @Override
62    public int describeContents() {
63        return 0;
64    }
65
66    @SuppressWarnings("rawtypes")
67    public static final Creator<NullParcelableAccountManagerCallback> CREATOR =
68            new Creator<NullParcelableAccountManagerCallback>() {
69                @Override
70                public NullParcelableAccountManagerCallback createFromParcel(Parcel in) {
71                    return new NullParcelableAccountManagerCallback();
72                }
73
74                @Override
75                public NullParcelableAccountManagerCallback[] newArray(int size) {
76                    return new NullParcelableAccountManagerCallback[size];
77                }
78            };
79}