1 /* 2 * Copyright 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 17 package android.media.tv.interactive; 18 19 import android.annotation.NonNull; 20 import android.content.ComponentName; 21 import android.net.Uri; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * App link information used by TV interactive app to launch Android apps. 27 */ 28 public final class AppLinkInfo implements Parcelable { 29 private @NonNull ComponentName mComponentName; 30 private @NonNull Uri mUri; 31 32 /** 33 * Creates a new AppLinkInfo. 34 * 35 * @param packageName Package Name of AppLinkInfo. 36 * @param className Class Name of AppLinkInfo. 37 * @param uriString Uri of AppLinkInfo. 38 */ AppLinkInfo( @onNull String packageName, @NonNull String className, @NonNull String uriString)39 public AppLinkInfo( 40 @NonNull String packageName, 41 @NonNull String className, 42 @NonNull String uriString) { 43 com.android.internal.util.AnnotationValidations.validate( 44 NonNull.class, null, packageName); 45 com.android.internal.util.AnnotationValidations.validate( 46 NonNull.class, null, className); 47 this.mComponentName = new ComponentName(packageName, className); 48 this.mUri = Uri.parse(uriString); 49 } 50 51 /** 52 * Gets component name of the App link, which contains package name and class name. 53 */ 54 @NonNull getComponentName()55 public ComponentName getComponentName() { 56 return mComponentName; 57 } 58 59 /** 60 * Gets URI of the App link. 61 */ 62 @NonNull getUri()63 public Uri getUri() { 64 return mUri; 65 } 66 67 @Override toString()68 public String toString() { 69 return "AppLinkInfo { " 70 + "packageName = " + mComponentName.getPackageName() + ", " 71 + "className = " + mComponentName.getClassName() + ", " 72 + "uri = " + mUri.toString() 73 + " }"; 74 } 75 76 @Override writeToParcel(@onNull Parcel dest, int flags)77 public void writeToParcel(@NonNull Parcel dest, int flags) { 78 mComponentName.writeToParcel(dest, flags); 79 String uriString = mUri == null ? null : mUri.toString(); 80 dest.writeString(uriString); 81 } 82 83 @Override describeContents()84 public int describeContents() { 85 return 0; 86 } 87 AppLinkInfo(@onNull Parcel in)88 /* package-private */ AppLinkInfo(@NonNull Parcel in) { 89 mComponentName = ComponentName.readFromParcel(in); 90 com.android.internal.util.AnnotationValidations.validate( 91 NonNull.class, null, mComponentName.getPackageName()); 92 com.android.internal.util.AnnotationValidations.validate( 93 NonNull.class, null, mComponentName.getClassName()); 94 String uriString = in.readString(); 95 mUri = uriString == null ? null : Uri.parse(uriString); 96 } 97 98 @NonNull 99 public static final Parcelable.Creator<AppLinkInfo> CREATOR = 100 new Parcelable.Creator<AppLinkInfo>() { 101 @Override 102 public AppLinkInfo[] newArray(int size) { 103 return new AppLinkInfo[size]; 104 } 105 106 @Override 107 public AppLinkInfo createFromParcel(@NonNull Parcel in) { 108 return new AppLinkInfo(in); 109 } 110 }; 111 } 112