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

Commit 57e3c32b authored by Kelvin Zhang's avatar Kelvin Zhang
Browse files

Move libbinderwrapper to update_engine

libbinderwrapper is only used by update_engine, it's better to move it
inside update_engine repo

Change-Id: Ia489f38a311b221744f7cf89c9da9c4f3682bb4c
parent 40e78443
Loading
Loading
Loading
Loading

libbinderwrapper/Android.bp

deleted100644 → 0
+0 −63
Original line number Diff line number Diff line
//
// Copyright (C) 2015 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 {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

cc_defaults {
    name: "libbinderwrapper_defaults",

    cflags: [
        "-Wall",
        "-Werror",
        "-Wno-unused-parameter",

    ],
    export_include_dirs: ["include"],
    shared_libs: [
        "libbinder",
        "libutils",
    ],
}

// libbinderwrapper shared library
// ========================================================
cc_library_shared {
    name: "libbinderwrapper",
    defaults: ["libbinderwrapper_defaults"],
    vendor_available: true,

    srcs: [
        "binder_wrapper.cc",
        "real_binder_wrapper.cc",
    ],
}

// libbinderwrapper_test_support static library
// ========================================================
cc_library_static {
    name: "libbinderwrapper_test_support",
    defaults: ["libbinderwrapper_defaults"],

    static_libs: ["libgtest"],
    shared_libs: ["libbinderwrapper"],

    srcs: [
        "binder_test_base.cc",
        "stub_binder_wrapper.cc",
    ],
}
+0 −33
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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 <binderwrapper/binder_test_base.h>

#include <binderwrapper/binder_wrapper.h>
#include <binderwrapper/stub_binder_wrapper.h>

namespace android {

BinderTestBase::BinderTestBase() : binder_wrapper_(new StubBinderWrapper()) {
  // Pass ownership.
  BinderWrapper::InitForTesting(binder_wrapper_);
}

BinderTestBase::~BinderTestBase() {
  BinderWrapper::Destroy();
}

}  // namespace android
+0 −60
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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 <binderwrapper/binder_wrapper.h>

#include <android-base/logging.h>

#include "real_binder_wrapper.h"

namespace android {

// Singleton instance.
BinderWrapper* BinderWrapper::instance_ = nullptr;

// static
void BinderWrapper::Create() {
  CHECK(!instance_) << "Already initialized; missing call to Destroy()?";
  instance_ = new RealBinderWrapper();
}

// static
void BinderWrapper::InitForTesting(BinderWrapper* wrapper) {
  CHECK(!instance_) << "Already initialized; missing call to Destroy()?";
  instance_ = wrapper;
}

// static
void BinderWrapper::Destroy() {
  CHECK(instance_) << "Not initialized; missing call to Create()?";
  delete instance_;
  instance_ = nullptr;
}

// static
BinderWrapper* BinderWrapper::Get() {
  CHECK(instance_) << "Not initialized; missing call to Create()?";
  return instance_;
}

// static
BinderWrapper* BinderWrapper::GetOrCreateInstance() {
  if (!instance_)
    instance_ = new RealBinderWrapper();
  return instance_;
}

}  // namespace android
+0 −44
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.
 */

#ifndef SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_TEST_BASE_H_
#define SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_TEST_BASE_H_

#include <gtest/gtest.h>

namespace android {

class StubBinderWrapper;

// Class that can be inherited from (or aliased via typedef/using) when writing
// tests that use StubBinderManager.
class BinderTestBase : public ::testing::Test {
 public:
  BinderTestBase();
  ~BinderTestBase() override;

  StubBinderWrapper* binder_wrapper() { return binder_wrapper_; }

 protected:
  StubBinderWrapper* binder_wrapper_;  // Not owned.

 private:
   BinderTestBase(const BinderTestBase&) = delete;
};

}  // namespace android

#endif  // SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_TEST_BASE_H_
+0 −87
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.
 */

#ifndef SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_WRAPPER_H_
#define SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_WRAPPER_H_

#include <sys/types.h>

#include <functional>
#include <string>

#include <utils/StrongPointer.h>

namespace android {

class BBinder;
class IBinder;

// Wraps libbinder to make it testable.
// NOTE: Static methods of this class are not thread-safe.
class BinderWrapper {
 public:
  virtual ~BinderWrapper() {}

  // Creates and initializes the singleton (using a wrapper that communicates
  // with the real binder system).
  static void Create();

  // Initializes |wrapper| as the singleton, taking ownership of it. Tests that
  // want to inject their own wrappers should call this instead of Create().
  static void InitForTesting(BinderWrapper* wrapper);

  // Destroys the singleton. Must be called before calling Create() or
  // InitForTesting() a second time.
  static void Destroy();

  // Returns the singleton instance previously created by Create() or set by
  // InitForTesting().
  static BinderWrapper* Get();

  // Returns the singleton instance if it was previously created by Create() or
  // set by InitForTesting(), or creates a new one by calling Create().
  static BinderWrapper* GetOrCreateInstance();

  // Gets the binder for communicating with the service identified by
  // |service_name|, returning null immediately if it doesn't exist.
  virtual sp<IBinder> GetService(const std::string& service_name) = 0;

  // Registers |binder| as |service_name| with the service manager.
  virtual bool RegisterService(const std::string& service_name,
                               const sp<IBinder>& binder) = 0;

  // Creates a local binder object.
  virtual sp<BBinder> CreateLocalBinder() = 0;

  // Registers |callback| to be invoked when |binder| dies. If another callback
  // is currently registered for |binder|, it will be replaced.
  virtual bool RegisterForDeathNotifications(const sp<IBinder>& binder,
                                             const std::function<void()>&) = 0;

  // Unregisters the callback, if any, for |binder|.
  virtual bool UnregisterForDeathNotifications(const sp<IBinder>& binder) = 0;

  // When called while in a transaction, returns the caller's UID or PID.
  virtual uid_t GetCallingUid() = 0;
  virtual pid_t GetCallingPid() = 0;

 private:
  static BinderWrapper* instance_;
};

}  // namespace android

#endif  // SYSTEM_CORE_INCLUDE_BINDERWRAPPER_BINDER_WRAPPER_H_
Loading