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