resolve merge conflicts of 7849607a7c to pi-dev-plus-aosp

Bug: 115707279
Test: I solemnly swear I tested this conflict resolution.
Change-Id: Ifd8f2c090ccd9eadbc7b789b927550bce732f1d1
Merged-In: I3d2ebad2879479a870bcdfe596bb88b83c424389
This commit is contained in:
Lei Yu
2018-10-25 14:20:08 -07:00
4 changed files with 202 additions and 25 deletions

View File

@@ -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 com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.nano.MetricsProto;
@@ -39,11 +44,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
@@ -103,9 +115,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();
}
}
}

View File

@@ -16,9 +16,14 @@
package com.android.settings.connecteddevice.usb;
import static android.net.ConnectivityManager.TETHERING_USB;
import android.content.Context;
import android.hardware.usb.UsbManager;
import android.hardware.usb.UsbPort;
import android.net.ConnectivityManager;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@@ -46,10 +51,18 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
}
private PreferenceCategory mProfilesContainer;
private ConnectivityManager mConnectivityManager;
@VisibleForTesting
OnStartTetheringCallback mOnStartTetheringCallback;
@VisibleForTesting
long mPreviousFunction;
public UsbDetailsFunctionsController(Context context, UsbDetailsFragment fragment,
UsbBackend backend) {
super(context, fragment, backend);
mConnectivityManager = context.getSystemService(ConnectivityManager.class);
mOnStartTetheringCallback = new OnStartTetheringCallback();
mPreviousFunction = mUsbBackend.getCurrentFunctions();
}
@Override
@@ -96,9 +109,28 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
@Override
public void onRadioButtonClicked(RadioButtonPreference preference) {
long function = UsbBackend.usbFunctionsFromString(preference.getKey());
if (function != mUsbBackend.getCurrentFunctions() && !Utils.isMonkeyRunning()) {
mUsbBackend.setCurrentFunctions(function);
final long function = UsbBackend.usbFunctionsFromString(preference.getKey());
final long previousFunction = mUsbBackend.getCurrentFunctions();
if (function != previousFunction && !Utils.isMonkeyRunning()) {
mPreviousFunction = previousFunction;
if (function == UsbManager.FUNCTION_RNDIS) {
//Update the UI in advance to make it looks smooth
final RadioButtonPreference prevPref =
(RadioButtonPreference) mProfilesContainer.findPreference(
UsbBackend.usbFunctionsToString(mPreviousFunction));
if (prevPref != null) {
prevPref.setChecked(false);
preference.setChecked(true);
}
// We need to have entitlement check for usb tethering, so use API in
// ConnectivityManager.
mConnectivityManager.startTethering(TETHERING_USB, true /* showProvisioningUi */,
mOnStartTetheringCallback);
} else {
mUsbBackend.setCurrentFunctions(function);
}
}
}
@@ -111,4 +143,15 @@ public class UsbDetailsFunctionsController extends UsbDetailsController
public String getPreferenceKey() {
return "usb_details_functions";
}
@VisibleForTesting
final class OnStartTetheringCallback extends
ConnectivityManager.OnStartTetheringCallback {
@Override
public void onTetheringFailed() {
super.onTetheringFailed();
mUsbBackend.setCurrentFunctions(mPreviousFunction);
}
}
}