List of usage examples for android.net ConnectivityManager getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:ota.otaupdates.MainActivity.java
/** * @return null if unconfirmed/* w ww . jav a 2s . c om*/ */ public Boolean isMobileDataEnabled() { Object connectivityService = getSystemService(CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) connectivityService; try { Class<?> c = Class.forName(cm.getClass().getName()); Method m = c.getDeclaredMethod("getMobileDataEnabled"); m.setAccessible(true); return (Boolean) m.invoke(cm); } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:org.saydroid.tether.usb.Engine.java
public boolean startupCheck() { boolean startupCheckSuccess = false; boolean mSupportedKernel = false; this.checkDirs(); if (!this.hasRootPermission()) { mSupportedKernel = false;//from w ww. j av a 2 s . c o m } if (this.binariesExists() == false) { if (this.hasRootPermission()) { this.installFiles(); } } /* * Add a function for get setting from settings.db to see if there is tether_supported * need to write a function to dump the settings.db secure table into a file and * read from this file to see if contains tether_supported. This function is defined * inside CoreTask.java */ boolean dumpSettingSuccess = false; boolean setGlobalSettingFail = false; if (this.hasRootPermission()) { if ((this.dumpGlobalSettings() == false) || (this.dumpGlobalSettingsMaxID() == false)) { //this.openFailToDumpSecureSettingDialog(); dumpSettingSuccess = false; } else dumpSettingSuccess = true; } int iMaxId = -1; if (!this.checkGlobalSetting(this.mGlobalSetting_tether_supported)) { iMaxId = this.globalSettingMaxId(); if (iMaxId < 0) { //error occurs during retrieve maxId of secure table, return -1 if error Log.d(TAG, "cannot read system setting's max id during checking tether_supported..."); } else { //if there is no error to retrieve maxId, then insert with new name field and maxid iMaxId = iMaxId + 1; if (!this.globalSettingInsertAndEnable(this.mGlobalSetting_tether_supported, iMaxId, 1)) { setGlobalSettingFail = true; Log.d(TAG, "cannot insert and enable " + this.mGlobalSetting_tether_supported); } } } else if (!this.globalSettingIsEnabled(this.mGlobalSetting_tether_supported, 1)) { if (!this.globalSettingEnable(this.mGlobalSetting_tether_supported, 1)) { setGlobalSettingFail = true; Log.d(TAG, "cannot enable " + this.mGlobalSetting_tether_supported); } } else { Log.d(TAG, this.mGlobalSetting_tether_supported + " has been enabled already"); } if (!this.checkGlobalSetting(this.mGlobalSetting_tether_dun_required)) { iMaxId = this.globalSettingMaxId(); if (iMaxId < 0) { //error occurs during retrieve maxId of secure table, return -1 if error Log.d(TAG, "cannot read system setting's max id during checking tether_dun_required..."); } else { //if there is no error to retrieve maxId, then insert with new name field and maxid iMaxId = iMaxId + 1; if (!this.globalSettingInsertAndEnable(this.mGlobalSetting_tether_dun_required, iMaxId, 0)) { setGlobalSettingFail = true; Log.d(TAG, "cannot insert and enable " + this.mGlobalSetting_tether_dun_required); } } } else if (!this.globalSettingIsEnabled(this.mGlobalSetting_tether_dun_required, 0)) { if (!this.globalSettingEnable(this.mGlobalSetting_tether_dun_required, 0)) { setGlobalSettingFail = true; Log.d(TAG, "cannot enable " + this.mGlobalSetting_tether_dun_required); } } else { Log.d(TAG, this.mGlobalSetting_tether_dun_required + " has been enabled already"); } Log.d(TAG, "dumpSettingSuccess is:" + dumpSettingSuccess); Log.d(TAG, "setSecureSettingFail is:" + setGlobalSettingFail); if (dumpSettingSuccess && !setGlobalSettingFail) { //Use reflection to retrieve the isTetheringSupported method from connnectivityManager ConnectivityManager cm = SgsApplication.getConnectivityManager(); Method isTetheringSupportedLocal = null; Method getTetherableUsbRegexsLocal = null; //added temp String[] tetherRegex; try { isTetheringSupportedLocal = cm.getClass().getMethod("isTetheringSupported"); getTetherableUsbRegexsLocal = cm.getClass().getMethod("getTetherableUsbRegexs"); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Use this high level general method to make judgment try { mSupportedKernel = (Boolean) isTetheringSupportedLocal.invoke(cm); tetherRegex = (String[]) getTetherableUsbRegexsLocal.invoke(cm); Log.d(TAG, "supportedKernel value is:" + mSupportedKernel); //note: cannot use (boolean) isTetheringSupportedLocal.invoke(cm); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!mSupportedKernel) { //this.openUnsupportedKernelDialog(); } } //TODO: those lines below for debug only int tetherEnabledInSettings = 0; try { tetherEnabledInSettings = Settings.Global.getInt(SgsApplication.getInstance().getContentResolver(), "tether_supported"); } catch (Settings.SettingNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d(TAG, "tetherEnabledInSettings is ..." + tetherEnabledInSettings); //SgsApplication.getInstance().checkForUpdate(); //this.toggleStartStop(); startupCheckSuccess = true; getConfigurationService().putBoolean(SgsConfigurationEntry.GENERAL_STARTUP_CHECK, !startupCheckSuccess); getConfigurationService().commit(); return startupCheckSuccess; }