From 3ea4310a2245763de1ba29b8ce0a21e99a702746 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Wed, 23 Jul 2014 23:41:31 +0100 Subject: [PATCH] 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 --- .../internal/app/IntentForwarderActivity.java | 27 ++++++++++++++++++---- core/res/res/values/strings.xml | 5 ++++ core/res/res/values/symbols.xml | 3 ++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/core/java/com/android/internal/app/IntentForwarderActivity.java b/core/java/com/android/internal/app/IntentForwarderActivity.java index 01e5d40d7b8b..0eadde1d735b 100644 --- a/core/java/com/android/internal/app/IntentForwarderActivity.java +++ b/core/java/com/android/internal/app/IntentForwarderActivity.java @@ -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()); diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 31920fa8baa0..351acf0a8f11 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -3926,6 +3926,11 @@ Permission requested Permission requested\nfor account %s. + + You\'re using this app in your personal space + + You\'re using this app in your work space + Input method diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index c324e93fa87b..9f627b4dea75 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -16,7 +16,6 @@ */ --> - @@ -1432,6 +1431,8 @@ + + -- 2.11.0