Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.example.android.systemupdatersample.ui; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 21 | import android.graphics.Color; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 22 | import android.os.Build; |
| 23 | import android.os.Bundle; |
| 24 | import android.os.UpdateEngine; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | import android.view.View; |
| 27 | import android.widget.ArrayAdapter; |
| 28 | import android.widget.Button; |
| 29 | import android.widget.ProgressBar; |
| 30 | import android.widget.Spinner; |
| 31 | import android.widget.TextView; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 32 | |
| 33 | import com.example.android.systemupdatersample.R; |
| 34 | import com.example.android.systemupdatersample.UpdateConfig; |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 35 | import com.example.android.systemupdatersample.UpdateManager; |
Zhomart Mukhamejanov | 674aa6c | 2018-05-25 17:00:11 -0700 | [diff] [blame] | 36 | import com.example.android.systemupdatersample.UpdaterState; |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 37 | import com.example.android.systemupdatersample.util.PayloadSpecs; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 38 | import com.example.android.systemupdatersample.util.UpdateConfigs; |
| 39 | import com.example.android.systemupdatersample.util.UpdateEngineErrorCodes; |
| 40 | import com.example.android.systemupdatersample.util.UpdateEngineStatuses; |
| 41 | |
| 42 | import java.util.List; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * UI for SystemUpdaterSample app. |
| 46 | */ |
| 47 | public class MainActivity extends Activity { |
| 48 | |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 49 | private static final String TAG = "MainActivity"; |
| 50 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 51 | private TextView mTextViewBuild; |
| 52 | private Spinner mSpinnerConfigs; |
| 53 | private TextView mTextViewConfigsDirHint; |
| 54 | private Button mButtonReload; |
| 55 | private Button mButtonApplyConfig; |
| 56 | private Button mButtonStop; |
| 57 | private Button mButtonReset; |
| 58 | private ProgressBar mProgressBar; |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 59 | private TextView mTextViewUpdaterState; |
| 60 | private TextView mTextViewEngineStatus; |
| 61 | private TextView mTextViewEngineErrorCode; |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 62 | private TextView mTextViewUpdateInfo; |
| 63 | private Button mButtonSwitchSlot; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 64 | |
| 65 | private List<UpdateConfig> mConfigs; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 66 | |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 67 | private final UpdateManager mUpdateManager = |
| 68 | new UpdateManager(new UpdateEngine(), new PayloadSpecs()); |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 69 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 70 | @Override |
| 71 | protected void onCreate(Bundle savedInstanceState) { |
| 72 | super.onCreate(savedInstanceState); |
| 73 | setContentView(R.layout.activity_main); |
| 74 | |
| 75 | this.mTextViewBuild = findViewById(R.id.textViewBuild); |
| 76 | this.mSpinnerConfigs = findViewById(R.id.spinnerConfigs); |
| 77 | this.mTextViewConfigsDirHint = findViewById(R.id.textViewConfigsDirHint); |
| 78 | this.mButtonReload = findViewById(R.id.buttonReload); |
| 79 | this.mButtonApplyConfig = findViewById(R.id.buttonApplyConfig); |
| 80 | this.mButtonStop = findViewById(R.id.buttonStop); |
| 81 | this.mButtonReset = findViewById(R.id.buttonReset); |
| 82 | this.mProgressBar = findViewById(R.id.progressBar); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 83 | this.mTextViewUpdaterState = findViewById(R.id.textViewUpdaterState); |
| 84 | this.mTextViewEngineStatus = findViewById(R.id.textViewEngineStatus); |
| 85 | this.mTextViewEngineErrorCode = findViewById(R.id.textViewEngineErrorCode); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 86 | this.mTextViewUpdateInfo = findViewById(R.id.textViewUpdateInfo); |
| 87 | this.mButtonSwitchSlot = findViewById(R.id.buttonSwitchSlot); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 88 | |
| 89 | this.mTextViewConfigsDirHint.setText(UpdateConfigs.getConfigsRoot(this)); |
| 90 | |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 91 | uiResetWidgets(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 92 | loadUpdateConfigs(); |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 93 | |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 94 | this.mUpdateManager.setOnStateChangeCallback(this::onUpdaterStateChange); |
| 95 | this.mUpdateManager.setOnEngineStatusUpdateCallback(this::onEngineStatusUpdate); |
| 96 | this.mUpdateManager.setOnEngineCompleteCallback(this::onEnginePayloadApplicationComplete); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 97 | this.mUpdateManager.setOnProgressUpdateCallback(this::onProgressUpdate); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
| 101 | protected void onDestroy() { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 102 | this.mUpdateManager.setOnEngineStatusUpdateCallback(null); |
| 103 | this.mUpdateManager.setOnProgressUpdateCallback(null); |
| 104 | this.mUpdateManager.setOnEngineCompleteCallback(null); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 105 | super.onDestroy(); |
| 106 | } |
| 107 | |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 108 | @Override |
| 109 | protected void onResume() { |
| 110 | super.onResume(); |
Zhomart Mukhamejanov | 7671f68 | 2018-05-24 09:11:47 -0700 | [diff] [blame] | 111 | // Binding to UpdateEngine invokes onStatusUpdate callback, |
| 112 | // persisted updater state has to be loaded and prepared beforehand. |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 113 | this.mUpdateManager.bind(); |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | protected void onPause() { |
| 118 | this.mUpdateManager.unbind(); |
| 119 | super.onPause(); |
| 120 | } |
| 121 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 122 | /** |
| 123 | * reload button is clicked |
| 124 | */ |
| 125 | public void onReloadClick(View view) { |
| 126 | loadUpdateConfigs(); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * view config button is clicked |
| 131 | */ |
| 132 | public void onViewConfigClick(View view) { |
| 133 | UpdateConfig config = mConfigs.get(mSpinnerConfigs.getSelectedItemPosition()); |
| 134 | new AlertDialog.Builder(this) |
| 135 | .setTitle(config.getName()) |
| 136 | .setMessage(config.getRawJson()) |
| 137 | .setPositiveButton(R.string.close, (dialog, id) -> dialog.dismiss()) |
| 138 | .show(); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * apply config button is clicked |
| 143 | */ |
| 144 | public void onApplyConfigClick(View view) { |
| 145 | new AlertDialog.Builder(this) |
| 146 | .setTitle("Apply Update") |
| 147 | .setMessage("Do you really want to apply this update?") |
| 148 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 149 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 150 | uiResetWidgets(); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 151 | uiResetEngineText(); |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 152 | applyUpdate(getSelectedConfig()); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 153 | }) |
| 154 | .setNegativeButton(android.R.string.cancel, null) |
| 155 | .show(); |
| 156 | } |
| 157 | |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 158 | private void applyUpdate(UpdateConfig config) { |
| 159 | try { |
| 160 | mUpdateManager.applyUpdate(this, config); |
| 161 | } catch (UpdaterState.InvalidTransitionException e) { |
| 162 | Log.e(TAG, "Failed to apply update " + config.getName(), e); |
| 163 | } |
| 164 | } |
| 165 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 166 | /** |
| 167 | * stop button clicked |
| 168 | */ |
| 169 | public void onStopClick(View view) { |
| 170 | new AlertDialog.Builder(this) |
| 171 | .setTitle("Stop Update") |
| 172 | .setMessage("Do you really want to cancel running update?") |
| 173 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 174 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 175 | cancelRunningUpdate(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 176 | }) |
| 177 | .setNegativeButton(android.R.string.cancel, null).show(); |
| 178 | } |
| 179 | |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 180 | private void cancelRunningUpdate() { |
| 181 | try { |
| 182 | mUpdateManager.cancelRunningUpdate(); |
| 183 | } catch (UpdaterState.InvalidTransitionException e) { |
| 184 | Log.e(TAG, "Failed to cancel running update", e); |
| 185 | } |
| 186 | } |
| 187 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 188 | /** |
| 189 | * reset button clicked |
| 190 | */ |
| 191 | public void onResetClick(View view) { |
| 192 | new AlertDialog.Builder(this) |
| 193 | .setTitle("Reset Update") |
| 194 | .setMessage("Do you really want to cancel running update" |
| 195 | + " and restore old version?") |
| 196 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 197 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 198 | resetUpdate(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 199 | }) |
| 200 | .setNegativeButton(android.R.string.cancel, null).show(); |
| 201 | } |
| 202 | |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 203 | private void resetUpdate() { |
| 204 | try { |
| 205 | mUpdateManager.resetUpdate(); |
| 206 | } catch (UpdaterState.InvalidTransitionException e) { |
| 207 | Log.e(TAG, "Failed to reset update", e); |
| 208 | } |
| 209 | } |
| 210 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 211 | /** |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 212 | * switch slot button clicked |
| 213 | */ |
| 214 | public void onSwitchSlotClick(View view) { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 215 | mUpdateManager.setSwitchSlotOnReboot(); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /** |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 219 | * Invoked when SystemUpdaterSample app state changes. |
| 220 | * Value of {@code state} will be one of the |
Zhomart Mukhamejanov | 674aa6c | 2018-05-25 17:00:11 -0700 | [diff] [blame] | 221 | * values from {@link UpdaterState}. |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 222 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 223 | private void onUpdaterStateChange(int state) { |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 224 | Log.i(TAG, "UpdaterStateChange state=" |
| 225 | + UpdaterState.getStateText(state) |
| 226 | + "/" + state); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 227 | runOnUiThread(() -> { |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 228 | setUiUpdaterState(state); |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 229 | |
| 230 | if (state == UpdaterState.IDLE) { |
| 231 | uiStateIdle(); |
| 232 | } else if (state == UpdaterState.RUNNING) { |
| 233 | uiStateRunning(); |
| 234 | } else if (state == UpdaterState.PAUSED) { |
| 235 | uiStatePaused(); |
| 236 | } else if (state == UpdaterState.ERROR) { |
| 237 | uiStateError(); |
| 238 | } else if (state == UpdaterState.SLOT_SWITCH_REQUIRED) { |
| 239 | uiStateSlotSwitchRequired(); |
| 240 | } else if (state == UpdaterState.REBOOT_REQUIRED) { |
| 241 | uiStateRebootRequired(); |
| 242 | } |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 243 | }); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Invoked when {@link UpdateEngine} status changes. Value of {@code status} will |
| 248 | * be one of the values from {@link UpdateEngine.UpdateStatusConstants}. |
| 249 | */ |
| 250 | private void onEngineStatusUpdate(int status) { |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 251 | Log.i(TAG, "StatusUpdate - status=" |
| 252 | + UpdateEngineStatuses.getStatusText(status) |
| 253 | + "/" + status); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 254 | runOnUiThread(() -> { |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 255 | setUiEngineStatus(status); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 256 | }); |
| 257 | } |
| 258 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 259 | /** |
| 260 | * Invoked when the payload has been applied, whether successfully or |
| 261 | * unsuccessfully. The value of {@code errorCode} will be one of the |
| 262 | * values from {@link UpdateEngine.ErrorCodeConstants}. |
| 263 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 264 | private void onEnginePayloadApplicationComplete(int errorCode) { |
| 265 | final String completionState = UpdateEngineErrorCodes.isUpdateSucceeded(errorCode) |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 266 | ? "SUCCESS" |
| 267 | : "FAILURE"; |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 268 | Log.i(TAG, |
| 269 | "PayloadApplicationCompleted - errorCode=" |
| 270 | + UpdateEngineErrorCodes.getCodeName(errorCode) + "/" + errorCode |
| 271 | + " " + completionState); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 272 | runOnUiThread(() -> { |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 273 | setUiEngineErrorCode(errorCode); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 274 | }); |
| 275 | } |
| 276 | |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Invoked when update progress changes. |
| 279 | */ |
| 280 | private void onProgressUpdate(double progress) { |
| 281 | mProgressBar.setProgress((int) (100 * progress)); |
| 282 | } |
| 283 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 284 | /** resets ui */ |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 285 | private void uiResetWidgets() { |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 286 | mTextViewBuild.setText(Build.DISPLAY); |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 287 | mSpinnerConfigs.setEnabled(false); |
| 288 | mButtonReload.setEnabled(false); |
| 289 | mButtonApplyConfig.setEnabled(false); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 290 | mButtonStop.setEnabled(false); |
| 291 | mButtonReset.setEnabled(false); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 292 | mProgressBar.setEnabled(false); |
| 293 | mProgressBar.setVisibility(ProgressBar.INVISIBLE); |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 294 | mButtonSwitchSlot.setEnabled(false); |
| 295 | mTextViewUpdateInfo.setTextColor(Color.parseColor("#aaaaaa")); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 298 | private void uiResetEngineText() { |
| 299 | mTextViewEngineStatus.setText(R.string.unknown); |
| 300 | mTextViewEngineErrorCode.setText(R.string.unknown); |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 301 | // Note: Do not reset mTextViewUpdaterState; UpdateManager notifies updater state properly. |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 304 | private void uiStateIdle() { |
| 305 | uiResetWidgets(); |
| 306 | mSpinnerConfigs.setEnabled(true); |
| 307 | mButtonReload.setEnabled(true); |
| 308 | mButtonApplyConfig.setEnabled(true); |
| 309 | mProgressBar.setProgress(0); |
| 310 | } |
| 311 | |
| 312 | private void uiStateRunning() { |
| 313 | uiResetWidgets(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 314 | mProgressBar.setEnabled(true); |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 315 | mProgressBar.setVisibility(ProgressBar.VISIBLE); |
| 316 | mButtonStop.setEnabled(true); |
| 317 | } |
| 318 | |
| 319 | private void uiStatePaused() { |
| 320 | uiResetWidgets(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 321 | mButtonReset.setEnabled(true); |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 322 | mProgressBar.setEnabled(true); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 323 | mProgressBar.setVisibility(ProgressBar.VISIBLE); |
| 324 | } |
| 325 | |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 326 | private void uiStateSlotSwitchRequired() { |
| 327 | uiResetWidgets(); |
| 328 | mButtonReset.setEnabled(true); |
| 329 | mProgressBar.setEnabled(true); |
| 330 | mProgressBar.setVisibility(ProgressBar.VISIBLE); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 331 | mButtonSwitchSlot.setEnabled(true); |
| 332 | mTextViewUpdateInfo.setTextColor(Color.parseColor("#777777")); |
| 333 | } |
| 334 | |
Zhomart Mukhamejanov | 469b35a | 2018-06-01 12:41:20 -0700 | [diff] [blame] | 335 | private void uiStateError() { |
| 336 | uiResetWidgets(); |
| 337 | mButtonReset.setEnabled(true); |
| 338 | mProgressBar.setEnabled(true); |
| 339 | mProgressBar.setVisibility(ProgressBar.VISIBLE); |
| 340 | } |
| 341 | |
| 342 | private void uiStateRebootRequired() { |
| 343 | uiResetWidgets(); |
| 344 | mButtonReset.setEnabled(true); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 347 | /** |
| 348 | * loads json configurations from configs dir that is defined in {@link UpdateConfigs}. |
| 349 | */ |
| 350 | private void loadUpdateConfigs() { |
| 351 | mConfigs = UpdateConfigs.getUpdateConfigs(this); |
| 352 | loadConfigsToSpinner(mConfigs); |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * @param status update engine status code |
| 357 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 358 | private void setUiEngineStatus(int status) { |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 359 | String statusText = UpdateEngineStatuses.getStatusText(status); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 360 | mTextViewEngineStatus.setText(statusText + "/" + status); |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /** |
| 364 | * @param errorCode update engine error code |
| 365 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 366 | private void setUiEngineErrorCode(int errorCode) { |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 367 | String errorText = UpdateEngineErrorCodes.getCodeName(errorCode); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 368 | mTextViewEngineErrorCode.setText(errorText + "/" + errorCode); |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * @param state updater sample state |
| 373 | */ |
| 374 | private void setUiUpdaterState(int state) { |
Zhomart Mukhamejanov | 674aa6c | 2018-05-25 17:00:11 -0700 | [diff] [blame] | 375 | String stateText = UpdaterState.getStateText(state); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 376 | mTextViewUpdaterState.setText(stateText + "/" + state); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | private void loadConfigsToSpinner(List<UpdateConfig> configs) { |
| 380 | String[] spinnerArray = UpdateConfigs.configsToNames(configs); |
| 381 | ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, |
| 382 | android.R.layout.simple_spinner_item, |
| 383 | spinnerArray); |
| 384 | spinnerArrayAdapter.setDropDownViewResource(android.R.layout |
| 385 | .simple_spinner_dropdown_item); |
| 386 | mSpinnerConfigs.setAdapter(spinnerArrayAdapter); |
| 387 | } |
| 388 | |
| 389 | private UpdateConfig getSelectedConfig() { |
| 390 | return mConfigs.get(mSpinnerConfigs.getSelectedItemPosition()); |
| 391 | } |
| 392 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 393 | } |