Add entitlement check for usb tethering
Before this CL, usb tethering in detail page doesn't have entitlement check. This CL fix it by using the correct API Also polish it by updating the UI before entitlement check to align hotspot page. So in UI it will first check "usb tethering". If entitlement check fail, it will revoke and go back to previous selection. Bug: 115707279 Test: RunSettingsRoboTests Change-Id: I3d2ebad2879479a870bcdfe596bb88b83c424389
This commit is contained in:
@@ -16,9 +16,14 @@
|
||||
|
||||
package com.android.settings.connecteddevice.usb;
|
||||
|
||||
import static android.net.ConnectivityManager.TETHERING_USB;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
@@ -40,11 +45,18 @@ import java.util.List;
|
||||
public class UsbDefaultFragment extends RadioButtonPickerFragment {
|
||||
@VisibleForTesting
|
||||
UsbBackend mUsbBackend;
|
||||
@VisibleForTesting
|
||||
ConnectivityManager mConnectivityManager;
|
||||
@VisibleForTesting
|
||||
OnStartTetheringCallback mOnStartTetheringCallback = new OnStartTetheringCallback();
|
||||
@VisibleForTesting
|
||||
long mPreviousFunctions;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mUsbBackend = new UsbBackend(context);
|
||||
mConnectivityManager = context.getSystemService(ConnectivityManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,9 +117,37 @@ public class UsbDefaultFragment extends RadioButtonPickerFragment {
|
||||
@Override
|
||||
protected boolean setDefaultKey(String key) {
|
||||
long functions = UsbBackend.usbFunctionsFromString(key);
|
||||
mPreviousFunctions = mUsbBackend.getCurrentFunctions();
|
||||
if (!Utils.isMonkeyRunning()) {
|
||||
mUsbBackend.setDefaultUsbFunctions(functions);
|
||||
if (functions == UsbManager.FUNCTION_RNDIS) {
|
||||
// We need to have entitlement check for usb tethering, so use API in
|
||||
// ConnectivityManager.
|
||||
mConnectivityManager.startTethering(TETHERING_USB, true /* showProvisioningUi */,
|
||||
mOnStartTetheringCallback);
|
||||
} else {
|
||||
mUsbBackend.setDefaultUsbFunctions(functions);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
final class OnStartTetheringCallback extends
|
||||
ConnectivityManager.OnStartTetheringCallback {
|
||||
|
||||
@Override
|
||||
public void onTetheringStarted() {
|
||||
super.onTetheringStarted();
|
||||
// Set default usb functions again to make internal data persistent
|
||||
mUsbBackend.setDefaultUsbFunctions(UsbManager.FUNCTION_RNDIS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTetheringFailed() {
|
||||
super.onTetheringFailed();
|
||||
mUsbBackend.setDefaultUsbFunctions(mPreviousFunctions);
|
||||
updateCandidates();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user