Change density for the correct user
Bug: 30839993 Change-Id: I5368accddfc4a03b8025a257b4155fcdc6197f11
This commit is contained in:
@@ -23,6 +23,7 @@ import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import android.util.AndroidException;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
@@ -201,9 +202,11 @@ public class Wm extends BaseCommand {
|
||||
try {
|
||||
if (density > 0) {
|
||||
// TODO(multidisplay): For now Configuration only applies to main screen.
|
||||
mWm.setForcedDisplayDensity(Display.DEFAULT_DISPLAY, density);
|
||||
mWm.setForcedDisplayDensityForUser(Display.DEFAULT_DISPLAY, density,
|
||||
UserHandle.USER_CURRENT);
|
||||
} else {
|
||||
mWm.clearForcedDisplayDensity(Display.DEFAULT_DISPLAY);
|
||||
mWm.clearForcedDisplayDensityForUser(Display.DEFAULT_DISPLAY,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ interface IWindowManager
|
||||
void clearForcedDisplaySize(int displayId);
|
||||
int getInitialDisplayDensity(int displayId);
|
||||
int getBaseDisplayDensity(int displayId);
|
||||
void setForcedDisplayDensity(int displayId, int density);
|
||||
void clearForcedDisplayDensity(int displayId);
|
||||
void setForcedDisplayDensityForUser(int displayId, int density, int userId);
|
||||
void clearForcedDisplayDensityForUser(int displayId, int userId);
|
||||
void setForcedDisplayScalingMode(int displayId, int mode); // 0 = auto, 1 = disable
|
||||
|
||||
void setOverscan(int displayId, int left, int top, int right, int bottom);
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.content.res.Resources;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.MathUtils;
|
||||
@@ -207,39 +208,41 @@ public class DisplayDensityUtils {
|
||||
|
||||
/**
|
||||
* Asynchronously applies display density changes to the specified display.
|
||||
* <p>
|
||||
* The change will be applied to the user specified by the value of
|
||||
* {@link UserHandle#myUserId()} at the time the method is called.
|
||||
*
|
||||
* @param displayId the identifier of the display to modify
|
||||
*/
|
||||
public static void clearForcedDisplayDensity(final int displayId) {
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
|
||||
wm.clearForcedDisplayDensity(displayId);
|
||||
} catch (RemoteException exc) {
|
||||
Log.w(LOG_TAG, "Unable to clear forced display density setting");
|
||||
}
|
||||
final int userId = UserHandle.myUserId();
|
||||
AsyncTask.execute(() -> {
|
||||
try {
|
||||
final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
|
||||
wm.clearForcedDisplayDensityForUser(displayId, userId);
|
||||
} catch (RemoteException exc) {
|
||||
Log.w(LOG_TAG, "Unable to clear forced display density setting");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously applies display density changes to the specified display.
|
||||
* <p>
|
||||
* The change will be applied to the user specified by the value of
|
||||
* {@link UserHandle#myUserId()} at the time the method is called.
|
||||
*
|
||||
* @param displayId the identifier of the display to modify
|
||||
* @param density the density to force for the specified display
|
||||
*/
|
||||
public static void setForcedDisplayDensity(final int displayId, final int density) {
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
|
||||
wm.setForcedDisplayDensity(displayId, density);
|
||||
} catch (RemoteException exc) {
|
||||
Log.w(LOG_TAG, "Unable to save forced display density setting");
|
||||
}
|
||||
final int userId = UserHandle.myUserId();
|
||||
AsyncTask.execute(() -> {
|
||||
try {
|
||||
final IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
|
||||
wm.setForcedDisplayDensityForUser(displayId, density, userId);
|
||||
} catch (RemoteException exc) {
|
||||
Log.w(LOG_TAG, "Unable to save forced display density setting");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.animation.ValueAnimator;
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerInternal;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.AppOpsManager;
|
||||
@@ -9192,7 +9193,7 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForcedDisplayDensity(int displayId, int density) {
|
||||
public void setForcedDisplayDensityForUser(int displayId, int density, int userId) {
|
||||
if (mContext.checkCallingOrSelfPermission(
|
||||
android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
|
||||
PackageManager.PERMISSION_GRANTED) {
|
||||
@@ -9202,16 +9203,20 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
if (displayId != Display.DEFAULT_DISPLAY) {
|
||||
throw new IllegalArgumentException("Can only set the default display");
|
||||
}
|
||||
|
||||
final int targetUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
|
||||
Binder.getCallingUid(), userId, false, true, "setForcedDisplayDensityForUser",
|
||||
null);
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
synchronized(mWindowMap) {
|
||||
final DisplayContent displayContent = getDisplayContentLocked(displayId);
|
||||
if (displayContent != null) {
|
||||
if (displayContent != null && mCurrentUserId == targetUserId) {
|
||||
setForcedDisplayDensityLocked(displayContent, density);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.DISPLAY_DENSITY_FORCED,
|
||||
Integer.toString(density), mCurrentUserId);
|
||||
}
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.DISPLAY_DENSITY_FORCED,
|
||||
Integer.toString(density), targetUserId);
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
@@ -9219,7 +9224,7 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearForcedDisplayDensity(int displayId) {
|
||||
public void clearForcedDisplayDensityForUser(int displayId, int userId) {
|
||||
if (mContext.checkCallingOrSelfPermission(
|
||||
android.Manifest.permission.WRITE_SECURE_SETTINGS) !=
|
||||
PackageManager.PERMISSION_GRANTED) {
|
||||
@@ -9229,16 +9234,20 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
if (displayId != Display.DEFAULT_DISPLAY) {
|
||||
throw new IllegalArgumentException("Can only set the default display");
|
||||
}
|
||||
|
||||
final int callingUserId = ActivityManager.handleIncomingUser(Binder.getCallingPid(),
|
||||
Binder.getCallingUid(), userId, false, true, "clearForcedDisplayDensityForUser",
|
||||
null);
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
synchronized(mWindowMap) {
|
||||
final DisplayContent displayContent = getDisplayContentLocked(displayId);
|
||||
if (displayContent != null) {
|
||||
if (displayContent != null && mCurrentUserId == callingUserId) {
|
||||
setForcedDisplayDensityLocked(displayContent,
|
||||
displayContent.mInitialDisplayDensity);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.DISPLAY_DENSITY_FORCED, "", mCurrentUserId);
|
||||
}
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.DISPLAY_DENSITY_FORCED, "", callingUserId);
|
||||
}
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
|
||||
@@ -96,7 +96,7 @@ public class IWindowManagerImpl implements IWindowManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearForcedDisplayDensity(int displayId) throws RemoteException {
|
||||
public void clearForcedDisplayDensityForUser(int displayId, int userId) throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@@ -397,7 +397,8 @@ public class IWindowManagerImpl implements IWindowManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForcedDisplayDensity(int displayId, int density) throws RemoteException {
|
||||
public void setForcedDisplayDensityForUser(int displayId, int density, int userId)
|
||||
throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user