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