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);
}
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);
}
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);
}
}
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;
}
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;
}
Aggregations