private void updateProgress() { for (Action a : Action.values()) { if (a == currentAction) { // this is the current action showInProgress(a.viewId); } else if (a.ordinal() < currentAction.ordinal()) { // this action has completed showResult(a.viewId, results[a.ordinal()]); } else { // this action hasn't started showNotStarted(a.viewId); } } ChipsetDetection detection = ChipsetDetection.getDetection(); if (currentAction == Action.Finished) if (detection == null || detection.getWifiChipset() == null || detection.getWifiChipset().supportedModes == null || detection.getWifiChipset().supportedModes.contains(WifiMode.Adhoc) == false) { app.showNoAdhocDialog = true; LogActivity.logMessage( "detect", "Could not work out how to control your WiFi chipset. Relying on operating system, so no ad-hoc WiFi.", false); } }
public void checkedChipsetSupported(boolean result) { // XXX - Need to handle multiple detections here so that we can give the // user a choice, and then test that choice. if (result) { TextView t = (TextView) findViewById(R.id.labelChipsetSupported); t.setText("I think your WiFi is '" + ChipsetDetection.getDetection().getChipset() + "'."); t = (TextView) findViewById(R.id.labelChipsetExperimental); t.setText("Skipped check for experimental support, since we already support your handset."); } }
@Override protected Action doInBackground(Void... arg) { wakeLock.acquire(); try { ChipsetDetection detection = ChipsetDetection.getDetection(); while (true) { boolean result = false; boolean fatal = currentAction.fatal; try { Log.v("BatPhone", "Performing action " + currentAction); switch (currentAction) { case Unpacking: app.installFilesIfRequired(); result = true; break; case AdhocWPA: if (false) { // Get wifi manager WifiManager wm = (WifiManager) ServalBatPhoneApplication.context.getSystemService(Context.WIFI_SERVICE); // enable wifi wm.setWifiEnabled(true); WifiConfiguration wc = new WifiConfiguration(); wc.SSID = "*supplicant-test"; int res = wm.addNetwork(wc); Log.d("BatPhone", "add Network returned " + res); boolean b = wm.enableNetwork(res, true); Log.d("WifiPreference", "enableNetwork returned " + b); } break; case RootCheck: result = ServalBatPhoneApplication.context.coretask.hasRootPermission(); break; case Supported: // Start out by only looking for non-experimental // chipsets detection.identifyChipset(); result = detection.detected_chipsets.size() > 0; break; case Experimental: if (!results[Action.Supported.ordinal()]) { detection.inventSupport(); // this will not select a chipset detection.detect(true); result = detection.detected_chipsets.size() > 0; } break; case CheckSupport: result = testSupport(); break; case Finished: break; } } catch (Exception e) { result = false; Log.e("BatPhone", e.toString(), e); app.displayToastMessage(e.getMessage()); fatal = true; } results[currentAction.ordinal()] = result; Log.v("BatPhone", "Result " + result); if (fatal && !result) { fatalError = true; return currentAction; } if (currentAction == Action.Finished) { ServalBatPhoneApplication.wifiSetup = true; return currentAction; } this.publishProgress(currentAction); currentAction = Action.values()[currentAction.ordinal() + 1]; } } finally { wakeLock.release(); dismissTryExperimentalChipsetDialog(); } }
private boolean testSupport() { ChipsetDetection detection = ChipsetDetection.getDetection(); List<Chipset> l = detection.detected_chipsets; boolean tryExperimental = false; while (true) { for (int i = 0; i < l.size(); i++) { Chipset c = l.get(i); if (c.isExperimental() != tryExperimental) continue; // only test scripts if we have root access, otherwise // assume the first one is correct if (results[Action.RootCheck.ordinal()]) { if (!c.supportedModes.contains(WifiMode.Adhoc)) continue; // Write a disable file that suppresses attempting // this detection again so that re-running the BatPhone // preparation wizard will not get stuck on the same // chipset every time File attemptFlag = new File(app.coretask.DATA_FILE_PATH + "/var/attempt_" + c.chipset); if (attemptFlag.exists()) { Log.v("BatPhone", "Skipping " + c.chipset + " as I think it failed before"); continue; } // If a chipset is marked experimental, then tell the // user. if (tryExperimental) PreparationWizard.showTryExperimentalChipsetDialog(); try { attemptFlag.createNewFile(); Log.v("BatPhone", "Trying to use chipset " + c.chipset); detection.setChipset(c); if (app.wifiRadio == null) app.wifiRadio = WiFiRadio.getWiFiRadio(app); // make sure we aren't still in adhoc mode from a // previous // install / test if (WifiMode.getWiFiMode() != WifiMode.Off) app.wifiRadio.setWiFiMode(WifiMode.Off); if (WifiMode.getWiFiMode() != WifiMode.Off) { throw new IllegalStateException("Could not turn wifi off"); } // test adhoc on & off try { app.wifiRadio.setWiFiMode(WifiMode.Adhoc); app.wifiRadio.setWiFiMode(WifiMode.Off); } finally { if (WifiMode.getWiFiMode() != WifiMode.Off) { attemptFlag = null; throw new IllegalStateException("Could not turn wifi off"); } } } catch (IOException e) { Log.e("BatPhone", e.toString(), e); } finally { // If we couldn't turn off wifi, just fail completely if (attemptFlag != null) attemptFlag.delete(); } } else { Log.v("BatPhone", "Assuming chipset " + c.chipset + " as there is no root access."); detection.setChipset(c); } Editor ed = app.settings.edit(); ed.putString("detectedChipset", c.chipset); ed.commit(); LogActivity.logMessage( "detect", "We will use the '" + c.chipset + "' script to control WiFi.", false); return true; } tryExperimental = !tryExperimental; if (tryExperimental == false) break; } detection.setChipset(null); Editor ed = app.settings.edit(); ed.putString("detectedChipset", "UnKnown"); ed.commit(); return false; }