Merge "Merge "Check device owner by callingUid in ActivityStarter" into qt-dev am: ab48af4b76" into qt-dev-plus-aosp

am: bafc04a7cb

Change-Id: I4bea983f40a81e412c468391050e77f91383c1be
This commit is contained in:
Ricky Wai
2019-04-11 11:57:15 -07:00
committed by android-build-merger
5 changed files with 21 additions and 20 deletions

View File

@@ -1018,11 +1018,11 @@ class ActivityStarter {
if (mSupervisor.mRecentTasks.isCallerRecents(callingUid)) {
return false;
}
// don't abort if the callingPackage is the device owner
if (mService.isDeviceOwner(callingPackage)) {
// don't abort if the callingUid is the device owner
if (mService.isDeviceOwner(callingUid)) {
return false;
}
// don't abort if the callingPackage has companion device
// don't abort if the callingUid has companion device
final int callingUserId = UserHandle.getUserId(callingUid);
if (mService.isAssociatedCompanionApp(callingUserId, callingUid)) {
return false;

View File

@@ -507,9 +507,9 @@ public abstract class ActivityTaskManagerInternal {
public abstract boolean isUidForeground(int uid);
/**
* Called by DevicePolicyManagerService to set the package name of the device owner.
* Called by DevicePolicyManagerService to set the uid of the device owner.
*/
public abstract void setDeviceOwnerPackageName(String deviceOwnerPkg);
public abstract void setDeviceOwnerUid(int uid);
/** Set all associated companion app that belongs to an userId. */
public abstract void setCompanionAppPackages(int userId, Set<String> companionAppPackages);

View File

@@ -633,7 +633,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
private FontScaleSettingObserver mFontScaleSettingObserver;
private String mDeviceOwnerPackageName;
private int mDeviceOwnerUid = Process.INVALID_UID;
private final class FontScaleSettingObserver extends ContentObserver {
private final Uri mFontScaleUri = Settings.System.getUriFor(FONT_SCALE);
@@ -5876,15 +5876,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|| mWindowManager.mRoot.isAnyNonToastWindowVisibleForUid(uid);
}
boolean isDeviceOwner(String packageName) {
if (packageName == null) {
return false;
}
return packageName.equals(mDeviceOwnerPackageName);
boolean isDeviceOwner(int uid) {
return uid >= 0 && mDeviceOwnerUid == uid;
}
void setDeviceOwnerPackageName(String deviceOwnerPkg) {
mDeviceOwnerPackageName = deviceOwnerPkg;
void setDeviceOwnerUid(int uid) {
mDeviceOwnerUid = uid;
}
/**
@@ -7334,9 +7331,9 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
}
@Override
public void setDeviceOwnerPackageName(String deviceOwnerPkg) {
public void setDeviceOwnerUid(int uid) {
synchronized (mGlobalLock) {
ActivityTaskManagerService.this.setDeviceOwnerPackageName(deviceOwnerPkg);
ActivityTaskManagerService.this.setDeviceOwnerUid(uid);
}
}

View File

@@ -26,6 +26,7 @@ import android.content.pm.PackageManagerInternal;
import android.content.pm.UserInfo;
import android.os.Binder;
import android.os.Environment;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManagerInternal;
@@ -209,8 +210,11 @@ class Owners {
}
private void pushToActivityTaskManagerLocked() {
mActivityTaskManagerInternal.setDeviceOwnerPackageName(mDeviceOwner != null
? mDeviceOwner.packageName : null);
final int uid = mDeviceOwner != null ? mPackageManagerInternal.getPackageUid(
mDeviceOwner.packageName,
PackageManager.MATCH_ALL | PackageManager.MATCH_KNOWN_PACKAGES, mDeviceOwnerUserId)
: Process.INVALID_UID;
mActivityTaskManagerInternal.setDeviceOwnerUid(uid);
}
String getDeviceOwnerPackageName() {

View File

@@ -659,7 +659,7 @@ public class ActivityStarterTests extends ActivityTestsBase {
boolean hasForegroundActivities, boolean callerIsRecents,
boolean callerIsTempWhitelisted,
boolean callerIsInstrumentingWithBackgroundActivityStartPrivileges,
boolean isCallingPackageNameDeviceOwner, boolean isCallingPackageTempWhitelisted) {
boolean isCallingUidDeviceOwner, boolean isCallingPackageTempWhitelisted) {
// window visibility
doReturn(callingUidHasVisibleWindow).when(mService.mWindowManager.mRoot)
.isAnyNonToastWindowVisibleForUid(callingUid);
@@ -685,8 +685,8 @@ public class ActivityStarterTests extends ActivityTestsBase {
// caller is instrumenting with background activity starts privileges
callerApp.setInstrumenting(callerIsInstrumentingWithBackgroundActivityStartPrivileges,
callerIsInstrumentingWithBackgroundActivityStartPrivileges);
// calling package name is the device owner
doReturn(isCallingPackageNameDeviceOwner).when(mService).isDeviceOwner(any());
// callingUid is the device owner
doReturn(isCallingUidDeviceOwner).when(mService).isDeviceOwner(callingUid);
// calling package name is temporarily whitelisted
doReturn(isCallingPackageTempWhitelisted).when(mService)
.isPackageNameWhitelistedForBgActivityStarts("com.whatever.dude");