@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { informaCam.setStatusListener(this); if (resultCode == Activity.RESULT_CANCELED) { if (informaCam.isOutsideTheLoop(init.getAction())) { // Logger.d(LOG, "coming back from VMM call WITH NOOOOO MEDIA, and i shoudl finish."); setResult(resultCode, getIntent()); finish(); return; } else if (data != null && data.hasExtra(Codes.Extras.LOGOUT_USER) && data.getBooleanExtra(Codes.Extras.LOGOUT_USER, false)) { Logger.d(LOG, "Logout the user and close."); informaCam.setStatusListener(null); // informaCam.stopInforma(); route = null; setResult(resultCode, getIntent()); finish(); if (data.hasExtra(Codes.Extras.PERFORM_WIPE) && data.getBooleanExtra(Codes.Extras.PERFORM_WIPE, false)) { wipe(); } return; } // XXX: DOES THIS BREAK LOGOUT? setResult(resultCode, data); finish(); } else if (resultCode == Activity.RESULT_OK) { Log.d(LOG, "returning with request code " + requestCode); /* if(informaCam.isOutsideTheLoop(init.getAction())) { Logger.d(LOG, "coming back from VMM call with SOME media, and i shoudl finish."); // TODO: immediately 1) chooser 2) encrypt (all? selected?) to org 3) start up a transport for each returned media finish(); return; } */ route = new Intent(this, HomeActivity.class); if (prefStealthIcon) route.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); routeCode = Home.ROUTE_CODE; switch (requestCode) { case Codes.Routes.CAMERA: route = new Intent(this, EditorActivity.class); routeCode = Editor.ROUTE_CODE; break; case Codes.Routes.EDITOR: break; case Codes.Routes.LOGIN: break; case Codes.Routes.HOME: if (data != null && data.hasExtra(Codes.Extras.CHANGE_LOCALE)) { route.putExtra(Codes.Extras.CHANGE_LOCALE, true); } break; case Codes.Routes.WIZARD: route = new Intent(this, HomeActivity.class); if (prefStealthIcon) route.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); routeCode = Home.ROUTE_CODE; route.putExtra(Codes.Extras.GENERATING_KEY, true); if (KeyUtility.initDevice()) { informaCam.user.hasCompletedWizard = true; informaCam.user.lastLogIn = System.currentTimeMillis(); informaCam.user.isLoggedIn = true; informaCam.saveState(informaCam.user); } break; } routeByIntent(); } else if (resultCode == Activity.RESULT_FIRST_USER) { if (data.hasExtra(Codes.Extras.CHANGE_LOCALE) && data.getBooleanExtra(Codes.Extras.CHANGE_LOCALE, false)) { route.putExtra(Codes.Extras.CHANGE_LOCALE, true); } } }
@Override public void wizardCompleted() { // save everything and finish InformaCam informaCam = (InformaCam) getApplication(); informaCam.user.hasCompletedWizard = true; informaCam.user.lastLogIn = System.currentTimeMillis(); informaCam.user.isLoggedIn = true; informaCam.saveState(informaCam.user); informaCam.saveState(informaCam.languageMap); try { informaCam.initData(); } catch (Exception re) { throw new RuntimeException("Could not init data", re); } try { for (String s : informaCam.getAssets().list("includedOrganizations")) { InputStream ictdIS = informaCam.ioService.getStream("includedOrganizations/" + s, Type.APPLICATION_ASSET); byte[] ictdBytes = new byte[ictdIS.available()]; ictdIS.read(ictdBytes); IOrganization organization = informaCam.installICTD( (JSONObject) new JSONTokener(new String(ictdBytes)).nextValue(), null, this); if (organization != null && !informaCam.user.isInOfflineMode) { INotification notification = new INotification( getResources().getString(R.string.key_sent), getResources() .getString( R.string.you_have_sent_your_credentials_to_x, organization.organizationName), Models.INotification.Type.NEW_KEY); notification.taskComplete = false; informaCam.addNotification(notification, null); ITransportStub transportStub = new ITransportStub(organization, notification); transportStub.setAsset( IUser.PUBLIC_CREDENTIALS, IUser.PUBLIC_CREDENTIALS, MimeType.ZIP, Storage.Type.IOCIPHER); transportStub.callbackCode = Models.ITransportStub.CallbackCodes.UPDATE_ORGANIZATION_HAS_KEY; TransportUtility.initTransport(transportStub); } } } catch (IOException e) { Log.e(LOG, e.toString()); e.printStackTrace(); } catch (JSONException e) { Log.e(LOG, e.toString()); e.printStackTrace(); } if (getIntent().getExtras() != null && getIntent().getExtras().size() > 0) { Iterator<String> it = getIntent().getExtras().keySet().iterator(); while (it.hasNext()) { getIntent().removeExtra(it.next()); } } setResult(Activity.RESULT_OK); finish(); }