Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f89b27af authored by Luca Stefani's avatar Luca Stefani
Browse files

Add adb_root daemon

Change-Id: I516f1b85e28f5d061c8c54282a7657d53162bccb
parent 282857e8
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -505,6 +505,24 @@ cc_binary {
    ],
}

cc_binary {
    name: "adb_root",
    srcs: [
        "root/adbroot_service.cpp",
        "root/main.cpp",
    ],
    init_rc: [
        "root/adb_root.rc",
    ],
    shared_libs: [
        "adbroot_aidl_interface-cpp",
        "libbase",
        "libbinder",
        "liblog",
        "libutils",
    ]
}

cc_binary {
    name: "abb",

@@ -604,3 +622,23 @@ python_test_host {
        },
    },
}

aidl_interface {
    name: "adbroot_aidl_interface",
    srcs: [
        "aidl/android/adbroot/IADBRootService.aidl",
    ],
    local_include_dir: "aidl",
    backend: {
        ndk: {
            enabled: false,
        },
    },
}

filegroup {
    name: "adbrootservice_aidl",
    srcs: [
        "aidl/android/adbroot/IADBRootService.aidl",
    ],
}
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.adbroot;

/** {@hide} */
interface IADBRootService {
    void setEnabled(boolean enabled);
    boolean getEnabled();
}

adb/root/adb_root.rc

0 → 100644
+7 −0
Original line number Diff line number Diff line
service adb_root /system/bin/adb_root
    class main
    user root
    group root

on boot
    mkdir /data/adbroot 0700 root root
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/strings.h>

#include "adbroot_service.h"

namespace {
const std::string kStoragePath = "/data/adbroot/";
const std::string kEnabled = "enabled";
}

namespace android {
namespace adbroot {

using ::android::base::ReadFileToString;
using ::android::base::Trim;
using ::android::base::WriteStringToFile;

ADBRootService::ADBRootService() : enabled_(false) {
    std::string buf;
    if (ReadFileToString(kStoragePath + kEnabled, &buf)) {
        enabled_ = std::stoi(Trim(buf));
    }
}

void ADBRootService::Register() {
    auto ret = android::BinderService<ADBRootService>::publish();
    if (ret != android::OK) {
        LOG(FATAL) << "Could not register adbroot service: " << ret;
    }
}

binder::Status ADBRootService::setEnabled(bool enabled) {
    enabled_ = enabled;
    WriteStringToFile(std::to_string(enabled), kStoragePath + kEnabled);
    return binder::Status::ok();
}

binder::Status ADBRootService::getEnabled(bool* _aidl_return) {
    *_aidl_return = enabled_;
    return binder::Status::ok();
}

}  // namespace adbroot
}  // namespace android
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <android/adbroot/BnADBRootService.h>
#include <binder/BinderService.h>

namespace android {
namespace adbroot {

class ADBRootService : public BinderService<ADBRootService>, public BnADBRootService {
  public:
    ADBRootService();

    static void Register();

    binder::Status setEnabled(bool enabled) override;
    binder::Status getEnabled(bool* _aidl_return) override;

    static char const* getServiceName() { return "adbroot_service"; }
  private:
    bool enabled_;
};

}  // namespace adbroot
}  // namespace android
Loading