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

Commit 3ea4310a authored by Robin Lee's avatar Robin Lee
Browse files

Show disclosure when an intent switches profiles

If an activity in one profile starts an activity in another profile
without any user interaction - such as operating the chooser - a toast
appears, saying something like 'you are using this app in your work
space'.

@bug 14375080

Change-Id: Id2dc5973a9b68ee29d0227947c19b78f021fb6ac
parent 89a4f5d7
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -16,24 +16,25 @@

package com.android.internal.app;

import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;

import android.app.Activity;
import android.app.ActivityManagerNative;
import android.app.AppGlobals;
import android.os.Bundle;
import android.content.Context;
import android.content.Intent;
import android.content.pm.IPackageManager;
import android.content.pm.UserInfo;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.app.ActivityManagerNative;
import android.os.RemoteException;
import android.util.Slog;
import android.widget.Toast;
import java.util.List;
import java.util.Set;




/*
 * This is used in conjunction with the {@link setCrossProfileIntentFilter} method of
 * {@link DevicePolicyManager} to enable intents to be passed in and out of a managed profile.
@@ -56,13 +57,17 @@ public class IntentForwarderActivity extends Activity {

        String className = intentReceived.getComponent().getClassName();
        final UserHandle userDest;
        final int userMessageId;

        if (className.equals(FORWARD_INTENT_TO_USER_OWNER)) {
            userMessageId = com.android.internal.R.string.forward_intent_to_owner;
            userDest = UserHandle.OWNER;
        } else if (className.equals(FORWARD_INTENT_TO_MANAGED_PROFILE)) {
            userMessageId = com.android.internal.R.string.forward_intent_to_work;
            userDest = getManagedProfile();
        } else {
            Slog.wtf(TAG, IntentForwarderActivity.class.getName() + " cannot be called directly");
            userMessageId = -1;
            userDest = null;
        }
        if (userDest == null) { // This covers the case where there is no managed profile.
@@ -85,7 +90,19 @@ public class IntentForwarderActivity extends Activity {
        }
        if (canForward) {
            newIntent.prepareToLeaveUser(callingUserId);

            final android.content.pm.ResolveInfo ri = getPackageManager().resolveActivityAsUser(
                        newIntent, MATCH_DEFAULT_ONLY, userDest.getIdentifier());

            // Only show a disclosure if this is a normal (non-OS) app
            final boolean shouldShowDisclosure =
                    !UserHandle.isSameApp(ri.activityInfo.applicationInfo.uid, Process.SYSTEM_UID);

            startActivityAsUser(newIntent, userDest);

            if (shouldShowDisclosure) {
                Toast.makeText(this, getString(userMessageId), Toast.LENGTH_LONG).show();
            }
        } else {
            Slog.wtf(TAG, "the intent: " + newIntent + "cannot be forwarded from user "
                    + callingUserId + " to user " + userDest.getIdentifier());
+5 −0
Original line number Diff line number Diff line
@@ -3926,6 +3926,11 @@
    <string name="permission_request_notification_title">Permission requested</string>
    <string name="permission_request_notification_with_subtitle">Permission requested\nfor account <xliff:g id="account" example="foo@gmail.com">%s</xliff:g>.</string>

    <!-- Message to show when an intent automatically switches users into the personal profile. -->
    <string name="forward_intent_to_owner">You\'re using this app in your personal space</string>
    <!-- Message to show when an intent automatically switches users into a work profile. -->
    <string name="forward_intent_to_work">You\'re using this app in your work space</string>

    <!-- Label to show for a service that is running because it is an input method. -->
    <string name="input_method_binding_label">Input method</string>
    <!-- Label to show for a service that is running because it is a sync adapter. -->
+2 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
*/
-->
<resources>

  <!-- We don't want to publish private symbols in android.R as part of the
       SDK.  Instead, put them here. -->
  <private-symbols package="com.android.internal" />
@@ -1432,6 +1431,8 @@
  <java-symbol type="style" name="Animation.LockScreen" />
  <java-symbol type="style" name="Theme.Dialog.RecentApplications" />
  <java-symbol type="style" name="Theme.ExpandedMenu" />
  <java-symbol type="string" name="forward_intent_to_owner" />
  <java-symbol type="string" name="forward_intent_to_work" />

  <!-- From services -->
  <java-symbol type="anim" name="screen_rotate_0_enter" />