• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 com.android.car.settings.testutils;
18 
19 import android.app.ActivityManager;
20 import android.content.pm.IPackageDataObserver;
21 import android.os.UserHandle;
22 
23 import org.robolectric.annotation.Implementation;
24 import org.robolectric.annotation.Implements;
25 import org.robolectric.annotation.Resetter;
26 
27 @Implements(value = ActivityManager.class)
28 public class ShadowActivityManager extends org.robolectric.shadows.ShadowActivityManager {
29     private static final int DEFAULT_CURRENT_USER_ID = UserHandle.USER_SYSTEM;
30 
31     private static boolean sIsApplicationUserDataCleared;
32     private static int sCurrentUserId = DEFAULT_CURRENT_USER_ID;
33 
34     private String mMostRecentlyStoppedPackage;
35 
36     @Resetter
reset()37     public static void reset() {
38         sIsApplicationUserDataCleared = false;
39         sCurrentUserId = DEFAULT_CURRENT_USER_ID;
40     }
41 
42     @Implementation
forceStopPackage(String packageName)43     protected void forceStopPackage(String packageName) {
44         mMostRecentlyStoppedPackage = packageName;
45     }
46 
47     @Implementation
clearApplicationUserData(String packageName, IPackageDataObserver observer)48     protected boolean clearApplicationUserData(String packageName, IPackageDataObserver observer) {
49         return sIsApplicationUserDataCleared;
50     }
51 
getMostRecentlyStoppedPackage()52     public String getMostRecentlyStoppedPackage() {
53         return mMostRecentlyStoppedPackage;
54     }
55 
setApplicationUserDataCleared(boolean applicationUserDataCleared)56     public static void setApplicationUserDataCleared(boolean applicationUserDataCleared) {
57         sIsApplicationUserDataCleared = applicationUserDataCleared;
58     }
59 
60     @Implementation
getCurrentUser()61     protected static int getCurrentUser() {
62         return sCurrentUserId;
63     }
64 
setCurrentUser(int userId)65     public static void setCurrentUser(int userId) {
66         sCurrentUserId = userId;
67     }
68 }
69