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

Commit a797472c authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "Activity manager: native callback for process state"

parents bdf9cec7 0559589b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -89,6 +89,15 @@ bool ActivityManager::isUidActive(const uid_t uid, const String16& callingPackag
    return false;
}

int32_t ActivityManager::getUidProcessState(const uid_t uid, const String16& callingPackage)
{
    sp<IActivityManager> service = getService();
    if (service != nullptr) {
        return service->getUidProcessState(uid, callingPackage);
    }
    return PROCESS_STATE_UNKNOWN;
}

status_t ActivityManager::linkToDeath(const sp<IBinder::DeathRecipient>& recipient) {
    sp<IActivityManager> service = getService();
    if (service != nullptr) {
+15 −1
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@
#include <unistd.h>
#include <fcntl.h>

#include <binder/ActivityManager.h>
#include <binder/IActivityManager.h>

#include <binder/Parcel.h>

namespace android {
@@ -90,6 +90,20 @@ public:
         if (reply.readExceptionCode() != 0) return false;
         return reply.readInt32() == 1;
    }

    virtual int32_t getUidProcessState(const uid_t uid, const String16& callingPackage)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IActivityManager::getInterfaceDescriptor());
        data.writeInt32(uid);
        data.writeString16(callingPackage);
        remote()->transact(GET_UID_PROCESS_STATE_TRANSACTION, data, &reply);
        // fail on exception
        if (reply.readExceptionCode() != 0) {
            return ActivityManager::PROCESS_STATE_UNKNOWN;
        }
        return reply.readInt32();
    }
};

// ------------------------------------------------------------------------------------
+18 −0
Original line number Diff line number Diff line
@@ -55,6 +55,16 @@ public:
        data.writeInt32(disabled ? 1 : 0);
        remote()->transact(ON_UID_IDLE_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
    }

    virtual void onUidStateChanged(uid_t uid, int32_t procState, int64_t procStateSeq)
    {
        Parcel data, reply;
        data.writeInterfaceToken(IUidObserver::getInterfaceDescriptor());
        data.writeInt32((int32_t) uid);
        data.writeInt32(procState);
        data.writeInt64(procStateSeq);
        remote()->transact(ON_UID_STATE_CHANGED_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
    }
};

// ----------------------------------------------------------------------
@@ -89,6 +99,14 @@ status_t BnUidObserver::onTransact(
            onUidIdle(uid, disabled);
            return NO_ERROR;
        } break;
        case ON_UID_STATE_CHANGED_TRANSACTION: {
            CHECK_INTERFACE(IUidObserver, data, reply);
            uid_t uid = data.readInt32();
            int32_t procState = data.readInt32();
            int64_t procStateSeq = data.readInt64();
            onUidStateChanged(uid, procState, procStateSeq);
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
+26 −3
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ class ActivityManager
public:

    enum {
        // Flag for registerUidObserver: report uid state changed
        UID_OBSERVER_PROCSTATE = 1<<0,
        // Flag for registerUidObserver: report uid gone
        UID_OBSERVER_GONE = 1<<1,
        // Flag for registerUidObserver: report uid has become idle
@@ -40,8 +42,27 @@ public:
    };

    enum {
        // Not a real process state
        PROCESS_STATE_UNKNOWN = -1
        PROCESS_STATE_UNKNOWN = -1,
        PROCESS_STATE_PERSISTENT = 0,
        PROCESS_STATE_PERSISTENT_UI = 1,
        PROCESS_STATE_TOP = 2,
        PROCESS_STATE_FOREGROUND_SERVICE = 3,
        PROCESS_STATE_BOUND_FOREGROUND_SERVICE = 4,
        PROCESS_STATE_IMPORTANT_FOREGROUND = 5,
        PROCESS_STATE_IMPORTANT_BACKGROUND = 6,
        PROCESS_STATE_TRANSIENT_BACKGROUND = 7,
        PROCESS_STATE_BACKUP = 8,
        PROCESS_STATE_SERVICE = 9,
        PROCESS_STATE_RECEIVER = 10,
        PROCESS_STATE_TOP_SLEEPING = 11,
        PROCESS_STATE_HEAVY_WEIGHT = 12,
        PROCESS_STATE_HOME = 13,
        PROCESS_STATE_LAST_ACTIVITY = 14,
        PROCESS_STATE_CACHED_ACTIVITY = 15,
        PROCESS_STATE_CACHED_ACTIVITY_CLIENT = 16,
        PROCESS_STATE_CACHED_RECENT = 17,
        PROCESS_STATE_CACHED_EMPTY = 18,
        PROCESS_STATE_NONEXISTENT = 19,
    };

    ActivityManager();
@@ -53,6 +74,8 @@ public:
                             const String16& callingPackage);
    void unregisterUidObserver(const sp<IUidObserver>& observer);
    bool isUidActive(const uid_t uid, const String16& callingPackage);
    int getUidProcessState(const uid_t uid, const String16& callingPackage);


  status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient);
    status_t unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient);
+3 −1
Original line number Diff line number Diff line
@@ -38,12 +38,14 @@ public:
                                     const String16& callingPackage) = 0;
    virtual void unregisterUidObserver(const sp<IUidObserver>& observer) = 0;
    virtual bool isUidActive(const uid_t uid, const String16& callingPackage) = 0;
    virtual int32_t getUidProcessState(const uid_t uid, const String16& callingPackage) = 0;

    enum {
        OPEN_CONTENT_URI_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
        REGISTER_UID_OBSERVER_TRANSACTION,
        UNREGISTER_UID_OBSERVER_TRANSACTION,
        IS_UID_ACTIVE_TRANSACTION
        IS_UID_ACTIVE_TRANSACTION,
        GET_UID_PROCESS_STATE_TRANSACTION
    };
};

Loading