Merge "Refactor checkAddPermission"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c57793cee4
@@ -45,7 +45,6 @@ import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
|
||||
import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
|
||||
import static android.view.WindowManager.LayoutParams.LAST_SUB_WINDOW;
|
||||
import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW;
|
||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY;
|
||||
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
|
||||
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
|
||||
@@ -2058,11 +2057,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
|
||||
final int type = attrs.type;
|
||||
final boolean isRoundedCornerOverlay =
|
||||
(attrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0;
|
||||
|
||||
public int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName,
|
||||
int[] outAppOp) {
|
||||
if (isRoundedCornerOverlay && mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW)
|
||||
!= PERMISSION_GRANTED) {
|
||||
return ADD_PERMISSION_DENIED;
|
||||
@@ -2119,7 +2115,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
ApplicationInfo appInfo;
|
||||
try {
|
||||
appInfo = mPackageManager.getApplicationInfoAsUser(
|
||||
attrs.packageName,
|
||||
packageName,
|
||||
0 /* flags */,
|
||||
UserHandle.getUserId(callingUid));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
@@ -2139,7 +2135,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
|
||||
// check if user has enabled this operation. SecurityException will be thrown if this app
|
||||
// has not been allowed by the user
|
||||
final int mode = mAppOpsManager.noteOpNoThrow(outAppOp[0], callingUid, attrs.packageName);
|
||||
final int mode = mAppOpsManager.noteOpNoThrow(outAppOp[0], callingUid, packageName);
|
||||
switch (mode) {
|
||||
case AppOpsManager.MODE_ALLOWED:
|
||||
case AppOpsManager.MODE_IGNORED:
|
||||
|
||||
@@ -686,17 +686,25 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
|
||||
WindowManagerFuncs windowManagerFuncs);
|
||||
|
||||
/**
|
||||
* Check permissions when adding a window.
|
||||
* Check permissions when adding a window or a window token from
|
||||
* {@link android.app.WindowContext}.
|
||||
*
|
||||
* @param attrs The window's LayoutParams.
|
||||
* @param type The window type
|
||||
* @param isRoundedCornerOverlay {@code true} to indicate the adding window is
|
||||
* round corner overlay.
|
||||
* @param packageName package name
|
||||
* @param outAppOp First element will be filled with the app op corresponding to
|
||||
* this window, or OP_NONE.
|
||||
*
|
||||
* @return {@link WindowManagerGlobal#ADD_OKAY} if the add can proceed;
|
||||
* else an error code, usually
|
||||
* {@link WindowManagerGlobal#ADD_PERMISSION_DENIED}, to abort the add.
|
||||
*
|
||||
* @see IWindowManager#addWindowTokenWithOptions(IBinder, int, int, Bundle, String)
|
||||
* @see WindowManager.LayoutParams#PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY
|
||||
*/
|
||||
public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp);
|
||||
int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName,
|
||||
int[] outAppOp);
|
||||
|
||||
/**
|
||||
* After the window manager has computed the current configuration based
|
||||
|
||||
@@ -1336,7 +1336,10 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
DisplayCutout.ParcelableWrapper outDisplayCutout, InputChannel outInputChannel,
|
||||
InsetsState outInsetsState) {
|
||||
int[] appOp = new int[1];
|
||||
int res = mPolicy.checkAddPermission(attrs, appOp);
|
||||
final boolean isRoundedCornerOverlay = (attrs.privateFlags
|
||||
& PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0;
|
||||
int res = mPolicy.checkAddPermission(attrs.type, isRoundedCornerOverlay, attrs.packageName,
|
||||
appOp);
|
||||
if (res != WindowManagerGlobal.ADD_OKAY) {
|
||||
return res;
|
||||
}
|
||||
@@ -1410,8 +1413,6 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
|
||||
}
|
||||
final IBinder binder = attrs.token != null ? attrs.token : client.asBinder();
|
||||
final boolean isRoundedCornerOverlay =
|
||||
(attrs.privateFlags & PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY) != 0;
|
||||
token = new WindowToken(this, binder, type, false, displayContent,
|
||||
session.mCanAddInternalSystemWindow, isRoundedCornerOverlay);
|
||||
} else if (rootType >= FIRST_APPLICATION_WINDOW
|
||||
@@ -2560,10 +2561,8 @@ public class WindowManagerService extends IWindowManager.Stub
|
||||
final boolean callerCanManageAppTokens =
|
||||
checkCallingPermission(MANAGE_APP_TOKENS, "addWindowToken()");
|
||||
if (!callerCanManageAppTokens) {
|
||||
// TODO(window-context): refactor checkAddPermission to not take attrs.
|
||||
LayoutParams attrs = new LayoutParams(type);
|
||||
attrs.packageName = packageName;
|
||||
final int res = mPolicy.checkAddPermission(attrs, new int[1]);
|
||||
final int res = mPolicy.checkAddPermission(type, false /* isRoundedCornerOverlay */,
|
||||
packageName, new int[1]);
|
||||
if (res != ADD_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,8 @@ class TestWindowManagerPolicy implements WindowManagerPolicy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
|
||||
public int checkAddPermission(int type, boolean isRoundedCornerOverlay, String packageName,
|
||||
int[] outAppOp) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user