Merge "Add log for manual network select settings" into qt-dev

This commit is contained in:
Pengquan Meng
2019-05-06 18:15:02 +00:00
committed by Android (Google) Code Review
3 changed files with 33 additions and 11 deletions

View File

@@ -34,6 +34,7 @@ import android.util.Log;
import com.android.internal.telephony.OperatorInfo;
import java.util.List;
import java.util.stream.Collectors;
/**
* Add static Utility functions to get information from the CellInfo object.
@@ -161,4 +162,21 @@ public final class CellInfoUtil {
String plmn = CellInfoUtil.getOperatorInfoFromCellInfo(cellInfo).getOperatorNumeric();
return forbiddenPlmns != null && forbiddenPlmns.contains(plmn);
}
/** Convert a list of cellInfos to readable string without sensitive info. */
public static String cellInfoListToString(List<CellInfo> cellInfos) {
return cellInfos.stream()
.map(cellInfo -> cellInfoToString(cellInfo))
.collect(Collectors.joining(", "));
}
/** Convert {@code cellInfo} to a readable string without sensitive info. */
public static String cellInfoToString(CellInfo cellInfo) {
String cellType = cellInfo.getClass().getSimpleName();
CellIdentity cid = cellInfo.getCellIdentity();
return String.format(
"{CellType = %s, isRegistered = %b, mcc = %s, mnc = %s, alphaL = %s, alphaS = %s}",
cellType, cellInfo.isRegistered(), cid.getMccString(), cid.getMncString(),
cid.getOperatorAlphaLong(), cid.getOperatorAlphaShort());
}
}

View File

@@ -45,7 +45,6 @@ import java.util.stream.Collectors;
*/
public class NetworkScanHelper {
public static final String TAG = "NetworkScanHelper";
private static final boolean DBG = false;
/**
* Callbacks interface to inform the network scan results.
@@ -184,7 +183,6 @@ public class NetworkScanHelper {
mExecutor.execute(new NetworkScanSyncTask(
mTelephonyManager, (SettableFuture) mNetworkScanFuture));
} else if (type == NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS) {
if (DBG) Log.d(TAG, "start network scan async");
mNetworkScanRequester = mTelephonyManager.requestNetworkScan(
NETWORK_SCAN_REQUEST,
mExecutor,
@@ -240,17 +238,18 @@ public class NetworkScanHelper {
private final class NetworkScanCallbackImpl extends TelephonyScanManager.NetworkScanCallback {
public void onResults(List<CellInfo> results) {
if (DBG) Log.d(TAG, "async scan onResults() results = " + results);
Log.d(TAG, "Async scan onResults() results = "
+ CellInfoUtil.cellInfoListToString(results));
NetworkScanHelper.this.onResults(results);
}
public void onComplete() {
if (DBG) Log.d(TAG, "async scan onComplete()");
Log.d(TAG, "async scan onComplete()");
NetworkScanHelper.this.onComplete();
}
public void onError(@NetworkScan.ScanErrorCode int errCode) {
if (DBG) Log.d(TAG, "async scan onError() errorCode = " + errCode);
Log.d(TAG, "async scan onError() errorCode = " + errCode);
NetworkScanHelper.this.onError(errCode);
}
}
@@ -267,19 +266,21 @@ public class NetworkScanHelper {
@Override
public void run() {
if (DBG) Log.d(TAG, "sync scan start");
CellNetworkScanResult result = mTelephonyManager.getAvailableNetworks();
final CellNetworkScanResult result = mTelephonyManager.getAvailableNetworks();
if (result.getStatus() == CellNetworkScanResult.STATUS_SUCCESS) {
List<CellInfo> cellInfos = result.getOperators()
final List<CellInfo> cellInfos = result.getOperators()
.stream()
.map(operatorInfo
-> CellInfoUtil.convertOperatorInfoToCellInfo(operatorInfo))
.collect(Collectors.toList());
if (DBG) Log.d(TAG, "sync scan complete");
Log.d(TAG, "Sync network scan completed, cellInfos = "
+ CellInfoUtil.cellInfoListToString(cellInfos));
mCallback.set(cellInfos);
} else {
mCallback.setException(new Throwable(
Integer.toString(convertToScanErrorCode(result.getStatus()))));
final Throwable error = new Throwable(
Integer.toString(convertToScanErrorCode(result.getStatus())));
mCallback.setException(error);
Log.d(TAG, "Sync network scan error, ex = " + error);
}
}
}

View File

@@ -31,6 +31,7 @@ import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import androidx.annotation.VisibleForTesting;
@@ -230,6 +231,8 @@ public class NetworkSelectSettings extends DashboardFragment {
break;
case EVENT_NETWORK_SCAN_RESULTS:
List<CellInfo> results = aggregateCellInfoList((List<CellInfo>) msg.obj);
Log.d(TAG, "CellInfoList after aggregation: "
+ CellInfoUtil.cellInfoListToString(results));
mCellInfoList = new ArrayList<>(results);
if (mCellInfoList != null && mCellInfoList.size() != 0) {
updateAllPreferenceCategory();