public static int getVersionCode(Context ctx) { int version = 0; try { version = ctx.getPackageManager().getPackageInfo(ctx.getApplicationInfo().packageName, 0).versionCode; } catch (Exception e) { Log.e("getVersionInt", e); } return version; }
private static byte[] generateKey(String input) { try { byte[] bytesOfMessage = input.getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("SHA256"); return md.digest(bytesOfMessage); } catch (Exception e) { Log.e("generateKey", e); return null; } }
private void setupCrypto(SecretKey key) { byte[] iv = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv); try { ecipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec); } catch (Exception e) { ecipher = null; Log.e("setupCrypto", e); } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public void setWindowLayoutType() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { try { mAnchor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); Method setWindowLayoutType = PopupWindow.class.getMethod("setWindowLayoutType", new Class[]{int.class}); setWindowLayoutType.invoke(mWindow, WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); } catch (Exception e) { Log.e("setWindowLayoutType", e); } } }
private PublicKey readKeyFromStream(InputStream keyStream) throws IOException { ObjectInputStream oin = new ObjectInputStream(new BufferedInputStream(keyStream)); try { PublicKey pubKey = (PublicKey) oin.readObject(); return pubKey; } catch (Exception e) { Log.e("readKeyFromStream", e); return null; } finally { oin.close(); } }
private void closeFD() { if (mFD != null) { try { mFD.close(); } catch (IOException e) { Log.e("closeFD", e); } mFD = null; } }
public String encrypt(String plaintext) { if (ecipher == null) return ""; try { byte[] ciphertext = ecipher.doFinal(plaintext.getBytes("UTF-8")); return Base64.encodeToString(ciphertext, Base64.NO_WRAP); } catch (Exception e) { Log.e("encryp", e); return ""; } }
public static int convertToInt(String str) throws NumberFormatException { int s, e; for (s = 0; s < str.length(); s++) if (Character.isDigit(str.charAt(s))) break; for (e = str.length(); e > 0; e--) if (Character.isDigit(str.charAt(e - 1))) break; if (e > s) { try { return Integer.parseInt(str.substring(s, e)); } catch (NumberFormatException ex) { Log.e("convertToInt", ex); throw new NumberFormatException(); } } else { throw new NumberFormatException(); } }
public String rsaEncrypt(InputStream keyStream, byte[] data) { try { PublicKey pubKey = readKeyFromStream(keyStream); Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, pubKey); byte[] cipherData = cipher.doFinal(data); return Base64.encodeToString(cipherData, Base64.NO_WRAP); } catch (Exception e) { Log.e("rsaEncrypt", e); return ""; } }
public Uri scanSingleFile(String path, String mimeType) { try { prescan(path); File file = new File(path); long lastModifiedSeconds = file.lastModified() / 1000; return mClient.doScanFile(path, lastModifiedSeconds, file.length(), true); } catch (RemoteException e) { Log.e("RemoteException in MediaScanner.scanFile()", e); return null; } }
public Crypto(String key) { try { SecretKeySpec skey = new SecretKeySpec(generateKey(key), "AES"); setupCrypto(skey); } catch (Exception e) { Log.e("Crypto", e); } }
private static Bitmap getMiniThumbFromFile(Cursor c, Uri baseUri, ContentResolver cr, BitmapFactory.Options options) { Bitmap bitmap = null; Uri thumbUri = null; try { long thumbId = c.getLong(0); thumbUri = ContentUris.withAppendedId(baseUri, thumbId); ParcelFileDescriptor pfdInput = cr.openFileDescriptor(thumbUri, "r"); bitmap = BitmapFactory.decodeFileDescriptor(pfdInput.getFileDescriptor(), null, options); pfdInput.close(); } catch (FileNotFoundException ex) { Log.e("getMiniThumbFromFile", ex); } catch (IOException ex) { Log.e("getMiniThumbFromFile", ex); } catch (OutOfMemoryError ex) { Log.e("getMiniThumbFromFile", ex); } return bitmap; }
private RandomAccessFile miniThumbDataFile() { if (mMiniThumbFile == null) { removeOldFile(); String path = randomAccessFilePath(MINI_THUMB_DATA_FILE_VERSION); File directory = new File(path).getParentFile(); if (!directory.isDirectory()) { if (!directory.mkdirs()) Log.e("Unable to create .thumbnails directory %s", directory.toString()); } File f = new File(path); try { mMiniThumbFile = new RandomAccessFile(f, "rw"); } catch (IOException ex) { try { mMiniThumbFile = new RandomAccessFile(f, "r"); } catch (IOException ex2) { } } if (mMiniThumbFile != null) mChannel = mMiniThumbFile.getChannel(); } return mMiniThumbFile; }
public Uri doScanFile(String path, long lastModified, long fileSize, boolean scanAlways) { Uri result = null; try { FileCacheEntry entry = beginFile(path, lastModified, fileSize); if (entry != null && (entry.mLastModifiedChanged || scanAlways)) { if (processFile(path, null)) { result = endFile(entry); } else { if (mCaseInsensitivePaths) mFileCache.remove(path.toLowerCase()); else mFileCache.remove(path); } } } catch (RemoteException e) { Log.e("RemoteException in MediaScanner.scanFile()", e); } return result; }
private static void postEventFromNative(Object mediaplayer_ref, int what, int arg1, int arg2, Object obj) { MediaPlayer mp = (MediaPlayer) (mediaplayer_ref); if (mp == null) return; try { //synchronized (mp.mEventHandler) { if (mp.mEventHandler != null) { Message m = mp.mEventHandler.obtainMessage(what, arg1, arg2, obj); mp.mEventHandler.sendMessage(m); } } catch (Exception e) { Log.e("exception: " + e); } }
private void updateSub(int subType, byte[] bytes, String encoding, int width, int height) { if (mEventHandler != null) { Message m = mEventHandler.obtainMessage(MEDIA_TIMED_TEXT, width, height); Bundle b = m.getData(); if (subType == SUBTITLE_TEXT) { b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_TEXT); if (encoding == null) { b.putString(MEDIA_SUBTITLE_STRING, new String(bytes)); } else { try { b.putString(MEDIA_SUBTITLE_STRING, new String(bytes, encoding.trim())); } catch (UnsupportedEncodingException e) { Log.e("updateSub", e); b.putString(MEDIA_SUBTITLE_STRING, new String(bytes)); } } } else if (subType == SUBTITLE_BITMAP) { b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_BITMAP); b.putByteArray(MEDIA_SUBTITLE_BYTES, bytes); } mEventHandler.sendMessage(m); } }
public void scanDirectories(String[] directories) { try { long start = System.currentTimeMillis(); prescan(null); long prescan = System.currentTimeMillis(); for (int i = 0; i < directories.length; i++) { if (!TextUtils.isEmpty(directories[i])) { directories[i] = ContextUtils.fixLastSlash(directories[i]); processDirectory(directories[i], MediaFile.sFileExtensions); } } long scan = System.currentTimeMillis(); postscan(directories); long end = System.currentTimeMillis(); Log.d(" prescan time: %dms", prescan - start); Log.d(" scan time: %dms", scan - prescan); Log.d("postscan time: %dms", end - scan); Log.d(" total time: %dms", end - start); } catch (SQLException e) { Log.e("SQLException in MediaScanner.scan()", e); } catch (UnsupportedOperationException e) { Log.e("UnsupportedOperationException in MediaScanner.scan()", e); } catch (RemoteException e) { Log.e("RemoteException in MediaScanner.scan()", e); } }
public int audioTrackInit() { // Log.e(" ffff mediaplayer audiotrackinit start . sampleRateInHz:=" + sampleRateInHz + " channels:=" + channels ); audioTrackRelease(); int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO; try { mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT); mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM); } catch (Exception e) { mAudioTrackBufferSize = 0; Log.e("audioTrackInit", e); } return mAudioTrackBufferSize; }
private void surfaceRender() { synchronized (this) { if (mLocalSurface == null || !mLocalSurface.isValid() || mBitmap == null || mByteBuffer == null) return; try { Canvas c = mLocalSurface.lockCanvas(null); mBitmap.copyPixelsFromBuffer(mByteBuffer); c.drawBitmap(mBitmap, 0, 0, null); mLocalSurface.unlockCanvasAndPost(c); } catch (Exception e) { Log.e("surfaceRender", e); } } }
@Override public boolean onInfo(MediaPlayer mp, int what, int extra) { Log.d("onInfo: (%d, %d)", what, extra); if(MediaPlayer.MEDIA_INFO_UNKNOW_TYPE == what){ Log.e(" VITAMIO--TYPE_CHECK stype not include onInfo mediaplayer unknow type "); } if(MediaPlayer.MEDIA_INFO_FILE_OPEN_OK == what){ long buffersize=mMediaPlayer.audioTrackInit(); mMediaPlayer.audioInitedOk(buffersize); } Log.d("onInfo: (%d, %d)", what, extra); if (mOnInfoListener != null) { mOnInfoListener.onInfo(mp, what, extra); } else if (mMediaPlayer != null) { if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) { mMediaPlayer.pause(); if (mMediaBufferingIndicator != null) mMediaBufferingIndicator.setVisibility(View.VISIBLE); } else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) { mMediaPlayer.start(); if (mMediaBufferingIndicator != null) mMediaBufferingIndicator.setVisibility(View.GONE); } } return true; } };