1 /* 2 * Copyright (C) 2022 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.adservices.service.measurement.attribution; 18 19 import android.content.ContentProvider; 20 import android.content.ContentValues; 21 import android.database.Cursor; 22 import android.net.Uri; 23 24 import com.android.adservices.LogUtil; 25 import com.android.adservices.service.measurement.Trigger; 26 import com.android.modules.utils.build.SdkLevel; 27 28 /** ContentProvider for monitoring changes to {@link Trigger}. */ 29 public final class TriggerContentProvider extends ContentProvider { 30 31 /** 32 * Gets the Trigger URI of this content provider 33 * 34 * @return the trigger uri, which can be different based on the Android version (S- vs. T+) 35 */ getTriggerUri()36 public static Uri getTriggerUri() { 37 String authority = 38 SdkLevel.isAtLeastT() 39 ? "com.android.adservices.provider.trigger" 40 : "com.android.ext.adservices.provider.trigger"; 41 return Uri.parse("content://" + authority); 42 } 43 44 @Override onCreate()45 public boolean onCreate() { 46 LogUtil.d("TriggerContentProvider.onCreate()"); 47 return true; 48 } 49 50 @Override query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)51 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, 52 String sortOrder) { 53 throw new UnsupportedOperationException(); 54 } 55 56 @Override getType(Uri uri)57 public String getType(Uri uri) { 58 throw new UnsupportedOperationException(); 59 } 60 61 @Override insert(Uri uri, ContentValues values)62 public Uri insert(Uri uri, ContentValues values) { 63 // TODO: Choose an integration option after Trigger datastore changes are available. 64 // 1) Call ContentProvider after insert in DAO 65 // Sample Code: 66 // Uri triggerUri = TriggerContentProvider.getTriggerUri(); 67 // ContentProviderClient contentProviderClient = ctx.getContentResolver() 68 // .acquireContentProviderClient(triggerUri) 69 // .insert(triggerUri, null); 70 // 2) Call ContentProvider for inserting during registration and call DAO from here. 71 // Sample Code: 72 // MeasurementDAO.getInstance(getContext()).insertTrigger(triggerObject); 73 Uri triggerUri = getTriggerUri(); 74 getContext().getContentResolver().notifyChange(triggerUri, null); 75 return triggerUri; 76 } 77 78 @Override delete(Uri uri, String selection, String[] selectionArgs)79 public int delete(Uri uri, String selection, String[] selectionArgs) { 80 throw new UnsupportedOperationException(); 81 } 82 83 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)84 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 85 throw new UnsupportedOperationException(); 86 } 87 } 88