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

Commit 92b17c6c authored by Steven Moreland's avatar Steven Moreland
Browse files

libbinder: remove SM Static.cpp vars.

No need for global exported static state anymore. This also
creates a new lock (gPermissionControllerLock) which controls
access to gPermissionController since there wasn't a reason to
have access to this and sm excluded (likely was out of convenience).

Bug: 129785390
Test: TH
Change-Id: I15bbe2f0ef4f73c555798cd7674edcc56e923575
parent a9ed1a64
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ namespace android {

sp<IServiceManager> defaultServiceManager()
{
    static Mutex gDefaultServiceManagerLock;
    static sp<IServiceManager> gDefaultServiceManager;

    if (gDefaultServiceManager != nullptr) return gDefaultServiceManager;

    {
@@ -74,10 +77,13 @@ bool checkCallingPermission(const String16& permission, int32_t* outPid, int32_t

bool checkPermission(const String16& permission, pid_t pid, uid_t uid)
{
    static Mutex gPermissionControllerLock;
    static sp<IPermissionController> gPermissionController;

    sp<IPermissionController> pc;
    gDefaultServiceManagerLock.lock();
    gPermissionControllerLock.lock();
    pc = gPermissionController;
    gDefaultServiceManagerLock.unlock();
    gPermissionControllerLock.unlock();

    int64_t startTime = 0;

@@ -101,11 +107,11 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid)
            }

            // Object is dead!
            gDefaultServiceManagerLock.lock();
            gPermissionControllerLock.lock();
            if (gPermissionController == pc) {
                gPermissionController = nullptr;
            }
            gDefaultServiceManagerLock.unlock();
            gPermissionControllerLock.unlock();
        }

        // Need to retrieve the permission controller.
@@ -121,9 +127,9 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid)
        } else {
            pc = interface_cast<IPermissionController>(binder);
            // Install the new permission controller, and try again.
            gDefaultServiceManagerLock.lock();
            gPermissionControllerLock.lock();
            gPermissionController = pc;
            gDefaultServiceManagerLock.unlock();
            gPermissionControllerLock.unlock();
        }
    }
}
@@ -142,6 +148,8 @@ public:

    virtual sp<IBinder> getService(const String16& name) const
    {
        static bool gSystemBootCompleted = false;

        sp<IBinder> svc = checkService(name);
        if (svc != nullptr) return svc;

+0 −9
Original line number Diff line number Diff line
@@ -75,13 +75,4 @@ TextOutput& aerr(gStderrTextOutput);
Mutex& gProcessMutex = *new Mutex;
sp<ProcessState> gProcess;

// ------------ IServiceManager.cpp

Mutex gDefaultServiceManagerLock;
sp<IServiceManager> gDefaultServiceManager;
#ifndef __ANDROID_VNDK__
sp<IPermissionController> gPermissionController;
#endif
bool gSystemBootCompleted = false;

}   // namespace android
+0 −12
Original line number Diff line number Diff line
@@ -21,10 +21,6 @@

#include <binder/IBinder.h>
#include <binder/ProcessState.h>
#ifndef __ANDROID_VNDK__
#include <binder/IPermissionController.h>
#endif
#include <binder/IServiceManager.h>

namespace android {

@@ -35,12 +31,4 @@ extern Vector<int32_t> gTextBuffers;
extern Mutex& gProcessMutex;
extern sp<ProcessState> gProcess;

// For IServiceManager.cpp
extern Mutex gDefaultServiceManagerLock;
extern sp<IServiceManager> gDefaultServiceManager;
#ifndef __ANDROID_VNDK__
extern sp<IPermissionController> gPermissionController;
#endif
extern bool gSystemBootCompleted;

}   // namespace android