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