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.googlecode.android_scripting.provider; 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.ParcelFileDescriptor; 24 import android.text.TextUtils; 25 26 import java.io.File; 27 import java.io.FileReader; 28 import java.io.BufferedReader; 29 import java.io.FileNotFoundException; 30 import java.io.IOException; 31 32 import com.googlecode.android_scripting.Log; 33 34 /** 35 * A simple provider to send MMS PDU to platform MMS service 36 */ 37 public class TelephonyTestProvider extends ContentProvider { 38 39 public static final String AUTHORITY = "telephonytestauthority"; 40 41 private final boolean DBG = false; 42 43 @Override onCreate()44 public boolean onCreate() { 45 if(DBG) Log.d("TelephonTestProvider Successfully created!"); 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 // Not supported 53 return null; 54 } 55 56 @Override getType(Uri uri)57 public String getType(Uri uri) { 58 // Not supported 59 return null; 60 } 61 62 @Override insert(Uri uri, ContentValues values)63 public Uri insert(Uri uri, ContentValues values) { 64 // Not supported 65 return null; 66 } 67 68 @Override delete(Uri uri, String selection, String[] selectionArgs)69 public int delete(Uri uri, String selection, String[] selectionArgs) { 70 // Not supported 71 return 0; 72 } 73 74 @Override update(Uri uri, ContentValues values, String selection, String[] selectionArgs)75 public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 76 // Not supported 77 return 0; 78 } 79 80 @Override openFile(Uri uri, String fileMode)81 public ParcelFileDescriptor openFile(Uri uri, String fileMode) throws FileNotFoundException { 82 Log.d(String.format("Entered ParcelFileDescriptor: Uri(%s), Mode(%s)", uri.toString(), 83 fileMode)); 84 File file = new File(getContext().getCacheDir(), uri.getPath()); 85 file.setReadable(true); 86 87 Log.d(String.format("Looking for file at %s", getContext().getCacheDir() + uri.getPath())); 88 int mode = (TextUtils.equals(fileMode, "r") ? ParcelFileDescriptor.MODE_READ_ONLY : 89 ParcelFileDescriptor.MODE_WRITE_ONLY 90 | ParcelFileDescriptor.MODE_TRUNCATE 91 | ParcelFileDescriptor.MODE_CREATE); 92 93 try { 94 ParcelFileDescriptor descriptor = ParcelFileDescriptor.open(file, mode); 95 96 if(DBG) { 97 try { 98 BufferedReader br = new BufferedReader(new 99 FileReader(descriptor.getFileDescriptor())); 100 String line = null; 101 while ((line = br.readLine()) != null) { 102 Log.d("MMS:" + line); 103 } 104 } catch (IOException e) { 105 } 106 } 107 108 return descriptor; 109 } catch (FileNotFoundException fnf) { 110 Log.e(fnf); 111 return null; 112 } 113 } 114 } 115