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

Commit b2a2a89b authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4518856 from 4d85b8c0 to pi-release

Change-Id: Idab5f590a2dbff6b36bddea73f272094bb55d5e4
parents 04afc00a 4d85b8c0
Loading
Loading
Loading
Loading
+81 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 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 <mutex>
#include <binder/ActivityManager.h>
#include <binder/Binder.h>
#include <binder/IServiceManager.h>

#include <utils/SystemClock.h>

namespace android {

ActivityManager::ActivityManager()
{
}

sp<IActivityManager> ActivityManager::getService()
{
    std::lock_guard<Mutex> scoped_lock(mLock);
    int64_t startTime = 0;
    sp<IActivityManager> service = mService;
    while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) {
        sp<IBinder> binder = defaultServiceManager()->checkService(String16("activity"));
        if (binder == NULL) {
            // Wait for the activity service to come back...
            if (startTime == 0) {
                startTime = uptimeMillis();
                ALOGI("Waiting for activity service");
            } else if ((uptimeMillis() - startTime) > 10000) {
                ALOGW("Waiting too long for activity service, giving up");
                service = NULL;
                break;
            }
            sleep(1);
        } else {
            service = interface_cast<IActivityManager>(binder);
            mService = service;
        }
    }
    return service;
}

int ActivityManager::openContentUri(const String16& stringUri)
{
    sp<IActivityManager> service = getService();
    return service != NULL ? service->openContentUri(stringUri) : -1;
}

void ActivityManager::registerUidObserver(const sp<IUidObserver>& observer,
                                          const int32_t event,
                                          const int32_t cutpoint,
                                          const String16& callingPackage)
{
    sp<IActivityManager> service = getService();
    if (service != NULL) {
        service->registerUidObserver(observer, event, cutpoint, callingPackage);
    }
}

void ActivityManager::unregisterUidObserver(const sp<IUidObserver>& observer)
{
    sp<IActivityManager> service = getService();
    if (service != NULL) {
        service->unregisterUidObserver(observer);
    }
}

}; // namespace android
+2 −0
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ cc_library {
    },
    },


    srcs: [
    srcs: [
        "ActivityManager.cpp",
        "AppOpsManager.cpp",
        "AppOpsManager.cpp",
        "Binder.cpp",
        "Binder.cpp",
        "BpBinder.cpp",
        "BpBinder.cpp",
@@ -56,6 +57,7 @@ cc_library {
        "IResultReceiver.cpp",
        "IResultReceiver.cpp",
        "IServiceManager.cpp",
        "IServiceManager.cpp",
        "IShellCallback.cpp",
        "IShellCallback.cpp",
        "IUidObserver.cpp",
        "MemoryBase.cpp",
        "MemoryBase.cpp",
        "MemoryDealer.cpp",
        "MemoryDealer.cpp",
        "MemoryHeapBase.cpp",
        "MemoryHeapBase.cpp",
+22 −0
Original line number Original line Diff line number Diff line
@@ -56,6 +56,28 @@ public:
        }
        }
        return fd;
        return fd;
    }
    }

    virtual void registerUidObserver(const sp<IUidObserver>& observer,
                                     const int32_t event,
                                     const int32_t cutpoint,
                                     const String16& callingPackage)
    {
         Parcel data, reply;
         data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor());
         data.writeStrongBinder(IInterface::asBinder(observer));
         data.writeInt32(event);
         data.writeInt32(cutpoint);
         data.writeString16(callingPackage);
         remote()->transact(REGISTER_UID_OBSERVER_TRANSACTION, data, &reply);
    }

    virtual void unregisterUidObserver(const sp<IUidObserver>& observer)
    {
         Parcel data, reply;
         data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor());
         data.writeStrongBinder(IInterface::asBinder(observer));
         remote()->transact(UNREGISTER_UID_OBSERVER_TRANSACTION, data, &reply);
    }
};
};


// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
+97 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 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 <binder/IUidObserver.h>

#include <binder/Parcel.h>

namespace android {

// ------------------------------------------------------------------------------------

class BpUidObserver : public BpInterface<IUidObserver>
{
public:
    explicit BpUidObserver(const sp<IBinder>& impl)
        : BpInterface<IUidObserver>(impl)
    {
    }

    virtual void onUidGone(uid_t uid, bool disabled)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
        data.writeInt32((int32_t) uid);
        data.writeInt32(disabled ? 1 : 0);
        remote()->transact(ON_UID_GONE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
    }

    virtual void onUidActive(uid_t uid)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
        data.writeInt32((int32_t) uid);
        remote()->transact(ON_UID_ACTIVE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
    }

    virtual void onUidIdle(uid_t uid, bool disabled)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
        data.writeInt32((int32_t) uid);
        data.writeInt32(disabled ? 1 : 0);
        remote()->transact(ON_UID_IDLE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
    }
};

// ----------------------------------------------------------------------

IMPLEMENT_META_INTERFACE(UidObserver, "android.app.IUidObserver");

// ----------------------------------------------------------------------

status_t BnUidObserver::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch(code) {
        case ON_UID_GONE_TRANSACTION: {
            CHECK_INTERFACE(IUidObserver, data, reply);
            uid_t uid = data.readInt32();
            bool disabled = data.readInt32() == 1;
            onUidGone(uid, disabled);
            return NO_ERROR;
        } break;

        case ON_UID_ACTIVE_TRANSACTION: {
            CHECK_INTERFACE(IUidObserver, data, reply);
            uid_t uid = data.readInt32();
            onUidActive(uid);
            return NO_ERROR;
        } break;

        case ON_UID_IDLE_TRANSACTION: {
            CHECK_INTERFACE(IUidObserver, data, reply);
            uid_t uid = data.readInt32();
            bool disabled = data.readInt32() == 1;
            onUidIdle(uid, disabled);
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}

}; // namespace android
+63 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 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 ANDROID_ACTIVITY_MANAGER_H
#define ANDROID_ACTIVITY_MANAGER_H

#include <binder/IActivityManager.h>

#include <utils/threads.h>

// ---------------------------------------------------------------------------
namespace android {

class ActivityManager
{
public:

    enum {
        // Flag for registerUidObserver: report uid gone
        UID_OBSERVER_GONE = 1<<1,
        // Flag for registerUidObserver: report uid has become idle
        UID_OBSERVER_IDLE = 1<<2,
        // Flag for registerUidObserver: report uid has become active
        UID_OBSERVER_ACTIVE = 1<<3
    };

    enum {
        // Not a real process state
        PROCESS_STATE_UNKNOWN = -1
    };

    ActivityManager();

    int openContentUri(const String16& stringUri);
    void registerUidObserver(const sp<IUidObserver>& observer,
                             const int32_t event,
                             const int32_t cutpoint,
                             const String16& callingPackage);
    void unregisterUidObserver(const sp<IUidObserver>& observer);

private:
    Mutex mLock;
    sp<IActivityManager> mService;
    sp<IActivityManager> getService();
};


}; // namespace android
// ---------------------------------------------------------------------------
#endif // ANDROID_ACTIVITY_MANAGER_H
Loading