Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3830374a authored by arangelov's avatar arangelov Committed by Antoan Angelov
Browse files

No disclaimer when switching profile for system SMS and dialer apps (2).

This CL improves on a previous one by preventing the Toast message from
showing when from a browser a user clicks a "tel:", "sms:", "smsto:",
"mms:" or "mmsto:" link. This is done by checking whether the intent
action is ACTION_VIEW and the intent category is CATEGORY_BROWSABLE
with intent data having one of the schemas. Also added
ACTION_CALL_PRIVILEGED and ACTION_CALL_EMERGENCY as they also open
the dialer.

Bug: 111228250
Test: atest FrameworksCoreTests:IntentForwarderActivityTest
Change-Id: I2e0c256aa170c868bf5528a06951cd75783e5d3c
parent d5796dd4
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.app.AppGlobals;
import android.app.admin.DevicePolicyManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -59,9 +58,11 @@ public class IntentForwarderActivity extends Activity {
    public static String FORWARD_INTENT_TO_MANAGED_PROFILE
            = "com.android.internal.app.ForwardIntentToManagedProfile";

    private static final Set<String> ALLOWED_TEXT_MESSAGE_SCHEME
    private static final Set<String> ALLOWED_TEXT_MESSAGE_SCHEMES
            = new HashSet<>(Arrays.asList("sms", "smsto", "mms", "mmsto"));

    private static final String TEL_SCHEME = "tel";

    private Injector mInjector;

    @Override
@@ -144,13 +145,21 @@ public class IntentForwarderActivity extends Activity {
    }

    private boolean isTextMessageIntent(Intent intent) {
        return Intent.ACTION_SENDTO.equals(intent.getAction()) && intent.getData() != null
            && ALLOWED_TEXT_MESSAGE_SCHEME.contains(intent.getData().getScheme());
        return (Intent.ACTION_SENDTO.equals(intent.getAction()) || isViewActionIntent(intent))
                && ALLOWED_TEXT_MESSAGE_SCHEMES.contains(intent.getScheme());
    }

    private boolean isDialerIntent(Intent intent) {
        return Intent.ACTION_DIAL.equals(intent.getAction())
            || Intent.ACTION_CALL.equals(intent.getAction());
                || Intent.ACTION_CALL.equals(intent.getAction())
                || Intent.ACTION_CALL_PRIVILEGED.equals(intent.getAction())
                || Intent.ACTION_CALL_EMERGENCY.equals(intent.getAction())
                || (isViewActionIntent(intent) && TEL_SCHEME.equals(intent.getScheme()));
    }

    private boolean isViewActionIntent(Intent intent) {
        return Intent.ACTION_VIEW.equals(intent.getAction())
                && intent.hasCategory(Intent.CATEGORY_BROWSABLE);
    }

    private boolean isTargetResolverOrChooserActivity(ActivityInfo activityInfo) {
+151 −22
Original line number Diff line number Diff line
@@ -68,12 +68,14 @@ public class IntentForwarderActivityTest {
    private static final String TYPE_PLAIN_TEXT = "text/plain";

    private static UserInfo MANAGED_PROFILE_INFO = new UserInfo();

    static {
        MANAGED_PROFILE_INFO.id = 10;
        MANAGED_PROFILE_INFO.flags = UserInfo.FLAG_MANAGED_PROFILE;
    }

    private static UserInfo CURRENT_USER_INFO = new UserInfo();

    static {
        CURRENT_USER_INFO.id = UserHandle.myUserId();
        CURRENT_USER_INFO.flags = 0;
@@ -84,10 +86,14 @@ public class IntentForwarderActivityTest {
    private static String sActivityName;
    private static String sPackageName;

    @Mock private IPackageManager mIPm;
    @Mock private PackageManager mPm;
    @Mock private UserManager mUserManager;
    @Mock private ApplicationInfo mApplicationInfo;
    @Mock
    private IPackageManager mIPm;
    @Mock
    private PackageManager mPm;
    @Mock
    private UserManager mUserManager;
    @Mock
    private ApplicationInfo mApplicationInfo;

    @Rule
    public ActivityTestRule<IntentForwarderWrapperActivity> mActivityRule =
@@ -300,6 +306,30 @@ public class IntentForwarderActivityTest {
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_callIntent_callPrivileged() throws RemoteException {
        setupShouldSkipDisclosureTest();
        Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class)
                .setAction(Intent.ACTION_CALL_PRIVILEGED);

        mActivityRule.launchActivity(intent);

        verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt());
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_callIntent_callEmergency() throws RemoteException {
        setupShouldSkipDisclosureTest();
        Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class)
                .setAction(Intent.ACTION_CALL_EMERGENCY);

        mActivityRule.launchActivity(intent);

        verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt());
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_callIntent_dial() throws RemoteException {
        setupShouldSkipDisclosureTest();
@@ -324,6 +354,20 @@ public class IntentForwarderActivityTest {
        verify(sInjector).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_callIntent_actionViewTel() throws RemoteException {
        setupShouldSkipDisclosureTest();
        Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class)
                .setAction(Intent.ACTION_VIEW)
                .addCategory(Intent.CATEGORY_BROWSABLE)
                .setData(Uri.fromParts("tel", PHONE_NUMBER, null));

        mActivityRule.launchActivity(intent);

        verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt());
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_textMessageIntent_sms() throws RemoteException {
        setupShouldSkipDisclosureTest();
@@ -376,6 +420,62 @@ public class IntentForwarderActivityTest {
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_textMessageIntent_actionViewSms() throws RemoteException {
        setupShouldSkipDisclosureTest();
        Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class)
                .setAction(Intent.ACTION_VIEW)
                .addCategory(Intent.CATEGORY_BROWSABLE)
                .setData(Uri.fromParts("sms", PHONE_NUMBER, null));

        mActivityRule.launchActivity(intent);

        verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt());
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_textMessageIntent_actionViewSmsto() throws RemoteException {
        setupShouldSkipDisclosureTest();
        Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class)
                .setAction(Intent.ACTION_VIEW)
                .addCategory(Intent.CATEGORY_BROWSABLE)
                .setData(Uri.fromParts("smsto", PHONE_NUMBER, null));

        mActivityRule.launchActivity(intent);

        verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt());
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_textMessageIntent_actionViewMms() throws RemoteException {
        setupShouldSkipDisclosureTest();
        Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class)
                .setAction(Intent.ACTION_VIEW)
                .addCategory(Intent.CATEGORY_BROWSABLE)
                .setData(Uri.fromParts("mms", PHONE_NUMBER, null));

        mActivityRule.launchActivity(intent);

        verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt());
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_textMessageIntent_actionViewMmsto() throws RemoteException {
        setupShouldSkipDisclosureTest();
        Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class)
                .setAction(Intent.ACTION_VIEW)
                .addCategory(Intent.CATEGORY_BROWSABLE)
                .setData(Uri.fromParts("mmsto", PHONE_NUMBER, null));

        mActivityRule.launchActivity(intent);

        verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt());
        verify(sInjector, never()).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_textMessageIntent_invalidUri() throws RemoteException {
        setupShouldSkipDisclosureTest();
@@ -389,6 +489,34 @@ public class IntentForwarderActivityTest {
        verify(sInjector).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_viewBrowsableIntent_invalidUri() throws RemoteException {
        setupShouldSkipDisclosureTest();
        Intent intent = new Intent(mContext, IntentForwarderWrapperActivity.class)
                .setAction(Intent.ACTION_VIEW)
                .addCategory(Intent.CATEGORY_BROWSABLE)
                .setData(Uri.fromParts("invalid", PHONE_NUMBER, null));

        mActivityRule.launchActivity(intent);

        verify(mIPm).canForwardTo(any(), any(), anyInt(), anyInt());
        verify(sInjector).showToast(anyInt(), anyInt());
    }

    @Test
    public void shouldSkipDisclosure_viewBrowsableIntent_normalUrl() throws RemoteException {
        setupShouldSkipDisclosureTest();
        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).showToast(anyInt(), anyInt());
    }

    private void setupShouldSkipDisclosureTest() throws RemoteException {
        sComponentName = FORWARD_TO_MANAGED_PROFILE_COMPONENT_NAME;
        sActivityName = "MyTestActivity";
@@ -405,6 +533,7 @@ public class IntentForwarderActivityTest {
    }

    public static class IntentForwarderWrapperActivity extends IntentForwarderActivity {

        private Intent mStartActivityIntent;
        private int mUserIdActivityLaunchedIn;