From f654533f2d22ede2103ebdb2119a924399234d59 Mon Sep 17 00:00:00 2001 From: Sander Alewijnse Date: Fri, 31 Oct 2014 12:39:02 +0000 Subject: [PATCH] Show message when intent is forwarded across profiles. In resolver activity. Solution uses the contentUserHint. Bug:17199630 Change-Id: I208e55a2bb37c7cd147240986c7659fc66f3e228 --- .../internal/app/ResolverActivity.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index ccffa1985dbc1..6a94d69dd3430 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -100,6 +100,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic private int mMaxColumns; private int mLastSelected = ListView.INVALID_POSITION; private boolean mResolvingHome = false; + private int mProfileSwitchMessageId = -1; private UsageStatsManager mUsm; private Map mStats; @@ -200,6 +201,11 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic List rList, boolean alwaysUseOption) { setTheme(R.style.Theme_DeviceDefault_Resolver); super.onCreate(savedInstanceState); + + // Determine whether we should show that intent is forwarded + // from managed profile to owner or other way around. + setProfileSwitchMessageId(intent.getContentUserHint()); + try { mLaunchedFromUid = ActivityManagerNative.getDefault().getLaunchedFromUid( getActivityToken()); @@ -320,6 +326,22 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } } + private void setProfileSwitchMessageId(int contentUserHint) { + if (contentUserHint != UserHandle.USER_CURRENT && + contentUserHint != UserHandle.myUserId()) { + UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE); + UserInfo originUserInfo = userManager.getUserInfo(contentUserHint); + boolean originIsManaged = originUserInfo != null ? originUserInfo.isManagedProfile() + : false; + boolean targetIsManaged = userManager.isManagedProfile(); + if (originIsManaged && !targetIsManaged) { + mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_owner; + } else if (!originIsManaged && targetIsManaged) { + mProfileSwitchMessageId = com.android.internal.R.string.forward_intent_to_work; + } + } + } + /** * Turn on launch mode that is safe to use when forwarding intents received from * applications and running in system processes. This mode uses Activity.startActivityAsCaller @@ -642,6 +664,11 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } public void safelyStartActivity(Intent intent) { + // If needed, show that intent is forwarded + // from managed profile to owner or other way around. + if (mProfileSwitchMessageId != -1) { + Toast.makeText(this, getString(mProfileSwitchMessageId), Toast.LENGTH_LONG).show(); + } if (!mSafeForwardingMode) { startActivity(intent); onActivityStarted(intent);