2

I am trying to copy a folder to "/data/data//" from "system/app/" folder during build time of aosp.

Using source code of android-marshmallow-6.0.1

LOG: 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at android.os.Looper.loop(Looper.java:148) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5422) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at java.lang.reflect.Method.invoke(Native Method) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at libcore.io.Posix.open(Native Method) 01-01 00:07:13.796 10269-10269/custompackagename.com.customapp W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) 01-01 00:07:13.797 10269-10269/custompackagename.com.customapp W/System.err: at java.io.File.createNewFile(File.java:932) 01-01 00:07:13.797 10269-10269/custompackagename.com.customapp W/System.err: ... 16 more 01-01 00:07:13.797 10269-10269/custompackagename.com.customapp D/CustomApp: copyAsset app_g3_models/en-IN/wordlist.syms 01-01 00:07:13.797 10269-10269/custompackagename.com.customapp D/CustomApp: copyAsset /data/data/com.google.android.googlequicksearchbox/app_g3_models/en-IN/wordlist.syms 01-01 00:07:13.798 10269-10269/custompackagename.com.customapp W/System.err: java.io.IOException: open failed: ENOENT (No such file or directory) 01-01 00:07:13.798 10269-10269/custompackagename.com.customapp W/System.err: at java.io.File.createNewFile(File.java:939) 01-01 00:07:13.798 10269-10269/custompackagename.com.customapp W/System.err: at custompackagename.com.customapp.CustomApp.copyAsset(CustomApp.java:139) 01-01 00:07:13.798 10269-10269/custompackagename.com.customapp W/System.err: at custompackagename.com.customapp.CustomApp.copyAssetFolder(CustomApp.java:116) 01-01 00:07:13.798 10269-10269/custompackagename.com.customapp W/System.err: at custompackagename.com.customapp.CustomApp.copyAssetFolder(CustomApp.java:120) 01-01 00:07:13.798 10269-10269/custompackagename.com.customapp W/System.err: at custompackagename.com.customapp.CustomApp.onCreate(CustomApp.java:81) 01-01 00:07:13.798 10269-10269/custompackagename.com.customapp W/System.err:

  • 2
    Welcome to StackOverflow. Please take the [tour](http://stackoverflow.com/tour) have a look around, and read through the [HELP center](http://stackoverflow.com/help), then read [How to Ask Question](http://stackoverflow.com/help/how-to-ask), [What types of questions should I avoid asking?](http://stackoverflow.com/help/dont-ask) and provide a [MCVE : Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). If people around can easily read and understand what you mean, or what the problem is, they'll be more likely willing to help :) – Dwhitz Mar 07 '18 at 11:11
  • Use [this site](https://android.stackexchange.com) – Jyoti JK Mar 07 '18 at 11:15
  • I didn't find any related link in the site you mentioned – Dhanya Shree Mar 07 '18 at 11:47
  • Try this [answer](https://stackoverflow.com/q/47807052/942015) – Nehaa Saxena Mar 07 '18 at 11:59
  • `during build time of aosp.` What is aosp? And when would that be build? And by whom? – greenapps Mar 07 '18 at 12:03
  • @greenapps Android Open Source Project(aosp), all I mean to say is, I have an android source code cloned from android.googlesource.com/platform/manifest, while I am building the source code, I need folder to get copied as mentioned above. – Dhanya Shree Mar 08 '18 at 06:35
  • It is pretty unclear what you want. You could have done better. But that has already been said. – greenapps Mar 08 '18 at 09:39
  • I cant agree with the comments saying your question is unclear. It's pretty clear what you want. It just misses an example of what you already tried so far. – IIIIIIIIIIIIIIIIIIIIII Mar 08 '18 at 14:45

2 Answers2

0

You can do that with: $(hide) cp -R system/app/folder /data/data/ inside any Android.mk / Makefile. Have a look at buid/core/Makefile

Or check: PRODUCT_COPY_FILES

IIIIIIIIIIIIIIIIIIIIII
  • 3,958
  • 5
  • 45
  • 70
  • Thanks for the response, As u mentioned, I tried adding " $(hide) cp -R system/app/CustomApp/data_folder/ /data/data/CustomPackagename/ " inside Android.mk of CustomApp, but this didn't create data_folder under path /data/data/com.CustomPackagename.CustomApp/ – Dhanya Shree Mar 09 '18 at 07:05
  • you can try to remove the $(hide) to see if the `cp` command fails with some kind of permission error for example. – IIIIIIIIIIIIIIIIIIIIII Mar 09 '18 at 07:38
  • No errors, no warning too.. I tried adding the same line in buid/core/Makefile but this too not helping either. – Dhanya Shree Mar 09 '18 at 09:24
  • Then I guess that its not even called -> check where you added the `cp` and be sure it got called. Also share some code/context or people wont be able to help you – IIIIIIIIIIIIIIIIIIIIII Mar 09 '18 at 10:16
  • yes, u r right, it was not called.Now, its called, I get packages/apps/CustomApp/Android.mk:6: *** missing separator. Stop. Android.mk LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := optional LOCAL_MODULE := CustomApp LOCAL_SRC_FILES := CustomApp.apk $(hide) cp -R $(TARGET_OUT)/app/CustomApp/data_folder/ $(TARGET_OUT_DATA)/data/com.CustomPackagename.CustomApp/data_folder LOCAL_CERTIFICATE := platform LOCAL_MODULE_CLASS := APPS include $(BUILD_PREBUILT) # Use the folloing include to make our test apk. include $(call all-makefiles-under,$(LOCAL_PATH)) – Dhanya Shree Mar 09 '18 at 11:34
  • Oh what about `$(LOCAL_BUILT_MODULE): $(hide) cp -R $(TARGET_OUT)/app/CustomApp/data_folder/ $(TARGET_OUT_DATA)/data/com.CustomPackagename.CustomApp/data_folder` ? – IIIIIIIIIIIIIIIIIIIIII Mar 09 '18 at 11:46
0

Are you sure it's OK to place anything to /data/data folder at build time? Folders /data/data/<package-name> are created at runtime, and if you place anything there, it will be cleared on factory reset.

You probably need (if you really need it) to place data there at bootup, in init.rc scripts. Check how AOSP does it: https://github.com/LineageOS/android_device_xiaomi_mido/tree/cm-14.1/rootdir

You can create your own .sh script and start is as a service (or modify an existing one, for testing, ie init.qcom.sh at the link above) , and copy your data then.

You can check in the script that your app was installed, if not then install it via pm command, then copy data in its data folder, from your folder on system partition.

So at AOSP build time you shall care about the folder on system partition, ie placing data there via PRODUCT_COPY_FILES variable in your device.mk file.

Mixaz
  • 4,068
  • 1
  • 29
  • 55
  • You are right about factory reset.. I want folder to be there always.. Now I will try the solution that you have given and let you know. – Dhanya Shree Mar 12 '18 at 06:15
  • Getting permission error for some of the files while copying from asset folder of a custom app to "/data/data/com.google.android.googlequicksearchbox/app_g3_models/en-US" Added Log to the question tag – Dhanya Shree Mar 27 '18 at 09:28
  • do you try to copy those files from regular app? Yes, it won't work for sure since it's prohibited by android security model, so no apps can copy files each other. If you do not want to modify the target app (to read data from other folder then its own), and can't share storage between them https://stackoverflow.com/a/36302991/1028256 then the simplest solution will probably be to run an init.rc scripts that periodically checks if source and target data exist, and copies it. Care of file permissions then – Mixaz Mar 27 '18 at 15:16