2012-08-05 06:26:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2012-08-05 06:26:35 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-08-05 06:26:35 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2012-08-05 06:26:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.research;
|
|
|
|
|
|
|
|
import android.app.AlarmManager;
|
|
|
|
import android.app.IntentService;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
2012-12-19 19:27:51 +00:00
|
|
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
2012-08-05 06:26:35 +00:00
|
|
|
|
2013-02-27 20:50:11 +00:00
|
|
|
/**
|
|
|
|
* Service to invoke the uploader.
|
|
|
|
*
|
|
|
|
* Can be regularly invoked, invoked on boot, etc.
|
|
|
|
*/
|
2012-08-05 06:26:35 +00:00
|
|
|
public final class UploaderService extends IntentService {
|
|
|
|
private static final String TAG = UploaderService.class.getSimpleName();
|
2013-03-18 09:21:18 +00:00
|
|
|
private static final boolean DEBUG = false
|
|
|
|
&& ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS_DEBUG;
|
2012-08-05 06:26:35 +00:00
|
|
|
public static final long RUN_INTERVAL = AlarmManager.INTERVAL_HOUR;
|
2013-01-22 01:12:44 +00:00
|
|
|
public static final String EXTRA_UPLOAD_UNCONDITIONALLY = UploaderService.class.getName()
|
2012-08-05 06:26:35 +00:00
|
|
|
+ ".extra.UPLOAD_UNCONDITIONALLY";
|
|
|
|
protected static final int TIMEOUT_IN_MS = 1000 * 4;
|
|
|
|
|
|
|
|
public UploaderService() {
|
|
|
|
super("Research Uploader Service");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-02-27 20:50:11 +00:00
|
|
|
protected void onHandleIntent(final Intent intent) {
|
|
|
|
final Uploader uploader = new Uploader(this);
|
|
|
|
if (!uploader.isPossibleToUpload()) return;
|
|
|
|
if (isUploadingUnconditionally(intent.getExtras()) || uploader.isConvenientToUpload()) {
|
|
|
|
uploader.doUpload();
|
2013-02-27 20:32:39 +00:00
|
|
|
}
|
2013-02-27 20:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isUploadingUnconditionally(final Bundle bundle) {
|
|
|
|
if (bundle == null) return false;
|
|
|
|
if (bundle.containsKey(EXTRA_UPLOAD_UNCONDITIONALLY)) {
|
|
|
|
return bundle.getBoolean(EXTRA_UPLOAD_UNCONDITIONALLY);
|
2012-08-05 06:26:35 +00:00
|
|
|
}
|
2013-02-27 20:17:49 +00:00
|
|
|
return false;
|
2012-08-05 06:26:35 +00:00
|
|
|
}
|
|
|
|
}
|