From 3fd508048e0264dbabd247f11d876dc629db7c31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?B=C3=B9i=20Minh=20=C4=90=E1=BB=A9c?=
<93396463+bmndc@users.noreply.github.com>
Date: Thu, 20 Jun 2024 21:31:17 +0700
Subject: [PATCH] webide: Move page from GitHub Wiki
---
webide.md | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 291 insertions(+)
create mode 100644 webide.md
diff --git a/webide.md b/webide.md
new file mode 100644
index 000000000..e321846ee
--- /dev/null
+++ b/webide.md
@@ -0,0 +1,291 @@
+---
+layout: page
+title: "Sideloading and debugging third-party applications"
+---
+As with other KaiOS 2.5.4 devices, the Nokia 6300 4G is classified as debug-enabled; you can install and debug any apps from outside sources as you wish. This comes with a few caveats: you cannot install apps with 'forbidden' permissions (`embed-apps`, `embed-widgets` and `engmode-extension`, such as Wallace Toolbox), or debug apps that come with the phone using DevTools.
+
+Developers, nevertheless, can debug system information and see warnings and errors outside their apps with `adb logcat`.
+
+To turn on debugging mode on the 6300 4G, dial `*#*#33284#*#*`. You should see a bug icon in the status bar letting you know ~~your phone has bugs inside~~ you’re in debugging mode, and you're good to go. You can also switch to ADB and DevTools access under Debugger in [the hidden Developer menu].
+
+Dial the code again to exit debugging mode. *Tip: You can save the code and add it as one of the speed dial contacts.*
+
+Note that sideloading on-device with OmniSD, plus many Gerda apps which require `navigator.mozApps.mgmt.import` API that has been removed from KaiOS 2.5.2.2, will no longer work on this phone. OmniSD's Privileged factory reset feature, however, can be used after permanent rooting to gain privileged userspace session.
+
+## ADB and WebIDE
+
+*Not to be confused with [jailbreaking] on iOS devices, which is the act of using exploits to gain elevated permissions and bypass Apple's security restrictions on their devices.*
+
+Now, let's learn how to sideload and debug an application on your KaiOS phone using ADB and WebIDE. This will let us install apps which might be not available from KaiStore, or ones that you are developing.
+
+ADB, short for Android Debug Bridge, is a powerful toolset that can be used on Android-based devices to unlock access to a range of functions beyond what the typical user interface provides. It's mainly designed for app developers to get access to system logs and debug the performance of their apps, but it's also a great tools for power users and enthusiasts to control their phones through shell access, install third-party APKs, tweak the system and restore it from being a dead paperweight.
+
+While KaiOS and Firefox OS are not directly based on Android and you cannot install APKs on them, their Gonk layer [makes significant use of Android's well-established hardware compatibility], including the ability to use ADB to interact with the phone through a computer. This is for the sake of deploying the OS onto different hardware without raising the cost for development.
+
+Meanwhile, WebIDE, short for Web Integrated Development Environment, allows you to create, edit, run and debug web applications on Firefox OS (and later KaiOS) devices and simulators. It's [built on the former Firefox OS App Manager] but with additional functions such as a code editor, boilerplate code templates and manifest validation, and includes Firefox debugging tools. With it, you can also connect your browser to one or multiple "runtimes" where you can manage app installation.
+
+We'll refer to this guide as the main, officially supported method of installing third-party apps onto your KaiOS phone, for the sake of simplicity. Other methods, such as Luxferre's CLI `gdeploy`, are also available.
+
+> [!NOTE]
+> This guide is only applicable on debug-enabled KaiOS 2.5 devices, and is no longer relevant for recent versions. In 2021, [Mozilla partnered with KaiOS Technologies] to "modernize the old Boot2Gecko codebase to run atop a modern Gecko so that it can be used by KaiOS as a basis for their future phones", and redesigned WebIDE in the process (currently included in Firefox Developer Edition).
+>
+> For debug-enabled KaiOS 3 devices, follow the instructions for KaiOS’s `appscmd` on [the official Developer Portal].
+>
+> Before proceeding, make sure that your phone is debug-enabled, or you have taken steps to enable debugging capability on your phone. To check if your phone is debug-enabled, go to [Devices page on BananaHackers Wiki].
+>
+> **Be careful when installing apps from unknown sources**; it's never a bad practice to proof-read their source code. While there are certain security practices, such as prohibiting installing apps with `engmode-extension` permission, KaiOS is still [prone to] [malicious code] which can result in performance degradation, data loss or worse.
+
+## What we need
+
+- a phone running KaiOS 2.5 (again, KaiOS 3 users should NOT follow this guide);
+- a x86_64 computer running Windows, macOS or Linux;
+ - armhf/aarch64 users may need to use `gdeploy` or [build one of the browsers below from source]
+- an USB cable with data transferring capability;
+- an Internet connection for both your phone and computer;
+- an archiver: built-in file manager on macOS/Linux, [7-Zip] or WinRAR on Windows;
+- latest version of Android Debug Bridge (ADB): [Windows], [macOS], [Linux]
+ - you can also install from your operating system's package manager:
+ - Windows:
+ - [Chocolatey]: `choco install adb`
+ - Scoop: `scoop install main/adb`
+ - `winget` [prohibits installing executables with symlinks]
+ - [macOS (Homebrew)]: `brew install android-platform-tools`
+ - Debian/Ubuntu: `sudo apt-get install adb`
+ - [Fedora]: `sudo dnf install android-tools`
+ - [Arch]/Manjaro: `sudo pacman -S android-tools`
+ - Termux (terminal emulator on Android): `pkg install android-tools`
+ - *tip: If you download the SDK from Android Developers' website, [include the extracted folder in PATH for quick access]. This would be handled for you if you installed ADB via package manager.*
+- Mozilla got rid of the old WebIDE since Firefox 59, so we'll have to install an older version of Firefox:
+ - [Waterfox Classic]: the most recently maintained browser which still has old WebIDE
+ - [Pale Moon 28.6.1](https://archive.palemoon.org/palemoon/28.x/28.6.1/) (Windows/Linux): a popular fork of Firefox with older user interface, legacy Firefox add-on support and always runs in single-process mode.
+ - Firefox 59 (ESR 52.9): the last official Firefox version to be bundled with working WebIDE and other tools for development on Firefox OS devices, before Mozilla decided to kill the project in 2016. Archives of all Firefox releases can be found [here](https://archive.mozilla.org).
+ - [KaiOS RunTime] (Ubuntu): official development environment for KaiOS 2.5 made by KaiOS. It's also possible to get KaiOSRT to work on Windows 10 and later using Windows Subsystem for Linux (WSLg). [See this video on YouTube for action].
+
+*Need a video tutorial? If you’re on Linux, KaiOS Technologies officially made one for their own WebIDE client KaiOSRT which can be found [on their channel]. Alternatively, there’s also [one on BananaHackers’ YouTube channel].*
+
+---
+
+Begin by turning on debugging mode on your phone and connecting your phone to the computer with the USB cable. This step will differ for each device; if you're unsure, it's best to look up your phone on the [Devices page on BananaHackers Wiki].
+
+On your computer, install ADB from the package manager, or download the SDK Platform Tools from Android Developers' website, which should contain the latest version of ADB. Extract the downloaded archive to a folder, then navigate to the `platform-tools` folder using Command Prompt or Terminal.
+
+![](https://raw.githubusercontent.com/bmndc/nokia-leo/docs/assets/images/webide/sdk-download.png)
+
+Start the ADB daemon by typing `adb devices`. ADB will automatically detect your phone in debugging mode. Proceed when you see a `device`, otherwise:
+
+- if the operating system states that `adb` is not a valid command, check if you're in the right folder and/or if `platform-tools` was properly added in PATH. You may need to specify `./adb.exe devices` to tell the OS where to look for ADB, or make ADB an executable: `chmod +x adb`.
+- if ADB executes but nothing appears under "List of devices attached" (as shown below), check if your phone is properly connected to the computer. On Windows, you may need to open Driver Manager (Win + R, `devmgmt.msc`) and look for any USB peripherals with missing drivers, and install accordingly.
+- if you’re connecting to a Linux-based computer, you may need to go to Settings, Storage and turn on USB Storage on the phone for `udev` to properly register your phone as an USB peripheral with external storage. An icon in the status bar will appear indicating storage access via USB. (If you don't wish to do this, see Setting up USB access on Linux below.)
+- on macOS and Linux, `udev` and `lsusb` are your friends to troubleshoot any USB connection issues here
+- if a device appears as `unauthorized`, it means that you need to approve the ADB connection to your phone with a pop-up on your phone's screen. Except... KaiOS does not have such thing! You're pretty much stuck here until someone figures out how to get your phone accessible by ADB.
+
+```console
+$ adb devices
+* daemon not running; starting now at tcp:5037
+* daemon started successfully
+List of devices attached
+1a2b3c4d device
+```
+
+Connect to ADB over Wi-Fi
+
+---
+
+*I was not able to get this to work. Proceed with caution.*
+
+If you are in a rush and wish to connect to your phone wirelessly, turn on Wi-Fi on your phone, set the TCP/IP socket on the phone to 5555:
+
+```console
+$ adb tcpip 5555
+restarting in TCP mode port: 5555
+```
+
+Disconnect the USB cable, wait a moment, then run:
+
+```console
+$ adb connect 192.168.1.14:5555
+connected to 192.168.1.14:5555
+
+$ adb devices
+List of devices attached
+192.168.1.14:5555 device
+
+$ adb forward tcp:6000 localfilesystem:/data/local/debugger-socket
+6000
+```
+
+Replace `192.168.1.14` with your phone's IP address assigned by local network—the same network your computer is on.
+
+You can find your phone's local IP address (192.168.1.x) by going to Settings, Network & Connectivity, Wi-Fi, Available networks, click on the connected Wi-Fi access point and look under IP address; or download N4NO’s [My IP Address] from KaiStore.
+
+It's also possible to connect to your phone entirely without an USB cable, though the connection will be less reliable. See [Connect to ADB wirelessly on Launch hidden settings] page for more details.
+
+---
+
+