Platform signed OTA updater app for android - java

Trying to build an app for updating android OS built from source. Even after signing the app with the platform key, the method RecoverySystem.installPackage(context,file) when applied on an updatefile placed in '/data/cache' gives error that writing to /cache is not permitted for the app. Also, an SElinux error is thrown for trying to access /cache partition.
The app holds the necessary permissions android.permission.RECOVERY, android.permission.REBOOT and android.permission.ACCESS_CACHE_FILESYSTEM
Going through the source code, the lines
...
FileWriter uncryptFile = new FileWriter(UNCRYPT_PACKAGE_FILE);
try {
uncryptFile.write(filename + "\n");
} finally {
uncryptFile.close();
}
...
in RecoverySystem.installPackage() triggers the error.
(http://androidxref.com/9.0.0_r3/xref/frameworks/base/core/java/android/os/RecoverySystem.java#562)
Even though the error is displayed, the device still reboots to apply update but the recovery shows "no command" screen most probably as no commands are written to /cache/recovery
the OS build is user build and thus not rooted.
am i missing something? is there any other way for a platform signed app to install firmware updates for the user build?
Similar : Android development RecoverySystem.installPackage() cannot write to /cache/recovery/command permission denied

Related

Opening app on macOS 11 Big Sur from JavaFX application randomly fails with kLSNoExecutableErr

We have a desktop JavaFX application (well, TornadoFX) that downloads an archive, extracts another app from it and launches this app with macOS open command.
Simplified kotlin code looks like:
ProcessBuilder(listOf("open", "/path/to/app.app", "arg")).start()
This has worked for years on older versions of macOS (10.15 and earlier) but now with macOS 11 Big Sur launching the app sometimes succeeds and sometimes fails.
In the mac Console.app following error can be seen:
OSStatus _LSCopyApplicationNodeFromOpenState(LSOpenState *): Returning kLSNoExecutableErr because node is a directory but we failed to register with error -10814
We extended the logic to check if all the files are really there before launching the app, and the files existed.
There is an assumption that maybe Launch Services database is not updated fast enough.
Following ways of trying to log what might be happening, didn't reveal any errors:
lsappinfo listen +all forever
log stream --debug --predicate 'subsystem == "com.apple.coreservices.launchservices"'
Does anybody have a clue if there is a way to avoid this behavior and to be always able to launch the app?
After a lot of research and debugging, what seem to have worked for us, was to force Launch Services to register the app in its database by executing command like:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f /path/to/app.app
and afterwards we could launch the app.
The idea for such solution was found in this answer.

What is the location of SQLite db file on the device/emulator after Android API 25?

I have an android project that demonstrates how to write android test cases which can be executed on an emulator or a device. As a result of those test cases, data is populated in the device and the resultant SQLite *.db file can be downloaded from Android Studio's DDMS screen.
NOTE: I have already tried as a root user in adb shell. Problem I am facing in accessing *.db file is consistent from adb and DDMS in emulator with API 26.
Code is accessible here.
I have created 2 emulators (API 23 and API 26) in AVD Manager.
AVD Manager
When I run the androidTest on both the emulators, all the test cases pass successfully.
Using Android Studio's DDMS ...
On the emulator with API 23, I am able to view the SQLite *.db file under /data/data/<package-name>/databases/weather.db and download it to my desktop and view it through http://inloop.github.io/sqlite-viewer/
DDMS
ADB Shell
On the emulator with API 26, the /data folder is empty?? I do not see the same hierarchy for accessing the SQLite *.db file as on device with API 23.
The android app and androidTest both run successfully on emulator with API 26 which means data is saved somewhere in android emulator but what is the new location?
DDMS
ADB Shell
Is it new behavior after API 25/26 and do I need special permissions to access data in DDMS or adb shell?
If this is new behavior then where is the SQLite *.db file located after API 25/26?
I have googled about it on stack overflow and android documentation but didn't find anything concrete, let me know if I have missed anything.
Make sure:
1) You are running adb as root user.
2) Your emulator should have root access.
Link: How to get root access on Android emulator?
#jrg I have been testing to see how to write to the SD CARD and how to find the path to the INTERNAL location of a sqlite db and how to view it with Api 26 or greater. I am not sure this will help and I am curious about rooting an Emulator once rooted can you remove the rooting by deleting the device from the AVD manager
here is some code that might help
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED) && (!state.equals(Environment.MEDIA_MOUNTED_READ_ONLY))) {
File removable = ContextCompat.getExternalFilesDirs(this, null)[1];
THE_PATH = String.valueOf(removable) + "/Documents/";
//System.out.println("ALL TRUE ==> " + THE_PATH);
} else {// if (state.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
THE_PATH = "";
//System.out.println("ALL FALSE ==> "+ THE_PATH);
}
When I eject the SD CARD on the emulator and a real device I use this code to create the path
Context context = this;
String removable = getFilesDir().getAbsolutePath();
THE_PATH = String.valueOf(removable)+"/";
System.out.println("INTERNAL PATH ======> "+THE_PATH);
File file = new File(context.getFilesDir(), "NAME_OF_FILE");
String PA = String.valueOf(file);
System.out.println("Where AM I ======> "+PA);
I do not think Android permits you to navigate to the internal storage without a File Manager application on your device. Have you considered installing a File Manager app on the emulator. Down side to this is I think your need AS 2.4 beta to be permitted to do this

Android Studio, unable to access data folder for database file on emulator

Ok, I have searched and searched without any success for someone with a similar question. I am developing an Android app using Android Studio and have started creating my SQLite database. In order to test my creation and upgrade functions I would like to extract my SQLite database and view it's contents.
Instructions online are fairly clear, open up Android Device Monitor, select the device, go to file explorer, and then browse a few levels deep in the data folder to find your .db file. Here is where the trouble starts. I am unable to expand the root level data folder at all. I have found numerous other questions regarding people having the same problem but they are all due to people trying to do it on un-rooted physical devices. I am simply trying to do it on an emulated device. I am certain it is a permissions problem but I'm not sure how to fix it.
Things I've tried:
Verified that my app is listed as a process on the device selected in the device monitor.
Restarted the AVD, Android Studio, and then my entire machine.
Uninstalled my app and reinstalled.
TLDR; can't access data folder in DDMS for emulated device in order to extract SQLite database file.
Same question to me.
When I want to access /data directory via Android Device Monitor, some error have occurred :
08-21 07:32:36.837: W/ls(3101): type=1400 audit(0.0:50): avc: denied { getattr } for path="/default.prop" dev="rootfs" ino=2941 scontext=u:r:shell:s0 tcontext=u:object_r:rootfs:s0 tclass=file permissive=0
08-21 07:32:37.418: W/PlatformStatsUtil(2507): Could not retrieve Usage & Diagnostics setting. Giving up.
This information tells us we don't have permission to access the directory.
Here are what I have done and works for me.
My OS is Window10
Start your ADV & Open Android Device Monitor
cd to /the/path/to/Android/sdk/platform-tools
Open your cmd or openshell here (shift + right click you will see the option)
execute following commands
.
./adb.exe shell
su
chmod -R 777 /data/data/your/package
Now, enjoy your coding.
Run your app in an emulator with API 23 (or lower).
check detailed information in link below,
Android Device Monitor "data" folder is empty

FFmpeg linker error: Error due to text relocations in libavcodec shared object

I am trying to build an Android app which uses FFmpeg native code for video decoding and encoding. I have a 64-bit machine running 32-bit Ubuntu 14.04, ADT version 23. I downloaded FFmpeg-2.4.4 (32-bit) and built it for Android following the steps mentioned here - http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/
I used latest Android NDK, that is NDK r10c. For testing, I used FFmpeg's API example code given in this link - http://ffmpeg.org/doxygen/trunk/decoding__encoding_8c-source.html
I was able to build all the shared objects successfully and Android project gets compiled successfully without any errors.
Following code is Android code to load all shared objects
public class CallNative {
public static String libName = "decode_encode" ;
public CallNative(){
System.loadLibrary("avutil-54");
System.loadLibrary("swresample-1");
System.loadLibrary("avcodec-56");
System.loadLibrary("avformat-56");
System.loadLibrary("swscale-3");
System.loadLibrary("avfilter-5");
System.loadLibrary(libName);
}
public native int decode(String Filename, int length);
}
And, this is how, decode function is called from Android.
Uri videoURI = Uri.parse(fileUri.toString());
String videoFilePath = getFilePathFromURI(getApplicationContext(), videoURI);
Log.d("SPLASH","Entering native decode call");
CallNative n = new CallNative();
n.decode(videoFilePath, videoFilePath.length());
Log.d("SPLASH","successfully returned from decode call");
When I debugged, App crashes when it enters native function call. I get following linker error.
W/linker(32244): libavcodec-56.so has text relocations. This is wasting memory and prevents security hardening. Please fix.
I tried the same with FFmpeg 2.4.3 and 2.0.6 packages as well. I am getting the same error.
How to resolve this?
The code will work on all android version < 23.
I.e. if you set your targetSkdVersion to 21, the code will run with a warning.
Unfortunately, since Marshmallow (v23), Google no longer allows loading libraries with text relocations. Thus if you set your target sdk version to 23, your app will crash.
Google will not change this behavior, see: https://code.google.com/p/android/issues/detail?id=191235&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
Ffmpeg team won't remove the text relocations "anytime soon", see: https://trac.ffmpeg.org/ticket/4928
So currently it seems your only option is to set your target sdk to 21.

Trouble reading an XML file in Android

I'm trying to parse an XML file thru a DOM parser. However, I am having difficulty in getting my Main Activity to actually read the file. I've read that I should place the file in Assets and then called with getAssets(). I used something like this:
InputStream is = this.getAssets().open("myXML.xml");
This just results in an error: Unexpected error while launching logcat. Try reselecting the device.] device not found.
I've also tried new File("myXML.xml") using variations on the absolute path. Nothing seems to work. I'm getting a little frustrated. Does anyone have any suggestions?
sounds to me, as if your IDE has no connection to the Emulator or device on which you are trying to test your app.
LogCat is a logging output stream that can be used by any app to print out informations /logs. And LogCat needs to be connected (via ADB) to your device.
If you don't have a real phone connected you can use an emulator:
/path/to/your/androidSDK/tools/android
this SDK manager helps you to create a new AVD (Android Virtual Device). Klick Tools>
Manage ACDs> New...
If you have a real phone or tablet connected to your computer, try restarting ADB
(should be possible from within your IDE) or use the command line.
change to the directory where the Android SDK is installed (in windows something like):
c:\Program Files\Android\android-sdk-windows\platform-tools\
on linux it could be:
/opt/android-sdk-linux/platform-tools/
then type (win and linux)
adb kill-server
adb start-server

Categories