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.car.CarAppFocusManager; 20 import android.car.IAppFocus; 21 import android.content.Context; 22 import android.os.Looper; 23 24 import com.android.car.AppFocusService; 25 26 /** 27 * Fake service that is used by {@link FakeCar} to provide an implementation of {@link IAppFocus} 28 * to allow the use of {@link CarAppFocusManager} in unit tests. 29 */ 30 public class FakeAppFocusService extends AppFocusService implements CarAppFocusController { 31 FakeSystemActivityMonitoringService mSystemActivityMonitoringService; 32 FakeAppFocusService( Context context, FakeSystemActivityMonitoringService fakeSystemActivityMonitoringService)33 private FakeAppFocusService( 34 Context context, 35 FakeSystemActivityMonitoringService fakeSystemActivityMonitoringService) { 36 super(context, fakeSystemActivityMonitoringService); 37 mSystemActivityMonitoringService = fakeSystemActivityMonitoringService; 38 } 39 FakeAppFocusService(Context context)40 public FakeAppFocusService(Context context) { 41 this(context, new FakeSystemActivityMonitoringService(context)); 42 super.init(); 43 } 44 45 //************************* CarAppFocusController implementation ******************************/ 46 47 @Override setForegroundUid(int uid)48 public synchronized void setForegroundUid(int uid) { 49 mSystemActivityMonitoringService.setForegroundUid(uid); 50 } 51 52 @Override setForegroundPid(int pid)53 public synchronized void setForegroundPid(int pid) { 54 mSystemActivityMonitoringService.setForegroundPid(pid); 55 } 56 57 @Override resetForegroundUid()58 public synchronized void resetForegroundUid() { 59 mSystemActivityMonitoringService.resetForegroundUid(); 60 } 61 62 @Override resetForegroundPid()63 public synchronized void resetForegroundPid() { 64 mSystemActivityMonitoringService.resetForegroundPid(); 65 } 66 67 @Override getLooper()68 public Looper getLooper() { 69 return super.getLooper(); 70 } 71 } 72