OSDN Git Service

Fix Settings crash when trying to show work policy info
authorIvan Podogov <ginkage@google.com>
Thu, 20 Jun 2019 15:01:29 +0000 (16:01 +0100)
committerIvan Podogov <ginkage@google.com>
Thu, 20 Jun 2019 15:28:47 +0000 (16:28 +0100)
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

src/com/android/settings/enterprise/EnterprisePrivacyFeatureProviderImpl.java

index d095d88..675795e 100644 (file)
@@ -279,7 +279,8 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
         // Only search for the required action in the Device Owner's package
         final Intent intent =
                 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);
         if (activities.size() != 0) {
             return intent;
@@ -302,7 +303,8 @@ public class EnterprisePrivacyFeatureProviderImpl implements EnterprisePrivacyFe
         // Only search for the required action in the Profile Owner's package
         final Intent intent =
                 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);
         if (activities.size() != 0) {
             return intent;