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