Prevent client got NPE crash if setIntent was set to null.

Not sure why app overwrite the start intent to null, but we should
prevent app from crash in frameworks.

Bug: 210930049
Test: run test app; presubmit
Change-Id: Ifa27c2258b1e7a2a49b1a4155bd5ada79fa2d1af
This commit is contained in:
wilsonshih
2021-12-27 21:17:05 +08:00
parent dfabfc6106
commit 70fb36f03d

View File

@@ -6191,18 +6191,20 @@ public class Activity extends ContextThemeWrapper
@Nullable
public Uri getReferrer() {
Intent intent = getIntent();
try {
Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
if (referrer != null) {
return referrer;
if (intent != null) {
try {
Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER);
if (referrer != null) {
return referrer;
}
String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME);
if (referrerName != null) {
return Uri.parse(referrerName);
}
} catch (BadParcelableException e) {
Log.w(TAG, "Cannot read referrer from intent;"
+ " intent extras contain unknown custom Parcelable objects");
}
String referrerName = intent.getStringExtra(Intent.EXTRA_REFERRER_NAME);
if (referrerName != null) {
return Uri.parse(referrerName);
}
} catch (BadParcelableException e) {
Log.w(TAG, "Cannot read referrer from intent;"
+ " intent extras contain unknown custom Parcelable objects");
}
if (mReferrer != null) {
return new Uri.Builder().scheme("android-app").authority(mReferrer).build();