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