From 1affbbc5932231d5a1fa4563ef0623b4eaaa9cdd Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Sun, 1 May 2016 09:03:52 -0700 Subject: [PATCH] Launch home activity in home stack if coming from ResolverActivity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ResolverActivity launches activities it resolves as the initial caller. In the case of the home intent it can be sys-ui, but only the system server is currently allow to launch things into the home stack, so the resolved home activity is placed in non-home stack. This wasn’t a visible problem in fullscreen mode as the user would notice since everything is fullscreen, however it is very visible in multi-window mode. We now allow home activities to be places in the home stack if it is coming from the ResolverActivity. Bug: 28487506 Change-Id: I68f81da68a207efab9ce911fa6661bd573f1e949 --- .../com/android/server/am/ActivityRecord.java | 50 ++++++++++++------- .../android/server/am/ActivityStarter.java | 2 +- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index 2386a361d94b8..fa69b4a857df3 100755 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -592,7 +592,7 @@ final class ActivityRecord { ActivityRecord _resultTo, String _resultWho, int _reqCode, boolean _componentSpecified, boolean _rootVoiceInteraction, ActivityStackSupervisor supervisor, - ActivityContainer container, ActivityOptions options) { + ActivityContainer container, ActivityOptions options, ActivityRecord sourceRecord) { service = _service; appToken = new Token(this, service); info = aInfo; @@ -705,21 +705,7 @@ final class ActivityRecord { noDisplay = ent != null && ent.array.getBoolean( com.android.internal.R.styleable.Window_windowNoDisplay, false); - if ((!_componentSpecified || _launchedFromUid == Process.myUid() - || _launchedFromUid == 0) && - Intent.ACTION_MAIN.equals(_intent.getAction()) && - _intent.hasCategory(Intent.CATEGORY_HOME) && - _intent.getCategories().size() == 1 && - _intent.getData() == null && - _intent.getType() == null && - !isResolverActivity()) { - // This sure looks like a home activity! - mActivityType = HOME_ACTIVITY_TYPE; - } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) { - mActivityType = RECENTS_ACTIVITY_TYPE; - } else { - mActivityType = APPLICATION_ACTIVITY_TYPE; - } + setActivityType(_componentSpecified, _launchedFromUid, _intent, sourceRecord); immersive = (aInfo.flags & ActivityInfo.FLAG_IMMERSIVE) != 0; @@ -740,6 +726,36 @@ final class ActivityRecord { } } + private boolean isHomeIntent(Intent intent) { + return Intent.ACTION_MAIN.equals(intent.getAction()) + && intent.hasCategory(Intent.CATEGORY_HOME) + && intent.getCategories().size() == 1 + && intent.getData() == null + && intent.getType() == null; + } + + private boolean canLaunchHomeActivity(int uid, ActivityRecord sourceRecord) { + if (uid == Process.myUid() || uid == 0) { + // System process can launch home activity. + return true; + } + // Resolver activity can launch home activity. + return sourceRecord != null && sourceRecord.isResolverActivity(); + } + + private void setActivityType(boolean componentSpecified, + int launchedFromUid, Intent intent, ActivityRecord sourceRecord) { + if ((!componentSpecified || canLaunchHomeActivity(launchedFromUid, sourceRecord)) + && isHomeIntent(intent) && !isResolverActivity()) { + // This sure looks like a home activity! + mActivityType = HOME_ACTIVITY_TYPE; + } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) { + mActivityType = RECENTS_ACTIVITY_TYPE; + } else { + mActivityType = APPLICATION_ACTIVITY_TYPE; + } + } + void setTask(TaskRecord newTask, TaskRecord taskToAffiliateWith) { if (task != null && task.removeActivity(this) && task != newTask && task.stack != null) { task.stack.removeTask(task, "setTask"); @@ -1473,7 +1489,7 @@ final class ActivityRecord { } final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid, launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(), - null, null, 0, componentSpecified, false, stackSupervisor, null, null); + null, null, 0, componentSpecified, false, stackSupervisor, null, null, null); r.persistentState = persistentState; r.taskDescription = taskDescription; diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java index 33b87b656fa08..5f1dd37e93042 100644 --- a/services/core/java/com/android/server/am/ActivityStarter.java +++ b/services/core/java/com/android/server/am/ActivityStarter.java @@ -492,7 +492,7 @@ class ActivityStarter { ActivityRecord r = new ActivityRecord(mService, callerApp, callingUid, callingPackage, intent, resolvedType, aInfo, mService.mConfiguration, resultRecord, resultWho, requestCode, componentSpecified, voiceSession != null, mSupervisor, container, - options); + options, sourceRecord); if (outActivity != null) { outActivity[0] = r; }