OSDN Git Service

Show disclosure when an intent switches profiles
authorRobin Lee <rgl@google.com>
Wed, 23 Jul 2014 22:41:31 +0000 (23:41 +0100)
committerRobin Lee <rgl@google.com>
Thu, 24 Jul 2014 09:12:55 +0000 (09:12 +0000)
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

core/java/com/android/internal/app/IntentForwarderActivity.java
core/res/res/values/strings.xml
core/res/res/values/symbols.xml

index 01e5d40..0eadde1 100644 (file)
 
 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());
index 31920fa..351acf0 100644 (file)
     <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. -->
index c324e93..9f627b4 100644 (file)
@@ -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" />
   <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" />