Commit 6073e2a4 authored by Lijin Shen's avatar Lijin Shen Committed by Commit Bot

Fix crash when default app manage setting activity is not available

Add a new criteria to detect the situation in which a browser other
than chrome channel is default and default app setting activity is not
available

Bug: 1105370
Change-Id: I625aae775933fdff8c912c07a2253db35a34bb21
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2296890
Commit-Queue: Lijin Shen <lazzzis@google.com>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788694}
parent 0e77709a
...@@ -82,7 +82,7 @@ public class DefaultBrowserPromoManager implements PauseResumeWithNativeObserver ...@@ -82,7 +82,7 @@ public class DefaultBrowserPromoManager implements PauseResumeWithNativeObserver
} else { } else {
promoByDisambiguationSheet(); promoByDisambiguationSheet();
} }
} else if (sdkInt >= Build.VERSION_CODES.M) { } else if (sdkInt >= Build.VERSION_CODES.N) {
promoBySystemSettings(); promoBySystemSettings();
} else { } else {
destroy(); destroy();
......
...@@ -8,6 +8,8 @@ import android.app.Activity; ...@@ -8,6 +8,8 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
...@@ -69,6 +71,8 @@ public class DefaultBrowserPromoUtils { ...@@ -69,6 +71,8 @@ public class DefaultBrowserPromoUtils {
* 4. On Chrome stable while no default browser is set and multiple chrome channels * 4. On Chrome stable while no default browser is set and multiple chrome channels
* are installed. * are installed.
* 5. Less than the promo interval if re-promoing. * 5. Less than the promo interval if re-promoing.
* 6. A browser other than chrome channel is default and default app setting is not
* available in the current system.
* *
* @param activity The context. * @param activity The context.
* @param dispatcher The {@link ActivityLifecycleDispatcher} of the current activity. * @param dispatcher The {@link ActivityLifecycleDispatcher} of the current activity.
...@@ -125,8 +129,12 @@ public class DefaultBrowserPromoUtils { ...@@ -125,8 +129,12 @@ public class DefaultBrowserPromoUtils {
// Already default // Already default
if (state == DefaultBrowserState.CHROME_DEFAULT) return false; if (state == DefaultBrowserState.CHROME_DEFAULT) return false;
// Criteria 3 // Criteria 3 & Criteria 6
if (state == DefaultBrowserState.OTHER_DEFAULT && isCurrentDefaultBrowserChrome(info)) { if (state == DefaultBrowserState.OTHER_DEFAULT
&& (isCurrentDefaultBrowserChrome(info)
|| !doesManageDefaultAppsSettingsActivityExist())) {
// Default apps setting activity does not exist on L and M. Early return
// before we write prefs and record metrics to skip the call to promo.
return false; return false;
} }
...@@ -234,4 +242,11 @@ public class DefaultBrowserPromoUtils { ...@@ -234,4 +242,11 @@ public class DefaultBrowserPromoUtils {
} }
return DefaultBrowserState.OTHER_DEFAULT; return DefaultBrowserState.OTHER_DEFAULT;
} }
private static boolean doesManageDefaultAppsSettingsActivityExist() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return false;
ResolveInfo info = PackageManagerUtils.resolveActivity(
new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS), 0);
return info != null && info.match != 0;
}
} }
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