mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-30 21:22:15 +09:00
[Refactor] (android-plugin/app, MG_Util/SelfTest): simplify Android controls and driver diagnostics
This commit is contained in:
1 parent
0059ccdd79
commit
adfed91a1e
6 files changed
+352
-499
No files matched your search
@@ -98,7 +98,7 @@ public final class PostActivity extends Activity {
|
||||
setContentView(NavBar.wrap(this, scrollView, NavBar.TAB_POST));
|
||||
|
||||
addText("MobileGL Driver POST", 20, COLOR_TEXT, true, 0);
|
||||
statusView = addText("Running self-test...", 14, COLOR_INFO, false, dp(8));
|
||||
statusView = addText("Checking drivers…", 14, COLOR_INFO, false, dp(8));
|
||||
|
||||
progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
|
||||
progressBar.setIndeterminate(true);
|
||||
@@ -119,8 +119,6 @@ public final class PostActivity extends Activity {
|
||||
postInFlight = true;
|
||||
startWorker = true;
|
||||
}
|
||||
// else: a probe is already in flight; leave "Running self-test..."
|
||||
// showing and wait for delivery to this (the current) activity.
|
||||
}
|
||||
if (renderNow) {
|
||||
renderCachedResult();
|
||||
@@ -174,7 +172,7 @@ public final class PostActivity extends Activity {
|
||||
Button button = benchButtons.get(backendType);
|
||||
if (button != null) {
|
||||
button.setEnabled(false);
|
||||
button.setText("Bench running... (can take a minute)");
|
||||
button.setText("Benchmark running…");
|
||||
}
|
||||
LinearLayout container = benchResultContainers.get(backendType);
|
||||
if (container != null) {
|
||||
@@ -191,7 +189,7 @@ public final class PostActivity extends Activity {
|
||||
Button button = benchButtons.get(backendType);
|
||||
if (button != null) {
|
||||
button.setEnabled(true);
|
||||
button.setText("Run Bench");
|
||||
button.setText("Run benchmark");
|
||||
}
|
||||
LinearLayout container = benchResultContainers.get(backendType);
|
||||
if (container == null) {
|
||||
@@ -202,7 +200,7 @@ public final class PostActivity extends Activity {
|
||||
JSONObject root = new JSONObject(json);
|
||||
String error = root.optString("error", "");
|
||||
if (!error.isEmpty()) {
|
||||
container.addView(makeText("Bench failed: " + error, 12, COLOR_FAIL, false));
|
||||
container.addView(makeText("Benchmark failed: " + error, 12, COLOR_FAIL, false));
|
||||
return;
|
||||
}
|
||||
container.addView(makeText(root.optString("renderer", ""), 11, COLOR_INFO, false));
|
||||
@@ -228,7 +226,7 @@ public final class PostActivity extends Activity {
|
||||
container.addView(view);
|
||||
}
|
||||
} catch (JSONException error) {
|
||||
container.addView(makeText("Bench result unparsable: " + error, 12, COLOR_FAIL, false));
|
||||
container.addView(makeText("Could not read benchmark result: " + error, 12, COLOR_FAIL, false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +315,9 @@ public final class PostActivity extends Activity {
|
||||
failure = cachedFailure;
|
||||
}
|
||||
if (failure != null) {
|
||||
showError("Driver POST failed: " + failure);
|
||||
showError("Could not start driver diagnostics.");
|
||||
addDisclosure(contentLayout, "Error details", dp(4))
|
||||
.addView(makeText(failure.toString(), 12, COLOR_DETAIL, false));
|
||||
return;
|
||||
}
|
||||
renderReport(json);
|
||||
@@ -325,34 +325,37 @@ public final class PostActivity extends Activity {
|
||||
|
||||
private void renderReport(String json) {
|
||||
if (json == null || json.isEmpty()) {
|
||||
showError("Driver POST returned an empty report.");
|
||||
showError("No diagnostics report was returned.");
|
||||
return;
|
||||
}
|
||||
JSONObject root;
|
||||
try {
|
||||
root = new JSONObject(json);
|
||||
} catch (JSONException error) {
|
||||
showError("Failed to parse POST report: " + error.getMessage() + "\n\n" + json);
|
||||
showError("Could not read the diagnostics report.");
|
||||
addRawJsonSection(json);
|
||||
return;
|
||||
}
|
||||
String nativeError = root.optString("error", "");
|
||||
if (!nativeError.isEmpty()) {
|
||||
showError(nativeError);
|
||||
showError("Driver diagnostics failed.");
|
||||
addRawJsonSection(json);
|
||||
return;
|
||||
}
|
||||
JSONArray backends = extractBackends(root);
|
||||
if (backends.length() == 0) {
|
||||
showError("POST report contains no backend sections:\n\n" + json);
|
||||
return;
|
||||
}
|
||||
statusView.setText("Self-test complete.");
|
||||
boolean hasBackend = false;
|
||||
for (int i = 0; i < backends.length(); ++i) {
|
||||
JSONObject backend = backends.optJSONObject(i);
|
||||
if (backend != null) {
|
||||
renderBackendSection(backend);
|
||||
hasBackend = true;
|
||||
}
|
||||
}
|
||||
if (hasBackend) {
|
||||
statusView.setVisibility(View.GONE);
|
||||
} else {
|
||||
showError("No backend results were reported.");
|
||||
}
|
||||
addRawJsonSection(json);
|
||||
}
|
||||
|
||||
@@ -381,88 +384,56 @@ public final class PostActivity extends Activity {
|
||||
|
||||
private void renderBackendSection(JSONObject backend) {
|
||||
String name = backend.optString("backend", backend.optString("name", "Unknown backend"));
|
||||
addText(sectionTitle(name), 16, COLOR_TEXT, true, dp(20));
|
||||
|
||||
if (!backend.optBoolean("available", true)) {
|
||||
addText("Driver not present / not probeable", 12, COLOR_INFO, false, dp(4));
|
||||
return;
|
||||
}
|
||||
|
||||
String verdict = backend.optString("verdict", "UNKNOWN");
|
||||
addText("Verdict: " + verdict, 14, verdictColor(verdict), true, dp(4));
|
||||
|
||||
String renderer = backend.optString("renderer", "");
|
||||
if (!renderer.isEmpty()) {
|
||||
addText(renderer, 12, COLOR_INFO, false, dp(2));
|
||||
}
|
||||
|
||||
addBenchControls(name);
|
||||
boolean available = backend.optBoolean("available", true);
|
||||
String verdict = available ? backend.optString("verdict", "Unknown") : "Unavailable";
|
||||
addText(sectionTitle(name) + " · " + verdict, 16, verdictColor(verdict), true, dp(16));
|
||||
|
||||
JSONArray checks = backend.optJSONArray("checks");
|
||||
JSONArray bugs = backend.optJSONArray("knownDriverBugs");
|
||||
LinearLayout issues = newColumn();
|
||||
LinearLayout otherChecks = newColumn();
|
||||
if (checks != null) {
|
||||
LinearLayout table = new LinearLayout(this);
|
||||
table.setOrientation(LinearLayout.VERTICAL);
|
||||
LinearLayout.LayoutParams tableParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
tableParams.topMargin = dp(6);
|
||||
contentLayout.addView(table, tableParams);
|
||||
int rowIndex = 0;
|
||||
for (int i = 0; i < checks.length(); ++i) {
|
||||
JSONObject check = checks.optJSONObject(i);
|
||||
if (check == null) {
|
||||
continue;
|
||||
}
|
||||
addCheckRow(table, check, rowIndex++);
|
||||
String status = check.optString("status", "INFO");
|
||||
boolean issue = "WARN".equalsIgnoreCase(status) || "FAIL".equalsIgnoreCase(status);
|
||||
addCheckRow(issue ? issues : otherChecks, check.optString("name", "Unnamed check"), status,
|
||||
check.optString("detail", check.optString("message", "")));
|
||||
}
|
||||
}
|
||||
|
||||
renderKnownDriverBugs(backend.optJSONArray("knownDriverBugs"));
|
||||
renderFormatCapabilities(backend.optJSONObject("formatCapabilities"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The "Known Driver Bugs" section: core functionality this driver advertises, accepts,
|
||||
* and then does not perform. Separate from the capability checks above because it answers
|
||||
* a different question and uses its own vocabulary.
|
||||
*
|
||||
* Only bugs the device actually HAS are reported, so a clean driver renders no section at
|
||||
* all rather than a list of reassurances - which is why the verdicts are FIXED (a MobileGL
|
||||
* quirk makes application behaviour correct anyway) and UNFIXABLE (no substitute; the
|
||||
* one-liner says what MobileGL does defensively), never PASS/FAIL.
|
||||
*/
|
||||
private void renderKnownDriverBugs(JSONArray bugs) {
|
||||
if (bugs == null || bugs.length() == 0) {
|
||||
return;
|
||||
if (bugs != null) {
|
||||
for (int i = 0; i < bugs.length(); ++i) {
|
||||
JSONObject bug = bugs.optJSONObject(i);
|
||||
if (bug == null) {
|
||||
continue;
|
||||
}
|
||||
String status = bug.optString("verdict", "UNFIXABLE");
|
||||
addCheckRow("FIXED".equalsIgnoreCase(status) ? otherChecks : issues,
|
||||
bug.optString("name", "Unnamed driver bug"), status, bug.optString("detail", ""));
|
||||
}
|
||||
}
|
||||
if (issues.getChildCount() != 0) {
|
||||
contentLayout.addView(issues);
|
||||
}
|
||||
addText("Known driver bugs", 14, COLOR_TEXT, true, dp(16));
|
||||
LinearLayout table = new LinearLayout(this);
|
||||
table.setOrientation(LinearLayout.VERTICAL);
|
||||
LinearLayout.LayoutParams tableParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
tableParams.topMargin = dp(6);
|
||||
contentLayout.addView(table, tableParams);
|
||||
|
||||
int rowIndex = 0;
|
||||
for (int i = 0; i < bugs.length(); ++i) {
|
||||
JSONObject bug = bugs.optJSONObject(i);
|
||||
if (bug == null) {
|
||||
continue;
|
||||
String renderer = backend.optString("renderer", "");
|
||||
String backendType = available ? backendTypeForSection(name) : null;
|
||||
JSONObject formats = backend.optJSONObject("formatCapabilities");
|
||||
if (!renderer.isEmpty() || otherChecks.getChildCount() != 0 || formats != null || backendType != null) {
|
||||
LinearLayout details = addDisclosure(contentLayout, "Details", dp(4));
|
||||
if (!renderer.isEmpty()) {
|
||||
details.addView(makeText(renderer, 12, COLOR_INFO, false));
|
||||
}
|
||||
// addCheckRow renders name + chip + collapsible detail, which is exactly this
|
||||
// section's shape; the chip text is the verdict rather than a status.
|
||||
JSONObject row = new JSONObject();
|
||||
try {
|
||||
row.put("name", bug.optString("name", "unnamed bug"));
|
||||
row.put("status", bug.optString("verdict", "UNFIXABLE"));
|
||||
row.put("detail", bug.optString("detail", ""));
|
||||
} catch (JSONException ignored) {
|
||||
continue;
|
||||
renderFormatCapabilities(details, formats);
|
||||
if (backendType != null) {
|
||||
addBenchControls(details, backendType);
|
||||
}
|
||||
if (otherChecks.getChildCount() != 0) {
|
||||
addDisclosure(details, "Other checks", dp(4)).addView(otherChecks);
|
||||
}
|
||||
addCheckRow(table, row, rowIndex++);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,13 +456,9 @@ public final class PostActivity extends Activity {
|
||||
* runs the Minecraft-shaped MG_Benchmark cases through the full MobileGL stack
|
||||
* on this backend, in a throwaway service process (see BenchService).
|
||||
*/
|
||||
private void addBenchControls(String sectionName) {
|
||||
final String backendType = backendTypeForSection(sectionName);
|
||||
if (backendType == null) {
|
||||
return;
|
||||
}
|
||||
private void addBenchControls(LinearLayout parent, String backendType) {
|
||||
Button button = new Button(this);
|
||||
button.setText("Run Bench");
|
||||
button.setText("Run benchmark");
|
||||
button.setAllCaps(false);
|
||||
button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
|
||||
button.setOnClickListener(v -> startBench(backendType));
|
||||
@@ -500,7 +467,7 @@ public final class PostActivity extends Activity {
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
buttonParams.topMargin = dp(6);
|
||||
contentLayout.addView(button, buttonParams);
|
||||
parent.addView(button, buttonParams);
|
||||
benchButtons.put(backendType, button);
|
||||
|
||||
LinearLayout results = new LinearLayout(this);
|
||||
@@ -510,7 +477,7 @@ public final class PostActivity extends Activity {
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
resultParams.topMargin = dp(4);
|
||||
contentLayout.addView(results, resultParams);
|
||||
parent.addView(results, resultParams);
|
||||
benchResultContainers.put(backendType, results);
|
||||
}
|
||||
|
||||
@@ -519,15 +486,12 @@ public final class PostActivity extends Activity {
|
||||
* a non-empty detail get a collapse indicator and toggle the detail text on tap;
|
||||
* rows without detail show no indicator and are not tappable.
|
||||
*/
|
||||
private void addCheckRow(LinearLayout table, JSONObject check, int rowIndex) {
|
||||
String status = check.optString("status", "INFO");
|
||||
String checkName = check.optString("name", "unnamed check");
|
||||
String detail = check.optString("detail", check.optString("message", ""));
|
||||
private void addCheckRow(LinearLayout table, String checkName, String status, String detail) {
|
||||
boolean hasDetail = !detail.isEmpty();
|
||||
|
||||
LinearLayout row = new LinearLayout(this);
|
||||
row.setOrientation(LinearLayout.VERTICAL);
|
||||
row.setBackgroundColor(rowIndex % 2 == 0 ? COLOR_ROW_EVEN : COLOR_ROW_ODD);
|
||||
row.setBackgroundColor(table.getChildCount() % 2 == 0 ? COLOR_ROW_EVEN : COLOR_ROW_ODD);
|
||||
table.addView(row, new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
@@ -543,7 +507,8 @@ public final class PostActivity extends Activity {
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
|
||||
TextView indicatorView = makeText(hasDetail ? INDICATOR_COLLAPSED : "", 12, COLOR_INFO, false);
|
||||
String indicator = hasDetail ? INDICATOR_COLLAPSED : "";
|
||||
TextView indicatorView = makeText(indicator, 12, COLOR_INFO, false);
|
||||
line.addView(indicatorView, new LinearLayout.LayoutParams(
|
||||
dp(16),
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
@@ -570,8 +535,9 @@ public final class PostActivity extends Activity {
|
||||
return;
|
||||
}
|
||||
|
||||
TextView detailView = makeText(detail, 11, COLOR_DETAIL, false);
|
||||
detailView.setPadding(dp(24), 0, dp(8), dp(8));
|
||||
TextView detailView = makeText(detail, 13, COLOR_DETAIL, false);
|
||||
detailView.setTypeface(Typeface.DEFAULT);
|
||||
detailView.setPadding(dp(24), 0, dp(12), dp(10));
|
||||
detailView.setVisibility(View.GONE);
|
||||
row.addView(detailView, new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
@@ -586,24 +552,22 @@ public final class PostActivity extends Activity {
|
||||
}
|
||||
|
||||
/** Adds one initially-collapsed capability matrix for every reported target. */
|
||||
private void renderFormatCapabilities(JSONObject formatCapabilities) {
|
||||
addText("Format capabilities", 14, COLOR_TEXT, true, dp(16));
|
||||
private void renderFormatCapabilities(LinearLayout parent, JSONObject formatCapabilities) {
|
||||
if (formatCapabilities == null) {
|
||||
addText("Format capability table unavailable.", 12, COLOR_INFO, false, dp(4));
|
||||
return;
|
||||
}
|
||||
|
||||
JSONArray capabilities = formatCapabilities.optJSONArray("capabilities");
|
||||
JSONArray targets = formatCapabilities.optJSONArray("targets");
|
||||
if (capabilities == null || capabilities.length() == 0 || targets == null || targets.length() == 0) {
|
||||
addText("Format capability table is empty.", 12, COLOR_INFO, false, dp(4));
|
||||
return;
|
||||
}
|
||||
|
||||
LinearLayout formats = addDisclosure(parent, "Format capabilities", dp(6));
|
||||
for (int targetIndex = 0; targetIndex < targets.length(); ++targetIndex) {
|
||||
JSONObject target = targets.optJSONObject(targetIndex);
|
||||
if (target != null) {
|
||||
addFormatTargetTable(target, capabilities);
|
||||
addFormatTargetTable(formats, target, capabilities);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -612,7 +576,7 @@ public final class PostActivity extends Activity {
|
||||
* Adds a target header whose table is created only while expanded. Removing the
|
||||
* table again on collapse avoids retaining all status cells for both backends.
|
||||
*/
|
||||
private void addFormatTargetTable(JSONObject target, JSONArray capabilities) {
|
||||
private void addFormatTargetTable(LinearLayout parent, JSONObject target, JSONArray capabilities) {
|
||||
String targetName = target.optString("name", "Unknown target");
|
||||
JSONArray rows = target.optJSONArray("rows");
|
||||
int formatCount = rows == null ? 0 : rows.length();
|
||||
@@ -624,7 +588,7 @@ public final class PostActivity extends Activity {
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
sectionParams.topMargin = dp(6);
|
||||
contentLayout.addView(section, sectionParams);
|
||||
parent.addView(section, sectionParams);
|
||||
|
||||
TextView toggleView = makeText(
|
||||
INDICATOR_COLLAPSED + " " + targetName + " (" + formatCount + " formats)",
|
||||
@@ -757,22 +721,35 @@ public final class PostActivity extends Activity {
|
||||
row.addView(cell, params);
|
||||
}
|
||||
|
||||
/** Adds the collapsed "Raw report" toggle plus the (initially hidden) raw JSON dump. */
|
||||
private void addRawJsonSection(String json) {
|
||||
TextView toggleView = addText(INDICATOR_COLLAPSED + " Raw report (tap to expand)", 12, COLOR_INFO, true, dp(24));
|
||||
toggleView.setMinimumHeight(dp(44));
|
||||
toggleView.setGravity(Gravity.CENTER_VERTICAL);
|
||||
LinearLayout details = addDisclosure(contentLayout, "Raw report", dp(12));
|
||||
details.addView(makeText(json, 10, COLOR_INFO, false));
|
||||
}
|
||||
|
||||
TextView rawView = addText(json, 10, COLOR_INFO, false, dp(4));
|
||||
rawView.setVisibility(View.GONE);
|
||||
private LinearLayout addDisclosure(LinearLayout parent, String label, int margin) {
|
||||
TextView toggle = makeText(INDICATOR_COLLAPSED + " " + label, 12, COLOR_TEXT, true);
|
||||
toggle.setMinimumHeight(dp(44));
|
||||
toggle.setGravity(Gravity.CENTER_VERTICAL);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
params.topMargin = margin;
|
||||
parent.addView(toggle, params);
|
||||
|
||||
toggleView.setOnClickListener(view -> {
|
||||
boolean expanded = rawView.getVisibility() == View.VISIBLE;
|
||||
rawView.setVisibility(expanded ? View.GONE : View.VISIBLE);
|
||||
toggleView.setText(expanded
|
||||
? INDICATOR_COLLAPSED + " Raw report (tap to expand)"
|
||||
: INDICATOR_EXPANDED + " Raw report (tap to collapse)");
|
||||
LinearLayout section = newColumn();
|
||||
section.setVisibility(View.GONE);
|
||||
parent.addView(section);
|
||||
toggle.setOnClickListener(view -> {
|
||||
boolean expanded = section.getVisibility() == View.VISIBLE;
|
||||
section.setVisibility(expanded ? View.GONE : View.VISIBLE);
|
||||
toggle.setText((expanded ? INDICATOR_COLLAPSED : INDICATOR_EXPANDED) + " " + label);
|
||||
});
|
||||
return section;
|
||||
}
|
||||
|
||||
private LinearLayout newColumn() {
|
||||
LinearLayout column = new LinearLayout(this);
|
||||
column.setOrientation(LinearLayout.VERTICAL);
|
||||
return column;
|
||||
}
|
||||
|
||||
private static String sectionTitle(String backendName) {
|
||||
@@ -793,6 +770,7 @@ public final class PostActivity extends Activity {
|
||||
case "DEGRADED":
|
||||
return COLOR_WARN;
|
||||
case "UNSUPPORTED":
|
||||
case "UNAVAILABLE":
|
||||
return COLOR_FAIL;
|
||||
default:
|
||||
return COLOR_INFO;
|
||||
@@ -823,9 +801,8 @@ public final class PostActivity extends Activity {
|
||||
|
||||
private void showError(String message) {
|
||||
Log.e(TAG, message);
|
||||
statusView.setText("Self-test failed.");
|
||||
statusView.setText(message);
|
||||
statusView.setTextColor(COLOR_FAIL);
|
||||
addText(message, 12, COLOR_FAIL, false, dp(8));
|
||||
}
|
||||
|
||||
private TextView addText(String text, int sizeSp, int color, boolean bold, int topMarginPx) {
|
||||
|
||||
Reference in new issue
Block a user