Fix Settings crash when trying to show work policy info

This fixes an exception in startActivity() call:

"android.util.AndroidRuntimeException: Calling startActivity() from outside of
an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really
what you want?"

Bug: 132904820
Test: manual
Change-Id: I0c687ea76068778554b072b6cc8274352de6fa28
This commit is contained in:
Ivan Podogov
2019-06-20 16:01:29 +01:00
parent 753215fff9
commit 242ff568d1

View File

@@ -279,7 +279,8 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
// Only search for the required action in the Device Owner's package // Only search for the required action in the Device Owner's package
final Intent intent = final Intent intent =
new Intent(mResources.getString(R.string.config_work_policy_info_intent_action)) new Intent(mResources.getString(R.string.config_work_policy_info_intent_action))
.setPackage(ownerComponent.getPackageName()); .setPackage(ownerComponent.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0); final List<ResolveInfo> activities = mPm.queryIntentActivities(intent, 0);
if (activities.size() != 0) { if (activities.size() != 0) {
return intent; return intent;
@@ -302,7 +303,8 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
// Only search for the required action in the Profile Owner's package // Only search for the required action in the Profile Owner's package
final Intent intent = final Intent intent =
new Intent(mResources.getString(R.string.config_work_policy_info_intent_action)) new Intent(mResources.getString(R.string.config_work_policy_info_intent_action))
.setPackage(ownerComponent.getPackageName()); .setPackage(ownerComponent.getPackageName())
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId); final List<ResolveInfo> activities = mPm.queryIntentActivitiesAsUser(intent, 0, userId);
if (activities.size() != 0) { if (activities.size() != 0) {
return intent; return intent;