mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a9fb5e0468 |
No files matched your search
@@ -2384,7 +2384,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
homeScreenEnabled = HomeApp.isHomeScreenEnabled(this)
|
||||
homeAppSelected = homeScreenEnabled && HomeApp.isDefault(this)
|
||||
defaultHomeLabel = HomeApp.defaultLabel(this)
|
||||
com.droiddeck.launcher.ui.NavTabs.syncHomeApps(this, homeAppSelected)
|
||||
refreshAndroidApps()
|
||||
integrationState = readIntegration()
|
||||
}
|
||||
|
||||
@@ -329,8 +329,8 @@ object BwrapSpawner {
|
||||
|
||||
private fun zypakShims(binds: List<Bind>, root: File, dir: File): List<Bind> {
|
||||
val wrappers = listOf("/app/bin/zypak-wrapper.sh", "/app/bin/zypak-wrapper").filter { guest ->
|
||||
val host = File(hostPath(binds, root.path, guest)).toPath()
|
||||
Files.isRegularFile(host, java.nio.file.LinkOption.NOFOLLOW_LINKS) || Files.isSymbolicLink(host)
|
||||
val host = File(hostPath(binds, root.path, guest))
|
||||
host.isFile && !Files.isSymbolicLink(host.toPath())
|
||||
}
|
||||
if (wrappers.isEmpty()) return emptyList()
|
||||
val shim = File(dir, "zypak-wrapper")
|
||||
|
||||
@@ -22,7 +22,7 @@ class RuntimeInstallService : Service() {
|
||||
if (intent?.action == ACTION_PACKAGE) return holdPackage(startId)
|
||||
val removal = intent?.action == ACTION_REMOVE
|
||||
val release = intent?.let(::releaseFrom)
|
||||
val foreground = enterForeground(notification(getString(if (LinuxRuntimeInstaller.isMaintaining()) R.string.desktop_removing else if (removal) R.string.rtinst_removing else R.string.user_apps_starting), -1))
|
||||
startForeground(NOTIFICATION_ID, notification(getString(if (LinuxRuntimeInstaller.isMaintaining()) R.string.desktop_removing else if (removal) R.string.rtinst_removing else R.string.user_apps_starting), -1))
|
||||
if (release == null && !removal) {
|
||||
stopSelf(startId)
|
||||
return START_NOT_STICKY
|
||||
@@ -31,7 +31,7 @@ class RuntimeInstallService : Service() {
|
||||
val manager = getSystemService(NotificationManager::class.java)
|
||||
var shown = ""
|
||||
val progress = LinuxRuntimeInstaller.ProgressListener { stage, percent ->
|
||||
if (foreground && "$stage:$percent" != shown) {
|
||||
if ("$stage:$percent" != shown) {
|
||||
shown = "$stage:$percent"
|
||||
manager?.notify(NOTIFICATION_ID, notification(stage, percent))
|
||||
}
|
||||
@@ -46,10 +46,7 @@ class RuntimeInstallService : Service() {
|
||||
}
|
||||
|
||||
private fun holdPackage(startId: Int): Int {
|
||||
if (!enterForeground(notification(packageStage, packagePercent, packageTitle))) {
|
||||
stopSelf(startId)
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
startForeground(NOTIFICATION_ID, notification(packageStage, packagePercent, packageTitle))
|
||||
Thread({
|
||||
val manager = getSystemService(NotificationManager::class.java)
|
||||
var shown = ""
|
||||
@@ -68,15 +65,6 @@ class RuntimeInstallService : Service() {
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
/** Android 12+ refuses a foreground start while the app is in the background; the work then goes on without the notification. */
|
||||
private fun enterForeground(notification: Notification): Boolean = try {
|
||||
startForeground(NOTIFICATION_ID, notification)
|
||||
true
|
||||
} catch (e: IllegalStateException) {
|
||||
android.util.Log.w("RuntimeInstallService", "running without a foreground service: $e")
|
||||
false
|
||||
}
|
||||
|
||||
private fun notification(stage: String, percent: Int, title: String? = null): Notification {
|
||||
val manager = getSystemService(NotificationManager::class.java)
|
||||
manager?.createNotificationChannel(NotificationChannel(CHANNEL_ID, getString(R.string.setup_runtime),
|
||||
|
||||
@@ -448,13 +448,6 @@ object SessionPrefs {
|
||||
prefs(context).edit().putString("navTabHidden", keys.joinToString(",")).apply()
|
||||
}
|
||||
|
||||
fun appsTabHomeSeen(context: Context): Boolean? =
|
||||
prefs(context).takeIf { it.contains("appsTabHomeSeen") }?.getBoolean("appsTabHomeSeen", false)
|
||||
|
||||
fun setAppsTabHomeSeen(context: Context, seen: Boolean) {
|
||||
prefs(context).edit().putBoolean("appsTabHomeSeen", seen).apply()
|
||||
}
|
||||
|
||||
private fun idList(raw: String?): List<String> = raw.orEmpty().split(',').map { it.trim() }.filter { it.isNotEmpty() }
|
||||
|
||||
val STORES_SORTS = listOf("lastPlayed", "recentlyInstalled", "titleAsc", "titleDesc", "sizeDesc", "sizeAsc", "releaseDateDesc")
|
||||
|
||||
@@ -27,9 +27,9 @@ internal object DeveloperTools {
|
||||
internal object NavTabs {
|
||||
const val MORE = "more"
|
||||
val ALL = listOf("steam", "desktop", "games", "downloads", "setup", "updates", "stores", "soundtracks", "components", "storage", "sync", "decky", "boot-movies", "android-apps", "agent")
|
||||
val DEFAULT_SHELVED = setOf("soundtracks", "components", "storage", "sync", "decky", "boot-movies", "agent")
|
||||
val DEFAULT_SHELVED = setOf("soundtracks", "components", "storage", "sync", "decky", "boot-movies", "android-apps", "agent")
|
||||
val DEFAULT_HIDDEN = setOf("android-apps", "agent")
|
||||
private val SHELVED_WHEN_NEW = setOf("storage", "sync", "decky", "boot-movies", "agent")
|
||||
private val SHELVED_WHEN_NEW = setOf("storage", "sync", "decky", "boot-movies", "android-apps", "agent")
|
||||
private val OLD_ORDER = listOf("steam", "games", "soundtracks", "stores", "downloads", "desktop", "agent", "components", "android-apps", "storage", "sync", "setup", "updates")
|
||||
private val OLD_SHELVED = setOf("soundtracks", "agent", "storage", "sync")
|
||||
private const val LAYOUT_VERSION = 2
|
||||
@@ -95,15 +95,6 @@ internal object NavTabs {
|
||||
else -> true
|
||||
}
|
||||
|
||||
// Apps only has content when DroidDeck is the home app, so it follows that state on each change and
|
||||
// otherwise stays wherever the user put it.
|
||||
fun syncHomeApps(context: Context, homeSelected: Boolean) {
|
||||
val seen = SessionPrefs.appsTabHomeSeen(context)
|
||||
SessionPrefs.setAppsTabHomeSeen(context, homeSelected)
|
||||
if (seen == homeSelected || (seen == null && !homeSelected)) return
|
||||
setHidden(context, "android-apps", !homeSelected)
|
||||
}
|
||||
|
||||
fun hideable(key: String) = key != "setup"
|
||||
|
||||
fun place(s: FrontEndState, key: String): TabPlace = when {
|
||||
|
||||
@@ -263,26 +263,8 @@ class BwrapSpawnerPlanTest {
|
||||
val shim = plan.binds.single { it.guest == "/app/bin/zypak-wrapper.sh" }
|
||||
assertTrue(shim.host.startsWith(dir.path))
|
||||
assertTrue(File(shim.host).readText().contains("exec \"\$program\" --no-sandbox \"\$@\""))
|
||||
assertEquals(shim.host, plan.binds.single { it.guest == "/app/bin/zypak-wrapper" }.host)
|
||||
assertFalse(plan.binds.any { it.guest == "/app/bin/zypak-wrapper" })
|
||||
assertTrue(File(app, "bin/zypak-wrapper.sh").readText().contains("zypak-helper"))
|
||||
assertEquals("/app/bin/zypak-wrapper.sh", Files.readSymbolicLink(File(app, "bin/zypak-wrapper").toPath()).toString())
|
||||
}
|
||||
|
||||
@Test fun zypakWrapperLinkThatDoesNotResolveOnTheHostGetsTheShim() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val app = File(runtime, "app").apply { File(this, "bin").mkdirs() }
|
||||
File(app, "bin/zypak-wrapper.sh").writeText("#!/usr/bin/bash\nexec zypak-helper host - \"\$@\"\n")
|
||||
val dangling = java.nio.file.Paths.get(LinuxRuntime.rootDir(context).path, "app/bin/zypak-wrapper.sh")
|
||||
Files.createSymbolicLink(File(app, "bin/zypak-wrapper").toPath(), dangling)
|
||||
val plan = BwrapSpawner.plan(context, request(
|
||||
op("t" to "bind", "src" to "/runtime-files/app", "dest" to "/app", "ro" to true),
|
||||
), dir)
|
||||
|
||||
assertFalse(Files.exists(dangling))
|
||||
val shim = plan.binds.single { it.guest == "/app/bin/zypak-wrapper" }
|
||||
assertTrue(shim.host.startsWith(dir.path))
|
||||
assertTrue(File(shim.host).readText().contains("exec \"\$program\" --no-sandbox \"\$@\""))
|
||||
assertEquals(shim.host, plan.binds.single { it.guest == "/app/bin/zypak-wrapper.sh" }.host)
|
||||
}
|
||||
|
||||
@Test fun appsWithoutZypakKeepTheirFiles() {
|
||||
|
||||
@@ -48,21 +48,6 @@ class NavTabsTest {
|
||||
assertTrue(NavTabs.isDefault())
|
||||
}
|
||||
|
||||
@Test fun appsFollowsTheHomeAppOnEachChangeAndOtherwiseKeepsTheUsersChoice() {
|
||||
NavTabs.syncHomeApps(ctx, false)
|
||||
assertEquals(TabPlace.HIDDEN, NavTabs.place(state(), "android-apps"))
|
||||
NavTabs.syncHomeApps(ctx, true)
|
||||
assertEquals(TabPlace.BAR, NavTabs.place(state(), "android-apps"))
|
||||
NavTabs.setHidden(ctx, "android-apps", true)
|
||||
NavTabs.syncHomeApps(ctx, true)
|
||||
assertEquals(TabPlace.HIDDEN, NavTabs.place(state(), "android-apps"))
|
||||
NavTabs.syncHomeApps(ctx, false)
|
||||
NavTabs.syncHomeApps(ctx, true)
|
||||
assertEquals(TabPlace.BAR, NavTabs.place(state(), "android-apps"))
|
||||
NavTabs.syncHomeApps(ctx, false)
|
||||
assertEquals(TabPlace.HIDDEN, NavTabs.place(state(), "android-apps"))
|
||||
}
|
||||
|
||||
@Test fun showingMusicOnceKeepsItShownAfterReload() {
|
||||
place("soundtracks", TabPlace.BAR)
|
||||
NavTabs.load(ctx)
|
||||
@@ -234,12 +219,12 @@ class NavTabsTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
val last = NavTabs.listed(state()).last { it !in NavTabs.shelved }
|
||||
val last = navigationKeys(state()).last { it != NavTabs.MORE }
|
||||
compose.onNodeWithTag("tab-row-$last").requestFocus()
|
||||
compose.onNodeWithTag("tab-row-$last").performKeyPress(pad(android.view.KeyEvent.KEYCODE_BUTTON_Y))
|
||||
compose.onNodeWithTag("tab-row-$last").performKeyPress(pad(android.view.KeyEvent.KEYCODE_DPAD_DOWN))
|
||||
compose.onNodeWithTag("tab-row-$last").performKeyPress(pad(android.view.KeyEvent.KEYCODE_BUTTON_Y))
|
||||
compose.runOnIdle { assertTrue(last in NavTabs.shelved) }
|
||||
compose.runOnIdle { assertEquals(last, NavTabs.more(state()).first()) }
|
||||
compose.onNodeWithTag("tab-shown-desktop").performClick()
|
||||
compose.runOnIdle { assertFalse("desktop" in navigationKeys(state())) }
|
||||
compose.onNodeWithTag("tab-shown-setup").performClick()
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <limits.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <net/route.h>
|
||||
#include <netpacket/packet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
@@ -533,6 +534,8 @@ static void write_table(FILE *out, const char *table, const struct link *link) {
|
||||
}
|
||||
}
|
||||
|
||||
#define ROUTE_TABLE 0
|
||||
#define IPV6_ROUTE_TABLE 1
|
||||
#define CARRIER_TABLE 5
|
||||
|
||||
#define SOCKET_TABLES 6
|
||||
@@ -606,6 +609,48 @@ static FILE *synthesize(int table) {
|
||||
return out;
|
||||
}
|
||||
|
||||
static int link_has_gateway(int family) {
|
||||
struct link link;
|
||||
if (!load_link(&link)) return 0;
|
||||
for (int i = 0; i < link.gateway_count; i++) {
|
||||
if (link.gateways[i].family == family) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int default_route_line(const char *line, int table) {
|
||||
unsigned flags, prefix;
|
||||
if (table == ROUTE_TABLE) {
|
||||
unsigned destination, gateway, mask;
|
||||
return sscanf(line, "%*s %x %x %x %*d %*d %*d %x", &destination, &gateway, &flags, &mask) == 4
|
||||
&& destination == 0 && mask == 0 && (flags & RTF_UP);
|
||||
}
|
||||
char destination[33];
|
||||
return sscanf(line, "%32s %x %*s %*x %*s %*x %*x %*x %x", destination, &prefix, &flags) == 3
|
||||
&& prefix == 0 && strspn(destination, "0") == 32 && (flags & RTF_UP) && !(flags & RTF_REJECT);
|
||||
}
|
||||
|
||||
static int misses_default_route(int fd, int table) {
|
||||
if (table != ROUTE_TABLE && table != IPV6_ROUTE_TABLE) return 0;
|
||||
if (!link_has_gateway(table == ROUTE_TABLE ? AF_INET : AF_INET6)) return 0;
|
||||
size_t capacity = 65536, size = 0;
|
||||
char *text = malloc(capacity + 1);
|
||||
if (text == NULL) return 0;
|
||||
ssize_t got = 1;
|
||||
while (size < capacity && (got = pread(fd, text + size, capacity - size, (off_t) size)) > 0) size += (size_t) got;
|
||||
int misses = got == 0;
|
||||
text[size] = '\0';
|
||||
for (char *line = text; misses && *line;) {
|
||||
char *end = strchr(line, '\n');
|
||||
if (end) *end = '\0';
|
||||
if (default_route_line(line, table)) misses = 0;
|
||||
if (end == NULL) break;
|
||||
line = end + 1;
|
||||
}
|
||||
free(text);
|
||||
return misses;
|
||||
}
|
||||
|
||||
int dd_status_without_tracer(const char *path, int flags, const void *caller) __attribute__((visibility("hidden")));
|
||||
|
||||
const char *dd_oom_adj_redirect(const char *path, int writing) __attribute__((visibility("hidden")));
|
||||
@@ -623,6 +668,12 @@ static FILE *open_stream(fopen_fn real, const char *path, const char *mode, cons
|
||||
FILE *f;
|
||||
if (table >= 0 && denied_recently(table, path) && (f = synthesize(table)) != NULL) return f;
|
||||
f = real(path, mode);
|
||||
if (f && table >= 0 && misses_default_route(fileno(f), table)) {
|
||||
FILE *link_table = synthesize(table);
|
||||
if (link_table == NULL) return f;
|
||||
fclose(f);
|
||||
return link_table;
|
||||
}
|
||||
if (f || table < 0) return f;
|
||||
int saved = errno;
|
||||
if ((f = synthesize(table)) != NULL) {
|
||||
@@ -636,9 +687,9 @@ static FILE *open_stream(fopen_fn real, const char *path, const char *mode, cons
|
||||
int dd_net_open(const char *path, int flags, int fd) __attribute__((visibility("hidden")));
|
||||
|
||||
int dd_net_open(const char *path, int flags, int fd) {
|
||||
if (fd >= 0 || path == NULL || (flags & O_ACCMODE) != O_RDONLY || (flags & O_DIRECTORY)) return fd;
|
||||
if (path == NULL || (flags & O_ACCMODE) != O_RDONLY || (flags & O_DIRECTORY)) return fd;
|
||||
int table = denied_table(path);
|
||||
if (table < 0) return fd;
|
||||
if (table < 0 || (fd >= 0 && !misses_default_route(fd, table))) return fd;
|
||||
int saved = errno;
|
||||
FILE *f = synthesize(table);
|
||||
if (f == NULL) {
|
||||
@@ -656,7 +707,8 @@ int dd_net_open(const char *path, int flags, int fd) {
|
||||
errno = saved;
|
||||
return fd;
|
||||
}
|
||||
if (saved == EACCES) remember_denial(table, path);
|
||||
if (fd >= 0) close(fd);
|
||||
else if (saved == EACCES) remember_denial(table, path);
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,12 +87,21 @@ int getsockopt(int fd, int level, int option, void *value, socklen_t *len) {
|
||||
return real(fd, level, option, value, len);
|
||||
}
|
||||
|
||||
static __thread char fixture_path[4096];
|
||||
|
||||
static const char *table_fixture(const char *path) {
|
||||
const char *directory = getenv("NETLINK_TEST_TABLES");
|
||||
if (!directory || !path || strncmp(path, "/proc/net/", 10)) return path;
|
||||
snprintf(fixture_path, sizeof(fixture_path), "%s/%s", directory, path + 10);
|
||||
return access(fixture_path, F_OK) == 0 ? fixture_path : path;
|
||||
}
|
||||
|
||||
FILE *fopen(const char *path, const char *mode) {
|
||||
static FILE *(*real)(const char *, const char *);
|
||||
if (!real) real = dlsym(RTLD_NEXT, "fopen");
|
||||
const char *snapshot = getenv("NETLINK_TEST_SNAPSHOT");
|
||||
if (snapshot && !strcmp(path, "/etc/droiddeck-net")) path = snapshot;
|
||||
return real(path, mode);
|
||||
return real(table_fixture(path), mode);
|
||||
}
|
||||
|
||||
static int denied(const char *path) {
|
||||
@@ -116,13 +125,13 @@ int open(const char *path, int flags, ...) {
|
||||
va_start(ap, flags);
|
||||
mode_t mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
return denied(path) ? -1 : real(path, flags, mode);
|
||||
return denied(path) ? -1 : real(table_fixture(path), flags, mode);
|
||||
}
|
||||
|
||||
int __open_2(const char *path, int flags) {
|
||||
static int (*real)(const char *, int);
|
||||
if (!real) real = dlsym(RTLD_NEXT, "__open_2");
|
||||
return denied(path) ? -1 : real(path, flags);
|
||||
return denied(path) ? -1 : real(table_fixture(path), flags);
|
||||
}
|
||||
|
||||
int openat(int dirfd, const char *path, int flags, ...) {
|
||||
@@ -132,7 +141,7 @@ int openat(int dirfd, const char *path, int flags, ...) {
|
||||
va_start(ap, flags);
|
||||
mode_t mode = va_arg(ap, mode_t);
|
||||
va_end(ap);
|
||||
return denied(path) ? -1 : real(dirfd, path, flags, mode);
|
||||
return denied(path) ? -1 : real(dirfd, table_fixture(path), flags, mode);
|
||||
}
|
||||
|
||||
int close_range(unsigned int first, unsigned int last, int flags) {
|
||||
@@ -214,6 +223,37 @@ static void proc_net_test(int denied, int sealed) {
|
||||
}
|
||||
}
|
||||
|
||||
static const char *table_source(int descriptor) {
|
||||
char link[64], target[4096];
|
||||
snprintf(link, sizeof(link), "/proc/self/fd/%d", descriptor);
|
||||
ssize_t length = readlink(link, target, sizeof(target) - 1);
|
||||
require(length > 0, "route table target");
|
||||
target[length] = 0;
|
||||
return strncmp(target, "/memfd:droiddeck-net", 20) == 0 ? "link" : "real";
|
||||
}
|
||||
|
||||
static void route_tables_test(void) {
|
||||
static const char *const tables[] = {"/proc/net/route", "/proc/net/ipv6_route"};
|
||||
static const char *const gateways[] = {"\t00000000\t0101A8C0\t0003\t", "20010db8000000000000000000000001 "};
|
||||
char text[4096];
|
||||
for (unsigned i = 0; i < 2; i++) {
|
||||
FILE *stream = fopen(tables[i], "r");
|
||||
require(stream != NULL, "route table fopen");
|
||||
const char *source = table_source(fileno(stream));
|
||||
size_t total = fread(text, 1, sizeof(text) - 1, stream);
|
||||
text[total] = 0;
|
||||
require(strcmp(source, "link") || strstr(text, gateways[i]), "link table lists the default gateway");
|
||||
printf("%s ", source);
|
||||
fclose(stream);
|
||||
int descriptor = i ? openat(AT_FDCWD, tables[i], O_RDONLY | O_CLOEXEC) : open(tables[i], O_RDONLY | O_CLOEXEC);
|
||||
require(descriptor >= 0, "route table open");
|
||||
require(fcntl(descriptor, F_GETFD) & FD_CLOEXEC, "route table keeps close-on-exec");
|
||||
printf("%s ", table_source(descriptor));
|
||||
close(descriptor);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static unsigned port_of(int descriptor) {
|
||||
struct sockaddr_nl address;
|
||||
socklen_t length = sizeof(address);
|
||||
@@ -1209,6 +1249,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
else if (!strcmp(argv[1], "range") || !strcmp(argv[1], "cloexec") || !strcmp(argv[1], "closefrom"))
|
||||
close_range_test(argv[1]);
|
||||
else if (!strcmp(argv[1], "route_tables")) route_tables_test();
|
||||
else if (!strcmp(argv[1], "proc_net")) proc_net_test(argc > 2 && strcmp(argv[2], "allowed"), argc > 2 && !strcmp(argv[2], "sealed"));
|
||||
else if (!strcmp(argv[1], "route")) {
|
||||
require(argc >= 3, "route destination");
|
||||
@@ -1218,6 +1259,21 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
"""
|
||||
|
||||
ROUTE_HEADER = "Iface\tDestination\tGateway \tFlags\tRefCnt\tUse\tMetric\tMask\t\tMTU\tWindow\tIRTT\n"
|
||||
ZERO_V6 = "0" * 32
|
||||
|
||||
ANDROID_ROUTE_TABLES = {
|
||||
"route": ROUTE_HEADER + "wlan0\t0001A8C0\t00000000\t0001\t0\t0\t0\t00FFFFFF\t0\t0\t0\n",
|
||||
"ipv6_route": f"fe800000000000000000000000000000 40 {ZERO_V6} 00 {ZERO_V6} 00000100 00000001 00000000 00000001 wlan0\n"
|
||||
f"{ZERO_V6} 00 {ZERO_V6} 00 {ZERO_V6} ffffffff 00000001 00000000 00200200 lo\n",
|
||||
}
|
||||
|
||||
DEFAULT_ROUTE_TABLES = {
|
||||
"route": ANDROID_ROUTE_TABLES["route"] + "wlan0\t00000000\t0101A8C0\t0003\t0\t0\t600\t00000000\t0\t0\t0\n",
|
||||
"ipv6_route": ANDROID_ROUTE_TABLES["ipv6_route"]
|
||||
+ f"{ZERO_V6} 00 {ZERO_V6} 00 fe800000000000000000000000000001 00000400 00000001 00000000 00450003 wlan0\n",
|
||||
}
|
||||
|
||||
SNAPSHOT = """if wlan0 2 1500
|
||||
mac 02:11:22:33:44:55
|
||||
addr 192.168.1.10 24
|
||||
@@ -1257,12 +1313,14 @@ class NetlinkPreloadTest(unittest.TestCase):
|
||||
def tearDownClass(cls):
|
||||
cls.temp.cleanup()
|
||||
|
||||
def run_program(self, mode, *arguments, snapshot=None, denied=None):
|
||||
def run_program(self, mode, *arguments, snapshot=None, denied=None, tables=None):
|
||||
env = dict(os.environ, LD_PRELOAD=f"{self.preload}:{self.shim}",
|
||||
NETLINK_TEST_SNAPSHOT=str(snapshot or self.snapshot),
|
||||
DD_SYSV_DIR=str(self.directory / "sysv"))
|
||||
if denied:
|
||||
env["NETLINK_TEST_DENIED"] = denied
|
||||
if tables:
|
||||
env["NETLINK_TEST_TABLES"] = str(tables)
|
||||
result = subprocess.run([str(self.program), mode, *arguments], env=env,
|
||||
capture_output=True, text=True, timeout=5)
|
||||
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
@@ -1391,6 +1449,25 @@ class NetlinkPreloadTest(unittest.TestCase):
|
||||
def test_readable_socket_tables_stay_real(self):
|
||||
self.run_program("proc_net")
|
||||
|
||||
def route_tables(self, name, contents):
|
||||
directory = self.directory / name
|
||||
directory.mkdir(exist_ok=True)
|
||||
for table, text in contents.items():
|
||||
(directory / table).write_text(text)
|
||||
return directory
|
||||
|
||||
def test_route_tables_without_a_default_route_answer_from_the_link(self):
|
||||
tables = self.route_tables("android-routes", ANDROID_ROUTE_TABLES)
|
||||
self.assertEqual(["link"] * 4, self.run_program("route_tables", tables=tables))
|
||||
|
||||
def test_route_tables_with_a_default_route_stay_real(self):
|
||||
tables = self.route_tables("default-routes", DEFAULT_ROUTE_TABLES)
|
||||
self.assertEqual(["real"] * 4, self.run_program("route_tables", tables=tables))
|
||||
|
||||
def test_route_tables_stay_real_when_the_link_has_no_gateway(self):
|
||||
tables = self.route_tables("android-routes", ANDROID_ROUTE_TABLES)
|
||||
self.assertEqual(["real"] * 4, self.run_program("route_tables", tables=tables, snapshot=self.direct))
|
||||
|
||||
def test_loopback_and_own_addresses_are_local_routes(self):
|
||||
for destination, source in (("127.0.0.2", "127.0.0.1"), ("::1", "::1"),
|
||||
("192.168.1.10", "192.168.1.10"), ("2001:db8::10", "2001:db8::10")):
|
||||
|
||||
Reference in new issue
Block a user