1 /* 2 * Copyright 2024 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.hardware.input; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.text.TextUtils; 22 23 import java.util.Objects; 24 25 /** 26 * Provides data for launching an application. 27 * 28 * @hide 29 */ 30 public interface AppLaunchData { 31 32 /** Creates AppLaunchData for the provided category */ 33 @NonNull createLaunchDataForCategory(@onNull String category)34 static AppLaunchData createLaunchDataForCategory(@NonNull String category) { 35 return new CategoryData(category); 36 } 37 38 /** Creates AppLaunchData for the provided role */ 39 @NonNull createLaunchDataForRole(@onNull String role)40 static AppLaunchData createLaunchDataForRole(@NonNull String role) { 41 return new RoleData(role); 42 } 43 44 /** Creates AppLaunchData for the target package name and class name */ 45 @NonNull createLaunchDataForComponent(@onNull String packageName, @NonNull String className)46 static AppLaunchData createLaunchDataForComponent(@NonNull String packageName, 47 @NonNull String className) { 48 return new ComponentData(packageName, className); 49 } 50 51 @Nullable createLaunchData(@ullable String category, @Nullable String role, @Nullable String packageName, @Nullable String className)52 static AppLaunchData createLaunchData(@Nullable String category, @Nullable String role, 53 @Nullable String packageName, @Nullable String className) { 54 if (!TextUtils.isEmpty(category)) { 55 return new CategoryData(category); 56 } 57 if (!TextUtils.isEmpty(role)) { 58 return new RoleData(role); 59 } 60 if (!TextUtils.isEmpty(packageName) && !TextUtils.isEmpty(className)) { 61 return new ComponentData(packageName, className); 62 } 63 return null; 64 } 65 66 /** Intent category based app launch data */ 67 class CategoryData implements AppLaunchData { 68 @NonNull 69 private final String mCategory; CategoryData(@onNull String category)70 public CategoryData(@NonNull String category) { 71 mCategory = category; 72 } 73 74 @NonNull getCategory()75 public String getCategory() { 76 return mCategory; 77 } 78 79 @Override equals(Object o)80 public boolean equals(Object o) { 81 if (this == o) return true; 82 if (!(o instanceof CategoryData that)) return false; 83 return Objects.equals(mCategory, that.mCategory); 84 } 85 86 @Override hashCode()87 public int hashCode() { 88 return Objects.hash(mCategory); 89 } 90 91 @Override toString()92 public String toString() { 93 return "CategoryData{" + 94 "mCategory='" + mCategory + '\'' + 95 '}'; 96 } 97 } 98 99 /** Role based app launch data */ 100 class RoleData implements AppLaunchData { 101 @NonNull 102 private final String mRole; RoleData(@onNull String role)103 public RoleData(@NonNull String role) { 104 mRole = role; 105 } 106 107 @NonNull getRole()108 public String getRole() { 109 return mRole; 110 } 111 112 @Override equals(Object o)113 public boolean equals(Object o) { 114 if (this == o) return true; 115 if (!(o instanceof RoleData roleData)) return false; 116 return Objects.equals(mRole, roleData.mRole); 117 } 118 119 @Override hashCode()120 public int hashCode() { 121 return Objects.hash(mRole); 122 } 123 124 @Override toString()125 public String toString() { 126 return "RoleData{" + 127 "mRole='" + mRole + '\'' + 128 '}'; 129 } 130 } 131 132 /** Target application launch data */ 133 class ComponentData implements AppLaunchData { 134 @NonNull 135 private final String mPackageName; 136 137 @NonNull 138 private final String mClassName; 139 ComponentData(@onNull String packageName, @NonNull String className)140 public ComponentData(@NonNull String packageName, @NonNull String className) { 141 mPackageName = packageName; 142 mClassName = className; 143 } 144 145 @NonNull getPackageName()146 public String getPackageName() { 147 return mPackageName; 148 } 149 150 @NonNull getClassName()151 public String getClassName() { 152 return mClassName; 153 } 154 155 @Override equals(Object o)156 public boolean equals(Object o) { 157 if (this == o) return true; 158 if (!(o instanceof ComponentData that)) return false; 159 return Objects.equals(mPackageName, that.mPackageName) && Objects.equals( 160 mClassName, that.mClassName); 161 } 162 163 @Override hashCode()164 public int hashCode() { 165 return Objects.hash(mPackageName, mClassName); 166 } 167 168 @Override toString()169 public String toString() { 170 return "ComponentData{" + 171 "mPackageName='" + mPackageName + '\'' + 172 ", mClassName='" + mClassName + '\'' + 173 '}'; 174 } 175 } 176 } 177