
ATV_Script [by cartmenezz_4pda.ru]
==================================

Home page:
https://4pda.to/forum/index.php?showtopic=1035680

System requirements:
* Windows 7/8/8.1/10.11 (x86/x64)
* Microsoft Visual C++ Redistributable 2022 (x86)
  - required for the local network device search function
  - the portable kit is integrated into the script, so most likely installation will not be required
  - if anything, the latest versions are here:
    https://learn.microsoft.com/ru-ru/cpp/windows/latest-supported-vc-redist

About:
This script is a shell for the console utility ADB (Android Debug Bridge).
Compatible with any Android devices that support debugging via ADB.
Initially created to clean Android TV (and Google TV) from "unnecessary" pre-installed applications.
But gradually acquired additional functionality.


Key features:
* Installing APK and Split-APK
* Templates to quickly uninstall the most common pre-installed Android TV apps
* There are additional templates for TCL/iFFALCON, Philips TV, Mi Box, Mi TV Stick, Mi TV
  For example: * Disabling system auto-updates for TCL
               * Deleting recommendations on the apps page for Mi Box / Mi TV Stick
               * Items for removing (with the possibility of recovery) various system applications
* Ability to work with applications in manual mode: Uninstall, Restore, Disable, Enable
* You can enter the package name yourself, or you can get a list from the device and select
* Multi-selection - entering several numbers at once (to select items from the main menu or select packages from the list)
* Selection a text-file with your list of packages
* Search for compatible devices in the local network
* Taking screenshots and recording video from the device screen
* File manager (browsing directories and files on the device, copying files between the device and PC)
* Remote control emulator (navigating the device, inserting text, adjusting the volume)
* Checking the connection with the device before completing the steps - in case of problems, a corresponding message will be displayed
* Informative hints (to help you connect your PC and android device)

Notes:
* You must decide for yourself which of the items you need
* I made the script for myself and added to it what was useful to me and saved me time

==========================================================

Block "MAIN_MENU"
01 Connect        - Connection via IP (search available), via USB, and also a new function "Wireless debugging"
02 Check connect  - Checking the connection status, displaying the device name and android version
03 Uninstall app  - Uninstalling apps (manually entering a package name / or selecting from a list / or loading your own list)
04 Re/install app - Installing apps + and Restoring uninstalled system apps (manually ... / or selecting from a list / or loading your own list)
05 Disable app    - Freeze/Disable apps (manually entering a package name / or selecting from a list / or loading your own list)
06 Enable app     - Unfreeze/Enable apps (manually entering a package name / or selecting from a list / or loading your own list)
07 File manager   - Browse directories, delete or copy files/directories to PC + copy files/directories to device
08 Screen capture - Taking a screenshot and recording a video from the device screen
09 Reboot device  - Restarting the connected device (normal - to the system) 
10 Additional     - Here are the items that did not find a place on the main page

Blocks "TCL/iFFALCON_...", "PHILIPS_...", "XIAOMI_MIBOX/TVSTICK/MITV_..."
* Items with actions for specific devices
  for example: disabling system updates for TCL, deleting recommendations for Mi Box / Mi TV Stick, etc.
* Displayed in the main menu only when the corresponding option is selected on the start page

Block "UNINSTALL_APPS"
* Uninstalling apps with the same name
* And their restoreing (you need to add the letter "z" to the point number, for example "21z")

Input line "ENTER"
* Enter the number of the desired item (or items) here, press Enter to execute
* Items from the block "MAIN_MENU" are performed separately - enter one at a time
* Items from other blocks can be entered as a group (several at once), separated by a space or a comma
  You can also enter a range of dots (separated by dashes, without spaces), for example: 22-25
  You can combine item numbers with ranges, for example: 22 26 28-35 37

==========================================================

First you need to enable "USB debugging" on the android device.

On TVs and TV-boxes the approximate algorithm is as follows:
1. Android settings >> System >> About 
2. Find the "Build" item at the bottom
3. Click on it 7 times until the "You are now a developer" message appears
4. Android Settings >> System >> { } Developer options
5. Find the "USB debugging" item, enable
*  The device may need to be rebooted (but usually not needed)
* The names of some items may differ on different devices

There are many variations on smartphones and tablets:
* It is best to look for instructions for a specific device model
* On modern smartphones/tablets, port 5555 is usually closed
  Therefore, even if you enable "USB debugging", you usually cannot connect by IP, only by cable
  But, starting with Android 11, the "Wireless debugging" item appeared in the Developer options
  This is the same, only it gives a random port for connection, which changes periodically
  This functionality is supported in the script

==========================================================

Using the script with a TV or TV box:

0. Unpack the script from the archive
1. Find out the IP address of the TV:
   a) Android settings >> Network & Internet >> Available networks: find your network, go in, look at IP
   b) Android settings >> Device Preferences >> About >> Status (Network, serialnumbers and other information)
2. Run the script, select the language, select one of the templates
3. Go to the Connection menu (item 01)
4. Connect to the device via IP:
   * Enter the IP address of the device (sub-item 1 or 2)
   * Or you can search for devices in the local network (sub-item 3)
   * In case of any problems, the script will display an error message with recommendations for solving them.
5. When connecting for the first time, the "USB debugging" window will pop up on the TV screen,
   check "Always allow from this computer" and give permission
6. Complete the required items
7. When finished working with the script, "USB debugging" can be disabled
   On some devices, with debugging enabled, the USB connector may not work (does not see drives)

Notes:
* Depending on the device, the names of some settings items may differ
* You can enter several numbers at once (separated by a space or comma), these items will be executed one after the other
  Except for the items from the "MAIN_MENU" block, they require manual manipulations, they need to be performed separately
* At the end, it is recommended to reboot the device - item "09 Reboot device"
  (you can immediately enter it at the end of the list, but it's better to wait a minute after cleaning)
* If channels from deleted apps remain on the Home screen:
  stand on this channel, press "Left" several times until you are to the left of the app icon >> "Remove"
* Or you can go to "Customize channels" before cleaning and turn off everything that is there
* It is very rare to encounter such a problem:
  you remove channels from remote applications, but after a while, or after a reboot, they reappear,
  in this case, you can use the "Completely clear apps channels on the Home screen" method, instructions below

==========================================================

Using the script with a smartphone or tablet:

0. Unpack the script from the archive
1. Run the script, select the language, select one of the templates
2. Go to the Connection menu (item 01)
3. Connect to the device:
   a) via USB cable (sub-item 8):
      - Connect the PC and the device with a cable
      - Follow sub-item 8
      - When connecting for the first time, a request for Debugging permission will pop up on the device screen,
        check "Always allow from this computer" and give permission
      - You may need drivers, you can get them here:
        https://4pda.to/forum/index.php?showtopic=383300
   b) via IP address (sub-item 5 or 7, only for Android 11 and above):
      * For the first time, you need to pair:
        - Android settings >> System (or Advanced settings) >> Developer options
        - Find the item "Wireless debugging", enable
          a window will open "Allow wireless debugging on this network?"
        - Check the item "Always allow on this network" and give permission
        - Find the item "Pair device with pairing code", click
          a window will open in which all the necessary parameters will be: Code, IP Address and Port
        - Enter these parameters in the script (sub-item 5 or 7)
      * Now you can connect:
        - On the "Wireless debugging" page, the IP and Port for connection will be indicated
        - In the script, perform sub-item 4 or 6
4. Complete the required items
5. When finished working with the script, "USB debugging" can be disabled
   On some devices, with debugging enabled, the USB connector may not work (does not see drives)

Notes:
* Depending on the device, the names of some settings items may differ
* You can enter several numbers at once (separated by a space or comma), these items will be executed one after the other
  Except for the items from the "MAIN_MENU" block, they require manual manipulations, they need to be performed separately
* At the end, it is recommended to reboot the device - item "09 Reboot device"
  (you can immediately enter it at the end of the list, but it's better to wait a minute after cleaning)

* Wireless debugging is disabled when Wi-Fi is disconnected, and the debugging port changes periodically
- Therefore, to simplify further use, you can open port 5555 on the device (sub-item 9)
  After that, you can connect by entering only the IP address of the device,
  and you can also use the search for devices in the local network (sub-item 3)
- Both USB debugging and Wireless debugging are suitable for working through port 5555

==========================================================

How to install apps:

1. Connect to device
2. Go to "04 Re/Install apps"
3. If you need to install a full APK, select the 1st sub-item
  * you can select multiple files at once
4. If you need to install a Split APK, select the 2nd sub-item
  * split must be pre-unpacked, select the desired parts

==========================================================

How to uninstall/reinstall/disable/enable an application for which there is no menu item:

1. Connect to device
2. Depending on what we need, select the appropriate item from the "MAIN_MENU" section:
   "03 Uninstall app" / "04 Re/install app" / "05 Disable app" / "06 Enable app"
3. They have sub-items: "enter package name" or "view package list" or "load a package list from text-file"
 * When choosing from the list, you can enter several numbers at once (separated by a space or comma)
   You can enter a range of numbers (separated by dashes, without spaces) for example: 23-28
   You can combine single numbers with ranges, for example: 15 22 35-41 66
   To quickly find package numbers, you can use the search (key combination: Ctrl + F)
 * Enter "package" name - adb doesn't know what "TCL Media Center" is, it needs "com.tcl.ui_mediaCenter"
 * You can find out the application package name like this:
   - Android settings >> Apps >> See All Apps
   - If it is system app >> at the bottom - "Show System Apps"
   - Find the app you need, click "OK" - a tab with info will open, the package name is written at the top

==========================================================

Creating and using your own package list:

1. Create a plain text file (supported extensions: txt, cfg, ini)
2. Enter the names of the packages: one line = one name (no spaces, no punctuation marks, .. nothing more!)
3. You can add lines with comments, for this put ";" at the beginning of the line (only semicolons, no quotes)
   * everything that is written in the line after ";" will be ignored by the script
   * you can also use the characters "#" (pound sign) and "/" (slash)

* The list can be used in items:
  "03 Uninstall app", "04 Reinstall app", "05 Disable app", "06 Enable app"
  to do this, simply select the sub-item "LOAD A PACKAGE LIST FROM TEXT-FILE"
* The function is compatible with presets from the program "ADB AppControl",
  there analog file syntax (vertical list of packages, comment character "#")

==========================================================

Completely clear apps channels on the Androd TV Home screen:

* if it is not possible to remove channels from remote applications (you remove them, but later they reappear)
* this is a very rare problem, the cause is unknown
* this method may not work on some devices
* not tested on Google TV

Method 1:
1. Android Settings >> Apps >> See All Apps >> Show System Apps
2. Find "TV Storage" (package name: com.android.providers.tv), go in
3. Click "Force Stop", click "Clear Data"
4. Find "Android TV Home" (package name: com.google.android.tvlauncher), go in
5. Click "Stop"
* The launcher will restart, all app feeds on the Home screen will disappear
  at first you won't even be able to add them - if you go to "Customize channels", it will be empty there,
  but don't worry, installed apps will be displayed there later, just use as usual
* Instead of steps 4-5, you can reboot the device (perhaps even better):
  - Android Settings >> Device Preferences >> About >> Restart
  - Or in ATV_Script item "09 Reboot device"

Method 2:
1. Run ATV_Script, connect to TV
2. Open the command line for manual command entry - "10 Additional", "1 ADB Terminal"
3. One by one, copy and paste the commands into the console:
adb shell am force-stop com.android.providers.tv
adb shell pm clear com.android.providers.tv
adb reboot
* to paste text into the command line, just press the right mouse button (in Win10 you can use [Ctrl+V])
4. To exit the console, enter: exit (or just close the script window)

==========================================================

File manager (copy/delete files and directories):

* restrictions:
  - Cannot  : see the contents of a directory whose name contains apostrophe symbol (')
  - Cannot  : delete a file/directory whose name contains apostrophe symbol (')
  - You can : copy a file/directory that has apostrophe symbol (') in its name
* In the main menu - item "07 File manager"
* If you need to delete a file/directory on the device - select sub-item "1"
* If you need to copy a file/directory from the device to the PC - also select sub-item "1"
  - To go to the directory, type its number
  - To go back one level up, type "0"
  - The title of the window will display the full path to the current directory/file
  - To delete the current directory/file, type "-", to confirm the action, type "Y" (you can use "y")
  - To copy the current directory/file to the PC (to the Desktop), type "+"
  - Check yourself with the title of the window - all actions will be performed on what is in the title
  - To close the file manager, type "x" or "X"
* If you need to copy a file/directory from a PC to a device - select sub-item "2" or "3"
  - An explorer window will open
  - When copying files, you can select several at once
  - Copying is done to the "Download" directory

==========================================================

Screen Capture (Screenshot and Video Recording):

* In the main menu - item "08 Screen capture"
* Files (screenshot/video) are copied and saved to the PC desktop
* The current date and time are written in the file name (for video recording - start time)
  name format: "Screenshot_YYYYMMDD-hhmmss" and "Screenrecord_YYYYMMDD-hhmmss"
* Due to android limitation, maximum video length = 180 seconds
* Press the any key to force stop recording
* Video recorded with adb has a variable frame rate (if there was no movement on the screen, then the frames are not written)
  - On the one hand, this is a plus (small file size), on the other hand, a minus (not all players play it correctly)
  - Therefore, it is desirable to compress the video with a constant frame rate (30fps)
  - The file size increases, but the "universality" also increases
  - Video compression is done with ffmpeg (preset Fast)
  - You can also choose the option without subsequent compression

==========================================================

 -= DONATE =-

 YooMoney: https://yoomoney.ru/to/410011090804043


