Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Reading and copying files from "data" folder in rooted phone


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 10 - Last Post: Sep 24, 2014 5:37 AM Last Post By: Petr Hlozek
Jiri Valtr

Posts: 11
Registered: 7/8/05
Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 28, 2013 11:04 AM
Hi all,

I am trying to get one file from exact location from reserved "data" folder (data/data/com.xxx.xxx/.........), but when try to, I got info, that path not exist. But, when I am checking for presence of folder data/data/com.xxx.xxx, it works correctly.
Same error is showed when try to copy existing file form absolute path in data folder. For copying, I am using TFile.Copy(path_to_source_file, path_to_destination).

My phone (Samsung Galaxy Nexus, rooted, Android 4.3). If check file presence by root explorer, it is existing in phone. When try to attempt it by my app, I have "path not exist" error.

Can you help me please, why and how to fix this?

Thanks!
Pavel Alhymov

Posts: 6
Registered: 3/16/07
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 28, 2013 4:00 PM   in response to: Jiri Valtr in response to: Jiri Valtr
Jiri Valtr wrote:
Hi all,

I am trying to get one file from exact location from reserved "data" folder (data/data/com.xxx.xxx/.........), but when try to, I got info, that path not exist. But, when I am checking for presence of folder data/data/com.xxx.xxx, it works correctly.
Same error is showed when try to copy existing file form absolute path in data folder. For copying, I am using TFile.Copy(path_to_source_file, path_to_destination).

My phone (Samsung Galaxy Nexus, rooted, Android 4.3). If check file presence by root explorer, it is existing in phone. When try to attempt it by my app, I have "path not exist" error.

Can you help me please, why and how to fix this?

Thanks!

I can not understand - how you get data path. May be your problem is empty value of TPath.GetSharedDocumentsPath? If you say 'yes', your problem in app permissions. See project's options.
Jiri Valtr

Posts: 11
Registered: 7/8/05
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 28, 2013 4:27 PM   in response to: Pavel Alhymov in response to: Pavel Alhymov
Pavel Alhymov wrote:
Jiri Valtr wrote:
Hi all,

I am trying to get one file from exact location from reserved "data" folder (data/data/com.xxx.xxx/.........), but when try to, I got info, that path not exist. But, when I am checking for presence of folder data/data/com.xxx.xxx, it works correctly.
Same error is showed when try to copy existing file form absolute path in data folder. For copying, I am using TFile.Copy(path_to_source_file, path_to_destination).

My phone (Samsung Galaxy Nexus, rooted, Android 4.3). If check file presence by root explorer, it is existing in phone. When try to attempt it by my app, I have "path not exist" error.

Can you help me please, why and how to fix this?

Thanks!

I can not understand - how you get data path. May be your problem is empty value of TPath.GetSharedDocumentsPath? If you say 'yes', your problem in app permissions. See project's options.

Hello,

as I wrote, I know exact position of file - it is not in shared documents but in data/data/com.name of application.xxx/files....... - I only need to copy this file to Shared Documents (exactly to Download, so I am using TPath.GetSharedDownload, but problem is, when I attempt to TFile.Copy, it tells me, that path is not correct (but I am 100% sure, that path IS correct, I verified it more times). I don't know, if there are some depth limitations (file is in 7 subfolders). Anyway, it looks to me, that even if I have rooted phone, app not have root rights to "touch" the file. When I use File Manager app with enabled root access, I can see the file.
Hope, that now it is clearer.
P.S.: I also added "android.permission.ACCESS_SUPERUSER" to AndroidManifest.xml, but this option not start Super User app to grant root for my application - maybe this is the problem?

Pavel Alhymov

Posts: 6
Registered: 3/16/07
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 29, 2013 12:30 AM   in response to: Jiri Valtr in response to: Jiri Valtr
Jiri Valtr wrote:
Hi all,

I am trying to get one file from exact location from reserved "data" folder (data/data/com.xxx.xxx/.........), but when try to, I got info, that path not exist. But, when I am checking for presence of folder data/data/com.xxx.xxx, it works correctly.
Same error is showed when try to copy existing file form absolute path in data folder. For copying, I am using TFile.Copy(path_to_source_file, path_to_destination).

My phone (Samsung Galaxy Nexus, rooted, Android 4.3). If check file presence by root explorer, it is existing in phone. When try to attempt it by my app, I have "path not exist" error.

Can you help me please, why and how to fix this?

Thanks!
What a path is not exists - source or destination? May be you are using wrong root for you path? See my code below - it works very good:
initialization
  {$ifdef Android}
  ConfigFile := TPath.GetSharedDocumentsPath;
  ConfigFile := ConfigFile.Substring( 0, ConfigFile.IndexOf( '/Android/' ) ) + '/WhoIsWho/WhoIsWho.Config';
  if not TFile.Exists( ConfigFile ) then begin
    ForceDirectories( TPath.GetDirectoryName(ConfigFile ) );
    TFile.Copy( TPath.GetDocumentsPath + '/WhoIsWho.Config', ConfigFile );
  end;
  {$else}
  ConfigFile :=
    TPath.GetDocumentsPath + PathDelim +
    'WhoIsWho.Config';
  {$endif}

Take attention to key moments: GetDocumentsPath for source and GetSharedDocumentsPath.IndexOf( '/Android/' ) for destination.

Edited by: Pavel Alhymov on Dec 29, 2013 12:31 AM
Jiri Valtr

Posts: 11
Registered: 7/8/05
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 29, 2013 12:33 AM   in response to: Pavel Alhymov in response to: Pavel Alhymov
Pavel Alhymov wrote:
Jiri Valtr wrote:
Hi all,

I am trying to get one file from exact location from reserved "data" folder (data/data/com.xxx.xxx/.........), but when try to, I got info, that path not exist. But, when I am checking for presence of folder data/data/com.xxx.xxx, it works correctly.
Same error is showed when try to copy existing file form absolute path in data folder. For copying, I am using TFile.Copy(path_to_source_file, path_to_destination).

My phone (Samsung Galaxy Nexus, rooted, Android 4.3). If check file presence by root explorer, it is existing in phone. When try to attempt it by my app, I have "path not exist" error.

Can you help me please, why and how to fix this?

Thanks!
What a path is not exists - source or destination? May be you are using wrong root for you path? See my code below - it works very good:
initialization
  {$ifdef Android}
  ConfigFile := TPath.GetSharedDocumentsPath;
  ConfigFile := ConfigFile.Substring( 0, ConfigFile.IndexOf( '/Android/' ) ) + '/WhoIsWho/WhoIsWho.Config';
  if not TFile.Exists( ConfigFile ) then begin
    ForceDirectories( TPath.GetDirectoryName(ConfigFile ) );
    TFile.Copy( TPath.GetDocumentsPath + '/WhoIsWho.Config', ConfigFile );
  end;
  {$else}
  ConfigFile :=
    TPath.GetDocumentsPath + PathDelim +
    'WhoIsWho.Config';
  {$endif}

Hi,

non-existing path is source path (data/data/com.xxx.xxx........), althrough path and file in that path is existing. Just for clear, I need to work with "data" folder, which is not accessible for non-rooted phones and must have SU access...
Jiri Valtr

Posts: 11
Registered: 7/8/05
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 29, 2013 5:02 AM   in response to: Jiri Valtr in response to: Jiri Valtr
So, after some searching, I found, that I need to set my app to behave as it want to request superuser privilegs before attampting to data folder in rooted phone. So, I found java command to do this "Process myprocess = Runtime.getRuntime().exec("su");".
But as it is Java command, I don't know, how to implement to Delphi code.
I am not sure, if it solves the problem, but I need to give a try...

Anybody able to help?
Jiri Valtr

Posts: 11
Registered: 7/8/05
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 30, 2013 11:30 AM   in response to: Jiri Valtr in response to: Jiri Valtr
Just want to ask you all, if anybody knows the solution...
Thanks a lot!
Jiri Valtr

Posts: 11
Registered: 7/8/05
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 20, 2014 1:45 PM   in response to: Jiri Valtr in response to: Jiri Valtr
Just refreshing the topic in case somebody know, how to run my app so it asks for SU installed in rooted phone to grant SU access??

Thanks!


Jiri Valtr wrote:
Just want to ask you all, if anybody knows the solution...
Thanks a lot!
Petr Hlozek

Posts: 5
Registered: 11/4/10
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 27, 2014 2:11 AM   in response to: Jiri Valtr in response to: Jiri Valtr
Hi,

maybe you could use TProcess. This code executes "su" command. Maybe you could run the command like "su cp from to". The "su" or "sudo" commands are used on Linux systems to raide the privilege.

Petr

Jiri Valtr wrote:
Just refreshing the topic in case somebody know, how to run my app so it asks for SU installed in rooted phone to grant SU access??

Thanks!
Jiri Valtr

Posts: 11
Registered: 7/8/05
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 11, 2014 11:07 AM   in response to: Petr Hlozek in response to: Petr Hlozek
Hi Petr,

can you be pleasde more detailed? This is my first Delphi To Android attempt and I am not so sure with that.. If you tell me more in detail, I will send you virtual beer.... :)

Thank you,
Jirka

Petr Hlozek wrote:
Hi,

maybe you could use TProcess. This code executes "su" command. Maybe you could run the command like "su cp from to". The "su" or "sudo" commands are used on Linux systems to raide the privilege.

Petr

Jiri Valtr wrote:
Just refreshing the topic in case somebody know, how to run my app so it asks for SU installed in rooted phone to grant SU access??

Thanks!
Petr Hlozek

Posts: 5
Registered: 11/4/10
Re: Reading and copying files from "data" folder in rooted phone  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2014 5:37 AM   in response to: Jiri Valtr in response to: Jiri Valtr
Ahoj Jirko,

I'm sorry, I'm not so keen in rooted phones. According to example you've posted here, it seems that Java just runs whole sudo to switch to superuser mode.
It could be something like this:

tp := TProcess.Create;

tp.CmdLine := 'su';
tp.Exec;

tp.CmdLine := 'this command will be with root rights';
tp.Exec;

But I just checked the Delphi and it seems there is no TProcess in Android Delphi code :(. Maybe there is something different.

Petr

Jiri Valtr wrote:
Hi Petr,

can you be pleasde more detailed? This is my first Delphi To Android attempt and I am not so sure with that.. If you tell me more in detail, I will send you virtual beer.... :)

Thank you,
Jirka

Petr Hlozek wrote:
Hi,

maybe you could use TProcess. This code executes "su" command. Maybe you could run the command like "su cp from to". The "su" or "sudo" commands are used on Linux systems to raide the privilege.

Petr

Jiri Valtr wrote:
Just refreshing the topic in case somebody know, how to run my app so it asks for SU installed in rooted phone to grant SU access??

Thanks!
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02