blob: 9435409c36d1c38c167b621c7b38f34bc1354065 [file] [log] [blame]
Ye Wene07acb92014-11-19 12:06:05 -08001/*
2 * Copyright (C) 2014 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
17package com.android.providers.telephony;
18
19import android.content.ContentValues;
20import android.content.Context;
Ye Wene07acb92014-11-19 12:06:05 -080021import android.os.Process;
22import android.provider.Telephony;
Ye Wen72f13552015-03-10 14:17:13 -070023
24import com.android.internal.telephony.SmsApplication;
Ye Wene07acb92014-11-19 12:06:05 -080025
26/**
27 * Helpers
28 */
29public class ProviderUtil {
30
31 /**
Ye Wen72f13552015-03-10 14:17:13 -070032 * Check if a caller of the provider has restricted access,
33 * i.e. being non-system, non-phone, non-default SMS app
Ye Wene07acb92014-11-19 12:06:05 -080034 *
Ye Wen72f13552015-03-10 14:17:13 -070035 * @param context the context to use
36 * @param packageName the caller package name
37 * @param uid the caller uid
38 * @return true if the caller is not system, or phone or default sms app, false otherwise
Ye Wene07acb92014-11-19 12:06:05 -080039 */
Ye Wen72f13552015-03-10 14:17:13 -070040 public static boolean isAccessRestricted(Context context, String packageName, int uid) {
41 return (uid != Process.SYSTEM_UID
42 && uid != Process.PHONE_UID
43 && !SmsApplication.isDefaultSmsApplication(context, packageName));
Ye Wene07acb92014-11-19 12:06:05 -080044 }
45
46 /**
47 * Whether should set CREATOR for an insertion
48 *
49 * @param values The content of the message
50 * @param uid The caller UID of the insertion
51 * @return true if we should set CREATOR, false otherwise
52 */
53 public static boolean shouldSetCreator(ContentValues values, int uid) {
54 return (uid != Process.SYSTEM_UID && uid != Process.PHONE_UID) ||
55 (!values.containsKey(Telephony.Sms.CREATOR) &&
56 !values.containsKey(Telephony.Mms.CREATOR));
57 }
58
59 /**
60 * Whether should remove CREATOR for an update
61 *
62 * @param values The content of the message
63 * @param uid The caller UID of the update
64 * @return true if we should remove CREATOR, false otherwise
65 */
66 public static boolean shouldRemoveCreator(ContentValues values, int uid) {
67 return (uid != Process.SYSTEM_UID && uid != Process.PHONE_UID) &&
68 (values.containsKey(Telephony.Sms.CREATOR) ||
69 values.containsKey(Telephony.Mms.CREATOR));
70 }
71}