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.app.Activity; 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 Activity} for clients 31 * which do not need to actually use the {@link Activity} param or return value. 32 */ 33@CustomParcelableWrapper(originalType = Activity.class) 34public final class NullParcelableActivity implements Parcelable { 35 36 /** 37 * Create a wrapper for a given {@link Activity}. 38 */ 39 public static <F> NullParcelableActivity of( 40 Bundler bundler, BundlerType type, 41 Activity activity) { 42 43 if (activity != null) { 44 throw new IllegalArgumentException("activity can only be null"); 45 } 46 47 return new NullParcelableActivity(); 48 } 49 50 private NullParcelableActivity() { 51 } 52 53 public Activity 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<NullParcelableActivity> CREATOR = 68 new Creator<NullParcelableActivity>() { 69 @Override 70 public NullParcelableActivity createFromParcel(Parcel in) { 71 return new NullParcelableActivity(); 72 } 73 74 @Override 75 public NullParcelableActivity[] newArray(int size) { 76 return new NullParcelableActivity[size]; 77 } 78 }; 79}