1 /* 2 * Copyright (C) 2023 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 static org.junit.Assert.assertFalse; 20 import static org.junit.Assert.assertTrue; 21 22 import android.content.ComponentName; 23 import android.content.Context; 24 import android.content.pm.PackageManager; 25 26 import androidx.test.core.app.ApplicationProvider; 27 28 import com.android.settings.Settings; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 33 public class LanguagePreferenceControllerTest { 34 private Context mContext; 35 private LanguagePreferenceController mController; 36 37 @Before setup()38 public void setup() { 39 mContext = ApplicationProvider.getApplicationContext(); 40 mController = new LanguagePreferenceController(mContext, "key"); 41 } 42 43 @Test getAvailabilityStatus_featureFlagOff_LanguageAndInputSettingsActivitydisabled()44 public void getAvailabilityStatus_featureFlagOff_LanguageAndInputSettingsActivitydisabled() { 45 mController.getAvailabilityStatus(); 46 47 assertFalse(isActivityEnable(mContext, Settings.LanguageAndInputSettingsActivity.class)); 48 assertTrue(isActivityEnable(mContext, Settings.LanguageSettingsActivity.class)); 49 } 50 isActivityEnable(Context context, Class klazz)51 private static boolean isActivityEnable(Context context, Class klazz) { 52 PackageManager packageManager = context.getPackageManager(); 53 ComponentName componentName = 54 new ComponentName(context, klazz); 55 int flag = packageManager.getComponentEnabledSetting(componentName); 56 return flag == PackageManager.COMPONENT_ENABLED_STATE_ENABLED; 57 } 58 } 59