From e89d0e1ba5cce0aa30575248c445c07ed4f923f3 Mon Sep 17 00:00:00 2001 From: Eric Sandness Date: Fri, 13 Mar 2020 17:55:51 +0000 Subject: [PATCH] Don't Show Work Profile Toast During Setup Before device setup is complete, we shouldn't ever show the "using this app outside your work profile" toast. This toast is confusing in the context of Setup Wizard. Fixes: 150451876 Test: atest com.android.internal.app.IntentForwarderActivityTest Test: Manually verified no toast during setup Test: Manually verified toast appears after setup Change-Id: I661cc18c625609726388f3705c7b893517e23323 --- .../internal/app/IntentForwarderActivity.java | 9 ++++++ .../app/IntentForwarderActivityTest.java | 30 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/core/java/com/android/internal/app/IntentForwarderActivity.java b/core/java/com/android/internal/app/IntentForwarderActivity.java index 7a0afa2036f69..9bdfa4ad4e438 100644 --- a/core/java/com/android/internal/app/IntentForwarderActivity.java +++ b/core/java/com/android/internal/app/IntentForwarderActivity.java @@ -38,6 +38,7 @@ import android.os.Bundle; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; +import android.provider.Settings; import android.util.Slog; import android.widget.Toast; @@ -153,6 +154,9 @@ public class IntentForwarderActivity extends Activity { } private boolean shouldShowDisclosure(@Nullable ResolveInfo ri, Intent intent) { + if (!isDeviceProvisioned()) { + return false; + } if (ri == null || ri.activityInfo == null) { return true; } @@ -163,6 +167,11 @@ public class IntentForwarderActivity extends Activity { return !isTargetResolverOrChooserActivity(ri.activityInfo); } + private boolean isDeviceProvisioned() { + return Settings.Global.getInt(getContentResolver(), + Settings.Global.DEVICE_PROVISIONED, /* def= */ 0) != 0; + } + private boolean isTextMessageIntent(Intent intent) { return (Intent.ACTION_SENDTO.equals(intent.getAction()) || isViewActionIntent(intent)) && ALLOWED_TEXT_MESSAGE_SCHEMES.contains(intent.getScheme()); diff --git a/core/tests/coretests/src/com/android/internal/app/IntentForwarderActivityTest.java b/core/tests/coretests/src/com/android/internal/app/IntentForwarderActivityTest.java index abfb4fb3cedc3..8cf146ea801d2 100644 --- a/core/tests/coretests/src/com/android/internal/app/IntentForwarderActivityTest.java +++ b/core/tests/coretests/src/com/android/internal/app/IntentForwarderActivityTest.java @@ -48,6 +48,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.os.UserHandle; import android.os.UserManager; +import android.provider.Settings; import androidx.test.InstrumentationRegistry; import androidx.test.rule.ActivityTestRule; @@ -56,6 +57,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -87,6 +89,7 @@ public class IntentForwarderActivityTest { static { MANAGED_PROFILE_INFO.id = 10; MANAGED_PROFILE_INFO.flags = UserInfo.FLAG_MANAGED_PROFILE; + MANAGED_PROFILE_INFO.userType = UserManager.USER_TYPE_PROFILE_MANAGED; } private static UserInfo CURRENT_USER_INFO = new UserInfo(); @@ -116,12 +119,21 @@ public class IntentForwarderActivityTest { private Context mContext; public static final String PHONE_NUMBER = "123-456-789"; + private int mDeviceProvisionedInitialValue; @Before public void setup() { MockitoAnnotations.initMocks(this); mContext = InstrumentationRegistry.getTargetContext(); sInjector = spy(new TestInjector()); + mDeviceProvisionedInitialValue = Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.DEVICE_PROVISIONED, /* def= */ 0); + } + + @After + public void tearDown() { + Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, + mDeviceProvisionedInitialValue); } @Test @@ -532,6 +544,22 @@ public class IntentForwarderActivityTest { verify(sInjector).showToast(anyInt(), anyInt()); } + @Test + public void shouldSkipDisclosure_duringDeviceSetup() throws RemoteException { + setupShouldSkipDisclosureTest(); + Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, + /* value= */ 0); + Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class) + .setAction(Intent.ACTION_VIEW) + .addCategory(Intent.CATEGORY_BROWSABLE) + .setData(Uri.fromParts("http", "apache.org", null)); + + mActivityRule.launchActivity(intent); + + verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt()); + verify(sInjector, never()).showToast(anyInt(), anyInt()); + } + @Test public void forwardToManagedProfile_LoggingTest() throws Exception { sComponentName = FORWARD_TO_MANAGED_PROFILE_COMPONENT_NAME; @@ -590,6 +618,8 @@ public class IntentForwarderActivityTest { sComponentName = FORWARD_TO_MANAGED_PROFILE_COMPONENT_NAME; sActivityName = "MyTestActivity"; sPackageName = "test.package.name"; + Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, + /* value= */ 1); when(mApplicationInfo.isSystemApp()).thenReturn(true); // Managed profile exists. List profiles = new ArrayList<>();