Merge "Enforcement control for READ_EXTERNAL permission."
This commit is contained in:
25
res/menu/storage.xml
Normal file
25
res/menu/storage.xml
Normal file
@@ -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>
|
@@ -1878,6 +1878,9 @@
|
|||||||
|
|
||||||
<!-- Storage setting. Menu option for USB transfer settings [CHAR LIMIT=30]-->
|
<!-- Storage setting. Menu option for USB transfer settings [CHAR LIMIT=30]-->
|
||||||
<string name="storage_menu_usb">USB computer connection</string>
|
<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]-->
|
<!-- Storage setting. Title for USB transfer settings [CHAR LIMIT=30]-->
|
||||||
<string name="storage_title_usb">USB computer connection</string>
|
<string name="storage_title_usb">USB computer connection</string>
|
||||||
<!-- Storage setting. USB connection category [CHAR LIMIT=30]-->
|
<!-- Storage setting. USB connection category [CHAR LIMIT=30]-->
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings;
|
|||||||
|
|
||||||
import com.android.settings.accounts.AccountSyncSettings;
|
import com.android.settings.accounts.AccountSyncSettings;
|
||||||
import com.android.settings.bluetooth.BluetoothEnabler;
|
import com.android.settings.bluetooth.BluetoothEnabler;
|
||||||
|
import com.android.settings.deviceinfo.Memory;
|
||||||
import com.android.settings.fuelgauge.PowerUsageSummary;
|
import com.android.settings.fuelgauge.PowerUsageSummary;
|
||||||
import com.android.settings.wifi.WifiEnabler;
|
import com.android.settings.wifi.WifiEnabler;
|
||||||
|
|
||||||
@@ -294,7 +295,8 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
|
|||||||
if (DataUsageSummary.class.getName().equals(fragmentName) ||
|
if (DataUsageSummary.class.getName().equals(fragmentName) ||
|
||||||
PowerUsageSummary.class.getName().equals(fragmentName) ||
|
PowerUsageSummary.class.getName().equals(fragmentName) ||
|
||||||
AccountSyncSettings.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);
|
intent.putExtra(EXTRA_CLEAR_UI_OPTIONS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.deviceinfo;
|
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.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@@ -23,6 +28,7 @@ import android.content.Context;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.pm.IPackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
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_CONFIRM_UNMOUNT = 1;
|
||||||
private static final int DLG_ERROR_UNMOUNT = 2;
|
private static final int DLG_ERROR_UNMOUNT = 2;
|
||||||
|
|
||||||
private static final int MENU_ID_USB = Menu.FIRST;
|
|
||||||
|
|
||||||
private Resources mResources;
|
private Resources mResources;
|
||||||
|
|
||||||
// The mountToggle Preference that has last been clicked.
|
// The mountToggle Preference that has last been clicked.
|
||||||
@@ -65,6 +69,7 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
private IMountService mMountService = null;
|
private IMountService mMountService = null;
|
||||||
|
|
||||||
private StorageManager mStorageManager = null;
|
private StorageManager mStorageManager = null;
|
||||||
|
private IPackageManager mPackageService;
|
||||||
|
|
||||||
private StorageVolumePreferenceCategory mInternalStorageVolumePreferenceCategory;
|
private StorageVolumePreferenceCategory mInternalStorageVolumePreferenceCategory;
|
||||||
private StorageVolumePreferenceCategory[] mStorageVolumePreferenceCategories;
|
private StorageVolumePreferenceCategory[] mStorageVolumePreferenceCategories;
|
||||||
@@ -78,6 +83,8 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
mStorageManager.registerListener(mStorageListener);
|
mStorageManager.registerListener(mStorageListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mPackageService = ActivityThread.getPackageManager();
|
||||||
|
|
||||||
addPreferencesFromResource(R.xml.device_info_memory);
|
addPreferencesFromResource(R.xml.device_info_memory);
|
||||||
|
|
||||||
mResources = getResources();
|
mResources = getResources();
|
||||||
@@ -92,9 +99,6 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
|
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;
|
int length = storageVolumes.length;
|
||||||
mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length];
|
mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
@@ -106,8 +110,13 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
mStorageVolumePreferenceCategories[i].init();
|
mStorageVolumePreferenceCategories[i].init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// only show options menu if we are not using the legacy USB mass storage support
|
setHasOptionsMenu(true);
|
||||||
setHasOptionsMenu(!massStorageEnabled);
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -163,15 +172,29 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
menu.add(Menu.NONE, MENU_ID_USB, 0, R.string.storage_menu_usb)
|
inflater.inflate(R.menu.storage, menu);
|
||||||
//.setIcon(com.android.internal.R.drawable.stat_sys_data_usb)
|
}
|
||||||
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
|
||||||
|
@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
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case MENU_ID_USB:
|
case R.id.storage_usb:
|
||||||
if (getActivity() instanceof PreferenceActivity) {
|
if (getActivity() instanceof PreferenceActivity) {
|
||||||
((PreferenceActivity) getActivity()).startPreferencePanel(
|
((PreferenceActivity) getActivity()).startPreferencePanel(
|
||||||
UsbSettings.class.getCanonicalName(),
|
UsbSettings.class.getCanonicalName(),
|
||||||
@@ -182,6 +205,19 @@ public class Memory extends SettingsPreferenceFragment {
|
|||||||
startFragment(this, UsbSettings.class.getCanonicalName(), -1, null);
|
startFragment(this, UsbSettings.class.getCanonicalName(), -1, null);
|
||||||
}
|
}
|
||||||
return true;
|
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);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user