Home | History | Annotate | Download | only in compat
      1 /*
      2  * Copyright (C) 2015 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 package com.android.dialer.compat;
     17 
     18 import android.content.Context;
     19 import android.os.Build;
     20 import android.os.Build.VERSION;
     21 import android.os.Build.VERSION_CODES;
     22 import android.os.LocaleList;
     23 import java.util.Locale;
     24 
     25 public final class CompatUtils {
     26 
     27   /** PrioritizedMimeType is added in API level 23. */
     28   public static boolean hasPrioritizedMimeType() {
     29     return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) >= Build.VERSION_CODES.M;
     30   }
     31 
     32   /**
     33    * Determines if this version is compatible with multi-SIM and the phone account APIs. Can also
     34    * force the version to be lower through SdkVersionOverride.
     35    *
     36    * @return {@code true} if multi-SIM capability is available, {@code false} otherwise.
     37    */
     38   public static boolean isMSIMCompatible() {
     39     return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP)
     40         >= Build.VERSION_CODES.LOLLIPOP_MR1;
     41   }
     42 
     43   /**
     44    * Determines if this version is compatible with video calling. Can also force the version to be
     45    * lower through SdkVersionOverride.
     46    *
     47    * @return {@code true} if video calling is allowed, {@code false} otherwise.
     48    */
     49   public static boolean isVideoCompatible() {
     50     return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP) >= Build.VERSION_CODES.M;
     51   }
     52 
     53   /**
     54    * Determines if this version is capable of using presence checking for video calling. Support for
     55    * video call presence indication is added in SDK 24.
     56    *
     57    * @return {@code true} if video presence checking is allowed, {@code false} otherwise.
     58    */
     59   public static boolean isVideoPresenceCompatible() {
     60     return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.M) > Build.VERSION_CODES.M;
     61   }
     62 
     63   /**
     64    * Determines if this version is compatible with call subject. Can also force the version to be
     65    * lower through SdkVersionOverride.
     66    *
     67    * @return {@code true} if call subject is a feature on this device, {@code false} otherwise.
     68    */
     69   public static boolean isCallSubjectCompatible() {
     70     return SdkVersionOverride.getSdkVersion(Build.VERSION_CODES.LOLLIPOP) >= Build.VERSION_CODES.M;
     71   }
     72 
     73   /** Returns locale of the device. */
     74   public static Locale getLocale(Context context) {
     75     if (VERSION.SDK_INT >= VERSION_CODES.N) {
     76       LocaleList localList = context.getResources().getConfiguration().getLocales();
     77       if (!localList.isEmpty()) {
     78         return localList.get(0);
     79       }
     80       return Locale.getDefault();
     81     } else {
     82       return context.getResources().getConfiguration().locale;
     83     }
     84   }
     85 }
     86