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 com.android.cts.deviceandprofileowner; 18 19 import android.app.Activity; 20 import android.content.ComponentName; 21 import android.content.Intent; 22 import android.os.Bundle; 23 24 import java.util.concurrent.CountDownLatch; 25 import java.util.concurrent.TimeUnit; 26 27 /** 28 * Wrapper class used to call the activity in the non-test APK and wait for its result. 29 */ 30 public class ContentSuggestionsActivity extends Activity { 31 32 public static final String CONTENT_SUGGESTIONS_PACKAGE_NAME = 33 "com.android.cts.devicepolicy.contentsuggestionsapp"; 34 public static final String CONTENT_SUGGESTIONS_ACTIVITY_NAME = CONTENT_SUGGESTIONS_PACKAGE_NAME 35 + ".SimpleActivity"; 36 37 private final CountDownLatch mLatch = new CountDownLatch(1); 38 private boolean mEnabled; 39 40 @Override onCreate(Bundle savedInstanceState)41 protected void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 44 final Intent launchIntent = new Intent(); 45 launchIntent.setComponent(new ComponentName( 46 CONTENT_SUGGESTIONS_PACKAGE_NAME, CONTENT_SUGGESTIONS_ACTIVITY_NAME)); 47 startActivityForResult(launchIntent, 42); 48 } 49 50 @Override onActivityResult(int requestCode, int resultCode, Intent data)51 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 52 mEnabled = resultCode == 1; 53 mLatch.countDown(); 54 } 55 isContentSuggestionsEnabled()56 public boolean isContentSuggestionsEnabled() throws InterruptedException { 57 final boolean called = mLatch.await(2, TimeUnit.SECONDS); 58 if (!called) { 59 throw new IllegalStateException(CONTENT_SUGGESTIONS_PACKAGE_NAME 60 + " didn't finish in 2 seconds"); 61 } 62 finish(); 63 return mEnabled; 64 } 65 } 66