Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Redmi K20 Pro] Front cam pops up on first boot and won't retract #539

Open
AndyCGYan opened this issue Jun 1, 2019 · 49 comments
Open

[Redmi K20 Pro] Front cam pops up on first boot and won't retract #539

AndyCGYan opened this issue Jun 1, 2019 · 49 comments

Comments

@AndyCGYan
Copy link
Collaborator

AndyCGYan commented Jun 1, 2019

Device: Redmi K20 Pro (raphael)
Treble status: Yes, A/B, native
Stock Android version: 9 - stock fastboot ROM here

This device has a pop-up front camera, and I was worried about how it'd work before I got the device. That suspicion turned out to be true, but in an unexpected way - on first boot of the GSI, the front cam motor enables and pops the cam out on its own, and refuses to retract afterwards. This makes the phone unsafe to carry around as a daily driver.

For anyone curious about this device: most other basic functions (except auto brightness, which I don't use) seems to work alright as far as I tested - even in-display FP seems to work out-of-the-box (I still have the factory protection film on so can't test how accurate). Likely is because this device is quite similar to Mi 9 (flashing procedure also nearly the same). Just this front cam issue solved and I can have it as my new primary device.

If you need any logs or dumps, or maybe need info on other aspects of the device, I'll gladly provide them when I can.

@AndyCGYan
Copy link
Collaborator Author

Log excerpt from under MIUI, switching to and out of front camera for 3 times. The log is filled with a ton of other error messages, but there are keywords like "PopupCameraManagerService" and "motor_impl" which might be of interest.
log.txt

@phhusson
Copy link
Owner

phhusson commented Jun 2, 2019 via email

@AndyCGYan
Copy link
Collaborator Author

AndyCGYan commented Jun 2, 2019

  1. Kernel sources not available yet.
  2. Requested console output:
raphael:/ # grep -r -e PopupCameraManagerService -e motor_impl /system 2>/dev/null
Binary file /system/framework/oat/arm64/services.vdex matches
Binary file /system/app/Cit/oat/arm64/Cit.vdex matches
Binary file /system/vendor/lib64/hw/vendor.xiaomi.hardware.motor@1.0-impl.so matches
Binary file /system/vendor/bin/hw/vendor.xiaomi.hardware.motor@1.0-service matches
Binary file /system/vendor/lib/hw/vendor.xiaomi.hardware.motor@1.0-impl.so matches
  1. Full system+vendor dump here

Have you got the kernel sources? Please grep for motor_impl and PopupCameraManagerService in /system: grep -r -e PopupCameraManagerService -e motor_impl /system And paste the result here If there are some files that matches in /system/framework, please attach the whole /system/framework here Le dim. 2 juin 2019 à 02:08, Andy Yan notifications@github.com a écrit :

Log excerpt from under MIUI, switching to and out of front camera for 3 times. The log is filled with a ton of other error messages, but there are keywords like "PopupCameraManagerService" and "motor_impl" which might be of interest. log.txt https://github.com/phhusson/treble_experimentations/files/3244314/log.txt — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#539?email_source=notifications&email_token=AAAA4OTPWY2PWN7QRCRQPWLPYMFOZA5CNFSM4HSA47L2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWXK4QQ#issuecomment-497987138>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAA4OUBTF5IEUYOIQ6WES3PYMFOZANCNFSM4HSA47LQ .

@AndyCGYan
Copy link
Collaborator Author

In the meantime, since I don't care that much about a working front cam, is it possible to forcefully disable it somehow, so the OS doesn't even try to initialize it (which I guess causes it to pop up)? I tried deleting /vendor/etc/permissions/android.hardware.camera.front.xml but that's not enough to make the OS think there's no front cam.

@phhusson
Copy link
Owner

phhusson commented Jun 2, 2019

Ok cool, sounds like we just need to reverse engineer vendor.xiaomi.hardware.motor from services.vdex.

I dont really know how you'd disable that though. Reversing the HAL sounds easier. Hopefully I'll have time to do that today or tomorrow

On stock ROM does camera pop at boot and then hide, or it never pops until camera starts?

@AndyCGYan
Copy link
Collaborator Author

Ok cool, sounds like we just need to reverse engineer vendor.xiaomi.hardware.motor from services.vdex.

Maybe too early to ask, but will the motor be triggered on calling front cam, or a separate app that summons the cam beforehand and hides it after? Personally I'm okay with both, front cam only gets used maybe weekly.

I dont really know how you'd disable that though. Reversing the HAL sounds easier. Hopefully I'll have time to do that today or tomorrow

You da man... Thanks!

On stock ROM does camera pop at boot and then hide, or it never pops until camera starts?

It never pops. Also, if for some reason the camera is already out (e.g. after flashing and booting the GSI), then at the end of the bootanimation it will be automatically retracted.

@AndyCGYan
Copy link
Collaborator Author

Oh yeah, forgot to mention that the regular K20 (davinci - not on the market yet) has the same pop-up mechanism, please add it into the device filter as well when you're ready to commit.

@phhusson
Copy link
Owner

phhusson commented Jun 2, 2019

Here is the reverse-engineered hal:

types.hal

package vendor.xiaomi.hardware.motor@1.0;

struct MotorEvent {
        int32_t vaalue;
        int32_t cookie;
};

IMotor.hal

package vendor.xiaomi.hardware.motor@1.0;

interface IMotor {
        popupMotor(int32_t cookie);
        takebackMotor(int32_t cookie);
        setMotorCallback(IMotorCallback motorcallback);
        init();
        release();
        getMotorStatus() generates (int32_t result);
        calibration();
        takebackMotorShortly();
};

IMotorCallback.hal

package vendor.xiaomi.hardware.motor@1.0;

interface IMotorCallback {
        oneway onNotify(MotorEvent event);
};

@AndyCGYan
Copy link
Collaborator Author

AndyCGYan commented Jun 2, 2019

Here is the reverse-engineered hal:

Can I test it out on my side? I assume this goes somewhere into vendor/interfaces? Sorry, not familiar with actual hardware stuff...

EDIT: Gonna read how other HALs were added and do it similarly, hope it works...

@phhusson
Copy link
Owner

phhusson commented Jun 2, 2019 via email

@AndyCGYan
Copy link
Collaborator Author

I recommend you to wait, but if you want to try it yourself, you need a "phh" AOSP tree, put the files I've mentioned in it a vendor/interfaces (it's Java like tree with folders matching package name), call hidl-gen -L androidbp on it, then do a little program to call that HAL, you can see samples in device/phh/treble/cmds/

Well seems I'm the only guy who's after running GSI on this device right now, so of course I'll have to test somehow. Are you going to make a separate fork which I can sync from?
But yeah, I just tried putting in just the vendor/interfaces files (btw, you forgot to import the callback in IMotor.hal) and generating bp, without calling it (I thought it was unnecessary), and yeah it didn't make a difference. I have no idea how to write the "calling" cmd though, so yeah for now I'll wait on you.

@AndyCGYan
Copy link
Collaborator Author

So uh, I got impatient, and after looking up some stuff and reading your codes, I wrote this:

#include <iostream>
#include <unistd.h>
#include <vendor/xiaomi/hardware/motor/1.0/IMotor.h>

using ::vendor::xiaomi::hardware::motor::V1_0::IMotor;
using ::vendor::xiaomi::hardware::motor::V1_0::IMotorCallback;
using ::vendor::xiaomi::hardware::motor::V1_0::MotorEvent;
using ::android::sp;
using ::android::hardware::Return;
using ::android::hardware::Void;

class MotorCallback: public IMotorCallback {
public:
	MotorCallback() {}
	~MotorCallback() {}
	Return<void> onNotify(const MotorEvent& event) {
		return Void();
	}
};

int main(int argc, char **argv) {
	auto svc = IMotor::getService();
	if(svc == nullptr) {
		std::cerr << "Failed getting IMotor" << std::endl;
		return -1;
	}
	if(argc != 2) {
		fprintf(stderr, "Usage: %s <POPUP|TAKEBACK|SETCALLBACK|INIT|RELEASE>\n", argv[0]);
		return -2;
	}
	sp<MotorCallback> motorcallback = new MotorCallback();
	std::string action(argv[1]);
	if(action == "POPUP")
		svc->popupMotor(1);
	if(action == "TAKEBACK")
		svc->takebackMotor(1);
	if(action == "SETCALLBACK")
		svc->setMotorCallback(motorcallback);
	if(action == "INIT")
		svc->init();
	if(action == "RELEASE")
		svc->release();
}

The binary was built just fine, but when I called it in adb shell, it simply returns "Failed getting IMotor", meaning I don't even get to test how it works...

@phhusson
Copy link
Owner

phhusson commented Jun 3, 2019

Helper pushed in phhusson/device_phh_treble@819cbe3
Interface pushed in phhusson/vendor_interfaces@be5b914

Here are prebuilts:
https://treble.phh.me/vendor.xiaomi.hardware.motor@1.0.so
https://treble.phh.me/xiaomi-motor

Now, push those two files in /data/local/tmp, then in adb do:
LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/xiaomi-motor "command"

where command can be:

  • init
  • release
  • takebackShortly
  • popup 42
  • takeback 42

the "42" here are placeholders for integers. I don't know the meaning of those integers (it's called cookie in Xiaomi HAL), but my guess is that you're supposed to use incrementing value at every command.

So please test those various commands and answer what happens when doing what.

@AndyCGYan
Copy link
Collaborator Author

AndyCGYan commented Jun 3, 2019

So please test those various commands and answer what happens when doing what.

Liked that "42" there :D

As for the test result:

  • popup makes it pop up, both takeback and takebackShortly makes it retract immediately
  • Above commands would still try to execute the action even when the cam is already out/retracted, causing the motor to make a strange buzzing sound - should limit this somehow to prevent mechanical damage
  • Cookie value doesn't seem to affect behaviour at all
  • init and release does nothing - the above actions can be done even before init and after release

Looking great so far!

P.S. I've already created a Wiki page for this device, will submit some other not-so-glaring issues as well while I have your attention.

@phhusson
Copy link
Owner

phhusson commented Jun 3, 2019

I don't really understand why the attempt you pasted here didn't work (sorry i missed it when i wrote mine -_-')

Ok it's good news it works.
The double takeback issue will be annoying... As for takeback vs takebackShortly, i still won't use the later one :P

My guess for init is that if we call init before framework is ready, then the camera won't popup on boot.
You can try to call xiaomi-motor init from some system/etc/init/xxx.rc

I guess next step is to integrate that into cameraservice. Or we could have an intermediate version where it's crudely integrated into treble app.

@AndyCGYan
Copy link
Collaborator Author

Ok it's good news it works.
The double takeback issue will be annoying...
...
I guess next step is to integrate that into cameraservice. Or we could have an intermediate version where it's crudely integrated into treble app.

Hope you could sort out the former solution (it should pop-up/retract automatically then, right?), and also take care of the double action issue in the process.
Also, I noticed that I can pair xiaomi-motor with the existing vendor.xiaomi.hardware.motor@1.0.so under /vendor/lib64: LD_LIBRARY_PATH=/vendor/lib64 xiaomi-motor "command". This should make for a crude but immediately usable intermediate solution for me - just drop xiaomi-motor into /system/bin and the cam can be controlled with a one-liner.

My guess for init is that if we call init before framework is ready, then the camera won't popup on boot.
You can try to call xiaomi-motor init from some system/etc/init/xxx.rc

When writing the rc, what group should I assign vendor.xiaomi.hardware.motor to, and in which section (on boot?) should I trigger init? rc confuses me even more than writing the helper @_@

@phhusson
Copy link
Owner

phhusson commented Jun 3, 2019

I guess next step is to integrate that into cameraservice. Or we could have an intermediate version where it's crudely integrated into treble app.

Hope you could sort out the former solution (it should pop-up/retract automatically then, right?), and also take care of the double action issue in the process.

Well it's possible to have popup/retract automatically in both cases. cameraservice is less flexible but most likely more stable. treble_app would probably do it on camera app launch though

Also, I noticed that I can pair xiaomi-motor with the existing vendor.xiaomi.hardware.motor@1.0.so under /vendor/lib64: LD_LIBRARY_PATH=/vendor/lib64 xiaomi-motor "command". This should make for a crude but immediately usable intermediate solution for me - just drop xiaomi-motor into /system/bin and the cam can be controlled with a one-liner.

You should rather push the vendor.xiaomi.hardware.motor@1.0.so i've provided to system/lib64
if you do that simply xiaomi-motor will work
(this is what will happen in my release)

My guess for init is that if we call init before framework is ready, then the camera won't popup on boot.
You can try to call xiaomi-motor init from some system/etc/init/xxx.rc

When writing the rc, what group should I assign vendor.xiaomi.hardware.motor to, and in which section (on boot?) should I trigger init? rc confuses me even more than writing the helper @_@

no group, leave default ( = root)
you'll need to set selinux label to u:r:phhsu_daemon:s0 (I think keyword for that is seclabel)
declare it as a oneshot service, with class main. I think "class main" is the right time for that. If not, try other classes.

@AndyCGYan
Copy link
Collaborator Author

Well it's possible to have popup/retract automatically in both cases. cameraservice is less flexible but most likely more stable. treble_app would probably do it on camera app launch though

Good to know, either is good enough for me then.

You should rather push the vendor.xiaomi.hardware.motor@1.0.so i've provided to system/lib64
if you do that simply xiaomi-motor will work
(this is what will happen in my release)

Yeah I made a build with your latest commits, and now the /system lib works as well. For now I've paired it with the app "Terminal Shortcut" that can execute the command for me one-tap (well, 2-tap).
Also I realized that the reason that my prior try at writing the helper seems to fail is simply because I forgot to su before executing the command... Derp.

no group, leave default ( = root)
you'll need to set selinux label to u:r:phhsu_daemon:s0 (I think keyword for that is seclabel)
declare it as a oneshot service, with class main. I think "class main" is the right time for that. If not, try other classes.

I wrote this /system/etc/init/vendor.xiaomi.hardware.motor@1.0-service.rc:

service motor-hal-1-0 /vendor/bin/hw/vendor.xiaomi.hardware.motor@1.0-service
    class core
    user system
    seclabel u:r:phhsu_daemon:s0
    oneshot

on boot
    xiaomi-motor init

...which doesn't work (I tried both class main and class core). Maybe there's still some errors within what I wrote?

@penn5
Copy link

penn5 commented Jun 3, 2019

When the device is in offline charging does the camera pop up?

@penn5
Copy link

penn5 commented Jun 3, 2019

I wrote this /system/etc/init/vendor.xiaomi.hardware.motor@1.0-service.rc:

service motor-hal-1-0 /vendor/bin/hw/vendor.xiaomi.hardware.motor@1.0-service
    class core
    user system
    seclabel u:r:phhsu_daemon:s0
    oneshot

on boot
    xiaomi-motor init

...which doesn't work (I tried both class main and class core). Maybe there's still some errors within what I wrote?

You're missing the LD_LIBRARY_PATH
Try using sh -c as the service setting
Where command includes LD settings i.e. is the one you run in terminal
And if it's in a class, no need to start on boot.

@phhusson
Copy link
Owner

phhusson commented Jun 3, 2019

service xiaomi-motor-init /system/bin/xiaomi-motor init
    class main
    seclabel u:r:phhsu_daemon:s0
    oneshot

on boot
    start xiaomi-motor-start

@AndyCGYan
Copy link
Collaborator Author

AndyCGYan commented Jun 3, 2019

When the device is in offline charging does the camera pop up?

The device doesn't offline charge - it flashes a weird cyan-colored screen. But yeah, in that case it doesn't pop up.

You're missing the LD_LIBRARY_PATH
Try using sh -c as the service setting
Where command includes LD settings i.e. is the one you run in terminal
And if it's in a class, no need to start on boot.

I tried with both LD_LIBRARY_PATH present and absent...

service xiaomi-motor-init /system/bin/xiaomi-motor init
    class main
    seclabel u:r:phhsu_daemon:s0
    oneshot

on boot
    start xiaomi-motor-start

Doesn't work...
I should mention that the front cam pops up really early - right before the "Redmi" logo disappears and bootanimation comes up.

@phhusson
Copy link
Owner

phhusson commented Jun 3, 2019 via email

@AndyCGYan
Copy link
Collaborator Author

Oh ok. Sounds like it's the kernel or even the bootloader that decides to do that. There isn't much we can do. Just call take back instead of init then

I thought of this as well, but then how come MIUI doesn't pop it up...? Kinda confused there.
Also, changing init to takeback <value> doesn't work either, so it seems the script just wasn't ran at all. To reiterate, I have the script as /system/etc/init/vendor.xiaomi.hardware.motor@1.0-service.rc and set proper permissions. Anything I'm missing?

@phhusson
Copy link
Owner

phhusson commented Jun 3, 2019

K, first thing to try is remove the on boot and the line after it

Then, if it still doesn't work, please provide kernel logs (dmesg)

@AndyCGYan
Copy link
Collaborator Author

AndyCGYan commented Jun 3, 2019

K, first thing to try is remove the on boot and the line after it

Then, if it still doesn't work, please provide kernel logs (dmesg)

Yeah, still nada. dmesg (60 secs long - should be enough) here.
Seems the "drv8846" keyword is particularly interesting - DRV8846 is a stepper motor driver.
Should I also get dmesg on MIUI as comparison?

@penn5
Copy link

penn5 commented Jun 4, 2019

At what bootstage does the camera pop up? Right as the boot anim begins? Or just as the lockscreen shows? Or before the boot animation?

@AndyCGYan
Copy link
Collaborator Author

At what bootstage does the camera pop up? Right as the boot anim begins? Or just as the lockscreen shows? Or before the boot animation?

As said earlier...

I should mention that the front cam pops up really early - right before the "Redmi" logo disappears and bootanimation comes up.

@penn5
Copy link

penn5 commented Jun 4, 2019

oh damn that makes very little sense.
perhaps you could remove the motor hal from /vendor (take backup!!!) and see if it still happens
or use xiaomi-motor to takeback cam then run stop; start

@AndyCGYan
Copy link
Collaborator Author

oh damn that makes very little sense.
perhaps you could remove the motor hal from /vendor (take backup!!!) and see if it still happens
or use xiaomi-motor to takeback cam then run stop; start

Camera doesn't pop up after a hot reboot from stop; start.
I then killed /vendor/lib*/(hw/)vendor.xiaomi.hardware.motor*.so and rebooted, and the camera doesn't pop up either.

@penn5
Copy link

penn5 commented Jun 5, 2019

That's really weird. I guess the kernel has some kind of state machine that the HAL reads to decide whether to pop up?

@AndyCGYan
Copy link
Collaborator Author

That's really weird. I guess the kernel has some kind of state machine that the HAL reads to decide whether to pop up?

Probably. At this point I guess we'd have to wait for the international release of this device, so that the kernel source can be made available.
Still, I don't really mind it popping up once on boot; connecting it to cameraserver is the main deal.
For now I'll live with manual control - I'll set up the device as daily driver in a few hours and wait for progress.

@AndyCGYan
Copy link
Collaborator Author

@phhusson Is it considered OK if I make a pull request to device_phh_treble that enables building xiaomi_motor, given that it's ultimately a debug command? I'm thinking about pushing the audio fix along with this as well.

@phhusson
Copy link
Owner

phhusson commented Jun 6, 2019 via email

abun880007 pushed a commit to Team-UB/device_phh_treble that referenced this issue Jun 6, 2019
Serves as a manual/intermediate solution to phhusson/treble_experimentations#539

Change-Id: Ia334f7d106b121014c791b0edb06b59a0eef3580
@AndyCGYan
Copy link
Collaborator Author

@phhusson Somewhat off-topic, but where can I ask you about something that probably doesn't qualify as an issue here?

@AndyCGYan
Copy link
Collaborator Author

Kernel source just dropped: https://github.com/MiCode/Xiaomi_Kernel_OpenSource/tree/raphael-p-oss - hopefully something helpful inside.

@whitechampaca
Copy link

I also had the same error. Can you show me how to fix it most easily? Thanks for the help.

@YadominJinta
Copy link

Can't tackback after I run ./xiaomi-motor tackbackShortly 1

@YadominJinta
Copy link

It works again after I reboot several times, and I notice ./xiaomi-motor doesn't need a root access(I use it in termux) ,which is not the same as wiki mentioned.

@AndyCGYan
Copy link
Collaborator Author

I notice ./xiaomi-motor doesn't need a root access(I use it in termux) ,which is not the same as wiki mentioned.

I remember back when we testing it did, but now that you mentioned it I tested again and you're right. Updated wiki page accordingly. Also, the takebackShortly command is pretty much useless, ignore it.

@AndyCGYan
Copy link
Collaborator Author

AndyCGYan commented Jul 1, 2019

Well, today I got some free time and tried my hands at auto popup/takeback, and after an afternoon/night of attempts, I think I've written the dirtiest hack I've ever did...
AndyCGYan/device_phh_treble@b738dcd
https://github.com/AndyCGYan/android_frameworks_av/commit/9896cab7db57b7daeb4a5b4518f9e5ef74533035
I don't know how to call HAL functions from within CameraService (or if that's even possible), so I had to rely on xiaomi-motor. In the end it worked out fine, and no double popup/takeback issues (since I always check for motorStatus).
Can you please review this @phhusson - I hesitate to even submit this hack as a PR.

@phhusson
Copy link
Owner

phhusson commented Jul 1, 2019 via email

@phhusson
Copy link
Owner

phhusson commented Jul 1, 2019

Except for SELinux policy, this should do the trick:

diff --git a/services/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk
index 96261ab0e..d5a40be93 100644
--- a/services/camera/libcameraservice/Android.mk
+++ b/services/camera/libcameraservice/Android.mk
@@ -81,7 +81,8 @@ LOCAL_SHARED_LIBRARIES:= \
     android.hardware.camera.device@1.0 \
     android.hardware.camera.device@3.2 \
     android.hardware.camera.device@3.3 \
-    android.hardware.camera.device@3.4
+    android.hardware.camera.device@3.4 \
+    vendor.xiaomi.hardware.motor@1.0
 
 LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libbinder libcamera_client libfmq
 
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 88f7be83b..e34297ce7 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -70,6 +70,8 @@
 #include "utils/CameraTraces.h"
 #include "utils/TagMonitor.h"
 
+#include <vendor/xiaomi/hardware/motor/1.0/IMotor.h>
+
 namespace {
     const char* kPermissionServiceName = "permission";
 }; // namespace anonymous
@@ -1441,6 +1443,15 @@ Status CameraService::connectHelper(const sp<CALLBACK>& cameraCb, const String8&
         }
     } // lock is destroyed, allow further connect calls
 
+
+    auto motorSvc = ::vendor::xiaomi::hardware::motor::V1_0::IMotor::getService();
+    if(motorSvc != nullptr) {
+           auto status = motorSvc->getMotorStatus();
+           if(status == 1 || status == 13) {
+                   motorSvc->popupMotor(1);
+           }
+    }
+
     // Important: release the mutex here so the client can call back into the service from its
     // destructor (can be at the end of the call)
     device = client;

@AndyCGYan
Copy link
Collaborator Author

+    vendor.xiaomi.hardware.motor@1.0

Oh shoot, no wonder I couldn't include the necessary header.
Need to write extra sepolicy for this?
What's status == 1 for? I've only observed 11 (up) and 13 (down) on my device.
Will leave the testing for tomorrow - thanks for the super quick and informative reply!

@phhusson
Copy link
Owner

phhusson commented Jul 1, 2019

Need to write extra sepolicy for this?

I don't know, I guess you'll see :P

What's status == 1 for? I've only observed 11 (up) and 13 (down) on my device.

Ah my bad, that was a poor copy/translate/paste, I read your code as (motorstatus == 1 || motor status == 13) instead of (cameraid == 1 && motor status == 13)

@AndyCGYan
Copy link
Collaborator Author

I don't know, I guess you'll see :P

Indeed:

07-02 09:15:29.332   575   575 E SELinux : avc:  denied  { find } for interface=vendor.xiaomi.hardware.motor::IMotor sid=u:r:cameraserver:s0 pid=1148 scontext=u:r:cameraserver:s0 tcontext=u:object_r:hal_motor_hwservice:s0 tclass=hwservice_manager permissive=0

It does work well when I use a permissive kernel, so I'll be submitting that part of the solution as a PR shortly.

I also tried to write sepolicy, but since I've never done it before, I could only imitate what I read, and for now I couldn't get it working - it builds but summoning the cam doesn't work, with this spit out in log:

07-02 11:11:30.172  1135  2057 W ServiceManagement: getService: unable to call into hwbinder service for vendor.xiaomi.hardware.motor@1.0::IMotor/default.

@AndyCGYan
Copy link
Collaborator Author

So after more swimming in codes, this here is what I wrote... 0001-sepolicy-Grant-cameraserver-permission-to-access-mot.patch.txt
But I really don't know jack about SELinux, and that doesn't solve the problem - the "unable to call into hwbinder service" error is still here. Please assist with this last piece of the puzzle if you can...

Meanwhile I'll shift my focus to running takeback on boot somehow. Maybe I missed something earlier.

@AndyCGYan
Copy link
Collaborator Author

So in trying to figure out running xiaomi-motor on boot, I realized I don't have PHH SU (since I run LOS), and turned to embedding the service into init.rc. Doing so results in SELinux denials reported in logcat, which means I just had to figure out sepolicy. And I did.
phhusson/platform_system_sepolicy#1
Please review this and see if there's any better way of doing it.

The irony is, this ended up achieving auto popup/takeback, but running xiaomi-motor on boot still doesn't work - no more SELinux denials, but the camera doesn't retract either, and I don't see any meaningful output from logcat/dmesg.

@AndyCGYan
Copy link
Collaborator Author

Now that there are proper ROMs, I've moved on from GSIs. It's been a wild ride...
There are some stuff from LOS that I think are worth taking a look though:
https://review.lineageos.org/q/topic:%22camera-motor%22+(status:open%20OR%20status:merged) - proper, universal camera motor HAL
https://review.lineageos.org/q/topic:%22fod%22+(status:open%20OR%20status:merged) - better in-display FP implementation with proper icon, brightness and orientation-independent facola position
@phhusson

Ramisky pushed a commit to Ramisky/device_phh_treble that referenced this issue Sep 14, 2019
Serves as a manual/intermediate solution to phhusson/treble_experimentations#539

Change-Id: Ia334f7d106b121014c791b0edb06b59a0eef3580
growtopiajaw pushed a commit to growtopiajaw/device_phh_treble that referenced this issue Nov 1, 2019
Serves as a manual/intermediate solution to phhusson/treble_experimentations#539

Change-Id: Ia334f7d106b121014c791b0edb06b59a0eef3580
growtopiajaw pushed a commit to growtopiajaw/device_phh_treble that referenced this issue Nov 1, 2019
Serves as a manual/intermediate solution to phhusson/treble_experimentations#539

Change-Id: Ia334f7d106b121014c791b0edb06b59a0eef3580
sooti pushed a commit to aosp-tissot/device_phh_treble that referenced this issue Jul 4, 2020
Serves as a manual/intermediate solution to phhusson/treble_experimentations#539

Change-Id: Ia334f7d106b121014c791b0edb06b59a0eef3580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants