| 1 |
package android.app.assist; |
| 2 |
|
| 3 |
import android.compat.annotation.UnsupportedAppUsage; |
| 4 |
import android.content.ClipData; |
| 5 |
import android.content.Intent; |
| 6 |
import android.net.Uri; |
| 7 |
import android.os.Build; |
| 8 |
import android.os.Bundle; |
| 9 |
import android.os.Parcel; |
| 10 |
import android.os.Parcelable; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public class AssistContent implements Parcelable { |
| 18 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 19 |
private boolean mIsAppProvidedIntent = false; |
| 20 |
private boolean mIsAppProvidedWebUri = false; |
| 21 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 22 |
private Intent mIntent; |
| 23 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 24 |
private String mStructuredData; |
| 25 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 26 |
private ClipData mClipData; |
| 27 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 28 |
private Uri mUri; |
| 29 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 30 |
private final Bundle mExtras; |
| 31 |
|
| 32 |
public AssistContent() { |
| 33 |
mExtras = new Bundle(); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public void setDefaultIntent(Intent intent) { |
| 45 |
mIntent = intent; |
| 46 |
mIsAppProvidedIntent = false; |
| 47 |
mIsAppProvidedWebUri = false; |
| 48 |
mUri = null; |
| 49 |
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { |
| 50 |
Uri uri = intent.getData(); |
| 51 |
if (uri != null) { |
| 52 |
if ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())) { |
| 53 |
mUri = uri; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public void setIntent(Intent intent) { |
| 66 |
mIsAppProvidedIntent = true; |
| 67 |
mIntent = intent; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public Intent getIntent() { |
| 75 |
return mIntent; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
public boolean isAppProvidedIntent() { |
| 85 |
return mIsAppProvidedIntent; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public void setClipData(ClipData clip) { |
| 94 |
mClipData = clip; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public ClipData getClipData() { |
| 101 |
return mClipData; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public void setStructuredData(String structuredData) { |
| 110 |
mStructuredData = structuredData; |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public String getStructuredData() { |
| 117 |
return mStructuredData; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public void setWebUri(Uri uri) { |
| 130 |
mIsAppProvidedWebUri = true; |
| 131 |
mUri = uri; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
public Uri getWebUri() { |
| 139 |
return mUri; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
public boolean isAppProvidedWebUri() { |
| 149 |
return mIsAppProvidedWebUri; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
public Bundle getExtras() { |
| 156 |
return mExtras; |
| 157 |
} |
| 158 |
|
| 159 |
@UnsupportedAppUsage |
| 160 |
AssistContent(Parcel in) { |
| 161 |
if (in.readInt() != 0) { |
| 162 |
mIntent = Intent.CREATOR.createFromParcel(in); |
| 163 |
} |
| 164 |
if (in.readInt() != 0) { |
| 165 |
mClipData = ClipData.CREATOR.createFromParcel(in); |
| 166 |
} |
| 167 |
if (in.readInt() != 0) { |
| 168 |
mUri = Uri.CREATOR.createFromParcel(in); |
| 169 |
} |
| 170 |
if (in.readInt() != 0) { |
| 171 |
mStructuredData = in.readString(); |
| 172 |
} |
| 173 |
mIsAppProvidedIntent = in.readInt() == 1; |
| 174 |
mExtras = in.readBundle(); |
| 175 |
mIsAppProvidedWebUri = in.readInt() == 1; |
| 176 |
} |
| 177 |
|
| 178 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 179 |
void writeToParcelInternal(Parcel dest, int flags) { |
| 180 |
if (mIntent != null) { |
| 181 |
dest.writeInt(1); |
| 182 |
mIntent.writeToParcel(dest, flags); |
| 183 |
} else { |
| 184 |
dest.writeInt(0); |
| 185 |
} |
| 186 |
if (mClipData != null) { |
| 187 |
dest.writeInt(1); |
| 188 |
mClipData.writeToParcel(dest, flags); |
| 189 |
} else { |
| 190 |
dest.writeInt(0); |
| 191 |
} |
| 192 |
if (mUri != null) { |
| 193 |
dest.writeInt(1); |
| 194 |
mUri.writeToParcel(dest, flags); |
| 195 |
} else { |
| 196 |
dest.writeInt(0); |
| 197 |
} |
| 198 |
if (mStructuredData != null) { |
| 199 |
dest.writeInt(1); |
| 200 |
dest.writeString(mStructuredData); |
| 201 |
} else { |
| 202 |
dest.writeInt(0); |
| 203 |
} |
| 204 |
dest.writeInt(mIsAppProvidedIntent ? 1 : 0); |
| 205 |
dest.writeBundle(mExtras); |
| 206 |
dest.writeInt(mIsAppProvidedWebUri ? 1 : 0); |
| 207 |
} |
| 208 |
|
| 209 |
@Override |
| 210 |
public int describeContents() { |
| 211 |
return 0; |
| 212 |
} |
| 213 |
|
| 214 |
@Override |
| 215 |
public void writeToParcel(Parcel dest, int flags) { |
| 216 |
writeToParcelInternal(dest, flags); |
| 217 |
} |
| 218 |
|
| 219 |
public static final @android.annotation.NonNull Parcelable.Creator<AssistContent> CREATOR |
| 220 |
= new Parcelable.Creator<AssistContent>() { |
| 221 |
public AssistContent createFromParcel(Parcel in) { |
| 222 |
return new AssistContent(in); |
| 223 |
} |
| 224 |
|
| 225 |
public AssistContent[] newArray(int size) { |
| 226 |
return new AssistContent[size]; |
| 227 |
} |
| 228 |
}; |
| 229 |
} |