Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2015 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 package com.android.packageinstaller.permission.ui;
     17 
     18 import android.app.Activity;
     19 import android.app.AppOpsManager;
     20 import android.os.Binder;
     21 import android.os.IBinder;
     22 
     23 public class OverlayTouchActivity extends Activity {
     24     private final IBinder mToken = new Binder();
     25 
     26     @Override
     27     protected void onResume() {
     28         super.onResume();
     29         setOverlayAllowed(false);
     30     }
     31 
     32     @Override
     33     protected void onPause() {
     34         super.onPause();
     35         setOverlayAllowed(true);
     36     }
     37 
     38     private void setOverlayAllowed(boolean allowed) {
     39         AppOpsManager appOpsManager = getSystemService(AppOpsManager.class);
     40         if (appOpsManager != null) {
     41             appOpsManager.setUserRestriction(AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
     42                     !allowed, mToken);
     43             appOpsManager.setUserRestriction(AppOpsManager.OP_TOAST_WINDOW,
     44                     !allowed, mToken);
     45         }
     46     }
     47 }
     48