Search in sources :

Example 16 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class MediaResourceGetter method extractMediaMetadata.

@CalledByNative
private static MediaMetadata extractMediaMetadata(Context context, String url, String cookies) {
    int durationInMilliseconds = 0;
    int width = 0;
    int height = 0;
    boolean success = false;
    // TODO(qinmin): use ConnectionTypeObserver to listen to the network type change.
    ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (mConnectivityManager != null) {
        NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
        if (info == null) {
            return new MediaMetadata(durationInMilliseconds, width, height, success);
        }
        switch(info.getType()) {
            case ConnectivityManager.TYPE_ETHERNET:
            case ConnectivityManager.TYPE_WIFI:
                break;
            case ConnectivityManager.TYPE_WIMAX:
            case ConnectivityManager.TYPE_MOBILE:
            default:
                return new MediaMetadata(durationInMilliseconds, width, height, success);
        }
    }
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
        Uri uri = Uri.parse(url);
        String scheme = uri.getScheme();
        if (scheme == null || scheme.equals("file")) {
            File file = new File(uri.getPath());
            String path = file.getAbsolutePath();
            if (file.exists() && (path.startsWith("/mnt/sdcard/") || path.startsWith("/sdcard/") || path.startsWith(PathUtils.getExternalStorageDirectory()))) {
                retriever.setDataSource(path);
            } else {
                Log.e(TAG, "Unable to read file: " + url);
                return new MediaMetadata(durationInMilliseconds, width, height, success);
            }
        } else {
            HashMap<String, String> headersMap = new HashMap<String, String>();
            if (!TextUtils.isEmpty(cookies)) {
                headersMap.put("Cookie", cookies);
            }
            retriever.setDataSource(url, headersMap);
        }
        durationInMilliseconds = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
        width = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH));
        height = Integer.parseInt(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
        success = true;
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Invalid url: " + e);
    } catch (RuntimeException e) {
        Log.e(TAG, "Invalid url: " + e);
    }
    return new MediaMetadata(durationInMilliseconds, width, height, success);
}
Also used : NetworkInfo(android.net.NetworkInfo) HashMap(java.util.HashMap) ConnectivityManager(android.net.ConnectivityManager) Uri(android.net.Uri) MediaMetadataRetriever(android.media.MediaMetadataRetriever) File(java.io.File) CalledByNative(org.chromium.base.CalledByNative)

Example 17 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class AwContentsClientBridge method allowCertificateError.

// If returns false, the request is immediately canceled, and any call to proceedSslError
// has no effect. If returns true, the request should be canceled or proceeded using
// proceedSslError().
// Unlike the webview classic, we do not keep keep a database of certificates that
// are allowed by the user, because this functionality is already handled via
// ssl_policy in native layers.
@CalledByNative
private boolean allowCertificateError(int certError, byte[] derBytes, final String url, final int id) {
    final SslCertificate cert = SslUtil.getCertificateFromDerBytes(derBytes);
    if (cert == null) {
        // if the certificate or the client is null, cancel the request
        return false;
    }
    final SslError sslError = SslUtil.sslErrorFromNetErrorCode(certError, cert, url);
    ValueCallback<Boolean> callback = new ValueCallback<Boolean>() {

        @Override
        public void onReceiveValue(Boolean value) {
            proceedSslError(value.booleanValue(), id);
        }
    };
    mClient.onReceivedSslError(callback, sslError);
    return true;
}
Also used : ValueCallback(android.webkit.ValueCallback) SslCertificate(android.net.http.SslCertificate) SslError(android.net.http.SslError) CalledByNative(org.chromium.base.CalledByNative)

Example 18 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class BuildInfo method getPackageLabel.

@CalledByNative
public static String getPackageLabel(Context context) {
    try {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
        CharSequence label = packageManager.getApplicationLabel(appInfo);
        return label != null ? label.toString() : "";
    } catch (NameNotFoundException e) {
        return "";
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) CalledByNative(org.chromium.base.CalledByNative)

Example 19 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class MediaPlayerBridge method getAllowedOperations.

/**
 * Returns an AllowedOperations object to show all the operations that are
 * allowed on the media player.
 */
@CalledByNative
private static AllowedOperations getAllowedOperations(MediaPlayer player) {
    boolean canPause = true;
    boolean canSeekForward = true;
    boolean canSeekBackward = true;
    try {
        Method getMetadata = player.getClass().getDeclaredMethod("getMetadata", boolean.class, boolean.class);
        getMetadata.setAccessible(true);
        Object data = getMetadata.invoke(player, false, false);
        if (data != null) {
            Class<?> metadataClass = data.getClass();
            Method hasMethod = metadataClass.getDeclaredMethod("has", int.class);
            Method getBooleanMethod = metadataClass.getDeclaredMethod("getBoolean", int.class);
            int pause = (Integer) metadataClass.getField("PAUSE_AVAILABLE").get(null);
            int seekForward = (Integer) metadataClass.getField("SEEK_FORWARD_AVAILABLE").get(null);
            int seekBackward = (Integer) metadataClass.getField("SEEK_BACKWARD_AVAILABLE").get(null);
            hasMethod.setAccessible(true);
            getBooleanMethod.setAccessible(true);
            canPause = !((Boolean) hasMethod.invoke(data, pause)) || ((Boolean) getBooleanMethod.invoke(data, pause));
            canSeekForward = !((Boolean) hasMethod.invoke(data, seekForward)) || ((Boolean) getBooleanMethod.invoke(data, seekForward));
            canSeekBackward = !((Boolean) hasMethod.invoke(data, seekBackward)) || ((Boolean) getBooleanMethod.invoke(data, seekBackward));
        }
    } catch (NoSuchMethodException e) {
        Log.e(TAG, "Cannot find getMetadata() method: " + e);
    } catch (InvocationTargetException e) {
        Log.e(TAG, "Cannot invoke MediaPlayer.getMetadata() method: " + e);
    } catch (IllegalAccessException e) {
        Log.e(TAG, "Cannot access metadata: " + e);
    } catch (NoSuchFieldException e) {
        Log.e(TAG, "Cannot find matching fields in Metadata class: " + e);
    }
    return new AllowedOperations(canPause, canSeekForward, canSeekBackward);
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) CalledByNative(org.chromium.base.CalledByNative)

Example 20 with CalledByNative

use of org.chromium.base.CalledByNative in project chromeview by pwnall.

the class AndroidKeyStore method rawSignDigestWithPrivateKey.

/**
 * Sign a given message with a given PrivateKey object. This method
 * shall only be used to implement signing in the context of SSL
 * client certificate support.
 *
 * The message will actually be a hash, computed and padded by OpenSSL,
 * itself, depending on the type of the key. The result should match
 * exactly what the vanilla implementations of the following OpenSSL
 * function calls do:
 *
 *  - For a RSA private key, this should be equivalent to calling
 *    RSA_sign(NDI_md5_sha1,....), i.e. it must generate a raw RSA
 *    signature. The message must a combined, 36-byte MD5+SHA1 message
 *    digest padded to the length of the modulus using PKCS#1 padding.
 *
 *  - For a DSA and ECDSA private keys, this should be equivalent to
 *    calling DSA_sign(0,...) and ECDSA_sign(0,...) respectively. The
 *    message must be a 20-byte SHA1 hash and the function shall
 *    compute a direct DSA/ECDSA signature for it.
 *
 * @param privateKey The PrivateKey handle.
 * @param message The message to sign.
 * @return signature as a byte buffer.
 *
 * Important: Due to a platform bug, this function will always fail on
 *            Android < 4.2 for RSA PrivateKey objects. See the
 *            getOpenSSLHandleForPrivateKey() below for work-around.
 */
@CalledByNative
public static byte[] rawSignDigestWithPrivateKey(PrivateKey privateKey, byte[] message) {
    // Get the Signature for this key.
    Signature signature = null;
    // http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html
    try {
        if (privateKey instanceof RSAPrivateKey) {
            // IMPORTANT: Due to a platform bug, this will throw NoSuchAlgorithmException
            // on Android 4.0.x and 4.1.x. Fixed in 4.2 and higher.
            // See https://android-review.googlesource.com/#/c/40352/
            signature = Signature.getInstance("NONEwithRSA");
        } else if (privateKey instanceof DSAPrivateKey) {
            signature = Signature.getInstance("NONEwithDSA");
        } else if (privateKey instanceof ECPrivateKey) {
            signature = Signature.getInstance("NONEwithECDSA");
        }
    } catch (NoSuchAlgorithmException e) {
        ;
    }
    if (signature == null) {
        Log.e(TAG, "Unsupported private key algorithm: " + privateKey.getAlgorithm());
        return null;
    }
    // Sign the message.
    try {
        signature.initSign(privateKey);
        signature.update(message);
        return signature.sign();
    } catch (Exception e) {
        Log.e(TAG, "Exception while signing message with " + privateKey.getAlgorithm() + " private key: " + e);
        return null;
    }
}
Also used : ECPrivateKey(java.security.interfaces.ECPrivateKey) Signature(java.security.Signature) DSAPrivateKey(java.security.interfaces.DSAPrivateKey) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CalledByNative(org.chromium.base.CalledByNative)

Aggregations

CalledByNative (org.chromium.base.CalledByNative)24 Intent (android.content.Intent)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 PackageManager (android.content.pm.PackageManager)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 PackageInfo (android.content.pm.PackageInfo)2 SurfaceTexture (android.graphics.SurfaceTexture)2 Uri (android.net.Uri)2 Method (java.lang.reflect.Method)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)2 HashMap (java.util.HashMap)2 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 Resources (android.content.res.Resources)1 Canvas (android.graphics.Canvas)1 Picture (android.graphics.Picture)1