diff options
Diffstat (limited to 'core/java/com/android/internal/app/ResolverActivity.java')
-rw-r--r-- | core/java/com/android/internal/app/ResolverActivity.java | 76 |
1 files changed, 70 insertions, 6 deletions
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 0062e2d..2db466a 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -74,6 +74,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; +import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; + /** * This activity is displayed when the system attempts to start an Intent for * which there is more than one matching activity, allowing the user to decide @@ -97,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<String, UsageStats> mStats; @@ -197,6 +201,11 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic List<ResolveInfo> 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()); @@ -269,12 +278,15 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic mListView = (ListView) findViewById(R.id.resolver_list); mListView.setVisibility(View.GONE); } + // Prevent the Resolver window from becoming the top fullscreen window and thus from taking + // control of the system bars. + getWindow().clearFlags(FLAG_LAYOUT_IN_SCREEN|FLAG_LAYOUT_INSET_DECOR); final ResolverDrawerLayout rdl = (ResolverDrawerLayout) findViewById(R.id.contentPanel); if (rdl != null) { - rdl.setOnClickOutsideListener(new View.OnClickListener() { + rdl.setOnDismissedListener(new ResolverDrawerLayout.OnDismissedListener() { @Override - public void onClick(View v) { + public void onDismissed() { finish(); } }); @@ -314,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 @@ -523,7 +551,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic /** * Replace me in subclasses! */ - public Intent getReplacementIntent(String packageName, Intent defIntent) { + public Intent getReplacementIntent(ActivityInfo aInfo, Intent defIntent) { return defIntent; } @@ -636,12 +664,19 @@ 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); return; } try { startActivityAsCaller(intent, null, UserHandle.USER_NULL); + onActivityStarted(intent); } catch (RuntimeException e) { String launchedFromPackage; try { @@ -656,6 +691,10 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } } + public void onActivityStarted(Intent intent) { + // Do nothing + } + void showAppDetails(ResolveInfo ri) { Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) .setData(Uri.fromParts("package", ri.activityInfo.packageName, null)) @@ -801,7 +840,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } if (N > 1) { Comparator<ResolveInfo> rComparator = - new ResolverComparator(ResolverActivity.this); + new ResolverComparator(ResolverActivity.this, mIntent); Collections.sort(currentResolveList, rComparator); } // First put the initial items at the top. @@ -819,6 +858,11 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } ResolveInfo ri = new ResolveInfo(); ri.activityInfo = ai; + UserManager userManager = + (UserManager) getSystemService(Context.USER_SERVICE); + if (userManager.isManagedProfile()) { + ri.noResourceId = true; + } if (ii instanceof LabeledIntent) { LabeledIntent li = (LabeledIntent)ii; ri.resolvePackageName = li.getSourcePackage(); @@ -926,7 +970,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic DisplayResolveInfo dri = filtered ? getItem(position) : mList.get(position); Intent intent = new Intent(dri.origIntent != null ? dri.origIntent : - getReplacementIntent(dri.ri.activityInfo.packageName, mIntent)); + getReplacementIntent(dri.ri.activityInfo, mIntent)); intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT |Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); ActivityInfo ai = dri.ri.activityInfo; @@ -1049,11 +1093,20 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } } + static final boolean isSpecificUriMatch(int match) { + match = match&IntentFilter.MATCH_CATEGORY_MASK; + return match >= IntentFilter.MATCH_CATEGORY_HOST + && match <= IntentFilter.MATCH_CATEGORY_PATH; + } + class ResolverComparator implements Comparator<ResolveInfo> { private final Collator mCollator; + private final boolean mHttp; - public ResolverComparator(Context context) { + public ResolverComparator(Context context, Intent intent) { mCollator = Collator.getInstance(context.getResources().getConfiguration().locale); + String scheme = intent.getScheme(); + mHttp = "http".equals(scheme) || "https".equals(scheme); } @Override @@ -1063,6 +1116,17 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic return 1; } + if (mHttp) { + // Special case: we want filters that match URI paths/schemes to be + // ordered before others. This is for the case when opening URIs, + // to make native apps go above browsers. + final boolean lhsSpecific = isSpecificUriMatch(lhs.match); + final boolean rhsSpecific = isSpecificUriMatch(rhs.match); + if (lhsSpecific != rhsSpecific) { + return lhsSpecific ? -1 : 1; + } + } + if (mStats != null) { final long timeDiff = getPackageTimeSpent(rhs.activityInfo.packageName) - |