• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.devicepolicy.cts.utils;
18 
19 import static android.app.admin.PolicyUpdateReceiver.ACTION_DEVICE_POLICY_SET_RESULT;
20 import static android.app.admin.PolicyUpdateReceiver.EXTRA_POLICY_BUNDLE_KEY;
21 import static android.app.admin.PolicyUpdateReceiver.EXTRA_POLICY_KEY;
22 import static android.app.admin.PolicyUpdateReceiver.EXTRA_POLICY_TARGET_USER_ID;
23 import static android.app.admin.PolicyUpdateReceiver.EXTRA_POLICY_UPDATE_RESULT_KEY;
24 
25 import static com.android.bedstead.enterprise.EnterpriseDeviceStateExtensionsKt.dpc;
26 
27 import static com.google.common.truth.Truth.assertThat;
28 
29 import android.content.Intent;
30 import android.os.Bundle;
31 
32 import com.android.bedstead.harrier.DeviceState;
33 
34 import java.time.Duration;
35 
36 public class PolicySetResultUtils {
37 
assertPolicySetResultReceived( DeviceState deviceState, String policyIdentifier, int resultKey, int targetUser, Bundle policyExtraBundle)38     public static void assertPolicySetResultReceived(
39             DeviceState deviceState, String policyIdentifier, int resultKey, int targetUser,
40             Bundle policyExtraBundle) {
41 
42         final Intent receivedIntent = dpc(deviceState).events().broadcastReceived()
43                 .whereIntent().action()
44                 .isEqualTo(ACTION_DEVICE_POLICY_SET_RESULT)
45                 .whereIntent().extras().key(EXTRA_POLICY_KEY).stringValue()
46                 .isEqualTo(policyIdentifier)
47                 .whereIntent().extras().key(EXTRA_POLICY_UPDATE_RESULT_KEY).integerValue()
48                 .isEqualTo(resultKey)
49                 .whereIntent().extras().key(EXTRA_POLICY_TARGET_USER_ID).integerValue()
50                 .isEqualTo(targetUser)
51                 .waitForEvent(Duration.ofMinutes(2)).intent();
52         assertThat(receivedIntent).isNotNull();
53 
54         // TODO: add checks on bundle values.
55         for (String key : policyExtraBundle.keySet()) {
56             assertThat(receivedIntent.getBundleExtra(EXTRA_POLICY_BUNDLE_KEY).containsKey(key))
57                     .isTrue();
58         }
59     }
60 }
61