Loading apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java +3 −0 Original line number Diff line number Diff line Loading @@ -245,4 +245,7 @@ public interface AppStandbyInternal { */ @Nullable String getAppStandbyConstant(@NonNull String key); /** Clears the last used timestamps data for the given {@code packageName}. */ void clearLastUsedTimestampsForTest(@NonNull String packageName, @UserIdInt int userId); } apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java +11 −0 Original line number Diff line number Diff line Loading @@ -686,6 +686,17 @@ public class AppIdleHistory { Integer.toString(userId)), APP_IDLE_FILENAME); } void clearLastUsedTimestamps(String packageName, int userId) { ArrayMap<String, AppUsageHistory> userHistory = getUserHistory(userId); AppUsageHistory appUsageHistory = getPackageHistory(userHistory, packageName, SystemClock.elapsedRealtime(), false /* create */); if (appUsageHistory != null) { appUsageHistory.lastUsedByUserElapsedTime = Integer.MIN_VALUE; appUsageHistory.lastUsedElapsedTime = Integer.MIN_VALUE; appUsageHistory.lastUsedScreenTime = Integer.MIN_VALUE; } } /** * Check if App Idle File exists on disk * @param userId Loading apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java +7 −0 Original line number Diff line number Diff line Loading @@ -1856,6 +1856,13 @@ public class AppStandbyController return mAppStandbyProperties.get(key); } @Override public void clearLastUsedTimestampsForTest(@NonNull String packageName, @UserIdInt int userId) { synchronized (mAppIdleLock) { mAppIdleHistory.clearLastUsedTimestamps(packageName, userId); } } @Override public void flushToDisk() { synchronized (mAppIdleLock) { Loading services/usage/java/com/android/server/usage/UsageStatsService.java +13 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; Loading Loading @@ -1982,6 +1983,10 @@ public class UsageStatsService extends SystemService implements } } void clearLastUsedTimestamps(@NonNull String packageName, @UserIdInt int userId) { mAppStandby.clearLastUsedTimestampsForTest(packageName, userId); } private final class BinderService extends IUsageStatsManager.Stub { private boolean hasPermission(String callingPackage) { Loading Loading @@ -2816,6 +2821,14 @@ public class UsageStatsService extends SystemService implements } return mAppStandby.getAppStandbyConstant(key); } @Override public int handleShellCommand(@NonNull ParcelFileDescriptor in, @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, @NonNull String[] args) { return new UsageStatsShellCommand(UsageStatsService.this).exec(this, in.getFileDescriptor(), out.getFileDescriptor(), err.getFileDescriptor(), args); } } void registerAppUsageObserver(int callingUid, int observerId, String[] packages, Loading services/usage/java/com/android/server/usage/UsageStatsShellCommand.java 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.usage; import android.annotation.SuppressLint; import android.app.ActivityManager; import android.os.ShellCommand; import android.os.UserHandle; import java.io.PrintWriter; class UsageStatsShellCommand extends ShellCommand { private final UsageStatsService mService; UsageStatsShellCommand(UsageStatsService usageStatsService) { mService = usageStatsService; } @Override public int onCommand(String cmd) { if (cmd == null) { return handleDefaultCommands(null); } switch (cmd) { case "clear-last-used-timestamps": return runClearLastUsedTimestamps(); default: return handleDefaultCommands(cmd); } } @Override public void onHelp() { final PrintWriter pw = getOutPrintWriter(); pw.println("UsageStats service (usagestats) commands:"); pw.println("help"); pw.println(" Print this help text."); pw.println(); pw.println("clear-last-used-timestamps PACKAGE_NAME [-u | --user USER_ID]"); pw.println(" Clears any existing usage data for the given package."); pw.println(); } @SuppressLint("AndroidFrameworkRequiresPermission") private int runClearLastUsedTimestamps() { final String packageName = getNextArgRequired(); int userId = UserHandle.USER_CURRENT; String opt; while ((opt = getNextOption()) != null) { if ("-u".equals(opt) || "--user".equals(opt)) { userId = UserHandle.parseUserArg(getNextArgRequired()); } else { getErrPrintWriter().println("Error: unknown option: " + opt); return -1; } } if (userId == UserHandle.USER_CURRENT) { userId = ActivityManager.getCurrentUser(); } mService.clearLastUsedTimestamps(packageName, userId); return 0; } } Loading
apex/jobscheduler/framework/java/com/android/server/usage/AppStandbyInternal.java +3 −0 Original line number Diff line number Diff line Loading @@ -245,4 +245,7 @@ public interface AppStandbyInternal { */ @Nullable String getAppStandbyConstant(@NonNull String key); /** Clears the last used timestamps data for the given {@code packageName}. */ void clearLastUsedTimestampsForTest(@NonNull String packageName, @UserIdInt int userId); }
apex/jobscheduler/service/java/com/android/server/usage/AppIdleHistory.java +11 −0 Original line number Diff line number Diff line Loading @@ -686,6 +686,17 @@ public class AppIdleHistory { Integer.toString(userId)), APP_IDLE_FILENAME); } void clearLastUsedTimestamps(String packageName, int userId) { ArrayMap<String, AppUsageHistory> userHistory = getUserHistory(userId); AppUsageHistory appUsageHistory = getPackageHistory(userHistory, packageName, SystemClock.elapsedRealtime(), false /* create */); if (appUsageHistory != null) { appUsageHistory.lastUsedByUserElapsedTime = Integer.MIN_VALUE; appUsageHistory.lastUsedElapsedTime = Integer.MIN_VALUE; appUsageHistory.lastUsedScreenTime = Integer.MIN_VALUE; } } /** * Check if App Idle File exists on disk * @param userId Loading
apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java +7 −0 Original line number Diff line number Diff line Loading @@ -1856,6 +1856,13 @@ public class AppStandbyController return mAppStandbyProperties.get(key); } @Override public void clearLastUsedTimestampsForTest(@NonNull String packageName, @UserIdInt int userId) { synchronized (mAppIdleLock) { mAppIdleHistory.clearLastUsedTimestamps(packageName, userId); } } @Override public void flushToDisk() { synchronized (mAppIdleLock) { Loading
services/usage/java/com/android/server/usage/UsageStatsService.java +13 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.SystemClock; Loading Loading @@ -1982,6 +1983,10 @@ public class UsageStatsService extends SystemService implements } } void clearLastUsedTimestamps(@NonNull String packageName, @UserIdInt int userId) { mAppStandby.clearLastUsedTimestampsForTest(packageName, userId); } private final class BinderService extends IUsageStatsManager.Stub { private boolean hasPermission(String callingPackage) { Loading Loading @@ -2816,6 +2821,14 @@ public class UsageStatsService extends SystemService implements } return mAppStandby.getAppStandbyConstant(key); } @Override public int handleShellCommand(@NonNull ParcelFileDescriptor in, @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, @NonNull String[] args) { return new UsageStatsShellCommand(UsageStatsService.this).exec(this, in.getFileDescriptor(), out.getFileDescriptor(), err.getFileDescriptor(), args); } } void registerAppUsageObserver(int callingUid, int observerId, String[] packages, Loading
services/usage/java/com/android/server/usage/UsageStatsShellCommand.java 0 → 100644 +79 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.usage; import android.annotation.SuppressLint; import android.app.ActivityManager; import android.os.ShellCommand; import android.os.UserHandle; import java.io.PrintWriter; class UsageStatsShellCommand extends ShellCommand { private final UsageStatsService mService; UsageStatsShellCommand(UsageStatsService usageStatsService) { mService = usageStatsService; } @Override public int onCommand(String cmd) { if (cmd == null) { return handleDefaultCommands(null); } switch (cmd) { case "clear-last-used-timestamps": return runClearLastUsedTimestamps(); default: return handleDefaultCommands(cmd); } } @Override public void onHelp() { final PrintWriter pw = getOutPrintWriter(); pw.println("UsageStats service (usagestats) commands:"); pw.println("help"); pw.println(" Print this help text."); pw.println(); pw.println("clear-last-used-timestamps PACKAGE_NAME [-u | --user USER_ID]"); pw.println(" Clears any existing usage data for the given package."); pw.println(); } @SuppressLint("AndroidFrameworkRequiresPermission") private int runClearLastUsedTimestamps() { final String packageName = getNextArgRequired(); int userId = UserHandle.USER_CURRENT; String opt; while ((opt = getNextOption()) != null) { if ("-u".equals(opt) || "--user".equals(opt)) { userId = UserHandle.parseUserArg(getNextArgRequired()); } else { getErrPrintWriter().println("Error: unknown option: " + opt); return -1; } } if (userId == UserHandle.USER_CURRENT) { userId = ActivityManager.getCurrentUser(); } mService.clearLastUsedTimestamps(packageName, userId); return 0; } }