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 LIVE_CAPTION_INTENT.setPackage(mPackageManager.getSystemCaptionsServicePackageName()); 43 } 44 45 @Override getAvailabilityStatus()46 public int getAvailabilityStatus() { 47 final List<ResolveInfo> resolved = 48 mPackageManager.queryIntentActivities(LIVE_CAPTION_INTENT, 0 /* flags */); 49 return resolved != null && !resolved.isEmpty() 50 ? AVAILABLE 51 : UNSUPPORTED_ON_DEVICE; 52 } 53 54 @Override updateState(Preference preference)55 public void updateState(Preference preference) { 56 super.updateState(preference); 57 preference.setIntent(LIVE_CAPTION_INTENT); 58 } 59 }