Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisplayAPI #595

Open
ksh-b opened this issue Mar 13, 2023 · 10 comments · May be fixed by #708
Open

DisplayAPI #595

ksh-b opened this issue Mar 13, 2023 · 10 comments · May be fixed by #708

Comments

@ksh-b
Copy link

ksh-b commented Mar 13, 2023

Feature description

API that would provide info about the display like screen size.

Reference implementation

Have you checked if the feature is accessible through the Android API?

https://developer.android.com/reference/android/view/WindowMetrics

Do you know of other open-source apps that has a similar feature as the one you want? (Provide links)

https://bitbucket.org/oF2pks/kaltura-device-info-android/src/master/

Output from the kaltura app:

    "#DISPLAY=": {
        "Built-inScreen_falseHDR": {
            "Name": "Built-in Screen",
            "State": "ON",
            "ro.sf.lcd_density": "300",
            "RefreshRate": 60.000003814697266,
            "ScreenSpecs": "720 x 1280",
            "ViewingMetrics": "DisplayMetrics{density=1.875, width=720, height=1280, scaledDensity=1.875, xdpi=294.967, ydpi=295.563}",
            "AllMetrics": "720 x 1280, largest app 1280 x 1280, smallest app 720 x 720, appVsyncOff 2000000, presDeadline 11666666, mode 1, defaultMode 1, modes [{id=1, width=720, height=1280, fps=60.000004, alternativeRefreshRates=[]}], hdrCapabilities HdrCapabilities{mSupportedHdrTypes=[], mMaxLuminance=500.0, mMaxAverageLuminance=500.0, mMinLuminance=0.0}, userDisabledHdrTypes [], minimalPostProcessingSupported false, rotation 0, state ON}",
            "SupportedHdrTypes": "",
            "SupportedModes": "{id=1, width=720, height=1280, fps=60.000004, alternativeRefreshRates=[]}",
            "Mode": "{id=1, width=720, height=1280, fps=60.000004, alternativeRefreshRates=[]}",
            "RefreshRates21": "60.000004",
            "Cutout": "null"
        }
    }
@Baba01hacker666

This comment was marked as off-topic.

@0m364
Copy link

0m364 commented Jul 16, 2023

you don't need an API....
'''
#!/bin/bash

Get screen resolution

screen_size=$(dumpsys window | grep mUnrestrictedScreen | cut -d'=' -f2 | cut -d' ' -f1)
echo "Screen resolution: ${screen_size}"
'''
name that something . sh and $ bash your name.sh

@0m364
Copy link

0m364 commented Jul 16, 2023

if you want a program here is one in kootlin

'''
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
val height = displayMetrics.heightPixels
val width = displayMetrics.widthPixels
'''

@0m364
Copy link

0m364 commented Jul 16, 2023

get_screen_res.py
'''
import subprocess

def get_screen_resolution():
result = subprocess.run(['dumpsys', 'window'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
lines = result.stdout.splitlines()

for line in lines:
    if 'mUnrestrictedScreen' in line:
        screen_size = line.split('=')[1].split()[0]
        return screen_size

print(f"Screen resolution: {get_screen_resolution()}")
'''

@Rudxain
Copy link

Rudxain commented Jul 17, 2023

@0m364

~ $ dumpsys window
Can't find service: window

Android 12.0

That command requires adb shell, to work on all devices

@0m364
Copy link

0m364 commented Jul 17, 2023

@0m364

~ $ dumpsys window
Can't find service: window

Android 12.0

That command requires adb shell, to work on all devices

you are correct I was working from my rooted device none of my commands work non root I am seeing now.. I will attempt to find a work around but since dumpsys is at a level termux doesn't access without root I'm not seeing a straightforward or easy way to do this... possibly by implementing something with x11 where it tries to determine screen size before providing a gui instead just display the values... I'll play around with it al little bit later... there should be a way to display screen sizes and frame rates

@Rudxain
Copy link

Rudxain commented Jul 17, 2023

dumpsys is at a level termux doesn't access without root

adb can be installed with

pkg i android-tools

but the pairing+connecting process is a big pain. The pairing-port and the connection-port are different, and multi-window must be used for pairing.

possibly by implementing something with x11 where it tries to determine screen size before providing a gui instead just display the values...

That's an interesting approach! I have no idea how to use the x11 API, but I guess it'll work

@Ammar-Husain
Copy link

Ammar-Husain commented Sep 12, 2024

none of the approaches you guys mention does work in non-rooted devices, even dumpsys isn't available without root.
can't this feature be added to the api?

@Rudxain
Copy link

Rudxain commented Sep 13, 2024

none of the approaches you guys mention does work

Which Android version? Perhaps Google hardened the system again.

can't this feature be added to the api?

It's technically possible

@Biswa96 Biswa96 linked a pull request Sep 14, 2024 that will close this issue
@Biswa96
Copy link
Member

Biswa96 commented Sep 14, 2024

I have added a pull request to fix this issue. Would you like to test the packages from GitHub Actions artifacts of that pull request? Link https://github.com/termux/termux-api/actions/runs/10864561131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants