Loading core/java/android/companion/CompanionDeviceManager.java +22 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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 { Loading Loading @@ -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); Loading @@ -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) { Loading Loading @@ -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(), Loading Loading @@ -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); Loading core/java/android/companion/utils/FeatureUtils.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * 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() { } } Loading
core/java/android/companion/CompanionDeviceManager.java +22 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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 { Loading Loading @@ -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); Loading @@ -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) { Loading Loading @@ -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(), Loading Loading @@ -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); Loading
core/java/android/companion/utils/FeatureUtils.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * 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() { } }