summaryrefslogtreecommitdiff
path: root/com/android/systemui/statusbar/AppOpsListener.java
blob: 019c6807478b7eabdc90df81e972914e1df84694 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * 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;

import android.app.AppOpsManager;
import android.content.Context;

import com.android.systemui.Dependency;
import com.android.systemui.ForegroundServiceController;

/**
 * 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 Context mContext;
    protected NotificationPresenter mPresenter;
    protected NotificationEntryManager mEntryManager;
    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,
            NotificationEntryManager entryManager) {
        mPresenter = presenter;
        mEntryManager = entryManager;
        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);
        mPresenter.getHandler().post(() -> {
          mEntryManager.updateNotificationsForAppOp(code, uid, packageName, active);
        });
    }
}