Home | History | Annotate | Download | only in cts
      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 android.net.wifi.aware.cts;
     18 
     19 import android.content.Context;
     20 import android.content.pm.PackageManager;
     21 
     22 import java.util.Arrays;
     23 
     24 /**
     25  * Test utilities for Wi-Fi Aware CTS test suite.
     26  */
     27 class TestUtils {
     28     static final String TAG = "WifiAwareCtsTests";
     29 
     30     /**
     31      * Returns a flag indicating whether or not Wi-Fi Aware should be tested. Wi-Fi Aware
     32      * should be tested if the feature is supported on the current device.
     33      */
     34     static boolean shouldTestWifiAware(Context context) {
     35         final PackageManager pm = context.getPackageManager();
     36         return pm.hasSystemFeature(PackageManager.FEATURE_WIFI_AWARE);
     37     }
     38 
     39     /**
     40      * Wraps a byte[] (MAC address representation). Intended to provide hash and equality operators
     41      * so that the MAC address can be used in containers.
     42      */
     43     static class MacWrapper {
     44         private byte[] mMac;
     45 
     46         MacWrapper(byte[] mac) {
     47             mMac = mac;
     48         }
     49 
     50         @Override
     51         public boolean equals(Object o) {
     52             if (this == o) {
     53                 return true;
     54             }
     55 
     56             if (!(o instanceof MacWrapper)) {
     57                 return false;
     58             }
     59 
     60             MacWrapper lhs = (MacWrapper) o;
     61             return Arrays.equals(mMac, lhs.mMac);
     62         }
     63 
     64         @Override
     65         public int hashCode() {
     66             return Arrays.hashCode(mMac);
     67         }
     68     }
     69 }
     70