TelephonyManager.requestNetworkScan - Android P Preview

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

TelephonyManager.requestNetworkScan - Android P Preview

Vitaliy Freidovich
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

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: TelephonyManager.requestNetworkScan - Android P Preview

Vitaliy Freidovich
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.

On Monday, July 16, 2018 at 5:50:30 PM UTC+3, [hidden email] wrote:
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

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/android-platform.
For more options, visit https://groups.google.com/d/optout.