--- /dev/null
+<?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>
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;
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;
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.
private IMountService mMountService = null;
private StorageManager mStorageManager = null;
+ private IPackageManager mPackageService;
private StorageVolumePreferenceCategory mInternalStorageVolumePreferenceCategory;
private StorageVolumePreferenceCategory[] mStorageVolumePreferenceCategories;
mStorageManager.registerListener(mStorageListener);
}
+ mPackageService = ActivityThread.getPackageManager();
+
addPreferencesFromResource(R.xml.device_info_memory);
mResources = getResources();
}
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++) {
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
@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(),
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);
}