Location Setting change for O
This is a change that adds a link from location settings to location permissions Test: Manual Bug: 34400189 Change-Id: If873fbb6e53c1fd86a3cfe38e06465cdec56bef8
This commit is contained in:
@@ -3039,6 +3039,8 @@
|
||||
<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 -->
|
||||
|
@@ -34,6 +34,11 @@
|
||||
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" />
|
||||
|
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
}
|
@@ -18,6 +18,7 @@ package com.android.settings.location;
|
||||
|
||||
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;
|
||||
@@ -95,11 +96,14 @@ public class LocationSettings extends LocationSettingsBase
|
||||
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;
|
||||
@@ -201,10 +205,21 @@ public class LocationSettings extends LocationSettingsBase
|
||||
}
|
||||
});
|
||||
|
||||
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(),
|
||||
@@ -261,6 +276,23 @@ public class LocationSettings extends LocationSettingsBase
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
@@ -0,0 +1,69 @@
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user