Merge "Ferrochrome app guides how to download the assets" into main
diff --git a/ferrochrome_app/AndroidManifest.xml b/ferrochrome_app/AndroidManifest.xml
index d783bbc..d0aa62c 100644
--- a/ferrochrome_app/AndroidManifest.xml
+++ b/ferrochrome_app/AndroidManifest.xml
@@ -8,7 +8,6 @@
android:label="Ferrochrome">
<activity android:name=".FerrochromeActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation|uiMode"
- android:theme="@style/MyTheme"
android:screenOrientation="landscape"
android:exported="true">
<intent-filter>
diff --git a/ferrochrome_app/java/com/android/virtualization/ferrochrome/FerrochromeActivity.java b/ferrochrome_app/java/com/android/virtualization/ferrochrome/FerrochromeActivity.java
index 58005aa..40af3b6 100644
--- a/ferrochrome_app/java/com/android/virtualization/ferrochrome/FerrochromeActivity.java
+++ b/ferrochrome_app/java/com/android/virtualization/ferrochrome/FerrochromeActivity.java
@@ -74,9 +74,11 @@
executorService.execute(
() -> {
- updateImageIfNeeded();
- updateStatus("Starting Ferrochrome...");
- runOnUiThread(() -> startActivityForResult(intent, REQUEST_CODE_VMLAUNCHER));
+ if (updateImageIfNeeded()) {
+ updateStatus("Starting Ferrochrome...");
+ runOnUiThread(
+ () -> startActivityForResult(intent, REQUEST_CODE_VMLAUNCHER));
+ }
});
}
@@ -87,18 +89,25 @@
}
}
- private void updateImageIfNeeded() {
+ private boolean updateImageIfNeeded() {
if (!isUpdateNeeded()) {
Log.d(TAG, "No update needed.");
- return;
+ return true;
}
- updateStatus("Copying images...");
try {
if (Files.notExists(DEST_DIR)) {
Files.createDirectory(DEST_DIR);
}
- for (String file : getAssets().list("ferrochrome")) {
+
+ String[] files = getAssets().list("ferrochrome");
+ if (files == null || files.length == 0) {
+ updateStatus("ChromeOS image not found. Please go/try-ferrochrome");
+ return false;
+ }
+
+ updateStatus("Copying images...");
+ for (String file : files) {
updateStatus(file);
Path dst = Path.of(DEST_DIR.toString(), file);
updateFile(getAssets().open("ferrochrome/" + file), dst);
@@ -106,7 +115,7 @@
} catch (IOException e) {
Log.e(TAG, "Error while updating image: " + e);
updateStatus("Failed.");
- return;
+ return false;
}
updateStatus("Done.");
@@ -118,10 +127,20 @@
} catch (Exception e) {
Log.e(TAG, "Error while extracting image: " + e);
updateStatus("Failed.");
- return;
+ return false;
}
}
+ // TODO(jiyong): remove this sleep.
+ try {
+ Thread.sleep(30 * 1000);
+ } catch (Exception e) {
+ Log.e(TAG, "Interrupted while waiting for the copy to finish");
+ updateStatus("Failed.");
+ return false;
+ }
+
updateStatus("Done.");
+ return true;
}
private boolean isUpdateNeeded() {
diff --git a/ferrochrome_app/res/layout/activity_ferrochrome.xml b/ferrochrome_app/res/layout/activity_ferrochrome.xml
index 7d5e8aa..3967167 100644
--- a/ferrochrome_app/res/layout/activity_ferrochrome.xml
+++ b/ferrochrome_app/res/layout/activity_ferrochrome.xml
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".FerrochromeActivity">
+ android:fitsSystemWindows="true"
+ android:paddingLeft="16dp"
+ android:paddingRight="16dp">
<TextView
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="wrap_content"
+ android:textSize="28sp"
android:id="@+id/status_txt_view"/>
-</RelativeLayout>
\ No newline at end of file
+</RelativeLayout>
diff --git a/ferrochrome_app/res/values/themes.xml b/ferrochrome_app/res/values/themes.xml
deleted file mode 100644
index c9a9ed2..0000000
--- a/ferrochrome_app/res/values/themes.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<resources xmlns:tools="http://schemas.android.com/tools">
- <style name="MyTheme" parent="@android:style/Theme.DeviceDefault.NoActionBar">
- </style>
-</resources>