use of android.content.ContentResolver in project platform_frameworks_base by android.
the class RootsCache method loadStoppedAuthority.
/**
* Load roots from a stopped authority. Normal {@link UpdateTask} passes
* ignore stopped applications.
*/
private void loadStoppedAuthority(String authority) {
final ContentResolver resolver = mContext.getContentResolver();
synchronized (mLock) {
if (!mStoppedAuthorities.contains(authority)) {
return;
}
if (DEBUG) {
Log.d(TAG, "Loading stopped authority " + authority);
}
mRoots.putAll(authority, loadRootsForAuthority(resolver, authority, true));
mStoppedAuthorities.remove(authority);
}
}
use of android.content.ContentResolver in project platform_frameworks_base by android.
the class PackageReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
final ContentResolver resolver = context.getContentResolver();
final String action = intent.getAction();
if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) {
resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE, null, null);
} else if (Intent.ACTION_PACKAGE_DATA_CLEARED.equals(action)) {
final Uri data = intent.getData();
if (data != null) {
final String packageName = data.getSchemeSpecificPart();
resolver.call(RecentsProvider.buildRecent(), RecentsProvider.METHOD_PURGE_PACKAGE, packageName, null);
}
}
}
use of android.content.ContentResolver in project platform_frameworks_base by android.
the class CreateDirectoryFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity();
final ContentResolver resolver = context.getContentResolver();
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext());
final View view = dialogInflater.inflate(R.layout.dialog_file_name, null, false);
final EditText editText = (EditText) view.findViewById(android.R.id.text1);
builder.setTitle(R.string.menu_create_dir);
builder.setView(view);
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
createDirectory(editText.getText().toString());
}
});
builder.setNegativeButton(android.R.string.cancel, null);
final AlertDialog dialog = builder.create();
// Workaround for the problem - virtual keyboard doesn't show on the phone.
Shared.ensureKeyboardPresent(context, dialog);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, @Nullable KeyEvent event) {
if ((actionId == EditorInfo.IME_ACTION_DONE) || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.hasNoModifiers())) {
createDirectory(editText.getText().toString());
dialog.dismiss();
return true;
}
return false;
}
});
return dialog;
}
use of android.content.ContentResolver in project platform_frameworks_base by android.
the class DirectoryLoader method loadInBackground.
@Override
public final DirectoryResult loadInBackground() {
synchronized (this) {
if (isLoadInBackgroundCanceled()) {
throw new OperationCanceledException();
}
mSignal = new CancellationSignal();
}
final ContentResolver resolver = getContext().getContentResolver();
final String authority = mUri.getAuthority();
final DirectoryResult result = new DirectoryResult();
result.doc = mDoc;
// Use default document when searching
if (mSearchMode) {
final Uri docUri = DocumentsContract.buildDocumentUri(mRoot.authority, mRoot.documentId);
try {
mDoc = DocumentInfo.fromUri(resolver, docUri);
} catch (FileNotFoundException e) {
Log.w(TAG, "Failed to query", e);
result.exception = e;
return result;
}
}
if (mUserSortOrder != State.SORT_ORDER_UNKNOWN) {
result.sortOrder = mUserSortOrder;
} else {
if ((mDoc.flags & Document.FLAG_DIR_PREFERS_LAST_MODIFIED) != 0) {
result.sortOrder = State.SORT_ORDER_LAST_MODIFIED;
} else {
result.sortOrder = State.SORT_ORDER_DISPLAY_NAME;
}
}
// Search always uses ranking from provider
if (mSearchMode) {
result.sortOrder = State.SORT_ORDER_UNKNOWN;
}
if (DEBUG)
Log.d(TAG, "userSortOrder=" + mUserSortOrder + ", sortOrder=" + result.sortOrder);
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority);
cursor = client.query(mUri, null, null, null, getQuerySortOrder(result.sortOrder), mSignal);
if (cursor == null) {
throw new RemoteException("Provider returned null");
}
cursor.registerContentObserver(mObserver);
cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1);
if (mSearchMode) {
// Filter directories out of search results, for now
cursor = new FilteringCursorWrapper(cursor, null, SEARCH_REJECT_MIMES);
}
result.client = client;
result.cursor = cursor;
} catch (Exception e) {
Log.w(TAG, "Failed to query", e);
result.exception = e;
ContentProviderClient.releaseQuietly(client);
} finally {
synchronized (this) {
mSignal = null;
}
}
return result;
}
use of android.content.ContentResolver in project platform_frameworks_base by android.
the class DocumentClipper method getClipDataForDocuments.
/**
* Returns ClipData representing the list of docs, or null if docs is empty,
* or docs cannot be converted.
*/
@Nullable
public ClipData getClipDataForDocuments(List<DocumentInfo> docs) {
final ContentResolver resolver = mContext.getContentResolver();
final String[] mimeTypes = getMimeTypes(resolver, docs);
ClipData clipData = null;
for (DocumentInfo doc : docs) {
if (clipData == null) {
// TODO: figure out what this string should be.
// Currently it is not displayed anywhere in the UI, but this might change.
final String label = "";
clipData = new ClipData(label, mimeTypes, new ClipData.Item(doc.derivedUri));
} else {
// TODO: update list of mime types in ClipData.
clipData.addItem(new ClipData.Item(doc.derivedUri));
}
}
return clipData;
}
Aggregations