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