Merge lp:~humpolec-team/humpolec/UbuntuInstaller_lp1262034 into lp:humpolec
- UbuntuInstaller_lp1262034
- Merge into UbuntuInstaller
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rex Tsai | Approve | ||
Review via email: mp+199404@code.launchpad.net |
Commit message
Description of the change
1. Rename ServiceState to InstallerState in UbuntuInstallSe
2. Use InstallerState, mAvailableChann
and mDownloadedVersion to decide what to show on UI.
3. move some preference related function to UbuntuInstallSe
4. call requestServiceS
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.
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.
}
- 21. By Yuan-Chen Cheng
-
cleaner way for doing fromOrdian for java enum
Preview Diff
1 | === modified file 'src/com/canonical/ubuntu/installer/InstallActivity.java' |
2 | --- src/com/canonical/ubuntu/installer/InstallActivity.java 2013-12-16 13:16:32 +0000 |
3 | +++ src/com/canonical/ubuntu/installer/InstallActivity.java 2013-12-18 11:59:13 +0000 |
4 | @@ -7,6 +7,7 @@ |
5 | import com.canonical.ubuntu.installer.TextPickerDialog; |
6 | import com.canonical.ubuntu.installer.UbuntuInstallService; |
7 | import com.canonical.ubuntu.installer.JsonChannelParser.Image; |
8 | +import com.canonical.ubuntu.installer.UbuntuInstallService.InstallerState; |
9 | import com.canonical.ubuntu.installer.VersionInfo.ReleaseType; |
10 | import com.canonical.ubuntu.widget.UbuntuButton; |
11 | |
12 | @@ -31,17 +32,16 @@ |
13 | public class InstallActivity extends Activity { |
14 | private static final String TAG = "UbuntuInstaller"; |
15 | |
16 | - private enum ActivityStatus { |
17 | - NORMAL, FETCHING_CHANNELS, NO_CHANNELS, READY_TO_DOWNLOAD, DOWNLOADING, READY_TO_INSTALL, INSTALLING |
18 | - }; |
19 | - |
20 | private UbuntuButton mInstallButton; |
21 | - private ActivityStatus mStatus = ActivityStatus.NORMAL; |
22 | + |
23 | + private InstallerState mStatus = InstallerState.READY; |
24 | + private VersionInfo mDownloadedVersion = null; |
25 | + |
26 | private ProgressBar mProgressBar; |
27 | private TextView mProgressText; |
28 | |
29 | private TextView mTerminal; |
30 | - private HashMap<String, String> mAvailableChannels; |
31 | + private HashMap<String, String> mAvailableChannels = new HashMap<String, String>(); |
32 | |
33 | @Override |
34 | protected void onCreate(Bundle savedInstanceState) { |
35 | @@ -56,12 +56,10 @@ |
36 | mProgressText = (TextView) findViewById(R.id.status); |
37 | mTerminal = (TextView) findViewById(R.id.terminal); |
38 | mTerminal.setMovementMethod(new ScrollingMovementMethod()); |
39 | - requestChannelList(); |
40 | - mStatus = ActivityStatus.FETCHING_CHANNELS; |
41 | mProgressBar.setEnabled(false); |
42 | mProgressBar.setProgress(0); |
43 | - |
44 | - SharedPreferences pref = getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE); |
45 | + |
46 | + SharedPreferences pref = getSharedPreferences(UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE); |
47 | pref.edit().putBoolean(UbuntuInstallService.PREF_KEY_DEVELOPER, true).commit(); |
48 | } |
49 | |
50 | @@ -81,15 +79,18 @@ |
51 | filter.addAction(UbuntuInstallService.VERSION_UPDATE); |
52 | filter.addAction(UbuntuInstallService.SERVICE_STATE); |
53 | registerReceiver(mServiceObserver, filter); |
54 | - |
55 | + |
56 | // do we know last activity |
57 | - if (mStatus == ActivityStatus.DOWNLOADING || mStatus == ActivityStatus.INSTALLING) { |
58 | + if (mStatus == InstallerState.READY) { |
59 | + requestServiceState(); |
60 | + mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(this.getApplicationContext()); |
61 | + } else if (mStatus == InstallerState.DOWNLOADING || mStatus == InstallerState.INSTALLING) { |
62 | // request last progress / status. this will update UI accordingly |
63 | - startService(new Intent(UbuntuInstallService.GET_PROGRESS_STATUS)); |
64 | + startService(new Intent(UbuntuInstallService.GET_PROGRESS_STATUS)); |
65 | } else { |
66 | - if (Utils.checkifReadyToInstall(this)) { |
67 | - mStatus = ActivityStatus.READY_TO_INSTALL; |
68 | - } |
69 | + // READY + mDownloadedVersion != null => READY_TO_INSTALL |
70 | + mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(this.getApplicationContext()); |
71 | + mStatus = InstallerState.READY; |
72 | updateUiElements(); |
73 | } |
74 | } |
75 | @@ -114,7 +115,8 @@ |
76 | switch (item.getItemId()) { |
77 | case R.id.action_delete_download: |
78 | deleteDownload(); |
79 | - mStatus = ActivityStatus.READY_TO_DOWNLOAD; |
80 | + mDownloadedVersion = null; |
81 | + mStatus = InstallerState.READY; |
82 | updateUiElements(); |
83 | break; |
84 | } |
85 | @@ -126,20 +128,23 @@ |
86 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
87 | context.startActivity(intent); |
88 | } |
89 | - |
90 | + |
91 | private void checkIfUbuntuIsInstalled() { |
92 | // check is there is Ubuntu installed |
93 | - SharedPreferences pref = getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE); |
94 | - if (VersionInfo.hasValidVersion(pref, UbuntuInstallService.PREF_KEY_INSTALLED_VERSION)) { |
95 | + if (UbuntuInstallService.isUbuntuInstalled(this.getApplicationContext())) { |
96 | // go to launch screen |
97 | - LaunchActivity.startFrom(this);; |
98 | + LaunchActivity.startFrom(this); |
99 | } |
100 | } |
101 | - |
102 | + |
103 | private void requestChannelList() { |
104 | startService(new Intent(UbuntuInstallService.GET_CHANNEL_LIST)); |
105 | } |
106 | |
107 | + private void requestServiceState() { |
108 | + startService(new Intent(UbuntuInstallService.GET_SERVICE_STATE)); |
109 | + } |
110 | + |
111 | private void deleteDownload() { |
112 | Intent action = new Intent(UbuntuInstallService.CLEAN_DOWNLOAD); |
113 | startService(action); |
114 | @@ -151,13 +156,13 @@ |
115 | // do we need to download release, or there is already one downloaded |
116 | // user might have missed SU request, then we have downloaded release and we just need deploy it |
117 | // TODO: we will need to handle also download resume |
118 | - if (mStatus == ActivityStatus.DOWNLOADING) { |
119 | + if (mStatus == InstallerState.DOWNLOADING) { |
120 | Intent startInstall = new Intent(UbuntuInstallService.CANCEL_DOWNLOAD); |
121 | startService(startInstall); |
122 | - } else if (mStatus == ActivityStatus.INSTALLING) { |
123 | + } else if (mStatus == InstallerState.INSTALLING) { |
124 | Intent startInstall = new Intent(UbuntuInstallService.CANCEL_INSTALL); |
125 | startService(startInstall); |
126 | - } else if (Utils.checkifReadyToInstall(v.getContext())) { |
127 | + } else if (UbuntuInstallService.checkifReadyToInstall(v.getContext())) { |
128 | startInstallationIfPossible(); |
129 | } else if (0 != mAvailableChannels.size()) { |
130 | // get list of aliases as array |
131 | @@ -178,7 +183,7 @@ |
132 | true /* default latest settings*/).show(); |
133 | } else { |
134 | // there are no channels to pick from, this was mistake, disable button |
135 | - mStatus = ActivityStatus.NO_CHANNELS; |
136 | + mStatus = InstallerState.READY; |
137 | updateUiElements(); |
138 | } |
139 | } |
140 | @@ -202,7 +207,7 @@ |
141 | Utils.showToast(this, "Starting Ubuntu installation"); |
142 | // reset progress bar |
143 | mProgressBar.setProgress(0); |
144 | - mStatus = ActivityStatus.INSTALLING; |
145 | + mStatus = InstallerState.INSTALLING; |
146 | updateUiElements(); |
147 | } |
148 | |
149 | @@ -231,7 +236,7 @@ |
150 | startService(startDownload); |
151 | mTerminal.setText(R.string.downloading_starting); |
152 | mProgressBar.setProgress(0); |
153 | - mStatus = ActivityStatus.DOWNLOADING; |
154 | + mStatus = InstallerState.DOWNLOADING; |
155 | updateUiElements(); |
156 | } |
157 | |
158 | @@ -278,12 +283,28 @@ |
159 | |
160 | private void updateUiElements() { |
161 | switch (mStatus) { |
162 | - case NORMAL: |
163 | - mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_fetching))); |
164 | - mInstallButton.setEnabled(false); |
165 | - mProgressBar.setEnabled(false); |
166 | - mProgressBar.setProgress(0); |
167 | - mProgressText.setText(""); |
168 | + case READY: |
169 | + { |
170 | + if (mDownloadedVersion != null) { |
171 | + mInstallButton.setText(R.string.install_button_label_resume); |
172 | + mInstallButton.setEnabled(true); |
173 | + mProgressBar.setEnabled(false); |
174 | + mProgressBar.setProgress(0); |
175 | + mProgressText.setText(""); |
176 | + } else if (mAvailableChannels.size() > 0) { |
177 | + mInstallButton.setText(R.string.install_button_label_install); |
178 | + mInstallButton.setEnabled(true); |
179 | + mProgressBar.setEnabled(false); |
180 | + mProgressBar.setProgress(0); |
181 | + mProgressText.setText(""); |
182 | + } else { |
183 | + mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_no_channel))); |
184 | + mInstallButton.setEnabled(false); |
185 | + mProgressBar.setEnabled(false); |
186 | + mProgressBar.setProgress(0); |
187 | + mProgressText.setText(""); |
188 | + } |
189 | + } |
190 | break; |
191 | case FETCHING_CHANNELS: |
192 | mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_fetching))); |
193 | @@ -292,27 +313,6 @@ |
194 | mProgressBar.setProgress(0); |
195 | mProgressText.setText(""); |
196 | break; |
197 | - case NO_CHANNELS: |
198 | - mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_no_channel))); |
199 | - mInstallButton.setEnabled(false); |
200 | - mProgressBar.setEnabled(false); |
201 | - mProgressBar.setProgress(0); |
202 | - mProgressText.setText(""); |
203 | - break; |
204 | - case READY_TO_DOWNLOAD: |
205 | - mInstallButton.setText(R.string.install_button_label_install); |
206 | - mInstallButton.setEnabled(true); |
207 | - mProgressBar.setEnabled(false); |
208 | - mProgressBar.setProgress(0); |
209 | - mProgressText.setText(""); |
210 | - break; |
211 | - case READY_TO_INSTALL: |
212 | - mInstallButton.setText(R.string.install_button_label_resume); |
213 | - mInstallButton.setEnabled(true); |
214 | - mProgressBar.setEnabled(false); |
215 | - mProgressBar.setProgress(0); |
216 | - mProgressText.setText(""); |
217 | - break; |
218 | case DOWNLOADING: |
219 | mInstallButton.setText(R.string.install_button_label_cancel); |
220 | mInstallButton.setEnabled(true); |
221 | @@ -338,19 +338,12 @@ |
222 | // List of available channels fetched |
223 | if (action.equals(UbuntuInstallService.AVAILABLE_CHANNELS)) { |
224 | // ignore channel list if we have already downloaded release |
225 | - if (!Utils.checkifReadyToInstall(context)) { |
226 | + if (!UbuntuInstallService.checkifReadyToInstall(context)) { |
227 | mAvailableChannels = (HashMap<String, String>) |
228 | intent.getSerializableExtra(UbuntuInstallService.AVAILABLE_CHANNELS_EXTRA_CHANNELS); |
229 | - if (0 != mAvailableChannels.size()) { |
230 | - mStatus = ActivityStatus.READY_TO_DOWNLOAD; |
231 | - updateUiElements(); |
232 | - } else { |
233 | - // we have no channels to choose from |
234 | - mStatus = ActivityStatus.NO_CHANNELS; |
235 | - updateUiElements(); |
236 | - } |
237 | + mStatus = InstallerState.READY; |
238 | + updateUiElements(); |
239 | } |
240 | - |
241 | // Handle progress |
242 | } else if (action.equals(UbuntuInstallService.PROGRESS)) { |
243 | String p = intent.getStringExtra(UbuntuInstallService.PROGRESS_EXTRA_TEXT); |
244 | @@ -379,12 +372,15 @@ |
245 | updateInfoOnUiThread(reason); |
246 | // if we still have download go back to resume installation |
247 | // TODO: we should distinguish between resume/retry |
248 | - if (Utils.checkifReadyToInstall(context)) { |
249 | - mStatus = ActivityStatus.READY_TO_INSTALL; |
250 | + mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); |
251 | + if (UbuntuInstallService.checkifReadyToInstall(context)) { |
252 | + mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); |
253 | + mStatus = InstallerState.READY; |
254 | } else { |
255 | - mStatus = ActivityStatus.NORMAL; |
256 | deleteDownload(); |
257 | + mDownloadedVersion = null; |
258 | requestChannelList(); |
259 | + mStatus = InstallerState.FETCHING_CHANNELS; |
260 | } |
261 | updateUiElements(); |
262 | } |
263 | @@ -405,18 +401,31 @@ |
264 | updateInfoOnUiThread(reason); |
265 | // delete failed download |
266 | deleteDownload(); |
267 | - mStatus = ActivityStatus.NORMAL; |
268 | + mStatus = InstallerState.READY; |
269 | updateUiElements(); |
270 | requestChannelList(); |
271 | } |
272 | - } else if (action.equals(UbuntuInstallService.VERSION_UPDATE) |
273 | - || action.equals(UbuntuInstallService.SERVICE_STATE)) { |
274 | + } else if (action.equals(UbuntuInstallService.VERSION_UPDATE)) { |
275 | checkIfUbuntuIsInstalled(); |
276 | if (!isFinishing()) { |
277 | // check what button should be shown |
278 | - if (Utils.checkifReadyToInstall(context)) { |
279 | - mStatus = ActivityStatus.READY_TO_INSTALL; |
280 | - } |
281 | + if (UbuntuInstallService.checkifReadyToInstall(context)) { |
282 | + mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); |
283 | + mStatus = InstallerState.READY; |
284 | + } |
285 | + updateUiElements(); |
286 | + } |
287 | + } else if (action.equals(UbuntuInstallService.SERVICE_STATE)) { |
288 | + checkIfUbuntuIsInstalled(); |
289 | + if (!isFinishing()) { |
290 | + mStatus = InstallerState.fromOrdian(intent.getIntExtra(UbuntuInstallService.SERVICE_STATE, 0)); |
291 | + if (mStatus != InstallerState.FETCHING_CHANNELS && |
292 | + mStatus != InstallerState.DOWNLOADING && |
293 | + mStatus != InstallerState.INSTALLING) { |
294 | + requestChannelList(); |
295 | + mStatus = InstallerState.FETCHING_CHANNELS; |
296 | + } |
297 | + mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); |
298 | updateUiElements(); |
299 | } |
300 | } |
301 | |
302 | === modified file 'src/com/canonical/ubuntu/installer/LaunchActivity.java' |
303 | --- src/com/canonical/ubuntu/installer/LaunchActivity.java 2013-12-18 01:01:21 +0000 |
304 | +++ src/com/canonical/ubuntu/installer/LaunchActivity.java 2013-12-18 11:59:13 +0000 |
305 | @@ -12,7 +12,6 @@ |
306 | import android.content.DialogInterface; |
307 | import android.content.Intent; |
308 | import android.content.IntentFilter; |
309 | -import android.content.SharedPreferences; |
310 | import android.os.Bundle; |
311 | import android.os.PowerManager; |
312 | import android.view.Menu; |
313 | @@ -149,7 +148,6 @@ |
314 | } |
315 | |
316 | private void fillInstalledVersionInfo() { |
317 | - SharedPreferences pref = getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE); |
318 | mTextChannel.setText(mUbuntuVersion.getChannelAlias()); |
319 | mTextVersion.setText(Integer.toString(mUbuntuVersion.getVersion())); |
320 | mTextDescription.setText(mUbuntuVersion.getDescription()); |
321 | @@ -159,12 +157,12 @@ |
322 | } |
323 | |
324 | private void ensureUbuntuIsInstalled() { |
325 | - SharedPreferences pref = getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE); |
326 | - if (!VersionInfo.hasValidVersion(pref, UbuntuInstallService.PREF_KEY_INSTALLED_VERSION)) { |
327 | + VersionInfo v = UbuntuInstallService.getInstalledVersion(this.getApplicationContext()); |
328 | + if (v == null) { |
329 | // go back to install screen |
330 | - InstallActivity.startFrom(this); |
331 | + InstallActivity.startFrom(this); |
332 | } else { |
333 | - mUbuntuVersion = new VersionInfo(pref, UbuntuInstallService.PREF_KEY_INSTALLED_VERSION); |
334 | + mUbuntuVersion = v; |
335 | } |
336 | } |
337 | |
338 | |
339 | === modified file 'src/com/canonical/ubuntu/installer/UbuntuInstallService.java' |
340 | --- src/com/canonical/ubuntu/installer/UbuntuInstallService.java 2013-12-18 01:07:42 +0000 |
341 | +++ src/com/canonical/ubuntu/installer/UbuntuInstallService.java 2013-12-18 11:59:13 +0000 |
342 | @@ -44,9 +44,9 @@ |
343 | // Key for string value: absolute path to update file |
344 | public final static String PREF_KEY_UPDATE_COMMAND = "update_command"; |
345 | // Key for String set value: version information: alias, Json, version, description |
346 | - public final static String PREF_KEY_DOWNLOADED_VERSION = "d_version"; |
347 | + private final static String PREF_KEY_DOWNLOADED_VERSION = "d_version"; |
348 | // Key for String set value: version information: alias, Json, version, description |
349 | - public final static String PREF_KEY_INSTALLED_VERSION = "i_version"; |
350 | + private final static String PREF_KEY_INSTALLED_VERSION = "i_version"; |
351 | // Key for boolean value: true if developer option is enabled |
352 | public final static String PREF_KEY_DEVELOPER = "developer"; |
353 | // Key for int value: estimated number of checkpoints for installation |
354 | @@ -93,7 +93,7 @@ |
355 | // Service broadcast |
356 | // ================================================================================================= |
357 | public static final String SERVICE_STATE = "com.canonical.ubuntuinstaller.UbuntuInstallService.SERVICE_STATE"; |
358 | - public static final String SERVICE_STATE_EXTRA_STATE = "state"; // ServiceState enum |
359 | + public static final String SERVICE_STATE_EXTRA_STATE = "state"; // InstallerState enum |
360 | public static final String AVAILABLE_CHANNELS = "com.canonical.ubuntuinstaller.UbuntuInstallService.AVAILABLE_CHANNELS"; |
361 | public static final String AVAILABLE_CHANNELS_EXTRA_CHANNELS = "channels"; // HashMap<String,String> channel aliases and json url |
362 | public static final String DOWNLOAD_RESULT = "com.canonical.ubuntuinstaller.UbuntuInstallService.DOWNLOAD_RESULT"; |
363 | @@ -128,10 +128,13 @@ |
364 | /** |
365 | * State of the service |
366 | */ |
367 | - public enum ServiceState { |
368 | - READY, FETCHING_CHANNELS, DOWNLOADING, INSTALLING, UNINSTALLING_UBUNTU, DELETING_USER_DATA |
369 | + public enum InstallerState { |
370 | + READY, FETCHING_CHANNELS, DOWNLOADING, INSTALLING, UNINSTALLING, DELETING_USER_DATA; |
371 | + public static InstallerState fromOrdian(int ordianl) { |
372 | + return InstallerState.values()[ordianl]; |
373 | + } |
374 | } |
375 | - |
376 | + |
377 | // ================================================================================================= |
378 | // Packed assets |
379 | // ================================================================================================= |
380 | @@ -175,7 +178,7 @@ |
381 | private long mProgress; // so far handled amount downloaded/processed |
382 | private int mLastSignalledProgress; |
383 | private long mTotalSize; // calculated |
384 | - private ServiceState mServiceState; |
385 | + private InstallerState mServiceState; |
386 | |
387 | public class Channel { |
388 | String alias; |
389 | @@ -224,13 +227,13 @@ |
390 | mRootOfWorkPath = getFilesDir().toString(); // "/data/data/com.canonical.ubuntuinstaller/files"; |
391 | workPathInCache = false; |
392 | } |
393 | - mServiceState = ServiceState.READY; |
394 | + mServiceState = InstallerState.READY; |
395 | } |
396 | |
397 | @Override |
398 | public int onStartCommand(Intent intent, int flags, int startId) { |
399 | // if service is not in ready state, handle specific requests here |
400 | - if (mServiceState != ServiceState.READY) { |
401 | + if (mServiceState != InstallerState.READY) { |
402 | String action = intent.getAction(); |
403 | if (action.equals(CANCEL_DOWNLOAD)) { |
404 | // set the cancel flag, but let it remove downloaded files on worker thread |
405 | @@ -248,44 +251,36 @@ |
406 | protected void onHandleIntent(Intent intent) { |
407 | String action = intent.getAction(); |
408 | Intent result = null; |
409 | + |
410 | + Log.d(TAG, this.toString() + " onHandleIntent: " + action); |
411 | if (action.equals(GET_CHANNEL_LIST)) { |
412 | - mServiceState = ServiceState.FETCHING_CHANNELS; |
413 | - Log.d(TAG, this.toString() + ": GET_CHANNEL_LIST"); |
414 | + mServiceState = InstallerState.FETCHING_CHANNELS; |
415 | result = doGetChannelList(intent); |
416 | } else if (action.equals(DOWNLOAD_RELEASE)) { |
417 | - Log.d(TAG, this.toString() + ": DOWNLOAD_RELEASE"); |
418 | - mServiceState = ServiceState.DOWNLOADING; |
419 | + mServiceState = InstallerState.DOWNLOADING; |
420 | result = doDownloadRelease(intent); |
421 | } else if (action.equals(CANCEL_DOWNLOAD)) { |
422 | - Log.d(TAG, this.toString() + ": CANCEL_DOWNLOAD"); |
423 | // download should be already cancelled, now delete all the files |
424 | result = doRemoreDownload(intent); |
425 | } else if (action.equals(PAUSE_DOWNLOAD)) { |
426 | - Log.d(TAG, this.toString() + ": PAUSE_DOWNLOAD"); |
427 | // TODO: handle download |
428 | } else if (action.equals(RESUME_DOWNLOAD)) { |
429 | - Log.d(TAG, this.toString() + ": RESUME_DOWNLOAD"); |
430 | - mServiceState = ServiceState.DOWNLOADING; |
431 | + mServiceState = InstallerState.DOWNLOADING; |
432 | // TODO: handle download |
433 | } else if (action.equals(CLEAN_DOWNLOAD)) { |
434 | - Log.d(TAG, this.toString() + ": CLEAN_DOWNLOAD"); |
435 | result = doRemoreDownload(intent); |
436 | } else if (action.equals(INSTALL_UBUNTU)) { |
437 | - Log.d(TAG, this.toString() + ": INSTALL_UBUNTU"); |
438 | - mServiceState = ServiceState.INSTALLING; |
439 | + mServiceState = InstallerState.INSTALLING; |
440 | result = doInstallUbuntu(intent); |
441 | } else if (action.equals(CANCEL_INSTALL)) { |
442 | - Log.d(TAG, this.toString() + ": CANCEL_INSTALL"); |
443 | // install should be already cancelled, try to delete it now |
444 | - mServiceState = ServiceState.UNINSTALLING_UBUNTU; |
445 | + mServiceState = InstallerState.UNINSTALLING; |
446 | result = doUninstallUbuntu(intent); |
447 | } else if (action.equals(UNINSTALL_UBUNTU)) { |
448 | - Log.d(TAG, this.toString() + ": UNINSTALL_UBUNTU"); |
449 | - mServiceState = ServiceState.UNINSTALLING_UBUNTU; |
450 | + mServiceState = InstallerState.UNINSTALLING; |
451 | result = doUninstallUbuntu(intent); |
452 | } else if (action.equals(DELETE_UBUNTU_USER_DATA)) { |
453 | - Log.d(TAG, this.toString() + ": DELETE_UBUNTU_USER_DATA"); |
454 | - mServiceState = ServiceState.DELETING_USER_DATA; |
455 | + mServiceState = InstallerState.DELETING_USER_DATA; |
456 | result = doDeleteUbuntuUserData(intent); |
457 | } else { |
458 | // for any other request broadcast service state |
459 | @@ -295,7 +290,8 @@ |
460 | if (result != null) { |
461 | sendBroadcast(result); |
462 | } |
463 | - mServiceState = ServiceState.READY; |
464 | + mServiceState = InstallerState.READY; |
465 | + Log.d(TAG, this.toString() + " onHandleIntent: " + action + " END"); |
466 | } |
467 | |
468 | private Intent doGetChannelList(Intent intent) { |
469 | @@ -920,7 +916,7 @@ |
470 | Log.w(TAG, "failed to remove old download"); |
471 | return "failed to remove old download"; |
472 | } |
473 | - SharedPreferences pref = getSharedPreferences( SHARED_PREF, Context.MODE_PRIVATE); |
474 | + SharedPreferences pref = getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE); |
475 | SharedPreferences.Editor editor = pref.edit(); |
476 | editor.putString(PREF_KEY_UPDATE_COMMAND, ""); |
477 | VersionInfo.storeEmptyVersion(editor, PREF_KEY_DOWNLOADED_VERSION); |
478 | @@ -970,4 +966,49 @@ |
479 | return true; |
480 | } |
481 | |
482 | + private static VersionInfo getVersionWithPrefKey(Context c, String prefKey) { |
483 | + SharedPreferences pref = c.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE); |
484 | + |
485 | + if (VersionInfo.hasValidVersion(pref, prefKey)) { |
486 | + return new VersionInfo(pref, prefKey); |
487 | + } |
488 | + return null; |
489 | + } |
490 | + |
491 | + public static VersionInfo getDownloadedVersion(Context c) { |
492 | + return getVersionWithPrefKey(c, PREF_KEY_DOWNLOADED_VERSION); |
493 | + } |
494 | + |
495 | + public static VersionInfo getInstalledVersion(Context c) { |
496 | + return getVersionWithPrefKey(c, PREF_KEY_INSTALLED_VERSION); |
497 | + } |
498 | + public static boolean isUbuntuInstalled(Context c) { |
499 | + SharedPreferences pref = c.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE); |
500 | + if (VersionInfo.hasValidVersion(pref, PREF_KEY_INSTALLED_VERSION)) { |
501 | + // go to launch screen |
502 | + return true; |
503 | + } |
504 | + return false; |
505 | + } |
506 | + |
507 | + /** |
508 | + * Check if there is downloaded release ready to install |
509 | + * @param context |
510 | + * @return true if there is downloaded release ready to install |
511 | + */ |
512 | + public static boolean checkifReadyToInstall(Context context) { |
513 | + SharedPreferences pref = context.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE); |
514 | + String command = pref.getString(PREF_KEY_UPDATE_COMMAND, ""); |
515 | + boolean ready = false; |
516 | + if (!command.equals("")){ |
517 | + File f = new File(command); |
518 | + if (f.exists()) { |
519 | + return true; |
520 | + } else { |
521 | + pref.edit().putString(PREF_KEY_UPDATE_COMMAND, "").commit(); |
522 | + return false; |
523 | + } |
524 | + } |
525 | + return false; |
526 | + } |
527 | } |
528 | |
529 | === modified file 'src/com/canonical/ubuntu/installer/Utils.java' |
530 | --- src/com/canonical/ubuntu/installer/Utils.java 2013-12-18 01:07:42 +0000 |
531 | +++ src/com/canonical/ubuntu/installer/Utils.java 2013-12-18 11:59:13 +0000 |
532 | @@ -74,7 +74,7 @@ |
533 | String result= convertStreamToString(instream); |
534 | // now you have the string representation of the HTML request |
535 | |
536 | - Log.i(TAG, result); |
537 | + // Log.i(TAG, result); |
538 | |
539 | instream.close(); |
540 | |
541 | @@ -184,27 +184,6 @@ |
542 | } |
543 | return size; |
544 | } |
545 | - |
546 | - /** |
547 | - * Check if there is downloaded release ready to install |
548 | - * @param context |
549 | - * @return true if there is downloaded release ready to install |
550 | - */ |
551 | - public static boolean checkifReadyToInstall(Context context) { |
552 | - SharedPreferences pref = context.getSharedPreferences( UbuntuInstallService.SHARED_PREF, Context.MODE_PRIVATE); |
553 | - String command = pref.getString(UbuntuInstallService.PREF_KEY_UPDATE_COMMAND, ""); |
554 | - boolean ready = false; |
555 | - if (!command.equals("")){ |
556 | - File f = new File(command); |
557 | - if (f.exists()) { |
558 | - return true; |
559 | - } else { |
560 | - pref.edit().putString(UbuntuInstallService.PREF_KEY_UPDATE_COMMAND, "").commit(); |
561 | - return false; |
562 | - } |
563 | - } |
564 | - return false; |
565 | - } |
566 | |
567 | @SuppressWarnings("deprecation") |
568 | public static long getFreeSpaceInBytes(String fsPath) { |
569 | @@ -225,7 +204,7 @@ |
570 | } |
571 | return ""; |
572 | } |
573 | - |
574 | + |
575 | public static String getRecoveryPartitionPath() { |
576 | String deviceModel = Build.DEVICE.toLowerCase(Locale.US); |
577 | if ("mako".equals(deviceModel)) { |
LGTM, +1