Replace 'Download' prefix with 'Updater'
These classes do more than controlling the download of the updates.
This commit is contained in:
@@ -28,7 +28,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service android:name=".controller.DownloadService" />
|
<service android:name=".controller.UpdaterService" />
|
||||||
|
|
||||||
<receiver android:name=".UpdatesCheckReceiver">
|
<receiver android:name=".UpdatesCheckReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@@ -31,9 +31,9 @@ import android.support.v7.widget.SimpleItemAnimator;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.lineageos.updater.controller.DownloadController;
|
import org.lineageos.updater.controller.UpdaterController;
|
||||||
import org.lineageos.updater.controller.DownloadControllerInt;
|
import org.lineageos.updater.controller.UpdaterControllerInt;
|
||||||
import org.lineageos.updater.controller.DownloadService;
|
import org.lineageos.updater.controller.UpdaterService;
|
||||||
import org.lineageos.updater.misc.Utils;
|
import org.lineageos.updater.misc.Utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -45,7 +45,7 @@ import java.util.List;
|
|||||||
public class UpdatesActivity extends AppCompatActivity {
|
public class UpdatesActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static final String TAG = "UpdatesActivity";
|
private static final String TAG = "UpdatesActivity";
|
||||||
private DownloadService mDownloadService;
|
private UpdaterService mUpdaterService;
|
||||||
private BroadcastReceiver mBroadcastReceiver;
|
private BroadcastReceiver mBroadcastReceiver;
|
||||||
|
|
||||||
private UpdatesListAdapter mAdapter;
|
private UpdatesListAdapter mAdapter;
|
||||||
@@ -68,10 +68,10 @@ public class UpdatesActivity extends AppCompatActivity {
|
|||||||
mBroadcastReceiver = new BroadcastReceiver() {
|
mBroadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
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();
|
mAdapter.notifyDataSetChanged();
|
||||||
} else if (DownloadController.PROGRESS_ACTION.equals(intent.getAction())) {
|
} else if (UpdaterController.PROGRESS_ACTION.equals(intent.getAction())) {
|
||||||
String downloadId = intent.getStringExtra(DownloadController.DOWNLOAD_ID_EXTRA);
|
String downloadId = intent.getStringExtra(UpdaterController.DOWNLOAD_ID_EXTRA);
|
||||||
mAdapter.notifyItemChanged(downloadId);
|
mAdapter.notifyItemChanged(downloadId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,20 +81,20 @@ public class UpdatesActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
Intent intent = new Intent(this, DownloadService.class);
|
Intent intent = new Intent(this, UpdaterService.class);
|
||||||
startService(intent);
|
startService(intent);
|
||||||
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(DownloadController.UPDATE_STATUS_ACTION);
|
intentFilter.addAction(UpdaterController.UPDATE_STATUS_ACTION);
|
||||||
intentFilter.addAction(DownloadController.PROGRESS_ACTION);
|
intentFilter.addAction(UpdaterController.PROGRESS_ACTION);
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
|
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
|
||||||
if (mDownloadService != null) {
|
if (mUpdaterService != null) {
|
||||||
unbindService(mConnection);
|
unbindService(mConnection);
|
||||||
}
|
}
|
||||||
super.onStop();
|
super.onStop();
|
||||||
@@ -105,23 +105,23 @@ public class UpdatesActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName className,
|
public void onServiceConnected(ComponentName className,
|
||||||
IBinder service) {
|
IBinder service) {
|
||||||
DownloadService.LocalBinder binder = (DownloadService.LocalBinder) service;
|
UpdaterService.LocalBinder binder = (UpdaterService.LocalBinder) service;
|
||||||
mDownloadService = binder.getService();
|
mUpdaterService = binder.getService();
|
||||||
mAdapter.setDownloadController(mDownloadService.getDownloadController());
|
mAdapter.setUpdaterController(mUpdaterService.getUpdaterController());
|
||||||
getUpdatesList();
|
getUpdatesList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName componentName) {
|
public void onServiceDisconnected(ComponentName componentName) {
|
||||||
mAdapter.setDownloadController(null);
|
mAdapter.setUpdaterController(null);
|
||||||
mDownloadService = null;
|
mUpdaterService = null;
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void loadUpdatesList() throws IOException, JSONException {
|
private void loadUpdatesList() throws IOException, JSONException {
|
||||||
Log.d(TAG, "Adding remote updates");
|
Log.d(TAG, "Adding remote updates");
|
||||||
DownloadControllerInt controller = mDownloadService.getDownloadController();
|
UpdaterControllerInt controller = mUpdaterService.getUpdaterController();
|
||||||
File jsonFile = Utils.getCachedUpdateList(this);
|
File jsonFile = Utils.getCachedUpdateList(this);
|
||||||
for (UpdateDownload update : Utils.parseJson(jsonFile, true)) {
|
for (UpdateDownload update : Utils.parseJson(jsonFile, true)) {
|
||||||
controller.addUpdate(update);
|
controller.addUpdate(update);
|
||||||
|
@@ -25,7 +25,7 @@ import android.widget.Button;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.lineageos.updater.controller.DownloadControllerInt;
|
import org.lineageos.updater.controller.UpdaterControllerInt;
|
||||||
import org.lineageos.updater.misc.Utils;
|
import org.lineageos.updater.misc.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -36,7 +36,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
private static final String TAG = "UpdateListAdapter";
|
private static final String TAG = "UpdateListAdapter";
|
||||||
|
|
||||||
private List<String> mDownloadIds;
|
private List<String> mDownloadIds;
|
||||||
private DownloadControllerInt mDownloadController;
|
private UpdaterControllerInt mUpdaterController;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
private enum Action {
|
private enum Action {
|
||||||
@@ -73,21 +73,21 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
return new ViewHolder(view);
|
return new ViewHolder(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDownloadController(DownloadControllerInt downloadController) {
|
public void setUpdaterController(UpdaterControllerInt updaterController) {
|
||||||
mDownloadController = downloadController;
|
mUpdaterController = updaterController;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ViewHolder viewHolder, int i) {
|
public void onBindViewHolder(final ViewHolder viewHolder, int i) {
|
||||||
if (mDownloadController == null) {
|
if (mUpdaterController == null) {
|
||||||
viewHolder.mButton1.setEnabled(false);
|
viewHolder.mButton1.setEnabled(false);
|
||||||
viewHolder.mButton2.setEnabled(false);
|
viewHolder.mButton2.setEnabled(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String downloadId = mDownloadIds.get(i);
|
final String downloadId = mDownloadIds.get(i);
|
||||||
UpdateDownload update = mDownloadController.getUpdate(downloadId);
|
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||||
viewHolder.mName.setText(update.getName());
|
viewHolder.mName.setText(update.getName());
|
||||||
|
|
||||||
viewHolder.mProgressBar.setProgress(update.getProgress());
|
viewHolder.mProgressBar.setProgress(update.getProgress());
|
||||||
@@ -96,12 +96,12 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
update.getStatus() == UpdateStatus.INSTALLING;
|
update.getStatus() == UpdateStatus.INSTALLING;
|
||||||
viewHolder.mProgressBar.setIndeterminate(indeterminate);
|
viewHolder.mProgressBar.setIndeterminate(indeterminate);
|
||||||
|
|
||||||
if (mDownloadController.isDownloading(downloadId)) {
|
if (mUpdaterController.isDownloading(downloadId)) {
|
||||||
setButtonAction(viewHolder.mButton1, Action.PAUSE, downloadId, true);
|
setButtonAction(viewHolder.mButton1, Action.PAUSE, downloadId, true);
|
||||||
viewHolder.mButton2.setEnabled(false);
|
viewHolder.mButton2.setEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
// Allow one active download
|
// Allow one active download
|
||||||
boolean enabled = !mDownloadController.hasActiveDownloads() && Utils.canInstall(update);
|
boolean enabled = !mUpdaterController.hasActiveDownloads() && Utils.canInstall(update);
|
||||||
int persistentStatus = update.getPersistentStatus();
|
int persistentStatus = update.getPersistentStatus();
|
||||||
if (persistentStatus == UpdateStatus.Persistent.INCOMPLETE) {
|
if (persistentStatus == UpdateStatus.Persistent.INCOMPLETE) {
|
||||||
setButtonAction(viewHolder.mButton1, Action.RESUME, downloadId, enabled);
|
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() {
|
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
mDownloadController.startDownload(downloadId);
|
mUpdaterController.startDownload(downloadId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -148,7 +148,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
mDownloadController.pauseDownload(downloadId);
|
mUpdaterController.pauseDownload(downloadId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -158,7 +158,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
mDownloadController.resumeDownload(downloadId);
|
mUpdaterController.resumeDownload(downloadId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -168,7 +168,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
button.setOnClickListener(!enabled ? null : new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
mDownloadController.cancelDownload(downloadId);
|
mUpdaterController.cancelDownload(downloadId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -180,7 +180,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
|
|||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
try {
|
try {
|
||||||
Utils.triggerUpdate(mContext,
|
Utils.triggerUpdate(mContext,
|
||||||
mDownloadController.getUpdate(downloadId));
|
mUpdaterController.getUpdate(downloadId));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Could not trigger the update", e);
|
Log.e(TAG, "Could not trigger the update", e);
|
||||||
// TODO: show error message
|
// TODO: show error message
|
||||||
|
@@ -36,15 +36,15 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
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 PROGRESS_ACTION = "progress_action";
|
||||||
public static final String UPDATE_STATUS_ACTION = "update_status_change_action";
|
public static final String UPDATE_STATUS_ACTION = "update_status_change_action";
|
||||||
public static final String DOWNLOAD_ID_EXTRA = "download_id_extra";
|
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;
|
private static final int MAX_REPORT_INTERVAL_MS = 1000;
|
||||||
|
|
||||||
@@ -55,18 +55,18 @@ public class DownloadController implements DownloadControllerInt {
|
|||||||
|
|
||||||
private final File mDownloadRoot;
|
private final File mDownloadRoot;
|
||||||
|
|
||||||
public static synchronized DownloadController getInstance() {
|
public static synchronized UpdaterController getInstance() {
|
||||||
return sDownloadController;
|
return sUpdaterController;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static synchronized DownloadController getInstance(Context context) {
|
protected static synchronized UpdaterController getInstance(Context context) {
|
||||||
if (sDownloadController == null) {
|
if (sUpdaterController == null) {
|
||||||
sDownloadController = new DownloadController(context);
|
sUpdaterController = new UpdaterController(context);
|
||||||
}
|
}
|
||||||
return sDownloadController;
|
return sUpdaterController;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DownloadController(Context context) {
|
private UpdaterController(Context context) {
|
||||||
mBroadcastManager = LocalBroadcastManager.getInstance(context);
|
mBroadcastManager = LocalBroadcastManager.getInstance(context);
|
||||||
mUpdatesDbHelper = new UpdatesDbHelper(context);
|
mUpdatesDbHelper = new UpdatesDbHelper(context);
|
||||||
mDownloadRoot = Utils.getDownloadPath(context);
|
mDownloadRoot = Utils.getDownloadPath(context);
|
@@ -20,7 +20,7 @@ import org.lineageos.updater.UpdateDownload;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface DownloadControllerInt {
|
public interface UpdaterControllerInt {
|
||||||
|
|
||||||
boolean addUpdate(UpdateDownload update);
|
boolean addUpdate(UpdateDownload update);
|
||||||
|
|
@@ -38,9 +38,9 @@ import org.lineageos.updater.misc.Utils;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.NumberFormat;
|
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 ACTION_DOWNLOAD_CONTROL = "action_download_control";
|
||||||
public static final String EXTRA_DOWNLOAD_ID = "extra_download_id";
|
public static final String EXTRA_DOWNLOAD_ID = "extra_download_id";
|
||||||
@@ -60,13 +60,13 @@ public class DownloadService extends Service {
|
|||||||
private NotificationManager mNotificationManager;
|
private NotificationManager mNotificationManager;
|
||||||
private NotificationCompat.BigTextStyle mNotificationStyle;;
|
private NotificationCompat.BigTextStyle mNotificationStyle;;
|
||||||
|
|
||||||
private DownloadControllerInt mDownloadController;
|
private UpdaterControllerInt mUpdaterController;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
mDownloadController = DownloadController.getInstance(this);
|
mUpdaterController = UpdaterController.getInstance(this);
|
||||||
|
|
||||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
mNotificationBuilder = new NotificationCompat.Builder(this);
|
mNotificationBuilder = new NotificationCompat.Builder(this);
|
||||||
@@ -83,13 +83,13 @@ public class DownloadService extends Service {
|
|||||||
mBroadcastReceiver = new BroadcastReceiver() {
|
mBroadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String downloadId = intent.getStringExtra(DownloadController.DOWNLOAD_ID_EXTRA);
|
String downloadId = intent.getStringExtra(UpdaterController.DOWNLOAD_ID_EXTRA);
|
||||||
if (DownloadController.UPDATE_STATUS_ACTION.equals(intent.getAction())) {
|
if (UpdaterController.UPDATE_STATUS_ACTION.equals(intent.getAction())) {
|
||||||
UpdateDownload update = mDownloadController.getUpdate(downloadId);
|
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||||
mNotificationBuilder.setContentTitle(update.getName());
|
mNotificationBuilder.setContentTitle(update.getName());
|
||||||
handleDownloadStatusChange(update);
|
handleUpdateStatusChange(update);
|
||||||
} else if (DownloadController.PROGRESS_ACTION.equals(intent.getAction())) {
|
} else if (UpdaterController.PROGRESS_ACTION.equals(intent.getAction())) {
|
||||||
UpdateDownload update = mDownloadController.getUpdate(downloadId);
|
UpdateDownload update = mUpdaterController.getUpdate(downloadId);
|
||||||
int progress = update.getProgress();
|
int progress = update.getProgress();
|
||||||
mNotificationBuilder.setProgress(100, progress, false);
|
mNotificationBuilder.setProgress(100, progress, false);
|
||||||
|
|
||||||
@@ -109,8 +109,8 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
IntentFilter intentFilter = new IntentFilter();
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
intentFilter.addAction(DownloadController.PROGRESS_ACTION);
|
intentFilter.addAction(UpdaterController.PROGRESS_ACTION);
|
||||||
intentFilter.addAction(DownloadController.UPDATE_STATUS_ACTION);
|
intentFilter.addAction(UpdaterController.UPDATE_STATUS_ACTION);
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
|
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, intentFilter);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -122,8 +122,8 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class LocalBinder extends Binder {
|
public class LocalBinder extends Binder {
|
||||||
public DownloadService getService() {
|
public UpdaterService getService() {
|
||||||
return DownloadService.this;
|
return UpdaterService.this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,16 +153,16 @@ public class DownloadService extends Service {
|
|||||||
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
|
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
|
||||||
int action = intent.getIntExtra(EXTRA_DOWNLOAD_CONTROL, -1);
|
int action = intent.getIntExtra(EXTRA_DOWNLOAD_CONTROL, -1);
|
||||||
if (action == DOWNLOAD_RESUME) {
|
if (action == DOWNLOAD_RESUME) {
|
||||||
mDownloadController.resumeDownload(downloadId);
|
mUpdaterController.resumeDownload(downloadId);
|
||||||
} else if (action == DOWNLOAD_PAUSE) {
|
} else if (action == DOWNLOAD_PAUSE) {
|
||||||
mDownloadController.pauseDownload(downloadId);
|
mUpdaterController.pauseDownload(downloadId);
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Unknown download action");
|
Log.e(TAG, "Unknown download action");
|
||||||
}
|
}
|
||||||
} else if (ACTION_INSTALL_UPDATE.equals(intent.getAction())) {
|
} else if (ACTION_INSTALL_UPDATE.equals(intent.getAction())) {
|
||||||
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
|
String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID);
|
||||||
try {
|
try {
|
||||||
Utils.triggerUpdate(this, mDownloadController.getUpdate(downloadId));
|
Utils.triggerUpdate(this, mUpdaterController.getUpdate(downloadId));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Could not install update");
|
Log.e(TAG, "Could not install update");
|
||||||
// TODO: user facing message
|
// TODO: user facing message
|
||||||
@@ -172,18 +172,18 @@ public class DownloadService extends Service {
|
|||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadControllerInt getDownloadController() {
|
public UpdaterControllerInt getUpdaterController() {
|
||||||
return mDownloadController;
|
return mUpdaterController;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tryStopSelf() {
|
private void tryStopSelf() {
|
||||||
if (!mHasClients && !mDownloadController.hasActiveDownloads()) {
|
if (!mHasClients && !mUpdaterController.hasActiveDownloads()) {
|
||||||
Log.d(TAG, "Service no longer needed, stopping");
|
Log.d(TAG, "Service no longer needed, stopping");
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleDownloadStatusChange(UpdateDownload update) {
|
private void handleUpdateStatusChange(UpdateDownload update) {
|
||||||
switch (update.getStatus()) {
|
switch (update.getStatus()) {
|
||||||
case DELETED: {
|
case DELETED: {
|
||||||
stopForeground(STOP_FOREGROUND_DETACH);
|
stopForeground(STOP_FOREGROUND_DETACH);
|
||||||
@@ -282,7 +282,7 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent getResumePendingIntent(String downloadId) {
|
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.setAction(ACTION_DOWNLOAD_CONTROL);
|
||||||
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
|
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
|
||||||
intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_RESUME);
|
intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_RESUME);
|
||||||
@@ -291,7 +291,7 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent getPausePendingIntent(String downloadId) {
|
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.setAction(ACTION_DOWNLOAD_CONTROL);
|
||||||
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
|
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
|
||||||
intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_PAUSE);
|
intent.putExtra(EXTRA_DOWNLOAD_CONTROL, DOWNLOAD_PAUSE);
|
||||||
@@ -300,7 +300,7 @@ public class DownloadService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PendingIntent getInstallPendingIntent(String downloadId) {
|
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.setAction(ACTION_INSTALL_UPDATE);
|
||||||
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
|
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
|
||||||
return PendingIntent.getService(this, 0, intent,
|
return PendingIntent.getService(this, 0, intent,
|
Reference in New Issue
Block a user