use of android.content.ContentProvider in project AndroidLife by CaMnter.
the class RemoteContentProvider method bulkInsert.
/**
* 获取插件 ContentProvider 后
* 解析复合 Uri 协议,获取其中包含的插件 Uri 协议
*
* 手动调用 插件 ContentProvider # bulkInsert(...)
*
* @param uri uri
* @param values values
* @return int
*/
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
ContentProvider provider = getContentProvider(uri);
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
if (provider != null) {
return provider.bulkInsert(pluginUri, values);
}
return 0;
}
use of android.content.ContentProvider in project AndroidLife by CaMnter.
the class RemoteContentProvider method update.
/**
* 获取插件 ContentProvider 后
* 解析复合 Uri 协议,获取其中包含的插件 Uri 协议
*
* 手动调用 插件 ContentProvider # update(...)
*
* @param uri uri
* @param values values
* @param selection selection
* @param selectionArgs selectionArgs
* @return int
*/
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
ContentProvider provider = getContentProvider(uri);
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
if (provider != null) {
return provider.update(pluginUri, values, selection, selectionArgs);
}
return 0;
}
use of android.content.ContentProvider in project AndroidLife by CaMnter.
the class RemoteContentProvider method getContentProvider.
/**
* 获取插件 ContentProvider
*
* 1. 解析复合 Uri 协议,获取其中包含的插件 Uri 协议
* 2. 获取插件 插件 Uri 协议 中的 Authority
* 3. 根据 插件 Uri Authority,拿出插件 ContentProvider 缓存
*
* 4. 当前面没获取到插件 ContentProvider 缓存的时候,根据 插件 Uri 协议包含的该 ContentProvider 所在
* - apk file 的绝对路径,获取到对应的 LoadedPlugin。如果还没有 LoadedPlugin,需要根据 apk file path
* - 加载出 LoadedPlugin
*
* 5. 在保证有 LoadedPlugin 缓存的情况下。去获取该 插件 ContentProvider 对应的 ProviderInfo 信息
* 6. 给 主线程 发消息,主线程获取对应的 LoadedPlugin 缓存,然后加载出对应的 插件 ContentProvider class
* - 手动调用 ContentProvider # attachInfo(...)。最后加入到 插件 ContentProvider 集合内
*
* @param uri uri
* @return ContentProvider
*/
private ContentProvider getContentProvider(final Uri uri) {
final PluginManager pluginManager = PluginManager.getInstance(getContext());
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
final String auth = pluginUri.getAuthority();
ContentProvider cachedProvider = sCachedProviders.get(auth);
if (cachedProvider != null) {
return cachedProvider;
}
synchronized (sCachedProviders) {
LoadedPlugin plugin = pluginManager.getLoadedPlugin(uri.getQueryParameter(KEY_PKG));
if (plugin == null) {
try {
pluginManager.loadPlugin(new File(uri.getQueryParameter(KEY_PLUGIN)));
} catch (Exception e) {
e.printStackTrace();
}
}
final ProviderInfo providerInfo = pluginManager.resolveContentProvider(auth, 0);
if (providerInfo != null) {
RunUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
LoadedPlugin loadedPlugin = pluginManager.getLoadedPlugin(uri.getQueryParameter(KEY_PKG));
ContentProvider contentProvider = (ContentProvider) Class.forName(providerInfo.name).newInstance();
contentProvider.attachInfo(loadedPlugin.getPluginContext(), providerInfo);
sCachedProviders.put(auth, contentProvider);
} catch (Exception e) {
e.printStackTrace();
}
}
}, true);
return sCachedProviders.get(auth);
}
}
return null;
}
use of android.content.ContentProvider in project AndroidLife by CaMnter.
the class RemoteContentProvider method delete.
/**
* 获取插件 ContentProvider 后
* 解析复合 Uri 协议,获取其中包含的插件 Uri 协议
*
* 手动调用 插件 ContentProvider # delete(...)
*
* @param uri uri
* @param selection selection
* @param selectionArgs selectionArgs
* @return int
*/
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
ContentProvider provider = getContentProvider(uri);
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
if (provider != null) {
return provider.delete(pluginUri, selection, selectionArgs);
}
return 0;
}
use of android.content.ContentProvider in project platform_packages_providers_telephonyprovider by aosp-mirror.
the class TelephonyBackupAgentTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
/* Filling up subscription maps */
mStringWriter = new StringWriter();
mSubId2Phone = new SparseArray<String>();
mSubId2Phone.append(1, "+111111111111111");
mSubId2Phone.append(3, "+333333333333333");
mPhone2SubId = new ArrayMap<>();
for (int i = 0; i < mSubId2Phone.size(); ++i) {
mPhone2SubId.put(mSubId2Phone.valueAt(i), mSubId2Phone.keyAt(i));
}
mCursors = new HashMap<Uri, FakeCursor>();
/* Bind tables to the cursors */
mSmsCursor = new FakeCursor(mSmsTable, TelephonyBackupAgent.SMS_PROJECTION);
mCursors.put(Telephony.Sms.CONTENT_URI, mSmsCursor);
mMmsCursor = new FakeCursor(mMmsTable, TelephonyBackupAgent.MMS_PROJECTION);
mCursors.put(Telephony.Mms.CONTENT_URI, mMmsCursor);
/* Generating test data */
mSmsRows = new ContentValues[4];
mSmsJson = new String[4];
mSmsRows[0] = createSmsRow(1, 1, "+1232132214124", "sms 1", "sms subject", 9087978987l, 999999999, 3, 44, 1, false);
mSmsJson[0] = "{\"self_phone\":\"+111111111111111\",\"address\":" + "\"+1232132214124\",\"body\":\"sms 1\",\"subject\":\"sms subject\",\"date\":" + "\"9087978987\",\"date_sent\":\"999999999\",\"status\":\"3\",\"type\":\"44\"," + "\"recipients\":[\"+123 (213) 2214124\"],\"archived\":true,\"read\":\"0\"}";
mThreadProvider.setArchived(mThreadProvider.getOrCreateThreadId(new String[] { "+123 (213) 2214124" }));
mSmsRows[1] = createSmsRow(2, 2, "+1232132214124", "sms 2", null, 9087978987l, 999999999, 0, 4, 1, true);
mSmsJson[1] = "{\"address\":\"+1232132214124\",\"body\":\"sms 2\",\"date\":" + "\"9087978987\",\"date_sent\":\"999999999\",\"status\":\"0\",\"type\":\"4\"," + "\"recipients\":[\"+123 (213) 2214124\"],\"read\":\"1\"}";
mSmsRows[2] = createSmsRow(4, 3, "+1232221412433 +1232221412444", "sms 3", null, 111111111111l, 999999999, 2, 3, 2, false);
mSmsJson[2] = "{\"self_phone\":\"+333333333333333\",\"address\":" + "\"+1232221412433 +1232221412444\",\"body\":\"sms 3\",\"date\":\"111111111111\"," + "\"date_sent\":" + "\"999999999\",\"status\":\"2\",\"type\":\"3\"," + "\"recipients\":[\"+1232221412433\",\"+1232221412444\"],\"read\":\"0\"}";
mThreadProvider.getOrCreateThreadId(new String[] { "+1232221412433", "+1232221412444" });
mSmsRows[3] = createSmsRow(5, 3, null, "sms 4", null, 111111111111l, 999999999, 2, 3, 5, false);
mSmsJson[3] = "{\"self_phone\":\"+333333333333333\"," + "\"body\":\"sms 4\",\"date\":\"111111111111\"," + "\"date_sent\":" + "\"999999999\",\"status\":\"2\",\"type\":\"3\",\"read\":\"0\"}";
mAllSmsJson = makeJsonArray(mSmsJson);
mMmsRows = new ContentValues[3];
mMmsJson = new String[3];
mMmsRows[0] = createMmsRow(1, /*id*/
1, /*subid*/
"Subject 1", /*subject*/
100, /*subcharset*/
111111, /*date*/
111112, /*datesent*/
3, /*type*/
17, /*version*/
1, /*textonly*/
11, /*msgBox*/
"location 1", /*contentLocation*/
"MMs body 1", /*body*/
111, /*body charset*/
new String[] { "+111 (111) 11111111", "+11121212", "example@example.com", "+999999999" }, /*addresses*/
3, /*threadId*/
false, /*read*/
null, /*smil*/
null, /*attachmentTypes*/
null);
mMmsJson[0] = "{\"self_phone\":\"+111111111111111\",\"sub\":\"Subject 1\"," + "\"date\":\"111111\",\"date_sent\":\"111112\",\"m_type\":\"3\",\"v\":\"17\"," + "\"msg_box\":\"11\",\"ct_l\":\"location 1\"," + "\"recipients\":[\"+11121212\",\"example@example.com\",\"+999999999\"]," + "\"read\":\"0\"," + "\"mms_addresses\":" + "[{\"type\":10,\"address\":\"+111 (111) 11111111\",\"charset\":100}," + "{\"type\":11,\"address\":\"+11121212\",\"charset\":101},{\"type\":12,\"address\":" + "\"example@example.com\",\"charset\":102},{\"type\":13,\"address\":\"+999999999\"" + ",\"charset\":103}],\"mms_body\":\"MMs body 1\",\"mms_charset\":111,\"" + "sub_cs\":\"100\"}";
mThreadProvider.getOrCreateThreadId(new String[] { "+11121212", "example@example.com", "+999999999" });
mMmsRows[1] = createMmsRow(2, /*id*/
2, /*subid*/
null, /*subject*/
100, /*subcharset*/
111122, /*date*/
1111112, /*datesent*/
4, /*type*/
18, /*version*/
1, /*textonly*/
222, /*msgBox*/
"location 2", /*contentLocation*/
"MMs body 2", /*body*/
121, /*body charset*/
new String[] { "+7 (333) ", "example@example.com", "+999999999" }, /*addresses*/
4, /*threadId*/
true, /*read*/
null, /*smil*/
null, /*attachmentTypes*/
null);
mMmsJson[1] = "{\"date\":\"111122\",\"date_sent\":\"1111112\",\"m_type\":\"4\"," + "\"v\":\"18\",\"msg_box\":\"222\",\"ct_l\":\"location 2\"," + "\"recipients\":[\"example@example.com\",\"+999999999\"]," + "\"read\":\"1\"," + "\"mms_addresses\":" + "[{\"type\":10,\"address\":\"+7 (333) \",\"charset\":100}," + "{\"type\":11,\"address\":\"example@example.com\",\"charset\":101}," + "{\"type\":12,\"address\":\"+999999999\",\"charset\":102}]," + "\"mms_body\":\"MMs body 2\",\"mms_charset\":121}";
mThreadProvider.getOrCreateThreadId(new String[] { "example@example.com", "+999999999" });
mMmsRows[2] = createMmsRow(9, /*id*/
3, /*subid*/
"Subject 10", /*subject*/
10, /*subcharset*/
111133, /*date*/
1111132, /*datesent*/
5, /*type*/
19, /*version*/
1, /*textonly*/
333, /*msgBox*/
null, /*contentLocation*/
"MMs body 3", /*body*/
131, /*body charset*/
new String[] { "333 333333333333", "+1232132214124" }, /*addresses*/
1, /*threadId*/
false, /*read*/
null, /*smil*/
null, /*attachmentTypes*/
null);
mMmsJson[2] = "{\"self_phone\":\"+333333333333333\",\"sub\":\"Subject 10\"," + "\"date\":\"111133\",\"date_sent\":\"1111132\",\"m_type\":\"5\",\"v\":\"19\"," + "\"msg_box\":\"333\"," + "\"recipients\":[\"+123 (213) 2214124\"],\"archived\":true," + "\"read\":\"0\"," + "\"mms_addresses\":" + "[{\"type\":10,\"address\":\"333 333333333333\",\"charset\":100}," + "{\"type\":11,\"address\":\"+1232132214124\",\"charset\":101}]," + "\"mms_body\":\"MMs body 3\",\"mms_charset\":131," + "\"sub_cs\":\"10\"}";
mAllMmsJson = makeJsonArray(mMmsJson);
mMmsAttachmentRows = new ContentValues[1];
mMmsAttachmentJson = new String[1];
mMmsAttachmentRows[0] = createMmsRow(1, /*id*/
1, /*subid*/
"Subject 1", /*subject*/
100, /*subcharset*/
111111, /*date*/
111112, /*datesent*/
3, /*type*/
17, /*version*/
0, /*textonly*/
11, /*msgBox*/
"location 1", /*contentLocation*/
"MMs body 1", /*body*/
111, /*body charset*/
new String[] { "+111 (111) 11111111", "+11121212", "example@example.com", "+999999999" }, /*addresses*/
3, /*threadId*/
false, /*read*/
"<smil><head><layout><root-layout/>" + "<region id='Image' fit='meet' top='0' left='0' height='100%'" + " width='100%'/></layout></head><body><par dur='5000ms'>" + "<img src='image000000.jpg' region='Image' /></par></body></smil>", new String[] { "image/jpg" }, /*attachmentTypes*/
new String[] { "GreatPict.jpg" });
mMmsAttachmentJson[0] = "{\"self_phone\":\"+111111111111111\",\"sub\":\"Subject 1\"," + "\"date\":\"111111\",\"date_sent\":\"111112\",\"m_type\":\"3\",\"v\":\"17\"," + "\"msg_box\":\"11\",\"ct_l\":\"location 1\"," + "\"recipients\":[\"+11121212\",\"example@example.com\",\"+999999999\"]," + "\"read\":\"0\"," + "\"mms_addresses\":" + "[{\"type\":10,\"address\":\"+111 (111) 11111111\",\"charset\":100}," + "{\"type\":11,\"address\":\"+11121212\",\"charset\":101},{\"type\":12,\"address\":" + "\"example@example.com\",\"charset\":102},{\"type\":13,\"address\":\"+999999999\"" + ",\"charset\":103}],\"mms_body\":\"MMs body 1\",\"mms_charset\":111,\"" + "sub_cs\":\"100\"}";
mMmsAllAttachmentJson = makeJsonArray(mMmsAttachmentJson);
ContentProvider contentProvider = new MockContentProvider() {
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (mCursors.containsKey(uri)) {
FakeCursor fakeCursor = mCursors.get(uri);
if (projection != null) {
fakeCursor.setProjection(projection);
}
fakeCursor.nextRow = 0;
return fakeCursor;
}
fail("No cursor for " + uri.toString());
return null;
}
};
mMockContentResolver.addProvider("sms", contentProvider);
mMockContentResolver.addProvider("mms", contentProvider);
mMockContentResolver.addProvider("mms-sms", mThreadProvider);
mTelephonyBackupAgent = new TelephonyBackupAgent();
mTelephonyBackupAgent.attach(new ContextWrapper(getContext()) {
@Override
public ContentResolver getContentResolver() {
return mMockContentResolver;
}
});
mTelephonyBackupAgent.clearSharedPreferences();
mTelephonyBackupAgent.setContentResolver(mMockContentResolver);
mTelephonyBackupAgent.setSubId(mSubId2Phone, mPhone2SubId);
}
Aggregations