App 2.19.6: remove the CarPlay full-screen switch and the export button
CarPlay's 1920x640 is fixed in Allgo's system app. On start the car build removes the CarPlay entry from policy_control if the switch was left on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
@@ -1,234 +0,0 @@
|
||||
package com.evsuite.abrp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Read-only diagnostic for the CarPlay resolution question: copies what decides CarPlay's size
|
||||
* to a folder on the USB stick, for reading on a computer. It reads the car and writes only to
|
||||
* the stick.
|
||||
*
|
||||
* What it writes to {@code <stick>/Android/data/<package>/files/nilsmg4-carplay-<time>/}:
|
||||
* <ul>
|
||||
* <li>the CarPlay app's APK files and its own native libraries;</li>
|
||||
* <li>libraries and configuration files under /system, /vendor, /odm and /product whose path
|
||||
* names CarPlay (see {@link #isCarPlayPath});</li>
|
||||
* <li>the display-related system properties, never identifiers ({@link #keepProperty});</li>
|
||||
* <li>the window manager, SurfaceFlinger and display state, captured while CarPlay is in front.</li>
|
||||
* </ul>
|
||||
* Only the system user (the car build) may run dumpsys; elsewhere those files say why not.
|
||||
*/
|
||||
final class CarPlayExport {
|
||||
|
||||
private static final String TAG = "EVABRP.CarPlayExport";
|
||||
static final String CARPLAY_PACKAGE = "com.allgo.carplay.service";
|
||||
|
||||
private static final long MAX_FILE_BYTES = 64L << 20;
|
||||
private static final int MAX_FOUND_FILES = 200;
|
||||
private static final String[] SEARCH_ROOTS = {
|
||||
"/system/etc", "/system/lib", "/system/lib64", "/system/priv-app", "/system/app",
|
||||
"/vendor/etc", "/vendor/lib", "/vendor/lib64", "/vendor/app", "/vendor/priv-app",
|
||||
"/odm/etc", "/product/etc", "/product/app", "/product/priv-app",
|
||||
};
|
||||
|
||||
private static final Pattern CARPLAY_PATH = Pattern.compile("(?i)carplay|allgo|iap2|airplay");
|
||||
private static final Pattern PROPERTY_KEEP = Pattern.compile(
|
||||
"(?i)carplay|allgo|iap|airplay|display|lcd|screen|resolution|density|surface|hwui|"
|
||||
+ "\\bsf\\.|\\.sf\\.|width|height|ro\\.build\\.(version|display|fingerprint|id)|"
|
||||
+ "vehicle_type|projection");
|
||||
private static final Pattern PROPERTY_DROP = Pattern.compile(
|
||||
"(?i)serial|vin\\b|\\.vin|imei|iccid|imsi|mac|bt\\.addr|bdaddr|wifi|ssid|password|token|"
|
||||
+ "key|account|phone|msisdn|sim");
|
||||
|
||||
private CarPlayExport() {}
|
||||
|
||||
/** A path whose name says it belongs to CarPlay. */
|
||||
static boolean isCarPlayPath(String path) {
|
||||
return path != null && CARPLAY_PATH.matcher(path).find();
|
||||
}
|
||||
|
||||
/** A {@code [key]: [value]} getprop line worth exporting: display-related, never an identifier. */
|
||||
static boolean keepProperty(String getpropLine) {
|
||||
if (getpropLine == null) return false;
|
||||
int end = getpropLine.indexOf("]:");
|
||||
String key = end > 0 ? getpropLine.substring(0, end) : getpropLine;
|
||||
return PROPERTY_KEEP.matcher(key).find() && !PROPERTY_DROP.matcher(key).find();
|
||||
}
|
||||
|
||||
/** Runs the export; returns one line for the screen. Blocking: call it off the main thread. */
|
||||
static String run(Context context) {
|
||||
File stick = stickFolder(context);
|
||||
if (stick == null) {
|
||||
Log.w(TAG, "no USB stick");
|
||||
return "No USB stick found";
|
||||
}
|
||||
String stamp = new SimpleDateFormat("yyyyMMdd-HHmmss", Locale.US).format(new Date());
|
||||
File out = new File(stick, "nilsmg4-carplay-" + stamp);
|
||||
if (!out.mkdirs()) {
|
||||
Log.w(TAG, "cannot create " + out);
|
||||
return "Could not create " + out;
|
||||
}
|
||||
List<String> notes = new ArrayList<>();
|
||||
int copied = 0;
|
||||
|
||||
// The live state first, while CarPlay is still in front.
|
||||
command(out, "dumpsys-window.txt", notes, "dumpsys", "window", "windows");
|
||||
command(out, "dumpsys-surfaceflinger.txt", notes, "dumpsys", "SurfaceFlinger");
|
||||
command(out, "dumpsys-display.txt", notes, "dumpsys", "display");
|
||||
command(out, "dumpsys-activity.txt", notes, "dumpsys", "activity", "activities");
|
||||
command(out, "wm.txt", notes, "sh", "-c", "wm size; wm density");
|
||||
properties(out, notes);
|
||||
|
||||
try {
|
||||
ApplicationInfo app = context.getPackageManager().getApplicationInfo(CARPLAY_PACKAGE, 0);
|
||||
notes.add("uid " + app.uid + ", flags 0x" + Integer.toHexString(app.flags)
|
||||
+ ", source " + app.sourceDir + ", native " + app.nativeLibraryDir);
|
||||
File apkDir = new File(out, "apk");
|
||||
copied += copy(new File(app.sourceDir), apkDir, notes);
|
||||
if (app.splitSourceDirs != null) {
|
||||
for (String split : app.splitSourceDirs) copied += copy(new File(split), apkDir, notes);
|
||||
}
|
||||
File[] libs = app.nativeLibraryDir == null ? null : new File(app.nativeLibraryDir).listFiles();
|
||||
if (libs != null) {
|
||||
for (File lib : libs) copied += copy(lib, new File(out, "native"), notes);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
notes.add("CarPlay app not found: " + e);
|
||||
}
|
||||
|
||||
List<File> found = new ArrayList<>();
|
||||
for (String root : SEARCH_ROOTS) find(new File(root), 0, found);
|
||||
for (File f : found) {
|
||||
copied += copy(f, new File(out, "found" + f.getParent()), notes);
|
||||
}
|
||||
notes.add(found.size() + " CarPlay-named files under the system partitions");
|
||||
|
||||
write(new File(out, "notes.txt"), String.join("\n", notes) + "\n");
|
||||
String result = "Exported " + copied + " files to " + out;
|
||||
Log.i(TAG, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This app's own folder on the removable volume, or on any volume (the emulator) when there is
|
||||
* none: <stick>/Android/data/<package>/files. Android 9 lets an app write there and nowhere
|
||||
* else on a removable volume — the stick's top folder is read-only to it.
|
||||
*/
|
||||
private static File stickFolder(Context context) {
|
||||
File fallback = null;
|
||||
for (File dir : context.getExternalFilesDirs(null)) {
|
||||
if (dir == null || UsbVolume.root(dir) == null) continue;
|
||||
boolean removable;
|
||||
try {
|
||||
removable = Environment.isExternalStorageRemovable(dir);
|
||||
} catch (IllegalArgumentException e) {
|
||||
removable = false;
|
||||
}
|
||||
if (removable) return dir;
|
||||
if (fallback == null) fallback = dir;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
private static void find(File dir, int depth, List<File> found) {
|
||||
if (depth > 5 || found.size() >= MAX_FOUND_FILES) return;
|
||||
File[] entries = dir.listFiles();
|
||||
if (entries == null) return;
|
||||
for (File f : entries) {
|
||||
if (found.size() >= MAX_FOUND_FILES) return;
|
||||
if (f.isDirectory()) {
|
||||
if (isCarPlayPath(f.getName())) {
|
||||
File[] inner = f.listFiles();
|
||||
if (inner != null) for (File g : inner) if (g.isFile()) found.add(g);
|
||||
}
|
||||
find(f, depth + 1, found);
|
||||
} else if (isCarPlayPath(f.getName())) {
|
||||
found.add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void properties(File out, List<String> notes) {
|
||||
String all = exec(notes, "getprop");
|
||||
if (all == null) return;
|
||||
StringBuilder kept = new StringBuilder();
|
||||
for (String line : all.split("\n")) if (keepProperty(line)) kept.append(line).append('\n');
|
||||
write(new File(out, "properties.txt"), kept.toString());
|
||||
}
|
||||
|
||||
private static void command(File out, String name, List<String> notes, String... argv) {
|
||||
String text = exec(notes, argv);
|
||||
if (text != null) write(new File(out, name), text);
|
||||
}
|
||||
|
||||
private static String exec(List<String> notes, String... argv) {
|
||||
Process p = null;
|
||||
try {
|
||||
p = new ProcessBuilder(argv).redirectErrorStream(true).start();
|
||||
p.getOutputStream().close();
|
||||
byte[] bytes = readAll(p.getInputStream(), 8 << 20);
|
||||
if (!p.waitFor(20, TimeUnit.SECONDS)) notes.add(String.join(" ", argv) + ": timed out");
|
||||
return new String(bytes, StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
notes.add(String.join(" ", argv) + ": " + e);
|
||||
return null;
|
||||
} finally {
|
||||
if (p != null) p.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private static int copy(File source, File dir, List<String> notes) {
|
||||
if (!source.isFile()) return 0;
|
||||
if (source.length() > MAX_FILE_BYTES) {
|
||||
notes.add("skipped (too large): " + source + " " + source.length());
|
||||
return 0;
|
||||
}
|
||||
if (!dir.isDirectory() && !dir.mkdirs()) {
|
||||
notes.add("no folder for " + source);
|
||||
return 0;
|
||||
}
|
||||
try (InputStream in = new FileInputStream(source);
|
||||
OutputStream os = new FileOutputStream(new File(dir, source.getName()))) {
|
||||
byte[] buffer = new byte[64 * 1024];
|
||||
int n;
|
||||
while ((n = in.read(buffer)) != -1) os.write(buffer, 0, n);
|
||||
return 1;
|
||||
} catch (IOException e) {
|
||||
notes.add("not copied: " + source + ": " + e.getMessage());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] readAll(InputStream in, int max) throws IOException {
|
||||
java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
|
||||
byte[] chunk = new byte[16 * 1024];
|
||||
int n;
|
||||
while ((n = in.read(chunk)) != -1 && buffer.size() < max) buffer.write(chunk, 0, n);
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
private static void write(File file, String text) {
|
||||
try (OutputStream os = new FileOutputStream(file)) {
|
||||
os.write(text.getBytes(StandardCharsets.UTF_8));
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, "not written: " + file, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,46 +242,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (r.statusBarPx != null) {
|
||||
sb.append('\n').append(getString(R.string.foreground_status_bar, r.statusBarPx));
|
||||
}
|
||||
if (lastCarPlayExport != null) {
|
||||
sb.append('\n').append(getString(R.string.carplay_export_last, lastCarPlayExport));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/** The last CarPlay export's outcome, for the Foreground apps card; null before the first. */
|
||||
private static volatile String lastCarPlayExport;
|
||||
|
||||
/**
|
||||
* Waits 20 seconds, so the driver can bring CarPlay to the front, then exports what decides
|
||||
* its size to the USB stick (CarPlayExport). Runs in the app's process, which the upload
|
||||
* service keeps alive while this activity is in the background.
|
||||
*/
|
||||
private void startCarPlayExport() {
|
||||
android.content.Context app = getApplicationContext();
|
||||
android.os.Handler main = new android.os.Handler(android.os.Looper.getMainLooper());
|
||||
Toast.makeText(app, R.string.carplay_export_started, Toast.LENGTH_LONG).show();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(20_000);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
main.post(() -> Toast.makeText(app, R.string.carplay_export_running, Toast.LENGTH_SHORT).show());
|
||||
String result;
|
||||
try {
|
||||
result = CarPlayExport.run(app);
|
||||
} catch (Throwable t) {
|
||||
result = "Export failed: " + t;
|
||||
}
|
||||
lastCarPlayExport = result;
|
||||
final String shown = result;
|
||||
main.post(() -> {
|
||||
Toast.makeText(app, shown, Toast.LENGTH_LONG).show();
|
||||
refreshForeground();
|
||||
});
|
||||
}, "carplay-export").start();
|
||||
}
|
||||
|
||||
/** Refreshes state + call log while the screen is visible. */
|
||||
private final android.os.Handler uiHandler = new android.os.Handler(android.os.Looper.getMainLooper());
|
||||
private final Runnable uiRefresh = new Runnable() {
|
||||
@@ -335,7 +298,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
logPane.findViewById(R.id.flush_now_button).setOnClickListener(v -> manualFlush());
|
||||
foregroundText = logPane.findViewById(R.id.foreground_text);
|
||||
logPane.findViewById(R.id.foreground_refresh_button).setOnClickListener(v -> refreshForeground());
|
||||
logPane.findViewById(R.id.carplay_export_button).setOnClickListener(v -> startCarPlayExport());
|
||||
|
||||
setUpPager();
|
||||
// Back on the page that was open when the activity was recreated (accent colour change).
|
||||
@@ -1105,54 +1067,27 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// ---------- Upload page ----------
|
||||
|
||||
/** The car's CarPlay app, as the Logs tab's foreground list showed it on SWI68. */
|
||||
private static final String CARPLAY_PACKAGE = "com.allgo.carplay.service";
|
||||
|
||||
/**
|
||||
* Experiment: forces CarPlay into immersive mode through Android 9's policy_control setting.
|
||||
* The switch shows what the setting holds, not a preference, and switching off removes only
|
||||
* our entry. Writing it needs WRITE_SECURE_SETTINGS, which only the car build (system user)
|
||||
* has; elsewhere the switch is disabled.
|
||||
* App 2.19.2–2.19.5 had a "Full screen for CarPlay" experiment that added CarPlay to Android 9's
|
||||
* policy_control setting; CarPlay's 1920×640 picture turned out to be fixed in its own app, so
|
||||
* the switch is gone. This takes our entry out again where the switch was left on, and leaves
|
||||
* anything else in the setting alone. Only the car build (system user) may write it.
|
||||
*/
|
||||
private void bindCarPlayFullScreen() {
|
||||
com.google.android.material.switchmaterial.SwitchMaterial sw =
|
||||
settingsPane.findViewById(R.id.carplay_full_screen_switch);
|
||||
boolean mayWrite = checkSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
|
||||
== android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
String current = android.provider.Settings.Global.getString(getContentResolver(), PolicyControl.KEY);
|
||||
sw.setOnCheckedChangeListener(null);
|
||||
sw.setChecked(PolicyControl.hasFull(current, CARPLAY_PACKAGE));
|
||||
sw.setEnabled(mayWrite);
|
||||
if (!mayWrite) {
|
||||
((TextView) settingsPane.findViewById(R.id.carplay_full_screen_hint))
|
||||
.setText(R.string.hint_carplay_full_screen_unavailable);
|
||||
return;
|
||||
}
|
||||
sw.setOnCheckedChangeListener((btn, checked) -> diagReader.execute(() -> {
|
||||
boolean ok;
|
||||
private void clearCarPlayFullScreen() {
|
||||
if (checkSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS)
|
||||
!= android.content.pm.PackageManager.PERMISSION_GRANTED) return;
|
||||
diagReader.execute(() -> {
|
||||
try {
|
||||
android.content.ContentResolver cr = getContentResolver();
|
||||
String before = android.provider.Settings.Global.getString(cr, PolicyControl.KEY);
|
||||
String after = checked ? PolicyControl.withFull(before, CARPLAY_PACKAGE)
|
||||
: PolicyControl.withoutFull(before, CARPLAY_PACKAGE);
|
||||
android.provider.Settings.Global.putString(cr, PolicyControl.KEY, after);
|
||||
String now = android.provider.Settings.Global.getString(cr, PolicyControl.KEY);
|
||||
ok = PolicyControl.hasFull(now, CARPLAY_PACKAGE) == checked;
|
||||
android.util.Log.i("EVABRP.Settings", "policy_control " + (checked ? "on" : "off") + ": " + now);
|
||||
if (!PolicyControl.hasFull(before, PolicyControl.CARPLAY_PACKAGE)) return;
|
||||
android.provider.Settings.Global.putString(cr, PolicyControl.KEY,
|
||||
PolicyControl.withoutFull(before, PolicyControl.CARPLAY_PACKAGE));
|
||||
android.util.Log.i("EVABRP.Settings", "CarPlay entry removed from policy_control");
|
||||
} catch (RuntimeException e) {
|
||||
android.util.Log.w("EVABRP.Settings", "policy_control not written", e);
|
||||
ok = false;
|
||||
android.util.Log.w("EVABRP.Settings", "policy_control not cleared", e);
|
||||
}
|
||||
final boolean written = ok;
|
||||
runOnUiThread(() -> {
|
||||
if (isDestroyed()) return;
|
||||
if (!written) {
|
||||
Toast.makeText(this, R.string.carplay_full_screen_failed, Toast.LENGTH_LONG).show();
|
||||
bindCarPlayFullScreen();
|
||||
}
|
||||
refreshForeground();
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void bindServicePane() {
|
||||
@@ -1168,7 +1103,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
prefs.edit().putBoolean(UploadSettings.KEY_FULL_SCREEN, checked).apply();
|
||||
applyFullScreen();
|
||||
});
|
||||
bindCarPlayFullScreen();
|
||||
clearCarPlayFullScreen();
|
||||
liveTelemetrySwitch = servicePane.findViewById(R.id.abrp_upload_switch);
|
||||
intervalChoices = servicePane.findViewById(R.id.interval_choices);
|
||||
boostSwitch = servicePane.findViewById(R.id.boost_switch);
|
||||
|
||||
@@ -7,14 +7,16 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* The value of Android 9's {@code policy_control} global setting, which forces other apps into
|
||||
* immersive mode: {@code immersive.full=pkg1,pkg2:immersive.status=pkg3}. This adds or removes
|
||||
* one package in {@code immersive.full} and leaves every other entry as it was, so switching
|
||||
* our experiment off restores what was there before. Pure Java, so it is unit-tested.
|
||||
* immersive mode: {@code immersive.full=pkg1,pkg2:immersive.status=pkg3}. Adds or removes one
|
||||
* package in {@code immersive.full} and leaves every other entry as it was. Kept to clear the
|
||||
* entry the removed CarPlay experiment wrote. Pure Java, so it is unit-tested.
|
||||
*/
|
||||
final class PolicyControl {
|
||||
|
||||
static final String KEY = "policy_control";
|
||||
static final String FULL = "immersive.full";
|
||||
/** The car's CarPlay app, which the removed full-screen experiment added. */
|
||||
static final String CARPLAY_PACKAGE = "com.allgo.carplay.service";
|
||||
|
||||
private PolicyControl() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user