use of android.content.ContentProviderClient in project android_frameworks_base by ParanoidAndroid.
the class ActivityTestMain method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Animate!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityTestMain.this, R.style.SlowDialog);
builder.setTitle("This is a title");
builder.show();
return true;
}
});
menu.add("Bind!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "Service connected " + name + " " + service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.i(TAG, "Service disconnected " + name);
}
};
if (bindService(intent, conn, Context.BIND_AUTO_CREATE)) {
mConnections.add(conn);
} else {
Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
}
return true;
}
});
menu.add("Start!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, SingleUserService.class);
startService(intent);
return true;
}
});
menu.add("Send!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, SingleUserReceiver.class);
sendOrderedBroadcast(intent, null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
return true;
}
});
menu.add("Call!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
ContentProviderClient cpl = getContentResolver().acquireContentProviderClient(SingleUserProvider.AUTHORITY);
Bundle res = null;
try {
res = cpl.call("getuser", null, null);
} catch (RemoteException e) {
}
int user = res != null ? res.getInt("user", -1) : -1;
Toast.makeText(ActivityTestMain.this, "Provider executed as user " + (user >= 0 ? Integer.toString(user) : "unknown"), Toast.LENGTH_LONG).show();
cpl.release();
return true;
}
});
menu.add("Send to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
sendOrderedBroadcastAsUser(intent, new UserHandle(0), null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
return true;
}
});
menu.add("Send to user " + mSecondUser + "!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, UserTarget.class);
sendOrderedBroadcastAsUser(intent, new UserHandle(mSecondUser), null, new BroadcastResultReceiver(), null, Activity.RESULT_OK, null, null);
return true;
}
});
menu.add("Bind to user 0!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "Service connected " + name + " " + service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.i(TAG, "Service disconnected " + name);
}
};
if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, UserHandle.OWNER)) {
mConnections.add(conn);
} else {
Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
}
return true;
}
});
menu.add("Bind to user " + mSecondUser + "!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Intent intent = new Intent(ActivityTestMain.this, ServiceUserTarget.class);
ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "Service connected " + name + " " + service);
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.i(TAG, "Service disconnected " + name);
}
};
if (bindServiceAsUser(intent, conn, Context.BIND_AUTO_CREATE, new UserHandle(mSecondUser))) {
mConnections.add(conn);
} else {
Toast.makeText(ActivityTestMain.this, "Failed to bind", Toast.LENGTH_LONG).show();
}
return true;
}
});
menu.add("Density!").setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (mOverrideConfig == null) {
mOverrideConfig = new Configuration();
}
if (mOverrideConfig.densityDpi == Configuration.DENSITY_DPI_UNDEFINED) {
mOverrideConfig.densityDpi = (getApplicationContext().getResources().getConfiguration().densityDpi * 2) / 3;
} else {
mOverrideConfig.densityDpi = Configuration.DENSITY_DPI_UNDEFINED;
}
recreate();
return true;
}
});
return true;
}
use of android.content.ContentProviderClient in project android_frameworks_base by ResurrectionRemix.
the class DocumentsApplication method acquireUnstableProviderOrThrow.
public static ContentProviderClient acquireUnstableProviderOrThrow(ContentResolver resolver, String authority) throws RemoteException {
final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(authority);
if (client == null) {
throw new RemoteException("Failed to acquire provider for " + authority);
}
client.setDetectNotResponding(PROVIDER_ANR_TIMEOUT);
return client;
}
use of android.content.ContentProviderClient in project android_frameworks_base by ResurrectionRemix.
the class DocumentInfo method updateFromUri.
public void updateFromUri(ContentResolver resolver, Uri uri) throws FileNotFoundException {
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, uri.getAuthority());
cursor = client.query(uri, null, null, null, null);
if (!cursor.moveToFirst()) {
throw new FileNotFoundException("Missing details for " + uri);
}
updateFromCursor(cursor, uri.getAuthority());
} catch (Throwable t) {
throw asFileNotFoundException(t);
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClient.releaseQuietly(client);
}
}
use of android.content.ContentProviderClient in project android_frameworks_base by ResurrectionRemix.
the class OpenExternalDirectoryActivity method getIntentForExistingPermission.
private static Intent getIntentForExistingPermission(OpenExternalDirectoryActivity activity, boolean isRoot, File root, File file) {
final String packageName = activity.getCallingPackage();
final ContentProviderClient storageClient = activity.getExternalStorageClient();
final Uri grantedUri = getGrantedUriPermission(activity, storageClient, file);
final Uri rootUri = root.equals(file) ? grantedUri : getGrantedUriPermission(activity, storageClient, root);
if (DEBUG)
Log.d(TAG, "checking if " + packageName + " already has permission for " + grantedUri + " or its root (" + rootUri + ")");
final ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
for (UriPermission uriPermission : am.getGrantedUriPermissions(packageName).getList()) {
final Uri uri = uriPermission.getUri();
if (uri == null) {
Log.w(TAG, "null URI for " + uriPermission);
continue;
}
if (uri.equals(grantedUri) || uri.equals(rootUri)) {
if (DEBUG)
Log.d(TAG, packageName + " already has permission: " + uriPermission);
return createGrantedUriPermissionsIntent(grantedUri);
}
}
if (DEBUG)
Log.d(TAG, packageName + " does not have permission for " + grantedUri);
return null;
}
use of android.content.ContentProviderClient in project android_frameworks_base by ResurrectionRemix.
the class RootsCache method loadRootsForAuthority.
/**
* Bring up requested provider and query for all active roots.
*/
private Collection<RootInfo> loadRootsForAuthority(ContentResolver resolver, String authority, boolean forceRefresh) {
if (DEBUG)
Log.d(TAG, "Loading roots for " + authority);
synchronized (mObservedAuthorities) {
if (mObservedAuthorities.add(authority)) {
// Watch for any future updates
final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
mContext.getContentResolver().registerContentObserver(rootsUri, true, mObserver);
}
}
final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
if (!forceRefresh) {
// Look for roots data that we might have cached for ourselves in the
// long-lived system process.
final Bundle systemCache = resolver.getCache(rootsUri);
if (systemCache != null) {
if (DEBUG)
Log.d(TAG, "System cache hit for " + authority);
return systemCache.getParcelableArrayList(TAG);
}
}
final ArrayList<RootInfo> roots = new ArrayList<>();
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority);
cursor = client.query(rootsUri, null, null, null, null);
while (cursor.moveToNext()) {
final RootInfo root = RootInfo.fromRootsCursor(authority, cursor);
roots.add(root);
}
} catch (Exception e) {
Log.w(TAG, "Failed to load some roots from " + authority + ": " + e);
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClient.releaseQuietly(client);
}
// Cache these freshly parsed roots over in the long-lived system
// process, in case our process goes away. The system takes care of
// invalidating the cache if the package or Uri changes.
final Bundle systemCache = new Bundle();
systemCache.putParcelableArrayList(TAG, roots);
resolver.putCache(rootsUri, systemCache);
return roots;
}
Aggregations