Inconsistent access to directories on rooted phone

Mick

I am writing an app that needs to work on a rooted Sony xperia z (Android 4.4.2, build number 10.5.A.0.230). The app reads the core speeds of the four cores by passing one of the following strings...

"/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
"/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq"
"/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq"
"/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq"

...to the function below...

   long sysfilenum(String str)
    {
        String text = null;
        try
        {
             File file = new File(str);

             BufferedReader br = new BufferedReader(new FileReader(file));    
             text = br.readLine();
        }
        catch (IOException e) 
        {
            e.printStackTrace();
        }
        return Long.valueOf(text);
    }

This function gets executed once per second:

This all works perfectly. I display the numbers in my app, and I see that they behave exactly as I would expect. The core speeds are often different to one another, and when the core heats up too much (I read the CPU temperature too) the speeds reduce. So I am confident these numbers are being read correctly.

Now this is where the mystery starts. If I open up an adb shell to my device, then type "su" as my first command. I can navigate to the "/sys/devices/system/cpu/cpu0/cpufreq/" directory without problem. But If I attempt to navigate to the directories for core 1,2 or 3. I get "No such file or directory". I am baffled.

EDIT: I just tested using a terminal emulator which runs on the device itself, and found I could access the directories for all the cores. So its adb shell that is behaving strangely.

EDIT: Just on a hunch I tried su -c "ls cpu1/cpufreq/" and it worked, I saw the cpu1 directory. So maybe typing su in the adb shell didn't give me superuser access?

EDIT: OMG! I just executed su -c "ls cpu1/cpufreq/" over and over again to find that sometimes it worked (i.e. I saw the directory listing) and sometimes it didn't (i.e. I got no such file or directory)!

EDIT:: According to this document, it appears that the directories are virtual. At one point it says says "cd /sys/devices/system/cpu # a virtual directory made visible by device drivers". Hmmm, maybe I have screwed up device drivers?

Jeffrey Mixon

The reason you are seeing the directories disappear is cpu hotplugging. This is the linux kernel feature which allows the OS to disable specific cores on the cpu to save power. The default Android kernel is designed to disable cores 1-3 on nearly all phones when the system load is such that they are not necessary for computations. When these cores are disabled, the corresponding directories are also removed.

Therefore, you can infer that if the directory exists, the core is operating at the specified frequency. If it does not exist, the core is disabled and thus has no frequency.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to run 'adb root' on a rooted Android phone

From Dev

Inconsistent behaviour of package private access level

From Dev

On Rooted phone read /data/data/****/**.db

From Dev

Access and manipulate files and directories on an external USB storage in a rooted Android device

From Dev

Windows Phone check if the phone is Jailbroken or rooted?

From Dev

Copy Files and directories with su command on rooted device

From Dev

Grant users access to directories on partition

From Dev

Select a row by phone number with inconsistent formatting

From Dev

Access append query inconsistent

From Dev

Grant users access to directories on partition

From Dev

Access to different directories

From Dev

How can I use android.permission.SHUTDOWN on a rooted phone?

From Dev

Inconsistent behaviour of package private access level

From Dev

How to solve ADB error [INSTALL_FAILED_UID_CHANGED] on non-rooted phone?

From Dev

On Rooted phone read /data/data/****/**.db

From Dev

How to delete other apps files? (rooted phone)

From Dev

VirtualDocumentRoot with ReWrite to prevent access to directories

From Dev

C# Windows Phone 8.1 Inconsistent Timer Issues with Periodic Timer

From Dev

Windows Phone check if the phone is Jailbroken or rooted?

From Dev

Copy Files and directories with su command on rooted device

From Dev

Removing user access to some directories

From Dev

Access phone data

From Dev

Problem with access in directories

From Dev

How to access element(s) and Remove a spefiic Class rooted within the DOM?

From Dev

Android HummingBad malware - can it install a rootkit on a non-rooted phone?

From Dev

Can a non-rooted phone android user see/edit the data stored in Realm DB?

From Dev

Preventing access to directories on apache server

From Dev

Is it possible in Android (noon rooted) to intercept access to the contact list?

From Dev

Inconsistent gmtime in C when recursively traversing directories

Related Related

  1. 1

    Unable to run 'adb root' on a rooted Android phone

  2. 2

    Inconsistent behaviour of package private access level

  3. 3

    On Rooted phone read /data/data/****/**.db

  4. 4

    Access and manipulate files and directories on an external USB storage in a rooted Android device

  5. 5

    Windows Phone check if the phone is Jailbroken or rooted?

  6. 6

    Copy Files and directories with su command on rooted device

  7. 7

    Grant users access to directories on partition

  8. 8

    Select a row by phone number with inconsistent formatting

  9. 9

    Access append query inconsistent

  10. 10

    Grant users access to directories on partition

  11. 11

    Access to different directories

  12. 12

    How can I use android.permission.SHUTDOWN on a rooted phone?

  13. 13

    Inconsistent behaviour of package private access level

  14. 14

    How to solve ADB error [INSTALL_FAILED_UID_CHANGED] on non-rooted phone?

  15. 15

    On Rooted phone read /data/data/****/**.db

  16. 16

    How to delete other apps files? (rooted phone)

  17. 17

    VirtualDocumentRoot with ReWrite to prevent access to directories

  18. 18

    C# Windows Phone 8.1 Inconsistent Timer Issues with Periodic Timer

  19. 19

    Windows Phone check if the phone is Jailbroken or rooted?

  20. 20

    Copy Files and directories with su command on rooted device

  21. 21

    Removing user access to some directories

  22. 22

    Access phone data

  23. 23

    Problem with access in directories

  24. 24

    How to access element(s) and Remove a spefiic Class rooted within the DOM?

  25. 25

    Android HummingBad malware - can it install a rootkit on a non-rooted phone?

  26. 26

    Can a non-rooted phone android user see/edit the data stored in Realm DB?

  27. 27

    Preventing access to directories on apache server

  28. 28

    Is it possible in Android (noon rooted) to intercept access to the contact list?

  29. 29

    Inconsistent gmtime in C when recursively traversing directories

HotTag

Archive