am 18b01e88: Merge "[Rlog41] ResearchLogger debugging support in UploaderService"
* commit '18b01e88acda36185242fdfdfe15b42945d5e523': [Rlog41] ResearchLogger debugging support in UploaderServicemain
commit
38ba76b7d9
|
@ -46,9 +46,10 @@ import java.net.URL;
|
||||||
|
|
||||||
public final class UploaderService extends IntentService {
|
public final class UploaderService extends IntentService {
|
||||||
private static final String TAG = UploaderService.class.getSimpleName();
|
private static final String TAG = UploaderService.class.getSimpleName();
|
||||||
|
private static final boolean DEBUG = false && ProductionFlag.IS_EXPERIMENTAL_DEBUG;
|
||||||
// Set IS_INHIBITING_AUTO_UPLOAD to true for local testing
|
// Set IS_INHIBITING_AUTO_UPLOAD to true for local testing
|
||||||
private static final boolean IS_INHIBITING_AUTO_UPLOAD =
|
private static final boolean IS_INHIBITING_AUTO_UPLOAD = false
|
||||||
false && ProductionFlag.IS_EXPERIMENTAL_DEBUG; // Force false in production
|
&& ProductionFlag.IS_EXPERIMENTAL_DEBUG; // Force false in production
|
||||||
public static final long RUN_INTERVAL = AlarmManager.INTERVAL_HOUR;
|
public static final long RUN_INTERVAL = AlarmManager.INTERVAL_HOUR;
|
||||||
private static final String EXTRA_UPLOAD_UNCONDITIONALLY = UploaderService.class.getName()
|
private static final String EXTRA_UPLOAD_UNCONDITIONALLY = UploaderService.class.getName()
|
||||||
+ ".extra.UPLOAD_UNCONDITIONALLY";
|
+ ".extra.UPLOAD_UNCONDITIONALLY";
|
||||||
|
@ -146,7 +147,9 @@ public final class UploaderService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean uploadFile(File file) {
|
private boolean uploadFile(File file) {
|
||||||
Log.d(TAG, "attempting upload of " + file.getAbsolutePath());
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "attempting upload of " + file.getAbsolutePath());
|
||||||
|
}
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
final int contentLength = (int) file.length();
|
final int contentLength = (int) file.length();
|
||||||
HttpURLConnection connection = null;
|
HttpURLConnection connection = null;
|
||||||
|
@ -162,6 +165,9 @@ public final class UploaderService extends IntentService {
|
||||||
int numBytesRead;
|
int numBytesRead;
|
||||||
while ((numBytesRead = fileInputStream.read(buf)) != -1) {
|
while ((numBytesRead = fileInputStream.read(buf)) != -1) {
|
||||||
os.write(buf, 0, numBytesRead);
|
os.write(buf, 0, numBytesRead);
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, new String(buf));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||||
Log.d(TAG, "upload failed: " + connection.getResponseCode());
|
Log.d(TAG, "upload failed: " + connection.getResponseCode());
|
||||||
|
@ -176,7 +182,9 @@ public final class UploaderService extends IntentService {
|
||||||
}
|
}
|
||||||
file.delete();
|
file.delete();
|
||||||
success = true;
|
success = true;
|
||||||
Log.d(TAG, "upload successful");
|
if (DEBUG) {
|
||||||
|
Log.d(TAG, "upload successful");
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue