• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.accessibility;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.pm.PackageManager;
22 import android.content.pm.ResolveInfo;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.preference.Preference;
26 
27 import com.android.settings.core.BasePreferenceController;
28 
29 import java.util.List;
30 
31 public class LiveCaptionPreferenceController extends BasePreferenceController {
32 
33     @VisibleForTesting
34     static final Intent LIVE_CAPTION_INTENT = new Intent(
35             "com.android.settings.action.live_caption");
36 
37     private final PackageManager mPackageManager;
38 
LiveCaptionPreferenceController(Context context, String preferenceKey)39     public LiveCaptionPreferenceController(Context context, String preferenceKey) {
40         super(context, preferenceKey);
41         mPackageManager = context.getPackageManager();
42     }
43 
44     @Override
getAvailabilityStatus()45     public int getAvailabilityStatus() {
46         final List<ResolveInfo> resolved =
47                 mPackageManager.queryIntentActivities(LIVE_CAPTION_INTENT, 0 /* flags */);
48         return resolved != null && !resolved.isEmpty()
49                 ? AVAILABLE
50                 : UNSUPPORTED_ON_DEVICE;
51     }
52 
53     @Override
updateState(Preference preference)54     public void updateState(Preference preference) {
55         super.updateState(preference);
56         preference.setIntent(LIVE_CAPTION_INTENT);
57     }
58 }