Tuesday, July 31, 2012

[android-developers] Re: Is setting invalid APN the only way to disable mobile network connection?

Actually I am writing a similar application, and ran into the platforms numurous odd and apparently silly limitations. 

While some limitations are probably needed, a lot of features which should be available to developers are disabled where they were previously were enabled, or are simply lacking, or blocked/ hidden.
If I, me, the user, wants control over how the device behaves, it should be my decision to automate it by installing an app, or do it manually from a settings menu.
If I want to be dictated by my device, I can always switch to Apple...
That has nothing to do with a "denial of service attack against other applications on the device", it has to do with wanting to have control over your device.
Ask yourself: is it a "denial of service attack" if the user changes the features the platform blocks in the settings menu?

If I download a application knowing it can programmaticaly enable/ disable NFC, then I must be fully aware that it does just that, arent't I?
No, actually I am not, not with the current way the permissions system works.
This is because the it is inheritly flawed, and thus unsecure, resulting in the need to block certain features.

All permissions are treated equally when you install the application, because of this most people won't read the whole permissions list.
"Dangerous" permissions can even be (and are mostly, ironically) on the lower part of the list.
These should be on top of the list, highlighted even, in red or whatever, so it catches your attention when you install a dangerous application.
If it catches your attention, you will think twice to install it as a user. 

And this opens up the way for developers to access features which are needed and should/ could be opened in the API, when new permissions are created for currently deemed "dangerous" features, lifting the problem of having to limit seemingly harmless things like NFC enable/ disable.

Op dinsdag 31 juli 2012 17:03:13 UTC+2 schreef CJ het volgende:
Hi,

I have been googling for a while able the best or right way to disable/enable mobile network.

I tried the following code which is all over Stackoverflow and is working fine for gingerbread and higher:

private void setMobileDataEnabled(Context context, boolean enabled)
throws Exception {
final ConnectivityManager conman = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
final Class<?> conmanClass = Class.forName(conman.getClass().getName());
final Field iConnectivityManagerField = conmanClass
.getDeclaredField("mService");
iConnectivityManagerField.setAccessible(true);
final Object iConnectivityManager = iConnectivityManagerField
.get(conman);
final Class<?> iConnectivityManagerClass = Class
.forName(iConnectivityManager.getClass().getName());
final Method setMobileDataEnabledMethod = iConnectivityManagerClass
.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.setAccessible(true);

setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled);
}

Somehow I didn't find a way to do the same thing for Android 2.2 and below. Many mentioned to change the APN name to something invalid like what app APNDroid did but is that the only way?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment