1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.autofill.ui; 18 19 import android.annotation.NonNull; 20 import android.app.AppOpsManager; 21 import android.content.Context; 22 import android.os.Binder; 23 import android.os.IBinder; 24 import android.os.UserHandle; 25 26 /** 27 * This class controls showing/hiding overlays. We don't 28 * hide all overlays (toast/system alerts) while sensitive 29 * autofill UI is up. 30 */ 31 class OverlayControl { 32 33 private final IBinder mToken = new Binder(); 34 35 private final @NonNull AppOpsManager mAppOpsManager; 36 OverlayControl(@onNull Context context)37 OverlayControl(@NonNull Context context) { 38 mAppOpsManager = context.getSystemService(AppOpsManager.class); 39 } 40 hideOverlays()41 void hideOverlays() { 42 setOverlayAllowed(false); 43 } 44 showOverlays()45 void showOverlays() { 46 setOverlayAllowed(true); 47 } 48 setOverlayAllowed(boolean allowed)49 private void setOverlayAllowed(boolean allowed) { 50 if (mAppOpsManager != null) { 51 mAppOpsManager.setUserRestrictionForUser(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, !allowed, 52 mToken, null, UserHandle.USER_ALL); 53 mAppOpsManager.setUserRestrictionForUser(AppOpsManager.OP_TOAST_WINDOW, !allowed, 54 mToken, null, UserHandle.USER_ALL); 55 } 56 } 57 } 58