Loading core/java/android/app/usage/UsageEventsQuery.java +22 −0 Original line number Diff line number Diff line Loading @@ -19,9 +19,11 @@ package android.app.usage; import android.annotation.CurrentTimeMillisLong; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.UserIdInt; import android.app.usage.UsageEvents.Event; import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; import android.util.ArraySet; import com.android.internal.util.ArrayUtils; Loading @@ -40,11 +42,13 @@ public final class UsageEventsQuery implements Parcelable { private final @CurrentTimeMillisLong long mBeginTimeMillis; private final @CurrentTimeMillisLong long mEndTimeMillis; private final @Event.EventType int[] mEventTypes; private final @UserIdInt int mUserId; private UsageEventsQuery(@NonNull Builder builder) { mBeginTimeMillis = builder.mBeginTimeMillis; mEndTimeMillis = builder.mEndTimeMillis; mEventTypes = ArrayUtils.convertToIntArray(builder.mEventTypes); mUserId = builder.mUserId; } private UsageEventsQuery(Parcel in) { Loading @@ -53,6 +57,7 @@ public final class UsageEventsQuery implements Parcelable { int eventTypesLength = in.readInt(); mEventTypes = new int[eventTypesLength]; in.readIntArray(mEventTypes); mUserId = in.readInt(); } /** Loading Loading @@ -87,6 +92,11 @@ public final class UsageEventsQuery implements Parcelable { return eventTypeSet; } /** @hide */ public @UserIdInt int getUserId() { return mUserId; } @Override public int describeContents() { return 0; Loading @@ -98,6 +108,7 @@ public final class UsageEventsQuery implements Parcelable { dest.writeLong(mEndTimeMillis); dest.writeInt(mEventTypes.length); dest.writeIntArray(mEventTypes); dest.writeInt(mUserId); } @NonNull Loading Loading @@ -126,6 +137,7 @@ public final class UsageEventsQuery implements Parcelable { private final @CurrentTimeMillisLong long mBeginTimeMillis; private final @CurrentTimeMillisLong long mEndTimeMillis; private final ArraySet<Integer> mEventTypes = new ArraySet<>(); private @UserIdInt int mUserId = UserHandle.USER_NULL; /** * Constructor that specifies the period for which to return events. Loading Loading @@ -169,5 +181,15 @@ public final class UsageEventsQuery implements Parcelable { } return this; } /** * Specifices the user id for the query. * @param userId for whom the query should be performed. * @hide */ public @NonNull Builder setUserId(@UserIdInt int userId) { mUserId = userId; return this; } } } services/usage/java/com/android/server/usage/UsageStatsService.java +13 −1 Original line number Diff line number Diff line Loading @@ -2395,7 +2395,19 @@ public class UsageStatsService extends SystemService implements return null; } return queryEventsHelper(UserHandle.getCallingUserId(), query.getBeginTimeMillis(), final int callingUserId = UserHandle.getCallingUserId(); int userId = query.getUserId(); if (userId == UserHandle.USER_NULL) { // Convert userId to actual user Id if not specified in the query object. userId = callingUserId; } if (userId != callingUserId) { getContext().enforceCallingPermission( Manifest.permission.INTERACT_ACROSS_USERS_FULL, "No permission to query usage stats for user " + userId); } return queryEventsHelper(userId, query.getBeginTimeMillis(), query.getEndTimeMillis(), callingPackage, query.getEventTypeFilter()); } Loading Loading
core/java/android/app/usage/UsageEventsQuery.java +22 −0 Original line number Diff line number Diff line Loading @@ -19,9 +19,11 @@ package android.app.usage; import android.annotation.CurrentTimeMillisLong; import android.annotation.FlaggedApi; import android.annotation.NonNull; import android.annotation.UserIdInt; import android.app.usage.UsageEvents.Event; import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; import android.util.ArraySet; import com.android.internal.util.ArrayUtils; Loading @@ -40,11 +42,13 @@ public final class UsageEventsQuery implements Parcelable { private final @CurrentTimeMillisLong long mBeginTimeMillis; private final @CurrentTimeMillisLong long mEndTimeMillis; private final @Event.EventType int[] mEventTypes; private final @UserIdInt int mUserId; private UsageEventsQuery(@NonNull Builder builder) { mBeginTimeMillis = builder.mBeginTimeMillis; mEndTimeMillis = builder.mEndTimeMillis; mEventTypes = ArrayUtils.convertToIntArray(builder.mEventTypes); mUserId = builder.mUserId; } private UsageEventsQuery(Parcel in) { Loading @@ -53,6 +57,7 @@ public final class UsageEventsQuery implements Parcelable { int eventTypesLength = in.readInt(); mEventTypes = new int[eventTypesLength]; in.readIntArray(mEventTypes); mUserId = in.readInt(); } /** Loading Loading @@ -87,6 +92,11 @@ public final class UsageEventsQuery implements Parcelable { return eventTypeSet; } /** @hide */ public @UserIdInt int getUserId() { return mUserId; } @Override public int describeContents() { return 0; Loading @@ -98,6 +108,7 @@ public final class UsageEventsQuery implements Parcelable { dest.writeLong(mEndTimeMillis); dest.writeInt(mEventTypes.length); dest.writeIntArray(mEventTypes); dest.writeInt(mUserId); } @NonNull Loading Loading @@ -126,6 +137,7 @@ public final class UsageEventsQuery implements Parcelable { private final @CurrentTimeMillisLong long mBeginTimeMillis; private final @CurrentTimeMillisLong long mEndTimeMillis; private final ArraySet<Integer> mEventTypes = new ArraySet<>(); private @UserIdInt int mUserId = UserHandle.USER_NULL; /** * Constructor that specifies the period for which to return events. Loading Loading @@ -169,5 +181,15 @@ public final class UsageEventsQuery implements Parcelable { } return this; } /** * Specifices the user id for the query. * @param userId for whom the query should be performed. * @hide */ public @NonNull Builder setUserId(@UserIdInt int userId) { mUserId = userId; return this; } } }
services/usage/java/com/android/server/usage/UsageStatsService.java +13 −1 Original line number Diff line number Diff line Loading @@ -2395,7 +2395,19 @@ public class UsageStatsService extends SystemService implements return null; } return queryEventsHelper(UserHandle.getCallingUserId(), query.getBeginTimeMillis(), final int callingUserId = UserHandle.getCallingUserId(); int userId = query.getUserId(); if (userId == UserHandle.USER_NULL) { // Convert userId to actual user Id if not specified in the query object. userId = callingUserId; } if (userId != callingUserId) { getContext().enforceCallingPermission( Manifest.permission.INTERACT_ACROSS_USERS_FULL, "No permission to query usage stats for user " + userId); } return queryEventsHelper(userId, query.getBeginTimeMillis(), query.getEndTimeMillis(), callingPackage, query.getEventTypeFilter()); } Loading