/* * Copyright 2016 Hippo Seven * * 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.hippo.nimingban.content; /* * Created by Hippo on 11/18/2016. */ import android.content.ContentProvider; import android.content.ContentResolver; import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; import android.os.ParcelFileDescriptor; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.io.FileNotFoundException; public class UpdateApkProvider extends ContentProvider { public static final Uri UPDATE_APK_URI = new Uri.Builder() .scheme(ContentResolver.SCHEME_CONTENT) .authority("com.hippo.nimingban.updateapk") .build(); private static Uri sUpdateApkUri; public static void setUpdateApkFile(Uri uri) { sUpdateApkUri = uri; } @Override public boolean onCreate() { return true; } @Nullable @Override public Cursor query(@NonNull Uri uri, String[] strings, String s, String[] strings1, String s1) { throw new UnsupportedOperationException(); } @Nullable @Override public String getType(@NonNull Uri uri) { throw new UnsupportedOperationException(); } @Nullable @Override public Uri insert(@NonNull Uri uri, ContentValues contentValues) { throw new UnsupportedOperationException(); } @Override public int delete(@NonNull Uri uri, String s, String[] strings) { throw new UnsupportedOperationException(); } @Override public int update(@NonNull Uri uri, ContentValues contentValues, String s, String[] strings) { throw new UnsupportedOperationException(); } @Override public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException { if (sUpdateApkUri != null) { return getContext().getContentResolver().openFileDescriptor(sUpdateApkUri, mode); } else { throw new FileNotFoundException("Can't find " + uri); } } }