2

I need to be able to read current APN name. My app is a system app (it's located under /system/app) and I have root access.

I'm trying to get APN name but it's being impossible because I'm always prompted with:

No permission to write APN settings

I also have added the following permissions in Android Manifest

<uses-permission android:name="android.permission.WRITE_APN_SETTINGS"/>

TARGET SDK > 18 (Lollipop)

Thanks a lot.

Aldridge1991
  • 1,326
  • 6
  • 24
  • 51

2 Answers2

2

Android 5.1 introduced Carrier Privileges (https://source.android.com/devices/tech/config/uicc).

To be possible to change the APN you have to sign your app with the same signature of the SIM card. If you do this, then it is possible to change the APN. You do not need the

<uses-permission android:name="android.permission.WRITE_APN_SETTINGS"/>

in Android Manifest.

You can sign your app with Android Studio for example (https://developer.android.com/studio/publish/app-signing.html)

pringi
  • 3,987
  • 5
  • 35
  • 45
  • How do I get the signature of the SIM card? Would the carrier have it? Can you point me to more information on SIM signature? I want to find out what else I can do if I get access to SIM signature.. thanks – Ram Ramesh Feb 12 '18 at 23:32
  • 1
    The card is signed by the Carrier. He will not provide it to anyone outside the Carrier since it is a High Security signature. – pringi Feb 16 '18 at 16:19
  • Thanks. I got the apk signed by the carrier. I should now be able to read, write APN? What else do I have access to with card signed? – Ram Ramesh Feb 17 '18 at 16:53
0

WRITE_APN_SETTINGS

Not for use by third-party applications. You cant read the APN settings in API > 18.

For API <= 18

public class APNHelper {

    private Context context;

    public APNHelper(final Context context) {
        this.context = context;
    }

    @SuppressWarnings("unchecked")
    public List<APN> getMMSApns() {
        final Cursor apnCursor = this.context.getContentResolver()
                .query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI,
                        "current"), null, null, null, null);
        if (apnCursor == null) {
            return Collections.EMPTY_LIST;
        } else {
            final List<APN> results = new ArrayList<APN>();
            if (apnCursor.moveToFirst()) {
                do {
                    final String type = apnCursor.getString(apnCursor
                            .getColumnIndex(Telephony.Carriers.TYPE));
                    if (!TextUtils.isEmpty(type)
                            && (type.equalsIgnoreCase("*") || type
                            .equalsIgnoreCase("mms"))) {
                        final String mmsc = apnCursor.getString(apnCursor
                                .getColumnIndex(Telephony.Carriers.MMSC));
                        final String mmsProxy = apnCursor.getString(apnCursor
                                .getColumnIndex(Telephony.Carriers.MMSPROXY));
                        final String port = apnCursor.getString(apnCursor
                                .getColumnIndex(Telephony.Carriers.MMSPORT));
                        final APN apn = new APN();
                        apn.MMSCenterUrl = mmsc;
                        apn.MMSProxy = mmsProxy;
                        apn.MMSPort = port;
                        results.add(apn);

                        Toast.makeText(context,
                                mmsc + " " + mmsProxy + " " + port,
                                Toast.LENGTH_LONG).show();
                    }
                } while (apnCursor.moveToNext());
            }
            apnCursor.close();
            return results;
        }
    }
}
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
  • I can't understand how can this be possible. Even as a system app and with root privileges? – Aldridge1991 May 20 '16 at 10:56
  • you `can` read APN setting in API < 19 and `cannot` read in greator then API > 18. what you really don't understand? – Sohail Zahid May 20 '16 at 10:59
  • Why is that happening – Aldridge1991 May 20 '16 at 11:02
  • @Aldridge1991 Since the DB may contain corp passwords, we should secure it. Using the same permission as writing to the DB as the read is potentially as damaging as a write.Original Answer [http://stackoverflow.com/questions/13453640/read-apns-in-android-4-2] – Sohail Zahid May 20 '16 at 11:07