OpenDelta: Refactor state handling out of UpdateService
TBD: Move more things out such as download handling
This commit is contained in:
parent
adf8449d9e
commit
5f25015f18
|
@ -137,7 +137,7 @@
|
||||||
<string name="flash_file_notice_message"><b>Attention:</b> There will be no checks if the selected ZIP file is suitable for your device!\n\n<b>Flashing the wrong ZIP can lead to a non functional device!</b></string>
|
<string name="flash_file_notice_message"><b>Attention:</b> There will be no checks if the selected ZIP file is suitable for your device!\n\n<b>Flashing the wrong ZIP can lead to a non functional device!</b></string>
|
||||||
<string name="channel_name">Update progress</string>
|
<string name="channel_name">Update progress</string>
|
||||||
<string name="channel_description"></string>
|
<string name="channel_description"></string>
|
||||||
<string name="text_update_file_flash_title">Update file</string>
|
<string name="text_update_file_flash_title">Update file:</string>
|
||||||
<string name="text_info_section">Press check to see if an update is available. After an update has been flashed you will be asked to reboot. Devices with a traditional recovery based update will enter recovery on reboot to execute the flash process. If your device supports seamless updates (A/B) the reboot will activate the update.</string>
|
<string name="text_info_section">Press check to see if an update is available. After an update has been flashed you will be asked to reboot. Devices with a traditional recovery based update will enter recovery on reboot to execute the flash process. If your device supports seamless updates (A/B) the reboot will activate the update.</string>
|
||||||
<string name="error_ab_timestamp">Current version is newer than the update</string>
|
<string name="error_ab_timestamp">Current version is newer than the update</string>
|
||||||
<string name="error_ab_inactive">Update is already installed and a reboot is needed</string>
|
<string name="error_ab_inactive">Update is already installed and a reboot is needed</string>
|
||||||
|
|
|
@ -154,7 +154,7 @@ public class MainActivity extends Activity {
|
||||||
updateInfoVisibility();
|
updateInfoVisibility();
|
||||||
|
|
||||||
if (mUpdateService == null) {
|
if (mUpdateService == null) {
|
||||||
startUpdateService(UpdateService.STATE_ACTION_NONE);
|
startUpdateService(State.ACTION_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,12 +217,12 @@ public class MainActivity extends Activity {
|
||||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||||
UpdateService.LocalBinder binder = (UpdateService.LocalBinder) iBinder;
|
UpdateService.LocalBinder binder = (UpdateService.LocalBinder) iBinder;
|
||||||
mUpdateService = binder.getService();
|
mUpdateService = binder.getService();
|
||||||
mUpdateService.registerStateCallback(updateReceiver);
|
mUpdateService.getState().registerStateCallback(updateReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName componentName) {
|
public void onServiceDisconnected(ComponentName componentName) {
|
||||||
mUpdateService.unregisterStateCallback();
|
mUpdateService.getState().unregisterStateCallback();
|
||||||
mUpdateService = null;
|
mUpdateService = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -251,7 +251,7 @@ public class MainActivity extends Activity {
|
||||||
mUpdateService.setFlashFilename(flashFilename);
|
mUpdateService.setFlashFilename(flashFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final UpdateService.StateCallback updateReceiver = new UpdateService.StateCallback() {
|
private final State.StateCallback updateReceiver = new State.StateCallback() {
|
||||||
private String formatLastChecked(long ms) {
|
private String formatLastChecked(long ms) {
|
||||||
if (ms == 0) {
|
if (ms == 0) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -262,9 +262,9 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(String state, Float progress,
|
public void update(String state, Float progress,
|
||||||
Long current, Long total, String filename,
|
Long current, Long total, String filename,
|
||||||
Long ms, int errorCode) {
|
Long ms, int errorCode) {
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
String title = "";
|
String title = "";
|
||||||
String sub = "";
|
String sub = "";
|
||||||
|
@ -312,17 +312,17 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
// check for first start until check button has been pressed
|
// check for first start until check button has been pressed
|
||||||
// use a special title then - but only once
|
// use a special title then - but only once
|
||||||
if (UpdateService.STATE_ACTION_NONE.equals(state)
|
if (State.ACTION_NONE.equals(state)
|
||||||
&& !mPrefs.getBoolean(SettingsActivity.PREF_START_HINT_SHOWN, false)) {
|
&& !mPrefs.getBoolean(SettingsActivity.PREF_START_HINT_SHOWN, false)) {
|
||||||
title = getString(R.string.last_checked_never_title_new);
|
title = getString(R.string.last_checked_never_title_new);
|
||||||
}
|
}
|
||||||
// don't spill for progress
|
// don't spill for progress
|
||||||
if (!UpdateService.isProgressState(state)) {
|
if (!State.isProgressState(state)) {
|
||||||
Logger.d("onReceive state = " + state);
|
Logger.d("onReceive state = " + state);
|
||||||
} else if (state.equals(mState)) {
|
} else if (state.equals(mState)) {
|
||||||
// same progress state as before.
|
// same progress state as before.
|
||||||
// save a lot of time by only updating progress
|
// save a lot of time by only updating progress
|
||||||
disableDataSpeed = UpdateService.STATE_ACTION_AB_FLASH.equals(state);
|
disableDataSpeed = State.ACTION_AB_FLASH.equals(state);
|
||||||
// long --> int overflows FTL (progress.setXXX)
|
// long --> int overflows FTL (progress.setXXX)
|
||||||
boolean progressInK = false;
|
boolean progressInK = false;
|
||||||
if (localTotal > 1024L * 1024L * 1024L) {
|
if (localTotal > 1024L * 1024L * 1024L) {
|
||||||
|
@ -365,7 +365,7 @@ public class MainActivity extends Activity {
|
||||||
mState = state;
|
mState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UpdateService.STATE_ERROR_DISK_SPACE.equals(state)) {
|
if (State.ERROR_DISK_SPACE.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
localCurrent /= 1024L * 1024L;
|
localCurrent /= 1024L * 1024L;
|
||||||
|
@ -373,28 +373,28 @@ public class MainActivity extends Activity {
|
||||||
|
|
||||||
extraText = getString(R.string.error_disk_space_sub,
|
extraText = getString(R.string.error_disk_space_sub,
|
||||||
localCurrent, localTotal);
|
localCurrent, localTotal);
|
||||||
} else if (UpdateService.STATE_ERROR_UNKNOWN.equals(state)) {
|
} else if (State.ERROR_UNKNOWN.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
} else if (UpdateService.STATE_ERROR_UNOFFICIAL.equals(state)) {
|
} else if (State.ERROR_UNOFFICIAL.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
extraText = getString(R.string.state_error_not_official_extra, versionType);
|
extraText = getString(R.string.state_error_not_official_extra, versionType);
|
||||||
} else if (UpdateService.STATE_ERROR_DOWNLOAD.equals(state)) {
|
} else if (State.ERROR_DOWNLOAD.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
} else if (UpdateService.STATE_ERROR_CONNECTION.equals(state)) {
|
} else if (State.ERROR_CONNECTION.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
} else if (UpdateService.STATE_ERROR_PERMISSIONS.equals(state)) {
|
} else if (State.ERROR_PERMISSIONS.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
} else if (UpdateService.STATE_ERROR_FLASH.equals(state)) {
|
} else if (State.ERROR_FLASH.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
enableFlash = true;
|
enableFlash = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
title = getString(R.string.state_error_flash_title);
|
title = getString(R.string.state_error_flash_title);
|
||||||
} else if (UpdateService.STATE_ERROR_AB_FLASH.equals(state)) {
|
} else if (State.ERROR_AB_FLASH.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
title = getString(R.string.state_error_ab_flash_title);
|
title = getString(R.string.state_error_ab_flash_title);
|
||||||
|
@ -403,14 +403,14 @@ public class MainActivity extends Activity {
|
||||||
} else if (errorCode == UpdateEngine.ErrorCodeConstants.UPDATED_BUT_NOT_ACTIVE) {
|
} else if (errorCode == UpdateEngine.ErrorCodeConstants.UPDATED_BUT_NOT_ACTIVE) {
|
||||||
extraText = getString(R.string.error_ab_inactive);
|
extraText = getString(R.string.error_ab_inactive);
|
||||||
}
|
}
|
||||||
} else if (UpdateService.STATE_ERROR_FLASH_FILE.equals(state)) {
|
} else if (State.ERROR_FLASH_FILE.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
title = getString(R.string.state_error_flash_file_title);
|
title = getString(R.string.state_error_flash_file_title);
|
||||||
} else if (UpdateService.STATE_ACTION_NONE.equals(state)) {
|
} else if (State.ACTION_NONE.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
} else if (UpdateService.STATE_ACTION_READY.equals(state)) {
|
} else if (State.ACTION_READY.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
enableFlash = true;
|
enableFlash = true;
|
||||||
enableChangelog = true;
|
enableChangelog = true;
|
||||||
|
@ -425,7 +425,7 @@ public class MainActivity extends Activity {
|
||||||
flashImageBase.lastIndexOf('.'));
|
flashImageBase.lastIndexOf('.'));
|
||||||
}
|
}
|
||||||
mUpdateVersionTitle.setText(R.string.text_update_version_title);
|
mUpdateVersionTitle.setText(R.string.text_update_version_title);
|
||||||
} else if (UpdateService.STATE_ACTION_FLASH_FILE_READY.equals(state)) {
|
} else if (State.ACTION_FLASH_FILE_READY.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
enableFlash = true;
|
enableFlash = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
|
@ -438,7 +438,7 @@ public class MainActivity extends Activity {
|
||||||
updateVersion = flashImageBase;
|
updateVersion = flashImageBase;
|
||||||
}
|
}
|
||||||
mUpdateVersionTitle.setText(R.string.text_update_file_flash_title);
|
mUpdateVersionTitle.setText(R.string.text_update_file_flash_title);
|
||||||
} else if (UpdateService.STATE_ACTION_AB_FINISHED.equals(state)) {
|
} else if (State.ACTION_AB_FINISHED.equals(state)) {
|
||||||
enableReboot = true;
|
enableReboot = true;
|
||||||
disableCheckNow = true;
|
disableCheckNow = true;
|
||||||
enableChangelog = !mPrefs.getBoolean(UpdateService.PREF_FILE_FLASH, false);
|
enableChangelog = !mPrefs.getBoolean(UpdateService.PREF_FILE_FLASH, false);
|
||||||
|
@ -455,7 +455,7 @@ public class MainActivity extends Activity {
|
||||||
|
|
||||||
mPrefs.edit().putString(UpdateService.PREF_READY_FILENAME_NAME, null).commit();
|
mPrefs.edit().putString(UpdateService.PREF_READY_FILENAME_NAME, null).commit();
|
||||||
mPrefs.edit().putString(UpdateService.PREF_LATEST_FULL_NAME, null).commit();
|
mPrefs.edit().putString(UpdateService.PREF_LATEST_FULL_NAME, null).commit();
|
||||||
} else if (UpdateService.STATE_ACTION_BUILD.equals(state)) {
|
} else if (State.ACTION_BUILD.equals(state)) {
|
||||||
enableCheck = true;
|
enableCheck = true;
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
|
|
||||||
|
@ -494,21 +494,21 @@ public class MainActivity extends Activity {
|
||||||
} else {
|
} else {
|
||||||
downloadSizeText = Formatter.formatFileSize(getApplicationContext(), downloadSize);
|
downloadSizeText = Formatter.formatFileSize(getApplicationContext(), downloadSize);
|
||||||
}
|
}
|
||||||
} else if (UpdateService.STATE_ACTION_SEARCHING.equals(state)
|
} else if (State.ACTION_SEARCHING.equals(state)
|
||||||
|| UpdateService.STATE_ACTION_CHECKING.equals(state)) {
|
|| State.ACTION_CHECKING.equals(state)) {
|
||||||
enableProgress = true;
|
enableProgress = true;
|
||||||
mProgress.setIndeterminate(true);
|
mProgress.setIndeterminate(true);
|
||||||
localCurrent = 1L;
|
localCurrent = 1L;
|
||||||
} else {
|
} else {
|
||||||
enableChangelog = !mPrefs.getBoolean(UpdateService.PREF_FILE_FLASH, false);
|
enableChangelog = !mPrefs.getBoolean(UpdateService.PREF_FILE_FLASH, false);
|
||||||
enableProgress = true;
|
enableProgress = true;
|
||||||
if (UpdateService.STATE_ACTION_AB_FLASH.equals(state)) {
|
if (State.ACTION_AB_FLASH.equals(state)) {
|
||||||
disableDataSpeed = true;
|
disableDataSpeed = true;
|
||||||
} else if (UpdateService.STATE_ACTION_DOWNLOADING.equals(state)) {
|
} else if (State.ACTION_DOWNLOADING.equals(state)) {
|
||||||
disableCheckNow = true;
|
disableCheckNow = true;
|
||||||
enableDownload = true;
|
enableDownload = true;
|
||||||
} else if (UpdateService.STATE_ERROR_DOWNLOAD_RESUME.equals(state) ||
|
} else if (State.ERROR_DOWNLOAD_RESUME.equals(state) ||
|
||||||
UpdateService.STATE_ACTION_DOWNLOADING_PAUSED.equals(state)) {
|
State.ACTION_DOWNLOADING_PAUSED.equals(state)) {
|
||||||
disableCheckNow = true;
|
disableCheckNow = true;
|
||||||
enableDownload = true;
|
enableDownload = true;
|
||||||
enableResume = true;
|
enableResume = true;
|
||||||
|
@ -772,7 +772,7 @@ public class MainActivity extends Activity {
|
||||||
startUpdateServiceFile(flashFilename);
|
startUpdateServiceFile(flashFilename);
|
||||||
} else {
|
} else {
|
||||||
Intent i = new Intent(UpdateService.BROADCAST_INTENT);
|
Intent i = new Intent(UpdateService.BROADCAST_INTENT);
|
||||||
i.putExtra(UpdateService.EXTRA_STATE, UpdateService.STATE_ERROR_FLASH_FILE);
|
i.putExtra(UpdateService.EXTRA_STATE, State.ERROR_FLASH_FILE);
|
||||||
sendBroadcast(i);
|
sendBroadcast(i);
|
||||||
}
|
}
|
||||||
} else if (requestCode == PERMISSIONS_REQUEST_MANAGE_EXTERNAL_STORAGE
|
} else if (requestCode == PERMISSIONS_REQUEST_MANAGE_EXTERNAL_STORAGE
|
||||||
|
@ -842,7 +842,7 @@ public class MainActivity extends Activity {
|
||||||
ACTIVITY_SELECT_FLASH_FILE);
|
ACTIVITY_SELECT_FLASH_FILE);
|
||||||
} catch (android.content.ActivityNotFoundException ex) {
|
} catch (android.content.ActivityNotFoundException ex) {
|
||||||
Intent i = new Intent(UpdateService.BROADCAST_INTENT);
|
Intent i = new Intent(UpdateService.BROADCAST_INTENT);
|
||||||
i.putExtra(UpdateService.EXTRA_STATE, UpdateService.STATE_ERROR_FLASH_FILE);
|
i.putExtra(UpdateService.EXTRA_STATE, State.ERROR_FLASH_FILE);
|
||||||
sendBroadcast(i);
|
sendBroadcast(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,146 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2022 Yet Another AOSP Project
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of OpenDelta.
|
||||||
|
*
|
||||||
|
* OpenDelta is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* OpenDelta is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with OpenDelta. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package eu.chainfire.opendelta;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class State {
|
||||||
|
public static final String ACTION_NONE = "action_none";
|
||||||
|
public static final String ACTION_CHECKING = "action_checking";
|
||||||
|
public static final String ACTION_CHECKING_SUM = "action_checking_sum";
|
||||||
|
public static final String ACTION_SEARCHING = "action_searching";
|
||||||
|
public static final String ACTION_SEARCHING_SUM = "action_searching_sum";
|
||||||
|
public static final String ACTION_DOWNLOADING = "action_downloading";
|
||||||
|
public static final String ACTION_DOWNLOADING_PAUSED = "action_downloading_paused";
|
||||||
|
public static final String ACTION_APPLYING = "action_applying";
|
||||||
|
public static final String ACTION_APPLYING_PATCH = "action_applying_patch";
|
||||||
|
public static final String ACTION_APPLYING_SUM = "action_applying_sum";
|
||||||
|
public static final String ACTION_READY = "action_ready";
|
||||||
|
public static final String ACTION_AB_FLASH = "action_ab_flash";
|
||||||
|
public static final String ACTION_AB_FINISHED = "action_ab_finished";
|
||||||
|
public static final String ACTION_BUILD = "action_build";
|
||||||
|
public static final String ACTION_FLASH_FILE_READY = "action_flash_file_ready";
|
||||||
|
public static final String ERROR_DISK_SPACE = "error_disk_space";
|
||||||
|
public static final String ERROR_UNKNOWN = "error_unknown";
|
||||||
|
public static final String ERROR_UNOFFICIAL = "error_unofficial";
|
||||||
|
public static final String ERROR_DOWNLOAD = "error_download";
|
||||||
|
public static final String ERROR_DOWNLOAD_RESUME = "error_download_resume";
|
||||||
|
public static final String ERROR_CONNECTION = "error_connection";
|
||||||
|
public static final String ERROR_PERMISSIONS = "error_permissions";
|
||||||
|
public static final String ERROR_FLASH = "error_flash";
|
||||||
|
public static final String ERROR_AB_FLASH = "error_ab_flash";
|
||||||
|
public static final String ERROR_FLASH_FILE = "error_flash_file";
|
||||||
|
|
||||||
|
private static final Set<String> mProgressStates = Set.of(
|
||||||
|
ACTION_DOWNLOADING,
|
||||||
|
ACTION_SEARCHING,
|
||||||
|
ACTION_SEARCHING_SUM,
|
||||||
|
ACTION_CHECKING,
|
||||||
|
ACTION_CHECKING_SUM,
|
||||||
|
ACTION_APPLYING,
|
||||||
|
ACTION_APPLYING_SUM,
|
||||||
|
ACTION_APPLYING_PATCH,
|
||||||
|
ACTION_AB_FLASH
|
||||||
|
);
|
||||||
|
|
||||||
|
private static final Set<String> mErrorStates = Set.of(
|
||||||
|
ERROR_DOWNLOAD,
|
||||||
|
ERROR_DOWNLOAD_RESUME,
|
||||||
|
ERROR_DISK_SPACE,
|
||||||
|
ERROR_UNKNOWN,
|
||||||
|
ERROR_UNOFFICIAL,
|
||||||
|
ERROR_CONNECTION,
|
||||||
|
ERROR_AB_FLASH,
|
||||||
|
ERROR_FLASH_FILE,
|
||||||
|
ERROR_FLASH
|
||||||
|
);
|
||||||
|
|
||||||
|
private static State mState;
|
||||||
|
private String mStateStr = ACTION_NONE;
|
||||||
|
private StateCallback mStateCallback;
|
||||||
|
|
||||||
|
private State() {}
|
||||||
|
|
||||||
|
public interface StateCallback {
|
||||||
|
void update(String state, Float progress,
|
||||||
|
Long current, Long total, String filename,
|
||||||
|
Long ms, int errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerStateCallback(StateCallback callback) {
|
||||||
|
mStateCallback = callback;
|
||||||
|
update(mStateStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterStateCallback() {
|
||||||
|
mStateCallback = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static State getInstance() {
|
||||||
|
if (mState == null) mState = new State();
|
||||||
|
return mState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(String state) {
|
||||||
|
update(state, null, null, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(String state, Float progress,
|
||||||
|
Long current, Long total, String filename, Long ms) {
|
||||||
|
update(state, progress, current, total, filename, ms, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void update(String state, Float progress,
|
||||||
|
Long current, Long total, String filename, Long ms, int errorCode) {
|
||||||
|
mStateStr = state;
|
||||||
|
if (mStateCallback != null)
|
||||||
|
mStateCallback.update(state, progress, current,
|
||||||
|
total, filename, ms, errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized String getState() {
|
||||||
|
return mStateStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isProgressState() {
|
||||||
|
return isProgressState(mStateStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isErrorState() {
|
||||||
|
return isErrorState(mStateStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isProgressState(String state) {
|
||||||
|
return mProgressStates.contains(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isErrorState(String state) {
|
||||||
|
return mErrorStates.contains(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(String state) {
|
||||||
|
return state.equals(mStateStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return mStateStr;
|
||||||
|
}
|
||||||
|
}
|
|
@ -114,32 +114,6 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
public static final String EXTRA_STATE = "eu.chainfire.opendelta.extra.ACTION_STATE";
|
public static final String EXTRA_STATE = "eu.chainfire.opendelta.extra.ACTION_STATE";
|
||||||
public static final String EXTRA_FILENAME = "eu.chainfire.opendelta.extra.FILENAME";
|
public static final String EXTRA_FILENAME = "eu.chainfire.opendelta.extra.FILENAME";
|
||||||
|
|
||||||
public static final String STATE_ACTION_NONE = "action_none";
|
|
||||||
public static final String STATE_ACTION_CHECKING = "action_checking";
|
|
||||||
public static final String STATE_ACTION_CHECKING_SUM = "action_checking_sum";
|
|
||||||
public static final String STATE_ACTION_SEARCHING = "action_searching";
|
|
||||||
public static final String STATE_ACTION_SEARCHING_SUM = "action_searching_sum";
|
|
||||||
public static final String STATE_ACTION_DOWNLOADING = "action_downloading";
|
|
||||||
public static final String STATE_ACTION_DOWNLOADING_PAUSED = "action_downloading_paused";
|
|
||||||
public static final String STATE_ACTION_APPLYING = "action_applying";
|
|
||||||
public static final String STATE_ACTION_APPLYING_PATCH = "action_applying_patch";
|
|
||||||
public static final String STATE_ACTION_APPLYING_SUM = "action_applying_sum";
|
|
||||||
public static final String STATE_ACTION_READY = "action_ready";
|
|
||||||
public static final String STATE_ACTION_AB_FLASH = "action_ab_flash";
|
|
||||||
public static final String STATE_ACTION_AB_FINISHED = "action_ab_finished";
|
|
||||||
public static final String STATE_ERROR_DISK_SPACE = "error_disk_space";
|
|
||||||
public static final String STATE_ERROR_UNKNOWN = "error_unknown";
|
|
||||||
public static final String STATE_ERROR_UNOFFICIAL = "error_unofficial";
|
|
||||||
public static final String STATE_ACTION_BUILD = "action_build";
|
|
||||||
public static final String STATE_ERROR_DOWNLOAD = "error_download";
|
|
||||||
public static final String STATE_ERROR_DOWNLOAD_RESUME = "error_download_resume";
|
|
||||||
public static final String STATE_ERROR_CONNECTION = "error_connection";
|
|
||||||
public static final String STATE_ERROR_PERMISSIONS = "error_permissions";
|
|
||||||
public static final String STATE_ERROR_FLASH = "error_flash";
|
|
||||||
public static final String STATE_ERROR_AB_FLASH = "error_ab_flash";
|
|
||||||
public static final String STATE_ERROR_FLASH_FILE = "error_flash_file";
|
|
||||||
public static final String STATE_ACTION_FLASH_FILE_READY = "action_flash_file_ready";
|
|
||||||
|
|
||||||
public static final String ACTION_CHECK = "eu.chainfire.opendelta.action.CHECK";
|
public static final String ACTION_CHECK = "eu.chainfire.opendelta.action.CHECK";
|
||||||
public static final String ACTION_FLASH = "eu.chainfire.opendelta.action.FLASH";
|
public static final String ACTION_FLASH = "eu.chainfire.opendelta.action.FLASH";
|
||||||
public static final String ACTION_ALARM = "eu.chainfire.opendelta.action.ALARM";
|
public static final String ACTION_ALARM = "eu.chainfire.opendelta.action.ALARM";
|
||||||
|
@ -204,7 +178,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
private HandlerThread mHandlerThread;
|
private HandlerThread mHandlerThread;
|
||||||
private Handler mHandler;
|
private Handler mHandler;
|
||||||
|
|
||||||
private String mState = STATE_ACTION_NONE;
|
private State mState = State.getInstance();
|
||||||
|
|
||||||
private NetworkState mNetworkState;
|
private NetworkState mNetworkState;
|
||||||
private BatteryState mBatteryState;
|
private BatteryState mBatteryState;
|
||||||
|
@ -237,7 +211,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (now >= mLastProgressTime[0] + 250L) {
|
if (now >= mLastProgressTime[0] + 250L) {
|
||||||
long ms = SystemClock.elapsedRealtime() - mLastProgressTime[1];
|
long ms = SystemClock.elapsedRealtime() - mLastProgressTime[1];
|
||||||
int sec = (int) (((((float) total / (float) current) * (float) ms) - ms) / 1000f);
|
int sec = (int) (((((float) total / (float) current) * (float) ms) - ms) / 1000f);
|
||||||
updateState(STATE_ACTION_AB_FLASH, progress, current, total, this.status, ms);
|
mState.update(State.ACTION_AB_FLASH, progress, current, total, this.status, ms);
|
||||||
setFlashNotificationProgress((int) progress, sec);
|
setFlashNotificationProgress((int) progress, sec);
|
||||||
mLastProgressTime[0] = now;
|
mLastProgressTime[0] = now;
|
||||||
}
|
}
|
||||||
|
@ -256,23 +230,6 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private StateCallback mStateCallback;
|
|
||||||
|
|
||||||
public interface StateCallback {
|
|
||||||
void updateState(String state, Float progress,
|
|
||||||
Long current, Long total, String filename,
|
|
||||||
Long ms, int errorCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerStateCallback(StateCallback callback) {
|
|
||||||
mStateCallback = callback;
|
|
||||||
updateState(mState);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unregisterStateCallback() {
|
|
||||||
mStateCallback = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Using reflection voodoo instead calling the hidden class directly, to
|
* Using reflection voodoo instead calling the hidden class directly, to
|
||||||
* dev/test outside of AOSP tree
|
* dev/test outside of AOSP tree
|
||||||
|
@ -412,8 +369,8 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (mNotificationManager != null)
|
if (mNotificationManager != null)
|
||||||
mNotificationManager.cancel(NOTIFICATION_BUSY);
|
mNotificationManager.cancel(NOTIFICATION_BUSY);
|
||||||
// if we have a paused download in progress we need to manually stop it
|
// if we have a paused download in progress we need to manually stop it
|
||||||
if (mState.equals(STATE_ERROR_DOWNLOAD_RESUME) ||
|
if (mState.equals(State.ERROR_DOWNLOAD_RESUME) ||
|
||||||
mState.equals(STATE_ACTION_DOWNLOADING_PAUSED)) {
|
mState.equals(State.ACTION_DOWNLOADING_PAUSED)) {
|
||||||
// to do so we just need to remove the file and update state
|
// to do so we just need to remove the file and update state
|
||||||
File[] files = new File(mConfig.getPathBase()).listFiles();
|
File[] files = new File(mConfig.getPathBase()).listFiles();
|
||||||
for (File file : files)
|
for (File file : files)
|
||||||
|
@ -423,8 +380,8 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTION_DOWNLOAD_PAUSE:
|
case ACTION_DOWNLOAD_PAUSE:
|
||||||
final boolean isPaused = mState.equals(STATE_ACTION_DOWNLOADING_PAUSED) ||
|
final boolean isPaused = mState.equals(State.ACTION_DOWNLOADING_PAUSED) ||
|
||||||
mState.equals(STATE_ERROR_DOWNLOAD_RESUME);
|
mState.equals(State.ERROR_DOWNLOAD_RESUME);
|
||||||
if (isPaused) {
|
if (isPaused) {
|
||||||
// resume
|
// resume
|
||||||
mStopDownload = -1;
|
mStopDownload = -1;
|
||||||
|
@ -441,24 +398,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateState(String state) {
|
public State getState() {
|
||||||
updateState(state, null, null, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateState(String state, Float progress,
|
|
||||||
Long current, Long total, String filename, Long ms) {
|
|
||||||
updateState(state, progress, current, total, filename, ms, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void updateState(String state, Float progress,
|
|
||||||
Long current, Long total, String filename, Long ms, int errorCode) {
|
|
||||||
mState = state;
|
|
||||||
if (mStateCallback != null)
|
|
||||||
mStateCallback.updateState(state, progress, current,
|
|
||||||
total, filename, ms, errorCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized String getState() {
|
|
||||||
return mState;
|
return mState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,7 +420,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onWantUpdateCheck() {
|
public boolean onWantUpdateCheck() {
|
||||||
if (isProgressState(mState)) {
|
if (mState.isProgressState()) {
|
||||||
Logger.i("Blocked scheduler requests while running in state " + mState);
|
Logger.i("Blocked scheduler requests while running in state " + mState);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -519,7 +459,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
private void autoState(boolean userInitiated, int checkOnly, boolean notify) {
|
private void autoState(boolean userInitiated, int checkOnly, boolean notify) {
|
||||||
Logger.d("autoState state = " + mState + " userInitiated = " + userInitiated + " checkOnly = " + checkOnly);
|
Logger.d("autoState state = " + mState + " userInitiated = " + userInitiated + " checkOnly = " + checkOnly);
|
||||||
|
|
||||||
if (isErrorState(mState)) {
|
if (mState.isErrorState()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,11 +474,11 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (mLastProgressTime == null)
|
if (mLastProgressTime == null)
|
||||||
mLastProgressTime = new long[] { 0, SystemClock.elapsedRealtime() };
|
mLastProgressTime = new long[] { 0, SystemClock.elapsedRealtime() };
|
||||||
mProgressListener.setStatus(_filename);
|
mProgressListener.setStatus(_filename);
|
||||||
updateState(STATE_ACTION_AB_FLASH, 0f, 0L, 100L, _filename, null);
|
mState.update(State.ACTION_AB_FLASH, 0f, 0L, 100L, _filename, null);
|
||||||
mIsUpdateRunning = ABUpdate.resume(flashFilename, mProgressListener, this);
|
mIsUpdateRunning = ABUpdate.resume(flashFilename, mProgressListener, this);
|
||||||
if (!mIsUpdateRunning) {
|
if (!mIsUpdateRunning) {
|
||||||
mNotificationManager.cancel(NOTIFICATION_UPDATE);
|
mNotificationManager.cancel(NOTIFICATION_UPDATE);
|
||||||
updateState(STATE_ERROR_AB_FLASH);
|
mState.update(State.ERROR_AB_FLASH);
|
||||||
} else {
|
} else {
|
||||||
newFlashNotification(_filename);
|
newFlashNotification(_filename);
|
||||||
}
|
}
|
||||||
|
@ -572,7 +512,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
final long current = found.length();
|
final long current = found.length();
|
||||||
final long lastTime = mPrefs.getLong(PREF_LAST_DOWNLOAD_TIME, 0);
|
final long lastTime = mPrefs.getLong(PREF_LAST_DOWNLOAD_TIME, 0);
|
||||||
final float progress = ((float) current / (float) total) * 100f;
|
final float progress = ((float) current / (float) total) * 100f;
|
||||||
updateState(STATE_ACTION_DOWNLOADING_PAUSED, progress, current, total, latestFullBuild, lastTime);
|
mState.update(State.ACTION_DOWNLOADING_PAUSED, progress, current, total, latestFullBuild, lastTime);
|
||||||
// display paused notification with the proper title
|
// display paused notification with the proper title
|
||||||
newDownloadNotification(true, getString(R.string.state_action_downloading_paused));
|
newDownloadNotification(true, getString(R.string.state_action_downloading_paused));
|
||||||
mDownloadNotificationBuilder.setProgress(100, Math.round(progress), false);
|
mDownloadNotificationBuilder.setProgress(100, Math.round(progress), false);
|
||||||
|
@ -587,12 +527,12 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
Logger.d("Checking step done");
|
Logger.d("Checking step done");
|
||||||
if (!updateAvailable()) {
|
if (!updateAvailable()) {
|
||||||
Logger.d("System up to date");
|
Logger.d("System up to date");
|
||||||
updateState(STATE_ACTION_NONE, null, null, null, null,
|
mState.update(State.ACTION_NONE, null, null, null, null,
|
||||||
mPrefs.getLong(PREF_LAST_CHECK_TIME_NAME,
|
mPrefs.getLong(PREF_LAST_CHECK_TIME_NAME,
|
||||||
PREF_LAST_CHECK_TIME_DEFAULT));
|
PREF_LAST_CHECK_TIME_DEFAULT));
|
||||||
} else {
|
} else {
|
||||||
Logger.d("Update available");
|
Logger.d("Update available");
|
||||||
updateState(STATE_ACTION_BUILD, null, null, null, null,
|
mState.update(State.ACTION_BUILD, null, null, null, null,
|
||||||
mPrefs.getLong(PREF_LAST_CHECK_TIME_NAME,
|
mPrefs.getLong(PREF_LAST_CHECK_TIME_NAME,
|
||||||
PREF_LAST_CHECK_TIME_DEFAULT));
|
PREF_LAST_CHECK_TIME_DEFAULT));
|
||||||
if (!userInitiated && notify) {
|
if (!userInitiated && notify) {
|
||||||
|
@ -608,12 +548,12 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
|
|
||||||
if (filename == null) {
|
if (filename == null) {
|
||||||
Logger.d("System up to date");
|
Logger.d("System up to date");
|
||||||
updateState(STATE_ACTION_NONE, null, null, null, null,
|
mState.update(State.ACTION_NONE, null, null, null, null,
|
||||||
mPrefs.getLong(PREF_LAST_CHECK_TIME_NAME,
|
mPrefs.getLong(PREF_LAST_CHECK_TIME_NAME,
|
||||||
PREF_LAST_CHECK_TIME_DEFAULT));
|
PREF_LAST_CHECK_TIME_DEFAULT));
|
||||||
} else {
|
} else {
|
||||||
Logger.d("Update found: %s", filename);
|
Logger.d("Update found: %s", filename);
|
||||||
updateState(STATE_ACTION_READY, null, null, null, (new File(
|
mState.update(State.ACTION_READY, null, null, null, (new File(
|
||||||
filename)).getName(), mPrefs.getLong(
|
filename)).getName(), mPrefs.getLong(
|
||||||
PREF_LAST_CHECK_TIME_NAME, PREF_LAST_CHECK_TIME_DEFAULT));
|
PREF_LAST_CHECK_TIME_NAME, PREF_LAST_CHECK_TIME_DEFAULT));
|
||||||
|
|
||||||
|
@ -944,7 +884,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String userFN = f.getName().substring(0, f.getName().length() - 5);
|
final String userFN = f.getName().substring(0, f.getName().length() - 5);
|
||||||
updateState(STATE_ACTION_DOWNLOADING, 0f, 0L, 0L, userFN, null);
|
mState.update(State.ACTION_DOWNLOADING, 0f, 0L, 0L, userFN, null);
|
||||||
urlConnection = setupHttpsRequest(url);
|
urlConnection = setupHttpsRequest(url);
|
||||||
if (urlConnection == null) return false;
|
if (urlConnection == null) return false;
|
||||||
|
|
||||||
|
@ -957,12 +897,12 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
Logger.d("Resuming download at: " + offset);
|
Logger.d("Resuming download at: " + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateState(STATE_ACTION_DOWNLOADING, 0f, 0L, len, userFN, null);
|
mState.update(State.ACTION_DOWNLOADING, 0f, 0L, len, userFN, null);
|
||||||
|
|
||||||
long freeSpace = (new StatFs(mConfig.getPathBase()))
|
long freeSpace = (new StatFs(mConfig.getPathBase()))
|
||||||
.getAvailableBytes();
|
.getAvailableBytes();
|
||||||
if (freeSpace < len - offset) {
|
if (freeSpace < len - offset) {
|
||||||
updateState(STATE_ERROR_DISK_SPACE, null, freeSpace, len, null,
|
mState.update(State.ERROR_DISK_SPACE, null, freeSpace, len, null,
|
||||||
null);
|
null);
|
||||||
Logger.d("not enough space!");
|
Logger.d("not enough space!");
|
||||||
return false;
|
return false;
|
||||||
|
@ -979,7 +919,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
progress = ((float) current / (float) total) * 100f;
|
progress = ((float) current / (float) total) * 100f;
|
||||||
long now = SystemClock.elapsedRealtime();
|
long now = SystemClock.elapsedRealtime();
|
||||||
if (now >= last[2] + 250L) {
|
if (now >= last[2] + 250L) {
|
||||||
updateState(STATE_ACTION_DOWNLOADING, progress,
|
mState.update(State.ACTION_DOWNLOADING, progress,
|
||||||
current, total, userFN, now - last[3]);
|
current, total, userFN, now - last[3]);
|
||||||
setDownloadNotificationProgress(progress, current,
|
setDownloadNotificationProgress(progress, current,
|
||||||
total,now - last[3]);
|
total,now - last[3]);
|
||||||
|
@ -1016,7 +956,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
|
|
||||||
StringBuilder SUM;
|
StringBuilder SUM;
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
SUM = new StringBuilder(getFileSHA256(f, getSUMProgress(STATE_ACTION_CHECKING_SUM, f.getName())));
|
SUM = new StringBuilder(getFileSHA256(f, getSUMProgress(State.ACTION_CHECKING_SUM, f.getName())));
|
||||||
} else {
|
} else {
|
||||||
if (digest == null) return false;
|
if (digest == null) return false;
|
||||||
SUM = new StringBuilder(new BigInteger(1, digest.digest())
|
SUM = new StringBuilder(new BigInteger(1, digest.digest())
|
||||||
|
@ -1033,7 +973,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
Logger.i("SUM check failed for " + url);
|
Logger.i("SUM check failed for " + url);
|
||||||
// if sum does not match when done, get rid
|
// if sum does not match when done, get rid
|
||||||
f.delete();
|
f.delete();
|
||||||
updateState(STATE_ERROR_DOWNLOAD);
|
mState.update(State.ERROR_DOWNLOAD);
|
||||||
}
|
}
|
||||||
return sumCheck;
|
return sumCheck;
|
||||||
}
|
}
|
||||||
|
@ -1110,7 +1050,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
|
|
||||||
String buildData = downloadUrlMemoryAsString(url);
|
String buildData = downloadUrlMemoryAsString(url);
|
||||||
if (buildData == null || buildData.length() == 0) {
|
if (buildData == null || buildData.length() == 0) {
|
||||||
updateState(STATE_ERROR_DOWNLOAD, null, null, null, url, null);
|
mState.update(State.ERROR_DOWNLOAD, null, null, null, url, null);
|
||||||
mNotificationManager.cancel(NOTIFICATION_BUSY);
|
mNotificationManager.cancel(NOTIFICATION_BUSY);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1168,7 +1108,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.ex(e);
|
Logger.ex(e);
|
||||||
}
|
}
|
||||||
updateState(STATE_ERROR_UNOFFICIAL, null, null, null, mConfig.getVersion(), null);
|
mState.update(State.ERROR_UNOFFICIAL, null, null, null, mConfig.getVersion(), null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1183,7 +1123,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
public void onProgress(float progress, long current, long total) {
|
public void onProgress(float progress, long current, long total) {
|
||||||
long now = SystemClock.elapsedRealtime();
|
long now = SystemClock.elapsedRealtime();
|
||||||
if (now >= last[0] + 16L) {
|
if (now >= last[0] + 16L) {
|
||||||
updateState(_state, progress, current, total, _filename,
|
mState.update(_state, progress, current, total, _filename,
|
||||||
SystemClock.elapsedRealtime() - last[1]);
|
SystemClock.elapsedRealtime() - last[1]);
|
||||||
last[0] = now;
|
last[0] = now;
|
||||||
}
|
}
|
||||||
|
@ -1220,7 +1160,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (mStopDownload >= 0) {
|
if (mStopDownload >= 0) {
|
||||||
Logger.d("download stopped");
|
Logger.d("download stopped");
|
||||||
} else {
|
} else {
|
||||||
updateState(STATE_ERROR_DOWNLOAD, null, null, null,
|
mState.update(State.ERROR_DOWNLOAD, null, null, null,
|
||||||
fn, null);
|
fn, null);
|
||||||
Logger.d("download error");
|
Logger.d("download error");
|
||||||
mNotificationManager.cancel(NOTIFICATION_BUSY);
|
mNotificationManager.cancel(NOTIFICATION_BUSY);
|
||||||
|
@ -1249,7 +1189,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
long current = _currentOut + _file.length();
|
long current = _currentOut + _file.length();
|
||||||
updateState(STATE_ACTION_APPLYING_PATCH,
|
mState.update(State.ACTION_APPLYING_PATCH,
|
||||||
((float) current / (float) _totalOut) * 100f,
|
((float) current / (float) _totalOut) * 100f,
|
||||||
current, _totalOut, _display,
|
current, _totalOut, _display,
|
||||||
SystemClock.elapsedRealtime() - _start);
|
SystemClock.elapsedRealtime() - _start);
|
||||||
|
@ -1358,12 +1298,12 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
|
|
||||||
if (!isSupportedVersion()) {
|
if (!isSupportedVersion()) {
|
||||||
// TODO - to be more generic this should maybe use the info from getNewestFullBuild
|
// TODO - to be more generic this should maybe use the info from getNewestFullBuild
|
||||||
updateState(STATE_ERROR_UNOFFICIAL, null, null, null, mConfig.getVersion(), null);
|
mState.update(State.ERROR_UNOFFICIAL, null, null, null, mConfig.getVersion(), null);
|
||||||
Logger.i("Ignoring request to check for updates - not compatible for update! " + mConfig.getVersion());
|
Logger.i("Ignoring request to check for updates - not compatible for update! " + mConfig.getVersion());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!mNetworkState.isConnected()) {
|
if (!mNetworkState.isConnected()) {
|
||||||
updateState(STATE_ERROR_CONNECTION);
|
mState.update(State.ERROR_CONNECTION);
|
||||||
Logger.i("Ignoring request to check for updates - no data connection");
|
Logger.i("Ignoring request to check for updates - no data connection");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1394,7 +1334,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getDeltaDownloadSize(List<DeltaInfo> deltas) {
|
private long getDeltaDownloadSize(List<DeltaInfo> deltas) {
|
||||||
updateState(STATE_ACTION_CHECKING);
|
mState.update(State.ACTION_CHECKING);
|
||||||
|
|
||||||
long deltaDownloadSize = 0L;
|
long deltaDownloadSize = 0L;
|
||||||
for (DeltaInfo di : deltas) {
|
for (DeltaInfo di : deltas) {
|
||||||
|
@ -1402,7 +1342,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (di.getUpdate().match(
|
if (di.getUpdate().match(
|
||||||
new File(fn),
|
new File(fn),
|
||||||
true,
|
true,
|
||||||
getSUMProgress(STATE_ACTION_CHECKING_SUM, di.getUpdate()
|
getSUMProgress(State.ACTION_CHECKING_SUM, di.getUpdate()
|
||||||
.getName())) == di.getUpdate().getUpdate()) {
|
.getName())) == di.getUpdate().getUpdate()) {
|
||||||
di.getUpdate().setTag(fn);
|
di.getUpdate().setTag(fn);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1418,7 +1358,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (lastDelta.getSignature().match(
|
if (lastDelta.getSignature().match(
|
||||||
new File(fn),
|
new File(fn),
|
||||||
true,
|
true,
|
||||||
getSUMProgress(STATE_ACTION_CHECKING_SUM, lastDelta
|
getSUMProgress(State.ACTION_CHECKING_SUM, lastDelta
|
||||||
.getSignature().getName())) == lastDelta
|
.getSignature().getName())) == lastDelta
|
||||||
.getSignature().getUpdate()) {
|
.getSignature().getUpdate()) {
|
||||||
lastDelta.getSignature().setTag(fn);
|
lastDelta.getSignature().setTag(fn);
|
||||||
|
@ -1429,7 +1369,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateState(STATE_ACTION_CHECKING);
|
mState.update(State.ACTION_CHECKING);
|
||||||
|
|
||||||
return deltaDownloadSize;
|
return deltaDownloadSize;
|
||||||
}
|
}
|
||||||
|
@ -1478,7 +1418,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
|
|
||||||
DeltaInfo firstDelta = deltas.get(0);
|
DeltaInfo firstDelta = deltas.get(0);
|
||||||
|
|
||||||
updateState(STATE_ACTION_SEARCHING);
|
mState.update(State.ACTION_SEARCHING);
|
||||||
|
|
||||||
String initialFile = null;
|
String initialFile = null;
|
||||||
|
|
||||||
|
@ -1499,7 +1439,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
match = firstDelta.getIn().match(
|
match = firstDelta.getIn().match(
|
||||||
new File(expectedLocation),
|
new File(expectedLocation),
|
||||||
true,
|
true,
|
||||||
getSUMProgress(STATE_ACTION_SEARCHING_SUM, firstDelta
|
getSUMProgress(State.ACTION_SEARCHING_SUM, firstDelta
|
||||||
.getIn().getName()));
|
.getIn().getName()));
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
initialFile = expectedLocation;
|
initialFile = expectedLocation;
|
||||||
|
@ -1521,7 +1461,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
DeltaInfo lastDelta = deltas.get(deltas.size() - 1);
|
DeltaInfo lastDelta = deltas.get(deltas.size() - 1);
|
||||||
|
|
||||||
final String[] filename = new String[] { null };
|
final String[] filename = new String[] { null };
|
||||||
updateState(STATE_ACTION_DOWNLOADING, 0f, 0L, totalDownloadSize, null,
|
mState.update(State.ACTION_DOWNLOADING, 0f, 0L, totalDownloadSize, null,
|
||||||
null);
|
null);
|
||||||
|
|
||||||
final long[] last = new long[] { 0, totalDownloadSize, 0,
|
final long[] last = new long[] { 0, totalDownloadSize, 0,
|
||||||
|
@ -1534,7 +1474,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
progress = ((float) current / (float) total) * 100f;
|
progress = ((float) current / (float) total) * 100f;
|
||||||
long now = SystemClock.elapsedRealtime();
|
long now = SystemClock.elapsedRealtime();
|
||||||
if (now >= last[2] + 250L) {
|
if (now >= last[2] + 250L) {
|
||||||
updateState(STATE_ACTION_DOWNLOADING, progress, current,
|
mState.update(State.ACTION_DOWNLOADING, progress, current,
|
||||||
total, filename[0], SystemClock.elapsedRealtime()
|
total, filename[0], SystemClock.elapsedRealtime()
|
||||||
- last[3]);
|
- last[3]);
|
||||||
setDownloadNotificationProgress(progress, current, total,
|
setDownloadNotificationProgress(progress, current, total,
|
||||||
|
@ -1565,7 +1505,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateState(STATE_ACTION_DOWNLOADING, 100f, totalDownloadSize,
|
mState.update(State.ACTION_DOWNLOADING, 100f, totalDownloadSize,
|
||||||
totalDownloadSize, null, null);
|
totalDownloadSize, null, null);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1601,17 +1541,17 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
autoState(false, PREF_AUTO_DOWNLOAD_DISABLED, false);
|
autoState(false, PREF_AUTO_DOWNLOAD_DISABLED, false);
|
||||||
mNotificationManager.cancel(NOTIFICATION_BUSY);
|
mNotificationManager.cancel(NOTIFICATION_BUSY);
|
||||||
} else if (mStopDownload != PREF_STOP_DOWNLOAD_RESUME &&
|
} else if (mStopDownload != PREF_STOP_DOWNLOAD_RESUME &&
|
||||||
!mState.equals(STATE_ERROR_DOWNLOAD)) {
|
!mState.equals(State.ERROR_DOWNLOAD)) {
|
||||||
// either pause or error
|
// either pause or error
|
||||||
final Long current = f.length();
|
final Long current = f.length();
|
||||||
final Long total = mPrefs.getLong(PREF_DOWNLOAD_SIZE, 1500000000L /* 1.5GB */);
|
final Long total = mPrefs.getLong(PREF_DOWNLOAD_SIZE, 1500000000L /* 1.5GB */);
|
||||||
final Long lastTime = mPrefs.getLong(PREF_LAST_DOWNLOAD_TIME, 0);
|
final Long lastTime = mPrefs.getLong(PREF_LAST_DOWNLOAD_TIME, 0);
|
||||||
final float progress = ((float) current / (float) total) * 100f;
|
final float progress = ((float) current / (float) total) * 100f;
|
||||||
final boolean isPause = mStopDownload == PREF_STOP_DOWNLOAD_PAUSE;
|
final boolean isPause = mStopDownload == PREF_STOP_DOWNLOAD_PAUSE;
|
||||||
final String newState = isPause ? STATE_ACTION_DOWNLOADING_PAUSED
|
final String newState = isPause ? State.ACTION_DOWNLOADING_PAUSED
|
||||||
: STATE_ERROR_DOWNLOAD_RESUME;
|
: State.ERROR_DOWNLOAD_RESUME;
|
||||||
Logger.d("download " + (isPause ? "paused" : "error"));
|
Logger.d("download " + (isPause ? "paused" : "error"));
|
||||||
updateState(newState, progress, current, total, imageName, lastTime);
|
mState.update(newState, progress, current, total, imageName, lastTime);
|
||||||
// display paused notification with the proper title
|
// display paused notification with the proper title
|
||||||
String title = getString(isPause
|
String title = getString(isPause
|
||||||
? R.string.state_action_downloading_paused
|
? R.string.state_action_downloading_paused
|
||||||
|
@ -1635,7 +1575,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
try {
|
try {
|
||||||
String fileSUM = getFileSHA256(
|
String fileSUM = getFileSHA256(
|
||||||
file,
|
file,
|
||||||
getSUMProgress(STATE_ACTION_CHECKING_SUM,
|
getSUMProgress(State.ACTION_CHECKING_SUM,
|
||||||
file.getName()));
|
file.getName()));
|
||||||
boolean sumCheck = fileSUM.equals(latestFullSUM);
|
boolean sumCheck = fileSUM.equals(latestFullSUM);
|
||||||
Logger.d("fileSUM=" + fileSUM + " latestFullSUM=" + latestFullSUM);
|
Logger.d("fileSUM=" + fileSUM + " latestFullSUM=" + latestFullSUM);
|
||||||
|
@ -1712,7 +1652,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (initialFileNeedsProcessing) {
|
if (initialFileNeedsProcessing) {
|
||||||
if (!zipadjust(initialFile, tempFiles[tempFile], start,
|
if (!zipadjust(initialFile, tempFiles[tempFile], start,
|
||||||
current, total)) {
|
current, total)) {
|
||||||
updateState(STATE_ERROR_UNKNOWN, null, null, null, null,
|
mState.update(State.ERROR_UNKNOWN, null, null, null, null,
|
||||||
null);
|
null);
|
||||||
Logger.d("zipadjust error");
|
Logger.d("zipadjust error");
|
||||||
return false;
|
return false;
|
||||||
|
@ -1733,7 +1673,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (!dedelta(inFile, mConfig.getPathBase()
|
if (!dedelta(inFile, mConfig.getPathBase()
|
||||||
+ di.getUpdate().getName(), outFile, start, current,
|
+ di.getUpdate().getName(), outFile, start, current,
|
||||||
total)) {
|
total)) {
|
||||||
updateState(STATE_ERROR_UNKNOWN, null, null, null, null,
|
mState.update(State.ERROR_UNKNOWN, null, null, null, null,
|
||||||
null);
|
null);
|
||||||
Logger.d("dedelta error");
|
Logger.d("dedelta error");
|
||||||
return false;
|
return false;
|
||||||
|
@ -1748,7 +1688,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
+ lastDelta.getSignature().getName(),
|
+ lastDelta.getSignature().getName(),
|
||||||
mConfig.getPathBase() + lastDelta.getOut().getName(),
|
mConfig.getPathBase() + lastDelta.getOut().getName(),
|
||||||
start, current, total)) {
|
start, current, total)) {
|
||||||
updateState(STATE_ERROR_UNKNOWN, null, null, null, null,
|
mState.update(State.ERROR_UNKNOWN, null, null, null, null,
|
||||||
null);
|
null);
|
||||||
Logger.d("dedelta error");
|
Logger.d("dedelta error");
|
||||||
return false;
|
return false;
|
||||||
|
@ -1801,9 +1741,9 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
mPrefs.edit().putString(PREF_CURRENT_FILENAME_NAME, flashFilename).commit();
|
mPrefs.edit().putString(PREF_CURRENT_FILENAME_NAME, flashFilename).commit();
|
||||||
}
|
}
|
||||||
startABRebootNotification(flashFilename);
|
startABRebootNotification(flashFilename);
|
||||||
updateState(STATE_ACTION_AB_FINISHED);
|
mState.update(State.ACTION_AB_FINISHED);
|
||||||
} else {
|
} else {
|
||||||
updateState(STATE_ERROR_AB_FLASH, null, null, null, null, null, errorCode);
|
mState.update(State.ERROR_AB_FLASH, null, null, null, null, null, errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1862,7 +1802,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
try {
|
try {
|
||||||
flashFilename = handleUpdateCleanup();
|
flashFilename = handleUpdateCleanup();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
updateState(STATE_ERROR_AB_FLASH);
|
mState.update(State.ERROR_AB_FLASH);
|
||||||
mIsUpdateRunning = false;
|
mIsUpdateRunning = false;
|
||||||
Logger.ex(ex);
|
Logger.ex(ex);
|
||||||
return;
|
return;
|
||||||
|
@ -1875,7 +1815,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
mPrefs.edit().putLong(PREF_DOWNLOAD_SIZE, -1).commit();
|
mPrefs.edit().putLong(PREF_DOWNLOAD_SIZE, -1).commit();
|
||||||
|
|
||||||
final String _filename = new File(flashFilename).getName();
|
final String _filename = new File(flashFilename).getName();
|
||||||
updateState(STATE_ACTION_AB_FLASH, 0f, 0L, 100L, _filename, null);
|
mState.update(State.ACTION_AB_FLASH, 0f, 0L, 100L, _filename, null);
|
||||||
|
|
||||||
newFlashNotification(_filename);
|
newFlashNotification(_filename);
|
||||||
|
|
||||||
|
@ -1889,12 +1829,12 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
mIsUpdateRunning = true;
|
mIsUpdateRunning = true;
|
||||||
if (!ABUpdate.start(flashFilename, mProgressListener, this)) {
|
if (!ABUpdate.start(flashFilename, mProgressListener, this)) {
|
||||||
mNotificationManager.cancel(NOTIFICATION_UPDATE);
|
mNotificationManager.cancel(NOTIFICATION_UPDATE);
|
||||||
updateState(STATE_ERROR_AB_FLASH);
|
mState.update(State.ERROR_AB_FLASH);
|
||||||
mIsUpdateRunning = false;
|
mIsUpdateRunning = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mNotificationManager.cancel(NOTIFICATION_UPDATE);
|
mNotificationManager.cancel(NOTIFICATION_UPDATE);
|
||||||
updateState(STATE_ERROR_AB_FLASH);
|
mState.update(State.ERROR_AB_FLASH);
|
||||||
mIsUpdateRunning = false;
|
mIsUpdateRunning = false;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -1924,7 +1864,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
try {
|
try {
|
||||||
flashFilename = handleUpdateCleanup();
|
flashFilename = handleUpdateCleanup();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
updateState(STATE_ERROR_FLASH);
|
mState.update(State.ERROR_FLASH);
|
||||||
Logger.ex(ex);
|
Logger.ex(ex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2028,14 +1968,14 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
dst.delete();
|
dst.delete();
|
||||||
Logger.d("flashUpdate - Could not install OTA package:");
|
Logger.d("flashUpdate - Could not install OTA package:");
|
||||||
Logger.ex(e);
|
Logger.ex(e);
|
||||||
updateState(STATE_ERROR_FLASH);
|
mState.update(State.ERROR_FLASH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// We have failed to write something. There's not really anything
|
// We have failed to write something. There's not really anything
|
||||||
// else to do at this stage than give up. No reason to crash though.
|
// else to do at this stage than give up. No reason to crash though.
|
||||||
Logger.ex(e);
|
Logger.ex(e);
|
||||||
updateState(STATE_ERROR_FLASH);
|
mState.update(State.ERROR_FLASH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2096,30 +2036,6 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isProgressState(String state) {
|
|
||||||
return state.equals(UpdateService.STATE_ACTION_DOWNLOADING) ||
|
|
||||||
state.equals(UpdateService.STATE_ACTION_SEARCHING) ||
|
|
||||||
state.equals(UpdateService.STATE_ACTION_SEARCHING_SUM) ||
|
|
||||||
state.equals(UpdateService.STATE_ACTION_CHECKING) ||
|
|
||||||
state.equals(UpdateService.STATE_ACTION_CHECKING_SUM) ||
|
|
||||||
state.equals(UpdateService.STATE_ACTION_APPLYING) ||
|
|
||||||
state.equals(UpdateService.STATE_ACTION_APPLYING_SUM) ||
|
|
||||||
state.equals(UpdateService.STATE_ACTION_APPLYING_PATCH) ||
|
|
||||||
state.equals(UpdateService.STATE_ACTION_AB_FLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isErrorState(String state) {
|
|
||||||
return state.equals(UpdateService.STATE_ERROR_DOWNLOAD) ||
|
|
||||||
state.equals(UpdateService.STATE_ERROR_DOWNLOAD_RESUME) ||
|
|
||||||
state.equals(UpdateService.STATE_ERROR_DISK_SPACE) ||
|
|
||||||
state.equals(UpdateService.STATE_ERROR_UNKNOWN) ||
|
|
||||||
state.equals(UpdateService.STATE_ERROR_UNOFFICIAL) ||
|
|
||||||
state.equals(UpdateService.STATE_ERROR_CONNECTION) ||
|
|
||||||
state.equals(UpdateService.STATE_ERROR_AB_FLASH) ||
|
|
||||||
state.equals(UpdateService.STATE_ERROR_FLASH_FILE) ||
|
|
||||||
state.equals(UpdateService.STATE_ERROR_FLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSnoozeNotification() {
|
private boolean isSnoozeNotification() {
|
||||||
// check if we're snoozed, using abs for clock changes
|
// check if we're snoozed, using abs for clock changes
|
||||||
boolean timeSnooze = Math.abs(System.currentTimeMillis()
|
boolean timeSnooze = Math.abs(System.currentTimeMillis()
|
||||||
|
@ -2168,7 +2084,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
private void checkForUpdatesAsync(final boolean userInitiated, final int checkOnly) {
|
private void checkForUpdatesAsync(final boolean userInitiated, final int checkOnly) {
|
||||||
Logger.d("checkForUpdatesAsync " + getPrefs().getAll());
|
Logger.d("checkForUpdatesAsync " + getPrefs().getAll());
|
||||||
|
|
||||||
updateState(STATE_ACTION_CHECKING);
|
mState.update(State.ACTION_CHECKING);
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
mWifiLock.acquire();
|
mWifiLock.acquire();
|
||||||
|
|
||||||
|
@ -2283,7 +2199,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (di.getOut()
|
if (di.getOut()
|
||||||
.match(new File(fn),
|
.match(new File(fn),
|
||||||
true,
|
true,
|
||||||
getSUMProgress(STATE_ACTION_CHECKING_SUM, di.getOut()
|
getSUMProgress(State.ACTION_CHECKING_SUM, di.getOut()
|
||||||
.getName())) != null) {
|
.getName())) != null) {
|
||||||
if (latestFullBuild.equals(di.getOut().getName())) {
|
if (latestFullBuild.equals(di.getOut().getName())) {
|
||||||
boolean signedFile = di.getOut().isSignedFile(new File(fn));
|
boolean signedFile = di.getOut().isSignedFile(new File(fn));
|
||||||
|
@ -2429,7 +2345,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
Logger.d("requiredSpace = " + requiredSpace + " freeSpace = " + freeSpace);
|
Logger.d("requiredSpace = " + requiredSpace + " freeSpace = " + freeSpace);
|
||||||
|
|
||||||
if (freeSpace < requiredSpace) {
|
if (freeSpace < requiredSpace) {
|
||||||
updateState(STATE_ERROR_DISK_SPACE, null, freeSpace, requiredSpace,
|
mState.update(State.ERROR_DISK_SPACE, null, freeSpace, requiredSpace,
|
||||||
null, null);
|
null, null);
|
||||||
Logger.d("not enough space!");
|
Logger.d("not enough space!");
|
||||||
return;
|
return;
|
||||||
|
@ -2454,9 +2370,9 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (lastDelta.getOut().match(
|
if (lastDelta.getOut().match(
|
||||||
new File(mConfig.getPathBase() + lastDelta.getOut().getName()),
|
new File(mConfig.getPathBase() + lastDelta.getOut().getName()),
|
||||||
true,
|
true,
|
||||||
getSUMProgress(STATE_ACTION_APPLYING_SUM, lastDelta.getOut()
|
getSUMProgress(State.ACTION_APPLYING_SUM, lastDelta.getOut()
|
||||||
.getName())) == null) {
|
.getName())) == null) {
|
||||||
updateState(STATE_ERROR_UNKNOWN);
|
mState.update(State.ERROR_UNKNOWN);
|
||||||
Logger.d("final verification error");
|
Logger.d("final verification error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2487,11 +2403,11 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (latestFullSUM != null) {
|
if (latestFullSUM != null) {
|
||||||
downloadFullBuild(latestFullFetch, latestFullSUM, latestFullBuild); // download full
|
downloadFullBuild(latestFullFetch, latestFullSUM, latestFullBuild); // download full
|
||||||
} else {
|
} else {
|
||||||
updateState(STATE_ERROR_DOWNLOAD);
|
mState.update(State.ERROR_DOWNLOAD);
|
||||||
Logger.d("aborting download due to sha256sum not found");
|
Logger.d("aborting download due to sha256sum not found");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
updateState(STATE_ERROR_DOWNLOAD);
|
mState.update(State.ERROR_DOWNLOAD);
|
||||||
Logger.d("aborting download due to network state");
|
Logger.d("aborting download due to network state");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2501,7 +2417,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
if (mWifiLock.isHeld()) mWifiLock.release();
|
if (mWifiLock.isHeld()) mWifiLock.release();
|
||||||
if (mWakeLock.isHeld()) mWakeLock.release();
|
if (mWakeLock.isHeld()) mWakeLock.release();
|
||||||
|
|
||||||
if (isErrorState(mState)) {
|
if (mState.isErrorState()) {
|
||||||
mFailedUpdateCount++;
|
mFailedUpdateCount++;
|
||||||
clearState();
|
clearState();
|
||||||
if (!userInitiated) {
|
if (!userInitiated) {
|
||||||
|
@ -2536,7 +2452,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
private boolean checkForFinishedUpdate() {
|
private boolean checkForFinishedUpdate() {
|
||||||
final boolean finished =
|
final boolean finished =
|
||||||
mPrefs.getBoolean(PREF_PENDING_REBOOT, false) ||
|
mPrefs.getBoolean(PREF_PENDING_REBOOT, false) ||
|
||||||
mState.equals(STATE_ACTION_AB_FINISHED) ||
|
mState.equals(State.ACTION_AB_FINISHED) ||
|
||||||
ABUpdate.isInstallingUpdate(this);
|
ABUpdate.isInstallingUpdate(this);
|
||||||
if (finished) {
|
if (finished) {
|
||||||
final String lastFilename = mPrefs.getString(PREF_CURRENT_AB_FILENAME_NAME, null);
|
final String lastFilename = mPrefs.getString(PREF_CURRENT_AB_FILENAME_NAME, null);
|
||||||
|
@ -2549,7 +2465,7 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
private boolean checkPermissions() {
|
private boolean checkPermissions() {
|
||||||
if (!Environment.isExternalStorageManager()) {
|
if (!Environment.isExternalStorageManager()) {
|
||||||
Logger.d("checkPermissions failed");
|
Logger.d("checkPermissions failed");
|
||||||
updateState(STATE_ERROR_PERMISSIONS);
|
mState.update(State.ERROR_PERMISSIONS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -2581,16 +2497,16 @@ public class UpdateService extends Service implements OnNetworkStateListener,
|
||||||
Logger.d("Flash file set: %s", flashFilename);
|
Logger.d("Flash file set: %s", flashFilename);
|
||||||
File fn = new File(flashFilename);
|
File fn = new File(flashFilename);
|
||||||
if (!fn.exists()) {
|
if (!fn.exists()) {
|
||||||
updateState(STATE_ERROR_FLASH_FILE);
|
mState.update(State.ERROR_FLASH_FILE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!fn.getName().endsWith(".zip")) {
|
if (!fn.getName().endsWith(".zip")) {
|
||||||
updateState(STATE_ERROR_FLASH_FILE);
|
mState.update(State.ERROR_FLASH_FILE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Logger.d("Set flash possible: %s", flashFilename);
|
Logger.d("Set flash possible: %s", flashFilename);
|
||||||
mPrefs.edit().putString(PREF_READY_FILENAME_NAME, flashFilename).commit();
|
mPrefs.edit().putString(PREF_READY_FILENAME_NAME, flashFilename).commit();
|
||||||
updateState(STATE_ACTION_FLASH_FILE_READY, null, null, null, (new File(flashFilename)).getName(), null);
|
mState.update(State.ACTION_FLASH_FILE_READY, null, null, null, (new File(flashFilename)).getName(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNotificationChannel() {
|
private void createNotificationChannel() {
|
||||||
|
|
Loading…
Reference in New Issue