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 22 import androidx.annotation.UiThread; 23 import androidx.annotation.VisibleForTesting; 24 25 import com.android.settings.core.PreferenceControllerMixin; 26 import com.android.settingslib.core.AbstractPreferenceController; 27 28 /** 29 * This class provides common members and refresh functionality for usb controllers. 30 */ 31 public abstract class UsbDetailsController extends AbstractPreferenceController 32 implements PreferenceControllerMixin { 33 34 protected final Context mContext; 35 protected final UsbDetailsFragment mFragment; 36 protected final UsbBackend mUsbBackend; 37 38 @VisibleForTesting 39 Handler mHandler; 40 UsbDetailsController(Context context, UsbDetailsFragment fragment, UsbBackend backend)41 public UsbDetailsController(Context context, UsbDetailsFragment fragment, UsbBackend backend) { 42 super(context); 43 mContext = context; 44 mFragment = fragment; 45 mUsbBackend = backend; 46 mHandler = new Handler(context.getMainLooper()); 47 } 48 49 @Override isAvailable()50 public boolean isAvailable() { 51 return true; 52 } 53 54 /** 55 * Called when the USB state has changed, so that this component can be refreshed. 56 * 57 * @param connected Whether USB is connected 58 * @param functions A mask of the currently enabled functions 59 * @param powerRole The current power role 60 * @param dataRole The current data role 61 */ 62 @UiThread refresh(boolean connected, long functions, int powerRole, int dataRole)63 protected abstract void refresh(boolean connected, long functions, int powerRole, int dataRole); 64 } 65