Commit edce258f authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Null check before getInstallerPackageName

The crash report shows the IllegalArgumentException is because of
package name is null.
Add a null check before getting the installer package name.

Bug: 1136018
Change-Id: I90f38bfcf67cf5de41996b3bf463633e2db2bca1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2457369
Commit-Queue: Ella Ge <eirage@chromium.org>
Reviewed-by: default avatarPeter Conn <peconn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815659}
parent 8bfd8243
...@@ -157,10 +157,7 @@ public class QualityEnforcer implements NativeInitObserver { ...@@ -157,10 +157,7 @@ public class QualityEnforcer implements NativeInitObserver {
// Do not crash on assetlink failures if the client app does not have installer package // Do not crash on assetlink failures if the client app does not have installer package
// name. // name.
if (type == ViolationType.DIGITAL_ASSETLINKS if (type == ViolationType.DIGITAL_ASSETLINKS && !isDebugInstall()) {
&& ContextUtils.getApplicationContext().getPackageManager().getInstallerPackageName(
mClientPackageNameProvider.get())
== null) {
return; return;
} }
...@@ -177,7 +174,7 @@ public class QualityEnforcer implements NativeInitObserver { ...@@ -177,7 +174,7 @@ public class QualityEnforcer implements NativeInitObserver {
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
// Only shows the toast when the TWA client app does not have installer info, i.e. install // Only shows the toast when the TWA client app does not have installer info, i.e. install
// via adb instead of a store. // via adb instead of a store.
if (pm.getInstallerPackageName(mClientPackageNameProvider.get()) == null) { if (!isDebugInstall()) {
Toast.makeText(context, message, Toast.LENGTH_LONG).show(); Toast.makeText(context, message, Toast.LENGTH_LONG).show();
} }
} }
...@@ -229,4 +226,13 @@ public class QualityEnforcer implements NativeInitObserver { ...@@ -229,4 +226,13 @@ public class QualityEnforcer implements NativeInitObserver {
return ""; return "";
} }
} }
private boolean isDebugInstall() {
// TODO(crbug.com/1136153) Need to figure out why the client package name can be null.
if (mClientPackageNameProvider.get() == null) return false;
return ContextUtils.getApplicationContext().getPackageManager().getInstallerPackageName(
mClientPackageNameProvider.get())
!= null;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment