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.settings.language; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.pm.PackageManager; 22 23 import com.android.settings.Settings; 24 import com.android.settings.core.BasePreferenceController; 25 26 /** 27 * This is a display controller for new language activity entry. 28 * TODO(b/273642892): When new layout is on board, this class shall be removed. 29 */ 30 public class LanguagePreferenceController extends BasePreferenceController { LanguagePreferenceController(Context context, String key)31 public LanguagePreferenceController(Context context, String key) { 32 super(context, key); 33 } 34 35 @Override getAvailabilityStatus()36 public int getAvailabilityStatus() { 37 setActivityEnabled(mContext, Settings.LanguageSettingsActivity.class, true); 38 return AVAILABLE; 39 } 40 setActivityEnabled(Context context, Class klass, final boolean isEnabled)41 private static void setActivityEnabled(Context context, Class klass, final boolean isEnabled) { 42 PackageManager packageManager = context.getPackageManager(); 43 44 ComponentName componentName = 45 new ComponentName(context, klass); 46 final int flag = isEnabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : 47 PackageManager.COMPONENT_ENABLED_STATE_DISABLED; 48 49 packageManager.setComponentEnabledSetting( 50 componentName, flag, PackageManager.DONT_KILL_APP); 51 } 52 }