Search in sources :

Example 46 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class SystemDownloadNotifier method startService.

/**
     * Starts and binds to the download notification service.
     */
@VisibleForTesting
void startService() {
    assert Thread.holdsLock(mLock);
    mApplicationContext.startService(new Intent(mApplicationContext, DownloadNotificationService.class));
    mApplicationContext.bindService(new Intent(mApplicationContext, DownloadNotificationService.class), mConnection, Context.BIND_AUTO_CREATE);
}
Also used : Intent(android.content.Intent) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 47 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class IncognitoNotificationService method getRemoveAllIncognitoTabsIntent.

@VisibleForTesting
public static PendingIntent getRemoveAllIncognitoTabsIntent(Context context) {
    Intent intent = new Intent(context, IncognitoNotificationService.class);
    intent.setAction(ACTION_CLOSE_ALL_INCOGNITO);
    return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 48 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class CastMessageHandler method onAppMessage.

/**
     * Forwards the application specific message to the page via the media router.
     * @param message The message within the namespace that's being sent by the receiver.
     * @param namespace The application specific namespace this message belongs to.
     * @param request The information about the client and the sequence number to respond with.
     */
@VisibleForTesting
void onAppMessage(String message, String namespace, RequestRecord request) {
    try {
        JSONObject jsonMessage = new JSONObject();
        jsonMessage.put("sessionId", mSession.getSessionId());
        jsonMessage.put("namespaceName", namespace);
        jsonMessage.put("message", message);
        if (request != null) {
            sendClientMessageTo(request.clientId, "app_message", jsonMessage.toString(), request.sequenceNumber);
        } else {
            broadcastClientMessage("app_message", jsonMessage.toString());
        }
    } catch (JSONException e) {
        Log.e(TAG, "Failed to create the message wrapper", e);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 49 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class CastMessageHandler method handleCastV2Message.

// An example of the Cast V2 message:
//    {
//        "type": "v2_message",
//        "message": {
//          "type": "...",
//          ...
//        },
//        "sequenceNumber": 0,
//        "timeoutMillis": 0,
//        "clientId": "144042901280235697"
//    }
@VisibleForTesting
boolean handleCastV2Message(JSONObject jsonMessage) throws JSONException {
    assert "v2_message".equals(jsonMessage.getString("type"));
    final String clientId = jsonMessage.getString("clientId");
    if (clientId == null || !mRouteProvider.getClients().contains(clientId))
        return false;
    JSONObject jsonCastMessage = jsonMessage.getJSONObject("message");
    String messageType = jsonCastMessage.getString("type");
    final int sequenceNumber = jsonMessage.optInt("sequenceNumber", INVALID_SEQUENCE_NUMBER);
    if ("STOP".equals(messageType)) {
        handleStopMessage(clientId, sequenceNumber);
        return true;
    }
    if ("SET_VOLUME".equals(messageType)) {
        CastSession.HandleVolumeMessageResult result = mSession.handleVolumeMessage(jsonCastMessage.getJSONObject("volume"), clientId, sequenceNumber);
        if (!result.mSucceeded)
            return false;
        // when the status update is received so we respond to the volume message immediately.
        if (result.mShouldWaitForVolumeChange) {
            mVolumeRequests.add(new RequestRecord(clientId, sequenceNumber));
        } else {
            // It's usually bad to have request and response on the same call stack so post the
            // response to the Android message loop.
            mHandler.post(new Runnable() {

                @Override
                public void run() {
                    onVolumeChanged(clientId, sequenceNumber);
                }
            });
        }
        return true;
    }
    if (Arrays.asList(MEDIA_MESSAGE_TYPES).contains(messageType)) {
        if (sMediaOverloadedMessageTypes.containsKey(messageType)) {
            messageType = sMediaOverloadedMessageTypes.get(messageType);
            jsonCastMessage.put("type", messageType);
        }
        return sendJsonCastMessage(jsonCastMessage, MEDIA_NAMESPACE, clientId, sequenceNumber);
    }
    return true;
}
Also used : JSONObject(org.json.JSONObject) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 50 with VisibleForTesting

use of org.chromium.base.VisibleForTesting in project AndroidChromium by JackyAndroid.

the class OfflinePageUtils method copyToShareableLocation.

/**
     * Copies the file from internal storage to a sharable directory.
     * @param src The original file to be copied.
     * @param dst The destination file.
     */
@VisibleForTesting
static boolean copyToShareableLocation(File src, File dst) {
    FileInputStream inputStream = null;
    FileOutputStream outputStream = null;
    try {
        inputStream = new FileInputStream(src);
        outputStream = new FileOutputStream(dst);
        FileChannel inChannel = inputStream.getChannel();
        FileChannel outChannel = outputStream.getChannel();
        inChannel.transferTo(0, inChannel.size(), outChannel);
    } catch (IOException e) {
        Log.e(TAG, "Failed to copy the file: " + src.getName(), e);
        return false;
    } finally {
        StreamUtil.closeQuietly(inputStream);
        StreamUtil.closeQuietly(outputStream);
    }
    return true;
}
Also used : FileChannel(java.nio.channels.FileChannel) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) VisibleForTesting(org.chromium.base.VisibleForTesting)

Aggregations

VisibleForTesting (org.chromium.base.VisibleForTesting)52 Intent (android.content.Intent)6 IOException (java.io.IOException)6 SharedPreferences (android.content.SharedPreferences)5 JSONObject (org.json.JSONObject)4 PendingIntent (android.app.PendingIntent)3 SpannableString (android.text.SpannableString)3 BufferedReader (java.io.BufferedReader)3 Matcher (java.util.regex.Matcher)3 CalledByNative (org.chromium.base.annotations.CalledByNative)3 AccountManagerHelper (org.chromium.components.signin.AccountManagerHelper)3 SpanInfo (org.chromium.ui.text.SpanApplier.SpanInfo)3 SuppressLint (android.annotation.SuppressLint)2 IntentFilter (android.content.IntentFilter)2 Paint (android.graphics.Paint)2 File (java.io.File)2 FileReader (java.io.FileReader)2 HttpURLConnection (java.net.HttpURLConnection)2 ArrayList (java.util.ArrayList)2 Formatter (java.util.Formatter)2