1 /* 2 * Copyright (C) 2017 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.bluetooth; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.content.pm.PackageManager; 23 24 import androidx.annotation.VisibleForTesting; 25 import androidx.preference.Preference; 26 27 import com.android.settings.core.BasePreferenceController; 28 import com.android.settings.core.PreferenceControllerMixin; 29 import com.android.settings.overlay.FeatureFactory; 30 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; 31 32 /** 33 * Controller that shows received files 34 */ 35 public class BluetoothFilesPreferenceController extends BasePreferenceController 36 implements PreferenceControllerMixin { 37 private static final String TAG = "BluetoothFilesPrefCtrl"; 38 39 public static final String KEY_RECEIVED_FILES = "bt_received_files"; 40 41 /* Private intent to show the list of received files */ 42 @VisibleForTesting 43 static final String ACTION_OPEN_FILES = "com.android.bluetooth.action.TransferHistory"; 44 @VisibleForTesting 45 static final String EXTRA_SHOW_ALL_FILES = "android.btopp.intent.extra.SHOW_ALL"; 46 @VisibleForTesting 47 static final String EXTRA_DIRECTION = "direction"; 48 49 private MetricsFeatureProvider mMetricsFeatureProvider; 50 BluetoothFilesPreferenceController(Context context)51 public BluetoothFilesPreferenceController(Context context) { 52 super(context, KEY_RECEIVED_FILES); 53 mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); 54 } 55 56 @Override getAvailabilityStatus()57 public int getAvailabilityStatus() { 58 return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH) 59 ? AVAILABLE 60 : UNSUPPORTED_ON_DEVICE; 61 } 62 63 @Override getPreferenceKey()64 public String getPreferenceKey() { 65 return KEY_RECEIVED_FILES; 66 } 67 68 @Override handlePreferenceTreeClick(Preference preference)69 public boolean handlePreferenceTreeClick(Preference preference) { 70 if (KEY_RECEIVED_FILES.equals(preference.getKey())) { 71 mMetricsFeatureProvider.action(mContext, 72 SettingsEnums.ACTION_BLUETOOTH_FILES); 73 Intent intent = new Intent(ACTION_OPEN_FILES); 74 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 75 intent.putExtra(EXTRA_DIRECTION, 1 /* DIRECTION_INBOUND */); 76 intent.putExtra(EXTRA_SHOW_ALL_FILES, true); 77 mContext.startActivity(intent); 78 return true; 79 } 80 81 return false; 82 } 83 84 85 } 86