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 | |
| 91 | uiReset(); |
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 | // TODO(zhomart) load saved states |
| 112 | // Binding to UpdateEngine invokes onStatusUpdate callback, |
| 113 | // persisted updater state has to be loaded and prepared beforehand. |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 114 | this.mUpdateManager.bind(); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | protected void onPause() { |
| 119 | this.mUpdateManager.unbind(); |
Zhomart Mukhamejanov | 7671f68 | 2018-05-24 09:11:47 -0700 | [diff] [blame] | 120 | // TODO(zhomart) save state |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 121 | super.onPause(); |
| 122 | } |
| 123 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 124 | /** |
| 125 | * reload button is clicked |
| 126 | */ |
| 127 | public void onReloadClick(View view) { |
| 128 | loadUpdateConfigs(); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * view config button is clicked |
| 133 | */ |
| 134 | public void onViewConfigClick(View view) { |
| 135 | UpdateConfig config = mConfigs.get(mSpinnerConfigs.getSelectedItemPosition()); |
| 136 | new AlertDialog.Builder(this) |
| 137 | .setTitle(config.getName()) |
| 138 | .setMessage(config.getRawJson()) |
| 139 | .setPositiveButton(R.string.close, (dialog, id) -> dialog.dismiss()) |
| 140 | .show(); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * apply config button is clicked |
| 145 | */ |
| 146 | public void onApplyConfigClick(View view) { |
| 147 | new AlertDialog.Builder(this) |
| 148 | .setTitle("Apply Update") |
| 149 | .setMessage("Do you really want to apply this update?") |
| 150 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 151 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
| 152 | uiSetUpdating(); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 153 | uiResetEngineText(); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 154 | mUpdateManager.applyUpdate(this, getSelectedConfig()); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 155 | }) |
| 156 | .setNegativeButton(android.R.string.cancel, null) |
| 157 | .show(); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * stop button clicked |
| 162 | */ |
| 163 | public void onStopClick(View view) { |
| 164 | new AlertDialog.Builder(this) |
| 165 | .setTitle("Stop Update") |
| 166 | .setMessage("Do you really want to cancel running update?") |
| 167 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 168 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 169 | mUpdateManager.cancelRunningUpdate(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 170 | }) |
| 171 | .setNegativeButton(android.R.string.cancel, null).show(); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * reset button clicked |
| 176 | */ |
| 177 | public void onResetClick(View view) { |
| 178 | new AlertDialog.Builder(this) |
| 179 | .setTitle("Reset Update") |
| 180 | .setMessage("Do you really want to cancel running update" |
| 181 | + " and restore old version?") |
| 182 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 183 | .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 184 | mUpdateManager.resetUpdate(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 185 | }) |
| 186 | .setNegativeButton(android.R.string.cancel, null).show(); |
| 187 | } |
| 188 | |
| 189 | /** |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 190 | * switch slot button clicked |
| 191 | */ |
| 192 | public void onSwitchSlotClick(View view) { |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 193 | mUpdateManager.setSwitchSlotOnReboot(); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 197 | * Invoked when SystemUpdaterSample app state changes. |
| 198 | * Value of {@code state} will be one of the |
Zhomart Mukhamejanov | 674aa6c | 2018-05-25 17:00:11 -0700 | [diff] [blame] | 199 | * values from {@link UpdaterState}. |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 200 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 201 | private void onUpdaterStateChange(int state) { |
| 202 | Log.i(TAG, "onUpdaterStateChange invoked state=" + state); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 203 | runOnUiThread(() -> { |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 204 | setUiUpdaterState(state); |
| 205 | }); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Invoked when {@link UpdateEngine} status changes. Value of {@code status} will |
| 210 | * be one of the values from {@link UpdateEngine.UpdateStatusConstants}. |
| 211 | */ |
| 212 | private void onEngineStatusUpdate(int status) { |
| 213 | runOnUiThread(() -> { |
| 214 | Log.e(TAG, "StatusUpdate - status=" |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 215 | + UpdateEngineStatuses.getStatusText(status) |
| 216 | + "/" + status); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 217 | if (status == UpdateEngine.UpdateStatusConstants.IDLE) { |
| 218 | Log.d(TAG, "status changed, resetting ui"); |
| 219 | uiReset(); |
| 220 | } else { |
| 221 | Log.d(TAG, "status changed, setting ui to updating mode"); |
| 222 | uiSetUpdating(); |
| 223 | } |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 224 | setUiEngineStatus(status); |
Zhomart Mukhamejanov | 6f26e71 | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 225 | }); |
| 226 | } |
| 227 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 228 | /** |
| 229 | * Invoked when the payload has been applied, whether successfully or |
| 230 | * unsuccessfully. The value of {@code errorCode} will be one of the |
| 231 | * values from {@link UpdateEngine.ErrorCodeConstants}. |
| 232 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 233 | private void onEnginePayloadApplicationComplete(int errorCode) { |
| 234 | final String completionState = UpdateEngineErrorCodes.isUpdateSucceeded(errorCode) |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 235 | ? "SUCCESS" |
| 236 | : "FAILURE"; |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 237 | runOnUiThread(() -> { |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 238 | Log.i(TAG, |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 239 | "Completed - errorCode=" |
Zhomart Mukhamejanov | 674aa6c | 2018-05-25 17:00:11 -0700 | [diff] [blame] | 240 | + UpdateEngineErrorCodes.getCodeName(errorCode) + "/" + errorCode |
| 241 | + " " + completionState); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 242 | setUiEngineErrorCode(errorCode); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 243 | if (errorCode == UpdateEngineErrorCodes.UPDATED_BUT_NOT_ACTIVE) { |
| 244 | // if update was successfully applied. |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 245 | if (mUpdateManager.isManualSwitchSlotRequired()) { |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 246 | // Show "Switch Slot" button. |
| 247 | uiShowSwitchSlotInfo(); |
| 248 | } |
| 249 | } |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 250 | }); |
| 251 | } |
| 252 | |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 253 | /** |
| 254 | * Invoked when update progress changes. |
| 255 | */ |
| 256 | private void onProgressUpdate(double progress) { |
| 257 | mProgressBar.setProgress((int) (100 * progress)); |
| 258 | } |
| 259 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 260 | /** resets ui */ |
| 261 | private void uiReset() { |
| 262 | mTextViewBuild.setText(Build.DISPLAY); |
| 263 | mSpinnerConfigs.setEnabled(true); |
| 264 | mButtonReload.setEnabled(true); |
| 265 | mButtonApplyConfig.setEnabled(true); |
| 266 | mButtonStop.setEnabled(false); |
| 267 | mButtonReset.setEnabled(false); |
| 268 | mProgressBar.setProgress(0); |
| 269 | mProgressBar.setEnabled(false); |
| 270 | mProgressBar.setVisibility(ProgressBar.INVISIBLE); |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 271 | uiHideSwitchSlotInfo(); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 274 | private void uiResetEngineText() { |
| 275 | mTextViewEngineStatus.setText(R.string.unknown); |
| 276 | mTextViewEngineErrorCode.setText(R.string.unknown); |
| 277 | // Note: Do not reset mTextViewUpdaterState; UpdateManager notifies properly. |
| 278 | } |
| 279 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 280 | /** sets ui updating mode */ |
| 281 | private void uiSetUpdating() { |
| 282 | mTextViewBuild.setText(Build.DISPLAY); |
| 283 | mSpinnerConfigs.setEnabled(false); |
| 284 | mButtonReload.setEnabled(false); |
| 285 | mButtonApplyConfig.setEnabled(false); |
| 286 | mButtonStop.setEnabled(true); |
| 287 | mProgressBar.setEnabled(true); |
| 288 | mButtonReset.setEnabled(true); |
| 289 | mProgressBar.setVisibility(ProgressBar.VISIBLE); |
| 290 | } |
| 291 | |
Zhomart Mukhamejanov | 238beb7 | 2018-05-09 16:25:40 -0700 | [diff] [blame] | 292 | private void uiShowSwitchSlotInfo() { |
| 293 | mButtonSwitchSlot.setEnabled(true); |
| 294 | mTextViewUpdateInfo.setTextColor(Color.parseColor("#777777")); |
| 295 | } |
| 296 | |
| 297 | private void uiHideSwitchSlotInfo() { |
| 298 | mTextViewUpdateInfo.setTextColor(Color.parseColor("#AAAAAA")); |
| 299 | mButtonSwitchSlot.setEnabled(false); |
| 300 | } |
| 301 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 302 | /** |
| 303 | * loads json configurations from configs dir that is defined in {@link UpdateConfigs}. |
| 304 | */ |
| 305 | private void loadUpdateConfigs() { |
| 306 | mConfigs = UpdateConfigs.getUpdateConfigs(this); |
| 307 | loadConfigsToSpinner(mConfigs); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * @param status update engine status code |
| 312 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 313 | private void setUiEngineStatus(int status) { |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 314 | String statusText = UpdateEngineStatuses.getStatusText(status); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 315 | mTextViewEngineStatus.setText(statusText + "/" + status); |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /** |
| 319 | * @param errorCode update engine error code |
| 320 | */ |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 321 | private void setUiEngineErrorCode(int errorCode) { |
Zhomart Mukhamejanov | f7a7038 | 2018-05-02 20:37:12 -0700 | [diff] [blame] | 322 | String errorText = UpdateEngineErrorCodes.getCodeName(errorCode); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 323 | mTextViewEngineErrorCode.setText(errorText + "/" + errorCode); |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * @param state updater sample state |
| 328 | */ |
| 329 | private void setUiUpdaterState(int state) { |
Zhomart Mukhamejanov | 674aa6c | 2018-05-25 17:00:11 -0700 | [diff] [blame] | 330 | String stateText = UpdaterState.getStateText(state); |
Zhomart Mukhamejanov | 8f4059d | 2018-05-18 10:15:31 -0700 | [diff] [blame] | 331 | mTextViewUpdaterState.setText(stateText + "/" + state); |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | private void loadConfigsToSpinner(List<UpdateConfig> configs) { |
| 335 | String[] spinnerArray = UpdateConfigs.configsToNames(configs); |
| 336 | ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, |
| 337 | android.R.layout.simple_spinner_item, |
| 338 | spinnerArray); |
| 339 | spinnerArrayAdapter.setDropDownViewResource(android.R.layout |
| 340 | .simple_spinner_dropdown_item); |
| 341 | mSpinnerConfigs.setAdapter(spinnerArrayAdapter); |
| 342 | } |
| 343 | |
| 344 | private UpdateConfig getSelectedConfig() { |
| 345 | return mConfigs.get(mSpinnerConfigs.getSelectedItemPosition()); |
| 346 | } |
| 347 | |
Zhomart Mukhamejanov | f4d280c | 2018-04-17 13:20:22 -0700 | [diff] [blame] | 348 | } |