Application context when run C++ app in shell

121 views
Skip to first unread message

Nguyễn Trung Thành

unread,
Oct 15, 2020, 12:26:30 PM10/15/20
to android-ndk
Hello,

I create an app in C++. I run it in shell however I cannot change context of the app. It run under u:r:su:s0 install my context

Result of ps -A -Z
u:r:su:s0                      root           2554   2552   15960   5516 0                   0 R TestApp

My sepolicy here:
type vendor_testapp, domain;
type vendor_testapp_exec, exec_type, vendor_file_type, file_type;
init_daemon_domain(vendor_testapp)

in file_contexts
/vendor/bin/TestApp     u:object_r:vendor_testapp_exec:s0

Anyone can help me?

Regards,
Thanh

Glenn Kasten

unread,
Oct 15, 2020, 12:34:19 PM10/15/20
to android-ndk
Can you please confirm: did you use NDK to create this app?
If so can you please a short code snippet?

Nguyễn Trung Thành

unread,
Oct 16, 2020, 11:03:59 PM10/16/20
to android-ndk
I write C++ inside AOSP source code. It is simple code to play with IVehicle

main.c
#define LOG_TAG "Test app"
#include <android/hardware/automotive/vehicle/2.0/IVehicle.h>
#include <android/hardware/automotive/vehicle/2.0/types.h>

#include <hidl/Status.h>
#include <hidl/LegacySupport.h>
#include <utils/misc.h>
#include <utils/Log.h>


#include <stdio.h>
#include <string.h>

using android::hardware::automotive::vehicle::V2_0::VehiclePropValue;
using android::sp;
using android::hardware::hidl_vec;
using namespace std;

using android::hardware::automotive::vehicle::V2_0::IVehicle;

int main(int argc, char** argv) {
size_t pos = 0;
android::sp<IVehicle> ser = IVehicle::getService();

ser->set(propValues);

return 0;
}

Android.bp
cc_binary {
    name: "TestApp",
    defaults: ["hidl_defaults"],
    //proprietary: true,
    vendor: true,
    srcs: ["main.cpp"],
 
    shared_libs: [
        "android.hardware.automotive.vehicle@2.0",
        "libhidlbase",
        "liblog",
        "libutils",
    ],
}
Reply all
Reply to author
Forward
0 new messages