diff options
author | Zhomart Mukhamejanov <zhomart@google.com> | 2018-05-09 23:28:49 +0200 |
---|---|---|
committer | Zhomart Mukhamejanov <zhomart@google.com> | 2018-05-10 02:33:52 +0200 |
commit | 6aa5fb0bbe8d074208648593d177553e732e6d9d (patch) | |
tree | 0ba8a4d125e3343d0278fa5505f3afc74bfc5185 /updater_sample/src/com/example/android/systemupdatersample/ui | |
parent | Merge "updater_sample: update tools" (diff) | |
download | android_bootable_recovery-6aa5fb0bbe8d074208648593d177553e732e6d9d.tar android_bootable_recovery-6aa5fb0bbe8d074208648593d177553e732e6d9d.tar.gz android_bootable_recovery-6aa5fb0bbe8d074208648593d177553e732e6d9d.tar.bz2 android_bootable_recovery-6aa5fb0bbe8d074208648593d177553e732e6d9d.tar.lz android_bootable_recovery-6aa5fb0bbe8d074208648593d177553e732e6d9d.tar.xz android_bootable_recovery-6aa5fb0bbe8d074208648593d177553e732e6d9d.tar.zst android_bootable_recovery-6aa5fb0bbe8d074208648593d177553e732e6d9d.zip |
Diffstat (limited to 'updater_sample/src/com/example/android/systemupdatersample/ui')
-rw-r--r-- | updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java | 25 |
1 files changed, 21 insertions, 4 deletions
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 359e2b10c..170825635 100644 --- a/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java +++ b/updater_sample/src/com/example/android/systemupdatersample/ui/MainActivity.java @@ -41,6 +41,7 @@ import com.example.android.systemupdatersample.util.UpdateEngineErrorCodes; import com.example.android.systemupdatersample.util.UpdateEngineStatuses; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -51,6 +52,10 @@ public class MainActivity extends Activity { private static final String TAG = "MainActivity"; + /** HTTP Header: User-Agent; it will be sent to the server when streaming the payload. */ + private static final String HTTP_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"; + private TextView mTextViewBuild; private Spinner mSpinnerConfigs; private TextView mTextViewConfigsDirHint; @@ -295,12 +300,17 @@ public class MainActivity extends Activity { .show(); return; } - updateEngineApplyPayload(payload); + updateEngineApplyPayload(payload, null); } else { Log.d(TAG, "Starting PrepareStreamingService"); PrepareStreamingService.startService(this, config, (code, payloadSpec) -> { if (code == PrepareStreamingService.RESULT_CODE_SUCCESS) { - updateEngineApplyPayload(payloadSpec); + List<String> extraProperties = new ArrayList<>(); + extraProperties.add("USER_AGENT=" + HTTP_USER_AGENT); + config.getStreamingMetadata() + .getAuthorization() + .ifPresent(s -> extraProperties.add("AUTHORIZATION=" + s)); + updateEngineApplyPayload(payloadSpec, extraProperties); } else { Log.e(TAG, "PrepareStreamingService failed, result code is " + code); Toast.makeText( @@ -317,14 +327,21 @@ public class MainActivity extends Activity { * * UpdateEngine works asynchronously. This method doesn't wait until * end of the update. + * + * @param payloadSpec contains url, offset and size to {@code PAYLOAD_BINARY_FILE_NAME} + * @param extraProperties additional properties to pass to {@link UpdateEngine#applyPayload} */ - private void updateEngineApplyPayload(PayloadSpec payloadSpec) { + private void updateEngineApplyPayload(PayloadSpec payloadSpec, List<String> extraProperties) { + ArrayList<String> properties = new ArrayList<>(payloadSpec.getProperties()); + if (extraProperties != null) { + properties.addAll(extraProperties); + } try { mUpdateEngine.applyPayload( payloadSpec.getUrl(), payloadSpec.getOffset(), payloadSpec.getSize(), - payloadSpec.getProperties().toArray(new String[0])); + properties.toArray(new String[0])); } catch (Exception e) { Log.e(TAG, "UpdateEngine failed to apply the update", e); Toast.makeText( |