1 /*
2  * Copyright (C) 2023 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.app.sdksandbox.testutils;
18 
19 import android.content.Intent;
20 import android.content.IntentFilter;
21 import android.content.pm.ApplicationInfo;
22 import android.content.pm.PackageManager.NameNotFoundException;
23 import android.content.pm.ProviderInfo;
24 import android.os.IBinder;
25 
26 import androidx.annotation.NonNull;
27 
28 import com.android.server.sdksandbox.SdkSandboxManagerLocal;
29 
30 public class FakeSdkSandboxManagerLocal implements SdkSandboxManagerLocal {
31 
32     private boolean mInstrumentationRunning = false;
33 
34     @Override
enforceAllowedToSendBroadcast(@onNull Intent intent)35     public void enforceAllowedToSendBroadcast(@NonNull Intent intent) {}
36 
37     @Override
canSendBroadcast(@onNull Intent intent)38     public boolean canSendBroadcast(@NonNull Intent intent) {
39         return false;
40     }
41 
42     @Override
enforceAllowedToStartActivity(@onNull Intent intent)43     public void enforceAllowedToStartActivity(@NonNull Intent intent) {}
44 
45     @Override
enforceAllowedToStartOrBindService(@onNull Intent intent)46     public void enforceAllowedToStartOrBindService(@NonNull Intent intent) {}
47 
48     @NonNull
49     @Override
getSdkSandboxProcessNameForInstrumentation( @onNull ApplicationInfo clientAppInfo)50     public String getSdkSandboxProcessNameForInstrumentation(
51             @NonNull ApplicationInfo clientAppInfo) {
52         return clientAppInfo.processName + "_sdk_sandbox_instr";
53     }
54 
55     @NonNull
56     @Override
getSdkSandboxApplicationInfoForInstrumentation( @onNull ApplicationInfo clientAppInfo, boolean isSdkInSandbox)57     public ApplicationInfo getSdkSandboxApplicationInfoForInstrumentation(
58             @NonNull ApplicationInfo clientAppInfo, boolean isSdkInSandbox) {
59         clientAppInfo.processName = getSdkSandboxProcessNameForInstrumentation(clientAppInfo);
60         return clientAppInfo;
61     }
62 
63     @Override
notifyInstrumentationStarted( @onNull String clientAppPackageName, int clientAppUid)64     public void notifyInstrumentationStarted(
65             @NonNull String clientAppPackageName, int clientAppUid) {
66         mInstrumentationRunning = true;
67     }
68 
69     @Override
notifyInstrumentationFinished( @onNull String clientAppPackageName, int clientAppUid)70     public void notifyInstrumentationFinished(
71             @NonNull String clientAppPackageName, int clientAppUid) {
72         mInstrumentationRunning = false;
73     }
74 
75     @Override
isInstrumentationRunning( @onNull String clientAppPackageName, int clientAppUid)76     public boolean isInstrumentationRunning(
77             @NonNull String clientAppPackageName, int clientAppUid) {
78         return mInstrumentationRunning;
79     }
80 
81     @Override
registerAdServicesManagerService(IBinder iBinder, boolean published)82     public void registerAdServicesManagerService(IBinder iBinder, boolean published) {}
83 
84     @Override
canRegisterBroadcastReceiver( @onNull IntentFilter intentFilter, int flags, boolean onlyProtectedBroadcasts)85     public boolean canRegisterBroadcastReceiver(
86             @NonNull IntentFilter intentFilter, int flags, boolean onlyProtectedBroadcasts) {
87         return true;
88     }
89 
90     @Override
canAccessContentProviderFromSdkSandbox(@onNull ProviderInfo providerInfo)91     public boolean canAccessContentProviderFromSdkSandbox(@NonNull ProviderInfo providerInfo) {
92         return true;
93     }
94 
95     @Override
enforceAllowedToHostSandboxedActivity( @onNull Intent intent, int clientAppUid, @NonNull String clientAppPackageName)96     public void enforceAllowedToHostSandboxedActivity(
97             @NonNull Intent intent, int clientAppUid, @NonNull String clientAppPackageName) {}
98 
99     @Override
getEffectiveTargetSdkVersion(int sdkSandboxUid)100     public int getEffectiveTargetSdkVersion(int sdkSandboxUid) throws NameNotFoundException {
101         return 0;
102     }
103 }
104