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.car.setupwizardlib; 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 org.robolectric.Robolectric; 26 27 /** 28 * An implementation of 29 * {@link com.google.android.car.setupwizard.common.config.FeatureManagementProvider} for 30 * Robolectric tests. 31 */ 32 public class FakeFeatureManagementProvider extends ContentProvider { 33 private static final String SUW_AUTHORITY = 34 "com.google.android.car.setupwizard.feature_management"; 35 private static final String GET_FEATURE_VERSION_METHOD = "getFeatureVersion"; 36 private static final String SPLIT_NAV_LAYOUT = "split_nav_layout"; 37 private static final String TYPE = "type"; 38 private static final String BOOLEAN_TYPE = "BOOLEAN"; 39 private static final String VALUE = "value"; 40 installProvider()41 public static FakeFeatureManagementProvider installProvider() { 42 return Robolectric.setupContentProvider(FakeFeatureManagementProvider.class, SUW_AUTHORITY); 43 } 44 45 @Override onCreate()46 public boolean onCreate() { 47 return true; 48 } 49 50 @Override query( Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)51 public Cursor query( 52 Uri uri, String[] projection, String selection, String[] selectionArgs, 53 String sortOrder) { 54 throw new UnsupportedOperationException("query operation not supported currently."); 55 } 56 57 @Override getType(Uri uri)58 public String getType(Uri uri) { 59 throw new UnsupportedOperationException("getType operation not supported currently."); 60 } 61 62 @Override insert(Uri uri, ContentValues values)63 public Uri insert(Uri uri, ContentValues values) { 64 throw new UnsupportedOperationException("insert operation not supported currently."); 65 } 66 67 @Override delete(Uri uri, String selection, String[] selectionArgs)68 public int delete(Uri uri, String selection, String[] selectionArgs) { 69 throw new UnsupportedOperationException("delete operation not supported currently."); 70 } 71 72 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)73 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 74 throw new UnsupportedOperationException("update operation not supported currently."); 75 } 76 77 @Override call(String method, String feature, Bundle extras)78 public Bundle call(String method, String feature, Bundle extras) { 79 Bundle bundle = new Bundle(); 80 if (!GET_FEATURE_VERSION_METHOD.equals(method)) { 81 return bundle; 82 } 83 84 switch(feature) { 85 case SPLIT_NAV_LAYOUT: 86 bundle.putString(TYPE, BOOLEAN_TYPE); 87 bundle.putBoolean(VALUE, true); 88 break; 89 default: 90 // Do nothing 91 } 92 return bundle; 93 } 94 } 95