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.systemui.statusbar; 18 19 import android.app.AppOpsManager; 20 import android.content.Context; 21 22 import com.android.systemui.Dependency; 23 import com.android.systemui.ForegroundServiceController; 24 25 /** 26 * This class handles listening to notification updates and passing them along to 27 * NotificationPresenter to be displayed to the user. 28 */ 29 public class AppOpsListener implements AppOpsManager.OnOpActiveChangedListener { 30 private static final String TAG = "NotificationListener"; 31 32 // Dependencies: 33 private final ForegroundServiceController mFsc = 34 Dependency.get(ForegroundServiceController.class); 35 36 private final Context mContext; 37 protected NotificationPresenter mPresenter; 38 protected NotificationEntryManager mEntryManager; 39 protected final AppOpsManager mAppOps; 40 41 protected static final int[] OPS = new int[] {AppOpsManager.OP_CAMERA, 42 AppOpsManager.OP_SYSTEM_ALERT_WINDOW, 43 AppOpsManager.OP_RECORD_AUDIO}; 44 45 public AppOpsListener(Context context) { 46 mContext = context; 47 mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); 48 } 49 50 public void setUpWithPresenter(NotificationPresenter presenter, 51 NotificationEntryManager entryManager) { 52 mPresenter = presenter; 53 mEntryManager = entryManager; 54 mAppOps.startWatchingActive(OPS, this); 55 } 56 57 public void destroy() { 58 mAppOps.stopWatchingActive(this); 59 } 60 61 @Override 62 public void onOpActiveChanged(int code, int uid, String packageName, boolean active) { 63 mFsc.onAppOpChanged(code, uid, packageName, active); 64 mPresenter.getHandler().post(() -> { 65 mEntryManager.updateNotificationsForAppOp(code, uid, packageName, active); 66 }); 67 } 68 } 69