1 /* 2 * Copyright (C) 2021 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.emergency; 18 19 20 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.EMERGENCY_GESTURE_CALL_NUMBER; 21 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.EMERGENCY_NUMBER_OVERRIDE_AUTHORITY; 22 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.EMERGENCY_SETTING_OFF; 23 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.EMERGENCY_SETTING_ON; 24 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.EMERGENCY_SETTING_VALUE; 25 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.METHOD_NAME_GET_EMERGENCY_GESTURE_ENABLED; 26 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.METHOD_NAME_GET_EMERGENCY_GESTURE_SOUND_ENABLED; 27 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.METHOD_NAME_GET_EMERGENCY_NUMBER_OVERRIDE; 28 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.METHOD_NAME_SET_EMERGENCY_GESTURE; 29 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.METHOD_NAME_SET_EMERGENCY_NUMBER_OVERRIDE; 30 import static com.android.settingslib.emergencynumber.EmergencyNumberUtils.METHOD_NAME_SET_EMERGENCY_SOUND; 31 32 import android.content.ContentProvider; 33 import android.content.ContentValues; 34 import android.content.Context; 35 import android.content.SharedPreferences; 36 import android.database.Cursor; 37 import android.net.Uri; 38 import android.os.Binder; 39 import android.os.Bundle; 40 import android.provider.Settings; 41 import android.util.Log; 42 43 /** 44 * Content provider that gets/sets emergency number override for emergency gesture. 45 */ 46 public class EmergencyGestureContentProvider extends ContentProvider { 47 private static final String TAG = "EmergencyNumberContentP"; 48 private static final boolean DEBUG = true; 49 private static final String SHARED_PREFERENCES_NAME = 50 "local_emergency_number_override_shared_pref"; 51 52 @Override call(String authority, String method, String arg, Bundle extras)53 public Bundle call(String authority, String method, String arg, Bundle extras) { 54 Log.d(TAG, "calling pid/uid" + Binder.getCallingPid() + "/" + Binder.getCallingUid()); 55 final Bundle bundle = new Bundle(); 56 final SharedPreferences preferences = getContext().getSharedPreferences( 57 SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); 58 switch (method) { 59 case METHOD_NAME_GET_EMERGENCY_NUMBER_OVERRIDE: 60 if (DEBUG) { 61 Log.d(TAG, METHOD_NAME_GET_EMERGENCY_NUMBER_OVERRIDE); 62 } 63 bundle.putString(EMERGENCY_GESTURE_CALL_NUMBER, 64 preferences.getString(EMERGENCY_GESTURE_CALL_NUMBER, null)); 65 break; 66 case METHOD_NAME_SET_EMERGENCY_NUMBER_OVERRIDE: 67 if (DEBUG) { 68 Log.d(TAG, METHOD_NAME_SET_EMERGENCY_NUMBER_OVERRIDE); 69 } 70 final String inputNumber = extras.getString(EMERGENCY_GESTURE_CALL_NUMBER); 71 preferences.edit().putString(EMERGENCY_GESTURE_CALL_NUMBER, inputNumber).apply(); 72 getContext().getContentResolver().notifyChange(EMERGENCY_NUMBER_OVERRIDE_AUTHORITY, 73 null); 74 break; 75 case METHOD_NAME_SET_EMERGENCY_GESTURE: 76 if (DEBUG) { 77 Log.d(TAG, METHOD_NAME_SET_EMERGENCY_GESTURE); 78 } 79 final int gestureSettingValue = extras.getInt(EMERGENCY_SETTING_VALUE); 80 Settings.Secure.putInt(getContext().getContentResolver(), 81 Settings.Secure.EMERGENCY_GESTURE_ENABLED, gestureSettingValue); 82 break; 83 case METHOD_NAME_SET_EMERGENCY_SOUND: 84 if (DEBUG) { 85 Log.d(TAG, METHOD_NAME_SET_EMERGENCY_SOUND); 86 } 87 final int soundSettingValue = extras.getInt(EMERGENCY_SETTING_VALUE); 88 Settings.Secure.putInt(getContext().getContentResolver(), 89 Settings.Secure.EMERGENCY_GESTURE_SOUND_ENABLED, soundSettingValue); 90 break; 91 case METHOD_NAME_GET_EMERGENCY_GESTURE_ENABLED: 92 if (DEBUG) { 93 Log.d(TAG, METHOD_NAME_GET_EMERGENCY_GESTURE_ENABLED); 94 } 95 bundle.putInt(EMERGENCY_SETTING_VALUE, 96 Settings.Secure.getInt(getContext().getContentResolver(), 97 Settings.Secure.EMERGENCY_GESTURE_ENABLED, 98 EMERGENCY_SETTING_ON)); 99 break; 100 case METHOD_NAME_GET_EMERGENCY_GESTURE_SOUND_ENABLED: 101 if (DEBUG) { 102 Log.d(TAG, METHOD_NAME_GET_EMERGENCY_GESTURE_SOUND_ENABLED); 103 } 104 bundle.putInt(EMERGENCY_SETTING_VALUE, 105 Settings.Secure.getInt(getContext().getContentResolver(), 106 Settings.Secure.EMERGENCY_GESTURE_SOUND_ENABLED, 107 EMERGENCY_SETTING_OFF)); 108 break; 109 } 110 return bundle; 111 } 112 113 @Override onCreate()114 public boolean onCreate() { 115 return true; 116 } 117 118 @Override query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)119 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, 120 String sortOrder) { 121 throw new UnsupportedOperationException(); 122 } 123 124 @Override getType(Uri uri)125 public String getType(Uri uri) { 126 throw new UnsupportedOperationException(); 127 } 128 129 @Override insert(Uri uri, ContentValues values)130 public Uri insert(Uri uri, ContentValues values) { 131 throw new UnsupportedOperationException(); 132 } 133 134 @Override delete(Uri uri, String selection, String[] selectionArgs)135 public int delete(Uri uri, String selection, String[] selectionArgs) { 136 throw new UnsupportedOperationException(); 137 } 138 139 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)140 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 141 throw new UnsupportedOperationException(); 142 } 143 } 144