Skip to content
This repository was archived by the owner on Sep 6, 2020. It is now read-only.

added optional wakelock argument to websocket for use with background… #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/com/codebutler/android_websockets/HybiParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

package com.codebutler.android_websockets;

import android.os.PowerManager.WakeLock;
import android.util.Log;

import java.io.*;
Expand All @@ -40,6 +41,8 @@ public class HybiParser {
private static final String TAG = "HybiParser";

private WebSocketClient mClient;

private WakeLock mWakeLock;

private boolean mMasking = true;

Expand Down Expand Up @@ -95,7 +98,12 @@ public HybiParser(WebSocketClient client) {
mClient = client;
}

private static byte[] mask(byte[] payload, byte[] mask, int offset) {
public HybiParser(WebSocketClient webSocketClient, WakeLock wakelock) {
mWakeLock = wakelock;
mClient = webSocketClient;
}

private static byte[] mask(byte[] payload, byte[] mask, int offset) {
if (mask.length == 0) return payload;

for (int i = 0; i < payload.length - offset; i++) {
Expand Down Expand Up @@ -127,11 +135,19 @@ public void start(HappyDataInputStream stream) throws IOException {
mStage = 0;
break;
}
if(mWakeLock != null && mFinal) synchronized (mWakeLock) {
if(mWakeLock.isHeld())mWakeLock.release();
}
}
mClient.getListener().onDisconnect(0, "EOF");
}

private void parseOpcode(byte data) throws ProtocolError {

if(mWakeLock != null) synchronized (mWakeLock) {
mWakeLock.acquire();
}

boolean rsv1 = (data & RSV1) == RSV1;
boolean rsv2 = (data & RSV2) == RSV2;
boolean rsv3 = (data & RSV3) == RSV3;
Expand Down
Loading