Merge lp:~humpolec-team/humpolec/UbuntuInstaller_lp1262034 into lp:humpolec

Proposed by Yuan-Chen Cheng
Status: Merged
Merged at revision: 21
Proposed branch: lp:~humpolec-team/humpolec/UbuntuInstaller_lp1262034
Merge into: lp:humpolec
Diff against target: 577 lines (+158/-131)
4 files modified
src/com/canonical/ubuntu/installer/InstallActivity.java (+83/-74)
src/com/canonical/ubuntu/installer/LaunchActivity.java (+4/-6)
src/com/canonical/ubuntu/installer/UbuntuInstallService.java (+69/-28)
src/com/canonical/ubuntu/installer/Utils.java (+2/-23)
To merge this branch: bzr merge lp:~humpolec-team/humpolec/UbuntuInstaller_lp1262034
Reviewer Review Type Date Requested Status
Rex Tsai Approve
Review via email: mp+199404@code.launchpad.net

Description of the change

1. Rename ServiceState to InstallerState in UbuntuInstallService.
2. Use InstallerState, mAvailableChannels.size() equals to zero or not
        and mDownloadedVersion to decide what to show on UI.
3. move some preference related function to UbuntuInstallService.
4. call requestServiceState() in onResume() of InstallActivity and
        update related code.

quick tested on n4. go back to andorid launcher as downloading image
and re-enter this app, the UI can goes back to downloading status
correctly.

To post a comment you must log in.
Revision history for this message
Rex Tsai (chihchun) wrote :

LGTM, +1

review: Approve
Revision history for this message
Ondrej Kubik (ondrak) wrote :

Looks good
small comment for
 public static InstallerState fromOrdian(int ordian)
this can be done this way
 public static InstallerState fromOrdian(int ordian) {
    return InstallerState.values()[ordinal];
 }

21. By Yuan-Chen Cheng

cleaner way for doing fromOrdian for java enum

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/com/canonical/ubuntu/installer/InstallActivity.java'
--- src/com/canonical/ubuntu/installer/InstallActivity.java 2013-12-16 13:16:32 +0000
+++ src/com/canonical/ubuntu/installer/InstallActivity.java 2013-12-18 11:59:13 +0000
@@ -7,6 +7,7 @@
7import com.canonical.ubuntu.installer.TextPickerDialog;7import com.canonical.ubuntu.installer.TextPickerDialog;
8import com.canonical.ubuntu.installer.UbuntuInstallService;8import com.canonical.ubuntu.installer.UbuntuInstallService;
9import com.canonical.ubuntu.installer.JsonChannelParser.Image;9import com.canonical.ubuntu.installer.JsonChannelParser.Image;
10import com.canonical.ubuntu.installer.UbuntuInstallService.InstallerState;
10import com.canonical.ubuntu.installer.VersionInfo.ReleaseType;11import com.canonical.ubuntu.installer.VersionInfo.ReleaseType;
11import com.canonical.ubuntu.widget.UbuntuButton;12import com.canonical.ubuntu.widget.UbuntuButton;
1213
@@ -31,17 +32,16 @@
31public class InstallActivity extends Activity {32public class InstallActivity extends Activity {
32 private static final String TAG = "UbuntuInstaller";33 private static final String TAG = "UbuntuInstaller";
3334
34 private enum ActivityStatus {
35 NORMAL, FETCHING_CHANNELS, NO_CHANNELS, READY_TO_DOWNLOAD, DOWNLOADING, READY_TO_INSTALL, INSTALLING
36 };
37
38 private UbuntuButton mInstallButton; 35 private UbuntuButton mInstallButton;
39 private ActivityStatus mStatus = ActivityStatus.NORMAL;36
37 private InstallerState mStatus = InstallerState.READY;
38 private VersionInfo mDownloadedVersion = null;
39
40 private ProgressBar mProgressBar;40 private ProgressBar mProgressBar;
41 private TextView mProgressText;41 private TextView mProgressText;
42 42
43 private TextView mTerminal;43 private TextView mTerminal;
44 private HashMap<String, String> mAvailableChannels;44 private HashMap<String, String> mAvailableChannels = new HashMap<String, String>();
4545
46 @Override46 @Override
47 protected void onCreate(Bundle savedInstanceState) {47 protected void onCreate(Bundle savedInstanceState) {
@@ -56,12 +56,10 @@
56 mProgressText = (TextView) findViewById(R.id.status); 56 mProgressText = (TextView) findViewById(R.id.status);
57 mTerminal = (TextView) findViewById(R.id.terminal);57 mTerminal = (TextView) findViewById(R.id.terminal);
58 mTerminal.setMovementMethod(new ScrollingMovementMethod());58 mTerminal.setMovementMethod(new ScrollingMovementMethod());
59 requestChannelList();
60 mStatus = ActivityStatus.FETCHING_CHANNELS;
61 mProgressBar.setEnabled(false);59 mProgressBar.setEnabled(false);
62 mProgressBar.setProgress(0);60 mProgressBar.setProgress(0);
63 61
64 SharedPreferences pref = getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE);62 SharedPreferences pref = getSharedPreferences(UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE);
65 pref.edit().putBoolean(UbuntuInstallService.PREF_KEY_DEVELOPER, true).commit();63 pref.edit().putBoolean(UbuntuInstallService.PREF_KEY_DEVELOPER, true).commit();
66 }64 }
67 65
@@ -81,15 +79,18 @@
81 filter.addAction(UbuntuInstallService.VERSION_UPDATE);79 filter.addAction(UbuntuInstallService.VERSION_UPDATE);
82 filter.addAction(UbuntuInstallService.SERVICE_STATE);80 filter.addAction(UbuntuInstallService.SERVICE_STATE);
83 registerReceiver(mServiceObserver, filter);81 registerReceiver(mServiceObserver, filter);
84 82
85 // do we know last activity83 // do we know last activity
86 if (mStatus == ActivityStatus.DOWNLOADING || mStatus == ActivityStatus.INSTALLING) {84 if (mStatus == InstallerState.READY) {
85 requestServiceState();
86 mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(this.getApplicationContext());
87 } else if (mStatus == InstallerState.DOWNLOADING || mStatus == InstallerState.INSTALLING) {
87 // request last progress / status. this will update UI accordingly88 // request last progress / status. this will update UI accordingly
88 startService(new Intent(UbuntuInstallService.GET_PROGRESS_STATUS)); 89 startService(new Intent(UbuntuInstallService.GET_PROGRESS_STATUS));
89 } else {90 } else {
90 if (Utils.checkifReadyToInstall(this)) {91 // READY + mDownloadedVersion != null => READY_TO_INSTALL
91 mStatus = ActivityStatus.READY_TO_INSTALL;92 mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(this.getApplicationContext());
92 }93 mStatus = InstallerState.READY;
93 updateUiElements();94 updateUiElements();
94 }95 }
95 }96 }
@@ -114,7 +115,8 @@
114 switch (item.getItemId()) {115 switch (item.getItemId()) {
115 case R.id.action_delete_download:116 case R.id.action_delete_download:
116 deleteDownload();117 deleteDownload();
117 mStatus = ActivityStatus.READY_TO_DOWNLOAD;118 mDownloadedVersion = null;
119 mStatus = InstallerState.READY;
118 updateUiElements();120 updateUiElements();
119 break;121 break;
120 }122 }
@@ -126,20 +128,23 @@
126 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);128 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
127 context.startActivity(intent);129 context.startActivity(intent);
128 }130 }
129 131
130 private void checkIfUbuntuIsInstalled() {132 private void checkIfUbuntuIsInstalled() {
131 // check is there is Ubuntu installed133 // check is there is Ubuntu installed
132 SharedPreferences pref = getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE);134 if (UbuntuInstallService.isUbuntuInstalled(this.getApplicationContext())) {
133 if (VersionInfo.hasValidVersion(pref, UbuntuInstallService.PREF_KEY_INSTALLED_VERSION)) {
134 // go to launch screen135 // go to launch screen
135 LaunchActivity.startFrom(this);;136 LaunchActivity.startFrom(this);
136 }137 }
137 }138 }
138 139
139 private void requestChannelList() {140 private void requestChannelList() {
140 startService(new Intent(UbuntuInstallService.GET_CHANNEL_LIST));141 startService(new Intent(UbuntuInstallService.GET_CHANNEL_LIST));
141 }142 }
142 143
144 private void requestServiceState() {
145 startService(new Intent(UbuntuInstallService.GET_SERVICE_STATE));
146 }
147
143 private void deleteDownload() {148 private void deleteDownload() {
144 Intent action = new Intent(UbuntuInstallService.CLEAN_DOWNLOAD);149 Intent action = new Intent(UbuntuInstallService.CLEAN_DOWNLOAD);
145 startService(action);150 startService(action);
@@ -151,13 +156,13 @@
151 // do we need to download release, or there is already one downloaded156 // do we need to download release, or there is already one downloaded
152 // user might have missed SU request, then we have downloaded release and we just need deploy it157 // user might have missed SU request, then we have downloaded release and we just need deploy it
153 // TODO: we will need to handle also download resume158 // TODO: we will need to handle also download resume
154 if (mStatus == ActivityStatus.DOWNLOADING) {159 if (mStatus == InstallerState.DOWNLOADING) {
155 Intent startInstall = new Intent(UbuntuInstallService.CANCEL_DOWNLOAD);160 Intent startInstall = new Intent(UbuntuInstallService.CANCEL_DOWNLOAD);
156 startService(startInstall);161 startService(startInstall);
157 } else if (mStatus == ActivityStatus.INSTALLING) {162 } else if (mStatus == InstallerState.INSTALLING) {
158 Intent startInstall = new Intent(UbuntuInstallService.CANCEL_INSTALL);163 Intent startInstall = new Intent(UbuntuInstallService.CANCEL_INSTALL);
159 startService(startInstall);164 startService(startInstall);
160 } else if (Utils.checkifReadyToInstall(v.getContext())) { 165 } else if (UbuntuInstallService.checkifReadyToInstall(v.getContext())) {
161 startInstallationIfPossible();166 startInstallationIfPossible();
162 } else if (0 != mAvailableChannels.size()) {167 } else if (0 != mAvailableChannels.size()) {
163 // get list of aliases as array168 // get list of aliases as array
@@ -178,7 +183,7 @@
178 true /* default latest settings*/).show();183 true /* default latest settings*/).show();
179 } else {184 } else {
180 // there are no channels to pick from, this was mistake, disable button185 // there are no channels to pick from, this was mistake, disable button
181 mStatus = ActivityStatus.NO_CHANNELS;186 mStatus = InstallerState.READY;
182 updateUiElements();187 updateUiElements();
183 }188 }
184 }189 }
@@ -202,7 +207,7 @@
202 Utils.showToast(this, "Starting Ubuntu installation");207 Utils.showToast(this, "Starting Ubuntu installation");
203 // reset progress bar208 // reset progress bar
204 mProgressBar.setProgress(0);209 mProgressBar.setProgress(0);
205 mStatus = ActivityStatus.INSTALLING;210 mStatus = InstallerState.INSTALLING;
206 updateUiElements();211 updateUiElements();
207 }212 }
208 213
@@ -231,7 +236,7 @@
231 startService(startDownload);236 startService(startDownload);
232 mTerminal.setText(R.string.downloading_starting);237 mTerminal.setText(R.string.downloading_starting);
233 mProgressBar.setProgress(0);238 mProgressBar.setProgress(0);
234 mStatus = ActivityStatus.DOWNLOADING;239 mStatus = InstallerState.DOWNLOADING;
235 updateUiElements();240 updateUiElements();
236 }241 }
237 242
@@ -278,12 +283,28 @@
278283
279 private void updateUiElements() {284 private void updateUiElements() {
280 switch (mStatus) {285 switch (mStatus) {
281 case NORMAL:286 case READY:
282 mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_fetching)));287 {
283 mInstallButton.setEnabled(false);288 if (mDownloadedVersion != null) {
284 mProgressBar.setEnabled(false);289 mInstallButton.setText(R.string.install_button_label_resume);
285 mProgressBar.setProgress(0);290 mInstallButton.setEnabled(true);
286 mProgressText.setText("");291 mProgressBar.setEnabled(false);
292 mProgressBar.setProgress(0);
293 mProgressText.setText("");
294 } else if (mAvailableChannels.size() > 0) {
295 mInstallButton.setText(R.string.install_button_label_install);
296 mInstallButton.setEnabled(true);
297 mProgressBar.setEnabled(false);
298 mProgressBar.setProgress(0);
299 mProgressText.setText("");
300 } else {
301 mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_no_channel)));
302 mInstallButton.setEnabled(false);
303 mProgressBar.setEnabled(false);
304 mProgressBar.setProgress(0);
305 mProgressText.setText("");
306 }
307 }
287 break;308 break;
288 case FETCHING_CHANNELS:309 case FETCHING_CHANNELS:
289 mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_fetching)));310 mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_fetching)));
@@ -292,27 +313,6 @@
292 mProgressBar.setProgress(0);313 mProgressBar.setProgress(0);
293 mProgressText.setText("");314 mProgressText.setText("");
294 break; 315 break;
295 case NO_CHANNELS:
296 mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_no_channel)));
297 mInstallButton.setEnabled(false);
298 mProgressBar.setEnabled(false);
299 mProgressBar.setProgress(0);
300 mProgressText.setText("");
301 break;
302 case READY_TO_DOWNLOAD:
303 mInstallButton.setText(R.string.install_button_label_install);
304 mInstallButton.setEnabled(true);
305 mProgressBar.setEnabled(false);
306 mProgressBar.setProgress(0);
307 mProgressText.setText("");
308 break;
309 case READY_TO_INSTALL:
310 mInstallButton.setText(R.string.install_button_label_resume);
311 mInstallButton.setEnabled(true);
312 mProgressBar.setEnabled(false);
313 mProgressBar.setProgress(0);
314 mProgressText.setText("");
315 break;
316 case DOWNLOADING:316 case DOWNLOADING:
317 mInstallButton.setText(R.string.install_button_label_cancel);317 mInstallButton.setText(R.string.install_button_label_cancel);
318 mInstallButton.setEnabled(true);318 mInstallButton.setEnabled(true);
@@ -338,19 +338,12 @@
338 // List of available channels fetched 338 // List of available channels fetched
339 if (action.equals(UbuntuInstallService.AVAILABLE_CHANNELS)) {339 if (action.equals(UbuntuInstallService.AVAILABLE_CHANNELS)) {
340 // ignore channel list if we have already downloaded release340 // ignore channel list if we have already downloaded release
341 if (!Utils.checkifReadyToInstall(context)) {341 if (!UbuntuInstallService.checkifReadyToInstall(context)) {
342 mAvailableChannels = (HashMap<String, String>) 342 mAvailableChannels = (HashMap<String, String>)
343 intent.getSerializableExtra(UbuntuInstallService.AVAILABLE_CHANNELS_EXTRA_CHANNELS);343 intent.getSerializableExtra(UbuntuInstallService.AVAILABLE_CHANNELS_EXTRA_CHANNELS);
344 if (0 != mAvailableChannels.size()) {344 mStatus = InstallerState.READY;
345 mStatus = ActivityStatus.READY_TO_DOWNLOAD;345 updateUiElements();
346 updateUiElements();
347 } else {
348 // we have no channels to choose from
349 mStatus = ActivityStatus.NO_CHANNELS;
350 updateUiElements();
351 }
352 }346 }
353
354 // Handle progress347 // Handle progress
355 } else if (action.equals(UbuntuInstallService.PROGRESS)) {348 } else if (action.equals(UbuntuInstallService.PROGRESS)) {
356 String p = intent.getStringExtra(UbuntuInstallService.PROGRESS_EXTRA_TEXT);349 String p = intent.getStringExtra(UbuntuInstallService.PROGRESS_EXTRA_TEXT);
@@ -379,12 +372,15 @@
379 updateInfoOnUiThread(reason);372 updateInfoOnUiThread(reason);
380 // if we still have download go back to resume installation373 // if we still have download go back to resume installation
381 // TODO: we should distinguish between resume/retry374 // TODO: we should distinguish between resume/retry
382 if (Utils.checkifReadyToInstall(context)) {375 mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context);
383 mStatus = ActivityStatus.READY_TO_INSTALL;376 if (UbuntuInstallService.checkifReadyToInstall(context)) {
377 mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context);
378 mStatus = InstallerState.READY;
384 } else {379 } else {
385 mStatus = ActivityStatus.NORMAL;
386 deleteDownload();380 deleteDownload();
381 mDownloadedVersion = null;
387 requestChannelList();382 requestChannelList();
383 mStatus = InstallerState.FETCHING_CHANNELS;
388 }384 }
389 updateUiElements();385 updateUiElements();
390 }386 }
@@ -405,18 +401,31 @@
405 updateInfoOnUiThread(reason);401 updateInfoOnUiThread(reason);
406 // delete failed download402 // delete failed download
407 deleteDownload();403 deleteDownload();
408 mStatus = ActivityStatus.NORMAL;404 mStatus = InstallerState.READY;
409 updateUiElements();405 updateUiElements();
410 requestChannelList();406 requestChannelList();
411 }407 }
412 } else if (action.equals(UbuntuInstallService.VERSION_UPDATE)408 } else if (action.equals(UbuntuInstallService.VERSION_UPDATE)) {
413 || action.equals(UbuntuInstallService.SERVICE_STATE)) {
414 checkIfUbuntuIsInstalled();409 checkIfUbuntuIsInstalled();
415 if (!isFinishing()) {410 if (!isFinishing()) {
416 // check what button should be shown411 // check what button should be shown
417 if (Utils.checkifReadyToInstall(context)) {412 if (UbuntuInstallService.checkifReadyToInstall(context)) {
418 mStatus = ActivityStatus.READY_TO_INSTALL;413 mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context);
419 }414 mStatus = InstallerState.READY;
415 }
416 updateUiElements();
417 }
418 } else if (action.equals(UbuntuInstallService.SERVICE_STATE)) {
419 checkIfUbuntuIsInstalled();
420 if (!isFinishing()) {
421 mStatus = InstallerState.fromOrdian(intent.getIntExtra(UbuntuInstallService.SERVICE_STATE, 0));
422 if (mStatus != InstallerState.FETCHING_CHANNELS &&
423 mStatus != InstallerState.DOWNLOADING &&
424 mStatus != InstallerState.INSTALLING) {
425 requestChannelList();
426 mStatus = InstallerState.FETCHING_CHANNELS;
427 }
428 mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context);
420 updateUiElements();429 updateUiElements();
421 }430 }
422 }431 }
423432
=== modified file 'src/com/canonical/ubuntu/installer/LaunchActivity.java'
--- src/com/canonical/ubuntu/installer/LaunchActivity.java 2013-12-18 01:01:21 +0000
+++ src/com/canonical/ubuntu/installer/LaunchActivity.java 2013-12-18 11:59:13 +0000
@@ -12,7 +12,6 @@
12import android.content.DialogInterface;12import android.content.DialogInterface;
13import android.content.Intent;13import android.content.Intent;
14import android.content.IntentFilter;14import android.content.IntentFilter;
15import android.content.SharedPreferences;
16import android.os.Bundle;15import android.os.Bundle;
17import android.os.PowerManager;16import android.os.PowerManager;
18import android.view.Menu;17import android.view.Menu;
@@ -149,7 +148,6 @@
149 }148 }
150149
151 private void fillInstalledVersionInfo() {150 private void fillInstalledVersionInfo() {
152 SharedPreferences pref = getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE);
153 mTextChannel.setText(mUbuntuVersion.getChannelAlias());151 mTextChannel.setText(mUbuntuVersion.getChannelAlias());
154 mTextVersion.setText(Integer.toString(mUbuntuVersion.getVersion()));152 mTextVersion.setText(Integer.toString(mUbuntuVersion.getVersion()));
155 mTextDescription.setText(mUbuntuVersion.getDescription());153 mTextDescription.setText(mUbuntuVersion.getDescription());
@@ -159,12 +157,12 @@
159 }157 }
160 158
161 private void ensureUbuntuIsInstalled() {159 private void ensureUbuntuIsInstalled() {
162 SharedPreferences pref = getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE);160 VersionInfo v = UbuntuInstallService.getInstalledVersion(this.getApplicationContext());
163 if (!VersionInfo.hasValidVersion(pref, UbuntuInstallService.PREF_KEY_INSTALLED_VERSION)) {161 if (v == null) {
164 // go back to install screen162 // go back to install screen
165 InstallActivity.startFrom(this);163 InstallActivity.startFrom(this);
166 } else {164 } else {
167 mUbuntuVersion = new VersionInfo(pref, UbuntuInstallService.PREF_KEY_INSTALLED_VERSION);165 mUbuntuVersion = v;
168 }166 }
169 }167 }
170 168
171169
=== modified file 'src/com/canonical/ubuntu/installer/UbuntuInstallService.java'
--- src/com/canonical/ubuntu/installer/UbuntuInstallService.java 2013-12-18 01:07:42 +0000
+++ src/com/canonical/ubuntu/installer/UbuntuInstallService.java 2013-12-18 11:59:13 +0000
@@ -44,9 +44,9 @@
44 // Key for string value: absolute path to update file44 // Key for string value: absolute path to update file
45 public final static String PREF_KEY_UPDATE_COMMAND = "update_command";45 public final static String PREF_KEY_UPDATE_COMMAND = "update_command";
46 // Key for String set value: version information: alias, Json, version, description 46 // Key for String set value: version information: alias, Json, version, description
47 public final static String PREF_KEY_DOWNLOADED_VERSION = "d_version";47 private final static String PREF_KEY_DOWNLOADED_VERSION = "d_version";
48 // Key for String set value: version information: alias, Json, version, description48 // Key for String set value: version information: alias, Json, version, description
49 public final static String PREF_KEY_INSTALLED_VERSION = "i_version";49 private final static String PREF_KEY_INSTALLED_VERSION = "i_version";
50 // Key for boolean value: true if developer option is enabled50 // Key for boolean value: true if developer option is enabled
51 public final static String PREF_KEY_DEVELOPER = "developer";51 public final static String PREF_KEY_DEVELOPER = "developer";
52 // Key for int value: estimated number of checkpoints for installation52 // Key for int value: estimated number of checkpoints for installation
@@ -93,7 +93,7 @@
93 // Service broadcast93 // Service broadcast
94 // =================================================================================================94 // =================================================================================================
95 public static final String SERVICE_STATE = "com.canonical.ubuntuinstaller.UbuntuInstallService.SERVICE_STATE";95 public static final String SERVICE_STATE = "com.canonical.ubuntuinstaller.UbuntuInstallService.SERVICE_STATE";
96 public static final String SERVICE_STATE_EXTRA_STATE = "state"; // ServiceState enum96 public static final String SERVICE_STATE_EXTRA_STATE = "state"; // InstallerState enum
97 public static final String AVAILABLE_CHANNELS = "com.canonical.ubuntuinstaller.UbuntuInstallService.AVAILABLE_CHANNELS";97 public static final String AVAILABLE_CHANNELS = "com.canonical.ubuntuinstaller.UbuntuInstallService.AVAILABLE_CHANNELS";
98 public static final String AVAILABLE_CHANNELS_EXTRA_CHANNELS = "channels"; // HashMap<String,String> channel aliases and json url98 public static final String AVAILABLE_CHANNELS_EXTRA_CHANNELS = "channels"; // HashMap<String,String> channel aliases and json url
99 public static final String DOWNLOAD_RESULT = "com.canonical.ubuntuinstaller.UbuntuInstallService.DOWNLOAD_RESULT";99 public static final String DOWNLOAD_RESULT = "com.canonical.ubuntuinstaller.UbuntuInstallService.DOWNLOAD_RESULT";
@@ -128,10 +128,13 @@
128 /**128 /**
129 * State of the service 129 * State of the service
130 */130 */
131 public enum ServiceState {131 public enum InstallerState {
132 READY, FETCHING_CHANNELS, DOWNLOADING, INSTALLING, UNINSTALLING_UBUNTU, DELETING_USER_DATA 132 READY, FETCHING_CHANNELS, DOWNLOADING, INSTALLING, UNINSTALLING, DELETING_USER_DATA;
133 public static InstallerState fromOrdian(int ordianl) {
134 return InstallerState.values()[ordianl];
135 }
133 }136 }
134 137
135 // =================================================================================================138 // =================================================================================================
136 // Packed assets139 // Packed assets
137 // =================================================================================================140 // =================================================================================================
@@ -175,7 +178,7 @@
175 private long mProgress; // so far handled amount downloaded/processed 178 private long mProgress; // so far handled amount downloaded/processed
176 private int mLastSignalledProgress;179 private int mLastSignalledProgress;
177 private long mTotalSize; // calculated180 private long mTotalSize; // calculated
178 private ServiceState mServiceState;181 private InstallerState mServiceState;
179 182
180 public class Channel {183 public class Channel {
181 String alias;184 String alias;
@@ -224,13 +227,13 @@
224 mRootOfWorkPath = getFilesDir().toString(); // "/data/data/com.canonical.ubuntuinstaller/files";227 mRootOfWorkPath = getFilesDir().toString(); // "/data/data/com.canonical.ubuntuinstaller/files";
225 workPathInCache = false;228 workPathInCache = false;
226 }229 }
227 mServiceState = ServiceState.READY;230 mServiceState = InstallerState.READY;
228 }231 }
229232
230 @Override233 @Override
231 public int onStartCommand(Intent intent, int flags, int startId) {234 public int onStartCommand(Intent intent, int flags, int startId) {
232 // if service is not in ready state, handle specific requests here235 // if service is not in ready state, handle specific requests here
233 if (mServiceState != ServiceState.READY) {236 if (mServiceState != InstallerState.READY) {
234 String action = intent.getAction(); 237 String action = intent.getAction();
235 if (action.equals(CANCEL_DOWNLOAD)) {238 if (action.equals(CANCEL_DOWNLOAD)) {
236 // set the cancel flag, but let it remove downloaded files on worker thread239 // set the cancel flag, but let it remove downloaded files on worker thread
@@ -248,44 +251,36 @@
248 protected void onHandleIntent(Intent intent) {251 protected void onHandleIntent(Intent intent) {
249 String action = intent.getAction();252 String action = intent.getAction();
250 Intent result = null;253 Intent result = null;
254
255 Log.d(TAG, this.toString() + " onHandleIntent: " + action);
251 if (action.equals(GET_CHANNEL_LIST)) {256 if (action.equals(GET_CHANNEL_LIST)) {
252 mServiceState = ServiceState.FETCHING_CHANNELS;257 mServiceState = InstallerState.FETCHING_CHANNELS;
253 Log.d(TAG, this.toString() + ": GET_CHANNEL_LIST");
254 result = doGetChannelList(intent);258 result = doGetChannelList(intent);
255 } else if (action.equals(DOWNLOAD_RELEASE)) {259 } else if (action.equals(DOWNLOAD_RELEASE)) {
256 Log.d(TAG, this.toString() + ": DOWNLOAD_RELEASE");260 mServiceState = InstallerState.DOWNLOADING;
257 mServiceState = ServiceState.DOWNLOADING;
258 result = doDownloadRelease(intent);261 result = doDownloadRelease(intent);
259 } else if (action.equals(CANCEL_DOWNLOAD)) {262 } else if (action.equals(CANCEL_DOWNLOAD)) {
260 Log.d(TAG, this.toString() + ": CANCEL_DOWNLOAD");
261 // download should be already cancelled, now delete all the files263 // download should be already cancelled, now delete all the files
262 result = doRemoreDownload(intent);264 result = doRemoreDownload(intent);
263 } else if (action.equals(PAUSE_DOWNLOAD)) {265 } else if (action.equals(PAUSE_DOWNLOAD)) {
264 Log.d(TAG, this.toString() + ": PAUSE_DOWNLOAD");
265 // TODO: handle download266 // TODO: handle download
266 } else if (action.equals(RESUME_DOWNLOAD)) {267 } else if (action.equals(RESUME_DOWNLOAD)) {
267 Log.d(TAG, this.toString() + ": RESUME_DOWNLOAD");268 mServiceState = InstallerState.DOWNLOADING;
268 mServiceState = ServiceState.DOWNLOADING;
269 // TODO: handle download269 // TODO: handle download
270 } else if (action.equals(CLEAN_DOWNLOAD)) {270 } else if (action.equals(CLEAN_DOWNLOAD)) {
271 Log.d(TAG, this.toString() + ": CLEAN_DOWNLOAD");
272 result = doRemoreDownload(intent);271 result = doRemoreDownload(intent);
273 } else if (action.equals(INSTALL_UBUNTU)) {272 } else if (action.equals(INSTALL_UBUNTU)) {
274 Log.d(TAG, this.toString() + ": INSTALL_UBUNTU");273 mServiceState = InstallerState.INSTALLING;
275 mServiceState = ServiceState.INSTALLING;
276 result = doInstallUbuntu(intent);274 result = doInstallUbuntu(intent);
277 } else if (action.equals(CANCEL_INSTALL)) {275 } else if (action.equals(CANCEL_INSTALL)) {
278 Log.d(TAG, this.toString() + ": CANCEL_INSTALL");
279 // install should be already cancelled, try to delete it now276 // install should be already cancelled, try to delete it now
280 mServiceState = ServiceState.UNINSTALLING_UBUNTU;277 mServiceState = InstallerState.UNINSTALLING;
281 result = doUninstallUbuntu(intent);278 result = doUninstallUbuntu(intent);
282 } else if (action.equals(UNINSTALL_UBUNTU)) {279 } else if (action.equals(UNINSTALL_UBUNTU)) {
283 Log.d(TAG, this.toString() + ": UNINSTALL_UBUNTU");280 mServiceState = InstallerState.UNINSTALLING;
284 mServiceState = ServiceState.UNINSTALLING_UBUNTU;
285 result = doUninstallUbuntu(intent);281 result = doUninstallUbuntu(intent);
286 } else if (action.equals(DELETE_UBUNTU_USER_DATA)) { 282 } else if (action.equals(DELETE_UBUNTU_USER_DATA)) {
287 Log.d(TAG, this.toString() + ": DELETE_UBUNTU_USER_DATA");283 mServiceState = InstallerState.DELETING_USER_DATA;
288 mServiceState = ServiceState.DELETING_USER_DATA;
289 result = doDeleteUbuntuUserData(intent);284 result = doDeleteUbuntuUserData(intent);
290 } else {285 } else {
291 // for any other request broadcast service state286 // for any other request broadcast service state
@@ -295,7 +290,8 @@
295 if (result != null) {290 if (result != null) {
296 sendBroadcast(result);291 sendBroadcast(result);
297 }292 }
298 mServiceState = ServiceState.READY;293 mServiceState = InstallerState.READY;
294 Log.d(TAG, this.toString() + " onHandleIntent: " + action + " END");
299 }295 }
300 296
301 private Intent doGetChannelList(Intent intent) {297 private Intent doGetChannelList(Intent intent) {
@@ -920,7 +916,7 @@
920 Log.w(TAG, "failed to remove old download");916 Log.w(TAG, "failed to remove old download");
921 return "failed to remove old download";917 return "failed to remove old download";
922 }918 }
923 SharedPreferences pref = getSharedPreferences( SHARED_PREF, Context.MODE_PRIVATE);919 SharedPreferences pref = getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE);
924 SharedPreferences.Editor editor = pref.edit();920 SharedPreferences.Editor editor = pref.edit();
925 editor.putString(PREF_KEY_UPDATE_COMMAND, "");921 editor.putString(PREF_KEY_UPDATE_COMMAND, "");
926 VersionInfo.storeEmptyVersion(editor, PREF_KEY_DOWNLOADED_VERSION);922 VersionInfo.storeEmptyVersion(editor, PREF_KEY_DOWNLOADED_VERSION);
@@ -970,4 +966,49 @@
970 return true;966 return true;
971 }967 }
972968
969 private static VersionInfo getVersionWithPrefKey(Context c, String prefKey) {
970 SharedPreferences pref = c.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE);
971
972 if (VersionInfo.hasValidVersion(pref, prefKey)) {
973 return new VersionInfo(pref, prefKey);
974 }
975 return null;
976 }
977
978 public static VersionInfo getDownloadedVersion(Context c) {
979 return getVersionWithPrefKey(c, PREF_KEY_DOWNLOADED_VERSION);
980 }
981
982 public static VersionInfo getInstalledVersion(Context c) {
983 return getVersionWithPrefKey(c, PREF_KEY_INSTALLED_VERSION);
984 }
985 public static boolean isUbuntuInstalled(Context c) {
986 SharedPreferences pref = c.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE);
987 if (VersionInfo.hasValidVersion(pref, PREF_KEY_INSTALLED_VERSION)) {
988 // go to launch screen
989 return true;
990 }
991 return false;
992 }
993
994 /**
995 * Check if there is downloaded release ready to install
996 * @param context
997 * @return true if there is downloaded release ready to install
998 */
999 public static boolean checkifReadyToInstall(Context context) {
1000 SharedPreferences pref = context.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE);
1001 String command = pref.getString(PREF_KEY_UPDATE_COMMAND, "");
1002 boolean ready = false;
1003 if (!command.equals("")){
1004 File f = new File(command);
1005 if (f.exists()) {
1006 return true;
1007 } else {
1008 pref.edit().putString(PREF_KEY_UPDATE_COMMAND, "").commit();
1009 return false;
1010 }
1011 }
1012 return false;
1013 }
973}1014}
9741015
=== modified file 'src/com/canonical/ubuntu/installer/Utils.java'
--- src/com/canonical/ubuntu/installer/Utils.java 2013-12-18 01:07:42 +0000
+++ src/com/canonical/ubuntu/installer/Utils.java 2013-12-18 11:59:13 +0000
@@ -74,7 +74,7 @@
74 String result= convertStreamToString(instream);74 String result= convertStreamToString(instream);
75 // now you have the string representation of the HTML request75 // now you have the string representation of the HTML request
7676
77 Log.i(TAG, result);77 // Log.i(TAG, result);
7878
79 instream.close();79 instream.close();
8080
@@ -184,27 +184,6 @@
184 }184 }
185 return size;185 return size;
186 }186 }
187
188 /**
189 * Check if there is downloaded release ready to install
190 * @param context
191 * @return true if there is downloaded release ready to install
192 */
193 public static boolean checkifReadyToInstall(Context context) {
194 SharedPreferences pref = context.getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE);
195 String command = pref.getString(UbuntuInstallService.PREF_KEY_UPDATE_COMMAND, "");
196 boolean ready = false;
197 if (!command.equals("")){
198 File f = new File(command);
199 if (f.exists()) {
200 return true;
201 } else {
202 pref.edit().putString(UbuntuInstallService.PREF_KEY_UPDATE_COMMAND, "").commit();
203 return false;
204 }
205 }
206 return false;
207 }
208187
209 @SuppressWarnings("deprecation")188 @SuppressWarnings("deprecation")
210 public static long getFreeSpaceInBytes(String fsPath) {189 public static long getFreeSpaceInBytes(String fsPath) {
@@ -225,7 +204,7 @@
225 }204 }
226 return "";205 return "";
227 }206 }
228 207
229 public static String getRecoveryPartitionPath() {208 public static String getRecoveryPartitionPath() {
230 String deviceModel = Build.DEVICE.toLowerCase(Locale.US);209 String deviceModel = Build.DEVICE.toLowerCase(Locale.US);
231 if ("mako".equals(deviceModel)) {210 if ("mako".equals(deviceModel)) {

Subscribers

People subscribed via source and target branches

to all changes: