From c61b1edc97ccbae2af500c50bfe480833a3845af Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Mon, 6 Jan 2020 16:26:05 -0800 Subject: [PATCH] [Telephony Mainline] Move CarrierAppUtils and LocationAccessPolicy to telephony common Bug: 146904426 Test: Build Change-Id: I6f6d24fd0adab803899b25a47199839bcbb09eb0 --- .../telephony/LocationAccessPolicy.java | 8 +++- .../internal/telephony/CarrierAppUtils.java | 37 ++++++++++--------- .../internal/telephony/util/ArrayUtils.java | 26 ++++++++++--- 3 files changed, 46 insertions(+), 25 deletions(-) rename telephony/{java => common}/android/telephony/LocationAccessPolicy.java (98%) rename telephony/{java => common}/com/android/internal/telephony/CarrierAppUtils.java (94%) rename telephony/{java => common}/com/android/internal/telephony/util/ArrayUtils.java (86%) diff --git a/telephony/java/android/telephony/LocationAccessPolicy.java b/telephony/common/android/telephony/LocationAccessPolicy.java similarity index 98% rename from telephony/java/android/telephony/LocationAccessPolicy.java rename to telephony/common/android/telephony/LocationAccessPolicy.java index 95aa101b8b2ce..f39981fdf25d0 100644 --- a/telephony/java/android/telephony/LocationAccessPolicy.java +++ b/telephony/common/android/telephony/LocationAccessPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 The Android Open Source Project + * Copyright (C) 2020 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. @@ -11,7 +11,7 @@ * 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 + * limitations under the License. */ package android.telephony; @@ -60,6 +60,7 @@ public final class LocationAccessPolicy { DENIED_HARD, } + /** Data structure for location permission query */ public static class LocationPermissionQuery { public final String callingPackage; public final String callingFeatureId; @@ -83,6 +84,7 @@ public final class LocationAccessPolicy { this.method = method; } + /** Builder for LocationPermissionQuery */ public static class Builder { private String mCallingPackage; private String mCallingFeatureId; @@ -161,6 +163,7 @@ public final class LocationAccessPolicy { return this; } + /** build LocationPermissionQuery */ public LocationPermissionQuery build() { return new LocationPermissionQuery(mCallingPackage, mCallingFeatureId, mCallingUid, mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine, @@ -258,6 +261,7 @@ public final class LocationAccessPolicy { } } + /** Check if location permissions have been granted */ public static LocationPermissionResult checkLocationPermission( Context context, LocationPermissionQuery query) { // Always allow the phone process and system server to access location. This avoid diff --git a/telephony/java/com/android/internal/telephony/CarrierAppUtils.java b/telephony/common/com/android/internal/telephony/CarrierAppUtils.java similarity index 94% rename from telephony/java/com/android/internal/telephony/CarrierAppUtils.java rename to telephony/common/com/android/internal/telephony/CarrierAppUtils.java index 2dc6ae3ff10b8..eb02ea6f5e40b 100644 --- a/telephony/java/com/android/internal/telephony/CarrierAppUtils.java +++ b/telephony/common/com/android/internal/telephony/CarrierAppUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Android Open Source Project + * Copyright (C) 2020 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. @@ -11,7 +11,7 @@ * 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 + * limitations under the License. */ package com.android.internal.telephony; @@ -74,7 +74,7 @@ public final class CarrierAppUtils { * system startup prior to any application running, as well as any time the set of carrier * privileged apps may have changed. */ - public synchronized static void disableCarrierAppsUntilPrivileged(String callingPackage, + public static synchronized void disableCarrierAppsUntilPrivileged(String callingPackage, IPackageManager packageManager, IPermissionManager permissionManager, TelephonyManager telephonyManager, ContentResolver contentResolver, int userId) { if (DEBUG) { @@ -101,7 +101,7 @@ public final class CarrierAppUtils { * broadcasts. The app will continue to run (briefly) after being disabled, before the Package * Manager can kill it, and this can lead to crashes as the app is in an unexpected state. */ - public synchronized static void disableCarrierAppsUntilPrivileged(String callingPackage, + public static synchronized void disableCarrierAppsUntilPrivileged(String callingPackage, IPackageManager packageManager, IPermissionManager permissionManager, ContentResolver contentResolver, int userId) { if (DEBUG) { @@ -119,7 +119,10 @@ public final class CarrierAppUtils { systemCarrierAppsDisabledUntilUsed, systemCarrierAssociatedAppsDisabledUntilUsed); } - // Must be public b/c framework unit tests can't access package-private methods. + /** + * Disable carrier apps until they are privileged + * Must be public b/c framework unit tests can't access package-private methods. + */ @VisibleForTesting public static void disableCarrierAppsUntilPrivileged(String callingPackage, IPackageManager packageManager, IPermissionManager permissionManager, @@ -169,10 +172,10 @@ public final class CarrierAppUtils { // Only update enabled state for the app on /system. Once it has been // updated we shouldn't touch it. if (!ai.isUpdatedSystemApp() - && (ai.enabledSetting == - PackageManager.COMPONENT_ENABLED_STATE_DEFAULT - || ai.enabledSetting == - PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED + && (ai.enabledSetting + == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT + || ai.enabledSetting + == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED || (ai.flags & ApplicationInfo.FLAG_INSTALLED) == 0)) { Rlog.i(TAG, "Update state(" + packageName + "): ENABLED for user " + userId); @@ -191,10 +194,10 @@ public final class CarrierAppUtils { // Also enable any associated apps for this carrier app. if (associatedAppList != null) { for (ApplicationInfo associatedApp : associatedAppList) { - if (associatedApp.enabledSetting == - PackageManager.COMPONENT_ENABLED_STATE_DEFAULT - || associatedApp.enabledSetting == - PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED + if (associatedApp.enabledSetting + == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT + || associatedApp.enabledSetting + == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED || (associatedApp.flags & ApplicationInfo.FLAG_INSTALLED) == 0) { Rlog.i(TAG, "Update associated state(" + associatedApp.packageName @@ -219,8 +222,8 @@ public final class CarrierAppUtils { // Only update enabled state for the app on /system. Once it has been // updated we shouldn't touch it. if (!ai.isUpdatedSystemApp() - && ai.enabledSetting == - PackageManager.COMPONENT_ENABLED_STATE_DEFAULT + && ai.enabledSetting + == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT && (ai.flags & ApplicationInfo.FLAG_INSTALLED) != 0) { Rlog.i(TAG, "Update state(" + packageName + "): DISABLED_UNTIL_USED for user " + userId); @@ -294,8 +297,8 @@ public final class CarrierAppUtils { ApplicationInfo ai = candidates.get(i); String packageName = ai.packageName; boolean hasPrivileges = - telephonyManager.checkCarrierPrivilegesForPackageAnyPhone(packageName) == - TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; + telephonyManager.checkCarrierPrivilegesForPackageAnyPhone(packageName) + == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; if (!hasPrivileges) { candidates.remove(i); } diff --git a/telephony/java/com/android/internal/telephony/util/ArrayUtils.java b/telephony/common/com/android/internal/telephony/util/ArrayUtils.java similarity index 86% rename from telephony/java/com/android/internal/telephony/util/ArrayUtils.java rename to telephony/common/com/android/internal/telephony/util/ArrayUtils.java index 2905125c69cc9..28401a6a7092b 100644 --- a/telephony/java/com/android/internal/telephony/util/ArrayUtils.java +++ b/telephony/common/com/android/internal/telephony/util/ArrayUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2020 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. @@ -29,17 +29,30 @@ public final class ArrayUtils { /** * Adds value to given array if not already present, providing set-like behavior. + * + * @param kind The class of the array elements. + * @param array The array to append to. + * @param element The array element to append. + * @return The array containing the appended element. */ @SuppressWarnings("unchecked") - public static @NonNull T[] appendElement(Class kind, @Nullable T[] array, T element) { + @NonNull + public static T[] appendElement(Class kind, @Nullable T[] array, T element) { return appendElement(kind, array, element, false); } /** * Adds value to given array. + * + * @param kind The class of the array elements. + * @param array The array to append to. + * @param element The array element to append. + * @param allowDuplicates Whether to allow duplicated elements in array. + * @return The array containing the appended element. */ @SuppressWarnings("unchecked") - public static @NonNull T[] appendElement(Class kind, @Nullable T[] array, T element, + @NonNull + public static T[] appendElement(Class kind, @Nullable T[] array, T element, boolean allowDuplicates) { final T[] result; final int end; @@ -59,13 +72,14 @@ public final class ArrayUtils { /** * Combine multiple arrays into a single array. * - * @param kind The class of the array elements + * @param kind The class of the array elements * @param arrays The arrays to combine - * @param The class of the array elements (inferred from kind). + * @param The class of the array elements (inferred from kind). * @return A single array containing all the elements of the parameter arrays. */ @SuppressWarnings("unchecked") - public static @NonNull T[] concatElements(Class kind, @Nullable T[]... arrays) { + @NonNull + public static T[] concatElements(Class kind, @Nullable T[]... arrays) { if (arrays == null || arrays.length == 0) { return createEmptyArray(kind); }