TelephonyManager.requestNetworkScan - Android P Preview

483 views
Skip to first unread message

vit...@1-family.net

unread,
Jul 16, 2018, 10:50:30 AM7/16/18
to android-platform
Hello!

I'm developing a privileged system app to scan the network.
Trying to use the new API in Android P -  TelephonyManager.requestNetworkScan for this purpose.
For some reason I get error 2 'Wrong parameters' when I try using the API .
Granted the app MODIFY_PHONE_STATE permission, and still get the error.

First thought that it might be an LTE / 3G issue, but I get the same results both for UTRAN & EUTRAN.

I also ruled out SIM issue - the same error happens with 2 different SIMS, both successfully scanning the network form settings app for example.

Trying to run it on Pixel 2, AOSP P release 4 - beta 3 - build: PPP4.180612.004


Here's the relevant extract of the code:

private class RadioCallback extends TelephonyScanManager.NetworkScanCallback {
    private List<CellInfo> mCellInfoResults;
   
private int mScanError;

   
@Override
   
public void onResults(List<CellInfo> cellInfoResults) {
        mCellInfoResults
= cellInfoResults;
           
ScannerActivity.this.runOnUiThread(new Runnable() {
               
@Override
               
public void run() {
                   
for (CellInfo cellInfo:mCellInfoResults) {
                       resultsTextView
.append(" " + cellInfo.toString() + " ");
                   
}
               
}
           
});
   
}


   
@Override
   
public void onError(int error) {
        mScanError
= error;
       
ScannerActivity.this.runOnUiThread(new Runnable() {
           
@Override
           
public void run() {
                resultsTextView
.append(" Error: " + mScanError);
           
}
       
});
   
}

   
@Override
   
public void onComplete() {
       
ScannerActivity.this.runOnUiThread(new Runnable() {
           
@Override
           
public void run() {
                resultsTextView
.append(" Scan Completed! ");
           
}
       
});
   
}

}

public void onClick(View view) {

   
NetworkScanRequest networkScanRequest;
   
RadioAccessSpecifier radioAccessSpecifiers[];
   
int bands[];
   
ArrayList<String> PLMNIds = new ArrayList<String>(Arrays.asList("42501"));


   
TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext()
           
.getSystemService(Context.TELEPHONY_SERVICE);

    bands
[0] = AccessNetworkConstants.UtranBand.BAND_1;
    radioAccessSpecifiers
= new RadioAccessSpecifier[1];
    radioAccessSpecifiers
[0] = new RadioAccessSpecifier(
           
AccessNetworkConstants.AccessNetworkType.UTRAN,
            bands
,
           
null);

    networkScanRequest
= new NetworkScanRequest(
           
NetworkScanRequest.SCAN_TYPE_ONE_SHOT,
            radioAccessSpecifiers
,
           
0,
           
60,
           
false,
           
0,
           
PLMNIds);

    telephonyManager
.requestNetworkScan(networkScanRequest, AsyncTask.SERIAL_EXECUTOR,new RadioCallback());
}

In logcat's radio buffer I only see the message:
D/TelephonyScanManager( 3634): onError: 2

In main logcat buffer I see:

07-12 14:02:48.348 E/AndroidRuntime(10563): FATAL EXCEPTION: TelephonyScanManager
07-12 14:02:48.348 E/AndroidRuntime(10563): java.lang.RuntimeException: Failed to find NetworkScanInfo with id 10
07-12 14:02:48.348 E/AndroidRuntime(10563):     at android.telephony.TelephonyScanManager$1.handleMessage(TelephonyScanManager.java:117)
07-12 14:02:48.348 E/AndroidRuntime(10563):     at android.os.Handler.dispatchMessage(Handler.java:106)
07-12 14:02:48.348 E/AndroidRuntime(10563):     at android.os.Looper.loop(Looper.java:193)
07-12 14:02:48.348 E/AndroidRuntime(10563):     at android.os.HandlerThread.run(HandlerThread.java:65)

Would appreciate any input!
Vitaliy

vit...@1-family.net

unread,
Jul 17, 2018, 5:25:13 PM7/17/18
to android-platform
OK, figured it out - for anyone who may come across this issue -

searchPeriodicity & incrementalResultsPeriodicity cannot be 0, despite the documentation,
and irrelevance of these parameters for a one shot scan.
Reply all
Reply to author
Forward
0 new messages