Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2018 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 package android.autofillservice.cts;
     17 
     18 import java.util.concurrent.CountDownLatch;
     19 import java.util.concurrent.TimeUnit;
     20 
     21 /**
     22  * Activity that allows capture recreated instance for testing multi window scenarios.
     23  */
     24 public class MultiWindowLoginActivity extends LoginActivity {
     25 
     26     private static MultiWindowLoginActivity sLastInstance;
     27     private static CountDownLatch sLastInstanceLatch;
     28 
     29     @Override
     30     protected void onStart() {
     31         super.onStart();
     32         sLastInstance = this;
     33         if (sLastInstanceLatch != null) {
     34             sLastInstanceLatch.countDown();
     35         }
     36     }
     37 
     38     @Override
     39     public void onWindowFocusChanged(boolean hasFocus) {
     40         if (hasFocus) {
     41             if (sLastInstanceLatch != null) {
     42                 sLastInstanceLatch.countDown();
     43             }
     44         }
     45     }
     46 
     47     public static void expectNewInstance(boolean waitWindowFocus) {
     48         sLastInstanceLatch = new CountDownLatch(waitWindowFocus ? 2 : 1);
     49     }
     50 
     51     public static MultiWindowLoginActivity waitNewInstance() throws InterruptedException {
     52         sLastInstanceLatch.await(Timeouts.ACTIVITY_RESURRECTION.getMaxValue(),
     53                 TimeUnit.MILLISECONDS);
     54         sLastInstanceLatch = null;
     55         return sLastInstance;
     56     }
     57 }
     58