| /* |
| * Copyright (C) 2012 The Android Open Source Project |
| * Copyright 2020-2022 Fairphone B.V. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package com.android.providers.partnerbookmarks; |
| |
| import android.content.ContentProvider; |
| import android.content.ContentValues; |
| import android.content.UriMatcher; |
| import android.content.res.Configuration; |
| import android.content.res.Resources; |
| import android.database.Cursor; |
| import android.database.MatrixCursor; |
| import android.net.Uri; |
| import android.util.Log; |
| |
| public class PartnerHomepageProvider extends ContentProvider { |
| private static final String TAG = "PartnerHomepageProvider"; |
| // Keep "http://www.android.com/" as fall-back. |
| // Other strings in this class must remain as it is. |
| private static String mHomepageUri = "http://www.android.com/"; |
| private static final int URI_MATCH_HOMEPAGE = 0; |
| private static final int URI_MATCH_DISABLE_INCOGNITO_MODE = 1; |
| private static final int URI_MATCH_DISABLE_BOOKMARKS_EDITING = 2; |
| private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH); |
| |
| static { |
| URI_MATCHER.addURI( |
| "com.android.partnerbrowsercustomizations", "homepage", URI_MATCH_HOMEPAGE); |
| } |
| |
| private boolean prepareHomepageUri() { |
| Resources res = getContext().getResources(); |
| try { |
| mHomepageUri = res.getString(R.string.homepage_uri); |
| } catch (android.content.res.Resources.NotFoundException e) { |
| Log.e(TAG, "prepareHomepageUri failed to fetch resources; bailing out"); |
| e.printStackTrace(); |
| return false; |
| } |
| |
| return true; |
| } |
| |
| @Override |
| public boolean onCreate() { |
| prepareHomepageUri(); |
| Log.d(TAG, "onCreate mHomepageUri=" + mHomepageUri); |
| return true; |
| } |
| |
| @Override |
| public void onConfigurationChanged(Configuration newConfig) { |
| prepareHomepageUri(); |
| Log.d(TAG, "onConfigurationChanged mHomepageUri=" + mHomepageUri); |
| } |
| |
| @Override |
| public String getType(Uri uri) { |
| switch (URI_MATCHER.match(uri)) { |
| case URI_MATCH_HOMEPAGE: |
| return "vnd.android.cursor.item/partnerhomepage"; |
| case URI_MATCH_DISABLE_INCOGNITO_MODE: |
| return "vnd.android.cursor.item/partnerdisableincognitomode"; |
| case URI_MATCH_DISABLE_BOOKMARKS_EDITING: |
| return "vnd.android.cursor.item/partnerdisablebookmarksediting"; |
| default: |
| return null; |
| } |
| } |
| |
| @Override |
| public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, |
| String sortOrder) { |
| switch (URI_MATCHER.match(uri)) { |
| case URI_MATCH_HOMEPAGE: { |
| MatrixCursor cursor = new MatrixCursor(new String[]{"homepage"}, 1); |
| cursor.addRow(new Object[]{mHomepageUri}); |
| return cursor; |
| } |
| case URI_MATCH_DISABLE_INCOGNITO_MODE: { |
| MatrixCursor cursor = |
| new MatrixCursor(new String[]{"disableincognitomode"}, 1); |
| cursor.addRow(new Object[]{1}); |
| return cursor; |
| } |
| case URI_MATCH_DISABLE_BOOKMARKS_EDITING: { |
| MatrixCursor cursor = |
| new MatrixCursor(new String[]{"disablebookmarksediting"}, 1); |
| cursor.addRow(new Object[]{1}); |
| return cursor; |
| } |
| default: |
| return null; |
| } |
| } |
| |
| @Override |
| public Uri insert(Uri uri, ContentValues values) { |
| throw new UnsupportedOperationException(); |
| } |
| |
| @Override |
| public int delete(Uri uri, String selection, String[] selectionArgs) { |
| throw new UnsupportedOperationException(); |
| } |
| |
| @Override |
| public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { |
| throw new UnsupportedOperationException(); |
| } |
| } |