| 1 | package net.paperclover.snowbound.providerprobe; |
| 2 | |
| 3 | import android.app.Activity; |
| 4 | import android.content.ComponentName; |
| 5 | import android.content.Intent; |
| 6 | import android.os.Bundle; |
| 7 | import java.util.concurrent.CountDownLatch; |
| 8 | |
| 9 | public final class Grant extends Activity { |
| 10 | static volatile Bundle reply; |
| 11 | static CountDownLatch done; |
| 12 | |
| 13 | @Override public void onCreate(Bundle state) { |
| 14 | super.onCreate(state); |
| 15 | startActivityForResult(new Intent().setComponent(new ComponentName( |
| 16 | "net.paperclover.snowbound.providerlab", "net.paperclover.snowbound.providerlab.Pick")) |
| 17 | .putExtra("write", getIntent().getBooleanExtra("write", false)), 1); |
| 18 | } |
| 19 | |
| 20 | @Override protected void onActivityResult(int request, int result, Intent data) { |
| 21 | super.onActivityResult(request, result, data); |
| 22 | reply = new Bundle(); |
| 23 | try { |
| 24 | if (request != 1 || result != RESULT_OK || data == null) throw new IllegalStateException("Grant result missing"); |
| 25 | int flags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); |
| 26 | getContentResolver().takePersistableUriPermission(data.getData(), flags); |
| 27 | reply.putBoolean("ok", true); |
| 28 | reply.putInt("receivedFlags", data.getFlags()); |
| 29 | reply.putInt("persistedFlags", flags); |
| 30 | reply.putString("uri", data.getData().toString()); |
| 31 | reply.putInt("providerUid", data.getIntExtra("providerUid", -1)); |
| 32 | reply.putInt("providerPid", data.getIntExtra("providerPid", -1)); |
| 33 | } catch (Exception e) { |
| 34 | reply.putString("error", e.toString()); |
| 35 | } |
| 36 | done.countDown(); |
| 37 | finish(); |
| 38 | } |
| 39 | } |