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