diff options
author | Ben Kwa <kenobi@google.com> | 2015-05-29 15:40:31 -0700 |
---|---|---|
committer | Ben Kwa <kenobi@google.com> | 2015-06-10 11:24:55 -0700 |
commit | 77797400ec103b1691e1c3fa602c329b49ac18ca (patch) | |
tree | bc9ea8cd42536ddeaf4fb2a50cdb05d8af38d6b8 /packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java | |
parent | 327c364113c18c9d5a05df0c912b65788461da41 (diff) | |
download | frameworks_base-77797400ec103b1691e1c3fa602c329b49ac18ca.zip frameworks_base-77797400ec103b1691e1c3fa602c329b49ac18ca.tar.gz frameworks_base-77797400ec103b1691e1c3fa602c329b49ac18ca.tar.bz2 |
Enable apps to exclude their own roots from the DocumentsUI roots list.
- Add DocumentsContract.EXTRA_EXCLUDE_SELF (boolean extra)
- Add code to DocumentsActivity to cache the providers of the calling
app if EXTRA_EXCLUDE_SELF is set on incoming Intents.
- Add code to RootsCache to exclude roots from the calling app.
- Add code to allow only system apps to use EXTRA_PACKAGE_NAME.
Change-Id: Ia7cc2a1a297676c7b26f6e583042a4607d8c9a4e
Diffstat (limited to 'packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java')
-rw-r--r-- | packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java index cb21131..8ea5816 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.concurrent.Executor; @@ -32,6 +33,10 @@ import libcore.io.IoUtils; import android.app.Activity; import android.app.Fragment; import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.ProviderInfo; import android.database.Cursor; import android.net.Uri; import android.os.AsyncTask; @@ -232,9 +237,38 @@ abstract class BaseActivity extends Activity { invalidateOptionsMenu(); } + final List<String> getExcludedAuthorities() { + List<String> authorities = new ArrayList<>(); + if (getIntent().getBooleanExtra(DocumentsContract.EXTRA_EXCLUDE_SELF, false)) { + // Exclude roots provided by the calling package. + String packageName = getCallingPackageMaybeExtra(); + try { + PackageInfo pkgInfo = getPackageManager().getPackageInfo(packageName, + PackageManager.GET_PROVIDERS); + for (ProviderInfo provider: pkgInfo.providers) { + authorities.add(provider.authority); + } + } catch (PackageManager.NameNotFoundException e) { + Log.e(mTag, "Calling package name does not resolve: " + packageName); + } + } + return authorities; + } + final String getCallingPackageMaybeExtra() { - final String extra = getIntent().getStringExtra(DocumentsContract.EXTRA_PACKAGE_NAME); - return (extra != null) ? extra : getCallingPackage(); + String callingPackage = getCallingPackage(); + // System apps can set the calling package name using an extra. + try { + ApplicationInfo info = getPackageManager().getApplicationInfo(callingPackage, 0); + if (info.isSystemApp() || info.isUpdatedSystemApp()) { + final String extra = getIntent().getStringExtra(DocumentsContract.EXTRA_PACKAGE_NAME); + if (extra != null) { + callingPackage = extra; + } + } + } finally { + return callingPackage; + } } public static BaseActivity get(Fragment fragment) { @@ -287,6 +321,9 @@ abstract class BaseActivity extends Activity { /** Currently copying file */ public List<DocumentInfo> selectedDocumentsForCopy = new ArrayList<DocumentInfo>(); + /** Name of the package that started DocsUI */ + public List<String> excludedAuthorities = new ArrayList<>(); + public static final int ACTION_OPEN = 1; public static final int ACTION_CREATE = 2; public static final int ACTION_GET_CONTENT = 3; @@ -327,6 +364,7 @@ abstract class BaseActivity extends Activity { out.writeString(currentSearch); out.writeMap(dirState); out.writeList(selectedDocumentsForCopy); + out.writeList(excludedAuthorities); } public static final Creator<State> CREATOR = new Creator<State>() { @@ -348,6 +386,7 @@ abstract class BaseActivity extends Activity { state.currentSearch = in.readString(); in.readMap(state.dirState, null); in.readList(state.selectedDocumentsForCopy, null); + in.readList(state.excludedAuthorities, null); return state; } |