Home | History | Annotate | Download | only in wifiaware
      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.app.AlertDialog;
     20 import android.content.Context;
     21 import android.content.DialogInterface;
     22 import android.content.Intent;
     23 import android.content.pm.PackageManager;
     24 import android.database.DataSetObserver;
     25 import android.net.wifi.aware.WifiAwareManager;
     26 import android.os.Bundle;
     27 import android.provider.Settings;
     28 import android.util.Log;
     29 import android.view.View;
     30 import android.widget.ListView;
     31 
     32 import com.android.cts.verifier.ArrayTestListAdapter;
     33 import com.android.cts.verifier.PassFailButtons;
     34 import com.android.cts.verifier.R;
     35 import com.android.cts.verifier.TestListAdapter;
     36 
     37 /**
     38  * Activity listing all Wi-Fi Aware tests.
     39  */
     40 public class TestListActivity extends PassFailButtons.TestListActivity {
     41     private static final String TAG = "TestListActivity";
     42 
     43     private WifiAwareManager mWifiAwareManager;
     44 
     45     @Override
     46     protected void onCreate(Bundle savedInstanceState) {
     47         super.onCreate(savedInstanceState);
     48 
     49         mWifiAwareManager = (WifiAwareManager) getSystemService(Context.WIFI_AWARE_SERVICE);
     50         if (mWifiAwareManager == null) {
     51             Log.wtf(TAG,
     52                     "Can't get WIFI_AWARE_SERVICE. Should be gated by 'test_required_features'!?");
     53             return;
     54         }
     55 
     56         boolean isRttSupported = getPackageManager().hasSystemFeature(
     57                 PackageManager.FEATURE_WIFI_RTT);
     58 
     59         setContentView(R.layout.pass_fail_list);
     60         setInfoResources(R.string.aware_test, R.string.aware_test_info, 0);
     61         setPassFailButtonClickListeners();
     62         getPassButton().setEnabled(false);
     63 
     64         // Add the sub-test/categories
     65         ArrayTestListAdapter adapter = new ArrayTestListAdapter(this);
     66 
     67         adapter.add(TestListAdapter.TestListItem.newCategory(this,
     68                 R.string.aware_dp_ib_open_unsolicited));
     69         adapter.add(TestListAdapter.TestListItem.newTest(this,
     70                 R.string.aware_publish,
     71                 DataPathOpenUnsolicitedPublishTestActivity.class.getName(),
     72                 new Intent(this, DataPathOpenUnsolicitedPublishTestActivity.class), null));
     73         adapter.add(TestListAdapter.TestListItem.newTest(this,
     74                 R.string.aware_subscribe,
     75                 DataPathOpenPassiveSubscribeTestActivity.class.getName(),
     76                 new Intent(this, DataPathOpenPassiveSubscribeTestActivity.class), null));
     77         adapter.add(TestListAdapter.TestListItem.newCategory(this,
     78                 R.string.aware_dp_ib_passphrase_unsolicited));
     79         adapter.add(TestListAdapter.TestListItem.newTest(this,
     80                 R.string.aware_publish,
     81                 DataPathPassphraseUnsolicitedPublishTestActivity.class.getName(),
     82                 new Intent(this, DataPathPassphraseUnsolicitedPublishTestActivity.class), null));
     83         adapter.add(TestListAdapter.TestListItem.newTest(this,
     84                 R.string.aware_subscribe,
     85                 DataPathPassphrasePassiveSubscribeTestActivity.class.getName(),
     86                 new Intent(this, DataPathPassphrasePassiveSubscribeTestActivity.class), null));
     87         adapter.add(TestListAdapter.TestListItem.newCategory(this,
     88                 R.string.aware_dp_ib_open_solicited));
     89         adapter.add(TestListAdapter.TestListItem.newTest(this,
     90                 R.string.aware_publish,
     91                 DataPathOpenSolicitedPublishTestActivity.class.getName(),
     92                 new Intent(this, DataPathOpenSolicitedPublishTestActivity.class), null));
     93         adapter.add(TestListAdapter.TestListItem.newTest(this,
     94                 R.string.aware_subscribe,
     95                 DataPathOpenActiveSubscribeTestActivity.class.getName(),
     96                 new Intent(this, DataPathOpenActiveSubscribeTestActivity.class), null));
     97         adapter.add(TestListAdapter.TestListItem.newCategory(this,
     98                 R.string.aware_dp_ib_passphrase_solicited));
     99         adapter.add(TestListAdapter.TestListItem.newTest(this,
    100                 R.string.aware_publish,
    101                 DataPathPassphraseSolicitedPublishTestActivity.class.getName(),
    102                 new Intent(this, DataPathPassphraseSolicitedPublishTestActivity.class), null));
    103         adapter.add(TestListAdapter.TestListItem.newTest(this,
    104                 R.string.aware_subscribe,
    105                 DataPathPassphraseActiveSubscribeTestActivity.class.getName(),
    106                 new Intent(this, DataPathPassphraseActiveSubscribeTestActivity.class), null));
    107         adapter.add(TestListAdapter.TestListItem.newCategory(this,
    108                 R.string.aware_dp_oob_open));
    109         adapter.add(TestListAdapter.TestListItem.newTest(this,
    110                 R.string.aware_responder,
    111                 DataPathOobOpenResponderTestActivity.class.getName(),
    112                 new Intent(this, DataPathOobOpenResponderTestActivity.class), null));
    113         adapter.add(TestListAdapter.TestListItem.newTest(this,
    114                 R.string.aware_initiator,
    115                 DataPathOobOpenInitiatorTestActivity.class.getName(),
    116                 new Intent(this, DataPathOobOpenInitiatorTestActivity.class), null));
    117         adapter.add(TestListAdapter.TestListItem.newCategory(this,
    118                 R.string.aware_dp_oob_passphrase));
    119         adapter.add(TestListAdapter.TestListItem.newTest(this,
    120                 R.string.aware_responder,
    121                 DataPathOobPassphraseResponderTestActivity.class.getName(),
    122                 new Intent(this, DataPathOobPassphraseResponderTestActivity.class), null));
    123         adapter.add(TestListAdapter.TestListItem.newTest(this,
    124                 R.string.aware_initiator,
    125                 DataPathOobPassphraseInitiatorTestActivity.class.getName(),
    126                 new Intent(this, DataPathOobPassphraseInitiatorTestActivity.class), null));
    127         if (isRttSupported) {
    128             adapter.add(TestListAdapter.TestListItem.newCategory(this,
    129                     R.string.aware_discovery_ranging));
    130             adapter.add(TestListAdapter.TestListItem.newTest(this,
    131                     R.string.aware_publish,
    132                     DiscoveryRangingPublishTestActivity.class.getName(),
    133                     new Intent(this, DiscoveryRangingPublishTestActivity.class), null));
    134             adapter.add(TestListAdapter.TestListItem.newTest(this,
    135                     R.string.aware_subscribe,
    136                     DiscoveryRangingSubscribeTestActivity.class.getName(),
    137                     new Intent(this, DiscoveryRangingSubscribeTestActivity.class), null));
    138         }
    139 
    140         adapter.registerDataSetObserver(new DataSetObserver() {
    141             @Override
    142             public void onChanged() {
    143                 updatePassButton();
    144             }
    145 
    146             @Override
    147             public void onInvalidated() {
    148                 updatePassButton();
    149             }
    150         });
    151 
    152         setTestListAdapter(adapter);
    153     }
    154 
    155     @Override
    156     protected void handleItemClick(ListView listView, View view, int position, long id) {
    157         if (!mWifiAwareManager.isAvailable()) {
    158             showAwareEnableDialog();
    159             return;
    160         }
    161 
    162         super.handleItemClick(listView, view, position, id);
    163     }
    164 
    165     /**
    166      * Show the dialog to jump to system settings in order to enable
    167      * WiFi (and by extension WiFi Aware).
    168      */
    169     private void showAwareEnableDialog() {
    170         AlertDialog.Builder builder = new AlertDialog.Builder(this);
    171         builder.setIcon(android.R.drawable.ic_dialog_alert);
    172         builder.setTitle(R.string.aware_not_enabled);
    173         builder.setMessage(R.string.aware_not_enabled_message);
    174         builder.setPositiveButton(R.string.aware_settings,
    175                 new DialogInterface.OnClickListener() {
    176                     @Override
    177                     public void onClick(DialogInterface dialog, int which) {
    178                         startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
    179                     }
    180                 });
    181         builder.create().show();
    182     }
    183 }
    184