Home | History | Annotate | Download | only in wificond
      1 /*
      2  * Copyright (C) 2016 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.server.wifi.wificond;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 
     22 import java.util.BitSet;
     23 
     24 /**
     25  * ScanResult from wificond
     26  *
     27  * @hide
     28  */
     29 public class NativeScanResult implements Parcelable {
     30     private static final int CAPABILITY_SIZE = 16;
     31 
     32     public byte[] ssid;
     33     public byte[] bssid;
     34     public byte[] infoElement;
     35     public int frequency;
     36     public int signalMbm;
     37     public long tsf;
     38     public BitSet capability;
     39     public boolean associated;
     40 
     41     /** public constructor */
     42     public NativeScanResult() { }
     43 
     44     /** copy constructor */
     45     public NativeScanResult(NativeScanResult source) {
     46         ssid = source.ssid.clone();
     47         bssid = source.bssid.clone();
     48         infoElement = source.infoElement.clone();
     49         frequency = source.frequency;
     50         signalMbm = source.signalMbm;
     51         tsf = source.tsf;
     52         capability = (BitSet) source.capability.clone();
     53         associated = source.associated;
     54     }
     55 
     56     /** implement Parcelable interface */
     57     @Override
     58     public int describeContents() {
     59         return 0;
     60     }
     61 
     62     /** implement Parcelable interface */
     63     @Override
     64     public void writeToParcel(Parcel out, int flags) {
     65         out.writeByteArray(ssid);
     66         out.writeByteArray(bssid);
     67         out.writeByteArray(infoElement);
     68         out.writeInt(frequency);
     69         out.writeInt(signalMbm);
     70         out.writeLong(tsf);
     71         int capabilityInt = 0;
     72         for (int i = 0; i < CAPABILITY_SIZE; i++) {
     73             if (capability.get(i)) {
     74                 capabilityInt |= 1 << i;
     75             }
     76         }
     77         out.writeInt(capabilityInt);
     78         out.writeInt(associated ? 1 : 0);
     79     }
     80 
     81     /** implement Parcelable interface */
     82     public static final Parcelable.Creator<NativeScanResult> CREATOR =
     83             new Parcelable.Creator<NativeScanResult>() {
     84         @Override
     85         public NativeScanResult createFromParcel(Parcel in) {
     86             NativeScanResult result = new NativeScanResult();
     87             result.ssid = in.createByteArray();
     88             result.bssid = in.createByteArray();
     89             result.infoElement = in.createByteArray();
     90             result.frequency = in.readInt();
     91             result.signalMbm = in.readInt();
     92             result.tsf = in.readLong();
     93             int capabilityInt = in.readInt();
     94             result.capability = new BitSet(CAPABILITY_SIZE);
     95             for (int i = 0; i < CAPABILITY_SIZE; i++) {
     96                 if ((capabilityInt & (1 << i)) != 0) {
     97                     result.capability.set(i);
     98                 }
     99             }
    100             result.associated = (in.readInt() != 0);
    101             return result;
    102         }
    103 
    104         @Override
    105         public NativeScanResult[] newArray(int size) {
    106             return new NativeScanResult[size];
    107         }
    108     };
    109 }
    110