<string name="location_mode_sensors_only_title">Device only</string>
<!-- [CHAR LIMIT=30] Location settings screen, location off mode -->
<string name="location_mode_location_off_title">Location off</string>
+ <!-- [CHAR LIMIT=30] Location settings screen, app-level permissions -->
+ <string name="location_app_level_permissions">App-level permissions</string>
<!-- [CHAR LIMIT=30] Location settings screen, sub category for recent location requests -->
<string name="location_category_recent_location_requests">Recent location requests</string>
<!-- Location settings screen, displayed when there's no recent app accessing location -->
android:enabled="false"
android:selectable="true" />
+ <!-- This preference category gets removed if new_recent_location_ui is disabled -->
+ <Preference
+ android:key="app_level_permissions"
+ android:title="@string/location_app_level_permissions" />
+
<com.android.settings.DividedCategory
android:key="recent_location_requests"
android:title="@string/location_category_recent_location_requests" />
--- /dev/null
+package com.android.settings.location;
+
+import android.content.Context;
+import android.content.Intent;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.core.PreferenceController;
+
+public class AppLocationPermissionPreferenceController extends PreferenceController {
+
+ private static final String KEY_APP_LEVEL_PERMISSIONS = "app_level_permissions";
+ private Preference mPreference;
+
+ public AppLocationPermissionPreferenceController(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ if (isAvailable()) {
+ mPreference = screen.findPreference(KEY_APP_LEVEL_PERMISSIONS);
+ }
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_APP_LEVEL_PERMISSIONS;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return Settings.Global.getInt(mContext.getContentResolver(),
+ android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED, 1)
+ == 1;
+ }
+}
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
+import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
private static final String KEY_LOCATION_MODE = "location_mode";
/** Key for preference category "Recent location requests" */
private static final String KEY_RECENT_LOCATION_REQUESTS = "recent_location_requests";
+ /** Key for preference "App-level permissions" */
+ private static final String KEY_APP_LEVEL_PERMISSIONS = "app_level_permissions";
/** Key for preference category "Location services" */
private static final String KEY_LOCATION_SERVICES = "location_services";
private static final int MENU_SCANNING = Menu.FIRST;
+ private static final String KEY_LOCATION_PERMISSION = "android.permission-group.LOCATION";
private SwitchBar mSwitchBar;
private Switch mSwitch;
private boolean mValidListener = false;
}
});
- mCategoryRecentLocationRequests =
- (PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
RecentLocationApps recentApps = new RecentLocationApps(activity);
List<RecentLocationApps.Request> recentLocationRequests = recentApps.getAppList();
+
+ final AppLocationPermissionPreferenceController preferenceController =
+ new AppLocationPermissionPreferenceController(activity);
+ preferenceController.displayPreference(root);
+ if (preferenceController.isAvailable()) {
+ Preference preferenceAppLevelPermissions =
+ root.findPreference(KEY_APP_LEVEL_PERMISSIONS);
+ setupAppLevelPermissionsPreference(preferenceAppLevelPermissions);
+ }
+
+ mCategoryRecentLocationRequests =
+ (PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
+
List<Preference> recentLocationPrefs = new ArrayList<>(recentLocationRequests.size());
for (final RecentLocationApps.Request request : recentLocationRequests) {
DimmableIconPreference pref = new DimmableIconPreference(getPrefContext(),
}
}
+ private void setupAppLevelPermissionsPreference(Preference preference) {
+ preference.setOnPreferenceClickListener(
+ new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ Intent intent = new Intent(Intent.ACTION_MANAGE_PERMISSION_APPS)
+ .putExtra(Intent.EXTRA_PERMISSION_NAME, KEY_LOCATION_PERMISSION);
+ try {
+ getActivity().startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Log.w("Permission", "No app to handle " + intent);
+ }
+ return true;
+ }
+ });
+ }
+
private void changeManagedProfileLocationAccessStatus(boolean mainSwitchOn) {
if (mManagedProfileSwitch == null) {
return;
--- /dev/null
+package com.android.settings.location;
+
+import android.content.Context;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+import static org.mockito.Answers.RETURNS_DEEP_STUBS;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AppLocationPermissionPreferenceControllerTest {
+ @Mock
+ private Preference mPreference;
+ @Mock(answer = RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
+
+ private AppLocationPermissionPreferenceController mController;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(mScreen.findPreference(anyString())).thenReturn(mPreference);
+ mController = new AppLocationPermissionPreferenceController(mContext);
+ }
+
+ @Test
+ public void displayPreference_shouldRemovePreference() {
+ Settings.System.putInt(mContext.getContentResolver(),
+ android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
+ 0);
+
+ mController.displayPreference(mScreen);
+
+ verify(mScreen).removePreference(any(Preference.class));
+ }
+
+ @Test
+ public void displayPreference_shouldNotRemovePreference() {
+ Settings.System.putInt(mContext.getContentResolver(),
+ android.provider.Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
+ 1);
+ mController.displayPreference(mScreen);
+
+ verify(mScreen, never()).removePreference(any(Preference.class));
+ }
+
+}