1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-02-02 17:56:56 +01:00

removed unused classes

This commit is contained in:
Mariotaku Lee 2015-06-19 00:14:59 +08:00
parent 456e7ff1c5
commit 630c6709e2
10 changed files with 41 additions and 162 deletions

View File

@ -556,23 +556,6 @@
</intent-filter>
</receiver>
<!-- Begin third Party components -->
<!-- SPICE -->
<service android:name="edu.tsinghua.spice.SpiceService"/>
<receiver
android:name="edu.tsinghua.spice.SpiceUploadReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE"/>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
<action android:name="edu.tsinghua.spice.UPLOAD_PROFILE"/>
</intent-filter>
</receiver>
<!-- Begin third Party components -->
</application>
</manifest>

View File

@ -1,70 +0,0 @@
package edu.tsinghua.spice;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import edu.tsinghua.spice.Utilies.NetworkStateUtil;
import edu.tsinghua.spice.Utilies.SpiceProfilingUtil;
/**
* Created by Denny C. Ng on 2/20/15.
* <p/>
* Request location ONCE per WAKE_PERIOD_IN_MILLI.
*/
public class SpiceService extends Service {
private AlarmManager mAlarmManager;
private PendingIntent mUploadIntent;
@Override
public IBinder onBind(final Intent intent) {
throw new IllegalStateException("Not implemented.");
}
@Override
public void onCreate() {
super.onCreate();
SpiceProfilingUtil.log("onCreate");
mAlarmManager = (AlarmManager) getSystemService(Service.ALARM_SERVICE);
IntentFilter screenFilter = new IntentFilter();
screenFilter.addAction(Intent.ACTION_SCREEN_ON);
screenFilter.addAction(Intent.ACTION_SCREEN_OFF);
registerReceiver(mScreenReceiver, screenFilter);
// Upload Service
final Intent uploadIntent = new Intent(SpiceUploadReceiver.ACTION_UPLOAD_PROFILE);
mUploadIntent = PendingIntent.getBroadcast(this, 0, uploadIntent, 0);
mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 12 * 60 * 60 * 1000, mUploadIntent);
}
@Override
public void onDestroy() {
mAlarmManager.cancel(mUploadIntent);
unregisterReceiver(mScreenReceiver);
super.onDestroy();
}
private BroadcastReceiver mScreenReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_SCREEN_ON)) {
SpiceProfilingUtil.profile(context, SpiceProfilingUtil.FILE_NAME_SCREEN, "SCREEN ON" + "," + NetworkStateUtil.getConnectedType(context));
SpiceProfilingUtil.log("SCREEN ON" + "," + NetworkStateUtil.getConnectedType(context));
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
SpiceProfilingUtil.profile(context, SpiceProfilingUtil.FILE_NAME_SCREEN, "SCREEN OFF" + "," + NetworkStateUtil.getConnectedType(context));
SpiceProfilingUtil.log("SCREEN OFF" + "," + NetworkStateUtil.getConnectedType(context));
}
}
};
}

View File

@ -1,30 +0,0 @@
package edu.tsinghua.spice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import org.mariotaku.twidere.util.Utils;
import edu.tsinghua.spice.Task.SpiceAsyUploadTask;
import edu.tsinghua.spice.Utilies.SpiceProfilingUtil;
/**
* Created by Denny C. Ng on 2/20/15.
*/
public class SpiceUploadReceiver extends BroadcastReceiver {
public static final String ACTION_UPLOAD_PROFILE = "edu.tsinghua.spice.UPLOAD_PROFILE";
@Override
public void onReceive(final Context context, final Intent intent) {
final String action = intent.getAction();
final boolean isWifi = Utils.isOnWifi(context.getApplicationContext());
final boolean isCharging = SpiceProfilingUtil.isCharging(context.getApplicationContext());
if (isWifi && isCharging) {
new SpiceAsyUploadTask(context).execute();
}
}
}

View File

@ -8,9 +8,11 @@ import android.util.Log;
import org.mariotaku.restfu.annotation.method.POST;
import org.mariotaku.restfu.http.RestHttpClient;
import org.mariotaku.restfu.http.RestHttpRequest;
import org.mariotaku.restfu.http.RestHttpResponse;
import org.mariotaku.restfu.http.mime.FileTypedData;
import org.mariotaku.restfu.http.mime.MultipartTypedBody;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import java.io.File;
@ -20,20 +22,18 @@ import java.io.IOException;
import edu.tsinghua.spice.Utilies.SpiceProfilingUtil;
import static org.mariotaku.twidere.TwidereConstants.LOGTAG;
import static org.mariotaku.twidere.util.Utils.copyStream;
/**
* Created by Denny C. Ng on 2/20/15.
*/
public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> {
public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> implements Constants {
public static final long UPLOAD_INTERVAL_MILLIS = 1000 * 60 * 60 * 24;
private static final String PROFILE_SERVER_URL = "http://spice.hot-mobile.org/spice/usage";
private static final String LAST_UPLOAD_DATE = "last_upload_time";
private static final double MILLSECS_HALF_DAY = 1000 * 60 * 60 * 12;
private final Context context;
private final RestHttpClient client;
@ -65,9 +65,12 @@ public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> {
final MultipartTypedBody body = new MultipartTypedBody();
body.add("file", new FileTypedData(tmp));
builder.body(body);
client.execute(builder.build());
SpiceProfilingUtil.log("server has already received file " + tmp.getName());
tmp.delete();
final RestHttpResponse response = client.execute(builder.build());
if (response.isSuccessful()) {
SpiceProfilingUtil.log("server has already received file " + tmp.getName());
tmp.delete();
}
throw new IOException("Unable to send file");
} catch (Exception e) {
if (BuildConfig.DEBUG) {
Log.w(LOGTAG, e);
@ -84,9 +87,9 @@ public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> {
final SharedPreferences prefs = context.getSharedPreferences("spice_data_profiling", Context.MODE_PRIVATE);
if (prefs.contains(LAST_UPLOAD_DATE)) {
final long lastUpload = prefs.getLong(LAST_UPLOAD_DATE, System.currentTimeMillis());
final double deltaDays = (System.currentTimeMillis() - lastUpload) / (MILLSECS_HALF_DAY * 2);
if (prefs.contains(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD)) {
final long lastUpload = prefs.getLong(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD, System.currentTimeMillis());
final double deltaDays = (System.currentTimeMillis() - lastUpload) / UPLOAD_INTERVAL_MILLIS;
if (deltaDays < 1) {
SpiceProfilingUtil.log("Last uploaded was conducted in 1 day ago.");
return null;
@ -96,7 +99,7 @@ public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> {
final File root = context.getFilesDir();
final File[] spiceFiles = root.listFiles(new SpiceFileFilter());
uploadToServer(spiceFiles);
prefs.edit().putLong(LAST_UPLOAD_DATE, System.currentTimeMillis()).apply();
prefs.edit().putLong(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD, System.currentTimeMillis()).apply();
return null;
}

View File

@ -177,6 +177,8 @@ public interface Constants extends TwidereConstants {
// SharedPreferences constants
@Preference(type = BOOLEAN, exportable = false)
String KEY_USAGE_STATISTICS = "usage_statistics";
@Preference(type = BOOLEAN, exportable = false)
String KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD = "usage_statistics_last_successful_upload";
@Preference(type = STRING, exportable = false)
String KEY_DEVICE_SERIAL = "device_serial";
}

View File

@ -73,13 +73,10 @@ import org.mariotaku.twidere.util.net.TwidereHostAddressResolver;
import java.io.File;
import edu.tsinghua.spice.SpiceService;
import static org.mariotaku.twidere.util.Utils.getBestCacheDir;
import static org.mariotaku.twidere.util.Utils.getInternalCacheDir;
import static org.mariotaku.twidere.util.Utils.initAccountColor;
import static org.mariotaku.twidere.util.Utils.startRefreshServiceIfNeeded;
import static org.mariotaku.twidere.util.Utils.startUsageStatisticsServiceIfNeeded;
@ReportsCrashes(formUri = "https://mariotaku.cloudant.com/acra-twidere/_design/acra-storage/_update/report",
reportType = HttpSender.Type.JSON,
@ -264,7 +261,6 @@ public class TwidereApplication extends MultiDexApplication implements Constants
}
migrateUsageStatisticsPreferences();
startUsageStatisticsServiceIfNeeded(this);
startRefreshServiceIfNeeded(this);
reloadConnectivitySettings();
@ -317,11 +313,6 @@ public class TwidereApplication extends MultiDexApplication implements Constants
} else if (KEY_ENABLE_PROXY.equals(key) || KEY_CONNECTION_TIMEOUT.equals(key) || KEY_PROXY_HOST.equals(key)
|| KEY_PROXY_PORT.equals(key)) {
reloadConnectivitySettings();
} else if (KEY_USAGE_STATISTICS.equals(key)) {
//spice
stopService(new Intent(this, SpiceService.class));
startUsageStatisticsServiceIfNeeded(this);
//end
} else if (KEY_CONSUMER_KEY.equals(key) || KEY_CONSUMER_SECRET.equals(key) || KEY_API_URL_FORMAT.equals(key)
|| KEY_AUTH_TYPE.equals(key) || KEY_SAME_OAUTH_SIGNING_URL.equals(key) || KEY_THUMBOR_ENABLED.equals(key)
|| KEY_THUMBOR_ADDRESS.equals(key) || KEY_THUMBOR_SECURITY_KEY.equals(key)) {

View File

@ -29,13 +29,14 @@ import android.util.Log;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.util.AsyncTaskUtils;
import org.mariotaku.twidere.util.Utils;
import edu.tsinghua.spice.Task.SpiceAsyUploadTask;
import edu.tsinghua.spice.Utilies.NetworkStateUtil;
import edu.tsinghua.spice.Utilies.SpiceProfilingUtil;
import static org.mariotaku.twidere.util.Utils.startRefreshServiceIfNeeded;
import static org.mariotaku.twidere.util.Utils.startUsageStatisticsServiceIfNeeded;
public class ConnectivityStateReceiver extends BroadcastReceiver implements Constants {
@ -47,7 +48,6 @@ public class ConnectivityStateReceiver extends BroadcastReceiver implements Cons
Log.d(RECEIVER_LOGTAG, String.format("Received Broadcast %s", intent));
}
if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) return;
startUsageStatisticsServiceIfNeeded(context);
startRefreshServiceIfNeeded(context);
final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME,
Context.MODE_PRIVATE);
@ -60,5 +60,12 @@ public class ConnectivityStateReceiver extends BroadcastReceiver implements Cons
+ location.getLatitude() + "," + location.getLongitude() + "," + location.getProvider());
}
}
final boolean isWifi = Utils.isOnWifi(context.getApplicationContext());
final boolean isCharging = SpiceProfilingUtil.isCharging(context.getApplicationContext());
final long currentTime = System.currentTimeMillis();
final long lastSuccessfulTime = prefs.getLong(KEY_USAGE_STATISTICS_LAST_SUCCESSFUL_UPLOAD, -1);
if (isWifi && isCharging && (currentTime - lastSuccessfulTime) > SpiceAsyUploadTask.UPLOAD_INTERVAL_MILLIS) {
AsyncTaskUtils.executeTask(new SpiceAsyUploadTask(context));
}
}
}

View File

@ -256,8 +256,6 @@ import java.util.zip.CRC32;
import javax.net.ssl.SSLException;
import edu.tsinghua.spice.SpiceService;
import static android.text.TextUtils.isEmpty;
import static android.text.format.DateUtils.getRelativeTimeSpanString;
import static org.mariotaku.twidere.provider.TwidereDataStore.CACHE_URIS;
@ -3420,19 +3418,6 @@ public final class Utils implements Constants {
showWarnMessage(context, context.getText(resId), long_message);
}
public static void startUsageStatisticsServiceIfNeeded(final Context context) {
final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
//spice
final Intent spiceProfilingServiceIntent = new Intent(context, SpiceService.class);
if (prefs.getBoolean(KEY_USAGE_STATISTICS, false)) {
//spice
context.startService(spiceProfilingServiceIntent);
} else {
//spice
context.stopService(spiceProfilingServiceIntent);
}
}
public static void startRefreshServiceIfNeeded(final Context context) {
final Intent refreshServiceIntent = new Intent(context, RefreshService.class);
AsyncTask.execute(new Runnable() {

View File

@ -23,16 +23,20 @@
<Preference android:layout="@layout/header_usage_statistics"/>
<org.mariotaku.twidere.preference.AutoFixCheckBoxPreference
android:order="11"
android:defaultValue="false"
android:title="@string/usage_statistics"
android:key="usage_statistics"/>
android:key="usage_statistics"
android:order="11"
android:title="@string/usage_statistics"/>
<PreferenceCategory
android:title="@string/projects_we_took_part"
android:order="12">
android:order="12"
android:title="@string/projects_we_took_part">
<Preference
android:title="@string/research_tsinghua_hot_mobile"/>
android:title="@string/research_tsinghua_hot_mobile">
<intent
android:action="android.intent.action.VIEW"
android:data="http://spice.hot-mobile.org/"/>
</Preference>
</PreferenceCategory>
</PreferenceScreen>

View File

@ -24,6 +24,10 @@
<org.mariotaku.twidere.preference.ForegroundColorIconPreference
android:order="11"
android:title="@string/research_tsinghua_hot_mobile"/>
android:title="@string/research_tsinghua_hot_mobile">
<intent
android:action="android.intent.action.VIEW"
android:data="http://spice.hot-mobile.org/"/>
</org.mariotaku.twidere.preference.ForegroundColorIconPreference>
</PreferenceScreen>