1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.connecteddevice.usb; 18 19 import android.content.Context; 20 import android.os.Handler; 21 import android.support.annotation.UiThread; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 import com.android.settings.core.PreferenceControllerMixin; 25 import com.android.settingslib.core.AbstractPreferenceController; 26 27 /** 28 * This class provides common members and refresh functionality for usb controllers. 29 */ 30 public abstract class UsbDetailsController extends AbstractPreferenceController 31 implements PreferenceControllerMixin { 32 33 protected final Context mContext; 34 protected final UsbDetailsFragment mFragment; 35 protected final UsbBackend mUsbBackend; 36 37 @VisibleForTesting 38 Handler mHandler; 39 40 public UsbDetailsController(Context context, UsbDetailsFragment fragment, UsbBackend backend) { 41 super(context); 42 mContext = context; 43 mFragment = fragment; 44 mUsbBackend = backend; 45 mHandler = new Handler(context.getMainLooper()); 46 } 47 48 @Override 49 public boolean isAvailable() { 50 return true; 51 } 52 53 /** 54 * Called when the USB state has changed, so that this component can be refreshed. 55 * 56 * @param connected Whether USB is connected 57 * @param functions A mask of the currently enabled functions 58 * @param powerRole The current power role 59 * @param dataRole The current data role 60 */ 61 @UiThread 62 protected abstract void refresh(boolean connected, long functions, int powerRole, int dataRole); 63 } 64