Update USB settings screen

Screen now handles data role and power
role switching as separate categories.

Change the UsbBackend api to use predefined
constants. Split out data and power direction
changes into separate functions.

Add tests for new controllers and new backend
functionality.

Bug: 72829348
Test: passes
Change-Id: I28b96cf49463fa4f3a4b6be41c57d5841731fbd6
This commit is contained in:
Jerry Zhang
2018-02-22 18:13:06 -08:00
parent 34bfe74249
commit 55d10dff53
23 changed files with 1510 additions and 747 deletions

View File

@@ -17,9 +17,10 @@
package com.android.settings.connecteddevice.usb;
import android.content.Context;
import android.os.Handler;
import android.support.annotation.UiThread;
import android.support.v14.preference.PreferenceFragment;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -30,14 +31,18 @@ public abstract class UsbDetailsController extends AbstractPreferenceController
implements PreferenceControllerMixin {
protected final Context mContext;
protected final PreferenceFragment mFragment;
protected final UsbDetailsFragment mFragment;
protected final UsbBackend mUsbBackend;
public UsbDetailsController(Context context, PreferenceFragment fragment, UsbBackend backend) {
@VisibleForTesting
Handler mHandler;
public UsbDetailsController(Context context, UsbDetailsFragment fragment, UsbBackend backend) {
super(context);
mContext = context;
mFragment = fragment;
mUsbBackend = backend;
mHandler = new Handler(context.getMainLooper());
}
@Override
@@ -46,9 +51,13 @@ public abstract class UsbDetailsController extends AbstractPreferenceController
}
/**
* This method is called when the USB mode has changed and the controller needs to update.
* @param newMode the new mode, made up of OR'd values from UsbBackend
* Called when the USB state has changed, so that this component can be refreshed.
*
* @param connected Whether USB is connected
* @param functions A mask of the currently enabled functions
* @param powerRole The current power role
* @param dataRole The current data role
*/
@UiThread
protected abstract void refresh(int newMode);
protected abstract void refresh(boolean connected, long functions, int powerRole, int dataRole);
}