Merge "Enabling ActivityTaskManagerService to retrieve PackageConfigUpdater for arbitrary packages." into sc-v2-dev
This commit is contained in:
@@ -596,10 +596,17 @@ public abstract class ActivityTaskManagerInternal {
|
||||
public abstract boolean isBaseOfLockedTask(String packageName);
|
||||
|
||||
/**
|
||||
* Create an interface to update configuration for an application.
|
||||
* Creates an interface to update configuration for the calling application.
|
||||
*/
|
||||
public abstract PackageConfigurationUpdater createPackageConfigurationUpdater();
|
||||
|
||||
/**
|
||||
* Creates an interface to update configuration for an arbitrary application specified by it's
|
||||
* packageName and userId.
|
||||
*/
|
||||
public abstract PackageConfigurationUpdater createPackageConfigurationUpdater(
|
||||
String packageName, int userId);
|
||||
|
||||
/**
|
||||
* An interface to update configuration for an application, and will persist override
|
||||
* configuration for this package.
|
||||
|
||||
@@ -6556,6 +6556,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
ActivityTaskManagerService.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageConfigurationUpdater createPackageConfigurationUpdater(
|
||||
String packageName , int userId) {
|
||||
return new PackageConfigurationUpdaterImpl(packageName, userId,
|
||||
ActivityTaskManagerService.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSystemAlertWindowPermission(int callingUid, int callingPid,
|
||||
String callingPackage) {
|
||||
|
||||
@@ -16,26 +16,40 @@
|
||||
|
||||
package com.android.server.wm;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Binder;
|
||||
import android.os.LocaleList;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Slog;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* An implementation of {@link ActivityTaskManagerInternal.PackageConfigurationUpdater}.
|
||||
*/
|
||||
final class PackageConfigurationUpdaterImpl implements
|
||||
ActivityTaskManagerInternal.PackageConfigurationUpdater {
|
||||
private static final String TAG = "PackageConfigurationUpdaterImpl";
|
||||
private final int mPid;
|
||||
private final Optional<Integer> mPid;
|
||||
private Integer mNightMode;
|
||||
private LocaleList mLocales;
|
||||
private String mPackageName;
|
||||
private int mUserId;
|
||||
private ActivityTaskManagerService mAtm;
|
||||
|
||||
PackageConfigurationUpdaterImpl(int pid, ActivityTaskManagerService atm) {
|
||||
mPid = pid;
|
||||
mPid = Optional.of(pid);
|
||||
mAtm = atm;
|
||||
}
|
||||
|
||||
PackageConfigurationUpdaterImpl(String packageName, int userId,
|
||||
ActivityTaskManagerService atm) {
|
||||
mPackageName = packageName;
|
||||
mUserId = userId;
|
||||
mAtm = atm;
|
||||
mPid = Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityTaskManagerInternal.PackageConfigurationUpdater setNightMode(int nightMode) {
|
||||
synchronized (this) {
|
||||
@@ -59,16 +73,29 @@ final class PackageConfigurationUpdaterImpl implements
|
||||
synchronized (mAtm.mGlobalLock) {
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
final WindowProcessController wpc = mAtm.mProcessMap.getProcess(mPid);
|
||||
if (wpc == null) {
|
||||
Slog.w(TAG, "Override application configuration: cannot find pid " + mPid);
|
||||
return;
|
||||
final int uid;
|
||||
if (mPid.isPresent()) {
|
||||
WindowProcessController wpc = mAtm.mProcessMap.getProcess(mPid.get());
|
||||
if (wpc == null) {
|
||||
Slog.w(TAG, "commit: Override application configuration failed: "
|
||||
+ "cannot find pid " + mPid);
|
||||
return;
|
||||
}
|
||||
uid = wpc.mUid;
|
||||
mUserId = wpc.mUserId;
|
||||
mPackageName = wpc.mInfo.packageName;
|
||||
} else {
|
||||
uid = mAtm.getPackageManagerInternalLocked().getPackageUid(mPackageName,
|
||||
/* flags = */ PackageManager.MATCH_ALL, mUserId);
|
||||
if (uid < 0) {
|
||||
Slog.w(TAG, "commit: update of application configuration failed: "
|
||||
+ "userId or packageName not valid " + mUserId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
LocaleList localesOverride = LocaleOverlayHelper.combineLocalesIfOverlayExists(
|
||||
mLocales, mAtm.getGlobalConfiguration().getLocales());
|
||||
wpc.applyAppSpecificConfig(mNightMode, localesOverride);
|
||||
wpc.updateAppSpecificSettingsForAllActivities(mNightMode, localesOverride);
|
||||
mAtm.mPackageConfigPersister.updateFromImpl(wpc.mName, wpc.mUserId, this);
|
||||
updateConfig(uid, mPackageName);
|
||||
mAtm.mPackageConfigPersister.updateFromImpl(mPackageName, mUserId, this);
|
||||
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
@@ -76,6 +103,19 @@ final class PackageConfigurationUpdaterImpl implements
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfig(int uid, String packageName) {
|
||||
final ArraySet<WindowProcessController> processes = mAtm.mProcessMap.getProcesses(uid);
|
||||
if (processes == null) return;
|
||||
for (int i = processes.size() - 1; i >= 0; i--) {
|
||||
final WindowProcessController wpc = processes.valueAt(i);
|
||||
if (!wpc.mInfo.packageName.equals(packageName)) continue;
|
||||
LocaleList localesOverride = LocaleOverlayHelper.combineLocalesIfOverlayExists(
|
||||
mLocales, mAtm.getGlobalConfiguration().getLocales());
|
||||
wpc.applyAppSpecificConfig(mNightMode, localesOverride);
|
||||
wpc.updateAppSpecificSettingsForAllActivities(mNightMode, localesOverride);
|
||||
}
|
||||
}
|
||||
|
||||
Integer getNightMode() {
|
||||
return mNightMode;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public class WindowProcessController extends ConfigurationContainer<Configuratio
|
||||
}
|
||||
|
||||
onConfigurationChanged(atm.getGlobalConfiguration());
|
||||
mAtm.mPackageConfigPersister.updateConfigIfNeeded(this, mUserId, mName);
|
||||
mAtm.mPackageConfigPersister.updateConfigIfNeeded(this, mUserId, mInfo.packageName);
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
|
||||
Reference in New Issue
Block a user