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.art.cts.tlr_app.fixture; 18 19 import android.content.ContentProvider; 20 import android.content.ContentValues; 21 import android.database.Cursor; 22 import android.net.Uri; 23 import android.os.Bundle; 24 25 import java.util.concurrent.ThreadLocalRandom; 26 27 public class ThreadLocalRandomProvider extends ContentProvider { 28 29 private static final String METHOD_NEXT_RANDOM = "next_random"; 30 31 private static final String CALL_RESULT_NEXT_RANDOM = "random"; 32 33 @Override onCreate()34 public boolean onCreate() { 35 return true; 36 } 37 38 @Override query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)39 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, 40 String sortOrder) { 41 // No impl. 42 return null; 43 } 44 45 @Override getType(Uri uri)46 public String getType(Uri uri) { 47 // No impl. 48 return null; 49 } 50 51 @Override insert(Uri uri, ContentValues values)52 public Uri insert(Uri uri, ContentValues values) { 53 // No impl. 54 return null; 55 } 56 57 @Override delete(Uri uri, String selection, String[] selectionArgs)58 public int delete(Uri uri, String selection, String[] selectionArgs) { 59 // No impl. 60 return 0; 61 } 62 63 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)64 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 65 // No impl. 66 return 0; 67 } 68 69 @Override call(String method, String arg, Bundle extras)70 public Bundle call(String method, String arg, Bundle extras) { 71 if (METHOD_NEXT_RANDOM.equals(method)) { 72 Bundle bundle = new Bundle(); 73 bundle.putLong(CALL_RESULT_NEXT_RANDOM, ThreadLocalRandom.current().nextLong()); 74 return bundle; 75 } 76 throw new IllegalArgumentException("Method " + method + " is not recognised"); 77 } 78 } 79