From 84c9e01f10bd5987bd9a401db9e0d46400f88540 Mon Sep 17 00:00:00 2001 From: yinxu Date: Thu, 20 Apr 2017 15:33:57 -0700 Subject: Add the new RIL requests and NetworkScanResult. Those new RIL requests will be used to start and stop network scan, and the scan result will be returned from RIL in the format of NetworkScanResult. Test: Telephony sanity tests Bug: 30954762 Change-Id: I2bfd0fb8cbb3815cc62ec4385594dec9c5e4d279 (cherry picked from commit b36a4cb40222e1c0a61b13c1eca601ba761bd26e) --- .../internal/telephony/NetworkScanResult.java | 129 +++++++++++++++++++++ .../android/internal/telephony/RILConstants.java | 3 + 2 files changed, 132 insertions(+) create mode 100644 telephony/java/com/android/internal/telephony/NetworkScanResult.java diff --git a/telephony/java/com/android/internal/telephony/NetworkScanResult.java b/telephony/java/com/android/internal/telephony/NetworkScanResult.java new file mode 100644 index 000000000000..0099961190e1 --- /dev/null +++ b/telephony/java/com/android/internal/telephony/NetworkScanResult.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.internal.telephony; + +import android.os.Parcel; +import android.os.Parcelable; +import android.telephony.CellInfo; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; + +/** + * Defines the incremental network scan result. + * + * This class contains the network scan results. When the user starts a new scan, multiple + * NetworkScanResult may be returned, containing either the scan result or error. When the user + * stops an ongoing scan, only one NetworkScanResult will be returned to indicate either the scan + * is now complete or there is some error stopping it. + * @hide + */ +public final class NetworkScanResult implements Parcelable { + + // Contains only part of the scan result and more are coming. + public static final int SCAN_STATUS_PARTIAL = 0; + + // Contains the last part of the scan result and the scan is now complete. + public static final int SCAN_STATUS_COMPLETE = 1; + + // The status of the scan, only valid when scanError = SUCCESS. + public int scanStatus; + + /** + * The error code of the scan + * + * This is the error code returned from the RIL, see {@link RILConstants} for more details + */ + public int scanError; + + // The scan results, only valid when scanError = SUCCESS. + public List networkInfos; + + /** + * Creates a new NetworkScanResult with scanStatus, scanError and networkInfos + * + * @param scanStatus The status of the scan. + * @param scanError The error code of the scan. + * @param networkInfos List of the CellInfo. + */ + public NetworkScanResult(int scanStatus, int scanError, List networkInfos) { + this.scanStatus = scanStatus; + this.scanError = scanError; + this.networkInfos = networkInfos; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(scanStatus); + dest.writeInt(scanError); + CellInfo[] ci = networkInfos.toArray(new CellInfo[networkInfos.size()]); + dest.writeParcelableArray(ci, flags); + } + + private NetworkScanResult(Parcel in) { + scanStatus = in.readInt(); + scanError = in.readInt(); + CellInfo[] ci = (CellInfo[]) in.readParcelableArray( + Object.class.getClassLoader(), + CellInfo.class); + networkInfos = Arrays.asList(ci); + } + + @Override + public boolean equals (Object o) { + NetworkScanResult nsr; + + try { + nsr = (NetworkScanResult) o; + } catch (ClassCastException ex) { + return false; + } + + if (o == null) { + return false; + } + + return (scanStatus == nsr.scanStatus + && scanError == nsr.scanError + && networkInfos.equals(nsr.networkInfos)); + } + + @Override + public int hashCode () { + return ((scanStatus * 31) + + (scanError * 23) + + (networkInfos.hashCode() * 37)); + } + + public static final Creator CREATOR = + new Creator() { + @Override + public NetworkScanResult createFromParcel(Parcel in) { + return new NetworkScanResult(in); + } + + @Override + public NetworkScanResult[] newArray(int size) { + return new NetworkScanResult[size]; + } + }; +} diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java index e50901f7eadc..e2d25b8e352c 100644 --- a/telephony/java/com/android/internal/telephony/RILConstants.java +++ b/telephony/java/com/android/internal/telephony/RILConstants.java @@ -415,6 +415,8 @@ cat include/telephony/ril.h | \ int RIL_REQUEST_SET_UNSOLICITED_RESPONSE_FILTER = 139; int RIL_REQUEST_SET_SIM_CARD_POWER = 140; int RIL_REQUEST_SET_CARRIER_INFO_IMSI_ENCRYPTION = 141; + int RIL_REQUEST_START_NETWORK_SCAN = 142; + int RIL_REQUEST_STOP_NETWORK_SCAN = 143; int RIL_RESPONSE_ACKNOWLEDGEMENT = 800; @@ -468,4 +470,5 @@ cat include/telephony/ril.h | \ int RIL_UNSOL_PCO_DATA = 1046; int RIL_UNSOL_MODEM_RESTART = 1047; int RIL_UNSOL_CARRIER_INFO_IMSI_ENCRYPTION = 1048; + int RIL_UNSOL_NETWORK_SCAN_RESULT = 1049; } -- cgit v1.2.3-59-g8ed1b