[CDM perm sync] Add feature flag check for perm sync APIs
Bug: 193583135 Test: manually tested the APIs Change-Id: Ifb02bfb773328a90b664d7b493dc8d22c1c8a978
This commit is contained in:
@@ -25,6 +25,7 @@ import android.annotation.IntDef;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.RequiresPermission;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.SystemService;
|
||||
import android.annotation.UserHandleAware;
|
||||
@@ -33,6 +34,7 @@ import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.companion.utils.FeatureUtils;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -81,6 +83,7 @@ import java.util.function.Consumer;
|
||||
* @see CompanionDeviceManager#associate
|
||||
* @see AssociationRequest
|
||||
*/
|
||||
@SuppressLint("LongLogTag")
|
||||
@SystemService(Context.COMPANION_DEVICE_SERVICE)
|
||||
public final class CompanionDeviceManager {
|
||||
|
||||
@@ -876,8 +879,12 @@ public final class CompanionDeviceManager {
|
||||
|
||||
/** {@hide} */
|
||||
@RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES)
|
||||
public final void attachSystemDataTransport(int associationId, @NonNull InputStream in,
|
||||
public void attachSystemDataTransport(int associationId, @NonNull InputStream in,
|
||||
@NonNull OutputStream out) throws DeviceNotAssociatedException {
|
||||
if (!FeatureUtils.isPermSyncEnabled()) {
|
||||
Log.e(LOG_TAG, "Calling attachSystemDataTransport, but perm sync is disabled.");
|
||||
return;
|
||||
}
|
||||
synchronized (mTransports) {
|
||||
if (mTransports.contains(associationId)) {
|
||||
detachSystemDataTransport(associationId);
|
||||
@@ -895,8 +902,12 @@ public final class CompanionDeviceManager {
|
||||
|
||||
/** {@hide} */
|
||||
@RequiresPermission(android.Manifest.permission.DELIVER_COMPANION_MESSAGES)
|
||||
public final void detachSystemDataTransport(int associationId)
|
||||
public void detachSystemDataTransport(int associationId)
|
||||
throws DeviceNotAssociatedException {
|
||||
if (!FeatureUtils.isPermSyncEnabled()) {
|
||||
Log.e(LOG_TAG, "Calling detachSystemDataTransport, but perm sync is disabled.");
|
||||
return;
|
||||
}
|
||||
synchronized (mTransports) {
|
||||
final Transport transport = mTransports.get(associationId);
|
||||
if (transport != null) {
|
||||
@@ -1004,6 +1015,11 @@ public final class CompanionDeviceManager {
|
||||
@Nullable
|
||||
public IntentSender buildPermissionTransferUserConsentIntent(int associationId)
|
||||
throws DeviceNotAssociatedException {
|
||||
if (!FeatureUtils.isPermSyncEnabled()) {
|
||||
Log.e(LOG_TAG, "Calling buildPermissionTransferUserConsentIntent,"
|
||||
+ " but perm sync is disabled.");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
PendingIntent pendingIntent = mService.buildPermissionTransferUserConsentIntent(
|
||||
mContext.getOpPackageName(),
|
||||
@@ -1036,6 +1052,10 @@ public final class CompanionDeviceManager {
|
||||
@Deprecated
|
||||
@UserHandleAware
|
||||
public void startSystemDataTransfer(int associationId) throws DeviceNotAssociatedException {
|
||||
if (!FeatureUtils.isPermSyncEnabled()) {
|
||||
Log.e(LOG_TAG, "Calling startSystemDataTransfer, but perm sync is disabled.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
mService.startSystemDataTransfer(mContext.getOpPackageName(), mContext.getUserId(),
|
||||
associationId, null);
|
||||
|
||||
40
core/java/android/companion/utils/FeatureUtils.java
Normal file
40
core/java/android/companion/utils/FeatureUtils.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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 android.companion.utils;
|
||||
|
||||
import android.os.Build;
|
||||
import android.provider.DeviceConfig;
|
||||
|
||||
/**
|
||||
* Util class for feature flags
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class FeatureUtils {
|
||||
|
||||
private static final String NAMESPACE_COMPANION = "companion";
|
||||
|
||||
private static final String PROPERTY_PERM_SYNC_ENABLED = "perm_sync_enabled";
|
||||
|
||||
public static boolean isPermSyncEnabled() {
|
||||
return Build.isDebuggable() || DeviceConfig.getBoolean(NAMESPACE_COMPANION,
|
||||
PROPERTY_PERM_SYNC_ENABLED, false);
|
||||
}
|
||||
|
||||
private FeatureUtils() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user