1 /* 2 * Copyright (C) 2017 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.verifier.wifiaware; 18 19 import android.content.Context; 20 import android.os.Bundle; 21 import android.os.Handler; 22 import android.view.View; 23 import android.view.WindowManager; 24 import android.widget.ProgressBar; 25 import android.widget.TextView; 26 27 import com.android.cts.verifier.PassFailButtons; 28 import com.android.cts.verifier.R; 29 30 /** 31 * Base class for Aware tests. 32 */ 33 public abstract class BaseTestActivity extends PassFailButtons.Activity implements 34 BaseTestCase.Listener { 35 /* 36 * Handles to GUI elements. 37 */ 38 private TextView mAwareInfo; 39 private ProgressBar mAwareProgress; 40 41 /* 42 * Test case to be executed 43 */ 44 private BaseTestCase mTestCase; 45 46 private Handler mHandler = new Handler(); 47 getTestCase(Context context)48 protected abstract BaseTestCase getTestCase(Context context); 49 50 @Override onCreate(Bundle savedInstanceState)51 protected void onCreate(Bundle savedInstanceState) { 52 super.onCreate(savedInstanceState); 53 setContentView(R.layout.aware_main); 54 setPassFailButtonClickListeners(); 55 getPassButton().setEnabled(false); 56 57 // Get UI component. 58 mAwareInfo = (TextView) findViewById(R.id.aware_info); 59 mAwareProgress = (ProgressBar) findViewById(R.id.aware_progress); 60 61 // Initialize test components. 62 mTestCase = getTestCase(this); 63 64 // keep screen on while this activity is front view. 65 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 66 } 67 68 @Override onResume()69 protected void onResume() { 70 super.onResume(); 71 mTestCase.start(this); 72 mAwareProgress.setVisibility(View.VISIBLE); 73 } 74 75 @Override onPause()76 protected void onPause() { 77 super.onPause(); 78 mTestCase.stop(); 79 mAwareProgress.setVisibility(View.GONE); 80 } 81 82 83 @Override onTestStarted()84 public void onTestStarted() { 85 // nop 86 } 87 88 @Override onTestMsgReceived(String msg)89 public void onTestMsgReceived(String msg) { 90 if (msg == null) { 91 return; 92 } 93 mHandler.post(new Runnable() { 94 @Override 95 public void run() { 96 mAwareInfo.append(msg); 97 mAwareInfo.append("\n"); 98 } 99 }); 100 } 101 102 @Override onTestSuccess()103 public void onTestSuccess() { 104 mHandler.post(new Runnable() { 105 @Override 106 public void run() { 107 getPassButton().setEnabled(true); 108 mAwareProgress.setVisibility(View.GONE); 109 } 110 }); 111 } 112 113 @Override onTestFailed(String reason)114 public void onTestFailed(String reason) { 115 mHandler.post(new Runnable() { 116 @Override 117 public void run() { 118 if (reason != null) { 119 mAwareInfo.append(reason); 120 } 121 mAwareProgress.setVisibility(View.GONE); 122 } 123 }); 124 } 125 } 126