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