Fix setApplicationNightMode crash due to permission denial.
Test activity crash when calling UiModeManager#setApplicationNightMode. There should call clearCallingIdentity before updating configuration in system server. Also clear some code around those methods. Fixes: 189166288 Test: atest SplashscreenTests#testSetApplicationNightMode Change-Id: I163919927030f81739aa3d9520e2012a92028793
This commit is contained in:
@@ -67,7 +67,6 @@ interface IUiModeManager {
|
||||
* 1 - notnight mode
|
||||
* 2 - night mode
|
||||
* 3 - automatic mode switching
|
||||
* @throws RemoteException
|
||||
*/
|
||||
void setApplicationNightMode(in int mode);
|
||||
|
||||
|
||||
@@ -754,8 +754,7 @@ final class UiModeManagerService extends SystemService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationNightMode(@UiModeManager.NightMode int mode)
|
||||
throws RemoteException {
|
||||
public void setApplicationNightMode(@UiModeManager.NightMode int mode) {
|
||||
switch (mode) {
|
||||
case UiModeManager.MODE_NIGHT_NO:
|
||||
case UiModeManager.MODE_NIGHT_YES:
|
||||
@@ -776,14 +775,10 @@ final class UiModeManagerService extends SystemService {
|
||||
default:
|
||||
configNightMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
|
||||
}
|
||||
try {
|
||||
final ActivityTaskManagerInternal.PackageConfigurationUpdater updater =
|
||||
mActivityTaskManager.createPackageConfigurationUpdater();
|
||||
updater.setNightMode(configNightMode);
|
||||
updater.commit();
|
||||
} catch (RemoteException e) {
|
||||
throw e;
|
||||
}
|
||||
final ActivityTaskManagerInternal.PackageConfigurationUpdater updater =
|
||||
mActivityTaskManager.createPackageConfigurationUpdater();
|
||||
updater.setNightMode(configNightMode);
|
||||
updater.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -618,7 +618,7 @@ public abstract class ActivityTaskManagerInternal {
|
||||
/**
|
||||
* Commit changes.
|
||||
*/
|
||||
void commit() throws RemoteException;
|
||||
void commit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6390,9 +6390,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
|
||||
@Override
|
||||
public PackageConfigurationUpdater createPackageConfigurationUpdater() {
|
||||
synchronized (mGlobalLock) {
|
||||
return new PackageConfigurationUpdaterImpl(Binder.getCallingPid());
|
||||
}
|
||||
return new PackageConfigurationUpdaterImpl(Binder.getCallingPid());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -6405,7 +6403,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
|
||||
final class PackageConfigurationUpdaterImpl implements
|
||||
ActivityTaskManagerInternal.PackageConfigurationUpdater {
|
||||
private int mPid;
|
||||
private final int mPid;
|
||||
private int mNightMode;
|
||||
|
||||
PackageConfigurationUpdaterImpl(int pid) {
|
||||
@@ -6419,24 +6417,26 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws RemoteException {
|
||||
if (mPid == 0) {
|
||||
throw new RemoteException("Invalid process");
|
||||
}
|
||||
public void commit() {
|
||||
synchronized (mGlobalLock) {
|
||||
final WindowProcessController wpc = mProcessMap.getProcess(mPid);
|
||||
if (wpc == null) {
|
||||
Slog.w(TAG, "Override application configuration: cannot find application");
|
||||
return;
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
final WindowProcessController wpc = mProcessMap.getProcess(mPid);
|
||||
if (wpc == null) {
|
||||
Slog.w(TAG, "Override application configuration: cannot find pid " + mPid);
|
||||
return;
|
||||
}
|
||||
if (wpc.getNightMode() == mNightMode) {
|
||||
return;
|
||||
}
|
||||
if (!wpc.setOverrideNightMode(mNightMode)) {
|
||||
return;
|
||||
}
|
||||
wpc.updateNightModeForAllActivities(mNightMode);
|
||||
mPackageConfigPersister.updateFromImpl(wpc.mName, wpc.mUserId, this);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
if (wpc.getNightMode() == mNightMode) {
|
||||
return;
|
||||
}
|
||||
if (!wpc.setOverrideNightMode(mNightMode)) {
|
||||
return;
|
||||
}
|
||||
wpc.updateNightModeForAllActivities(mNightMode);
|
||||
mPackageConfigPersister.updateFromImpl(wpc.mName, wpc.mUserId, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user