1 /* 2 * Copyright (C) 2017 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.settings.dashboard.suggestions; 18 19 import static android.content.Intent.EXTRA_COMPONENT_NAME; 20 21 import android.content.ComponentName; 22 import android.content.ContentProvider; 23 import android.content.ContentValues; 24 import android.content.Context; 25 import android.database.Cursor; 26 import android.net.Uri; 27 import android.os.Bundle; 28 import android.util.Log; 29 30 import androidx.annotation.VisibleForTesting; 31 32 import com.android.settings.overlay.FeatureFactory; 33 34 public class SuggestionStateProvider extends ContentProvider { 35 36 private static final String TAG = "SugstStatusProvider"; 37 38 @VisibleForTesting 39 static final String METHOD_GET_SUGGESTION_STATE = "getSuggestionState"; 40 @VisibleForTesting 41 static final String EXTRA_CANDIDATE_ID = "candidate_id"; 42 private static final String RESULT_IS_COMPLETE = "candidate_is_complete"; 43 44 @Override onCreate()45 public boolean onCreate() { 46 return true; 47 } 48 49 @Override query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)50 public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, 51 String sortOrder) { 52 throw new UnsupportedOperationException("query operation not supported currently."); 53 } 54 55 @Override getType(Uri uri)56 public String getType(Uri uri) { 57 throw new UnsupportedOperationException("getType operation not supported currently."); 58 } 59 60 @Override insert(Uri uri, ContentValues values)61 public Uri insert(Uri uri, ContentValues values) { 62 throw new UnsupportedOperationException("insert operation not supported currently."); 63 } 64 65 @Override delete(Uri uri, String selection, String[] selectionArgs)66 public int delete(Uri uri, String selection, String[] selectionArgs) { 67 throw new UnsupportedOperationException("delete operation not supported currently."); 68 } 69 70 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)71 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 72 throw new UnsupportedOperationException("update operation not supported currently."); 73 } 74 75 @Override call(String method, String arg, Bundle extras)76 public Bundle call(String method, String arg, Bundle extras) { 77 final Bundle bundle = new Bundle(); 78 if (METHOD_GET_SUGGESTION_STATE.equals(method)) { 79 final String id = extras.getString(EXTRA_CANDIDATE_ID); 80 final ComponentName cn = extras.getParcelable(EXTRA_COMPONENT_NAME); 81 final boolean isComplete; 82 if (cn == null) { 83 isComplete = true; 84 } else { 85 final Context context = getContext(); 86 isComplete = FeatureFactory.getFactory(context) 87 .getSuggestionFeatureProvider(context) 88 .isSuggestionComplete(context, cn); 89 } 90 Log.d(TAG, "Suggestion " + id + " complete: " + isComplete); 91 bundle.putBoolean(RESULT_IS_COMPLETE, isComplete); 92 } 93 return bundle; 94 } 95 } 96