Merge "[Telephony Mainline] Move CarrierAppUtils and LocationAccessPolicy to telephony common"
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package android.telephony;
|
package android.telephony;
|
||||||
@@ -59,6 +59,7 @@ public final class LocationAccessPolicy {
|
|||||||
DENIED_HARD,
|
DENIED_HARD,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Data structure for location permission query */
|
||||||
public static class LocationPermissionQuery {
|
public static class LocationPermissionQuery {
|
||||||
public final String callingPackage;
|
public final String callingPackage;
|
||||||
public final int callingUid;
|
public final int callingUid;
|
||||||
@@ -80,6 +81,7 @@ public final class LocationAccessPolicy {
|
|||||||
this.method = method;
|
this.method = method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Builder for LocationPermissionQuery */
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private String mCallingPackage;
|
private String mCallingPackage;
|
||||||
private int mCallingUid;
|
private int mCallingUid;
|
||||||
@@ -149,6 +151,7 @@ public final class LocationAccessPolicy {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** build LocationPermissionQuery */
|
||||||
public LocationPermissionQuery build() {
|
public LocationPermissionQuery build() {
|
||||||
return new LocationPermissionQuery(mCallingPackage, mCallingUid,
|
return new LocationPermissionQuery(mCallingPackage, mCallingUid,
|
||||||
mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine,
|
mCallingPid, mMinSdkVersionForCoarse, mMinSdkVersionForFine,
|
||||||
@@ -235,6 +238,7 @@ public final class LocationAccessPolicy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check if location permissions have been granted */
|
||||||
public static LocationPermissionResult checkLocationPermission(
|
public static LocationPermissionResult checkLocationPermission(
|
||||||
Context context, LocationPermissionQuery query) {
|
Context context, LocationPermissionQuery query) {
|
||||||
// Always allow the phone process and system server to access location. This avoid
|
// Always allow the phone process and system server to access location. This avoid
|
||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.internal.telephony;
|
package com.android.internal.telephony;
|
||||||
@@ -73,7 +73,7 @@ public final class CarrierAppUtils {
|
|||||||
* system startup prior to any application running, as well as any time the set of carrier
|
* system startup prior to any application running, as well as any time the set of carrier
|
||||||
* privileged apps may have changed.
|
* privileged apps may have changed.
|
||||||
*/
|
*/
|
||||||
public synchronized static void disableCarrierAppsUntilPrivileged(String callingPackage,
|
public static synchronized void disableCarrierAppsUntilPrivileged(String callingPackage,
|
||||||
IPackageManager packageManager, TelephonyManager telephonyManager,
|
IPackageManager packageManager, TelephonyManager telephonyManager,
|
||||||
ContentResolver contentResolver, int userId) {
|
ContentResolver contentResolver, int userId) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@@ -100,7 +100,7 @@ public final class CarrierAppUtils {
|
|||||||
* broadcasts. The app will continue to run (briefly) after being disabled, before the Package
|
* 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.
|
* 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, ContentResolver contentResolver, int userId) {
|
IPackageManager packageManager, ContentResolver contentResolver, int userId) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "disableCarrierAppsUntilPrivileged");
|
Slog.d(TAG, "disableCarrierAppsUntilPrivileged");
|
||||||
@@ -117,7 +117,10 @@ public final class CarrierAppUtils {
|
|||||||
systemCarrierAppsDisabledUntilUsed, systemCarrierAssociatedAppsDisabledUntilUsed);
|
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
|
@VisibleForTesting
|
||||||
public static void disableCarrierAppsUntilPrivileged(String callingPackage,
|
public static void disableCarrierAppsUntilPrivileged(String callingPackage,
|
||||||
IPackageManager packageManager, @Nullable TelephonyManager telephonyManager,
|
IPackageManager packageManager, @Nullable TelephonyManager telephonyManager,
|
||||||
@@ -166,10 +169,10 @@ public final class CarrierAppUtils {
|
|||||||
// Only update enabled state for the app on /system. Once it has been
|
// Only update enabled state for the app on /system. Once it has been
|
||||||
// updated we shouldn't touch it.
|
// updated we shouldn't touch it.
|
||||||
if (!ai.isUpdatedSystemApp()
|
if (!ai.isUpdatedSystemApp()
|
||||||
&& (ai.enabledSetting ==
|
&& (ai.enabledSetting
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
== PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
||||||
|| ai.enabledSetting ==
|
|| ai.enabledSetting
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
|
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
|
||||||
|| (ai.flags & ApplicationInfo.FLAG_INSTALLED) == 0)) {
|
|| (ai.flags & ApplicationInfo.FLAG_INSTALLED) == 0)) {
|
||||||
Slog.i(TAG, "Update state(" + packageName + "): ENABLED for user "
|
Slog.i(TAG, "Update state(" + packageName + "): ENABLED for user "
|
||||||
+ userId);
|
+ userId);
|
||||||
@@ -188,10 +191,10 @@ public final class CarrierAppUtils {
|
|||||||
// Also enable any associated apps for this carrier app.
|
// Also enable any associated apps for this carrier app.
|
||||||
if (associatedAppList != null) {
|
if (associatedAppList != null) {
|
||||||
for (ApplicationInfo associatedApp : associatedAppList) {
|
for (ApplicationInfo associatedApp : associatedAppList) {
|
||||||
if (associatedApp.enabledSetting ==
|
if (associatedApp.enabledSetting
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
== PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
||||||
|| associatedApp.enabledSetting ==
|
|| associatedApp.enabledSetting
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
|
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED
|
||||||
|| (associatedApp.flags
|
|| (associatedApp.flags
|
||||||
& ApplicationInfo.FLAG_INSTALLED) == 0) {
|
& ApplicationInfo.FLAG_INSTALLED) == 0) {
|
||||||
Slog.i(TAG, "Update associated state(" + associatedApp.packageName
|
Slog.i(TAG, "Update associated state(" + associatedApp.packageName
|
||||||
@@ -216,8 +219,8 @@ public final class CarrierAppUtils {
|
|||||||
// Only update enabled state for the app on /system. Once it has been
|
// Only update enabled state for the app on /system. Once it has been
|
||||||
// updated we shouldn't touch it.
|
// updated we shouldn't touch it.
|
||||||
if (!ai.isUpdatedSystemApp()
|
if (!ai.isUpdatedSystemApp()
|
||||||
&& ai.enabledSetting ==
|
&& ai.enabledSetting
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
== PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
|
||||||
&& (ai.flags & ApplicationInfo.FLAG_INSTALLED) != 0) {
|
&& (ai.flags & ApplicationInfo.FLAG_INSTALLED) != 0) {
|
||||||
Slog.i(TAG, "Update state(" + packageName
|
Slog.i(TAG, "Update state(" + packageName
|
||||||
+ "): DISABLED_UNTIL_USED for user " + userId);
|
+ "): DISABLED_UNTIL_USED for user " + userId);
|
||||||
@@ -291,8 +294,8 @@ public final class CarrierAppUtils {
|
|||||||
ApplicationInfo ai = candidates.get(i);
|
ApplicationInfo ai = candidates.get(i);
|
||||||
String packageName = ai.packageName;
|
String packageName = ai.packageName;
|
||||||
boolean hasPrivileges =
|
boolean hasPrivileges =
|
||||||
telephonyManager.checkCarrierPrivilegesForPackageAnyPhone(packageName) ==
|
telephonyManager.checkCarrierPrivilegesForPackageAnyPhone(packageName)
|
||||||
TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
|
== TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
|
||||||
if (!hasPrivileges) {
|
if (!hasPrivileges) {
|
||||||
candidates.remove(i);
|
candidates.remove(i);
|
||||||
}
|
}
|
||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.
|
* 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")
|
@SuppressWarnings("unchecked")
|
||||||
public static @NonNull <T> T[] appendElement(Class<T> kind, @Nullable T[] array, T element) {
|
@NonNull
|
||||||
|
public static <T> T[] appendElement(Class<T> kind, @Nullable T[] array, T element) {
|
||||||
return appendElement(kind, array, element, false);
|
return appendElement(kind, array, element, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds value to given array.
|
* 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")
|
@SuppressWarnings("unchecked")
|
||||||
public static @NonNull <T> T[] appendElement(Class<T> kind, @Nullable T[] array, T element,
|
@NonNull
|
||||||
|
public static <T> T[] appendElement(Class<T> kind, @Nullable T[] array, T element,
|
||||||
boolean allowDuplicates) {
|
boolean allowDuplicates) {
|
||||||
final T[] result;
|
final T[] result;
|
||||||
final int end;
|
final int end;
|
||||||
@@ -59,13 +72,14 @@ public final class ArrayUtils {
|
|||||||
/**
|
/**
|
||||||
* Combine multiple arrays into a single array.
|
* 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 arrays The arrays to combine
|
||||||
* @param <T> The class of the array elements (inferred from kind).
|
* @param <T> The class of the array elements (inferred from kind).
|
||||||
* @return A single array containing all the elements of the parameter arrays.
|
* @return A single array containing all the elements of the parameter arrays.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static @NonNull <T> T[] concatElements(Class<T> kind, @Nullable T[]... arrays) {
|
@NonNull
|
||||||
|
public static <T> T[] concatElements(Class<T> kind, @Nullable T[]... arrays) {
|
||||||
if (arrays == null || arrays.length == 0) {
|
if (arrays == null || arrays.length == 0) {
|
||||||
return createEmptyArray(kind);
|
return createEmptyArray(kind);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user