summaryrefslogtreecommitdiffstats
path: root/updater_sample/src/com
diff options
context:
space:
mode:
authorZhomart Mukhamejanov <zhomart@google.com>2018-06-01 21:41:20 +0200
committerZhomart Mukhamejanov <zhomart@google.com>2018-06-04 23:23:37 +0200
commit469b35a4576a0398f62440383b520d091c90edb1 (patch)
treee24302c89b566cce468109fdeb0dc3ab45f74fd9 /updater_sample/src/com
parentMerge "updater_sample: validate state only once" (diff)
downloadandroid_bootable_recovery-469b35a4576a0398f62440383b520d091c90edb1.tar
android_bootable_recovery-469b35a4576a0398f62440383b520d091c90edb1.tar.gz
android_bootable_recovery-469b35a4576a0398f62440383b520d091c90edb1.tar.bz2
android_bootable_recovery-469b35a4576a0398f62440383b520d091c90edb1.tar.lz
android_bootable_recovery-469b35a4576a0398f62440383b520d091c90edb1.tar.xz
android_bootable_recovery-469b35a4576a0398f62440383b520d091c90edb1.tar.zst
android_bootable_recovery-469b35a4576a0398f62440383b520d091c90edb1.zip
Diffstat (limited to 'updater_sample/src/com')
-rw-r--r--updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java215
-rw-r--r--updater_sample/src/com/example/android/systemupdatersample/UpdaterState.java15
-rw-r--r--updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java139
3 files changed, 223 insertions, 146 deletions
diff --git a/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java b/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java
index 2fe04bdde..e4c09346b 100644
--- a/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java
+++ b/updater_sample/src/com/example/android/systemupdatersample/UpdateManager.java
@@ -64,8 +64,8 @@ public class UpdateManager {
private AtomicBoolean mManualSwitchSlotRequired = new AtomicBoolean(true);
- /** Validate state only once when app binds to UpdateEngine. */
- private AtomicBoolean mStateValidityEnsured = new AtomicBoolean(false);
+ /** Synchronize state with engine status only once when app binds to UpdateEngine. */
+ private AtomicBoolean mStateSynchronized = new AtomicBoolean(false);
@GuardedBy("mLock")
private UpdateData mLastUpdateData = null;
@@ -90,10 +90,12 @@ public class UpdateManager {
}
/**
- * Binds to {@link UpdateEngine}.
+ * Binds to {@link UpdateEngine}. Invokes onStateChangeCallback if present.
*/
public void bind() {
- mStateValidityEnsured.set(false);
+ getOnStateChangeCallback().ifPresent(callback -> callback.accept(mUpdaterState.get()));
+
+ mStateSynchronized.set(false);
this.mUpdateEngine.bind(mUpdateEngineCallback);
}
@@ -104,11 +106,8 @@ public class UpdateManager {
this.mUpdateEngine.unbind();
}
- /**
- * @return a number from {@code 0.0} to {@code 1.0}.
- */
- public float getProgress() {
- return (float) this.mProgress.get();
+ public int getUpdaterState() {
+ return mUpdaterState.get();
}
/**
@@ -202,21 +201,40 @@ public class UpdateManager {
* Updates {@link this.mState} and if state is changed,
* it also notifies {@link this.mOnStateChangeCallback}.
*/
- private void setUpdaterState(int updaterState) {
+ private void setUpdaterState(int newUpdaterState)
+ throws UpdaterState.InvalidTransitionException {
+ Log.d(TAG, "setUpdaterState invoked newState=" + newUpdaterState);
int previousState = mUpdaterState.get();
+ mUpdaterState.set(newUpdaterState);
+ if (previousState != newUpdaterState) {
+ getOnStateChangeCallback().ifPresent(callback -> callback.accept(newUpdaterState));
+ }
+ }
+
+ /**
+ * Same as {@link this.setUpdaterState}. Logs the error if new state
+ * cannot be set.
+ */
+ private void setUpdaterStateSilent(int newUpdaterState) {
try {
- mUpdaterState.set(updaterState);
+ setUpdaterState(newUpdaterState);
} catch (UpdaterState.InvalidTransitionException e) {
- // Note: invalid state transitions should be handled properly,
- // but to make sample app simple, we just throw runtime exception.
- throw new RuntimeException("Can't set state " + updaterState, e);
- }
- if (previousState != updaterState) {
- getOnStateChangeCallback().ifPresent(callback -> callback.accept(updaterState));
+ // Most likely UpdateEngine status and UpdaterSample state got de-synchronized.
+ // To make sample app simple, we don't handle it properly.
+ Log.e(TAG, "Failed to set updater state", e);
}
}
/**
+ * Creates new UpdaterState, assigns it to {@link this.mUpdaterState},
+ * and notifies callbacks.
+ */
+ private void initializeUpdateState(int state) {
+ this.mUpdaterState = new UpdaterState(state);
+ getOnStateChangeCallback().ifPresent(callback -> callback.accept(state));
+ }
+
+ /**
* Requests update engine to stop any ongoing update. If an update has been applied,
* leave it as is.
*
@@ -224,13 +242,10 @@ public class UpdateManager {
* update engine would throw an error when the method is called, and the only way to
* handle it is to catch the exception.</p>
*/
- public void cancelRunningUpdate() {
- try {
- mUpdateEngine.cancel();
- setUpdaterState(UpdaterState.IDLE);
- } catch (Exception e) {
- Log.w(TAG, "UpdateEngine failed to stop the ongoing update", e);
- }
+ public synchronized void cancelRunningUpdate() throws UpdaterState.InvalidTransitionException {
+ Log.d(TAG, "cancelRunningUpdate invoked");
+ setUpdaterState(UpdaterState.IDLE);
+ mUpdateEngine.cancel();
}
/**
@@ -240,13 +255,10 @@ public class UpdateManager {
* update engine would throw an error when the method is called, and the only way to
* handle it is to catch the exception.</p>
*/
- public void resetUpdate() {
- try {
- mUpdateEngine.resetStatus();
- setUpdaterState(UpdaterState.IDLE);
- } catch (Exception e) {
- Log.w(TAG, "UpdateEngine failed to reset the update", e);
- }
+ public synchronized void resetUpdate() throws UpdaterState.InvalidTransitionException {
+ Log.d(TAG, "resetUpdate invoked");
+ setUpdaterState(UpdaterState.IDLE);
+ mUpdateEngine.resetStatus();
}
/**
@@ -255,7 +267,8 @@ public class UpdateManager {
* <p>UpdateEngine works asynchronously. This method doesn't wait until
* end of the update.</p>
*/
- public void applyUpdate(Context context, UpdateConfig config) {
+ public synchronized void applyUpdate(Context context, UpdateConfig config)
+ throws UpdaterState.InvalidTransitionException {
mEngineErrorCode.set(UpdateEngineErrorCodes.UNKNOWN);
setUpdaterState(UpdaterState.RUNNING);
@@ -277,7 +290,8 @@ public class UpdateManager {
}
}
- private void applyAbNonStreamingUpdate(UpdateConfig config) {
+ private void applyAbNonStreamingUpdate(UpdateConfig config)
+ throws UpdaterState.InvalidTransitionException {
UpdateData.Builder builder = UpdateData.builder()
.setExtraProperties(prepareExtraProperties(config));
@@ -306,7 +320,7 @@ public class UpdateManager {
updateEngineApplyPayload(builder.build());
} else {
Log.e(TAG, "PrepareStreamingService failed, result code is " + code);
- setUpdaterState(UpdaterState.ERROR);
+ setUpdaterStateSilent(UpdaterState.ERROR);
}
});
}
@@ -333,6 +347,8 @@ public class UpdateManager {
* with the given id.</p>
*/
private void updateEngineApplyPayload(UpdateData update) {
+ Log.d(TAG, "updateEngineApplyPayload invoked with url " + update.mPayload.getUrl());
+
synchronized (mLock) {
mLastUpdateData = update;
}
@@ -348,11 +364,15 @@ public class UpdateManager {
properties.toArray(new String[0]));
} catch (Exception e) {
Log.e(TAG, "UpdateEngine failed to apply the update", e);
- setUpdaterState(UpdaterState.ERROR);
+ setUpdaterStateSilent(UpdaterState.ERROR);
}
}
+ /**
+ * Re-applies {@link this.mLastUpdateData} to update_engine.
+ */
private void updateEngineReApplyPayload() {
+ Log.d(TAG, "updateEngineReApplyPayload invoked");
UpdateData lastUpdate;
synchronized (mLock) {
// mLastPayloadSpec might be empty in some cases.
@@ -377,8 +397,14 @@ public class UpdateManager {
* {@link UpdateEngine#applyPayload} might take several seconds to finish, and it will
* invoke callbacks {@link this#onStatusUpdate} and {@link this#onPayloadApplicationComplete)}.
*/
- public void setSwitchSlotOnReboot() {
+ public synchronized void setSwitchSlotOnReboot() {
Log.d(TAG, "setSwitchSlotOnReboot invoked");
+
+ // When mManualSwitchSlotRequired set false, next time
+ // onApplicationPayloadComplete is called,
+ // it will set updater state to REBOOT_REQUIRED.
+ mManualSwitchSlotRequired.set(false);
+
UpdateData.Builder builder;
synchronized (mLock) {
// To make sample app simple, we don't handle it.
@@ -396,65 +422,62 @@ public class UpdateManager {
}
/**
- * Verifies if mUpdaterState matches mUpdateEngineStatus.
- * If they don't match, runs applyPayload to trigger onPayloadApplicationComplete
- * callback, which updates mUpdaterState.
+ * Synchronize UpdaterState with UpdateEngine status.
+ * Apply necessary UpdateEngine operation if status are out of sync.
+ *
+ * It's expected to be called once when sample app binds itself to UpdateEngine.
*/
- private void ensureCorrectUpdaterState() {
- // When mUpdaterState is one of IDLE, PAUSED, ERROR, SLOT_SWITCH_REQUIRED
- // then mUpdateEngineStatus must be IDLE.
- // When mUpdaterState is RUNNING,
- // then mUpdateEngineStatus must not be IDLE or UPDATED_NEED_REBOOT.
- // When mUpdaterState is REBOOT_REQUIRED,
- // then mUpdateEngineStatus must be UPDATED_NEED_REBOOT.
- int state = mUpdaterState.get();
- int updateEngineStatus = mUpdateEngineStatus.get();
- if (state == UpdaterState.IDLE
- || state == UpdaterState.ERROR
- || state == UpdaterState.PAUSED
- || state == UpdaterState.SLOT_SWITCH_REQUIRED) {
- ensureUpdateEngineStatusIdle(state, updateEngineStatus);
- } else if (state == UpdaterState.RUNNING) {
- ensureUpdateEngineStatusRunning(state, updateEngineStatus);
- } else if (state == UpdaterState.REBOOT_REQUIRED) {
- ensureUpdateEngineStatusReboot(state, updateEngineStatus);
- }
- }
+ private void synchronizeUpdaterStateWithUpdateEngineStatus() {
+ Log.d(TAG, "synchronizeUpdaterStateWithUpdateEngineStatus is invoked.");
- private void ensureUpdateEngineStatusIdle(int state, int updateEngineStatus) {
- if (updateEngineStatus == UpdateEngine.UpdateStatusConstants.IDLE) {
- return;
- }
- // It might happen when update is started not from the sample app.
- // To make the sample app simple, we won't handle this case.
- throw new RuntimeException("When mUpdaterState is " + state
- + " mUpdateEngineStatus expected to be "
- + UpdateEngine.UpdateStatusConstants.IDLE
- + ", but it is " + updateEngineStatus);
- }
+ int state = mUpdaterState.get();
+ int engineStatus = mUpdateEngineStatus.get();
- private void ensureUpdateEngineStatusRunning(int state, int updateEngineStatus) {
- if (updateEngineStatus != UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT
- && updateEngineStatus != UpdateEngine.UpdateStatusConstants.IDLE) {
+ if (engineStatus == UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT) {
+ // If update has been installed before running the sample app,
+ // set state to REBOOT_REQUIRED.
+ initializeUpdateState(UpdaterState.REBOOT_REQUIRED);
return;
}
- // Re-apply latest update. It makes update_engine to invoke
- // onPayloadApplicationComplete callback. The callback notifies
- // if update was successful or not.
- updateEngineReApplyPayload();
- }
- private void ensureUpdateEngineStatusReboot(int state, int updateEngineStatus) {
- if (updateEngineStatus == UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT) {
- return;
+ switch (state) {
+ case UpdaterState.IDLE:
+ case UpdaterState.ERROR:
+ case UpdaterState.PAUSED:
+ case UpdaterState.SLOT_SWITCH_REQUIRED:
+ // It might happen when update is started not from the sample app.
+ // To make the sample app simple, we won't handle this case.
+ Preconditions.checkState(
+ engineStatus == UpdateEngine.UpdateStatusConstants.IDLE,
+ "When mUpdaterState is %s, mUpdateEngineStatus "
+ + "must be 0/IDLE, but it is %s",
+ state,
+ engineStatus);
+ break;
+ case UpdaterState.RUNNING:
+ if (engineStatus == UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT
+ || engineStatus == UpdateEngine.UpdateStatusConstants.IDLE) {
+ Log.i(TAG, "ensureUpdateEngineStatusIsRunning - re-applying last payload");
+ // Re-apply latest update. It makes update_engine to invoke
+ // onPayloadApplicationComplete callback. The callback notifies
+ // if update was successful or not.
+ updateEngineReApplyPayload();
+ }
+ break;
+ case UpdaterState.REBOOT_REQUIRED:
+ // This might happen when update is installed by other means,
+ // and sample app is not aware of it.
+ // To make the sample app simple, we won't handle this case.
+ Preconditions.checkState(
+ engineStatus == UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT,
+ "When mUpdaterState is %s, mUpdateEngineStatus "
+ + "must be 6/UPDATED_NEED_REBOOT, but it is %s",
+ state,
+ engineStatus);
+ break;
+ default:
+ throw new IllegalStateException("This block should not be reached.");
}
- // This might happen when update is installed by other means,
- // and sample app is not aware of it. To make the sample app simple,
- // we won't handle this case.
- throw new RuntimeException("When mUpdaterState is " + state
- + " mUpdateEngineStatus expected to be "
- + UpdateEngine.UpdateStatusConstants.UPDATED_NEED_REBOOT
- + ", but it is " + updateEngineStatus);
}
/**
@@ -468,13 +491,19 @@ public class UpdateManager {
* @param progress a number from 0.0 to 1.0.
*/
private void onStatusUpdate(int status, float progress) {
+ Log.d(TAG, String.format(
+ "onStatusUpdate invoked, status=%s, progress=%.2f",
+ status,
+ progress));
+
int previousStatus = mUpdateEngineStatus.get();
mUpdateEngineStatus.set(status);
mProgress.set(progress);
- if (!mStateValidityEnsured.getAndSet(true)) {
- // We ensure correct state once only when sample app is bound to UpdateEngine.
- ensureCorrectUpdaterState();
+ if (!mStateSynchronized.getAndSet(true)) {
+ // We synchronize state with engine status once
+ // only when sample app is bound to UpdateEngine.
+ synchronizeUpdaterStateWithUpdateEngineStatus();
}
getOnProgressUpdateCallback().ifPresent(callback -> callback.accept(progress));
@@ -489,11 +518,11 @@ public class UpdateManager {
mEngineErrorCode.set(errorCode);
if (errorCode == UpdateEngine.ErrorCodeConstants.SUCCESS
|| errorCode == UpdateEngineErrorCodes.UPDATED_BUT_NOT_ACTIVE) {
- setUpdaterState(isManualSwitchSlotRequired()
+ setUpdaterStateSilent(isManualSwitchSlotRequired()
? UpdaterState.SLOT_SWITCH_REQUIRED
: UpdaterState.REBOOT_REQUIRED);
} else if (errorCode != UpdateEngineErrorCodes.USER_CANCELLED) {
- setUpdaterState(UpdaterState.ERROR);
+ setUpdaterStateSilent(UpdaterState.ERROR);
}
getOnEngineCompleteCallback()
diff --git a/updater_sample/src/com/example/android/systemupdatersample/UpdaterState.java b/updater_sample/src/com/example/android/systemupdatersample/UpdaterState.java
index 36a90982e..573d336e9 100644
--- a/updater_sample/src/com/example/android/systemupdatersample/UpdaterState.java
+++ b/updater_sample/src/com/example/android/systemupdatersample/UpdaterState.java
@@ -51,12 +51,15 @@ public class UpdaterState {
* are allowed to transition to from key.
*/
private static final ImmutableMap<Integer, ImmutableSet<Integer>> TRANSITIONS =
- ImmutableMap.of(
- IDLE, ImmutableSet.of(RUNNING),
- RUNNING, ImmutableSet.of(ERROR, PAUSED, REBOOT_REQUIRED, SLOT_SWITCH_REQUIRED),
- PAUSED, ImmutableSet.of(RUNNING),
- SLOT_SWITCH_REQUIRED, ImmutableSet.of(ERROR)
- );
+ ImmutableMap.<Integer, ImmutableSet<Integer>>builder()
+ .put(IDLE, ImmutableSet.of(ERROR, RUNNING))
+ .put(RUNNING, ImmutableSet.of(
+ ERROR, PAUSED, REBOOT_REQUIRED, SLOT_SWITCH_REQUIRED))
+ .put(PAUSED, ImmutableSet.of(ERROR, RUNNING, IDLE))
+ .put(SLOT_SWITCH_REQUIRED, ImmutableSet.of(ERROR, IDLE))
+ .put(ERROR, ImmutableSet.of(IDLE))
+ .put(REBOOT_REQUIRED, ImmutableSet.of(IDLE))
+ .build();
private AtomicInteger mState;
diff --git a/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java b/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java
index 1de72c2d6..6c71cb6f4 100644
--- a/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java
+++ b/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java
@@ -88,7 +88,7 @@ public class MainActivity extends Activity {
this.mTextViewConfigsDirHint.setText(UpdateConfigs.getConfigsRoot(this));
- uiReset();
+ uiResetWidgets();
loadUpdateConfigs();
this.mUpdateManager.setOnStateChangeCallback(this::onUpdaterStateChange);
@@ -108,7 +108,6 @@ public class MainActivity extends Activity {
@Override
protected void onResume() {
super.onResume();
- // TODO(zhomart) load saved states
// Binding to UpdateEngine invokes onStatusUpdate callback,
// persisted updater state has to be loaded and prepared beforehand.
this.mUpdateManager.bind();
@@ -117,7 +116,6 @@ public class MainActivity extends Activity {
@Override
protected void onPause() {
this.mUpdateManager.unbind();
- // TODO(zhomart) save state
super.onPause();
}
@@ -149,14 +147,22 @@ public class MainActivity extends Activity {
.setMessage("Do you really want to apply this update?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> {
- uiSetUpdating();
+ uiResetWidgets();
uiResetEngineText();
- mUpdateManager.applyUpdate(this, getSelectedConfig());
+ applyUpdate(getSelectedConfig());
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
+ private void applyUpdate(UpdateConfig config) {
+ try {
+ mUpdateManager.applyUpdate(this, config);
+ } catch (UpdaterState.InvalidTransitionException e) {
+ Log.e(TAG, "Failed to apply update " + config.getName(), e);
+ }
+ }
+
/**
* stop button clicked
*/
@@ -166,11 +172,19 @@ public class MainActivity extends Activity {
.setMessage("Do you really want to cancel running update?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> {
- mUpdateManager.cancelRunningUpdate();
+ cancelRunningUpdate();
})
.setNegativeButton(android.R.string.cancel, null).show();
}
+ private void cancelRunningUpdate() {
+ try {
+ mUpdateManager.cancelRunningUpdate();
+ } catch (UpdaterState.InvalidTransitionException e) {
+ Log.e(TAG, "Failed to cancel running update", e);
+ }
+ }
+
/**
* reset button clicked
*/
@@ -181,11 +195,19 @@ public class MainActivity extends Activity {
+ " and restore old version?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.ok, (dialog, whichButton) -> {
- mUpdateManager.resetUpdate();
+ resetUpdate();
})
.setNegativeButton(android.R.string.cancel, null).show();
}
+ private void resetUpdate() {
+ try {
+ mUpdateManager.resetUpdate();
+ } catch (UpdaterState.InvalidTransitionException e) {
+ Log.e(TAG, "Failed to reset update", e);
+ }
+ }
+
/**
* switch slot button clicked
*/
@@ -199,9 +221,25 @@ public class MainActivity extends Activity {
* values from {@link UpdaterState}.
*/
private void onUpdaterStateChange(int state) {
- Log.i(TAG, "onUpdaterStateChange invoked state=" + state);
+ Log.i(TAG, "UpdaterStateChange state="
+ + UpdaterState.getStateText(state)
+ + "/" + state);
runOnUiThread(() -> {
setUiUpdaterState(state);
+
+ if (state == UpdaterState.IDLE) {
+ uiStateIdle();
+ } else if (state == UpdaterState.RUNNING) {
+ uiStateRunning();
+ } else if (state == UpdaterState.PAUSED) {
+ uiStatePaused();
+ } else if (state == UpdaterState.ERROR) {
+ uiStateError();
+ } else if (state == UpdaterState.SLOT_SWITCH_REQUIRED) {
+ uiStateSlotSwitchRequired();
+ } else if (state == UpdaterState.REBOOT_REQUIRED) {
+ uiStateRebootRequired();
+ }
});
}
@@ -210,17 +248,10 @@ public class MainActivity extends Activity {
* be one of the values from {@link UpdateEngine.UpdateStatusConstants}.
*/
private void onEngineStatusUpdate(int status) {
+ Log.i(TAG, "StatusUpdate - status="
+ + UpdateEngineStatuses.getStatusText(status)
+ + "/" + status);
runOnUiThread(() -> {
- Log.e(TAG, "StatusUpdate - status="
- + UpdateEngineStatuses.getStatusText(status)
- + "/" + status);
- if (status == UpdateEngine.UpdateStatusConstants.IDLE) {
- Log.d(TAG, "status changed, resetting ui");
- uiReset();
- } else {
- Log.d(TAG, "status changed, setting ui to updating mode");
- uiSetUpdating();
- }
setUiEngineStatus(status);
});
}
@@ -234,19 +265,12 @@ public class MainActivity extends Activity {
final String completionState = UpdateEngineErrorCodes.isUpdateSucceeded(errorCode)
? "SUCCESS"
: "FAILURE";
+ Log.i(TAG,
+ "PayloadApplicationCompleted - errorCode="
+ + UpdateEngineErrorCodes.getCodeName(errorCode) + "/" + errorCode
+ + " " + completionState);
runOnUiThread(() -> {
- Log.i(TAG,
- "Completed - errorCode="
- + UpdateEngineErrorCodes.getCodeName(errorCode) + "/" + errorCode
- + " " + completionState);
setUiEngineErrorCode(errorCode);
- if (errorCode == UpdateEngineErrorCodes.UPDATED_BUT_NOT_ACTIVE) {
- // if update was successfully applied.
- if (mUpdateManager.isManualSwitchSlotRequired()) {
- // Show "Switch Slot" button.
- uiShowSwitchSlotInfo();
- }
- }
});
}
@@ -258,45 +282,66 @@ public class MainActivity extends Activity {
}
/** resets ui */
- private void uiReset() {
+ private void uiResetWidgets() {
mTextViewBuild.setText(Build.DISPLAY);
- mSpinnerConfigs.setEnabled(true);
- mButtonReload.setEnabled(true);
- mButtonApplyConfig.setEnabled(true);
+ mSpinnerConfigs.setEnabled(false);
+ mButtonReload.setEnabled(false);
+ mButtonApplyConfig.setEnabled(false);
mButtonStop.setEnabled(false);
mButtonReset.setEnabled(false);
- mProgressBar.setProgress(0);
mProgressBar.setEnabled(false);
mProgressBar.setVisibility(ProgressBar.INVISIBLE);
- uiHideSwitchSlotInfo();
+ mButtonSwitchSlot.setEnabled(false);
+ mTextViewUpdateInfo.setTextColor(Color.parseColor("#aaaaaa"));
}
private void uiResetEngineText() {
mTextViewEngineStatus.setText(R.string.unknown);
mTextViewEngineErrorCode.setText(R.string.unknown);
- // Note: Do not reset mTextViewUpdaterState; UpdateManager notifies properly.
+ // Note: Do not reset mTextViewUpdaterState; UpdateManager notifies updater state properly.
}
- /** sets ui updating mode */
- private void uiSetUpdating() {
- mTextViewBuild.setText(Build.DISPLAY);
- mSpinnerConfigs.setEnabled(false);
- mButtonReload.setEnabled(false);
- mButtonApplyConfig.setEnabled(false);
- mButtonStop.setEnabled(true);
+ private void uiStateIdle() {
+ uiResetWidgets();
+ mSpinnerConfigs.setEnabled(true);
+ mButtonReload.setEnabled(true);
+ mButtonApplyConfig.setEnabled(true);
+ mProgressBar.setProgress(0);
+ }
+
+ private void uiStateRunning() {
+ uiResetWidgets();
mProgressBar.setEnabled(true);
+ mProgressBar.setVisibility(ProgressBar.VISIBLE);
+ mButtonStop.setEnabled(true);
+ }
+
+ private void uiStatePaused() {
+ uiResetWidgets();
mButtonReset.setEnabled(true);
+ mProgressBar.setEnabled(true);
mProgressBar.setVisibility(ProgressBar.VISIBLE);
}
- private void uiShowSwitchSlotInfo() {
+ private void uiStateSlotSwitchRequired() {
+ uiResetWidgets();
+ mButtonReset.setEnabled(true);
+ mProgressBar.setEnabled(true);
+ mProgressBar.setVisibility(ProgressBar.VISIBLE);
mButtonSwitchSlot.setEnabled(true);
mTextViewUpdateInfo.setTextColor(Color.parseColor("#777777"));
}
- private void uiHideSwitchSlotInfo() {
- mTextViewUpdateInfo.setTextColor(Color.parseColor("#AAAAAA"));
- mButtonSwitchSlot.setEnabled(false);
+ private void uiStateError() {
+ uiResetWidgets();
+ mButtonReset.setEnabled(true);
+ mProgressBar.setEnabled(true);
+ mProgressBar.setVisibility(ProgressBar.VISIBLE);
+ }
+
+ private void uiStateRebootRequired() {
+ uiResetWidgets();
+ mButtonReset.setEnabled(true);
}
/**