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