diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-03-19 16:54:07 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2012-03-19 17:23:01 -0700 |
commit | 11d3012c78fcd23d2dfc7830e03db191af7ba476 (patch) | |
tree | 98eb4aac9f95bbea779373b76b4dabebab331efd | |
parent | d88d7daf1b3e0b19dd6645cb08d8f67e919f2101 (diff) | |
download | packages_apps_settings-11d3012c78fcd23d2dfc7830e03db191af7ba476.zip packages_apps_settings-11d3012c78fcd23d2dfc7830e03db191af7ba476.tar.gz packages_apps_settings-11d3012c78fcd23d2dfc7830e03db191af7ba476.tar.bz2 |
Enforcement control for READ_EXTERNAL permission.
Surface enforcement controls for READ_EXTERNAL_STORAGE permission
using new PackageManager API.
Bug: 6131916
Change-Id: I0ece4742666fda58e41410cb4b0b7175f280fa31
-rw-r--r-- | res/menu/storage.xml | 25 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/com/android/settings/Settings.java | 4 | ||||
-rw-r--r-- | src/com/android/settings/deviceinfo/Memory.java | 58 |
4 files changed, 78 insertions, 12 deletions
diff --git a/res/menu/storage.xml b/res/menu/storage.xml new file mode 100644 index 0000000..fa9639c --- /dev/null +++ b/res/menu/storage.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2012 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item + android:id="@+id/storage_usb" + android:title="@string/storage_menu_usb" /> + <item + android:id="@+id/storage_enforce_read_external" + android:title="@string/storage_menu_enforce_read_external" + android:checkable="true" /> +</menu> diff --git a/res/values/strings.xml b/res/values/strings.xml index fddc6cb..e31a83a 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1878,6 +1878,9 @@ <!-- Storage setting. Menu option for USB transfer settings [CHAR LIMIT=30]--> <string name="storage_menu_usb">USB computer connection</string> + <!-- Storage setting. Menu option to enforce read external storage permission. [CHAR LIMIT=30]--> + <string name="storage_menu_enforce_read_external">Enforce read external</string> + <!-- Storage setting. Title for USB transfer settings [CHAR LIMIT=30]--> <string name="storage_title_usb">USB computer connection</string> <!-- Storage setting. USB connection category [CHAR LIMIT=30]--> diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index c9f5c73..eb30809 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -18,6 +18,7 @@ package com.android.settings; import com.android.settings.accounts.AccountSyncSettings; import com.android.settings.bluetooth.BluetoothEnabler; +import com.android.settings.deviceinfo.Memory; import com.android.settings.fuelgauge.PowerUsageSummary; import com.android.settings.wifi.WifiEnabler; @@ -294,7 +295,8 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler { if (DataUsageSummary.class.getName().equals(fragmentName) || PowerUsageSummary.class.getName().equals(fragmentName) || AccountSyncSettings.class.getName().equals(fragmentName) || - UserDictionarySettings.class.getName().equals(fragmentName)) { + UserDictionarySettings.class.getName().equals(fragmentName) || + Memory.class.getName().equals(fragmentName)) { intent.putExtra(EXTRA_CLEAR_UI_OPTIONS, true); } diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java index 728e558..999449a 100644 --- a/src/com/android/settings/deviceinfo/Memory.java +++ b/src/com/android/settings/deviceinfo/Memory.java @@ -16,6 +16,11 @@ package com.android.settings.deviceinfo; +import static android.Manifest.permission.READ_EXTERNAL_STORAGE; +import static android.content.pm.PackageManager.ENFORCEMENT_DEFAULT; +import static android.content.pm.PackageManager.ENFORCEMENT_YES; + +import android.app.ActivityThread; import android.app.AlertDialog; import android.app.Dialog; import android.content.BroadcastReceiver; @@ -23,6 +28,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.IPackageManager; import android.content.res.Resources; import android.os.Bundle; import android.os.Environment; @@ -51,8 +57,6 @@ public class Memory extends SettingsPreferenceFragment { private static final int DLG_CONFIRM_UNMOUNT = 1; private static final int DLG_ERROR_UNMOUNT = 2; - private static final int MENU_ID_USB = Menu.FIRST; - private Resources mResources; // The mountToggle Preference that has last been clicked. @@ -65,6 +69,7 @@ public class Memory extends SettingsPreferenceFragment { private IMountService mMountService = null; private StorageManager mStorageManager = null; + private IPackageManager mPackageService; private StorageVolumePreferenceCategory mInternalStorageVolumePreferenceCategory; private StorageVolumePreferenceCategory[] mStorageVolumePreferenceCategories; @@ -78,6 +83,8 @@ public class Memory extends SettingsPreferenceFragment { mStorageManager.registerListener(mStorageListener); } + mPackageService = ActivityThread.getPackageManager(); + addPreferencesFromResource(R.xml.device_info_memory); mResources = getResources(); @@ -92,9 +99,6 @@ public class Memory extends SettingsPreferenceFragment { } StorageVolume[] storageVolumes = mStorageManager.getVolumeList(); - // mass storage is enabled if primary volume supports it - boolean massStorageEnabled = (storageVolumes.length > 0 - && storageVolumes[0].allowMassStorage()); int length = storageVolumes.length; mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length]; for (int i = 0; i < length; i++) { @@ -106,8 +110,13 @@ public class Memory extends SettingsPreferenceFragment { mStorageVolumePreferenceCategories[i].init(); } - // only show options menu if we are not using the legacy USB mass storage support - setHasOptionsMenu(!massStorageEnabled); + setHasOptionsMenu(true); + } + + private boolean isMassStorageEnabled() { + // mass storage is enabled if primary volume supports it + final StorageVolume[] storageVolumes = mStorageManager.getVolumeList(); + return (storageVolumes.length > 0 && storageVolumes[0].allowMassStorage()); } @Override @@ -163,15 +172,29 @@ public class Memory extends SettingsPreferenceFragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - menu.add(Menu.NONE, MENU_ID_USB, 0, R.string.storage_menu_usb) - //.setIcon(com.android.internal.R.drawable.stat_sys_data_usb) - .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); + inflater.inflate(R.menu.storage, menu); + } + + @Override + public void onPrepareOptionsMenu(Menu menu) { + final MenuItem usb = menu.findItem(R.id.storage_usb); + usb.setVisible(!isMassStorageEnabled()); + + final int enforcement; + try { + enforcement = mPackageService.getPermissionEnforcement(READ_EXTERNAL_STORAGE); + } catch (RemoteException e) { + throw new RuntimeException("Problem talking with PackageManager", e); + } + + final MenuItem enforceReadExternal = menu.findItem(R.id.storage_enforce_read_external); + enforceReadExternal.setChecked(enforcement == ENFORCEMENT_YES); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case MENU_ID_USB: + case R.id.storage_usb: if (getActivity() instanceof PreferenceActivity) { ((PreferenceActivity) getActivity()).startPreferencePanel( UsbSettings.class.getCanonicalName(), @@ -182,6 +205,19 @@ public class Memory extends SettingsPreferenceFragment { startFragment(this, UsbSettings.class.getCanonicalName(), -1, null); } return true; + case R.id.storage_enforce_read_external: { + final boolean checked = !item.isChecked(); + item.setChecked(checked); + + final int enforcement = checked ? ENFORCEMENT_YES : ENFORCEMENT_DEFAULT; + try { + // TODO: offload to background thread + mPackageService.setPermissionEnforcement(READ_EXTERNAL_STORAGE, enforcement); + } catch (RemoteException e) { + throw new RuntimeException("Problem talking with PackageManager", e); + } + return true; + } } return super.onOptionsItemSelected(item); } |