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