• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 android.car.testapi;
18 
19 import android.content.Context;
20 
21 import com.android.car.SystemActivityMonitoringService;
22 
23 /**
24  * This is fake implementation of the SystemActivityMonitoringService which is used by the
25  * {@link com.android.car.AppFocusService}. A faked version is needed for offline unit tests so that
26  * the foreground app ID can be changed manually.
27  *
28  * @hide
29  */
30 public class FakeSystemActivityMonitoringService extends SystemActivityMonitoringService {
31     private static final int DEFAULT_FOREGROUND_ID = -1;
32 
33     private int mForegroundPid = DEFAULT_FOREGROUND_ID;
34     private int mForegroundUid = DEFAULT_FOREGROUND_ID;
35 
FakeSystemActivityMonitoringService(Context context)36     FakeSystemActivityMonitoringService(Context context) {
37          super(context);
38     }
39 
40     @Override
isInForeground(int pid, int uid)41     public boolean isInForeground(int pid, int uid) {
42         return (mForegroundPid == DEFAULT_FOREGROUND_ID || mForegroundPid == pid)
43                 && (mForegroundUid == DEFAULT_FOREGROUND_ID || mForegroundUid == uid);
44     }
45 
setForegroundPid(int pid)46     void setForegroundPid(int pid) {
47         mForegroundPid = pid;
48     }
49 
setForegroundUid(int uid)50     void setForegroundUid(int uid) {
51         mForegroundUid = uid;
52     }
53 
resetForegroundPid()54     void resetForegroundPid() {
55         mForegroundPid = DEFAULT_FOREGROUND_ID;
56     }
57 
resetForegroundUid()58     void resetForegroundUid() {
59         mForegroundUid = DEFAULT_FOREGROUND_ID;
60     }
61 }
62