Android 12 では、IT 管理者が企業所有デバイスで USB 経由でのデータ シグナリングを無効にする機能が追加されています(充電機能を除く)。OEM がこの機能をサポートするには、USB HAL を更新し、Device Policy Manager API の追加サポートを利用する必要があります。
デバイス ポリシー マネージャー
USB 経由のシグナリングを無効にするために、次の 3 つの公開 API が DevicePolicyManager に含まれています。
setUsbDataSignalingEnabled(boolean enabled)は、UsbManagerでenableUsbDataSignalAPI を呼び出すことで USB データ シグナリングの有効と無効を切り替える API です。canUsbDataSignalingBeDisabled()は、USB データ シグナリングの有効化と無効化のどちらがデバイスでサポートされているかを確認する API です。isUsbDataSignalingEnabled()は、USB データ シグナリングが有効になっているかどうかを確認する API です。- これは、ポリシーの透明性ダイアログ ウィンドウが表示されているかどうかを確認するために必要です。システム ユーザーは、システム ユーザーが呼び出せるこの API の隠しバリアントを呼び出して、特定のユーザーに対して USB データ シグナリングが有効になっているかどうかを確認することができます。
- [設定] をタップします。
- [接続済みのデバイス] をタップします。
- [USB] をタップします。
デバイス ポリシー マネージャーの実装例
デバイス ポリシー マネージャーを実装する方法の例を次に示します。
class android.app.admin.DevicePolicyManager {
/**
* Called by device owner or profile owner of an organization-owned managed profile to
* enable or disable USB data signaling for the device. When disabled, USB data connections
* (except from charging functions) are prohibited.
*
* <p> This API is not supported on all devices, the caller should call
* {@link #canUsbDataSignalingBeDisabled()} to check whether enabling or disabling USB data
* signaling is supported on the device.
*
* @param enabled whether USB data signaling should be enabled or not.
* @throws SecurityException if the caller is not a device owner or a profile owner on
* an organization-owned managed profile.
* @throws IllegalStateException if disabling USB data signaling is not supported or
* if USB data signaling fails to be enabled/disabled.
*/
public void setUsbDataSignalingEnabled(boolean enabled);
/**
* Called by device owner or profile owner of an organization-owned managed profile to return
* whether USB data signaling is currently enabled by the admin.
*
* @return {@code true} if USB data signaling is enabled, {@code false} otherwise.
*/
public boolean isUsbDataSignalingEnabled();
/**
* Called by the system to check whether USB data signaling is currently enabled for this user.
*
* @param userId which user to check for.
* @return {@code true} if USB data signaling is enabled, {@code false} otherwise.
* @hide
*/
public boolean isUsbDataSignalingEnabledForUser(@UserIdInt int userId);
/**
* Returns whether enabling or disabling USB data signaling is supported on the device.
*
* @return {@code true} if the device supports enabling and disabling USB data signaling.
*/
public boolean canUsbDataSignalingBeDisabled();
設定
ユーザーは、USB が接続された直後に、USB の設定やテザリング設定を変更できます。USB 設定画面にアクセスする方法は次のとおりです。
注: USB が接続されていない場合、USB の設定は変更できず、[接続済みのデバイス] ウィンドウにも表示されません。
IT 管理者が会社所有デバイスで USB データ シグナリングを無効にした場合、ユーザーは USB 設定を変更できません。[設定] のすべての USB 設定が完全に無効になり、代わりにポリシーの透明性ダイアログ ウィンドウが作成されます。
注: USB データ シグナリングを無効にすると、USB デバッグ、デフォルトの USB 設定、USB オーディオ ルーティングの設定がすべて開発者向けオプションで無効になります。