Propagate calling UID to AM from LauncherApps

- So that AM can perform all the necessary caller checks, except for the cross-profile/user check.

- Note PixelLauncher is the recent app which gets extra privileges. So I used ShortcutLauncherDemo
and a 3p launcher for manual tests.

Fixes: 78635323
Test: manual test, with a 3p launcher. (nova)
- Launch primary profile app -> launches fine
- Launch work profile app-> launches fine
- Launch suspended work profile app -> "can't open this app" dialog is shown.
- Launch the primary counterpart of the suspended work profile app -> launches fine.
- Launch work profile app in quiet mode, with separate work challenge
  -> "turn on work profile"? dialog is shown
    -> then "cancel" -> nothing happens.
    -> then "turn on" -> "re-enter your pin" is shown -> type pin -> work profile app starts fine.
- Launch work profile app without separate work challenge
  -> "turn on work profile"? dialog is shown
    -> then "cancel" -> nothing happens.
    -> then "turn on" -> work profile starts and the app starts fine.
- "App info" on work profile app -> Setting page opens fine.
- "App info" on primary profile app -> Setting page opens fine.

Test: atest frameworks/base/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest*.java
Test: atest cts/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/LauncherApps*.java

Change-Id: Ie665a8890407d05c1d877f04d9c5c3a1caad18e1
This commit is contained in:
Makoto Onuki
2018-04-26 14:56:59 -07:00
parent 5d8dfe17c8
commit 1a34274336
9 changed files with 91 additions and 34 deletions

View File

@@ -235,6 +235,17 @@ public abstract class ActivityManagerInternal {
public abstract int startActivitiesAsPackage(String packageName,
int userId, Intent[] intents, Bundle bOptions);
/**
* Start activity {@code intent} without calling user-id check.
*
* - DO NOT call it with the calling UID cleared.
* - The caller must do the calling user ID check.
*
* @return error codes used by {@link IActivityManager#startActivity} and its siblings.
*/
public abstract int startActivityAsUser(IApplicationThread caller, String callingPackage,
Intent intent, @Nullable Bundle options, int userId);
/**
* Get the procstate for the UID. The return value will be between
* {@link ActivityManager#MIN_PROCESS_STATE} and {@link ActivityManager#MAX_PROCESS_STATE}.

View File

@@ -16,6 +16,7 @@
package android.content.pm;
import android.app.IApplicationThread;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentSender;
@@ -42,10 +43,10 @@ interface ILauncherApps {
String callingPackage, String packageName, in UserHandle user);
ActivityInfo resolveActivity(
String callingPackage, in ComponentName component, in UserHandle user);
void startActivityAsUser(String callingPackage,
void startActivityAsUser(in IApplicationThread caller, String callingPackage,
in ComponentName component, in Rect sourceBounds,
in Bundle opts, in UserHandle user);
void showAppDetailsAsUser(
void showAppDetailsAsUser(in IApplicationThread caller,
String callingPackage, in ComponentName component, in Rect sourceBounds,
in Bundle opts, in UserHandle user);
boolean isPackageEnabled(String callingPackage, String packageName, in UserHandle user);

View File

@@ -548,7 +548,8 @@ public class LauncherApps {
Log.i(TAG, "StartMainActivity " + component + " " + user.getIdentifier());
}
try {
mService.startActivityAsUser(mContext.getPackageName(),
mService.startActivityAsUser(mContext.getIApplicationThread(),
mContext.getPackageName(),
component, sourceBounds, opts, user);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
@@ -568,7 +569,8 @@ public class LauncherApps {
Rect sourceBounds, Bundle opts) {
logErrorForInvalidProfileAccess(user);
try {
mService.showAppDetailsAsUser(mContext.getPackageName(),
mService.showAppDetailsAsUser(mContext.getIApplicationThread(),
mContext.getPackageName(),
component, sourceBounds, opts, user);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();