Merge lp:~humpolec-team/humpolec/UbuntuInstaller-alfa-release-fixes into lp:humpolec
- UbuntuInstaller-alfa-release-fixes
- Merge into UbuntuInstaller
Status: | Merged |
---|---|
Merged at revision: | 26 |
Proposed branch: | lp:~humpolec-team/humpolec/UbuntuInstaller-alfa-release-fixes |
Merge into: | lp:humpolec |
Diff against target: |
846 lines (+180/-169) 8 files modified
AndroidManifest.xml (+3/-2) assets/system-image-upgrader (+11/-9) make_release.sh (+16/-0) res/menu/installer_menu.xml (+2/-2) res/menu/launcher_menu.xml (+2/-2) res/values/strings.xml (+3/-2) src/com/canonical/ubuntu/installer/InstallActivity.java (+68/-71) src/com/canonical/ubuntu/installer/UbuntuInstallService.java (+75/-81) |
To merge this branch: | bzr merge lp:~humpolec-team/humpolec/UbuntuInstaller-alfa-release-fixes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rex Tsai | Needs Information | ||
Yuan-Chen Cheng (community) | Approve | ||
The Humpolec team | Pending | ||
Review via email: mp+199740@code.launchpad.net |
Commit message
Description of the change
Fixing UI issue when sometimes Install activity was out of sync from service and showing fetching channels
Fixing UI issue when app tasked away during download, then auto install progress was dimmed
Cleanup of service state changes, now broadcasted whenever it changes.
Fixing CyanogenMod issue. CM su behaves differently and requires correction in scripts
Renaming tar to u_tar so when we use tar, it's not accidentally using platform (busybox) one
Cleaning install and download fail and following cleanup.
Fixing downloaded version and update command out of sync, causing non functional "resume install" state
Adding new ROOT permission used by CyanogenMod
Adding signing script
Rex Tsai (chihchun) wrote : | # |
+1 for fixed fetching channels UI issues
+Adding new ROOT permission used by CyanogenMod
+Fixing CyanogenMod su issue.
+0 on Cleaning install and download fail and following cleanup
1. It should check if the original installation exist.
2. It should prompt a confirmation dialog to let user's know his/her installation will be deleted.
Yuan-Chen Cheng (ycheng-twn) wrote : | # |
If we don't consider user install ubuntu phone by other method, as in InstallActivity, there always should not have any previous installtion. If yes, the disk space calculation will get confused.
We should use something like sudo to detect whether there exists previous installation in next version.
Preview Diff
1 | === modified file 'AndroidManifest.xml' | |||
2 | --- AndroidManifest.xml 2013-12-18 13:27:15 +0000 | |||
3 | +++ AndroidManifest.xml 2013-12-20 03:53:27 +0000 | |||
4 | @@ -1,8 +1,8 @@ | |||
5 | 1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
6 | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | 2 | <manifest xmlns:android="http://schemas.android.com/apk/res/android" |
7 | 3 | package="com.canonical.ubuntu.installer" | 3 | package="com.canonical.ubuntu.installer" |
10 | 4 | android:versionCode="1" | 4 | android:versionCode="19" |
11 | 5 | android:versionName="1.0" > | 5 | android:versionName="0.2" > |
12 | 6 | 6 | ||
13 | 7 | <uses-sdk | 7 | <uses-sdk |
14 | 8 | android:minSdkVersion="17" | 8 | android:minSdkVersion="17" |
15 | @@ -22,6 +22,7 @@ | |||
16 | 22 | <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> | 22 | <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> |
17 | 23 | <uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" /> | 23 | <uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" /> |
18 | 24 | <uses-permission android:name="android.permission.REBOOT"/> | 24 | <uses-permission android:name="android.permission.REBOOT"/> |
19 | 25 | <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/> | ||
20 | 25 | 26 | ||
21 | 26 | <application | 27 | <application |
22 | 27 | android:allowBackup="true" | 28 | android:allowBackup="true" |
23 | 28 | 29 | ||
24 | === modified file 'assets/system-image-upgrader' | |||
25 | --- assets/system-image-upgrader 2013-12-18 01:01:21 +0000 | |||
26 | +++ assets/system-image-upgrader 2013-12-20 03:53:27 +0000 | |||
27 | @@ -3,6 +3,8 @@ | |||
28 | 3 | export PATH=$PATH:${PWD} | 3 | export PATH=$PATH:${PWD} |
29 | 4 | UPDATE_FOLDER=${PWD} | 4 | UPDATE_FOLDER=${PWD} |
30 | 5 | PRIVATE_DIR=$2 | 5 | PRIVATE_DIR=$2 |
31 | 6 | BUSYBOX=busybox | ||
32 | 7 | TAR=u_tar | ||
33 | 6 | set -e | 8 | set -e |
34 | 7 | 9 | ||
35 | 8 | if [ ! -e "$1" ]; then | 10 | if [ ! -e "$1" ]; then |
36 | @@ -61,9 +63,9 @@ | |||
37 | 61 | fi | 63 | fi |
38 | 62 | 64 | ||
39 | 63 | # Unpacking | 65 | # Unpacking |
41 | 64 | TMPDIR=$(busybox mktemp -d ${TMP}/tempdir.XXXXXXXX) | 66 | TMPDIR=$($BUSYBOX mktemp -d ${TMP}/tempdir.XXXXXXXX) |
42 | 65 | cd $TMPDIR | 67 | cd $TMPDIR |
44 | 66 | cat $1 | busybox unxz | tar xf - | 68 | cat $1 | $BUSYBOX unxz | $TAR xf - |
45 | 67 | if [ ! -e keyring.json ] || [ ! -e keyring.gpg ]; then | 69 | if [ ! -e keyring.json ] || [ ! -e keyring.gpg ]; then |
46 | 68 | rm -Rf $TMPDIR | 70 | rm -Rf $TMPDIR |
47 | 69 | echo "Invalid keyring: $1" | 71 | echo "Invalid keyring: $1" |
48 | @@ -71,7 +73,7 @@ | |||
49 | 71 | fi | 73 | fi |
50 | 72 | 74 | ||
51 | 73 | # Extract the expiry | 75 | # Extract the expiry |
53 | 74 | keyring_expiry=$(grep "^ \"expiry\": " keyring.json | busybox cut -d: -f2 | busybox sed -e "s/[ \",]//g") | 76 | keyring_expiry=$(grep "^ \"expiry\": " keyring.json | $BUSYBOX cut -d: -f2 | $BUSYBOX sed -e "s/[ \",]//g") |
54 | 75 | if [ -n "$keyring_expiry" ] && [ "$keyring_expiry" -lt "$(date +%s)" ]; then | 77 | if [ -n "$keyring_expiry" ] && [ "$keyring_expiry" -lt "$(date +%s)" ]; then |
55 | 76 | rm -Rf $TMPDIR | 78 | rm -Rf $TMPDIR |
56 | 77 | echo "Keyring expired: $1" | 79 | echo "Keyring expired: $1" |
57 | @@ -79,7 +81,7 @@ | |||
58 | 79 | fi | 81 | fi |
59 | 80 | 82 | ||
60 | 81 | # Extract the keyring type | 83 | # Extract the keyring type |
62 | 82 | keyring_type=$(grep "^ \"type\": " keyring.json | busybox cut -d: -f2 | busybox sed -e "s/[, \"]//g") | 84 | keyring_type=$(grep "^ \"type\": " keyring.json | $BUSYBOX cut -d: -f2 | $BUSYBOX sed -e "s/[, \"]//g") |
63 | 83 | if [ -z "$keyring_type" ]; then | 85 | if [ -z "$keyring_type" ]; then |
64 | 84 | rm -Rf $TMPDIR | 86 | rm -Rf $TMPDIR |
65 | 85 | echo "Missing keyring type: $1" | 87 | echo "Missing keyring type: $1" |
66 | @@ -153,8 +155,8 @@ | |||
67 | 153 | FULL_IMAGE=1 | 155 | FULL_IMAGE=1 |
68 | 154 | rm -f /data/system.img | 156 | rm -f /data/system.img |
69 | 155 | rm -f /data/.layout_version | 157 | rm -f /data/.layout_version |
72 | 156 | busybox dd if=/dev/zero of=/data/system.img seek=500K bs=4096 count=1 | 158 | $BUSYBOX dd if=/dev/zero of=/data/system.img seek=500K bs=4096 count=1 |
73 | 157 | busybox mkfs.ext2 -F /data/system.img | 159 | $BUSYBOX mkfs.ext2 -F /data/system.img |
74 | 158 | ;; | 160 | ;; |
75 | 159 | 161 | ||
76 | 160 | data) | 162 | data) |
77 | @@ -233,7 +235,7 @@ | |||
78 | 233 | 235 | ||
79 | 234 | # Start by removing any file listed in "removed" | 236 | # Start by removing any file listed in "removed" |
80 | 235 | if [ "$FULL_IMAGE" != "1" ]; then | 237 | if [ "$FULL_IMAGE" != "1" ]; then |
82 | 236 | cat $UPDATE_FOLDER/$2 | busybox unxz | tar xf - removed >/dev/null 2>&1 || true | 238 | cat $UPDATE_FOLDER/$2 | $BUSYBOX unxz | $TAR xf - removed >/dev/null 2>&1 || true |
83 | 237 | if [ -e removed ]; then | 239 | if [ -e removed ]; then |
84 | 238 | while read file; do | 240 | while read file; do |
85 | 239 | rm -Rf $file | 241 | rm -Rf $file |
86 | @@ -243,7 +245,7 @@ | |||
87 | 243 | fi | 245 | fi |
88 | 244 | 246 | ||
89 | 245 | # Unpack everything else on top of the system partition | 247 | # Unpack everything else on top of the system partition |
91 | 246 | cat $UPDATE_FOLDER/$2 | busybox unxz | tar --checkpoint=200 -xf - | 248 | cat $UPDATE_FOLDER/$2 | $BUSYBOX unxz | $TAR --checkpoint=200 -xf - |
92 | 247 | rm -f removed | 249 | rm -f removed |
93 | 248 | 250 | ||
94 | 249 | if [ -e "partitions/boot.img" ]; then | 251 | if [ -e "partitions/boot.img" ]; then |
95 | @@ -287,7 +289,7 @@ | |||
96 | 287 | echo "Moving SWAP device to final destination" >&2 | 289 | echo "Moving SWAP device to final destination" >&2 |
97 | 288 | mv $PRIVATE_DIR/SWAP.img /data/ | 290 | mv $PRIVATE_DIR/SWAP.img /data/ |
98 | 289 | echo "Calling mkswap on /data/SWAP.img" >&2 | 291 | echo "Calling mkswap on /data/SWAP.img" >&2 |
100 | 290 | busybox mkswap /data/SWAP.img | 292 | $BUSYBOX mkswap /data/SWAP.img |
101 | 291 | fi | 293 | fi |
102 | 292 | 294 | ||
103 | 293 | touch /data/.last_update || true | 295 | touch /data/.last_update || true |
104 | 294 | 296 | ||
105 | === renamed file 'assets/tar' => 'assets/u_tar' | |||
106 | === added file 'make_release.sh' | |||
107 | --- make_release.sh 1970-01-01 00:00:00 +0000 | |||
108 | +++ make_release.sh 2013-12-20 03:53:27 +0000 | |||
109 | @@ -0,0 +1,16 @@ | |||
110 | 1 | #!/sbin/sh | ||
111 | 2 | KEY=$1 | ||
112 | 3 | if [[ -z "$KEY" ]]; then | ||
113 | 4 | echo "Pass path to the keystore" | ||
114 | 5 | exit -1 | ||
115 | 6 | fi | ||
116 | 7 | echo "Release tool, using key" | ||
117 | 8 | echo "Getting ready for build" | ||
118 | 9 | android update project --path . | ||
119 | 10 | echo "Removing old release" | ||
120 | 11 | rm -rf bin/ | ||
121 | 12 | ant release | ||
122 | 13 | echo "Signing build" | ||
123 | 14 | jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $KEY bin/MainActivity-release-unsigned.apk humpolec | ||
124 | 15 | mv bin/MainActivity-release-unsigned.apk bin/UbuntuInstaller.apk | ||
125 | 16 | echo "Signed relase is at bin/UbuntuInstaller.apk" | ||
126 | 0 | \ No newline at end of file | 17 | \ No newline at end of file |
127 | 1 | 18 | ||
128 | === modified file 'res/menu/installer_menu.xml' | |||
129 | --- res/menu/installer_menu.xml 2013-12-13 01:06:14 +0000 | |||
130 | +++ res/menu/installer_menu.xml 2013-12-20 03:53:27 +0000 | |||
131 | @@ -5,10 +5,10 @@ | |||
132 | 5 | android:orderInCategory="100" | 5 | android:orderInCategory="100" |
133 | 6 | android:showAsAction="never" | 6 | android:showAsAction="never" |
134 | 7 | android:title="@string/action_detele_download"/> | 7 | android:title="@string/action_detele_download"/> |
136 | 8 | <item | 8 | <!-- <item |
137 | 9 | android:id="@+id/action_settings" | 9 | android:id="@+id/action_settings" |
138 | 10 | android:orderInCategory="100" | 10 | android:orderInCategory="100" |
139 | 11 | android:showAsAction="never" | 11 | android:showAsAction="never" |
140 | 12 | android:title="@string/action_settings"/> | 12 | android:title="@string/action_settings"/> |
142 | 13 | 13 | --> | |
143 | 14 | </menu> | 14 | </menu> |
144 | 15 | 15 | ||
145 | === modified file 'res/menu/launcher_menu.xml' | |||
146 | --- res/menu/launcher_menu.xml 2013-12-13 01:06:14 +0000 | |||
147 | +++ res/menu/launcher_menu.xml 2013-12-20 03:53:27 +0000 | |||
148 | @@ -11,10 +11,10 @@ | |||
149 | 11 | android:showAsAction="never" | 11 | android:showAsAction="never" |
150 | 12 | android:title="@string/action_delete_user_data"/> | 12 | android:title="@string/action_delete_user_data"/> |
151 | 13 | 13 | ||
153 | 14 | <item | 14 | <!-- <item |
154 | 15 | android:id="@+id/action_settings" | 15 | android:id="@+id/action_settings" |
155 | 16 | android:orderInCategory="100" | 16 | android:orderInCategory="100" |
156 | 17 | android:showAsAction="never" | 17 | android:showAsAction="never" |
157 | 18 | android:title="@string/action_settings"/> | 18 | android:title="@string/action_settings"/> |
159 | 19 | 19 | --> | |
160 | 20 | </menu> | 20 | </menu> |
161 | 21 | 21 | ||
162 | === modified file 'res/values/strings.xml' | |||
163 | --- res/values/strings.xml 2013-12-19 09:09:25 +0000 | |||
164 | +++ res/values/strings.xml 2013-12-20 03:53:27 +0000 | |||
165 | @@ -11,11 +11,12 @@ | |||
166 | 11 | <string name="action_delete_udata_button">Delete</string> | 11 | <string name="action_delete_udata_button">Delete</string> |
167 | 12 | <string name="cancel">Cancel</string> | 12 | <string name="cancel">Cancel</string> |
168 | 13 | <string name="welcome_world">Your life is about to change, welcome in Ubuntu installer</string> | 13 | <string name="welcome_world">Your life is about to change, welcome in Ubuntu installer</string> |
170 | 14 | <string name="install_button_label_install">Install Ubuntu</string> | 14 | <string name="install_button_label_install">Choose channel to install</string> |
171 | 15 | <string name="install_button_label_fetching"><![CDATA[Install Ubuntu<br/><small>fetching channel list</small>]]></string> | 15 | <string name="install_button_label_fetching"><![CDATA[Install Ubuntu<br/><small>fetching channel list</small>]]></string> |
172 | 16 | <string name="install_button_label_no_channel"><![CDATA[Install Ubuntu<br/><small>no available channels</small>]]></string> | 16 | <string name="install_button_label_no_channel"><![CDATA[Install Ubuntu<br/><small>no available channels</small>]]></string> |
173 | 17 | <string name="install_button_label_resume">Resume install</string> | 17 | <string name="install_button_label_resume">Resume install</string> |
175 | 18 | <string name="install_button_label_cancel">Cancel install</string> | 18 | <string name="install_button_label_cancel_download">Cancel download</string> |
176 | 19 | <string name="install_button_label_cancel_install">Cancel install</string> | ||
177 | 19 | <string name="channel_picker_dialog_title">Select channel to install</string> | 20 | <string name="channel_picker_dialog_title">Select channel to install</string> |
178 | 20 | <string name="version_picker_dialog_title">Select version to install</string> | 21 | <string name="version_picker_dialog_title">Select version to install</string> |
179 | 21 | <string name="bootstrap_check">bootstrap</string> | 22 | <string name="bootstrap_check">bootstrap</string> |
180 | 22 | 23 | ||
181 | === modified file 'src/com/canonical/ubuntu/installer/InstallActivity.java' | |||
182 | --- src/com/canonical/ubuntu/installer/InstallActivity.java 2013-12-19 12:57:21 +0000 | |||
183 | +++ src/com/canonical/ubuntu/installer/InstallActivity.java 2013-12-20 03:53:27 +0000 | |||
184 | @@ -32,7 +32,8 @@ | |||
185 | 32 | public class InstallActivity extends Activity { | 32 | public class InstallActivity extends Activity { |
186 | 33 | private static final String TAG = "UbuntuInstaller"; | 33 | private static final String TAG = "UbuntuInstaller"; |
187 | 34 | 34 | ||
189 | 35 | private UbuntuButton mInstallButton; | 35 | private UbuntuButton mInstallButton; |
190 | 36 | private boolean mObserversRegistered; | ||
191 | 36 | 37 | ||
192 | 37 | private InstallerState mStatus = InstallerState.READY; | 38 | private InstallerState mStatus = InstallerState.READY; |
193 | 38 | private VersionInfo mDownloadedVersion = null; | 39 | private VersionInfo mDownloadedVersion = null; |
194 | @@ -79,28 +80,31 @@ | |||
195 | 79 | filter.addAction(UbuntuInstallService.VERSION_UPDATE); | 80 | filter.addAction(UbuntuInstallService.VERSION_UPDATE); |
196 | 80 | filter.addAction(UbuntuInstallService.SERVICE_STATE); | 81 | filter.addAction(UbuntuInstallService.SERVICE_STATE); |
197 | 81 | registerReceiver(mServiceObserver, filter); | 82 | registerReceiver(mServiceObserver, filter); |
198 | 83 | mObserversRegistered = true; | ||
199 | 82 | 84 | ||
200 | 83 | // do we know last activity | 85 | // do we know last activity |
205 | 84 | if (mStatus == InstallerState.READY) { | 86 | if (mStatus == InstallerState.DOWNLOADING || mStatus == InstallerState.INSTALLING) { |
202 | 85 | requestServiceState(); | ||
203 | 86 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(this.getApplicationContext()); | ||
204 | 87 | } else if (mStatus == InstallerState.DOWNLOADING || mStatus == InstallerState.INSTALLING) { | ||
206 | 88 | // request last progress / status. this will update UI accordingly | 87 | // request last progress / status. this will update UI accordingly |
207 | 89 | startService(new Intent(UbuntuInstallService.GET_PROGRESS_STATUS)); | 88 | startService(new Intent(UbuntuInstallService.GET_PROGRESS_STATUS)); |
208 | 90 | } else { | 89 | } else { |
209 | 91 | // READY + mDownloadedVersion != null => READY_TO_INSTALL | 90 | // READY + mDownloadedVersion != null => READY_TO_INSTALL |
210 | 92 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(this.getApplicationContext()); | 91 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(this.getApplicationContext()); |
213 | 93 | mStatus = InstallerState.READY; | 92 | if (mDownloadedVersion == null) { |
214 | 94 | updateUiElements(); | 93 | requestChannelList(); |
215 | 94 | } | ||
216 | 95 | } | 95 | } |
217 | 96 | requestServiceState(); | ||
218 | 96 | } | 97 | } |
219 | 97 | 98 | ||
220 | 98 | @Override | 99 | @Override |
221 | 99 | public void onPause() { | 100 | public void onPause() { |
222 | 100 | super.onPause(); | 101 | super.onPause(); |
223 | 101 | mInstallButton.setOnClickListener(null); | ||
224 | 102 | // cancel observer if there is any | 102 | // cancel observer if there is any |
226 | 103 | unregisterReceiver(mServiceObserver); | 103 | if (mObserversRegistered) { |
227 | 104 | mInstallButton.setOnClickListener(null); | ||
228 | 105 | unregisterReceiver(mServiceObserver); | ||
229 | 106 | } | ||
230 | 107 | mObserversRegistered = false; | ||
231 | 104 | } | 108 | } |
232 | 105 | 109 | ||
233 | 106 | @Override | 110 | @Override |
234 | @@ -114,10 +118,13 @@ | |||
235 | 114 | public boolean onOptionsItemSelected(MenuItem item) { | 118 | public boolean onOptionsItemSelected(MenuItem item) { |
236 | 115 | switch (item.getItemId()) { | 119 | switch (item.getItemId()) { |
237 | 116 | case R.id.action_delete_download: | 120 | case R.id.action_delete_download: |
238 | 121 | // also attempt to uninstall ubuntu, since there should be none anyway, keep user data | ||
239 | 122 | Intent action = new Intent(UbuntuInstallService.UNINSTALL_UBUNTU); | ||
240 | 123 | action.putExtra(UbuntuInstallService.UNINSTALL_UBUNTU_EXTRA_REMOVE_USER_DATA, false); | ||
241 | 124 | startService(action); | ||
242 | 117 | deleteDownload(); | 125 | deleteDownload(); |
243 | 118 | mDownloadedVersion = null; | 126 | mDownloadedVersion = null; |
246 | 119 | mStatus = InstallerState.READY; | 127 | requestServiceState(); |
245 | 120 | updateUiElements(); | ||
247 | 121 | break; | 128 | break; |
248 | 122 | } | 129 | } |
249 | 123 | return super.onOptionsItemSelected(item); | 130 | return super.onOptionsItemSelected(item); |
250 | @@ -184,8 +191,7 @@ | |||
251 | 184 | true /* default latest settings*/).show(); | 191 | true /* default latest settings*/).show(); |
252 | 185 | } else { | 192 | } else { |
253 | 186 | // there are no channels to pick from, this was mistake, disable button | 193 | // there are no channels to pick from, this was mistake, disable button |
256 | 187 | mStatus = InstallerState.READY; | 194 | requestServiceState(); |
255 | 188 | updateUiElements(); | ||
257 | 189 | } | 195 | } |
258 | 190 | } | 196 | } |
259 | 191 | }; | 197 | }; |
260 | @@ -209,8 +215,6 @@ | |||
261 | 209 | Utils.showToast(this, "Starting Ubuntu installation"); | 215 | Utils.showToast(this, "Starting Ubuntu installation"); |
262 | 210 | // reset progress bar | 216 | // reset progress bar |
263 | 211 | mProgressBar.setProgress(0); | 217 | mProgressBar.setProgress(0); |
264 | 212 | mStatus = InstallerState.INSTALLING; | ||
265 | 213 | updateUiElements(); | ||
266 | 214 | } | 218 | } |
267 | 215 | 219 | ||
268 | 216 | TextPickerDialog.OnChannelPicktListener mInstallDialogListener | 220 | TextPickerDialog.OnChannelPicktListener mInstallDialogListener |
269 | @@ -238,8 +242,6 @@ | |||
270 | 238 | startService(startDownload); | 242 | startService(startDownload); |
271 | 239 | mTerminal.setText(R.string.downloading_starting); | 243 | mTerminal.setText(R.string.downloading_starting); |
272 | 240 | mProgressBar.setProgress(0); | 244 | mProgressBar.setProgress(0); |
273 | 241 | mStatus = InstallerState.DOWNLOADING; | ||
274 | 242 | updateUiElements(); | ||
275 | 243 | } | 245 | } |
276 | 244 | 246 | ||
277 | 245 | private void downloadVersion(final Context context, final String channel, final boolean bootstrap) { | 247 | private void downloadVersion(final Context context, final String channel, final boolean bootstrap) { |
278 | @@ -284,50 +286,56 @@ | |||
279 | 284 | } | 286 | } |
280 | 285 | 287 | ||
281 | 286 | private void updateUiElements() { | 288 | private void updateUiElements() { |
303 | 287 | switch (mStatus) { | 289 | this.runOnUiThread(new Runnable() { |
304 | 288 | case READY: | 290 | @Override |
305 | 289 | { | 291 | public void run() { |
306 | 290 | if (mDownloadedVersion != null) { | 292 | Log.v(TAG,"updateUiElements(" + mStatus + ")"); |
307 | 291 | mInstallButton.setText(R.string.install_button_label_resume); | 293 | switch (mStatus) { |
308 | 292 | mInstallButton.setEnabled(true); | 294 | case READY: |
309 | 293 | mProgressBar.setEnabled(false); | 295 | { |
310 | 294 | mProgressBar.setProgress(0); | 296 | if (mDownloadedVersion != null) { |
311 | 295 | mProgressText.setText(""); | 297 | mInstallButton.setText(R.string.install_button_label_resume); |
312 | 296 | } else if (mAvailableChannels.size() > 0) { | 298 | mInstallButton.setEnabled(true); |
313 | 297 | mInstallButton.setText(R.string.install_button_label_install); | 299 | mProgressBar.setEnabled(false); |
314 | 298 | mInstallButton.setEnabled(true); | 300 | mProgressBar.setProgress(0); |
315 | 299 | mProgressBar.setEnabled(false); | 301 | mProgressText.setText(""); |
316 | 300 | mProgressBar.setProgress(0); | 302 | } else if (mAvailableChannels.size() > 0) { |
317 | 301 | mProgressText.setText(""); | 303 | mInstallButton.setText(R.string.install_button_label_install); |
318 | 302 | } else { | 304 | mInstallButton.setEnabled(true); |
319 | 303 | mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_no_channel))); | 305 | mProgressBar.setEnabled(false); |
320 | 304 | mInstallButton.setEnabled(false); | 306 | mProgressBar.setProgress(0); |
321 | 305 | mProgressBar.setEnabled(false); | 307 | mProgressText.setText(""); |
322 | 306 | mProgressBar.setProgress(0); | 308 | } else { |
323 | 307 | mProgressText.setText(""); | 309 | mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_no_channel))); |
324 | 310 | mInstallButton.setEnabled(false); | ||
325 | 311 | mProgressBar.setEnabled(false); | ||
326 | 312 | mProgressBar.setProgress(0); | ||
327 | 313 | mProgressText.setText(""); | ||
328 | 314 | } | ||
329 | 315 | } | ||
330 | 316 | break; | ||
331 | 317 | case FETCHING_CHANNELS: | ||
332 | 318 | mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_fetching))); | ||
333 | 319 | mInstallButton.setEnabled(false); | ||
334 | 320 | mProgressBar.setEnabled(false); | ||
335 | 321 | mProgressBar.setProgress(0); | ||
336 | 322 | mProgressText.setText(""); | ||
337 | 323 | break; | ||
338 | 324 | case DOWNLOADING: | ||
339 | 325 | mInstallButton.setText(R.string.install_button_label_cancel_download); | ||
340 | 326 | mInstallButton.setEnabled(true); | ||
341 | 327 | mProgressBar.setEnabled(true); | ||
342 | 328 | mProgressText.setText(R.string.downloading_release); | ||
343 | 329 | break; | ||
344 | 330 | case INSTALLING: | ||
345 | 331 | mInstallButton.setText(R.string.install_button_label_cancel_install); | ||
346 | 332 | mInstallButton.setEnabled(true); | ||
347 | 333 | mProgressBar.setEnabled(true); | ||
348 | 334 | mProgressText.setText(R.string.installing_release); | ||
349 | 335 | break; | ||
350 | 308 | } | 336 | } |
351 | 309 | } | 337 | } |
373 | 310 | break; | 338 | }); |
353 | 311 | case FETCHING_CHANNELS: | ||
354 | 312 | mInstallButton.setText(Html.fromHtml(getResources().getString(R.string.install_button_label_fetching))); | ||
355 | 313 | mInstallButton.setEnabled(false); | ||
356 | 314 | mProgressBar.setEnabled(false); | ||
357 | 315 | mProgressBar.setProgress(0); | ||
358 | 316 | mProgressText.setText(""); | ||
359 | 317 | break; | ||
360 | 318 | case DOWNLOADING: | ||
361 | 319 | mInstallButton.setText(R.string.install_button_label_cancel); | ||
362 | 320 | mInstallButton.setEnabled(true); | ||
363 | 321 | mProgressBar.setEnabled(true); | ||
364 | 322 | mProgressText.setText(R.string.downloading_release); | ||
365 | 323 | break; | ||
366 | 324 | case INSTALLING: | ||
367 | 325 | mInstallButton.setText(R.string.install_button_label_cancel); | ||
368 | 326 | mInstallButton.setEnabled(true); | ||
369 | 327 | mProgressBar.setEnabled(true); | ||
370 | 328 | mProgressText.setText(R.string.installing_release); | ||
371 | 329 | break; | ||
372 | 330 | } | ||
374 | 331 | } | 339 | } |
375 | 332 | 340 | ||
376 | 333 | BroadcastReceiver mServiceObserver = new BroadcastReceiver() { | 341 | BroadcastReceiver mServiceObserver = new BroadcastReceiver() { |
377 | @@ -335,8 +343,8 @@ | |||
378 | 335 | @SuppressWarnings("unchecked") | 343 | @SuppressWarnings("unchecked") |
379 | 336 | @Override | 344 | @Override |
380 | 337 | public void onReceive(Context context, Intent intent) { | 345 | public void onReceive(Context context, Intent intent) { |
381 | 338 | |||
382 | 339 | String action = intent.getAction(); | 346 | String action = intent.getAction(); |
383 | 347 | Log.v(TAG,"mServiceObserver.onReceive(" + action + ")"); | ||
384 | 340 | // List of available channels fetched | 348 | // List of available channels fetched |
385 | 341 | if (action.equals(UbuntuInstallService.AVAILABLE_CHANNELS)) { | 349 | if (action.equals(UbuntuInstallService.AVAILABLE_CHANNELS)) { |
386 | 342 | // ignore channel list if we have already downloaded release | 350 | // ignore channel list if we have already downloaded release |
387 | @@ -379,12 +387,10 @@ | |||
388 | 379 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); | 387 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); |
389 | 380 | if (UbuntuInstallService.checkifReadyToInstall(context)) { | 388 | if (UbuntuInstallService.checkifReadyToInstall(context)) { |
390 | 381 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); | 389 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); |
391 | 382 | mStatus = InstallerState.READY; | ||
392 | 383 | } else { | 390 | } else { |
393 | 384 | deleteDownload(); | 391 | deleteDownload(); |
394 | 385 | mDownloadedVersion = null; | 392 | mDownloadedVersion = null; |
395 | 386 | requestChannelList(); | 393 | requestChannelList(); |
396 | 387 | mStatus = InstallerState.FETCHING_CHANNELS; | ||
397 | 388 | } | 394 | } |
398 | 389 | updateUiElements(); | 395 | updateUiElements(); |
399 | 390 | } | 396 | } |
400 | @@ -405,8 +411,6 @@ | |||
401 | 405 | updateInfoOnUiThread(reason); | 411 | updateInfoOnUiThread(reason); |
402 | 406 | // delete failed download | 412 | // delete failed download |
403 | 407 | deleteDownload(); | 413 | deleteDownload(); |
404 | 408 | mStatus = InstallerState.READY; | ||
405 | 409 | updateUiElements(); | ||
406 | 410 | requestChannelList(); | 414 | requestChannelList(); |
407 | 411 | } | 415 | } |
408 | 412 | } else if (action.equals(UbuntuInstallService.VERSION_UPDATE)) { | 416 | } else if (action.equals(UbuntuInstallService.VERSION_UPDATE)) { |
409 | @@ -415,7 +419,6 @@ | |||
410 | 415 | // check what button should be shown | 419 | // check what button should be shown |
411 | 416 | if (UbuntuInstallService.checkifReadyToInstall(context)) { | 420 | if (UbuntuInstallService.checkifReadyToInstall(context)) { |
412 | 417 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); | 421 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); |
413 | 418 | mStatus = InstallerState.READY; | ||
414 | 419 | } | 422 | } |
415 | 420 | updateUiElements(); | 423 | updateUiElements(); |
416 | 421 | } | 424 | } |
417 | @@ -423,12 +426,6 @@ | |||
418 | 423 | checkIfUbuntuIsInstalled(); | 426 | checkIfUbuntuIsInstalled(); |
419 | 424 | if (!isFinishing()) { | 427 | if (!isFinishing()) { |
420 | 425 | mStatus = InstallerState.fromOrdian(intent.getIntExtra(UbuntuInstallService.SERVICE_STATE, 0)); | 428 | mStatus = InstallerState.fromOrdian(intent.getIntExtra(UbuntuInstallService.SERVICE_STATE, 0)); |
421 | 426 | if (mStatus != InstallerState.FETCHING_CHANNELS && | ||
422 | 427 | mStatus != InstallerState.DOWNLOADING && | ||
423 | 428 | mStatus != InstallerState.INSTALLING) { | ||
424 | 429 | requestChannelList(); | ||
425 | 430 | mStatus = InstallerState.FETCHING_CHANNELS; | ||
426 | 431 | } | ||
427 | 432 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); | 429 | mDownloadedVersion = UbuntuInstallService.getDownloadedVersion(context); |
428 | 433 | updateUiElements(); | 430 | updateUiElements(); |
429 | 434 | } | 431 | } |
430 | 435 | 432 | ||
431 | === modified file 'src/com/canonical/ubuntu/installer/UbuntuInstallService.java' | |||
432 | --- src/com/canonical/ubuntu/installer/UbuntuInstallService.java 2013-12-19 11:21:02 +0000 | |||
433 | +++ src/com/canonical/ubuntu/installer/UbuntuInstallService.java 2013-12-20 03:53:27 +0000 | |||
434 | @@ -148,7 +148,7 @@ | |||
435 | 148 | // ================================================================================================= | 148 | // ================================================================================================= |
436 | 149 | private static final String BUSYBOX = "busybox"; | 149 | private static final String BUSYBOX = "busybox"; |
437 | 150 | private static final String GPG = "gpg"; | 150 | private static final String GPG = "gpg"; |
439 | 151 | private static final String TAR = "tar"; | 151 | private static final String TAR = "u_tar"; |
440 | 152 | private static final String ANDROID_LOOP_MOUNT = "aloopmount"; | 152 | private static final String ANDROID_LOOP_MOUNT = "aloopmount"; |
441 | 153 | private static final String ANDROID_BOOTMGR = "bootmgr"; | 153 | private static final String ANDROID_BOOTMGR = "bootmgr"; |
442 | 154 | private static final String UPDATE_SCRIPT = "system-image-upgrader"; | 154 | private static final String UPDATE_SCRIPT = "system-image-upgrader"; |
443 | @@ -187,7 +187,7 @@ | |||
444 | 187 | private long mProgress; // so far handled amount downloaded/processed | 187 | private long mProgress; // so far handled amount downloaded/processed |
445 | 188 | private int mLastSignalledProgress; | 188 | private int mLastSignalledProgress; |
446 | 189 | private long mTotalSize; // calculated | 189 | private long mTotalSize; // calculated |
448 | 190 | private InstallerState mServiceState; | 190 | private InstallerState mInstallerState; |
449 | 191 | 191 | ||
450 | 192 | public class Channel { | 192 | public class Channel { |
451 | 193 | String alias; | 193 | String alias; |
452 | @@ -236,13 +236,13 @@ | |||
453 | 236 | mRootOfWorkPath = getFilesDir().toString(); // "/data/data/com.canonical.ubuntuinstaller/files"; | 236 | mRootOfWorkPath = getFilesDir().toString(); // "/data/data/com.canonical.ubuntuinstaller/files"; |
454 | 237 | workPathInCache = false; | 237 | workPathInCache = false; |
455 | 238 | } | 238 | } |
457 | 239 | mServiceState = InstallerState.READY; | 239 | mInstallerState = InstallerState.READY; |
458 | 240 | } | 240 | } |
459 | 241 | 241 | ||
460 | 242 | @Override | 242 | @Override |
461 | 243 | public int onStartCommand(Intent intent, int flags, int startId) { | 243 | public int onStartCommand(Intent intent, int flags, int startId) { |
462 | 244 | // if service is not in ready state, handle specific requests here | 244 | // if service is not in ready state, handle specific requests here |
464 | 245 | if (mServiceState != InstallerState.READY) { | 245 | if (mInstallerState != InstallerState.READY) { |
465 | 246 | String action = intent.getAction(); | 246 | String action = intent.getAction(); |
466 | 247 | if (action.equals(CANCEL_DOWNLOAD)) { | 247 | if (action.equals(CANCEL_DOWNLOAD)) { |
467 | 248 | // set the cancel flag, but let it remove downloaded files on worker thread | 248 | // set the cancel flag, but let it remove downloaded files on worker thread |
468 | @@ -250,7 +250,7 @@ | |||
469 | 250 | } else if (action.equals(GET_PROGRESS_STATUS)) { | 250 | } else if (action.equals(GET_PROGRESS_STATUS)) { |
470 | 251 | broadcastProgress(mLastSignalledProgress, ""); | 251 | broadcastProgress(mLastSignalledProgress, ""); |
471 | 252 | } else if (action.equals(GET_SERVICE_STATE)) { | 252 | } else if (action.equals(GET_SERVICE_STATE)) { |
473 | 253 | broadcastServiceState(); | 253 | broadcastInstallerState(); |
474 | 254 | } | 254 | } |
475 | 255 | } | 255 | } |
476 | 256 | return super.onStartCommand(intent, flags, startId); | 256 | return super.onStartCommand(intent, flags, startId); |
477 | @@ -263,10 +263,10 @@ | |||
478 | 263 | 263 | ||
479 | 264 | Log.d(TAG, this.toString() + " onHandleIntent: " + action); | 264 | Log.d(TAG, this.toString() + " onHandleIntent: " + action); |
480 | 265 | if (action.equals(GET_CHANNEL_LIST)) { | 265 | if (action.equals(GET_CHANNEL_LIST)) { |
482 | 266 | mServiceState = InstallerState.FETCHING_CHANNELS; | 266 | updateInstallerState(InstallerState.FETCHING_CHANNELS); |
483 | 267 | result = doGetChannelList(intent); | 267 | result = doGetChannelList(intent); |
484 | 268 | } else if (action.equals(DOWNLOAD_RELEASE)) { | 268 | } else if (action.equals(DOWNLOAD_RELEASE)) { |
486 | 269 | mServiceState = InstallerState.DOWNLOADING; | 269 | updateInstallerState(InstallerState.DOWNLOADING); |
487 | 270 | result = doDownloadRelease(intent); | 270 | result = doDownloadRelease(intent); |
488 | 271 | } else if (action.equals(CANCEL_DOWNLOAD)) { | 271 | } else if (action.equals(CANCEL_DOWNLOAD)) { |
489 | 272 | // download should be already cancelled, now delete all the files | 272 | // download should be already cancelled, now delete all the files |
490 | @@ -274,22 +274,22 @@ | |||
491 | 274 | } else if (action.equals(PAUSE_DOWNLOAD)) { | 274 | } else if (action.equals(PAUSE_DOWNLOAD)) { |
492 | 275 | // TODO: handle download | 275 | // TODO: handle download |
493 | 276 | } else if (action.equals(RESUME_DOWNLOAD)) { | 276 | } else if (action.equals(RESUME_DOWNLOAD)) { |
495 | 277 | mServiceState = InstallerState.DOWNLOADING; | 277 | updateInstallerState(InstallerState.DOWNLOADING); |
496 | 278 | // TODO: handle download | 278 | // TODO: handle download |
497 | 279 | } else if (action.equals(CLEAN_DOWNLOAD)) { | 279 | } else if (action.equals(CLEAN_DOWNLOAD)) { |
498 | 280 | result = doRemoreDownload(intent); | 280 | result = doRemoreDownload(intent); |
499 | 281 | } else if (action.equals(INSTALL_UBUNTU)) { | 281 | } else if (action.equals(INSTALL_UBUNTU)) { |
501 | 282 | mServiceState = InstallerState.INSTALLING; | 282 | updateInstallerState(InstallerState.INSTALLING); |
502 | 283 | result = doInstallUbuntu(intent); | 283 | result = doInstallUbuntu(intent); |
503 | 284 | } else if (action.equals(CANCEL_INSTALL)) { | 284 | } else if (action.equals(CANCEL_INSTALL)) { |
504 | 285 | // install should be already cancelled, try to delete it now | 285 | // install should be already cancelled, try to delete it now |
506 | 286 | mServiceState = InstallerState.UNINSTALLING; | 286 | updateInstallerState(InstallerState.UNINSTALLING); |
507 | 287 | result = doUninstallUbuntu(intent); | 287 | result = doUninstallUbuntu(intent); |
508 | 288 | } else if (action.equals(UNINSTALL_UBUNTU)) { | 288 | } else if (action.equals(UNINSTALL_UBUNTU)) { |
510 | 289 | mServiceState = InstallerState.UNINSTALLING; | 289 | updateInstallerState(InstallerState.UNINSTALLING); |
511 | 290 | result = doUninstallUbuntu(intent); | 290 | result = doUninstallUbuntu(intent); |
512 | 291 | } else if (action.equals(DELETE_UBUNTU_USER_DATA)) { | 291 | } else if (action.equals(DELETE_UBUNTU_USER_DATA)) { |
514 | 292 | mServiceState = InstallerState.DELETING_USER_DATA; | 292 | updateInstallerState(InstallerState.DELETING_USER_DATA); |
515 | 293 | result = doDeleteUbuntuUserData(intent); | 293 | result = doDeleteUbuntuUserData(intent); |
516 | 294 | } else if(action.equals(REBOOT_UBUNTU)) { | 294 | } else if(action.equals(REBOOT_UBUNTU)) { |
517 | 295 | Log.d(TAG, this.toString() + ": REBOOT_UBUNTU"); | 295 | Log.d(TAG, this.toString() + ": REBOOT_UBUNTU"); |
518 | @@ -298,12 +298,12 @@ | |||
519 | 298 | } else { | 298 | } else { |
520 | 299 | // for any other request broadcast service state | 299 | // for any other request broadcast service state |
521 | 300 | result = new Intent(SERVICE_STATE); | 300 | result = new Intent(SERVICE_STATE); |
523 | 301 | result.putExtra(SERVICE_STATE_EXTRA_STATE, mServiceState.ordinal()); | 301 | result.putExtra(SERVICE_STATE_EXTRA_STATE, mInstallerState.ordinal()); |
524 | 302 | } | 302 | } |
525 | 303 | if (result != null) { | 303 | if (result != null) { |
526 | 304 | sendBroadcast(result); | 304 | sendBroadcast(result); |
527 | 305 | } | 305 | } |
529 | 306 | mServiceState = InstallerState.READY; | 306 | updateInstallerState(InstallerState.READY); |
530 | 307 | Log.d(TAG, this.toString() + " onHandleIntent: " + action + " END"); | 307 | Log.d(TAG, this.toString() + " onHandleIntent: " + action + " END"); |
531 | 308 | } | 308 | } |
532 | 309 | 309 | ||
533 | @@ -335,7 +335,7 @@ | |||
534 | 335 | if (alias == null || alias.equals("")) { | 335 | if (alias == null || alias.equals("")) { |
535 | 336 | alias = key; // use key instead | 336 | alias = key; // use key instead |
536 | 337 | } | 337 | } |
538 | 338 | Log.v(TAG, "Channel:" + alias + " url:" + url); | 338 | // Log.v(TAG, "Channel:" + alias + " url:" + url); |
539 | 339 | if (!hidden || includeHidden) { | 339 | if (!hidden || includeHidden) { |
540 | 340 | channels.put(alias, url); | 340 | channels.put(alias, url); |
541 | 341 | } | 341 | } |
542 | @@ -354,12 +354,14 @@ | |||
543 | 354 | } | 354 | } |
544 | 355 | 355 | ||
545 | 356 | private Intent doRemoreDownload(Intent intent) { | 356 | private Intent doRemoreDownload(Intent intent) { |
547 | 357 | Intent result = new Intent(); | 357 | Intent result = new Intent(SERVICE_STATE); |
548 | 358 | String s = deleteRelease(); | 358 | String s = deleteRelease(); |
549 | 359 | if (s!= null) { | 359 | if (s!= null) { |
550 | 360 | broadcastProgress(-1, s); | ||
551 | 360 | // delete failed | 361 | // delete failed |
552 | 361 | } | 362 | } |
554 | 362 | return result; | 363 | result.putExtra(SERVICE_STATE, InstallerState.READY.ordinal()); |
555 | 364 | return result; | ||
556 | 363 | } | 365 | } |
557 | 364 | 366 | ||
558 | 365 | private Intent doInstallUbuntu(Intent intent) { | 367 | private Intent doInstallUbuntu(Intent intent) { |
559 | @@ -367,14 +369,11 @@ | |||
560 | 367 | Intent result = new Intent(INSTALL_RESULT); | 369 | Intent result = new Intent(INSTALL_RESULT); |
561 | 368 | // get update command file | 370 | // get update command file |
562 | 369 | SharedPreferences pref = getSharedPreferences( SHARED_PREF, Context.MODE_PRIVATE); | 371 | SharedPreferences pref = getSharedPreferences( SHARED_PREF, Context.MODE_PRIVATE); |
565 | 370 | String updateCommand = // "/cache/ubuntu_release/update_command"; | 372 | String updateCommand = pref.getString(PREF_KEY_UPDATE_COMMAND,""); |
564 | 371 | pref.getString(PREF_KEY_UPDATE_COMMAND,""); | ||
566 | 372 | mTotalSize = pref.getInt(PREF_KEY_ESTIMATED_CHECKPOINTS, 0); | 373 | mTotalSize = pref.getInt(PREF_KEY_ESTIMATED_CHECKPOINTS, 0); |
567 | 373 | mLastSignalledProgress = 0; | 374 | mLastSignalledProgress = 0; |
568 | 374 | if (updateCommand.equals("") || ! new File(updateCommand).exists()) { | 375 | if (updateCommand.equals("") || ! new File(updateCommand).exists()) { |
572 | 375 | result.putExtra(INSTALL_RESULT_EXTRA_INT, -1); | 376 | return handleInstallFail(result, -1, "Missing update command"); |
570 | 376 | result.putExtra(INSTALL_RESULT_EXTRA_STR, "Missing update command"); | ||
571 | 377 | return result; | ||
573 | 378 | } | 377 | } |
574 | 379 | mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ubuntu-installing"); | 378 | mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ubuntu-installing"); |
575 | 380 | try { | 379 | try { |
576 | @@ -394,9 +393,7 @@ | |||
577 | 394 | Utils.extractExecutableAsset(this, U_REBOOT_APP_ASC, supportingFiles.toString(), false); | 393 | Utils.extractExecutableAsset(this, U_REBOOT_APP_ASC, supportingFiles.toString(), false); |
578 | 395 | } catch (IOException e) { | 394 | } catch (IOException e) { |
579 | 396 | e.printStackTrace(); | 395 | e.printStackTrace(); |
583 | 397 | result.putExtra(INSTALL_RESULT_EXTRA_INT, -1); | 396 | return handleInstallFail(result, -1, "Failed to extract supporting assets"); |
581 | 398 | result.putExtra(INSTALL_RESULT_EXTRA_STR, "Failed to extract supporting assets"); | ||
582 | 399 | return result; | ||
584 | 400 | } | 397 | } |
585 | 401 | // get superuser and run update script | 398 | // get superuser and run update script |
586 | 402 | broadcastProgress(-1, "Starting update script"); | 399 | broadcastProgress(-1, "Starting update script"); |
587 | @@ -405,30 +402,34 @@ | |||
588 | 405 | DataOutputStream os = new DataOutputStream(process.getOutputStream()); | 402 | DataOutputStream os = new DataOutputStream(process.getOutputStream()); |
589 | 406 | // debug purpose. | 403 | // debug purpose. |
590 | 407 | // os.writeBytes("set -x\n"); | 404 | // os.writeBytes("set -x\n"); |
591 | 405 | // make sure we are in work folder | ||
592 | 406 | os.writeBytes(String.format("cd %s\n", supportingFiles.getAbsolutePath())); | ||
593 | 407 | os.writeBytes("echo \"SU granted\"\n"); | ||
594 | 408 | // run system-image-upgrader. | 408 | // run system-image-upgrader. |
595 | 409 | os.writeBytes(String.format("sh %s %s %s\n", | 409 | os.writeBytes(String.format("sh %s %s %s\n", |
596 | 410 | UPDATE_SCRIPT, | 410 | UPDATE_SCRIPT, |
597 | 411 | updateCommand, | 411 | updateCommand, |
599 | 412 | getFilesDir().toString() | 412 | getFilesDir().getAbsolutePath() |
600 | 413 | )); | 413 | )); |
601 | 414 | os.writeBytes(String.format("cd %s\n", supportingFiles.getAbsolutePath())); | ||
602 | 414 | // backup original recovery. | 415 | // backup original recovery. |
603 | 415 | if(!new File(getFilesDir().toString(), ANDROID_REOCVERY_IMG).exists()) { | 416 | if(!new File(getFilesDir().toString(), ANDROID_REOCVERY_IMG).exists()) { |
606 | 416 | os.writeBytes(String.format("%s/%s -b %s %s/%s\n", | 417 | os.writeBytes(String.format("./%s -b %s %s/%s\n", |
605 | 417 | supportingFiles.toString(), | ||
607 | 418 | ANDROID_BOOTMGR, | 418 | ANDROID_BOOTMGR, |
608 | 419 | Utils.getRecoveryPartitionPath(), | 419 | Utils.getRecoveryPartitionPath(), |
610 | 420 | getFilesDir().toString(), | 420 | getFilesDir().getAbsolutePath(), |
611 | 421 | ANDROID_REOCVERY_IMG | 421 | ANDROID_REOCVERY_IMG |
612 | 422 | )); | 422 | )); |
613 | 423 | } | 423 | } |
614 | 424 | os.writeBytes(String.format("cd %s\n", supportingFiles.getAbsolutePath())); | ||
615 | 424 | // overwrite the recovery partition. | 425 | // overwrite the recovery partition. |
618 | 425 | os.writeBytes(String.format("%s/%s -b %s/%s %s\n", | 426 | os.writeBytes(String.format("./%s -b %s/%s %s\n", |
617 | 426 | supportingFiles.toString(), | ||
619 | 427 | ANDROID_BOOTMGR, | 427 | ANDROID_BOOTMGR, |
621 | 428 | getFilesDir().toString(), | 428 | getFilesDir().getAbsolutePath(), |
622 | 429 | UBUNTU_BOOT_IMG, | 429 | UBUNTU_BOOT_IMG, |
623 | 430 | Utils.getRecoveryPartitionPath() | 430 | Utils.getRecoveryPartitionPath() |
624 | 431 | )); | 431 | )); |
625 | 432 | |||
626 | 432 | // close terminal | 433 | // close terminal |
627 | 433 | os.writeBytes("exit\n"); | 434 | os.writeBytes("exit\n"); |
628 | 434 | os.flush(); | 435 | os.flush(); |
629 | @@ -474,13 +475,9 @@ | |||
630 | 474 | Log.v(TAG, "Worker thread exited with: " + ret); | 475 | Log.v(TAG, "Worker thread exited with: " + ret); |
631 | 475 | // if script was not executed, then user did not granted SU permissions | 476 | // if script was not executed, then user did not granted SU permissions |
632 | 476 | if (ret == 255 || !scriptExecuted ) { | 477 | if (ret == 255 || !scriptExecuted ) { |
636 | 477 | result.putExtra(INSTALL_RESULT_EXTRA_INT, -1); | 478 | return handleInstallFail(result, -1, "Failed to get SU permissions"); |
634 | 478 | result.putExtra(INSTALL_RESULT_EXTRA_STR, "Failed to get SU permissions"); | ||
635 | 479 | return result; | ||
637 | 480 | } else if (ret != 0) { | 479 | } else if (ret != 0) { |
641 | 481 | result.putExtra(INSTALL_RESULT_EXTRA_INT, -1); | 480 | return handleInstallFail(result, -1, "Instalation failed"); |
639 | 482 | result.putExtra(INSTALL_RESULT_EXTRA_STR, "Instalation failed"); | ||
640 | 483 | return result; | ||
642 | 484 | } | 481 | } |
643 | 485 | running =false; | 482 | running =false; |
644 | 486 | } catch (IllegalThreadStateException e) { | 483 | } catch (IllegalThreadStateException e) { |
645 | @@ -491,9 +488,7 @@ | |||
646 | 491 | } catch (IOException e) { | 488 | } catch (IOException e) { |
647 | 492 | e.printStackTrace(); | 489 | e.printStackTrace(); |
648 | 493 | Log.w(TAG, "Update failed"); | 490 | Log.w(TAG, "Update failed"); |
652 | 494 | result.putExtra(INSTALL_RESULT_EXTRA_INT, -1); | 491 | return handleInstallFail(result, -1, "Install failed"); |
650 | 495 | result.putExtra(INSTALL_RESULT_EXTRA_STR, "Install failed"); | ||
651 | 496 | return result; | ||
653 | 497 | } | 492 | } |
654 | 498 | } finally { | 493 | } finally { |
655 | 499 | if (mWakeLock != null && mWakeLock.isHeld()) { | 494 | if (mWakeLock != null && mWakeLock.isHeld()) { |
656 | @@ -508,6 +503,13 @@ | |||
657 | 508 | result.putExtra(INSTALL_RESULT_EXTRA_INT, 0); | 503 | result.putExtra(INSTALL_RESULT_EXTRA_INT, 0); |
658 | 509 | return result; | 504 | return result; |
659 | 510 | } | 505 | } |
660 | 506 | |||
661 | 507 | private Intent handleInstallFail(Intent i, int res, String failReason) { | ||
662 | 508 | i.putExtra(INSTALL_RESULT_EXTRA_INT, -1); | ||
663 | 509 | i.putExtra(INSTALL_RESULT_EXTRA_STR, "Missing update command"); | ||
664 | 510 | doUninstallUbuntu(i); | ||
665 | 511 | return i; | ||
666 | 512 | } | ||
667 | 511 | 513 | ||
668 | 512 | private Intent doUninstallUbuntu(Intent intent) { | 514 | private Intent doUninstallUbuntu(Intent intent) { |
669 | 513 | File workingFolder = new File(mRootOfWorkPath, TEMP_FOLDER); | 515 | File workingFolder = new File(mRootOfWorkPath, TEMP_FOLDER); |
670 | @@ -588,13 +590,13 @@ | |||
671 | 588 | try { | 590 | try { |
672 | 589 | Process process = Runtime.getRuntime().exec("su", null, getFilesDir()); | 591 | Process process = Runtime.getRuntime().exec("su", null, getFilesDir()); |
673 | 590 | DataOutputStream os = new DataOutputStream(process.getOutputStream()); | 592 | DataOutputStream os = new DataOutputStream(process.getOutputStream()); |
675 | 591 | 593 | ||
676 | 592 | Utils.extractExecutableAsset(this, ANDROID_BOOTMGR, getFilesDir().toString(), true); | 594 | Utils.extractExecutableAsset(this, ANDROID_BOOTMGR, getFilesDir().toString(), true); |
677 | 593 | // overwrite the recovery partition. | 595 | // overwrite the recovery partition. |
678 | 594 | os.writeBytes(String.format("%s/%s -b %s/%s %s\n", | 596 | os.writeBytes(String.format("%s/%s -b %s/%s %s\n", |
680 | 595 | getFilesDir().toString(), | 597 | getFilesDir().getAbsolutePath(), |
681 | 596 | ANDROID_BOOTMGR, | 598 | ANDROID_BOOTMGR, |
683 | 597 | getFilesDir().toString(), | 599 | getFilesDir().getAbsolutePath(), |
684 | 598 | UBUNTU_BOOT_IMG, | 600 | UBUNTU_BOOT_IMG, |
685 | 599 | Utils.getRecoveryPartitionPath() | 601 | Utils.getRecoveryPartitionPath() |
686 | 600 | )); | 602 | )); |
687 | @@ -643,9 +645,12 @@ | |||
688 | 643 | try { | 645 | try { |
689 | 644 | Process process = Runtime.getRuntime().exec("su", null, workingFolder); | 646 | Process process = Runtime.getRuntime().exec("su", null, workingFolder); |
690 | 645 | DataOutputStream os = new DataOutputStream(process.getOutputStream()); | 647 | DataOutputStream os = new DataOutputStream(process.getOutputStream()); |
691 | 648 | // make sure we are in work folder | ||
692 | 646 | os.writeBytes("echo \"SU granted\"\n"); | 649 | os.writeBytes("echo \"SU granted\"\n"); |
693 | 647 | for (String c : commands) { | 650 | for (String c : commands) { |
694 | 648 | Log.v(TAG, "Executing:" + c); | 651 | Log.v(TAG, "Executing:" + c); |
695 | 652 | // make sure we are always at working folder before running next command | ||
696 | 653 | os.writeBytes(String.format("cd %s\n", workingFolder.getAbsolutePath())); | ||
697 | 649 | os.writeBytes(c); | 654 | os.writeBytes(c); |
698 | 650 | } | 655 | } |
699 | 651 | os.writeBytes(String.format("rm -rf %s\n", workingFolder.getAbsolutePath())); | 656 | os.writeBytes(String.format("rm -rf %s\n", workingFolder.getAbsolutePath())); |
700 | @@ -728,9 +733,7 @@ | |||
701 | 728 | if (releases.size() == 0 || releases.get(0).files.length == 0 ) { | 733 | if (releases.size() == 0 || releases.get(0).files.length == 0 ) { |
702 | 729 | // something is wrong, empty release | 734 | // something is wrong, empty release |
703 | 730 | Log.e(TAG, "Empty releas"); | 735 | Log.e(TAG, "Empty releas"); |
707 | 731 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | 736 | return handleDownloadError(result, -1, "Empty release"); |
705 | 732 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "Empty release"); | ||
706 | 733 | return result; | ||
708 | 734 | } | 737 | } |
709 | 735 | // get right version, otherwise first since that is most recent one | 738 | // get right version, otherwise first since that is most recent one |
710 | 736 | Image choosenRelease = null; | 739 | Image choosenRelease = null; |
711 | @@ -744,9 +747,7 @@ | |||
712 | 744 | } | 747 | } |
713 | 745 | if (choosenRelease == null) { | 748 | if (choosenRelease == null) { |
714 | 746 | Log.e(TAG, "wrong release vwersion"); | 749 | Log.e(TAG, "wrong release vwersion"); |
718 | 747 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | 750 | return handleDownloadError(result, -1, "wrong release vwersion"); |
716 | 748 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "wrong release vwersion"); | ||
717 | 749 | return result; | ||
719 | 750 | } | 751 | } |
720 | 751 | } else { | 752 | } else { |
721 | 752 | choosenRelease = releases.get(0); | 753 | choosenRelease = releases.get(0); |
722 | @@ -771,9 +772,7 @@ | |||
723 | 771 | String s = deleteRelease(); | 772 | String s = deleteRelease(); |
724 | 772 | if (s != null) { | 773 | if (s != null) { |
725 | 773 | // remove failed | 774 | // remove failed |
729 | 774 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | 775 | return handleDownloadError(result, -1, s); |
727 | 775 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, s); | ||
728 | 776 | return result; | ||
730 | 777 | } | 776 | } |
731 | 778 | // make sure release folder exists | 777 | // make sure release folder exists |
732 | 779 | File release = new File(rootFolder,RELEASE_FOLDER); | 778 | File release = new File(rootFolder,RELEASE_FOLDER); |
733 | @@ -794,10 +793,7 @@ | |||
734 | 794 | msg += "/data need 2.5G for system plus " + String.valueOf(mTotalSize) + " bytes for download"; | 793 | msg += "/data need 2.5G for system plus " + String.valueOf(mTotalSize) + " bytes for download"; |
735 | 795 | } | 794 | } |
736 | 796 | Log.i(TAG, msg); | 795 | Log.i(TAG, msg); |
741 | 797 | 796 | return handleDownloadError(result, -1, msg); | |
738 | 798 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | ||
739 | 799 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, msg); | ||
740 | 800 | return result; | ||
742 | 801 | } | 797 | } |
743 | 802 | 798 | ||
744 | 803 | // mProgressSteps = mTotalDownloadSize / 100; // we want 1% steps | 799 | // mProgressSteps = mTotalDownloadSize / 100; // we want 1% steps |
745 | @@ -832,29 +828,19 @@ | |||
746 | 832 | } | 828 | } |
747 | 833 | } catch (MalformedURLException e) { | 829 | } catch (MalformedURLException e) { |
748 | 834 | Log.e(TAG, "Failed to download release:", e); | 830 | Log.e(TAG, "Failed to download release:", e); |
752 | 835 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | 831 | return handleDownloadError(result, -1, "Malformed release url"); |
750 | 836 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "Malformed release url"); | ||
751 | 837 | return result; | ||
753 | 838 | } catch (FileNotFoundException e) { | 832 | } catch (FileNotFoundException e) { |
754 | 839 | Log.e(TAG, "Failed to download release:", e); | 833 | Log.e(TAG, "Failed to download release:", e); |
758 | 840 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | 834 | return handleDownloadError(result, -1, "File not found"); |
756 | 841 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "File not found"); | ||
757 | 842 | return result; | ||
759 | 843 | } catch (IOException e){ | 835 | } catch (IOException e){ |
760 | 844 | Log.e(TAG, "Failed to download release:", e); | 836 | Log.e(TAG, "Failed to download release:", e); |
764 | 845 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | 837 | return handleDownloadError(result, -1, "IO Error"); |
762 | 846 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "IO Error"); | ||
763 | 847 | return result; | ||
765 | 848 | } catch (ESumNotMatchException e) { | 838 | } catch (ESumNotMatchException e) { |
766 | 849 | // Download file check sum error !! | 839 | // Download file check sum error !! |
770 | 850 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | 840 | return handleDownloadError(result, -1, "Download check sum error"); |
768 | 851 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "Download check sum error"); | ||
769 | 852 | return result; | ||
771 | 853 | } catch (ECancelException e) { | 841 | } catch (ECancelException e) { |
772 | 854 | // Download was cancelled by user | 842 | // Download was cancelled by user |
776 | 855 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -2); | 843 | return handleDownloadError(result, -2, "Download cancelled by user"); |
774 | 856 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "Download cancelled by user"); | ||
775 | 857 | return result; | ||
777 | 858 | } | 844 | } |
778 | 859 | 845 | ||
779 | 860 | Log.i(TAG, "Download done in " + (System.currentTimeMillis() - time )/1000 + " seconds"); | 846 | Log.i(TAG, "Download done in " + (System.currentTimeMillis() - time )/1000 + " seconds"); |
780 | @@ -907,9 +893,7 @@ | |||
781 | 907 | } | 893 | } |
782 | 908 | } catch (IOException e) { | 894 | } catch (IOException e) { |
783 | 909 | e.printStackTrace(); | 895 | e.printStackTrace(); |
787 | 910 | result.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); | 896 | return handleDownloadError(result, -1, "Failed to generate update command"); |
785 | 911 | result.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "Failed to generate update command"); | ||
786 | 912 | return result; | ||
788 | 913 | } | 897 | } |
789 | 914 | broadcastProgress(-1, "Download done in " + (System.currentTimeMillis() - time )/1000 + " seconds"); | 898 | broadcastProgress(-1, "Download done in " + (System.currentTimeMillis() - time )/1000 + " seconds"); |
790 | 915 | int estimatedCheckCount = 0; | 899 | int estimatedCheckCount = 0; |
791 | @@ -939,9 +923,11 @@ | |||
792 | 939 | return result; | 923 | return result; |
793 | 940 | } | 924 | } |
794 | 941 | 925 | ||
798 | 942 | class DownloadTask { | 926 | private Intent handleDownloadError(Intent i, int res, String reason) { |
799 | 943 | URL url; | 927 | i.putExtra(DOWNLOAD_RESULT_EXTRA_INT, -1); |
800 | 944 | File targetFolder; | 928 | i.putExtra(DOWNLOAD_RESULT_EXTRA_STR, "Failed to generate update command"); |
801 | 929 | deleteRelease(); | ||
802 | 930 | return i; | ||
803 | 945 | } | 931 | } |
804 | 946 | 932 | ||
805 | 947 | private String doDownloadUrl(URL url, File targerLocation) throws MalformedURLException, | 933 | private String doDownloadUrl(URL url, File targerLocation) throws MalformedURLException, |
806 | @@ -1018,12 +1004,19 @@ | |||
807 | 1018 | return null; | 1004 | return null; |
808 | 1019 | } | 1005 | } |
809 | 1020 | 1006 | ||
811 | 1021 | private void broadcastServiceState() { | 1007 | private void broadcastInstallerState() { |
812 | 1022 | Intent i = new Intent(SERVICE_STATE); | 1008 | Intent i = new Intent(SERVICE_STATE); |
814 | 1023 | i.putExtra(SERVICE_STATE, mServiceState.ordinal()); | 1009 | i.putExtra(SERVICE_STATE, mInstallerState.ordinal()); |
815 | 1024 | sendBroadcast(i); | 1010 | sendBroadcast(i); |
816 | 1025 | } | 1011 | } |
817 | 1026 | 1012 | ||
818 | 1013 | private void updateInstallerState(InstallerState newState) { | ||
819 | 1014 | mInstallerState = newState; | ||
820 | 1015 | Intent i = new Intent(SERVICE_STATE); | ||
821 | 1016 | i.putExtra(SERVICE_STATE, mInstallerState.ordinal()); | ||
822 | 1017 | sendBroadcast(i); | ||
823 | 1018 | } | ||
824 | 1019 | |||
825 | 1027 | private void broadcastProgress(int val, String progress) { | 1020 | private void broadcastProgress(int val, String progress) { |
826 | 1028 | Intent i = new Intent(PROGRESS); | 1021 | Intent i = new Intent(PROGRESS); |
827 | 1029 | i.putExtra(PROGRESS_EXTRA_INT, val); | 1022 | i.putExtra(PROGRESS_EXTRA_INT, val); |
828 | @@ -1092,16 +1085,17 @@ | |||
829 | 1092 | public static boolean checkifReadyToInstall(Context context) { | 1085 | public static boolean checkifReadyToInstall(Context context) { |
830 | 1093 | SharedPreferences pref = context.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE); | 1086 | SharedPreferences pref = context.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE); |
831 | 1094 | String command = pref.getString(PREF_KEY_UPDATE_COMMAND, ""); | 1087 | String command = pref.getString(PREF_KEY_UPDATE_COMMAND, ""); |
832 | 1095 | boolean ready = false; | ||
833 | 1096 | if (!command.equals("")){ | 1088 | if (!command.equals("")){ |
834 | 1097 | File f = new File(command); | 1089 | File f = new File(command); |
835 | 1098 | if (f.exists()) { | 1090 | if (f.exists()) { |
836 | 1099 | return true; | 1091 | return true; |
837 | 1100 | } else { | 1092 | } else { |
838 | 1101 | pref.edit().putString(PREF_KEY_UPDATE_COMMAND, "").commit(); | 1093 | pref.edit().putString(PREF_KEY_UPDATE_COMMAND, "").commit(); |
839 | 1094 | VersionInfo.storeEmptyVersion(pref.edit(), PREF_KEY_DOWNLOADED_VERSION); | ||
840 | 1102 | return false; | 1095 | return false; |
841 | 1103 | } | 1096 | } |
842 | 1104 | } | 1097 | } |
843 | 1098 | VersionInfo.storeEmptyVersion(pref.edit(), PREF_KEY_DOWNLOADED_VERSION); | ||
844 | 1105 | return false; | 1099 | return false; |
845 | 1106 | } | 1100 | } |
846 | 1107 | } | 1101 | } |
look good to me.