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

Commit 2df6cead authored by Bhavya Sokke Mallikarjunappa's avatar Bhavya Sokke Mallikarjunappa Committed by Linux Build Service Account
Browse files

Remove SystemServer dependency for DpmService

Remove SystemServer dependency for DpmService and
use AlarmManager and PowerManager services.

Change-Id: I346970ff36acbeaa123e9b550a620ff01137bd75
parent f3639249
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ interface IAlarmManager {
    void setTimeZone(String zone);
    void remove(in PendingIntent operation);
    AlarmManager.AlarmClockInfo getNextAlarmClock(int userId);
    // update the uids being synchronized by network socket request manager
    void updateBlockedUids(int uid, boolean isBlocked);
}

+2 −0
Original line number Diff line number Diff line
@@ -58,4 +58,6 @@ interface IPowerManager

    // sets the attention light (used by phone app only)
    void setAttentionLight(boolean on, int color);
    // update the uids being synchronized by network socket request manager
    void updateBlockedUids(int uid, boolean isBlocked);
}
+33 −24
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PowerManager;
import android.os.Process;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
@@ -883,6 +884,38 @@ class AlarmManagerService extends SystemService {

            dumpImpl(pw);
        }

        @Override
        /* updates the blocked uids, so if a wake lock is acquired to only fire
         * alarm for it, it can be released.
         */
        public void updateBlockedUids(int uid, boolean isBlocked) {

            if (localLOGV) Slog.v(TAG, "UpdateBlockedUids: uid = " + uid + " isBlocked = " + isBlocked);

            if (Binder.getCallingUid() != Process.SYSTEM_UID) {
                if (localLOGV) Slog.v(TAG, "UpdateBlockedUids is not allowed");
                return;
            }

            synchronized(mLock) {
                if(isBlocked) {
                    mBlockedUids.add(new Integer(uid));
                    if (checkReleaseWakeLock()) {
                        /* all the uids for which the alarms are triggered
                         * are either blocked or have called onSendFinished.
                         */
                        if (mWakeLock.isHeld()) {
                            mWakeLock.release();
                            if (localLOGV)
                                Slog.v(TAG, "AM WakeLock Released Internally in updateBlockedUids");
                        }
                    }
                } else {
                    mBlockedUids.clear();
                }
            }
        }
    };

    void dumpImpl(PrintWriter pw) {
@@ -1286,30 +1319,6 @@ class AlarmManagerService extends SystemService {
        }
    }

    /* updates the blocked uids, so if a wake lock is acquired to only fire
     * alarm for it, it can be released.
     */
    void updateBlockedUids(int uid, boolean isBlocked) {
        if (localLOGV) Slog.v(TAG, "UpdateBlockedUids: uid = "+uid +" isBlocked = "+isBlocked);
        synchronized(mLock) {
            if(isBlocked) {
                mBlockedUids.add(new Integer(uid));
                if (checkReleaseWakeLock()) {
                    /* all the uids for which the alarms are triggered
                     * are either blocked or have called onSendFinished.
                     */
                    if (mWakeLock.isHeld()) {
                        mWakeLock.release();
                        if (localLOGV)
                            Slog.v(TAG, "AM WakeLock Released Internally in updateBlockedUids");
                    }
                }
            } else {
               mBlockedUids.clear();
            }
        }
    }

    boolean checkReleaseWakeLock() {
        if (mTriggeredUids.size() == 0 || mBlockedUids.size() == 0)
            return false;
+40 −33
Original line number Diff line number Diff line
@@ -899,39 +899,6 @@ public final class PowerManagerService extends SystemService
        }
    }

    /* updates the blocked uids, so if a wake lock is acquired for it
     * can be released.
     */
    public void updateBlockedUids(int uid, boolean isBlocked) {
        synchronized(mLock) {
            if (DEBUG_SPEW) Slog.v(TAG, "updateBlockedUids: uid = "+uid +"isBlocked = "+isBlocked);
            if(isBlocked) {
                mBlockedUids.add(new Integer(uid));
                for (int index = 0; index < mWakeLocks.size(); index++) {
                    WakeLock wl = mWakeLocks.get(index);
                    if(wl != null) {
                        if(wl.mTag.startsWith("*sync*") && wl.mOwnerUid == Process.SYSTEM_UID) {
                            releaseWakeLockInternal(wl.mLock, wl.mFlags);
                            index--;
                            if (DEBUG_SPEW) Slog.v(TAG, "Internally releasing the wakelock"
                                    + "acquired by SyncManager");
                            continue;
                        }
                        // release the wakelock for the blocked uid
                        if (wl.mOwnerUid == uid || checkWorkSourceObjectId(uid, wl)) {
                            releaseWakeLockInternal(wl.mLock, wl.mFlags);
                            index--;
                            if (DEBUG_SPEW) Slog.v(TAG, "Internally releasing it");
                        }
                    }
                }
            }
            else {
                mBlockedUids.remove(new Integer(uid));
            }
        }
    }

    private boolean checkWorkSourceObjectId(int uid, WakeLock wl) {
        try {
            for (int index = 0; index < wl.mWorkSource.size(); index++) {
@@ -3243,6 +3210,46 @@ public final class PowerManagerService extends SystemService
                Binder.restoreCallingIdentity(ident);
            }
        }

        /* updates the blocked uids, so if a wake lock is acquired for it
         * can be released.
         */
        public void updateBlockedUids(int uid, boolean isBlocked) {

            if (DEBUG_SPEW) Slog.v(TAG, "updateBlockedUids: uid = " + uid + "isBlocked = " + isBlocked);

            if (Binder.getCallingUid() != Process.SYSTEM_UID) {
                if (DEBUG_SPEW) Slog.v(TAG, "UpdateBlockedUids is not allowed");
                return;
            }

            synchronized(mLock) {
                if(isBlocked) {
                    mBlockedUids.add(new Integer(uid));
                    for (int index = 0; index < mWakeLocks.size(); index++) {
                        WakeLock wl = mWakeLocks.get(index);
                        if(wl != null) {
                            if(wl.mTag.startsWith("*sync*") && wl.mOwnerUid == Process.SYSTEM_UID) {
                                releaseWakeLockInternal(wl.mLock, wl.mFlags);
                                index--;
                                if (DEBUG_SPEW) Slog.v(TAG, "Internally releasing the wakelock"
                                        + "acquired by SyncManager");
                                continue;
                            }
                            // release the wakelock for the blocked uid
                            if (wl.mOwnerUid == uid || checkWorkSourceObjectId(uid, wl)) {
                                releaseWakeLockInternal(wl.mLock, wl.mFlags);
                                index--;
                                if (DEBUG_SPEW) Slog.v(TAG, "Internally releasing it");
                            }
                        }
                    }
                }
                else {
                    mBlockedUids.remove(new Integer(uid));
                }
            }
        }
    }

    private final class LocalService extends PowerManagerInternal {
+4 −18
Original line number Diff line number Diff line
@@ -701,7 +701,7 @@ public final class SystemServer {
                }
                try {
                    Slog.i(TAG, "DPM Service");
                    startDpmService(context, this);
                    startDpmService(context);
                } catch (Throwable e) {
                    reportWtf("starting DpmService", e);
                }
@@ -1228,7 +1228,7 @@ public final class SystemServer {
        context.startServiceAsUser(intent, UserHandle.OWNER);
    }

    private static final void startDpmService(Context context, SystemServer systemServer) {
    private static final void startDpmService(Context context) {
        try {
            Object dpmObj = null;
            int dpmFeature = SystemProperties.getInt("persist.dpm.feature", 0);
@@ -1240,8 +1240,8 @@ public final class SystemServer {
                            ClassLoader.getSystemClassLoader());
                Class dpmClass = dpmClassLoader.loadClass("com.qti.dpm.DpmService");
                Constructor dpmConstructor = dpmClass.getConstructor(
                        new Class[] {Context.class, SystemServer.class});
                dpmObj = dpmConstructor.newInstance(context, systemServer);
                        new Class[] {Context.class});
                dpmObj = dpmConstructor.newInstance(context);
                try {
                    if(dpmObj != null && (dpmObj instanceof IBinder)) {
                        ServiceManager.addService("dpmservice", (IBinder)dpmObj);
@@ -1255,18 +1255,4 @@ public final class SystemServer {
            Slog.i(TAG, "starting DPM Service", e);
        }
    }


    public void updateBlockedUids(int uid, boolean isBlocked) {
        try {
            mAlarmManagerService.updateBlockedUids(uid, isBlocked);
        } catch (NullPointerException e) {
            Slog.w(TAG, "Could Not Update blocked Uids with alarmManager" + e);
        }
        try {
            mPowerManagerService.updateBlockedUids(uid, isBlocked);
        } catch (NullPointerException e) {
            Slog.w(TAG, "Could Not Update blocked Uids with powerManager" + e);
        }
    }
}