# Environment Preparation

```{note}
This chapter provides documentation for manual deployment, suitable for situations where you need to embed the server into a ROM or manually start the FIRERPA service. If you have already started the server via the APP and have no such requirements, you can skip this chapter.
```

This document introduces the device, system, and network environment preparations required before installing and running FIRERPA. FIRERPA supports a wide variety of device types and architectures. Here, we list common devices and the settings that need to be configured in advance. You can choose the appropriate method according to your actual situation. FIRERPA is divided into a client and a server: the client mainly consists of Python-related libraries and interfaces, while the server is a service running on the target phone. You can install the Python libraries on a computer to control the phone; however, if you need to control the device via Python, you must install and run the Android server on the phone.

## Basic Requirements

The ideal operating environment for FIRERPA is an Android device or emulator with more than 4 GB of RAM and more than 4 GB of available storage. If you do not have a physical Android phone, you can also use the latest versions of NoxPlayer, LDPlayer, or the AVD emulator. To utilize all features of FIRERPA, your device needs root permissions. If the device does not have root permissions, it can still run with adb shell permissions via Developer Mode, but some privileged features will be limited or unavailable.

## System Settings

Typically, your phone also requires the following settings. These are not mandatory, but to ensure success on the first try, we recommend completing these settings if time permits.

### Check Timezone and Time

Open system settings, find Date & Time, and check if it is automatically set to **China Standard Time** or your local timezone, and verify that the time is correct or within an acceptable margin of error. If not, turn off **Use network-provided timezone** and **Network time**, then manually set the timezone and time to the appropriate values for your current location.

### Disable Accessibility Services

Open system settings, find Accessibility (located under System or More settings), and disable or uninstall all applications that use accessibility services (e.g., TalkBack, AutoJS, etc.).

```{note}
Accessibility services may cause conflicts with related functions. Only check this environment setting if you are unable to use FIRERPA's remote desktop or related interfaces normally.
```

## Network Settings

Physical phones, cloud phones, emulators, and other devices have different network conditions. You need to complete the following corresponding settings according to your actual situation; otherwise, you may not be able to access the service normally after installation.

For physical phones, simply ensure that the computer and the phone are on the same network. For emulators, the default created emulator usually does not share the network with the host machine. If you are using an Android-x86 virtual machine based on VMware, set the network mode to bridged in the virtual machine settings. For emulators like LDPlayer and NoxPlayer, you need to install the driver in the instance settings as prompted, enable bridge mode, and restart the system. For Android Studio virtual devices, as they lack relevant settings, to connect to FIRERPA inside the AVD, you need to run `adb forward tcp:65000 tcp:65000` and then connect using `localhost`.

```{note}
For service ports that are forwarded or originally bound to the loopback address, we recommend using `localhost` instead of `127.0.0.1`, because some of our tools (such as the man-in-the-middle packet capture) rely on `localhost` to determine whether the connection is made via USB.
```

## Other Settings

### WSA (Windows Subsystem for Android)

If you are using WSA (Windows Subsystem for Android), ensure that the WSA version is not lower than 2210.40000. Then, open WSA settings -> Subsystem Resources -> select Continuous, turn off Advanced Networking. Next, select Developer, enable Developer mode and expand the tab, check "Support single machine UI automation", and finally restart the WSA subsystem.

### AVD (Android Studio Virtual Device)

If you are using an AVD (Android Studio Virtual Device), first expand the default storage space and memory size.

Click Virtual Device Manager in Android Studio to create a new virtual device. Then find the corresponding device and click the edit button (pencil icon) behind it, click Show Advanced Settings, find Storage -> Internal Storage and set it to at least 2 GB, and set RAM memory size to at least 4 GB.

### Redroid (android in docker)

```{attention}
The following method may not apply to other Linux distributions.
```

If you are using Redroid (android in docker), taking the officially recommended `Ubuntu 20.04` as an example, first install the linux-modules-extra related modules.

```bash
apt install linux-modules-extra-`uname -r`
```

Edit the file `/etc/modules`, copy the following names and insert them at the bottom of the file, then restart the host machine.

```bash
# redroid modules
mac80211_hwsim

binder_linux
ashmem_linux
```

Finally, start using the following command. Adjust `redroid_gpu_mode` and other related parameters according to your actual situation.

```{attention}
Note: The following command differs from the official guide; please be sure to use it as follows.
```

```bash
docker run -itd --rm --privileged --pull always -v /lib/modules:/lib/modules:ro -v ~/redroid:/data -p 127.0.0.1:5555:5555 -p 127.0.0.1:65001:65000 redroid/redroid:12.0.0-latest androidboot.redroid_gpu_mode=guest
```

In the above command, mapping container port 65000 to host port 65001 is because some tools need to temporarily bind to port 65000 on the host. To avoid conflicts, we use port 65001.

```{note}
For the Android redroid container started with the above command, due to port mapping, port 65000 inside the system is mapped to port 65001 on the host. Access it on the host via http://127.0.0.1:65001.
```