diff options
| author | 2025-01-12 21:19:29 +0000 | |
|---|---|---|
| committer | 2025-01-12 21:24:07 +0000 | |
| commit | bccf20331c4a75b99ea1fd3fbcf6d4ddd739ce6e (patch) | |
| tree | 1db255c92aa604128819db086047b1f09e5f811f | |
| parent | e452657bd578d6508e71efa3d5f517b4488505c4 (diff) | |
Delete dead code
We don't have any reference remaining to few function calls.
Removing that code to ensure line coverage
Bug: 326916057
Test: TH
Flag: EXEMPT code removal
Change-Id: I4633b0c113bbeec0d65a7c0dcd9da3e192eef779
4 files changed, 0 insertions, 269 deletions
diff --git a/packages/CrashRecovery/services/module/java/com/android/server/RescueParty.java b/packages/CrashRecovery/services/module/java/com/android/server/RescueParty.java index 40bc5f78a9c6..846da194b3c3 100644 --- a/packages/CrashRecovery/services/module/java/com/android/server/RescueParty.java +++ b/packages/CrashRecovery/services/module/java/com/android/server/RescueParty.java @@ -29,18 +29,13 @@ import android.content.pm.PackageManager; import android.content.pm.VersionedPackage; import android.crashrecovery.flags.Flags; import android.os.Build; -import android.os.Environment; import android.os.PowerManager; import android.os.RecoverySystem; import android.os.SystemClock; import android.os.SystemProperties; -import android.os.UserHandle; -import android.provider.DeviceConfig; import android.provider.Settings; import android.sysprop.CrashRecoveryProperties; import android.text.TextUtils; -import android.util.ArraySet; -import android.util.ArrayUtils; import android.util.EventLog; import android.util.FileUtils; import android.util.Log; @@ -56,10 +51,7 @@ import com.android.server.crashrecovery.proto.CrashRecoveryStatsLog; import java.io.File; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -241,87 +233,11 @@ public class RescueParty { CrashRecoveryProperties.maxRescueLevelAttempted(level); } - private static Set<String> getPresetNamespacesForPackages(List<String> packageNames) { - Set<String> resultSet = new ArraySet<String>(); - if (!Flags.deprecateFlagsAndSettingsResets()) { - try { - String flagVal = DeviceConfig.getString(NAMESPACE_CONFIGURATION, - NAMESPACE_TO_PACKAGE_MAPPING_FLAG, ""); - String[] mappingEntries = flagVal.split(","); - for (int i = 0; i < mappingEntries.length; i++) { - if (TextUtils.isEmpty(mappingEntries[i])) { - continue; - } - String[] splitEntry = mappingEntries[i].split(":"); - if (splitEntry.length != 2) { - throw new RuntimeException("Invalid mapping entry: " + mappingEntries[i]); - } - String namespace = splitEntry[0]; - String packageName = splitEntry[1]; - - if (packageNames.contains(packageName)) { - resultSet.add(namespace); - } - } - } catch (Exception e) { - resultSet.clear(); - Slog.e(TAG, "Failed to read preset package to namespaces mapping.", e); - } finally { - return resultSet; - } - } else { - return resultSet; - } - } - @VisibleForTesting static long getElapsedRealtime() { return SystemClock.elapsedRealtime(); } - private static class RescuePartyMonitorCallback implements DeviceConfig.MonitorCallback { - Context mContext; - - RescuePartyMonitorCallback(Context context) { - this.mContext = context; - } - - public void onNamespaceUpdate(@NonNull String updatedNamespace) { - if (!Flags.deprecateFlagsAndSettingsResets()) { - startObservingPackages(mContext, updatedNamespace); - } - } - - public void onDeviceConfigAccess(@NonNull String callingPackage, - @NonNull String namespace) { - - if (!Flags.deprecateFlagsAndSettingsResets()) { - RescuePartyObserver.getInstance(mContext).recordDeviceConfigAccess( - callingPackage, - namespace); - } - } - } - - private static void startObservingPackages(Context context, @NonNull String updatedNamespace) { - if (!Flags.deprecateFlagsAndSettingsResets()) { - RescuePartyObserver rescuePartyObserver = RescuePartyObserver.getInstance(context); - Set<String> callingPackages = rescuePartyObserver.getCallingPackagesSet( - updatedNamespace); - if (callingPackages == null) { - return; - } - List<String> callingPackageList = new ArrayList<>(); - callingPackageList.addAll(callingPackages); - Slog.i(TAG, "Starting to observe: " + callingPackageList + ", updated namespace: " - + updatedNamespace); - PackageWatchdog.getInstance(context).startExplicitHealthCheck( - callingPackageList, - DEFAULT_OBSERVING_DURATION_MS, - rescuePartyObserver); - } - } - private static int getMaxRescueLevel(boolean mayPerformReboot) { if (Flags.recoverabilityDetection()) { if (!mayPerformReboot @@ -849,34 +765,6 @@ public class RescueParty { } } - private synchronized void recordDeviceConfigAccess(@NonNull String callingPackage, - @NonNull String namespace) { - if (!Flags.deprecateFlagsAndSettingsResets()) { - // Record it in calling packages to namespace map - Set<String> namespaceSet = mCallingPackageNamespaceSetMap.get(callingPackage); - if (namespaceSet == null) { - namespaceSet = new ArraySet<>(); - mCallingPackageNamespaceSetMap.put(callingPackage, namespaceSet); - } - namespaceSet.add(namespace); - // Record it in namespace to calling packages map - Set<String> callingPackageSet = mNamespaceCallingPackageSetMap.get(namespace); - if (callingPackageSet == null) { - callingPackageSet = new ArraySet<>(); - } - callingPackageSet.add(callingPackage); - mNamespaceCallingPackageSetMap.put(namespace, callingPackageSet); - } - } - - private synchronized Set<String> getAffectedNamespaceSet(String failedPackage) { - return mCallingPackageNamespaceSetMap.get(failedPackage); - } - - private synchronized Set<String> getAllAffectedNamespaceSet() { - return new HashSet<String>(mNamespaceCallingPackageSetMap.keySet()); - } - private synchronized Set<String> getCallingPackagesSet(String namespace) { return mNamespaceCallingPackageSetMap.get(namespace); } @@ -894,26 +782,6 @@ public class RescueParty { return now < lastResetTime + TimeUnit.MINUTES.toMillis(throttleDurationMin); } - private static int[] getAllUserIds() { - int systemUserId = UserHandle.SYSTEM.getIdentifier(); - int[] userIds = { systemUserId }; - try { - for (File file : FileUtils.listFilesOrEmpty( - Environment.getDataSystemDeviceProtectedDirectory())) { - try { - final int userId = Integer.parseInt(file.getName()); - if (userId != systemUserId) { - userIds = ArrayUtils.appendInt(userIds, userId); - } - } catch (NumberFormatException ignored) { - } - } - } catch (Throwable t) { - Slog.w(TAG, "Trouble discovering users", t); - } - return userIds; - } - /** * Hacky test to check if the device has an active USB connection, which is * a good proxy for someone doing local development work. diff --git a/packages/CrashRecovery/services/module/java/com/android/util/ArrayUtils.java b/packages/CrashRecovery/services/module/java/com/android/util/ArrayUtils.java index 0b7b98603419..29ff7cced897 100644 --- a/packages/CrashRecovery/services/module/java/com/android/util/ArrayUtils.java +++ b/packages/CrashRecovery/services/module/java/com/android/util/ArrayUtils.java @@ -16,13 +16,8 @@ package android.util; -import android.annotation.NonNull; import android.annotation.Nullable; -import java.io.File; -import java.util.List; -import java.util.Objects; - /** * Copied over from frameworks/base/core/java/com/android/internal/util/ArrayUtils.java * @@ -30,25 +25,6 @@ import java.util.Objects; */ public class ArrayUtils { private ArrayUtils() { /* cannot be instantiated */ } - public static final File[] EMPTY_FILE = new File[0]; - - - /** - * Return first index of {@code value} in {@code array}, or {@code -1} if - * not found. - */ - public static <T> int indexOf(@Nullable T[] array, T value) { - if (array == null) return -1; - for (int i = 0; i < array.length; i++) { - if (Objects.equals(array[i], value)) return i; - } - return -1; - } - - /** @hide */ - public static @NonNull File[] defeatNullable(@Nullable File[] val) { - return (val != null) ? val : EMPTY_FILE; - } /** * Checks if given array is null or has zero elements. @@ -63,53 +39,4 @@ public class ArrayUtils { public static boolean isEmpty(@Nullable byte[] array) { return array == null || array.length == 0; } - - /** - * Converts from List of bytes to byte array - * @param list - * @return byte[] - */ - public static byte[] toPrimitive(List<byte[]> list) { - if (list.size() == 0) { - return new byte[0]; - } - int byteLen = list.get(0).length; - byte[] array = new byte[list.size() * byteLen]; - for (int i = 0; i < list.size(); i++) { - for (int j = 0; j < list.get(i).length; j++) { - array[i * byteLen + j] = list.get(i)[j]; - } - } - return array; - } - - /** - * Adds value to given array if not already present, providing set-like - * behavior. - */ - public static @NonNull int[] appendInt(@Nullable int[] cur, int val) { - return appendInt(cur, val, false); - } - - /** - * Adds value to given array. - */ - public static @NonNull int[] appendInt(@Nullable int[] cur, int val, - boolean allowDuplicates) { - if (cur == null) { - return new int[] { val }; - } - final int n = cur.length; - if (!allowDuplicates) { - for (int i = 0; i < n; i++) { - if (cur[i] == val) { - return cur; - } - } - } - int[] ret = new int[n + 1]; - System.arraycopy(cur, 0, ret, 0, n); - ret[n] = val; - return ret; - } } diff --git a/packages/CrashRecovery/services/module/java/com/android/util/FileUtils.java b/packages/CrashRecovery/services/module/java/com/android/util/FileUtils.java index 9c73feeffb6c..d60a9b9847ca 100644 --- a/packages/CrashRecovery/services/module/java/com/android/util/FileUtils.java +++ b/packages/CrashRecovery/services/module/java/com/android/util/FileUtils.java @@ -16,7 +16,6 @@ package android.util; -import android.annotation.NonNull; import android.annotation.Nullable; import java.io.BufferedInputStream; @@ -115,14 +114,4 @@ public class FileUtils { } return false; } - - /** - * List the files in the directory or return empty file. - * - * @hide - */ - public static @NonNull File[] listFilesOrEmpty(@Nullable File dir) { - return (dir != null) ? ArrayUtils.defeatNullable(dir.listFiles()) - : ArrayUtils.EMPTY_FILE; - } } diff --git a/packages/CrashRecovery/services/module/java/com/android/util/XmlUtils.java b/packages/CrashRecovery/services/module/java/com/android/util/XmlUtils.java index 50823f5c9c34..488b531c2b8a 100644 --- a/packages/CrashRecovery/services/module/java/com/android/util/XmlUtils.java +++ b/packages/CrashRecovery/services/module/java/com/android/util/XmlUtils.java @@ -16,21 +16,10 @@ package android.util; -import android.annotation.NonNull; -import android.system.ErrnoException; -import android.system.Os; - -import com.android.modules.utils.TypedXmlPullParser; - -import libcore.util.XmlObjectFactory; - import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; -import java.io.BufferedInputStream; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; /** * Bits and pieces copied from hidden API of @@ -40,8 +29,6 @@ import java.io.InputStream; */ public class XmlUtils { - private static final String STRING_ARRAY_SEPARATOR = ":"; - /** @hide */ public static final void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException { @@ -76,44 +63,4 @@ public class XmlUtils { } } } - - private static XmlPullParser newPullParser() { - try { - XmlPullParser parser = XmlObjectFactory.newXmlPullParser(); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true); - parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true); - return parser; - } catch (XmlPullParserException e) { - throw new AssertionError(); - } - } - - /** @hide */ - public static @NonNull TypedXmlPullParser resolvePullParser(@NonNull InputStream in) - throws IOException { - final byte[] magic = new byte[4]; - if (in instanceof FileInputStream) { - try { - Os.pread(((FileInputStream) in).getFD(), magic, 0, magic.length, 0); - } catch (ErrnoException e) { - throw e.rethrowAsIOException(); - } - } else { - if (!in.markSupported()) { - in = new BufferedInputStream(in); - } - in.mark(8); - in.read(magic); - in.reset(); - } - - final TypedXmlPullParser xml; - xml = (TypedXmlPullParser) newPullParser(); - try { - xml.setInput(in, "UTF_8"); - } catch (XmlPullParserException e) { - throw new IOException(e); - } - return xml; - } } |