Loading src/com/android/dialer/compat/SettingsCompat.java 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.dialer.compat; import android.content.Context; import android.os.Build; import android.os.Build.VERSION_CODES; import android.provider.Settings; import com.android.contacts.common.compat.SdkVersionOverride; /** * Compatibility class for {@link android.provider.Settings} */ public class SettingsCompat { public static class System { /** * Compatibility version of {@link android.provider.Settings.System#canWrite(Context)} * * Note: Since checking preferences at runtime started in M, this method always returns * {@code true} for SDK versions prior to 23. In those versions, the app wouldn't be * installed if it didn't have the proper permission */ public static boolean canWrite(Context context) { if (SdkVersionOverride.getSdkVersion(VERSION_CODES.LOLLIPOP) >= Build.VERSION_CODES.M) { return Settings.System.canWrite(context); } return true; } } } src/com/android/dialer/settings/DefaultRingtonePreference.java +2 −3 Original line number Diff line number Diff line Loading @@ -16,17 +16,16 @@ package com.android.dialer.settings; import android.app.AppOpsManager; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.net.Uri; import android.preference.RingtonePreference; import android.provider.Settings; import android.util.AttributeSet; import android.widget.Toast; import com.android.dialer.R; import com.android.dialer.compat.SettingsCompat; /** * RingtonePreference which doesn't show default ringtone setting. Loading @@ -49,7 +48,7 @@ public class DefaultRingtonePreference extends RingtonePreference { @Override protected void onSaveRingtone(Uri ringtoneUri) { if (!Settings.System.canWrite(getContext())) { if (!SettingsCompat.System.canWrite(getContext())) { Toast.makeText( getContext(), getContext().getResources().getString(R.string.toast_cannot_write_system_settings), Loading src/com/android/dialer/settings/DialerSettingsActivity.java +2 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.view.MenuItem; import android.widget.Toast; import com.android.dialer.R; import com.android.dialer.compat.SettingsCompat; import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity; import java.util.List; Loading Loading @@ -109,7 +110,7 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { // If we don't have the permission to write to system settings, go to system sound // settings instead. Otherwise, perform the super implementation (which launches our // own preference fragment. if (!Settings.System.canWrite(this)) { if (!SettingsCompat.System.canWrite(this)) { Toast.makeText( this, getResources().getString(R.string.toast_cannot_write_system_settings), Loading src/com/android/dialer/settings/SoundSettingsFragment.java +4 −15 Original line number Diff line number Diff line Loading @@ -16,9 +16,7 @@ package com.android.dialer.settings; import android.app.AppOpsManager; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.os.Bundle; import android.os.Handler; Loading @@ -32,21 +30,12 @@ import android.preference.PreferenceScreen; import android.provider.Settings; import android.telephony.CarrierConfigManager; import android.telephony.TelephonyManager; import android.view.MenuItem; import android.widget.Toast; import com.android.contacts.common.util.PermissionsUtil; import com.android.dialer.R; import com.android.dialer.compat.SettingsCompat; import com.android.phone.common.util.SettingsUtil; import java.lang.Boolean; import java.lang.CharSequence; import java.lang.Object; import java.lang.Override; import java.lang.Runnable; import java.lang.String; import java.lang.Thread; public class SoundSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener { Loading Loading @@ -137,7 +126,7 @@ public class SoundSettingsFragment extends PreferenceFragment public void onResume() { super.onResume(); if (!Settings.System.canWrite(getContext())) { if (!SettingsCompat.System.canWrite(getContext())) { // If the user launches this setting fragment, then toggles the WRITE_SYSTEM_SETTINGS // AppOp, then close the fragment since there is nothing useful to do. getActivity().onBackPressed(); Loading @@ -160,7 +149,7 @@ public class SoundSettingsFragment extends PreferenceFragment */ @Override public boolean onPreferenceChange(Preference preference, Object objValue) { if (!Settings.System.canWrite(getContext())) { if (!SettingsCompat.System.canWrite(getContext())) { // A user shouldn't be able to get here, but this protects against monkey crashes. Toast.makeText( getContext(), Loading @@ -186,7 +175,7 @@ public class SoundSettingsFragment extends PreferenceFragment */ @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (!Settings.System.canWrite(getContext())) { if (!SettingsCompat.System.canWrite(getContext())) { Toast.makeText( getContext(), getResources().getString(R.string.toast_cannot_write_system_settings), Loading Loading
src/com/android/dialer/compat/SettingsCompat.java 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.dialer.compat; import android.content.Context; import android.os.Build; import android.os.Build.VERSION_CODES; import android.provider.Settings; import com.android.contacts.common.compat.SdkVersionOverride; /** * Compatibility class for {@link android.provider.Settings} */ public class SettingsCompat { public static class System { /** * Compatibility version of {@link android.provider.Settings.System#canWrite(Context)} * * Note: Since checking preferences at runtime started in M, this method always returns * {@code true} for SDK versions prior to 23. In those versions, the app wouldn't be * installed if it didn't have the proper permission */ public static boolean canWrite(Context context) { if (SdkVersionOverride.getSdkVersion(VERSION_CODES.LOLLIPOP) >= Build.VERSION_CODES.M) { return Settings.System.canWrite(context); } return true; } } }
src/com/android/dialer/settings/DefaultRingtonePreference.java +2 −3 Original line number Diff line number Diff line Loading @@ -16,17 +16,16 @@ package com.android.dialer.settings; import android.app.AppOpsManager; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.net.Uri; import android.preference.RingtonePreference; import android.provider.Settings; import android.util.AttributeSet; import android.widget.Toast; import com.android.dialer.R; import com.android.dialer.compat.SettingsCompat; /** * RingtonePreference which doesn't show default ringtone setting. Loading @@ -49,7 +48,7 @@ public class DefaultRingtonePreference extends RingtonePreference { @Override protected void onSaveRingtone(Uri ringtoneUri) { if (!Settings.System.canWrite(getContext())) { if (!SettingsCompat.System.canWrite(getContext())) { Toast.makeText( getContext(), getContext().getResources().getString(R.string.toast_cannot_write_system_settings), Loading
src/com/android/dialer/settings/DialerSettingsActivity.java +2 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import android.view.MenuItem; import android.widget.Toast; import com.android.dialer.R; import com.android.dialer.compat.SettingsCompat; import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity; import java.util.List; Loading Loading @@ -109,7 +110,7 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { // If we don't have the permission to write to system settings, go to system sound // settings instead. Otherwise, perform the super implementation (which launches our // own preference fragment. if (!Settings.System.canWrite(this)) { if (!SettingsCompat.System.canWrite(this)) { Toast.makeText( this, getResources().getString(R.string.toast_cannot_write_system_settings), Loading
src/com/android/dialer/settings/SoundSettingsFragment.java +4 −15 Original line number Diff line number Diff line Loading @@ -16,9 +16,7 @@ package com.android.dialer.settings; import android.app.AppOpsManager; import android.content.Context; import android.content.Intent; import android.media.RingtoneManager; import android.os.Bundle; import android.os.Handler; Loading @@ -32,21 +30,12 @@ import android.preference.PreferenceScreen; import android.provider.Settings; import android.telephony.CarrierConfigManager; import android.telephony.TelephonyManager; import android.view.MenuItem; import android.widget.Toast; import com.android.contacts.common.util.PermissionsUtil; import com.android.dialer.R; import com.android.dialer.compat.SettingsCompat; import com.android.phone.common.util.SettingsUtil; import java.lang.Boolean; import java.lang.CharSequence; import java.lang.Object; import java.lang.Override; import java.lang.Runnable; import java.lang.String; import java.lang.Thread; public class SoundSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener { Loading Loading @@ -137,7 +126,7 @@ public class SoundSettingsFragment extends PreferenceFragment public void onResume() { super.onResume(); if (!Settings.System.canWrite(getContext())) { if (!SettingsCompat.System.canWrite(getContext())) { // If the user launches this setting fragment, then toggles the WRITE_SYSTEM_SETTINGS // AppOp, then close the fragment since there is nothing useful to do. getActivity().onBackPressed(); Loading @@ -160,7 +149,7 @@ public class SoundSettingsFragment extends PreferenceFragment */ @Override public boolean onPreferenceChange(Preference preference, Object objValue) { if (!Settings.System.canWrite(getContext())) { if (!SettingsCompat.System.canWrite(getContext())) { // A user shouldn't be able to get here, but this protects against monkey crashes. Toast.makeText( getContext(), Loading @@ -186,7 +175,7 @@ public class SoundSettingsFragment extends PreferenceFragment */ @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (!Settings.System.canWrite(getContext())) { if (!SettingsCompat.System.canWrite(getContext())) { Toast.makeText( getContext(), getResources().getString(R.string.toast_cannot_write_system_settings), Loading