| /* |
| * Copyright (C) 2017 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License |
| */ |
| |
| package com.android.systemui.statusbar.notification; |
| |
| import android.app.AppOpsManager; |
| import android.content.Context; |
| |
| import com.android.systemui.Dependency; |
| import com.android.systemui.ForegroundServiceController; |
| import com.android.systemui.statusbar.NotificationPresenter; |
| |
| /** |
| * This class handles listening to notification updates and passing them along to |
| * NotificationPresenter to be displayed to the user. |
| */ |
| public class AppOpsListener implements AppOpsManager.OnOpActiveChangedListener { |
| private static final String TAG = "NotificationListener"; |
| |
| // Dependencies: |
| private final ForegroundServiceController mFsc = |
| Dependency.get(ForegroundServiceController.class); |
| private final NotificationEntryManager mEntryManager = |
| Dependency.get(NotificationEntryManager.class); |
| |
| private final Context mContext; |
| protected NotificationPresenter mPresenter; |
| protected final AppOpsManager mAppOps; |
| |
| protected static final int[] OPS = new int[] {AppOpsManager.OP_CAMERA, |
| AppOpsManager.OP_SYSTEM_ALERT_WINDOW, |
| AppOpsManager.OP_RECORD_AUDIO}; |
| |
| public AppOpsListener(Context context) { |
| mContext = context; |
| mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); |
| } |
| |
| public void setUpWithPresenter(NotificationPresenter presenter) { |
| mPresenter = presenter; |
| mAppOps.startWatchingActive(OPS, this); |
| } |
| |
| public void destroy() { |
| mAppOps.stopWatchingActive(this); |
| } |
| |
| @Override |
| public void onOpActiveChanged(int code, int uid, String packageName, boolean active) { |
| mFsc.onAppOpChanged(code, uid, packageName, active); |
| Dependency.get(Dependency.MAIN_HANDLER).post(() -> { |
| mEntryManager.updateNotificationsForAppOp(code, uid, packageName, active); |
| }); |
| } |
| } |