Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 18 | |
Pranav Madapurmath | ac29a0c | 2023-05-25 21:58:19 +0000 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
| 22 | import android.content.Context; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 23 | import android.graphics.drawable.Drawable; |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 24 | import android.graphics.drawable.Icon; |
Pranav Madapurmath | ac29a0c | 2023-05-25 21:58:19 +0000 | [diff] [blame] | 25 | import android.os.Binder; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 26 | import android.os.Bundle; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 27 | import android.os.Parcel; |
| 28 | import android.os.Parcelable; |
Pranav Madapurmath | ac29a0c | 2023-05-25 21:58:19 +0000 | [diff] [blame] | 29 | import android.os.UserHandle; |
| 30 | |
| 31 | import com.android.internal.annotations.VisibleForTesting; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 32 | |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 33 | import java.util.Objects; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Contains status label and icon displayed in the in-call UI. |
| 37 | */ |
| 38 | public final class StatusHints implements Parcelable { |
| 39 | |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 40 | private final CharSequence mLabel; |
Pranav Madapurmath | ac29a0c | 2023-05-25 21:58:19 +0000 | [diff] [blame] | 41 | private Icon mIcon; |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 42 | private final Bundle mExtras; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 43 | |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 44 | /** |
| 45 | * @hide |
| 46 | */ |
| 47 | @SystemApi @Deprecated |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 48 | public StatusHints(ComponentName packageName, CharSequence label, int iconResId, |
| 49 | Bundle extras) { |
Sailesh Nepal | d9be9cf | 2015-05-14 18:28:10 -0700 | [diff] [blame] | 50 | this(label, iconResId == 0 ? null : Icon.createWithResource(packageName.getPackageName(), |
| 51 | iconResId), extras); |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | public StatusHints(CharSequence label, Icon icon, Bundle extras) { |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 55 | mLabel = label; |
Pranav Madapurmath | ac29a0c | 2023-05-25 21:58:19 +0000 | [diff] [blame] | 56 | mIcon = validateAccountIconUserBoundary(icon, Binder.getCallingUserHandle()); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 57 | mExtras = extras; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /** |
Pranav Madapurmath | ac29a0c | 2023-05-25 21:58:19 +0000 | [diff] [blame] | 61 | * @param icon |
| 62 | * @hide |
| 63 | */ |
| 64 | @VisibleForTesting |
| 65 | public StatusHints(@Nullable Icon icon) { |
| 66 | mLabel = null; |
| 67 | mExtras = null; |
| 68 | mIcon = icon; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * |
| 73 | * @param icon |
| 74 | * @hide |
| 75 | */ |
| 76 | public void setIcon(@Nullable Icon icon) { |
| 77 | mIcon = icon; |
| 78 | } |
| 79 | |
| 80 | /** |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 81 | * @return A package used to load the icon. |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 82 | * |
| 83 | * @hide |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 84 | */ |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 85 | @SystemApi @Deprecated |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 86 | public ComponentName getPackageName() { |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 87 | // Minimal compatibility shim for legacy apps' tests |
| 88 | return new ComponentName("", ""); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @return The label displayed in the in-call UI. |
| 93 | */ |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 94 | public CharSequence getLabel() { |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 95 | return mLabel; |
| 96 | } |
| 97 | |
| 98 | /** |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 99 | * The icon resource ID for the icon to show. |
| 100 | * |
| 101 | * @return A resource ID. |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 102 | * |
| 103 | * @hide |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 104 | */ |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 105 | @SystemApi @Deprecated |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 106 | public int getIconResId() { |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 107 | // Minimal compatibility shim for legacy apps' tests |
| 108 | return 0; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /** |
| 112 | * @return An icon displayed in the in-call UI. |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 113 | * |
| 114 | * @hide |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 115 | */ |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 116 | @SystemApi @Deprecated |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 117 | public Drawable getIcon(Context context) { |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 118 | return mIcon.loadDrawable(context); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @return An icon depicting the status. |
| 123 | */ |
| 124 | public Icon getIcon() { |
| 125 | return mIcon; |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 128 | /** |
| 129 | * @return Extra data used to display status. |
| 130 | */ |
| 131 | public Bundle getExtras() { |
| 132 | return mExtras; |
| 133 | } |
| 134 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 135 | @Override |
| 136 | public int describeContents() { |
| 137 | return 0; |
| 138 | } |
| 139 | |
Pranav Madapurmath | ac29a0c | 2023-05-25 21:58:19 +0000 | [diff] [blame] | 140 | /** |
| 141 | * Validates the StatusHints image icon to see if it's not in the calling user space. |
| 142 | * Invalidates the icon if so, otherwise returns back the original icon. |
| 143 | * |
| 144 | * @param icon |
| 145 | * @return icon (validated) |
| 146 | * @hide |
| 147 | */ |
| 148 | public static Icon validateAccountIconUserBoundary(Icon icon, UserHandle callingUserHandle) { |
| 149 | // Refer to Icon#getUriString for context. The URI string is invalid for icons of |
| 150 | // incompatible types. |
| 151 | if (icon != null && (icon.getType() == Icon.TYPE_URI |
| 152 | || icon.getType() == Icon.TYPE_URI_ADAPTIVE_BITMAP)) { |
| 153 | String encodedUser = icon.getUri().getEncodedUserInfo(); |
| 154 | // If there is no encoded user, the URI is calling into the calling user space |
| 155 | if (encodedUser != null) { |
| 156 | int userId = Integer.parseInt(encodedUser); |
| 157 | // Do not try to save the icon if the user id isn't in the calling user space. |
| 158 | if (userId != callingUserHandle.getIdentifier()) return null; |
| 159 | } |
| 160 | } |
| 161 | return icon; |
| 162 | } |
| 163 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 164 | @Override |
| 165 | public void writeToParcel(Parcel out, int flags) { |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 166 | out.writeCharSequence(mLabel); |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 167 | out.writeParcelable(mIcon, 0); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 168 | out.writeParcelable(mExtras, 0); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 171 | public static final @android.annotation.NonNull Creator<StatusHints> CREATOR |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 172 | = new Creator<StatusHints>() { |
| 173 | public StatusHints createFromParcel(Parcel in) { |
| 174 | return new StatusHints(in); |
| 175 | } |
| 176 | |
| 177 | public StatusHints[] newArray(int size) { |
| 178 | return new StatusHints[size]; |
| 179 | } |
| 180 | }; |
| 181 | |
| 182 | private StatusHints(Parcel in) { |
Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 183 | mLabel = in.readCharSequence(); |
Bernardo Rufino | 1a5cb38 | 2022-01-14 17:35:36 +0000 | [diff] [blame] | 184 | mIcon = in.readParcelable(getClass().getClassLoader(), android.graphics.drawable.Icon.class); |
| 185 | mExtras = in.readParcelable(getClass().getClassLoader(), android.os.Bundle.class); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 188 | @Override |
| 189 | public boolean equals(Object other) { |
| 190 | if (other != null && other instanceof StatusHints) { |
| 191 | StatusHints otherHints = (StatusHints) other; |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 192 | return Objects.equals(otherHints.getLabel(), getLabel()) && |
| 193 | Objects.equals(otherHints.getIcon(), getIcon()) && |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 194 | Objects.equals(otherHints.getExtras(), getExtras()); |
| 195 | } |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public int hashCode() { |
Ihab Awad | a7684ed | 2015-05-13 11:34:53 -0700 | [diff] [blame] | 201 | return Objects.hashCode(mLabel) + Objects.hashCode(mIcon) + Objects.hashCode(mExtras); |
Sailesh Nepal | f20b916 | 2014-08-12 11:53:32 -0700 | [diff] [blame] | 202 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 203 | } |