Replace 'Download' prefix with 'Updater'

These classes do more than controlling the download of the updates.
This commit is contained in:
Gabriele M
2017-07-04 19:05:04 +02:00
parent 21cc96f300
commit db3f14832a
6 changed files with 66 additions and 66 deletions

View File

@@ -28,7 +28,7 @@
</intent-filter>
</activity>
<service android:name=".controller.DownloadService" />
<service android:name=".controller.UpdaterService" />
<receiver android:name=".UpdatesCheckReceiver">
<intent-filter>

View File

@@ -31,9 +31,9 @@ import android.support.v7.widget.SimpleItemAnimator;
import android.util.Log;
import org.json.JSONException;
import org.lineageos.updater.controller.DownloadController;
import org.lineageos.updater.controller.DownloadControllerInt;
import org.lineageos.updater.controller.DownloadService;
import org.lineageos.updater.controller.UpdaterController;
import org.lineageos.updater.controller.UpdaterControllerInt;
import org.lineageos.updater.controller.UpdaterService;
import org.lineageos.updater.misc.Utils;
import java.io.File;
@@ -45,7 +45,7 @@ import java.util.List;
public class UpdatesActivity extends AppCompatActivity {
private static final String TAG = "UpdatesActivity";
private DownloadService mDownloadService;
private UpdaterService mUpdaterService;
private BroadcastReceiver mBroadcastReceiver;
private UpdatesListAdapter mAdapter;
@@ -68,10 +68,10 @@ public class UpdatesActivity extends AppCompatActivity {
mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (DownloadController.UPDATE_STATUS_ACTION.equals(intent.getAction())) {
if (UpdaterController.UPDATE_STATUS_ACTION.equals(intent.getAction())) {
mAdapter.notifyDataSetChanged();
} else if (DownloadController.PROGRESS_ACTION.equals(intent.getAction())) {
String downloadId = intent.getStringExtra(DownloadController.DOWNLOAD_ID_EXTRA);
} else if (UpdaterController.PROGRESS_ACTION.equals(intent.getAction())) {
String downloadId = intent.getStringExtra(UpdaterController.DOWNLOAD_ID_EXTRA);
mAdapter.notifyItemChanged(downloadId);
}
}
@@ -81,20 +81,20 @@ public class UpdatesActivity extends AppCompatActivity {
@Override
public void onStart() {
super.onStart();
Intent intent = new Intent(this, DownloadService.class);
Intent intent = new Intent(this, UpdaterService.class);
startService(intent);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(DownloadController.UPDATE_STATUS_ACTION);
intentFilter.addAction(DownloadController.PROGRESS_ACTION);
intentFilter.addAction(UpdaterController.UPDATE_STATUS_ACTION);
intentFilter.addAction(UpdaterController.PROGRESS_ACTION);
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
}
@Override
public void onStop() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
if (mDownloadService != null) {
if (mUpdaterService != null) {
unbindService(mConnection);
}
super.onStop();
@@ -105,23 +105,23 @@ public class UpdatesActivity extends AppCompatActivity {
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
DownloadService.LocalBinder binder = (DownloadService.LocalBinder) service;
mDownloadService = binder.getService();
mAdapter.setDownloadController(mDownloadService.getDownloadController());
UpdaterService.LocalBinder binder = (UpdaterService.LocalBinder) service;
mUpdaterService = binder.getService();
mAdapter.setUpdaterController(mUpdaterService.getUpdaterController());
getUpdatesList();
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
mAdapter.setDownloadController(null);
mDownloadService = null;
mAdapter.setUpdaterController(null);
mUpdaterService = null;
mAdapter.notifyDataSetChanged();
}
};
private void loadUpdatesList() throws IOException, JSONException {
Log.d(TAG, "Adding remote updates");
DownloadControllerInt controller = mDownloadService.getDownloadController();
UpdaterControllerInt controller = mUpdaterService.getUpdaterController();
File jsonFile = Utils.getCachedUpdateList(this);
for (UpdateDownload update : Utils.parseJson(jsonFile, true)) {
controller.addUpdate(update);

View File

@@ -25,7 +25,7 @@ import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.lineageos.updater.controller.DownloadControllerInt;
import org.lineageos.updater.controller.UpdaterControllerInt;
import org.lineageos.updater.misc.Utils;
import java.io.IOException;
@@ -36,7 +36,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
private static final String TAG = "UpdateListAdapter";
private List<String> mDownloadIds;
private DownloadControllerInt mDownloadController;
private UpdaterControllerInt mUpdaterController;
private Context mContext;
private enum Action {
@@ -73,21 +73,21 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
return new ViewHolder(view);
}
public void setDownloadController(DownloadControllerInt downloadController) {
mDownloadController = downloadController;
public void setUpdaterController(UpdaterControllerInt updaterController) {
mUpdaterController = updaterController;
notifyDataSetChanged();
}
@Override
public void onBindViewHolder(final ViewHolder viewHolder, int i) {
if (mDownloadController == null) {
if (mUpdaterController == null) {
viewHolder.mButton1.setEnabled(false);
viewHolder.mButton2.setEnabled(false);
return;
}
final String downloadId = mDownloadIds.get(i);
UpdateDownload update = mDownloadController.getUpdate(downloadId);
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
viewHolder.mName.setText(update.getName());
viewHolder.mProgressBar.setProgress(update.getProgress());
@@ -96,12 +96,12 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
update.getStatus() == UpdateStatus.INSTALLING;
viewHolder.mProgressBar.setIndeterminate(indeterminate);
if (mDownloadController.isDownloading(downloadId)) {
if (mUpdaterController.isDownloading(downloadId)) {
setButtonAction(viewHolder.mButton1, Action.PAUSE, downloadId, true);
viewHolder.mButton2.setEnabled(false);
} else {
// Allow one active download
boolean enabled = !mDownloadController.hasActiveDownloads() && Utils.canInstall(update);
boolean enabled = !mUpdaterController.hasActiveDownloads() && Utils.canInstall(update);
int persistentStatus = update.getPersistentStatus();
if (persistentStatus == UpdateStatus.Persistent.INCOMPLETE) {
setButtonAction(viewHolder.mButton1, Action.RESUME, downloadId, enabled);
@@ -138,7 +138,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
@Override
public void onClick(View view) {
mDownloadController.startDownload(downloadId);
mUpdaterController.startDownload(downloadId);
}
});
break;
@@ -148,7 +148,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
@Override
public void onClick(View view) {
mDownloadController.pauseDownload(downloadId);
mUpdaterController.pauseDownload(downloadId);
}
});
break;
@@ -158,7 +158,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
@Override
public void onClick(View view) {
mDownloadController.resumeDownload(downloadId);
mUpdaterController.resumeDownload(downloadId);
}
});
break;
@@ -168,7 +168,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
@Override
public void onClick(View view) {
mDownloadController.cancelDownload(downloadId);
mUpdaterController.cancelDownload(downloadId);
}
});
break;
@@ -180,7 +180,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
public void onClick(View view) {
try {
Utils.triggerUpdate(mContext,
mDownloadController.getUpdate(downloadId));
mUpdaterController.getUpdate(downloadId));
} catch (IOException e) {
Log.e(TAG, "Could not trigger the update", e);
// TODO: show error message

View File

@@ -36,15 +36,15 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
public class DownloadController implements DownloadControllerInt {
public class UpdaterController implements UpdaterControllerInt {
public static final String PROGRESS_ACTION = "progress_action";
public static final String UPDATE_STATUS_ACTION = "update_status_change_action";
public static final String DOWNLOAD_ID_EXTRA = "download_id_extra";
private final String TAG = "DownloadController";
private final String TAG = "UpdaterController";
private static DownloadController sDownloadController;
private static UpdaterController sUpdaterController;
private static final int MAX_REPORT_INTERVAL_MS = 1000;
@@ -55,18 +55,18 @@ public class DownloadController implements DownloadControllerInt {
private final File mDownloadRoot;
public static synchronized DownloadController getInstance() {
return sDownloadController;
public static synchronized UpdaterController getInstance() {
return sUpdaterController;
}
protected static synchronized DownloadController getInstance(Context context) {
if (sDownloadController == null) {
sDownloadController = new DownloadController(context);
protected static synchronized UpdaterController getInstance(Context context) {
if (sUpdaterController == null) {
sUpdaterController = new UpdaterController(context);
}
return sDownloadController;
return sUpdaterController;
}
private DownloadController(Context context) {
private UpdaterController(Context context) {
mBroadcastManager = LocalBroadcastManager.getInstance(context);
mUpdatesDbHelper = new UpdatesDbHelper(context);
mDownloadRoot = Utils.getDownloadPath(context);

View File

@@ -20,7 +20,7 @@ import org.lineageos.updater.UpdateDownload;
import java.util.List;
import java.util.Set;
public interface DownloadControllerInt {
public interface UpdaterControllerInt {
boolean addUpdate(UpdateDownload update);

View File

@@ -38,9 +38,9 @@ import org.lineageos.updater.misc.Utils;
import java.io.IOException;
import java.text.NumberFormat;
public class DownloadService extends Service {
public class UpdaterService extends Service {
private static final String TAG = "DownloadService";
private static final String TAG = "UpdaterService";
public static final String ACTION_DOWNLOAD_CONTROL = "action_download_control";
public static final String EXTRA_DOWNLOAD_ID = "extra_download_id";
@@ -60,13 +60,13 @@ public class DownloadService extends Service {
private NotificationManager mNotificationManager;
private NotificationCompat.BigTextStyle mNotificationStyle;;
private DownloadControllerInt mDownloadController;
private UpdaterControllerInt mUpdaterController;
@Override
public void onCreate() {
super.onCreate();
mDownloadController = DownloadController.getInstance(this);
mUpdaterController = UpdaterController.getInstance(this);
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotificationBuilder = new NotificationCompat.Builder(this);
@@ -83,13 +83,13 @@ public class DownloadService extends Service {
mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String downloadId = intent.getStringExtra(DownloadController.DOWNLOAD_ID_EXTRA);
if (DownloadController.UPDATE_STATUS_ACTION.equals(intent.getAction())) {
UpdateDownload update = mDownloadController.getUpdate(downloadId);
String downloadId = intent.getStringExtra(UpdaterController.DOWNLOAD_ID_EXTRA);
if (UpdaterController.UPDATE_STATUS_ACTION.equals(intent.getAction())) {
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
mNotificationBuilder.setContentTitle(update.getName());
handleDownloadStatusChange(update);
} else if (DownloadController.PROGRESS_ACTION.equals(intent.getAction())) {
UpdateDownload update = mDownloadController.getUpdate(downloadId);
handleUpdateStatusChange(update);
} else if (UpdaterController.PROGRESS_ACTION.equals(intent.getAction())) {
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
int progress = update.getProgress();
mNotificationBuilder.setProgress(100, progress, false);
@@ -109,8 +109,8 @@ public class DownloadService extends Service {
}
};
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(DownloadController.PROGRESS_ACTION);
intentFilter.addAction(DownloadController.UPDATE_STATUS_ACTION);
intentFilter.addAction(UpdaterController.PROGRESS_ACTION);
intentFilter.addAction(UpdaterController.UPDATE_STATUS_ACTION);
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
}
@@ -122,8 +122,8 @@ public class DownloadService extends Service {
}
public class LocalBinder extends Binder {
public DownloadService getService() {
return DownloadService.this;
public UpdaterService getService() {
return UpdaterService.this;
}
}
@@ -153,16 +153,16 @@ public class DownloadService extends Service {
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
int action = intent.getIntExtra(EXTRA_DOWNLOAD_CONTROL, -1);
if (action == DOWNLOAD_RESUME) {
mDownloadController.resumeDownload(downloadId);
mUpdaterController.resumeDownload(downloadId);
} else if (action == DOWNLOAD_PAUSE) {
mDownloadController.pauseDownload(downloadId);
mUpdaterController.pauseDownload(downloadId);
} else {
Log.e(TAG, "Unknown download action");
}
} else if (ACTION_INSTALL_UPDATE.equals(intent.getAction())) {
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
try {
Utils.triggerUpdate(this, mDownloadController.getUpdate(downloadId));
Utils.triggerUpdate(this, mUpdaterController.getUpdate(downloadId));
} catch (IOException e) {
Log.e(TAG, "Could not install update");
// TODO: user facing message
@@ -172,18 +172,18 @@ public class DownloadService extends Service {
return START_STICKY;
}
public DownloadControllerInt getDownloadController() {
return mDownloadController;
public UpdaterControllerInt getUpdaterController() {
return mUpdaterController;
}
private void tryStopSelf() {
if (!mHasClients && !mDownloadController.hasActiveDownloads()) {
if (!mHasClients && !mUpdaterController.hasActiveDownloads()) {
Log.d(TAG, "Service no longer needed, stopping");
stopSelf();
}
}
private void handleDownloadStatusChange(UpdateDownload update) {
private void handleUpdateStatusChange(UpdateDownload update) {
switch (update.getStatus()) {
case DELETED: {
stopForeground(STOP_FOREGROUND_DETACH);
@@ -282,7 +282,7 @@ public class DownloadService extends Service {
}
private PendingIntent getResumePendingIntent(String downloadId) {
final Intent intent = new Intent(this, DownloadService.class);
final Intent intent = new Intent(this, UpdaterService.class);
intent.setAction(ACTION_DOWNLOAD_CONTROL);
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_RESUME);
@@ -291,7 +291,7 @@ public class DownloadService extends Service {
}
private PendingIntent getPausePendingIntent(String downloadId) {
final Intent intent = new Intent(this, DownloadService.class);
final Intent intent = new Intent(this, UpdaterService.class);
intent.setAction(ACTION_DOWNLOAD_CONTROL);
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_PAUSE);
@@ -300,7 +300,7 @@ public class DownloadService extends Service {
}
private PendingIntent getInstallPendingIntent(String downloadId) {
final Intent intent = new Intent(this, DownloadService.class);
final Intent intent = new Intent(this, UpdaterService.class);
intent.setAction(ACTION_INSTALL_UPDATE);
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
return PendingIntent.getService(this, 0, intent,