@WorkerThread private void runProgram(Context context, JavaProjectFolder projectFile, int action, Intent intent) throws Exception { InputStream in = mConsoleEditText.getInputStream(); File tempDir = getDir("dex", MODE_PRIVATE); switch (action) { case CompileHelper.Action.RUN: { CompileHelper.compileAndRun(context, in, tempDir, projectFile); break; } case CompileHelper.Action.RUN_DEX: { File dex = (File) intent.getSerializableExtra(CompileManager.DEX_FILE); if (dex != null) { String mainClass = projectFile.getMainClass().getName(); CompileHelper.executeDex(context, in, dex, tempDir, mainClass); } break; } } }
/** * Delete rows from the specified {@code table} and notify any subscribed queries. This method * will not trigger a notification if no rows were deleted. * * @see SQLiteDatabase#delete(String, String, String[]) */ @WorkerThread public int delete(@NonNull String table, @Nullable String whereClause, @Nullable String... whereArgs) { SQLiteDatabase db = getWritableDatabase(); if (logging) { log("DELETE\n table: %s\n whereClause: %s\n whereArgs: %s", table, whereClause, Arrays.toString(whereArgs)); } int rows = db.delete(table, whereClause, whereArgs); if (logging) log("DELETE affected %s %s", rows, rows != 1 ? "rows" : "row"); if (rows > 0) { // Only send a table trigger if rows were affected. sendTableTrigger(Collections.singleton(table)); } return rows; }
@UiThread public void surfaceChanged(final SurfaceHolder holder, int format, int width, int height) { runOnNativeThread(new Runnable() { @WorkerThread @Override public void run() { m_surfaceHolder = holder; if (m_surfaceHolder != null) { Surface surface = m_surfaceHolder.getSurface(); if (surface.isValid()) { nativeSetSurface(m_jniApiRunnerPtr, surface); } } } }); }
@UiThread public void onPointerUp(final int primaryActionIndex, final int primaryActionIdentifier, final int pointerCount, final float[] x, final float y[], final int[] pointerIdentity, final int[] pointerIndex) { runOnNativeThread(new Runnable() { @WorkerThread @Override public void run() { nativeProcessPointerUp(m_jniApiRunnerPtr, primaryActionIndex, primaryActionIdentifier, pointerCount, x, y, pointerIdentity, pointerIndex); } }); if (m_eeGeoMap == null) { Log.d("eegeo-android-sdk", "skipping input event -- map not ready"); return; } if (x.length > 0) { // TODO: remove this and promote to native ITouchController Point mouseUpPoint = new Point((int) x[0], (int) y[0]); double distSquared = Math.pow(mouseUpPoint.x - m_mouseDownPoint.x, 2) + Math.pow(mouseUpPoint.y - m_mouseDownPoint.y, 2); if (distSquared < 25) { m_eeGeoMap.onTapped(mouseUpPoint); } } }
@WorkerThread private void writeToFile() { if (mFiles.canWrite(mLogFile)) { List<LogMessage> list; synchronized (mLock) { list = new LinkedList<>(mCacheQueue); mCacheQueue.clear(); } mFiles.writeToFile(list, mLogFile); if (mSetting.debuggable()) { mWriteCount ++; } } }
@WorkerThread private void jniOnIndoorEntered() { final IndoorMap indoorMap = IndoorsApiJniCalls.getIndoorMapData(m_eegeoMapApiPtr); final int currentIndoorFloor = IndoorsApiJniCalls.getCurrentFloorIndex(m_eegeoMapApiPtr); m_uiRunner.runOnUiThread(new Runnable() { @UiThread @Override public void run() { m_indoorMap = indoorMap; m_currentIndoorFloor = currentIndoorFloor; for (OnIndoorEnteredListener listener : m_onIndoorEnteredListeners) { listener.onIndoorEntered(); } } }); }
@WorkerThread public void notifyTagsLoaded() { m_uiRunner.runOnUiThread(new Runnable() { @Override public void run() { m_hasLoadedTags = true; m_loadInProgress = false; if(m_listener != null) { m_listener.onTagsLoadCompleted(); } m_listener = null; } }); }
@WorkerThread public int create(PolygonOptions polygonOptions, Polygon.AllowHandleAccess allowHandleAccess) throws InvalidParameterException { if (allowHandleAccess == null) throw new NullPointerException("Null access token. Method is intended for internal use by Polygon"); if (polygonOptions.getPoints().size() < 2) throw new InvalidParameterException("PolygonOptions points must contain at least two elements"); List<LatLng> exteriorPoints = polygonOptions.getPoints(); List<List<LatLng>> holes = polygonOptions.getHoles(); final int[] ringVertexCounts = buildRingVertexCounts(exteriorPoints, holes); final double[] allPointsDoubleArray = buildPointsArray(exteriorPoints, holes, ringVertexCounts); return nativeCreatePolygon( m_jniEegeoMapApiPtr, polygonOptions.getIndoorMapId(), polygonOptions.getIndoorFloorId(), polygonOptions.getElevation(), polygonOptions.getElevationMode().ordinal(), allPointsDoubleArray, ringVertexCounts, polygonOptions.getFillColor() ); }
@WorkerThread static void setProgramViewCount(Context context, long programId, int numberOfViews) { Uri programUri = TvContractCompat.buildPreviewProgramUri(programId); try (Cursor cursor = context.getContentResolver().query(programUri, null, null, null, null)) { if (!cursor.moveToFirst()) { return; } PreviewProgram existingProgram = PreviewProgram.fromCursor(cursor); PreviewProgram.Builder builder = new PreviewProgram.Builder(existingProgram) .setInteractionCount(numberOfViews) .setInteractionType(TvContractCompat.PreviewProgramColumns .INTERACTION_TYPE_VIEWS); int rowsUpdated = context.getContentResolver().update( TvContractCompat.buildPreviewProgramUri(programId), builder.build().toContentValues(), null, null); if (rowsUpdated != 1) { Log.e(TAG, "Update program failed"); } } }
/** * Get all the multimedia files, including videos and pictures. */ @WorkerThread public ArrayList<AlbumFolder> getAllMedia() { Map<String, AlbumFolder> albumFolderMap = new HashMap<>(); AlbumFolder allFileFolder = new AlbumFolder(); allFileFolder.setChecked(true); allFileFolder.setName(mContext.getString(R.string.album_all_images_videos)); scanImageFile(albumFolderMap, allFileFolder); scanVideoFile(albumFolderMap, allFileFolder); ArrayList<AlbumFolder> albumFolders = new ArrayList<>(); Collections.sort(allFileFolder.getAlbumFiles()); albumFolders.add(allFileFolder); for (Map.Entry<String, AlbumFolder> folderEntry : albumFolderMap.entrySet()) { AlbumFolder albumFolder = folderEntry.getValue(); Collections.sort(albumFolder.getAlbumFiles()); albumFolders.add(albumFolder); } return albumFolders; }
@WorkerThread T getVariable(String variableName) throws ParticleCloudException, IOException, VariableDoesNotExistException { if (!device.deviceState.variables.containsKey(variableName)) { throw new VariableDoesNotExistException(variableName); } R reply; try { reply = callApi(variableName); } catch (RetrofitError e) { throw new ParticleCloudException(e); } if (!reply.coreInfo.connected) { // FIXME: we should be doing this "connected" check on _any_ reply that comes back // with a "coreInfo" block. device.cloud.onDeviceNotConnected(device.deviceState); throw new IOException("Device is not connected."); } else { return reply.result; } }
@WorkerThread private void fetchBuildingInformation(int nativeHandle) { final BuildingHighlight buildingHighlight = m_nativeHandleToBuildingHighlight.get(nativeHandle); if (buildingHighlight == null) throw new NullPointerException("BuildingHighlight object not found for nativeHandle"); final BuildingInformation buildingInformation = nativeGetBuildingInformation(m_jniEegeoMapApiPtr, nativeHandle); if (buildingInformation != null) { m_uiRunner.runOnUiThread(new Runnable() { @UiThread @Override public void run() { buildingHighlight.setBuildingInformation(buildingInformation); } }); } }
@WorkerThread public List<AttachmentViewInfo> extractAttachmentInfoForView(List<Part> attachmentParts) throws MessagingException { List<AttachmentViewInfo> attachments = new ArrayList<>(); for (Part part : attachmentParts) { AttachmentViewInfo attachmentViewInfo = extractAttachmentInfo(part); attachments.add(attachmentViewInfo); } return attachments; }
@UiThread private void updateElevation() { final double elevation = m_elevation; submit(new Runnable() { @WorkerThread public void run() { m_bluesphereApi.setElevation(BlueSphere.m_allowHandleAccess, elevation); } }); }
@WorkerThread public MessageViewInfo extractMessageForView(Message message, @Nullable MessageCryptoAnnotations cryptoAnnotations) throws MessagingException { ArrayList<Part> extraParts = new ArrayList<>(); Part cryptoContentPart = MessageCryptoStructureDetector.findPrimaryEncryptedOrSignedPart(message, extraParts); if (cryptoContentPart == null) { if (cryptoAnnotations != null && !cryptoAnnotations.isEmpty()) { Timber.e("Got crypto message cryptoContentAnnotations but no crypto root part!"); } return extractSimpleMessageForView(message, message); } boolean isOpenPgpEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedOpenPgpProtocol(cryptoContentPart)) || MessageCryptoStructureDetector.isPartPgpInlineEncrypted(cryptoContentPart); boolean isSMimeEncrypted = (MessageCryptoStructureDetector.isPartMultipartEncrypted(cryptoContentPart) && MessageCryptoStructureDetector.isMultipartEncryptedSMimeProtocol(cryptoContentPart)); if ((!QMail.isOpenPgpProviderConfigured() && isOpenPgpEncrypted) || (!QMail.isSMimeProviderConfigured() && isSMimeEncrypted)) { CryptoResultAnnotation noProviderAnnotation = CryptoResultAnnotation.createErrorAnnotation( CryptoError.SMIME_ENCRYPTED_NO_PROVIDER, null); return MessageViewInfo.createWithErrorState(message, false) .withCryptoData(noProviderAnnotation, null, null, null); } CryptoResultAnnotation cryptoContentPartAnnotation = cryptoAnnotations != null ? cryptoAnnotations.get(cryptoContentPart) : null; if (cryptoContentPartAnnotation != null) { return extractCryptoMessageForView(message, extraParts, cryptoContentPart, cryptoContentPartAnnotation); } return extractSimpleMessageForView(message, message); }
@Override @WorkerThread public MessageViewInfo loadInBackground() { try { return messageViewInfoExtractor.extractMessageForView(message, annotations); } catch (Exception e) { Timber.e(e, "Error while decoding message"); return null; } }
@UiThread public MapsceneRequest requestMapscene(final MapsceneRequestOptions options) { MapsceneRequest request = new MapsceneRequest( this, options.getApplyOnLoad(), options.getOnMapsceneRequestCompletedListener(), new Callable<Integer>() { @WorkerThread @Override public Integer call() throws Exception { return beginMapsceneRequest(options); } }); return request; }
@WorkerThread public static Uri createTempUriForContentUri(Context context, Uri uri) throws IOException { Context applicationContext = context.getApplicationContext(); File tempFile = getTempFileForUri(uri, applicationContext); writeUriContentToTempFileIfNotExists(context, uri, tempFile); Uri tempFileUri = FileProvider.getUriForFile(context, AUTHORITY, tempFile); registerFileCleanupReceiver(applicationContext); return tempFileUri; }
@WorkerThread public long create(EegeoMap eegeoMap, EegeoMapOptions eegeoMapOptions) { String apiKey = EegeoApi.getInstance().getApiKey(); String coverageTreeManifest = eegeoMapOptions.getCoverageTreeManifest(); if (coverageTreeManifest == null) { coverageTreeManifest = ""; } String environmentThemesManifest = eegeoMapOptions.getEnvironmentThemesManifest(); if (environmentThemesManifest == null) { environmentThemesManifest = ""; } long jniEegeoMapApiPtr = nativeCreateEegeoMapApi(m_jniApiRunnerPtr, eegeoMap, apiKey, coverageTreeManifest, environmentThemesManifest); return jniEegeoMapApiPtr; }
/** * Get a short-lived claiming token for transmitting to soon-to-be-claimed device in * soft AP setup process * * @return a claim code string set on success (48 random bytes, base64 encoded * to 64 ASCII characters) */ @WorkerThread public Responses.ClaimCodeResponse generateClaimCode() throws ParticleCloudException { try { // Offer empty string to appease newer OkHttp versions which require a POST body, // even if it's empty or (as far as the endpoint cares) nonsense return mainApi.generateClaimCode("okhttp_appeasement"); } catch (RetrofitError error) { throw new ParticleCloudException(error); } }
/** * See {@link #executeUpdateDelete(String, SQLiteStatement)} for usage. This overload allows for triggering multiple tables. * * @see BriteDatabase#executeUpdateDelete(String, SQLiteStatement) */ @WorkerThread @RequiresApi(Build.VERSION_CODES.HONEYCOMB) public int executeUpdateDelete(Set<String> tables, SQLiteStatement statement) { if (logging) log("EXECUTE\n %s", statement); int rows = statement.executeUpdateDelete(); if (rows > 0) { // Only send a table trigger if rows were affected. sendTableTrigger(tables); } return rows; }
/** * Gets the bookmarks associated with the given account. * * Both the request and the callback occur on the calling thread (this is unintuitive: issue #3). * * @param itemLimit The number of items to fetch. If < 0, fetches all items. */ @WorkerThread // network request. static void getBlocking(final FirefoxSyncConfig syncConfig, final int itemLimit, final OnSyncComplete<BookmarkFolder> onComplete) { final SyncClientBookmarksResourceDelegate resourceDelegate = new SyncClientBookmarksResourceDelegate(syncConfig, onComplete); try { FirefoxSyncUtils.makeGetRequestForCollection(syncConfig, BOOKMARKS_COLLECTION, getArgs(itemLimit), resourceDelegate); } catch (final FirefoxDataException e) { onComplete.onException(e); } }
@UiThread public void onDestroy() { Log.d("eegeo-android-sdk", "onDestroy"); runOnNativeThread(new Runnable() { @WorkerThread @Override public void run() { Log.d("eegeo-android-sdk", "Native Thread: onDestroy"); m_nativeThread.stopUpdating(); nativeDestroyApiRunner(m_jniApiRunnerPtr); m_jniApiRunnerPtr = 0; synchronized (m_nativeThread) { m_nativeThread.notifyAll(); } } }); Log.d("eegeo-android-sdk", "begin wait nativeDestroyApiRunner"); synchronized (m_nativeThread) { try { m_nativeThread.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } Log.d("eegeo-android-sdk", "end wait nativeDestroyApiRunner"); m_nativeThread.quit(); }
@UiThread public void onPause() { Log.d("eegeo-android-sdk", "onPause"); runOnNativeThread(new Runnable() { @WorkerThread @Override public void run() { m_nativeThread.stopUpdating(); nativePauseApiRunner(m_jniApiRunnerPtr); } }); }
@WorkerThread public int create(PolylineOptions polylineOptions, Polyline.AllowHandleAccess allowHandleAccess) throws InvalidParameterException { if (allowHandleAccess == null) throw new NullPointerException("Null access token. Method is intended for internal use by Polyline"); if (polylineOptions.getPoints().size() < 2) throw new InvalidParameterException("PolylineOptions points must contain at least two elements"); double[] latLongs = pointsToArray(polylineOptions.getPoints()); List<Double> perPointElevationsList = polylineOptions.getPerPointElevations(); double[] perPointElevations = new double[perPointElevationsList.size()]; for (int i = 0; i < perPointElevationsList.size(); ++i) { perPointElevations[i] = perPointElevationsList.get(i); } return nativeCreatePolyline( m_jniEegeoMapApiPtr, polylineOptions.getIndoorMapId(), polylineOptions.getIndoorFloorId(), polylineOptions.getElevation(), polylineOptions.getElevationMode().ordinal(), latLongs, perPointElevations, polylineOptions.getWidth(), polylineOptions.getColor(), polylineOptions.getMiterLimit() ); }
/** * Call a function on the device * * @param functionName Function name * @param args Array of arguments to pass to the function on the device. * Arguments must not be more than MAX_PARTICLE_FUNCTION_ARG_LENGTH chars * in length. If any arguments are longer, a runtime exception will be thrown. * @return result code: a value of 1 indicates success */ @WorkerThread public int callFunction(String functionName, @Nullable List<String> args) throws ParticleCloudException, IOException, FunctionDoesNotExistException { // TODO: check response of calling a non-existent function if (!deviceState.functions.contains(functionName)) { throw new FunctionDoesNotExistException(functionName); } // null is accepted here, but it won't be in the Retrofit API call later if (args == null) { args = list(); } String argsString = ParticleInternalStringUtils.join(args, ','); Preconditions.checkArgument(argsString.length() < MAX_PARTICLE_FUNCTION_ARG_LENGTH, String.format("Arguments '%s' exceed max args length of %d", argsString, MAX_PARTICLE_FUNCTION_ARG_LENGTH)); Responses.CallFunctionResponse response; try { response = mainApi.callFunction(deviceState.deviceId, functionName, new FunctionArgs(argsString)); } catch (RetrofitError e) { throw new ParticleCloudException(e); } if (!response.connected) { cloud.onDeviceNotConnected(deviceState); throw new IOException("Device is not connected."); } else { return response.returnValue; } }
@UiThread private void updateEnabled() { final boolean enabled = m_enabled; submit(new Runnable() { @WorkerThread public void run() { m_bluesphereApi.setEnabled(BlueSphere.m_allowHandleAccess, enabled); } }); }
@UiThread public void onResume() { runOnNativeThread(new Runnable() { @WorkerThread @Override public void run() { if (m_surfaceHolder != null && m_surfaceHolder.getSurface() != null) { nativeSetSurface(m_jniApiRunnerPtr, m_surfaceHolder.getSurface()); nativeResumeApiRunner(m_jniApiRunnerPtr); } m_nativeThread.startUpdating(); } }); }
/** * Sync log message to file. */ @WorkerThread public static void syncLog(int priority, String message) { if (checkInit()) { sLogEngine.syncLog(priority, null, message); } }
@WorkerThread public boolean updateAfterSync(HashSet<T> tHashSet) { LinkedHashSet<ParamUpdate> paramUpdates = new LinkedHashSet<>(); for(T t : tHashSet){ paramUpdates.add(new ParamUpdate(getTableName(), getIdFieldName() + " = ?", new String[]{t.id}, getSyncContentValuesAfterSync(t))); } return BaseDao.bulkUpdate(paramUpdates) >= tHashSet.size(); }
@WorkerThread @NonNull private synchronized SQLiteDatabase lazyDatabase() { if (mDatabase == null || !mDatabase.isOpen()) { mDatabase = this.getWritableDatabase(); } return mDatabase; }
@WorkerThread private void jniOnCameraMove() { m_uiRunner.runOnUiThread(new Runnable() { @UiThread @Override public void run() { for (OnCameraMoveListener listener : m_onCameraMoveListeners) { listener.onCameraMove(); } } }); }
@WorkerThread private Cursor query(Param param){ SQLiteQueryBuilder sqLiteQueryBuilder = getQueryBuilder(); Cursor c; if(sqLiteQueryBuilder != null){ c = sqLiteQueryBuilder.query( Database.getDatabase(), param.projection, param.selection, param.selectionArgs, null, null, param.sortOrder ); } else { c = Database.getDatabase().query( getTableName(), param.projection, param.selection, param.selectionArgs, null, null, param.sortOrder ); } return c; }
/** * Zipping log files and return the zip file. */ @WorkerThread public static File zippingLogFiles(int mode, List<File> attaches) { if (checkInit()) { return sLogEngine.zippingFiles(mode, attaches); } return null; }
@WorkerThread protected int getNativeHandle() { if (m_nativeHandle == null) throw new RuntimeException("nativeHandle not yet available, ensure all calls to getNativeHandle are wrapped by submit()"); return m_nativeHandle.intValue(); }
@WorkerThread @Nullable synchronized String getHistoryItem(@NonNull String url) { Cursor cursor = lazyDatabase().query(TABLE_HISTORY, new String[]{KEY_ID, KEY_URL, KEY_TITLE}, KEY_URL + " = ?", new String[]{url}, null, null, null, "1"); String m = null; if (cursor != null) { cursor.moveToFirst(); m = cursor.getString(0); cursor.close(); } return m; }
@UiThread PoiSearch(final PoiApi poiApi, OnPoiSearchCompletedListener callback, Callable<Integer> beginSearchCallable) { super(poiApi.getNativeRunner(), poiApi.getUiRunner(), beginSearchCallable); m_poiApi = poiApi; m_callback = callback; submit(new Runnable() { @WorkerThread @Override public void run() { m_poiApi.register(PoiSearch.this, getNativeHandle()); } }); }
@WorkerThread private void jniOnIndoorEnterFailed() { m_uiRunner.runOnUiThread(new Runnable() { public void run() { m_indoorMap = null; m_currentIndoorFloor = -1; } }); }
@WorkerThread public void setElevation(BlueSphere.AllowHandleAccess allowHandleAccess, double elevation) { if (allowHandleAccess == null) throw new NullPointerException("Null access token. Method is intended for internal use by BlueSphere"); nativeSetElevation( m_jniEegeoMapApiPtr, elevation); }
@WorkerThread void unclaimDevice(String deviceId) { mainApi.unclaimDevice(deviceId); synchronized (devices) { devices.remove(deviceId); } sendUpdateBroadcast(); }