Merge "Make a fallback tag for listener alarms" into tm-qpr-dev am: 7a2bfa7c30

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21342198

Change-Id: I0c843fcf20071c94e3cc5d16116f1b79a6d2a0a9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
TreeHugger Robot
2023-02-10 01:29:43 +00:00
committed by Automerger Merge Worker

View File

@@ -37,7 +37,9 @@ import android.os.Handler;
import android.os.HandlerExecutor; import android.os.HandlerExecutor;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle;
import android.os.WorkSource; import android.os.WorkSource;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -91,6 +93,14 @@ import java.util.concurrent.Executor;
public class AlarmManager { public class AlarmManager {
private static final String TAG = "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 */ /** @hide */
@IntDef(prefix = { "RTC", "ELAPSED" }, value = { @IntDef(prefix = { "RTC", "ELAPSED" }, value = {
RTC_WAKEUP, RTC_WAKEUP,
@@ -860,6 +870,24 @@ public class AlarmManager {
targetHandler, workSource, null); 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)}. * Direct callback version of {@link #set(int, long, long, long, PendingIntent, WorkSource)}.
* Note that repeating alarms must use the PendingIntent variant, not an OnAlarmListener. * 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, public void set(@AlarmType int type, long triggerAtMillis, long windowMillis,
long intervalMillis, OnAlarmListener listener, Handler targetHandler, long intervalMillis, OnAlarmListener listener, Handler targetHandler,
WorkSource workSource) { WorkSource workSource) {
setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener, null, setImpl(type, triggerAtMillis, windowMillis, intervalMillis, 0, null, listener,
targetHandler, workSource, null); makeTag(triggerAtMillis, workSource), targetHandler, workSource, null);
} }
/** /**