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_CODES;
     21 import android.provider.Settings;
     22 
     23 import com.android.contacts.common.compat.SdkVersionOverride;
     24 
     25 /**
     26  * Compatibility class for {@link android.provider.Settings}
     27  */
     28 public class SettingsCompat {
     29 
     30     public static class System {
     31 
     32         /**
     33          * Compatibility version of {@link android.provider.Settings.System#canWrite(Context)}
     34          *
     35          * Note: Since checking preferences at runtime started in M, this method always returns
     36          * {@code true} for SDK versions prior to 23. In those versions, the app wouldn't be
     37          * installed if it didn't have the proper permission
     38          */
     39         public static boolean canWrite(Context context) {
     40             if (SdkVersionOverride.getSdkVersion(VERSION_CODES.LOLLIPOP) >= Build.VERSION_CODES.M) {
     41                 return Settings.System.canWrite(context);
     42             }
     43             return true;
     44         }
     45     }
     46 
     47 }
     48