1 /* 2 * Copyright (C) 2022 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.server.accessibility; 18 19 import android.content.Context; 20 import android.os.Binder; 21 import android.provider.Settings; 22 import android.view.accessibility.CaptioningManager; 23 24 /** 25 * Implementation class for CaptioningManager's interface that need system server identity. 26 */ 27 public class CaptioningManagerImpl implements CaptioningManager.SystemAudioCaptioningAccessing { 28 private static final boolean SYSTEM_AUDIO_CAPTIONING_UI_DEFAULT_ENABLED = false; 29 30 private final Context mContext; 31 CaptioningManagerImpl(Context context)32 public CaptioningManagerImpl(Context context) { 33 mContext = context; 34 } 35 36 /** 37 * Sets the system audio caption enabled state. 38 * 39 * @param isEnabled The system audio captioning enabled state. 40 * @param userId The user Id. 41 */ 42 @Override setSystemAudioCaptioningEnabled(boolean isEnabled, int userId)43 public void setSystemAudioCaptioningEnabled(boolean isEnabled, int userId) { 44 final long identity = Binder.clearCallingIdentity(); 45 try { 46 Settings.Secure.putIntForUser(mContext.getContentResolver(), 47 Settings.Secure.ODI_CAPTIONS_ENABLED, isEnabled ? 1 : 0, userId); 48 } finally { 49 Binder.restoreCallingIdentity(identity); 50 } 51 } 52 53 /** 54 * Gets the system audio caption UI enabled state. 55 * 56 * @param userId The user Id. 57 * @return the system audio caption UI enabled state. 58 */ 59 @Override isSystemAudioCaptioningUiEnabled(int userId)60 public boolean isSystemAudioCaptioningUiEnabled(int userId) { 61 final long identity = Binder.clearCallingIdentity(); 62 try { 63 return Settings.Secure.getIntForUser(mContext.getContentResolver(), 64 Settings.Secure.ODI_CAPTIONS_VOLUME_UI_ENABLED, 65 SYSTEM_AUDIO_CAPTIONING_UI_DEFAULT_ENABLED ? 1 : 0, userId) == 1; 66 } finally { 67 Binder.restoreCallingIdentity(identity); 68 } 69 } 70 71 /** 72 * Sets the system audio caption UI enabled state. 73 * 74 * @param isEnabled The system audio captioning UI enabled state. 75 * @param userId The user Id. 76 */ 77 @Override setSystemAudioCaptioningUiEnabled(boolean isEnabled, int userId)78 public void setSystemAudioCaptioningUiEnabled(boolean isEnabled, int userId) { 79 final long identity = Binder.clearCallingIdentity(); 80 try { 81 Settings.Secure.putIntForUser(mContext.getContentResolver(), 82 Settings.Secure.ODI_CAPTIONS_VOLUME_UI_ENABLED, isEnabled ? 1 : 0, userId); 83 } finally { 84 Binder.restoreCallingIdentity(identity); 85 } 86 } 87 } 88