Using a .so file in an android app? How can I access the hardware depth sensor on my (rooted) phone? - Android Q&A, Help & Troubleshooting

I'm building an application that requires the use of the depth sensor on my Samsung Galaxy A80. However it seems like it's impossible to access it through Camera2 and ARCore. I asked Samsung directly and the tech support guys best guess was that Samsung has locked it from being used by third parties.
I rooted my phone and started digging through the file system and eventually found a file called 'com.samsung.sensor.imx316.so' located in /vendor/lib/camera (imx316 is the depth sensor). There are also some similar files that ends in '.bin', but .so files seems to be runnable code if I understood the google results correctly.
That file has the same name as the sensor I can't seem to access. Can this file be used somehow? Can I run it in my own app to get access to the depth data? And if not, there should be a way of getting that data right? I mean, it obviously exists somewhere in the phone since pre-installed apps are using it, and a rooted phone has access to everything?

Did you check REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT? How do you know it's impossible?
Most likely you need to reverse engineer the Camera app from your phone.

Your app can call com.samsung.sensor.imx316.so , it's really "just" a linux elf library.
The problem you face is the exported routines from the library, you won't really know
1) the parameters to the functions inside the library
2) any specific order to call functions inside the library i.e. like an init function first , release memory last...
You need to disassemble / reverse engineer the library to make some sense of it (see ghidra / radare2/ ida pro etc ).
Use strace on the current process/app which uses the library to make some sense of the order of calls into the library.
The depth data will be coming from a kernel level driver, you can likely obtain the Samsung kernel source and the driver source should be there. Then it's up to you whether you can make user space library/code to read what the driver exposes. The kernel driver source code will have an uapi header file to investigate.

idk if it helps but i used for a Huawei P30 Pro this https://github.com/Nufflee/tof-camera

Related

[Q] Finding APK dependencies

Hey devs.
I have a little question. Let's say I have an APK, like the TouchWiz launcher( just an example ). Obviously, if i push it to /system/app on an AOSP ROM, it won't work, because it is missing some dependencies, or my android version is too low.
So, how do I find out which dependencies an APK needs, what android version, etc.
Thanks, Joe.
Please use the Q&A Forum for questions Thanks
Moving to Q&A
That's all listed in the APKs AndroidManifest.XML. I think the minimum Android version is listed as MinSDKVersion or something.
To view an APKs AndroidManifest.XML, use a tool like Root Explorer. If you're using RE, just click on the APK and choose View, then long press on the AndroidManifest and choose the option for viewing it in a text viewer.
- chris
GodSlayer said:
Hey devs.
I have a little question. Let's say I have an APK, like the TouchWiz launcher( just an example ). Obviously, if i push it to /system/app on an AOSP ROM, it won't work, because it is missing some dependencies, or my android version is too low.
So, how do I find out which dependencies an APK needs, what android version, etc.
Thanks, Joe.
Click to expand...
Click to collapse
Google for "APK Analyzer"
Same question here. Root Explorer is not very handy for this task. And I can't find "APK Analyzer". I need a desktop application.
maximilliangreat said:
Same question here. Root Explorer is not very handy for this task. And I can't find "APK Analyzer". I need a desktop application.
Click to expand...
Click to collapse
Apk Analyzer is a windows desktop app from Sony. But its for developers. I find it easier to just read logcat for FC's which will mention a nullpointer or missing function, then do a full text search for said function in the fully decompiled ROM. Takes a while doing that but it always works if you know your way around smali.
Sent from my X10i using Tapatalk 2
Apk Analyzer is a windows desktop app from Sony.
Click to expand...
Click to collapse
Good application, but heavily developer oriented.
I need a much simpler (and faster) tool, to quickly preview required android version, application name and version. Functions used by application are less important to me.
maximilliangreat said:
Good application, but heavily developer oriented.
I need a much simpler (and faster) tool, to quickly preview required android version, application name and version. Functions used by application are less important to me.
Click to expand...
Click to collapse
All this stuff is about the dependencies scanning, for the application name/version/etc stuff see my EDIT: post at the bottom
As far as I know, there is no tool made to do this. The nature of the Java/DalvikVM programming is much like other languages, modular. When the Android OS boots up, it preloads all classes and functions into the dalvik cache and registry, and if a seperate package (APK or JAR) references that function then the system loads it when it needs it. Apart from examining the .java source, there is no "header" or "include" file to see what other packages the package depends on.
Take this example - this is taken from a smali file from deep in the framework.jar for AOSP ROM's:
Code:
invoke-static {}, Landroid/os/SystemClock;->uptimeMillis()J
This is from ./android/net/http/IdleCache.smali. It is requesting to run the "uptimeMillis()J" function from ./android/os/SystemClock, it does not reference which JAR or APK has it. In this case it's the same framework.jar file, but Android has no idea about this because the classes/functions are preloaded in one chunk when the OS boots. Technically, you could remove these SystemClock smali files from framework.jar and put them in a file named "scoobydoo.jar" and the function would still work fine.
What I am saying is, the names of APK's and JAR's are never referenced in the decompiled smali code of an APK - only (sometimes) in the java source. So in the case of reverse engineering i.e. porting apps from one ROM/device to another where building-from-source is not possible, you would need to search every single smali file for invokes, member classes, etc. and then do a full text search for those functions on a fully-decompiled ROM to see where those functions/classes are.
This is why it's easier to just grab the APK you want, dump it into the ROM, and see what happens. Run logcat, run the program, when it FC's then examine the Error or Warnings relating to that package. It will probably mention "nullpointer exception" or "unknown reference" or something, I can't remember the exact message - and also the name of the function, like "Lcom/android/somepackage/somefunction()L" which it couldn't find, which caused the FC. You then would do a full text-search on either all decompiled APK's/JAR's, or on the ones you have a hunch on, and merge that APK/JAR file in too. If the JAR/APK already exists though, then it gets complicated - you need to merge the function into the existing package. Sometimes this is very difficult.
As I said, if you give me an example APK and a Logcat of it crashing, I will help But what you are asking for is a Package Dependency-Walker, which currently doesn't exist for Android. Such a thing would be nice though, as it'd make hacking a kanging much easier - but its useless for android developers because the original source code/project already shows its' dependencies (or, if written properly, has its' dependencies already included in the projects' build tree).
EDIT: Finding the required Android version however is easy. Decompile the APK and open AndroidManifest.xml, near the top you'll see a line like this:
Code:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10" />
Which means it's requires at least Froyo to run, but was targeted at Gingerbread MaintenanceRelease1 (2.3.3-2.3.4). For decoding the API integers, see here.
Application name and version are also in the manifest file. They commonly use values from the string table though (which looks like android:label="@string/app_name"), which means you need to search for that variable in (e.g.) ./res/values-en/strings.xml

Programmatic bluetooth file transfer - security issue?

I need to programmatically transfer some files from one Android device to another via a Bluetooth connection. The devices will have been paired already and in close range. This isn't for something that will be for public consumption. It's for use between two devices under the permanent control of a company for use only within the company. One device (the sending device) will have an app that we'll write that calls for user input. Once the user choices are made and submitted, the sending device will send a file or files (probably text files that we'll create dynamically) to a specific path on the receiving device via that Bluetooth connection.
Both devices will probably be rooted, certainly the receiving device will be. But we'll write to a directory on /sdcard, not at the root level. It's likely that the OS will be 4.1.2 or later on both. It'll be 4.2.2 on the receiving device for sure.
I can execute this file transfer easily with something like ES File Explorer. But that won't work in the application that I'm developing because the users can't handle that sort of interactivity and wouldn't have the knowledge to create or choose the files to transfer if they could. They'll need the aforementioned app with the form to make this appropriately simple.
My question is: can I write an app that lets me transfer files via Bluetooth from one device to a specific path on another, without security issues on the receiving device stopping the transfer from successfully taking place? I'm figuring that if ES File Explorer and the like can do it, that I should be able to do it using the Android API. But I'm not clear on that, so better to ask than to have to tell my client after doing a bunch of work.
Any help would be appreciated.

[Q] hybridizing a Stock ROM to add features, it is possible

Hey everybody,
In my spare time I'm trying to figure out a means to be able to port specific features that one ROM may have that a stock ROM doesn't.
To be more specific, Doug Yeager was able to create additional subclasses for near field communications that allows for smart card emulation (IE contactless payment). This code was officially merged into the Cyangonmod ROM 10.1 and allows users of that ROM to enjoy features similar to Google Wallet without having problems of carrier restrictions that plagues Wallet. When Wallet originally came out it required access to the near field communications secure element as a means to store the card credentials. The problem came where three of the four US carriers (AT&T, T-Mobile and Verizon) would not allow Google to access the secure element (IE would not provide their keys), thereby placing a barrier to near field communications adoption.
The reason why I'm posting this is, in an attempt to allow mobile device users that may not want to use CM 10.1, but rather a rooted stock ROM, I'm trying to find a way to import solely just the new NFC code. Amateur attempts to try and add the code into the framework.jar file has resulted in a frozen boot ( the device uses odex) with an adb logcat denoting missing dependencies everywhere. In addition most of the threads deal with purely porting the ROM itself to various hardware and not porting code between various ROMS.
Is it possible, with the framework as it is, be able to modify it, or is it techinally impossible with a manufacturers alterations upon the the stock Android framework?
Thanks
Joe
=Technical specs=
Samsung Galaxay Rugby Pro (SGH-I547)
OS version 4.1.2
framework-res.apk
(been able to add the code to the apk to show the NFC subclasses)
framework_ext.apk
framework_2.apk
twframework-res.apk
framework-res.odex
(attempts to add the new NFC subclasses results in a frozen boot due to missing class dependencies)
framework_ext.odex
framework_2.odex
twframework-res.odex

Create global content filter for files

Hey guys!
I´m new here and I hope you can help me with some questions... I didn´t know if I´m right here, so please correct me if I do something wrong
My "setup":
- Samsung S3 international with CM13
I like to create a global "Content Filter", which filters files (pictures, videos, documents, etc.) on my smartphone. So what I mean is something like what the UserManager (sorry I can´t poste the Link to Android API) from Android framework does:
User A (owner) creates pictures with the camera, download files, etc. and if User B (guest) logs in, User B can´t access the files from User A and vice versa.
The diffrent part is that I like to "hide" or better make them not accessable by custom criteria - for example "only pictures from the last two hours will be shown to User B". And the main point ist that every application gets the same content.
I thought I have to edit and extend the internal/external storage functions (or ContentProvider?) by my custom filter. Later there will be a system app for controlling the behavior of this filter.
Now there are some question, which I ask myself:
- Is it possible to implement this functionality in Android specific code and not in device specific code? So is it possible to make it portable for other devices and Android versions (Custom ROM, manufacture ROM or the pure Stock Android from Google´s Nexus phones) without "much" effort?
- Does it make more sense to use the original Stock Android instead of Cyanogenmod to reach the portability?
- Where do I have to start? I downloaded the source Code of CM13 for the Samsung S3. But how I ask before - is there a generic way for all devices and android versions? I started to look into the framework specific code of android (system/frameworks/base/... ). I thougth I can build the filter between the api calls (java -> jni bridge -> c/c++), but that would be not the right place, yes?
I hope someone understand my plan and can help me with some informations and tipps or where I have to look to get them!
Thanks!!
Fabian
I think you might mean the profile system that android used to have on ICS?.
Unfortunately I can't answer why they removed that feature. Does the phone not have an option or something if you have 2 or more google accounts registered to the device?..
Beamed in by telepathy.

Root Check Native Library -> Hacked

Dears,
i've successfully managed to modify with Android Studio library "libtool-checker.so" that is currently used by my Bank App to detect root on devices.
If root is detected , app will not start.
This library is an open source project well known as RootBeer and i'm a little worried about my Bank is using an opensource project (without any mod) to ensure my safety and security :angel:
The question is:
My device is on Lollipop 5.0.1 Arm7 processor. Bank App data are stored into:
1 - /data/app/com.bank/base.apk
2- /data/app/com.bank/lib/libtool-checker.so
i'm manually overwriting file 2 with my version and everything works fine.
However after each device reboot, lib file is restored with the original version (extracted from base.apk). I cannot modify lib inside base.apk file because if i change APK signature the app will be installed but will not run (server side check i suppose).
How i can permanently fix this issue?
Thank you very much for your answer.
FransisFor.
Hack signature
You can hack signature first,after you can lib check exchange if you can send hacked files me,please

Categories

Resources