Merge "Setting Session commited broadcast when an existing apk is enabled for a different user" into oc-dev
This commit is contained in:
@@ -1696,15 +1696,27 @@ public class ApplicationPackageManager extends PackageManager {
|
||||
|
||||
@Override
|
||||
public int installExistingPackage(String packageName) throws NameNotFoundException {
|
||||
return installExistingPackageAsUser(packageName, mContext.getUserId());
|
||||
return installExistingPackage(packageName, PackageManager.INSTALL_REASON_UNKNOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int installExistingPackage(String packageName, int installReason)
|
||||
throws NameNotFoundException {
|
||||
return installExistingPackageAsUser(packageName, installReason, mContext.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int installExistingPackageAsUser(String packageName, int userId)
|
||||
throws NameNotFoundException {
|
||||
return installExistingPackageAsUser(packageName, PackageManager.INSTALL_REASON_UNKNOWN,
|
||||
userId);
|
||||
}
|
||||
|
||||
private int installExistingPackageAsUser(String packageName, int installReason, int userId)
|
||||
throws NameNotFoundException {
|
||||
try {
|
||||
int res = mPM.installExistingPackageAsUser(packageName, userId, 0 /*installFlags*/,
|
||||
PackageManager.INSTALL_REASON_UNKNOWN);
|
||||
installReason);
|
||||
if (res == INSTALL_FAILED_INVALID_URI) {
|
||||
throw new NameNotFoundException("Package " + packageName + " doesn't exist");
|
||||
}
|
||||
|
||||
@@ -4628,6 +4628,14 @@ public abstract class PackageManager {
|
||||
*/
|
||||
public abstract int installExistingPackage(String packageName) throws NameNotFoundException;
|
||||
|
||||
/**
|
||||
* If there is already an application with the given package name installed
|
||||
* on the system for other users, also install it for the calling user.
|
||||
* @hide
|
||||
*/
|
||||
public abstract int installExistingPackage(String packageName, @InstallReason int installReason)
|
||||
throws NameNotFoundException;
|
||||
|
||||
/**
|
||||
* If there is already an application with the given package name installed
|
||||
* on the system for other users, also install it for the specified user.
|
||||
|
||||
@@ -29,7 +29,6 @@ import static com.android.server.pm.PackageInstallerService.prepareExternalStage
|
||||
import static com.android.server.pm.PackageInstallerService.prepareStageDir;
|
||||
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
@@ -46,7 +45,6 @@ import android.content.pm.PackageParser.ApkLite;
|
||||
import android.content.pm.PackageParser.PackageLite;
|
||||
import android.content.pm.PackageParser.PackageParserException;
|
||||
import android.content.pm.Signature;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.FileBridge;
|
||||
@@ -56,7 +54,6 @@ import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
import android.os.ProxyFileDescriptorCallback;
|
||||
import android.os.RemoteException;
|
||||
import android.os.RevocableFileDescriptor;
|
||||
import android.os.UserHandle;
|
||||
@@ -1168,19 +1165,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
||||
// Send broadcast to default launcher only if it's a new install
|
||||
final boolean isNewInstall = extras == null || !extras.getBoolean(Intent.EXTRA_REPLACING);
|
||||
if (success && isNewInstall) {
|
||||
UserManagerService ums = UserManagerService.getInstance();
|
||||
if (ums != null) {
|
||||
final UserInfo parent = ums.getProfileParent(userId);
|
||||
final int launcherUid = (parent != null) ? parent.id : userId;
|
||||
final ComponentName launcherComponent = mPm.getDefaultHomeActivity(launcherUid);
|
||||
if (launcherComponent != null) {
|
||||
Intent launcherIntent = new Intent(PackageInstaller.ACTION_SESSION_COMMITTED)
|
||||
.putExtra(PackageInstaller.EXTRA_SESSION, generateInfo())
|
||||
.putExtra(Intent.EXTRA_USER, UserHandle.of(userId))
|
||||
.setPackage(launcherComponent.getPackageName());
|
||||
mContext.sendBroadcastAsUser(launcherIntent, UserHandle.of(launcherUid));
|
||||
}
|
||||
}
|
||||
mPm.sendSessionCommitBroadcast(generateInfo(), userId);
|
||||
}
|
||||
|
||||
mCallback.onSessionFinished(this, success);
|
||||
|
||||
@@ -13627,6 +13627,12 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
int userId) {
|
||||
final boolean isSystem = isSystemApp(pkgSetting) || isUpdatedSystemApp(pkgSetting);
|
||||
sendPackageAddedForNewUsers(packageName, isSystem, pkgSetting.appId, userId);
|
||||
|
||||
// Send a session commit broadcast
|
||||
final PackageInstaller.SessionInfo info = new PackageInstaller.SessionInfo();
|
||||
info.installReason = pkgSetting.getInstallReason(userId);
|
||||
info.appPackageName = packageName;
|
||||
sendSessionCommitBroadcast(info, userId);
|
||||
}
|
||||
|
||||
public void sendPackageAddedForNewUsers(String packageName, boolean isSystem, int appId, int... userIds) {
|
||||
@@ -20142,11 +20148,27 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
|
||||
return getHomeActivitiesAsUser(allHomeCandidates, UserHandle.getCallingUserId());
|
||||
}
|
||||
|
||||
public void sendSessionCommitBroadcast(PackageInstaller.SessionInfo sessionInfo, int userId) {
|
||||
UserManagerService ums = UserManagerService.getInstance();
|
||||
if (ums != null) {
|
||||
final UserInfo parent = ums.getProfileParent(userId);
|
||||
final int launcherUid = (parent != null) ? parent.id : userId;
|
||||
final ComponentName launcherComponent = getDefaultHomeActivity(launcherUid);
|
||||
if (launcherComponent != null) {
|
||||
Intent launcherIntent = new Intent(PackageInstaller.ACTION_SESSION_COMMITTED)
|
||||
.putExtra(PackageInstaller.EXTRA_SESSION, sessionInfo)
|
||||
.putExtra(Intent.EXTRA_USER, UserHandle.of(userId))
|
||||
.setPackage(launcherComponent.getPackageName());
|
||||
mContext.sendBroadcastAsUser(launcherIntent, UserHandle.of(launcherUid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report the 'Home' activity which is currently set as "always use this one". If non is set
|
||||
* then reports the most likely home activity or null if there are more than one.
|
||||
*/
|
||||
public ComponentName getDefaultHomeActivity(int userId) {
|
||||
private ComponentName getDefaultHomeActivity(int userId) {
|
||||
List<ResolveInfo> allHomeCandidates = new ArrayList<>();
|
||||
ComponentName cn = getHomeActivitiesAsUser(allHomeCandidates, userId);
|
||||
if (cn != null) {
|
||||
|
||||
@@ -982,6 +982,15 @@ public class MockPackageManager extends PackageManager {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
@Override
|
||||
public int installExistingPackage(String packageName, int installReason)
|
||||
throws NameNotFoundException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
|
||||
@@ -620,6 +620,12 @@ public class BridgePackageManager extends PackageManager {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int installExistingPackage(String packageName, int installReason)
|
||||
throws NameNotFoundException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int installExistingPackageAsUser(String packageName, int userId)
|
||||
throws NameNotFoundException {
|
||||
|
||||
Reference in New Issue
Block a user