1 /* 2 * Copyright (C) 2018 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.settings; 18 19 import android.app.Activity; 20 import android.app.AppOpsManager; 21 import android.content.DialogInterface; 22 import android.content.Intent; 23 import android.os.Bundle; 24 25 public class ActionDisabledByAppOpsDialog extends Activity 26 implements DialogInterface.OnDismissListener { 27 28 private static final String TAG = "ActionDisabledByAppOpsDialog"; 29 30 private ActionDisabledByAppOpsHelper mDialogHelper; 31 32 @Override onCreate(Bundle savedInstanceState)33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 mDialogHelper = new ActionDisabledByAppOpsHelper(this); 36 mDialogHelper.prepareDialogBuilder() 37 .setOnDismissListener(this) 38 .show(); 39 updateAppOps(); 40 } 41 updateAppOps()42 private void updateAppOps() { 43 final Intent intent = getIntent(); 44 final String packageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME); 45 final int uid = intent.getIntExtra(Intent.EXTRA_UID, android.os.Process.INVALID_UID); 46 getSystemService(AppOpsManager.class) 47 .setMode(AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS, 48 uid, 49 packageName, 50 AppOpsManager.MODE_IGNORED); 51 } 52 53 @Override onNewIntent(Intent intent)54 public void onNewIntent(Intent intent) { 55 super.onNewIntent(intent); 56 mDialogHelper.updateDialog(); 57 updateAppOps(); 58 } 59 60 @Override onDismiss(DialogInterface dialog)61 public void onDismiss(DialogInterface dialog) { 62 finish(); 63 } 64 } 65