/** * Base64-encode the given data and return a newly allocated * byte[] with the result. * * @param input the data to encode * @param flags controls certain features of the encoded output. * Passing {@code DEFAULT} results in output that * adheres to RFC 2045. */ public static byte[] encode(byte[] input, int flags) { return encode(input, 0, input.length, flags); }
/** * Gets the resolution, * @return a pair to return the width and height * */ public static Pair<Integer,Integer> getResolution(Context ctx){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { return getRealResolution(ctx); } else { return getRealResolutionOnOldDevice(ctx); } }
public static String getFeatureString() { getFeature(); return cachedFeatureString; }
public static String getDeviceFeatures(Context ctx) { return getIdentifiers(ctx) + getSystemFeatures() + getScreenFeatures(ctx); }
public Crypto(String key) { try { SecretKeySpec skey = new SecretKeySpec(generateKey(key), "AES"); setupCrypto(skey); } catch (Exception e) { Log.e("Crypto", e); } }
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 static String getSystemFeatures() { StringBuilder sb = new StringBuilder(); sb.append(getPair("android_release", Build.VERSION.RELEASE)); sb.append(getPair("android_sdk_int", "" + Build.VERSION.SDK_INT)); sb.append(getPair("device_cpu_abi", Build.CPU_ABI)); sb.append(getPair("device_model", Build.MODEL)); sb.append(getPair("device_manufacturer", Build.MANUFACTURER)); sb.append(getPair("device_board", Build.BOARD)); sb.append(getPair("device_fingerprint", Build.FINGERPRINT)); sb.append(getPair("device_cpu_feature", CPU.getFeatureString())); return sb.toString(); }
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 ""; } }
@Override public void onTimedTextUpdate(byte[] pixels, int width, int height) { Log.i("onSubtitleUpdate: bitmap subtitle, %dx%d", width, height); if (mOnTimedTextListener != null) mOnTimedTextListener.onTimedTextUpdate(pixels, width, height); }
@Override public void onSeekComplete(MediaPlayer mp) { Log.d("onSeekComplete"); if (mOnSeekCompleteListener != null) mOnSeekCompleteListener.onSeekComplete(mp); } };
/** * Decode the Base64-encoded data in input and return the data in * a new byte array. * * <p>The padding '=' characters at the end are considered optional, but * if any are present, there must be the correct number of them. * * @param input the input array to decode * @param flags controls certain features of the decoded output. * Pass {@code DEFAULT} to decode standard Base64. * * @throws IllegalArgumentException if the input contains * incorrect padding */ public static byte[] decode(byte[] input, int flags) { return decode(input, 0, input.length, flags); }
public static String getDataDir(Context ctx) { ApplicationInfo ai = ctx.getApplicationInfo(); if (ai.dataDir != null) return fixLastSlash(ai.dataDir); else return "/data/data/" + ai.packageName + "/"; }
/** * Check if Vitamio is initialized at this device * * @param ctx Android Context * @return true if the Vitamio has been initialized. */ public static boolean isInitialized(Context ctx) { vitamioPackage = ctx.getPackageName(); vitamioLibraryPath = ContextUtils.getDataDir(ctx) + "lib/"; return true; }
public String rsaEncrypt(InputStream keyStream, String data) { try { return rsaEncrypt(keyStream, data.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { return ""; } }
public static String getName(String uri) { String path = getPath(uri); if (path != null) return new File(path).getName(); return null; }
public static void deleteDir(File f) { if (f.exists() && f.isDirectory()) { for (File file : f.listFiles()) { if (file.isDirectory()) deleteDir(file); file.delete(); } f.delete(); } } }
private void closeFD() { if (mFD != null) { try { mFD.close(); } catch (IOException e) { Log.e("closeFD", e); } mFD = null; } }
public void setMimeType(String mimeType) { Log.i("setMimeType: %s", mimeType); mMimeType = mimeType; mFileType = MediaFile.getFileTypeForMimeType(mimeType); }
public void suspend() { if (isInPlaybackState()) { release(false); mCurrentState = STATE_SUSPEND_UNSUPPORTED; Log.d("Unable to suspend video. Release MediaPlayer."); } }
@Override public void onTimedText(String text) { Log.i("onSubtitleUpdate: %s", text); if (mOnTimedTextListener != null) mOnTimedTextListener.onTimedText(text); } };