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

Commit c03c00d3 authored by Nishith  Khanna's avatar Nishith Khanna
Browse files

Merge branch 'lineage-20.0' into v1-t

parents 0e3b9186 4662984b
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
@@ -37,7 +37,9 @@ import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.WorkSource;
import android.text.TextUtils;
import android.util.Log;
@@ -91,6 +93,14 @@ import java.util.concurrent.Executor;
public class AlarmManager {
    private static final String TAG = "AlarmManager";

    /**
     * Prefix used by {{@link #makeTag(long, WorkSource)}} to make a tag on behalf of the caller
     * when the {@link #set(int, long, long, long, OnAlarmListener, Handler, WorkSource)} API is
     * used. This prefix is a unique sequence of characters to differentiate with other tags that
     * apps may provide to other APIs that accept a listener callback.
     */
    private static final String GENERATED_TAG_PREFIX = "$android.alarm.generated";

    /** @hide */
    @IntDef(prefix = { "RTC", "ELAPSED" }, value = {
            RTC_WAKEUP,
@@ -860,6 +870,24 @@ public class AlarmManager {
                targetHandler, workSource, null);
    }

    /**
     * This is only used to make an identifying tag for the deprecated
     * {@link #set(int, long, long, long, OnAlarmListener, Handler, WorkSource)} API which doesn't
     * accept a tag. For all other APIs, the tag provided by the app is used, even if it is
     * {@code null}.
     */
    private static String makeTag(long triggerMillis, WorkSource ws) {
        final StringBuilder tagBuilder = new StringBuilder(GENERATED_TAG_PREFIX);

        tagBuilder.append(":");
        final int attributionUid =
                (ws == null || ws.isEmpty()) ? Process.myUid() : ws.getAttributionUid();
        tagBuilder.append(UserHandle.formatUid(attributionUid));
        tagBuilder.append(":");
        tagBuilder.append(triggerMillis);
        return tagBuilder.toString();
    }

    /**
     * Direct callback version of {@link #set(int, long, long, long, PendingIntent, WorkSource)}.
     * Note that repeating alarms must use the PendingIntent variant, not an OnAlarmListener.
@@ -875,8 +903,8 @@ public class AlarmManager {
    public void set(@AlarmType int type, long triggerAtMillis, long windowMillis,
            long intervalMillis, OnAlarmListener listener, Handler targetHandler,
            WorkSource workSource) {
        setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, null,
                targetHandler, workSource, null);
        setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener,
                makeTag(triggerAtMillis, workSource), targetHandler, workSource, null);
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -225,6 +225,8 @@ public interface AppStandbyInternal {

    void setActiveAdminApps(Set<String> adminPkgs, int userId);

    void setAdminProtectedPackages(Set<String> packageNames, int userId);

    /**
     * @return {@code true} if the given package is an active device admin app.
     */
+35 −7
Original line number Diff line number Diff line
@@ -4739,8 +4739,14 @@ public class AlarmManagerService extends SystemService {
                            }
                            final ArraySet<Pair<String, Integer>> triggerPackages =
                                    new ArraySet<>();
                            final SparseIntArray countsPerUid = new SparseIntArray();
                            final SparseIntArray wakeupCountsPerUid = new SparseIntArray();
                            for (int i = 0; i < triggerList.size(); i++) {
                                final Alarm a = triggerList.get(i);
                                increment(countsPerUid, a.uid);
                                if (a.wakeup) {
                                    increment(wakeupCountsPerUid, a.uid);
                                }
                                if (mConstants.USE_TARE_POLICY) {
                                    if (!isExemptFromTare(a)) {
                                        triggerPackages.add(Pair.create(
@@ -4761,7 +4767,8 @@ public class AlarmManagerService extends SystemService {
                            }
                            rescheduleKernelAlarmsLocked();
                            updateNextAlarmClockLocked();
                            MetricsHelper.pushAlarmBatchDelivered(triggerList.size(), wakeUps);
                            logAlarmBatchDelivered(
                                    triggerList.size(), wakeUps, countsPerUid, wakeupCountsPerUid);
                        }
                    }

@@ -4776,6 +4783,32 @@ public class AlarmManagerService extends SystemService {
        }
    }

    private static void increment(SparseIntArray array, int key) {
        final int index = array.indexOfKey(key);
        if (index >= 0) {
            array.setValueAt(index, array.valueAt(index) + 1);
        } else {
            array.put(key, 1);
        }
    }

    private void logAlarmBatchDelivered(
            int alarms,
            int wakeups,
            SparseIntArray countsPerUid,
            SparseIntArray wakeupCountsPerUid) {
        final int[] uids = new int[countsPerUid.size()];
        final int[] countsArray = new int[countsPerUid.size()];
        final int[] wakeupCountsArray = new int[countsPerUid.size()];
        for (int i = 0; i < countsPerUid.size(); i++) {
            uids[i] = countsPerUid.keyAt(i);
            countsArray[i] = countsPerUid.valueAt(i);
            wakeupCountsArray[i] = wakeupCountsPerUid.get(uids[i], 0);
        }
        MetricsHelper.pushAlarmBatchDelivered(
                alarms, wakeups, uids, countsArray, wakeupCountsArray);
    }

    /**
     * Attribute blame for a WakeLock.
     *
@@ -5695,12 +5728,7 @@ public class AlarmManagerService extends SystemService {
    }

    private void incrementAlarmCount(int uid) {
        final int uidIndex = mAlarmsPerUid.indexOfKey(uid);
        if (uidIndex >= 0) {
            mAlarmsPerUid.setValueAt(uidIndex, mAlarmsPerUid.valueAt(uidIndex) + 1);
        } else {
            mAlarmsPerUid.put(uid, 1);
        }
        increment(mAlarmsPerUid, uid);
    }

    /**
+6 −2
Original line number Diff line number Diff line
@@ -111,10 +111,14 @@ class MetricsHelper {
                ActivityManager.processStateAmToProto(callerProcState));
    }

    static void pushAlarmBatchDelivered(int numAlarms, int wakeups) {
    static void pushAlarmBatchDelivered(
            int numAlarms, int wakeups, int[] uids, int[] alarmsPerUid, int[] wakeupAlarmsPerUid) {
        FrameworkStatsLog.write(
                FrameworkStatsLog.ALARM_BATCH_DELIVERED,
                numAlarms,
                wakeups);
                wakeups,
                uids,
                alarmsPerUid,
                wakeupAlarmsPerUid);
    }
}
+40 −0
Original line number Diff line number Diff line
@@ -264,6 +264,10 @@ public class AppStandbyController
    @GuardedBy("mActiveAdminApps")
    private final SparseArray<Set<String>> mActiveAdminApps = new SparseArray<>();

    /** List of admin protected packages. Can contain {@link android.os.UserHandle#USER_ALL}. */
    @GuardedBy("mAdminProtectedPackages")
    private final SparseArray<Set<String>> mAdminProtectedPackages = new SparseArray<>();

    /**
     * Set of system apps that are headless (don't have any "front door" activities, enabled or
     * disabled). Presence in this map indicates that the app is a headless system app.
@@ -1335,6 +1339,9 @@ public class AppStandbyController
            synchronized (mActiveAdminApps) {
                mActiveAdminApps.remove(userId);
            }
            synchronized (mAdminProtectedPackages) {
                mAdminProtectedPackages.remove(userId);
            }
        }
    }

@@ -1424,6 +1431,10 @@ public class AppStandbyController
                return STANDBY_BUCKET_EXEMPTED;
            }

            if (isAdminProtectedPackages(packageName, userId)) {
                return STANDBY_BUCKET_EXEMPTED;
            }

            if (isActiveNetworkScorer(packageName)) {
                return STANDBY_BUCKET_EXEMPTED;
            }
@@ -1871,6 +1882,17 @@ public class AppStandbyController
        }
    }

    private boolean isAdminProtectedPackages(String packageName, int userId) {
        synchronized (mAdminProtectedPackages) {
            if (mAdminProtectedPackages.contains(UserHandle.USER_ALL)
                    && mAdminProtectedPackages.get(UserHandle.USER_ALL).contains(packageName)) {
                return true;
            }
            return mAdminProtectedPackages.contains(userId)
                    && mAdminProtectedPackages.get(userId).contains(packageName);
        }
    }

    @Override
    public void addActiveDeviceAdmin(String adminPkg, int userId) {
        synchronized (mActiveAdminApps) {
@@ -1894,6 +1916,17 @@ public class AppStandbyController
        }
    }

    @Override
    public void setAdminProtectedPackages(Set<String> packageNames, int userId) {
        synchronized (mAdminProtectedPackages) {
            if (packageNames == null || packageNames.isEmpty()) {
                mAdminProtectedPackages.remove(userId);
            } else {
                mAdminProtectedPackages.put(userId, packageNames);
            }
        }
    }

    @Override
    public void onAdminDataAvailable() {
        mAdminDataAvailableLatch.countDown();
@@ -1916,6 +1949,13 @@ public class AppStandbyController
        }
    }

    @VisibleForTesting
    Set<String> getAdminProtectedPackagesForTest(int userId) {
        synchronized (mAdminProtectedPackages) {
            return mAdminProtectedPackages.get(userId);
        }
    }

    /**
     * Returns {@code true} if the supplied package is the device provisioning app. Otherwise,
     * returns {@code false}.
Loading