• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.server.pm;
18 
19 import android.annotation.Nullable;
20 
21 import java.io.PrintWriter;
22 
23 /**
24  * Overrides the unlocked methods in {@link AppsFilterBase} and guards them with locks.
25  * These are used by {@link AppsFilterImpl} which contains modifications to the class members
26  */
27 abstract class AppsFilterLocked extends AppsFilterBase {
28     /**
29      * The following locks guard the accesses for the list/set class members
30      */
31     protected final Object mForceQueryableLock = new Object();
32     protected final Object mQueriesViaPackageLock = new Object();
33     protected final Object mQueriesViaComponentLock = new Object();
34     /**
35      * This lock covers both {@link #mImplicitlyQueryable} and {@link #mRetainedImplicitlyQueryable}
36       */
37     protected final Object mImplicitlyQueryableLock = new Object();
38     protected final Object mQueryableViaUsesLibraryLock = new Object();
39     protected final Object mProtectedBroadcastsLock = new Object();
40 
41     /**
42      * Guards the access for {@link AppsFilterBase#mShouldFilterCache};
43      */
44     protected final Object mCacheLock = new Object();
45 
46     @Override
isForceQueryable(int appId)47     protected boolean isForceQueryable(int appId) {
48         synchronized (mForceQueryableLock) {
49             return super.isForceQueryable(appId);
50         }
51     }
52 
53     @Override
isQueryableViaPackage(int callingAppId, int targetAppId)54     protected boolean isQueryableViaPackage(int callingAppId, int targetAppId) {
55         synchronized (mQueriesViaPackageLock) {
56             return super.isQueryableViaPackage(callingAppId, targetAppId);
57         }
58     }
59 
60     @Override
isQueryableViaComponent(int callingAppId, int targetAppId)61     protected boolean isQueryableViaComponent(int callingAppId, int targetAppId) {
62         synchronized (mQueriesViaComponentLock) {
63             return super.isQueryableViaComponent(callingAppId, targetAppId);
64         }
65     }
66 
67     @Override
isImplicitlyQueryable(int callingUid, int targetUid)68     protected boolean isImplicitlyQueryable(int callingUid, int targetUid) {
69         synchronized (mImplicitlyQueryableLock) {
70             return super.isImplicitlyQueryable(callingUid, targetUid);
71         }
72     }
73 
74     @Override
isRetainedImplicitlyQueryable(int callingUid, int targetUid)75     protected boolean isRetainedImplicitlyQueryable(int callingUid, int targetUid) {
76         synchronized (mImplicitlyQueryableLock) {
77             return super.isRetainedImplicitlyQueryable(callingUid, targetUid);
78         }
79     }
80 
81     @Override
isQueryableViaUsesLibrary(int callingAppId, int targetAppId)82     protected boolean isQueryableViaUsesLibrary(int callingAppId, int targetAppId) {
83         synchronized (mQueryableViaUsesLibraryLock) {
84             return super.isQueryableViaUsesLibrary(callingAppId, targetAppId);
85         }
86     }
87 
88     @Override
shouldFilterApplicationUsingCache(int callingUid, int appId, int userId)89     protected boolean shouldFilterApplicationUsingCache(int callingUid, int appId, int userId) {
90         synchronized (mCacheLock) {
91             return super.shouldFilterApplicationUsingCache(callingUid, appId, userId);
92         }
93     }
94 
95     @Override
dumpForceQueryable(PrintWriter pw, @Nullable Integer filteringAppId, ToString<Integer> expandPackages)96     protected void dumpForceQueryable(PrintWriter pw, @Nullable Integer filteringAppId,
97             ToString<Integer> expandPackages) {
98         synchronized (mForceQueryableLock) {
99             super.dumpForceQueryable(pw, filteringAppId, expandPackages);
100         }
101     }
102 
103     @Override
dumpQueriesViaPackage(PrintWriter pw, @Nullable Integer filteringAppId, ToString<Integer> expandPackages)104     protected void dumpQueriesViaPackage(PrintWriter pw, @Nullable Integer filteringAppId,
105             ToString<Integer> expandPackages) {
106         synchronized (mQueriesViaPackageLock) {
107             super.dumpQueriesViaPackage(pw, filteringAppId, expandPackages);
108         }
109     }
110 
111     @Override
dumpQueriesViaComponent(PrintWriter pw, @Nullable Integer filteringAppId, ToString<Integer> expandPackages)112     protected void dumpQueriesViaComponent(PrintWriter pw, @Nullable Integer filteringAppId,
113             ToString<Integer> expandPackages) {
114         synchronized (mQueriesViaComponentLock) {
115             super.dumpQueriesViaComponent(pw, filteringAppId, expandPackages);
116         }
117     }
118 
119     @Override
dumpQueriesViaImplicitlyQueryable(PrintWriter pw, @Nullable Integer filteringAppId, int[] users, ToString<Integer> expandPackages)120     protected void dumpQueriesViaImplicitlyQueryable(PrintWriter pw,
121             @Nullable Integer filteringAppId, int[] users, ToString<Integer> expandPackages) {
122         synchronized (mImplicitlyQueryableLock) {
123             super.dumpQueriesViaImplicitlyQueryable(pw, filteringAppId, users, expandPackages);
124         }
125     }
126 
127     @Override
dumpQueriesViaUsesLibrary(PrintWriter pw, @Nullable Integer filteringAppId, ToString<Integer> expandPackages)128     protected void dumpQueriesViaUsesLibrary(PrintWriter pw, @Nullable Integer filteringAppId,
129             ToString<Integer> expandPackages) {
130         synchronized (mQueryableViaUsesLibraryLock) {
131             super.dumpQueriesViaUsesLibrary(pw, filteringAppId, expandPackages);
132         }
133     }
134 }
135